Page 1 of 1
Forth for the w65c265
Posted: Mon Sep 15, 2025 9:14 pm
by Martin_H
Are there any current modern ANSI Forth versions running on the 65816? It looks like LiaraForth has been inactive since 2017.
I previously ported a FigForth for the 65c02, so I am familiar with how the 6502 version works. Porting a 65816 version to the 65c265 should be possible. But the link in the other thread was to an IP address and went nowhere.
Worst case scenario is porting GForth, but I'd wager it was written in C, which seems like an insult to the spirit of Forth.
Update: I found the GForth sources online and skimmed them. On the surface it is written in Forth, but the makefile shows it being built be the GCC. Moreover, the README states that GCC is a requirement. My guess is that it uses macros and the C preprocessor to translate Forth into C to produce the binary, but I haven't figured out how it does that.
Re: Forth for the w65c265
Posted: Tue Sep 16, 2025 6:36 am
by leepivonka
65816F is an 95% ANS FORTH for the 65816. It is subroutine threaded & has an optimizing compiler.
An older version of it that will load & run from RAM on a bare W65C265SXB board is at
http://174.31.20.105:81/65816F/
Re: Forth for the w65c265
Posted: Tue Sep 16, 2025 1:11 pm
by Martin_H
Thank you for replying.
The S record file at
http://174.31.20.105:81/65816F/0265sxb.s28 gets a 404 error.
0265sxb.lst is a listing rather than a source file, but I can work with it.
Re: Forth for the w65c265
Posted: Wed Sep 17, 2025 2:05 am
by Martin_H
Also, can your emulator load binaries produced by ld65? If not is their source for it?
Re: Forth for the w65c265
Posted: Thu Sep 18, 2025 2:12 am
by Martin_H
I've been mulling it over, and I think a direct threaded Forth may be a better option. I'm not yet proficient in 65816 assembly, but here's why I believe that.
The code bank register points to native code in the EEPROM.
The data bank register points to the user byte code in high RAM above the EEPROM.
The direct page register points to the area containing the stacks and Forth VM registers.
That should allow for using 96kb+ of memory without having to get too deep into 24-bit addressing.
Re: Forth for the w65c265
Posted: Thu Sep 18, 2025 9:00 am
by leepivonka
The 0265sxb.s28 link is fixed.
The emulator can load binary files with the V command. I use this to run Tali Forth:
V loads the binary file taliforth-65816s.bin at an offset of $8000.
Z does a reset, to pick up the Tali reset vector.
G starts execution.
If you make the ca65 segments absolute instead of the default relocatable, the ca65 listing shows absolute addresses. The emulator can then load this listing file directly. 0265sxb.lis is set up & loaded this way.
I've been thinking about how to use other banks of memory too. So far 65816F puts all the standard FORTH stuff in bank 0. It has a few non-standard memory access words that use double-cell addresses.
It is also easy to write a set of FORTH words to access data tables up to 64k in other banks with a 16bit offset. For example: the strings in Adventure could be stored in a segment in a hi bank, & referenced by their 16bit offset.
It is possible to put large assembler code routines in another bank by having standard FORTH words that wrap a jsl to a routine. I've thought about trying this for some of the floating-point code.
Standard FORTHs tend to assume a single flat address space that fits in a single cell.
A problem with putting user variables in bank 0 & other variables in another bank is how to make the word @ work for both. For example:
Code: Select all
: PrintBase12 ( n -- )
Base @ >R \ save existing base
12 Base ! \ set base 12
. \ print the number
R> Base ! \ restore existing base
;
I also need to go back & look at how DOES> works in dtc.
Re: Forth for the w65c265
Posted: Fri Sep 19, 2025 10:58 pm
by Martin_H
I don't see a V option to load s record. Here's the output I get:
Code: Select all
..\tools\65816S.exe ?
65816S Mar 6 2019 21:28:44
loader: open error ?: Invalid argument
65c265 mode on
A=0000 X=0000 Y=0000 S=0180 EnvMXdIzc D=0000 B=00 42424242 004242 wdm
.?
I don't know command '?'
Lfn : Load hex or listing
Sfn : Save Intel hex
1fn : Save S19 hex
2fn : Save S28 hex
Dl,h : Dump memory l to h (in hex)
E : Execution history
Tn : Trace n instructions
Un : Trace (no display) n instructions
O : Step Over instruction
G : Go full speed (^B to stop)
@fn : Start reading a text file into console
R : Register display
P : Polymorphic register display
Bb : Breakpoint move to b (in hex)
Cc : Character input to console
Hcc : Hex input to console
Q : Quit simulator
Waa : Write memory at aa (in hex)
X : Initialize performance tracing
Y : Write performance trace results
Z : CPU reset
I : IRQ
N : NMI
# : Disassemble to file DISASMF.ASM
%lo,hi,fn : Disassemble from lo to hi to file fn
.
When I used py65 I did not use it interactively. My Makefile would use the command line to load and run the unit test, write the output to a file, and diff it with a master. I would then write unit tests for each module and then link them into a program to load on real hardware. With sufficient unit testing the program would work on real hardware with almost no debugging.
Re: Forth for the w65c265
Posted: Tue Sep 23, 2025 6:48 am
by leepivonka
Arg! I've replaced 65816S.exe with a newer version that does have the V command!
Source is at
https://github.com/leepivonka/65816S
Re: Forth for the w65c265
Posted: Tue Sep 23, 2025 7:37 pm
by Martin_H
Thanks. I downloaded the exe and will look at the source code.