ROMable Forth
ROMable Forth
Garth, in the General Discusions forum, wrote:
...In fact if you put a Forth kernel on your 6502 machine...
Bill
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Hmmm... well, the public-domain FIG-Forth source is available at http://6502.org/source/forth65.zip . It's written out for a very basic assembler with no macro capabilities. I wondered what they were doing with variables since it might make a difference whether the kernel is in ROM or RAM. From a quick look, it looks like they're putting the system variables' data space in ZP RAM near address 0. Since that data space is separate from the code space, it would work with either RAM- or ROM-based systems, although you might still want to move it out of the precious page-0 space.
This issue of the variables' data space is the only difference between ROM and RAM versions that comes to mind offhand. The variables' headers (which FIND uses to find their addresses during compilation or interpretation of the input stream), as well as the small code that determines their runtime behavior, can go in either ROM or RAM, but the data itself must go in RAM, meaning it can't be mixed in with any headers and code in ROM.
What has kept me from publishing my own '02 Forth is that there are still a lot of fragments left that one particular company could claim a copyright on. A couple of months ago I started to look more seriously at taking care of those and neatening up the source code, and more-or-less decided that because of the size of the project, it would be better to spend my time on making my next computer with the '816 and further improving my very extensive '816 Forth instead. I have sent the '816 Forth out to several people, and one of them used it quite a bit.
I know, I know, if we're going to keep plugging Forth, we really ought to have something a little more turn-key for beginners. That, however, almost means either bundling it with working hardware that we supply, or publishing a version that is for specific hardware that's already available, whether Daryl's SBC-2 with a certain LCD, or something like that. As it stands now, the newbie would have quite an uphill battle to learn a system that he cannot see working yet, in order to make the necessary changes so it will work on his own hardware. There are plenty of Forths for PCs though, from very low-end to very high-end, if you want to tinker with it before trying to get it going on custom hardware. Samuel has some recommendations at viewtopic.php?t=1358&start=10 and viewtopic.php?t=1358&start=17 (both in the same topic). When you finally move to Forth on your own 6502 computer, you will normally have more freedom than you would on the PC.
As far as it being compact, Forth makes extremely efficient use of memory. I think I've heard of kernels themselves being as little as 2KB, but it's sure nice to also have a lot of the non-basics there ready to go, so you don't have to compile them every time you want them. After the kernel is in place, I've seen where someone won a competition by making a very full-featured screen editor in only 1KB of source code. The compiled code would take less than that. A screen editor is like a text editor for Forth source code, organized in 1KB blocks, 16 lines of 64 bytes each. I personally don't like screens. Although they have a couple of advantages, I think they're mostly very outdated and it works better to use a nice programmer's text editor and text files for your source code.
Keep hammering on us and someday we might get you a turn-key "starter kit".
This issue of the variables' data space is the only difference between ROM and RAM versions that comes to mind offhand. The variables' headers (which FIND uses to find their addresses during compilation or interpretation of the input stream), as well as the small code that determines their runtime behavior, can go in either ROM or RAM, but the data itself must go in RAM, meaning it can't be mixed in with any headers and code in ROM.
What has kept me from publishing my own '02 Forth is that there are still a lot of fragments left that one particular company could claim a copyright on. A couple of months ago I started to look more seriously at taking care of those and neatening up the source code, and more-or-less decided that because of the size of the project, it would be better to spend my time on making my next computer with the '816 and further improving my very extensive '816 Forth instead. I have sent the '816 Forth out to several people, and one of them used it quite a bit.
I know, I know, if we're going to keep plugging Forth, we really ought to have something a little more turn-key for beginners. That, however, almost means either bundling it with working hardware that we supply, or publishing a version that is for specific hardware that's already available, whether Daryl's SBC-2 with a certain LCD, or something like that. As it stands now, the newbie would have quite an uphill battle to learn a system that he cannot see working yet, in order to make the necessary changes so it will work on his own hardware. There are plenty of Forths for PCs though, from very low-end to very high-end, if you want to tinker with it before trying to get it going on custom hardware. Samuel has some recommendations at viewtopic.php?t=1358&start=10 and viewtopic.php?t=1358&start=17 (both in the same topic). When you finally move to Forth on your own 6502 computer, you will normally have more freedom than you would on the PC.
As far as it being compact, Forth makes extremely efficient use of memory. I think I've heard of kernels themselves being as little as 2KB, but it's sure nice to also have a lot of the non-basics there ready to go, so you don't have to compile them every time you want them. After the kernel is in place, I've seen where someone won a competition by making a very full-featured screen editor in only 1KB of source code. The compiled code would take less than that. A screen editor is like a text editor for Forth source code, organized in 1KB blocks, 16 lines of 64 bytes each. I personally don't like screens. Although they have a couple of advantages, I think they're mostly very outdated and it works better to use a nice programmer's text editor and text files for your source code.
Keep hammering on us and someday we might get you a turn-key "starter kit".
One other possibility is to port eForth. According to one its authors this has already been done, but a quick web search turned up empty for me. Anyway, eForth is specifically design to be quickly ported, as it has only a couple dozen primitives (the rest is basically DW directives). The downside is that its not geared toward performance; the idea was that you rewrite high level words as primitives once you got it working. I took a shot at porting the primitives, and I could post/email/what-have-you if anyone's interested/adventurous. They are completely untested.
-
electronicresourceguy
- Posts: 8
- Joined: 06 Apr 2009
- Location: United States
BillO wrote:
Is there a compact ROMable version of Forth?
GARTHWILSON wrote:
What has kept me from publishing my own '02 Forth is that there are still a lot of fragments left that one particular company could claim a copyright on.
GARTHWILSON wrote:
I know, I know, if we're going to keep plugging Forth, we really ought to have something a little more turn-key for beginners. That, however, almost means either bundling it with working hardware that we supply, or publishing a version that is for specific hardware that's already available, whether Daryl's SBC-2 with a certain LCD, or something like that. As it stands now, the newbie would have quite an uphill battle to learn a system that he cannot see working yet, in order to make the necessary changes so it will work on his own hardware.
Forth really only has two methods for interfacing to the world, get a character (KEY) and put a character (EMIT). I designed my system to use a vectored forth call for these routines. By default, KEY executes "0" and EMIT executes DROP. This is sort of an "I here nothing, I say nothing!" Just like Unix dev/null. These vectors are changed at first boot time with Forth code written in a boot rom area. You get to develop your preliminary I/O code in Forth, and can redevelop in ML if necessary.
This boot rom can be separate from the kernel rom. I have even been known to put a ram chip in a wire-wrap socket with a 5V regulator attached to a 9V battery clip and a pull-up resistor for the write line. Instant rom simulator. I would drop it into a zif socket attached to an Atari for programming, then move it to the zif socket in the breadboard computer. Pop the reset button, and away we go!
GARTHWILSON wrote:
As far as it being compact, Forth makes extremely efficient use of memory. I think I've heard of kernels themselves being as little as 2KB, but it's sure nice to also have a lot of the non-basics there ready to go, so you don't have to compile them every time you want them.
dclxvi wrote:
The downside is that its not geared toward performance; the idea was that you rewrite high level words as primitives once you got it working.
GARTHWILSON wrote:
Keep hammering on us and someday we might get you a turn-key "starter kit".
The Electronic Resource Guy
maybe inspiration can be found in forth dimension, check vol 4 num 4
"ROMable Forth With Separate Headers Robert H. Hertel 4 4 9 ROM"
it can be found here http://www.forth.org/fd/FDcover.html
"ROMable Forth With Separate Headers Robert H. Hertel 4 4 9 ROM"
it can be found here http://www.forth.org/fd/FDcover.html
KEY can reliably return 0 as a valid character, particularly if you're using the console interface to receive a binary file. You really ought to be using KEY? to query whether or not a byte from standard input is available or not. This also significantly benefits the performance of multitasking implementations, as KEY is simply:
Some systems also implement EMIT? to see if the output device is capable of receiving data. It's probably a good idea to implement this word too, for similar reasons.
Code: Select all
: KEY BEGIN PAUSE KEY? UNTIL (KEY) ;
-
electronicresourceguy
- Posts: 8
- Joined: 06 Apr 2009
- Location: United States
kc5tja wrote:
KEY can reliably return 0 as a valid character, particularly if you're using the console interface to receive a binary file. You really ought to be using KEY? to query whether or not a byte from standard input is available or not. This also significantly benefits the performance of multitasking implementations, as KEY is simply:
Some systems also implement EMIT? to see if the output device is capable of receiving data. It's probably a good idea to implement this word too, for similar reasons.
Code: Select all
: KEY BEGIN PAUSE KEY? UNTIL (KEY) ;
; KEY [ -- sb,da:da ] Gets input character.
; sb: Key value.
; da: Key status - true if key availale, false if not.
The status is returned along with a byte if it is available. I did recognize that you could get a 0 from the input stream. I have not implemented round robin but I have implemented zero overhead interrupt support. According to Garth, this method has worked well in his embedded projects. I have enjoyed this feature as well under simulation, but am looking forward to seeing what can be done with actual hardware.
I have also considered the check to see if a write to output is necessary, but for now I believe that since you are writing the "driver" yourself, that retry functionality can be embedded in the driver.
The Electronic Resource Guy
electronicresourceguy wrote:
Actually, I have implemented KEY like this:
Quote:
I have not implemented round robin but I have implemented zero overhead interrupt support. According to Garth, this method has worked well in his embedded projects. I have enjoyed this feature as well under simulation, but am looking forward to seeing what can be done with actual hardware.
Personally, I wouldn't use zero-overhead interrupts because I prefer more control in my code, and I'm willing to pay the price in high-level expressivity. Plus, since I prefer subroutine-threaded Forth implementations over direct-threaded, the distinction between CODE and colon-definition interrupt handlers tends to fade away with only minimal impact on readability anyway.
Speaking of which, I really should complete my Kestrel Forth one of these days. Hehe. Having too much fun trying to solve my HDLC implementation for my optical transceiver project at the moment, though.
-
electronicresourceguy
- Posts: 8
- Joined: 06 Apr 2009
- Location: United States
kc5tja wrote:
It impacts Forth runtime performance, but has the advantage that it makes writing event-driven software in high-level Forth somewhat easier. I think you'll find its expressivity beneficial in real-world applications.
Code: Select all
pNEXT LDY zINT ; Check for interrupt.
BNE pNEXT2 ; Jump if interrupt has occured.
Either way, I have had to make some design choices since my main goal was size over speed. I have also been working on a new NEXT method that will reduce cycles from 40 to about 23. If I can get that to work, I get a lot of performance back. Still should be faster than BasicStamp.
My overall goal was to have something that was very plug and play:
CPU, RAM, ROM, simple address decoding, and the ability to interface to anything and everything. I have some chips that I bought at RadioShack about 20 years ago that I would still like to use, and the basic stamp just didn't cut it. I just wish that I would have found Forth 15 years ago!
The Electronic Resource Guy
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Quote:
Quote:
What has kept me from publishing my own '02 Forth is that there are still a lot of fragments left that one particular company could claim a copyright on.
What would take more time is writing it all out in a form that an assembler, instead of a metacompiler, could use. If I distribute it, it will have to be in a form that can be modified and re-assembled without the overpriced PC-based metacompiler which the company quit selling when I pointed out all the sinkholes (not mere pot holes!) in Forth Dimensions magazine. (I didn't give the name of the company in the article, but it wasn't hard to figure out.) The bugs became more and more severe as my overall code grew to 10,000 lines. (And this wasn't like the FIG source which only has one word per line, either.) Since the metacompiler itself was a black box, I could not get into it and fix it like you can in Forth. I figured out some work-arounds but they were running out of gas and I pretty much decided I'd have to re-write it for an assembler anyway even for my own use.
Quote:
I started with the FIG Forth code that I downloaded from this site. I then re-wrote it about 20 times, making several major changes to the architecture, especially in the data stack. This means that most primitives do not look even remotely close to the original
Quote:
In order to fit into this space, I did have to make some tradeoffs. But you can always define new primitives for performance as needed.
Quote:
Quote:
but I have implemented zero overhead interrupt support.
Quote:
I wouldn't use zero-overhead interrupts because I prefer more control in my code, and I'm willing to pay the price in high-level expressivity.
Quote:
Quote:
I know, I know, if we're going to keep plugging Forth, we really ought to have something a little more turn-key for beginners. That, however, almost means either bundling it with working hardware that we supply, or publishing a version that is for specific hardware that's already available, whether Daryl's SBC-2 with a certain LCD, or something like that. As it stands now, the newbie would have quite an uphill battle to learn a system that he cannot see working yet, in order to make the necessary changes so it will work on his own hardware.
Forth really only has two methods for interfacing to the world, get a character (KEY) and put a character (EMIT).
Quote:
Quote:
Keep hammering on us and someday we might get you a turn-key "starter kit".
Quote:
Still should be faster than BasicStamp.
-
electronicresourceguy
- Posts: 8
- Joined: 06 Apr 2009
- Location: United States
GARTHWILSON wrote:
KEY and EMIT are primarily for human I/O, which is only a minor part of my workbench computer's I/O; and even then, there still needs to be code to take care of the details of how to feed data to the LCD, scan the keypad, bring data in from a UART, etc.. If the newbie doesn't have those written and debugged already, he'll have quite an uphill battle to get it all going. It would be nice if he could start with something that works right out of the box-- plug it in, turn it on, see "Ok { 0 }", and, before he's out of page 1 of the tuturial, be typing in something and seeing results.
The system as it stands works with the Michal Kowalski simulator. This is working as if you already had a working UART connected to a dumb terminal.
To write code to support an actual UART should not be too difficult, I hope. Again, something that I am looking forward to. After that interface is up, you would have a functional interactive development environment to bring up any additional hardware that you connect. It would sort of be a Forth Stamp, allowing connection to just about anything.
The Electronic Resource Guy
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
I really should do a YouTube video of my interactive embedded development. We have a digital camera that can do video, but I guess we'll have to find and learn some video-editing software. I had an article about this interactive embedded delvelopment in FD XVI-1 (May-June '94). Until they see it, people can't comprehend how simple it is to get instant turnaround between writing a piece of code on the PC and actually running it on the target 6502 computer connected by an RS-232 line.
I use the PC for the text editor for the program and to keep the source files on disc; but you could use any computer that has a text editor that allows marking a block in the text and sending it over the serial port to the target (6502) computer. No special software is needed for the PC-- no TSRs, no assembler or compiler (once the Forth is in the target's ROM), no OS or BIOS tricks etc.-- just the text editor. To write a new addition to the code, you just put it in the text editor in the PC, mark it as a block, and "print" the block. The text editor isn't even backgrounded, let alone suspended or exited, even it you were doing it on an old Kaypro computer. (Myself, I usually use DOS on a PC, but I can also use my HP handheld computers with the HPIL-to-RS232 interface adapter.) The target takes it in, and does its own interpretation, compilation, or assembly as appropriate, on the fly. As far as the PC is concerned, the target is just a serial printer. As far as the target is concerned, you just have an RS-232 keyboard and you're a lightning typist who never makes a mistake. As long as there's even a minimal display on the target (I have a 16-character LCD), there's no need for the RS-232 to be bi-directional. Sometimes I've had the target doing something else at the same time while I'm feeding it new instructions from the PC, instructions that change parameters on the other process while it's happening, so I can experiment and tweak things without pausing the operation every time I want to make a change. It's way more interactive than any BASIC I've seen.
I use the PC for the text editor for the program and to keep the source files on disc; but you could use any computer that has a text editor that allows marking a block in the text and sending it over the serial port to the target (6502) computer. No special software is needed for the PC-- no TSRs, no assembler or compiler (once the Forth is in the target's ROM), no OS or BIOS tricks etc.-- just the text editor. To write a new addition to the code, you just put it in the text editor in the PC, mark it as a block, and "print" the block. The text editor isn't even backgrounded, let alone suspended or exited, even it you were doing it on an old Kaypro computer. (Myself, I usually use DOS on a PC, but I can also use my HP handheld computers with the HPIL-to-RS232 interface adapter.) The target takes it in, and does its own interpretation, compilation, or assembly as appropriate, on the fly. As far as the PC is concerned, the target is just a serial printer. As far as the target is concerned, you just have an RS-232 keyboard and you're a lightning typist who never makes a mistake. As long as there's even a minimal display on the target (I have a 16-character LCD), there's no need for the RS-232 to be bi-directional. Sometimes I've had the target doing something else at the same time while I'm feeding it new instructions from the PC, instructions that change parameters on the other process while it's happening, so I can experiment and tweak things without pausing the operation every time I want to make a change. It's way more interactive than any BASIC I've seen.
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Going Forth <Groan>
I'm not at all familiar with Forth, despite it having been around for eons. However, when I get my POC machine scaled up beyond the toy concept and have it to the point where it can chatter with a disk or similar mass storage, I may look at trying out Forth on it.
x86? We ain't got no x86. We don't NEED no stinking x86!
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Quote:
I'm not at all familiar with Forth, despite it having been around for eons. However, when I get my POC machine scaled up beyond the toy concept and have it to the point where it can chatter with a disk or similar mass storage, I may look at trying out Forth on it.
The old standard book for starting Forth is called just that, "Starting Forth," by Leo Brodie who apparently was quite a comedian. It has been out of print for a long time, but there have been various efforts to put it online. One is at http://home.iae.nl/users/mhx/sf.html . Unfortunately the original cartoons have been replaced with ones that aren't as entertaining, and I see they still discuss some rather outdated methods; but you'll still learn plenty. [Edit: Forth, Inc. has it online now with the original cartoons, and with updates for ANS Forth.]
Samuel also posted a link to the follow-up book "Thinking Forth", http://thinking-forth.sourceforge.net/t ... -forth.pdf , but I just tried it and it's not working, at least not at the moment.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?