Getting started in Forth
Getting started in Forth
I decided to take the plunge and explore Forth. I wanted to use a 6502-based Forth so I chose the FIG6502 source from the source code repository as my starting point.
In order to get it working quick, I decided to use the Kowalski IDE as my "platform". I built a quick wrapper for the FIG6502 source that handles the reset/IRQ/NMI vectors and provided the terminal interface code - XKEY (wait for key), XEMIT (output character), and XCR (output cr & lf).
I still need to do the XQTER (test for break key) code and provide support for the R/W command, but I was able to get the FIG6502 code running in short order.
Assembling the wrapper, running the debugger, and pressing the RST symbol brings up the terminal with the "fig-FORTH 1.0" banner.
Entering "2 4 + ." returns "6 OK" as expected.
Next is to fix the bugs Garth has mentioned.
I have a copy of the FigFORTH Installation Manual and plan to test each of the words in the glossary to get a good understanding of how each works.
From there, I'll find some simple code examples to experiment with.
If anyone is interested in getting these files to play with, PM be with your email address and I'll forward what I have.
Daryl
In order to get it working quick, I decided to use the Kowalski IDE as my "platform". I built a quick wrapper for the FIG6502 source that handles the reset/IRQ/NMI vectors and provided the terminal interface code - XKEY (wait for key), XEMIT (output character), and XCR (output cr & lf).
I still need to do the XQTER (test for break key) code and provide support for the R/W command, but I was able to get the FIG6502 code running in short order.
Assembling the wrapper, running the debugger, and pressing the RST symbol brings up the terminal with the "fig-FORTH 1.0" banner.
Entering "2 4 + ." returns "6 OK" as expected.
Next is to fix the bugs Garth has mentioned.
I have a copy of the FigFORTH Installation Manual and plan to test each of the words in the glossary to get a good understanding of how each works.
From there, I'll find some simple code examples to experiment with.
If anyone is interested in getting these files to play with, PM be with your email address and I'll forward what I have.
Daryl
Here's an update:
I took the code that runs on the Kowalski platform and changed just the three IO vectors, and ran on my SBC-2 (WDC65C02).
I took the same code and modified it for the SBC-4P (WDC65816 in native mode) and it will not run. I get a long burst of garbage to the terminal then it hangs. The D reg is pointing to page 0 and all registers are set for 8 bit. There must be something in the indirect references or page wrapping that is causing this. I will try on my SBC-3 (65816 native mode) next.
In the mean time, it does not appear that my version of Fig6502 has the UM/MOD word. I can only find the U/ word that has the same code as Garth describes in his fix article. When I replaced that code, it failed. I think the byte order is different but have not dug into that yet.
I have played with a few more words, but have a long way to go yet.
Daryl
I took the code that runs on the Kowalski platform and changed just the three IO vectors, and ran on my SBC-2 (WDC65C02).
I took the same code and modified it for the SBC-4P (WDC65816 in native mode) and it will not run. I get a long burst of garbage to the terminal then it hangs. The D reg is pointing to page 0 and all registers are set for 8 bit. There must be something in the indirect references or page wrapping that is causing this. I will try on my SBC-3 (65816 native mode) next.
In the mean time, it does not appear that my version of Fig6502 has the UM/MOD word. I can only find the U/ word that has the same code as Garth describes in his fix article. When I replaced that code, it failed. I think the byte order is different but have not dug into that yet.
I have played with a few more words, but have a long way to go yet.
Daryl
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Quote:
In the mean time, it does not appear that my version of Fig6502 has the UM/MOD word. I can only find the U/ word that has the same code as Garth describes in his fix article.
Again, one of the best books for getting started in Forth is Leo Brodie's humorous book "Starting Forth" which you can read online, free, at http://www.forth.com/starting-forth/index.html . The differences between versions (like the U/ and UM/MOD above) are few, and this book does cover them.
8BIT wrote:
I took the same code and modified it for the SBC-4P (WDC65816 in native mode) and it will not run.
8BIT wrote:
There must be something in the indirect references or page wrapping that is causing this.
I have fond memories of many, MANY fascinating hours spent with FIG Forth, btw!
-- Jeff
GARTHWILSON wrote:
...it is indeed called U/ in FIG-Forth, whereas Forth-79, Forth-83, and ANS Forth call it UM/MOD.
Dr Jefyll wrote:
I'm no expert on the '816, but wouldn't the first and most basic test be to attempt running in Emulation mode (utterly 8-bit, backward compatible)?
The only changes to the code are the IO vector assignments and the removal of the test functions.
I think that there must be some page wrap functions that do work on a 65c02, might work on a 65816 in emulation mode, but the 65816 in native mode advances to the next page. I had some issues with Lee's EhBASIC doing that too.
I hope to find time today to work on it more.
Thanks all
Daryl
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Going Forth
8BIT wrote:
Just tested emulation mode and it works so there has to be some page wrapping or stack wrapping going on - just need to find it.
Dr Jefyll wrote:
I'm no expert on the '816, but wouldn't the first and most basic test be to attempt running in Emulation mode (utterly 8-bit, backward compatible)?
Re: Going Forth
BigDumbDinosaur wrote:
When the '816 is in native mode, the hardware vectors (IRQ and NMI) are in different locations, and BRK and IRQ are separately vectored. That could that be part of the problem.
Daryl
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Going Forth
8BIT wrote:
I'm loading Fig6502 into RAM and the OS is left intact, so the vectors are all correct.
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Quote:
Doesn't Fig6502 do some interrupt processing? I've never looked at the source code.
There are no limits on assembly-language interrupt service of course, and the Forth doesn't even have to be aware that you're doing it.
Quote:
The good thing is that you could program those in Forth!
Re: Going Forth
BigDumbDinosaur wrote:
The 65C816's emulation mode is not 100 percent 8 bit compatible.
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Going Forth
Dr Jefyll wrote:
BigDumbDinosaur wrote:
The 65C816's emulation mode is not 100 percent 8 bit compatible.
Garth, thanks again for pointing out that book. I have worked through to chapter 3 and am finding it very helpful.
Also, your UM/MOD fix works just fine. I was trying to enter a double number by just typing it in. I found that it only loaded the upper 16 bits onto the data stack, not the entire 32 bits. After switching to HEX mode and entering two dividend words and one divisor, the code worked just as you described. (original's bugs and modified code's correct results)
Now, on to other bug fixes and Chapter 3. That deals with disk I/O so I need to fix up those routines too.
For now, I am running Fig6502 in emulation mode on SBC-4. I still plan to investigate the native mode issues.
Daryl
Also, your UM/MOD fix works just fine. I was trying to enter a double number by just typing it in. I found that it only loaded the upper 16 bits onto the data stack, not the entire 32 bits. After switching to HEX mode and entering two dividend words and one divisor, the code worked just as you described. (original's bugs and modified code's correct results)
Now, on to other bug fixes and Chapter 3. That deals with disk I/O so I need to fix up those routines too.
For now, I am running Fig6502 in emulation mode on SBC-4. I still plan to investigate the native mode issues.
Daryl
if it can help, i've also a well commented source by hand, i can scan and put online.
meanwhile here you can find a working original code
http://ptorric.tsc4.com/index.php/proje ... forth.html
meanwhile here you can find a working original code
http://ptorric.tsc4.com/index.php/proje ... forth.html