6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 01, 2024 12:36 pm

All times are UTC




Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Getting started in Forth
PostPosted: Thu Oct 06, 2011 5:44 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 4:59 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 5:26 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
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.

I've never used FIG-Forth so I had to look it up: it is indeed called U/ in FIG-Forth, whereas Forth-79, Forth-83, and ANS Forth call it UM/MOD.

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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 6:25 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
8BIT wrote:
I took the same code and modified it for the SBC-4P (WDC65816 in native mode) and it will not run.
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)? Also you don't mention what modifications you made to the code. Aside from the switch to Native mode, is there anything else?

8BIT wrote:
There must be something in the indirect references or page wrapping that is causing this.
Perusing the '816 data sheet I notice that Native mode allows a full 16-bit Stack Pointer. Sorry if this is a dumb question, but did you initialize all 16 bits? I think the hi-byte ought to be set to $01, if I understand what it is you're doing, that is. Just trying to help...

I have fond memories of many, MANY fascinating hours spent with FIG Forth, btw! :)

-- Jeff


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 2:30 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
GARTHWILSON wrote:
...it is indeed called U/ in FIG-Forth, whereas Forth-79, Forth-83, and ANS Forth call it UM/MOD.


That might explain also why the data stack byte order might be different as well. I'll check out that book.

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)?
Yes, I thought about that too. All of my other code runs in native mode though and I was hoping to keep it that way. I do keep the registers set to 8 bit vs 16 bit and the stack is initialized to $01ff.

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 2:53 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
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.

Daryl


Top
 Profile  
Reply with quote  
 Post subject: Going Forth
PostPosted: Sat Oct 08, 2011 4:06 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8468
Location: Midwestern USA
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.

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.

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 65C816's emulation mode is not 100 percent 8 bit compatible. Unlike the 65C02, where some opcodes are technically illegal (and act as NOPs of various lengths), the '816 has no illegal opcodes and all of them work in either mode. Also, instructions such as XBA have no 8 bit equivalent. So the emulation mode is just that: emulation, which is not the same as exact equivalency.


Top
 Profile  
Reply with quote  
 Post subject: Re: Going Forth
PostPosted: Sat Oct 08, 2011 4:26 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
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.


I'm loading Fig6502 into RAM and the OS is left intact, so the vectors are all correct. When I first ran Lee's EhBASIC on the SBC-3, I found some stack manipulations were causing problems and another member here pointed out that there was some page wrapping being used. Meaning that an indexed address that results in an offset of over 256 would wrap around to the beginning of that same page on a 65c02, but on the 65816, in native mode, it would advance to the next page. That was the only issue to fixing EhBASIC and am hoping that's all there is with this too.

Daryl


Top
 Profile  
Reply with quote  
 Post subject: Re: Going Forth
PostPosted: Sat Oct 08, 2011 4:34 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8468
Location: Midwestern USA
8BIT wrote:
I'm loading Fig6502 into RAM and the OS is left intact, so the vectors are all correct.

Doesn't Fig6502 do some interrupt processing? I've never looked at the source code.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 4:50 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
This one doesn't, yet. I think you have to add that and any other system tools. The good thing is that you could program those in Forth!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 08, 2011 6:25 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
Quote:
Doesn't Fig6502 do some interrupt processing? I've never looked at the source code.

No. For servicing interrupts in high-level Forth, you need my article at http://6502.org/tutorials/zero_overhead ... rupts.html .

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!

Yes, but when you get the assembler loaded too, you can write Forth primitives (or code definitions), runtimes, and subroutines, and also mix sections of assembly into a secondary (or colon definition) if you want.


Top
 Profile  
Reply with quote  
 Post subject: Re: Going Forth
PostPosted: Sat Oct 08, 2011 7:09 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
BigDumbDinosaur wrote:
The 65C816's emulation mode is not 100 percent 8 bit compatible.
Good to know -- thanks. (I told you I wasn't an expert!! :D )


Top
 Profile  
Reply with quote  
 Post subject: Re: Going Forth
PostPosted: Sat Oct 08, 2011 7:18 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8468
Location: Midwestern USA
Dr Jefyll wrote:
BigDumbDinosaur wrote:
The 65C816's emulation mode is not 100 percent 8 bit compatible.
Good to know -- thanks. (I told you I wasn't an expert!! :D )

I didn't say I was either. :lol:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 09, 2011 3:52 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1745
Location: Sacramento, CA
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Oct 09, 2011 3:57 pm 
Offline
User avatar

Joined: Sun Feb 13, 2005 9:58 am
Posts: 85
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: