Liara Forth, an "ANSI(ish) initial Forth" for the W65C265SXB
Posted: Sun Mar 27, 2016 3:46 pm
So it's time to stop fooling around with blinking LEDs and write a Forth for the 265SXB.
From what I've seen, other people here such as Andrew (viewtopic.php?f=9&t=3612) are already working on large Forths for the 65816. My aim is to create a "first" or "initial" Forth for the 265SXB: The one you can download as a binary and install immediately after you've bought the board and some Flash memory. There should be tools to access expanded memory, but it will work "out of the box" with the 32 Kb RAM and 24 Kb Flash memory, which is the most simple (useful) configuration. As such, it will access the Mensch Monitor routines (at least at first), which is where the other 8 Kb are.
Obviously I'll be drawing a lot of inspiration from Tali Forth for the 65c02. There are two things that didn't work out so well there I'll be changing:
Tailored specifically for the 265SXB. Tali Forth did have a hardware basis, but it was sorta, kinda supposed to run on more general hardware, which, to put it politely, lead to some lack of structure. This time, the machine is exectly defined. Yes, there will be words to blink the LED and write to Flash.
Dictionary headers and code are kept separate. That allows fallthroughs and all other kinds of neat tricks with the code (see viewtopic.php?p=3331#p3331 for examples) that Tali can't do. (I should probably do a complete rewrite of Tali Forth, but as other people here have pointed out, once you have gone 16 bit with the 65816, it's pretty hard to go back.)
Like Tali, Liara will be based on subroutine threaded code (STC). Again, other people here are working on ITC and DTC versions. And I would still argue that because there are so few registers available, this makes a better fit. Also, like Tali, the ratio of primitives to threaded words will be rather high, for the added speed (fast the 265SXB ain't), the optimizations, and simply because I enjoyed all that coding. STC is good for these things.
(Footnote: I'm probably going to get a RPi 3 soon, which has the ARM-A53 64-bit CPU where they cleaned up the assembler ("AArch64", see https://www.element14.com/community/ser ... Manual.pdf). If I ever write a Forth for that, I promise to take a more serious look at DTC, because then I'll have about 30 64-bit registers to play with.)
The Return Stack will be the system stack, starting at 03FF and growing down. Direct Page (DP) would start at 0200, avoiding the first two pages completely where the Mensch Monitor does its thing. The Data Stack would start after whatever space the DP variables take and use X as the DSP. More on that in a later post, because I'm considering doing something weird with the stacks.
The other stuff is pretty obvious: 16-bit cell size, max code size 24 Kb, terminal access at first via the USB power jack, but with the option of the serial port as an alternative input source. I'm still considering cooperative ("PAUSE") multitasking. There should be enough space for a small editor of some sort, which then should be able to cope with any extra RAM.
I've started a (rather empty) GitHub respository at https://github.com/scotws/LiaraForth . I expect things to be slow going for a while, first because I'll probably be finding bugs galore with my assembler and emulator, second because I'm going to get chased out in the garden a lot in the next few weeks.
From what I've seen, other people here such as Andrew (viewtopic.php?f=9&t=3612) are already working on large Forths for the 65816. My aim is to create a "first" or "initial" Forth for the 265SXB: The one you can download as a binary and install immediately after you've bought the board and some Flash memory. There should be tools to access expanded memory, but it will work "out of the box" with the 32 Kb RAM and 24 Kb Flash memory, which is the most simple (useful) configuration. As such, it will access the Mensch Monitor routines (at least at first), which is where the other 8 Kb are.
Obviously I'll be drawing a lot of inspiration from Tali Forth for the 65c02. There are two things that didn't work out so well there I'll be changing:
Tailored specifically for the 265SXB. Tali Forth did have a hardware basis, but it was sorta, kinda supposed to run on more general hardware, which, to put it politely, lead to some lack of structure. This time, the machine is exectly defined. Yes, there will be words to blink the LED and write to Flash.
Dictionary headers and code are kept separate. That allows fallthroughs and all other kinds of neat tricks with the code (see viewtopic.php?p=3331#p3331 for examples) that Tali can't do. (I should probably do a complete rewrite of Tali Forth, but as other people here have pointed out, once you have gone 16 bit with the 65816, it's pretty hard to go back.)
Like Tali, Liara will be based on subroutine threaded code (STC). Again, other people here are working on ITC and DTC versions. And I would still argue that because there are so few registers available, this makes a better fit. Also, like Tali, the ratio of primitives to threaded words will be rather high, for the added speed (fast the 265SXB ain't), the optimizations, and simply because I enjoyed all that coding. STC is good for these things.
(Footnote: I'm probably going to get a RPi 3 soon, which has the ARM-A53 64-bit CPU where they cleaned up the assembler ("AArch64", see https://www.element14.com/community/ser ... Manual.pdf). If I ever write a Forth for that, I promise to take a more serious look at DTC, because then I'll have about 30 64-bit registers to play with.)
The Return Stack will be the system stack, starting at 03FF and growing down. Direct Page (DP) would start at 0200, avoiding the first two pages completely where the Mensch Monitor does its thing. The Data Stack would start after whatever space the DP variables take and use X as the DSP. More on that in a later post, because I'm considering doing something weird with the stacks.
The other stuff is pretty obvious: 16-bit cell size, max code size 24 Kb, terminal access at first via the USB power jack, but with the option of the serial port as an alternative input source. I'm still considering cooperative ("PAUSE") multitasking. There should be enough space for a small editor of some sort, which then should be able to cope with any extra RAM.
I've started a (rather empty) GitHub respository at https://github.com/scotws/LiaraForth . I expect things to be slow going for a while, first because I'll probably be finding bugs galore with my assembler and emulator, second because I'm going to get chased out in the garden a lot in the next few weeks.