6502 Subroutine-Threaded Forth

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
Post Reply
kc5tja
Posts: 1706
Joined: 04 Jan 2003

6502 Subroutine-Threaded Forth

Post by kc5tja »

Excellent news!

The 6502 STC Forth that I'm working on now runs, albeit very incomplete, under the Commodore 64 emulator.

A number of basic primitives exist -- I implement primitives only as I need them to write the rest of the Forth environment, so as to minimize the need for debugging while maximizing progress. I even wrote my own version of * which does a 16x16=16 multiplication. Amazingly, it worked the first time. :)

The Forth 'outer interpreter' now works great. I rely on Commodore's kernel for the screen editing capabilities, which makes my text input code utterly trivial. But it's factored enough to let me rewrite the text input code if required. The interpreter itself, however, works like a dream, although it took me a number of days to fix a bug where it would never detect a missing word.

The things that it lacks now include:

* Colon-compiler -- this is the biggest omission. However, implementing this ought not be too terribly difficult now that most of the words it depends on have been written.

* Word names are still not precisely correct -- because I'm using a cross-compiling environment to develop the software, words are written using commas after their names to distinguish host from target compiled words. This system works *great*, doesn't require the use of a Forth with vocabularies. However, inside the target image, those commas all exist inside the word names, so you still have to use commas there too. For example, to exit the Forth environment, you need to type GO64, instead of GO64. :-)

* Because I used commas to distinguish target and host words, there is a conflict between the assembler's AND, instruction and the host Forth word AND,. Therefore, I need to change from the use of commas to the use of ticks (e.g., instead of AND,, I would use AND'). As a temporary work-around, I'm currently using &, to stand for AND,.

* Because of how PETSCII works, I need to capitalize all words in my sources.

* I need to implement loading from blocks, which means I'll also need to implement the generic block I/O words too.

One thing is for sure though -- I should have been writing this with literate programming, as with my Colonel project, so that it could be precisely documented. I think I will spend a few weeks to do that, because once this is finished, I'd like to be able to publish the entire design and its rationales on the web.

The statistics from the latest compilation run is as follows:

Code: Select all

bash-2.05b$ gforth forth.fs
**** Kestrel Forth 1
Cross Compiler Release 1r1

Copyright (c) 2006 Samuel A. Falvo II
All Rights Reserved.

================================================================
Bytes Assembled: 2936 
 Data Stack Low: $87A 
Data Stack High: $8FA 
    Entry Point: $1373 
================================================================
Not too shabby, weighing in at only 3KB, and that's without tail-call optimization, and with inlining of certain primitives (averaging 12 bytes a pop)! My guess, based on these numbers, is that a Forth environment without blocks but with the colon compiler will fall in at just under 5K, and with block I/O support, will probably consume closer to 6K. If I were to include the assembler in the static image, it looks to be about 9K all-together. I can probably shrink it down somewhat by using pure STC instead of inlining certain primitives like pushing constants onto the stack. But I'll see about that only after it becomes a problem for me.
cas
Posts: 27
Joined: 21 May 2003
Location: Germany
Contact:

Post by cas »

Hi kc5tja,

I'm working in the GForth Team to document the GForth EC (Embedded Cross-Compiler). Bernd Paysan has recently added the R8C Target, and I try to get the 6502 and 8086 targets running again.

Did you use the GForth EC Cross-Compiler or your own Cross-Compiler?

If you used the GForth EC, will you publish your sources?

Carsten
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

cas wrote:
Hi kc5tja,

I'm working in the GForth Team to document the GForth EC (Embedded Cross-Compiler). Bernd Paysan has recently added the R8C Target, and I try to get the 6502 and 8086 targets running again.

Did you use the GForth EC Cross-Compiler or your own Cross-Compiler?

If you used the GForth EC, will you publish your sources?

Carsten
I wrote my own target compiler in Linux GForth. I do not have any intention of porting GForth to the 65xx architecture -- it's too heavyweight and absolutely won't fit in 8K of ROM space. It also depends on a C compiler, which I don't have any intention of porting either.
cas
Posts: 27
Joined: 21 May 2003
Location: Germany
Contact:

Post by cas »

kc5tja wrote:
cas wrote:
Hi kc5tja,

I'm working in the GForth Team to document the GForth EC (Embedded Cross-Compiler). Bernd Paysan has recently added the R8C Target, and I try to get the 6502 and 8086 targets running again.

Did you use the GForth EC Cross-Compiler or your own Cross-Compiler?

If you used the GForth EC, will you publish your sources?

Carsten
I wrote my own target compiler in Linux GForth. I do not have any intention of porting GForth to the 65xx architecture -- it's too heavyweight and absolutely won't fit in 8K of ROM space. It also depends on a C compiler, which I don't have any intention of porting either.
There are two flavors of GForth, the full GFOrth (C-Based) and GForth EC for embedded systems. GForth EC is crosscompiled using the full GForth (for ecample on Linux).

There is already a 6502 GForth EC target in the GForth distribution, but it is broken (since GForth 0.5.x). So I wasn't sure if you use the GForth EC sources for your Forth (the compiling messages look very similar to GForth EC).

Best regards

Carsten
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

Can the GForth EC kernel compile itself once it's on the new architecture? If so, I will be more interested in it as a disk-loaded Forth environment.

Thanks.
cas
Posts: 27
Joined: 21 May 2003
Location: Germany
Contact:

Post by cas »

kc5tja wrote:
Can the GForth EC kernel compile itself once it's on the new architecture? If so, I will be more interested in it as a disk-loaded Forth environment.

Thanks.
This should be possibe, I never tried it. The GForth Cross-Compiler is a direct descendant of the VolksForth Cross-Compiler (-> volksforth.sf.net ), and VolksForth can CrossCompile itself on a C=64.

Another project on my desk is to try to cross-compile VolksForth using the GForth Cross Compiler. VolksForth is a more lean than GForth EC.

Best regards

Carsten Strotmann
johnnyblame
Posts: 1
Joined: 04 Nov 2009

Post by johnnyblame »

Hi guys
I need help,I am working on building my own home-brew computer, and I want to base it on the MOS 6510. I noticed on the 6510 data sheet that it is possible to run this chip at 3 MHz, though I've never seen it done at more than 1MHz. Has anyone tried to run it at 3 MHz?
r4
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

johnnyblame, are you the same person as ccureau? This exact post and the discussion that followed are at viewtopic.php?t=73 in the Hardware forum. (Edit: Wow, I just realized most of your answers came six years after you posted!! After all that time you probably forgot you posted, or couldn't find it!) This here is the Forth forum though. Forth is a programming language and environment.
Post Reply