Is there a non-commercial 6502 Forth cross-compiler for PC?

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
Post Reply
User avatar
pjeaton
Posts: 23
Joined: 23 Feb 2005
Location: Zurich, Switzerland

Is there a non-commercial 6502 Forth cross-compiler for PC?

Post by pjeaton »

Hi All,

Last time I logged on here was 2005 :!: :o

In the same way that Brad R published the excellent 6809 CamelForth with a PC cross-compiler, that runs with F83 (and subsequently with Gforth), does such a thing exist for the 6502 target?

I see that FigForth is out there as an assembly listing and there were several commercial Forths for Vic20/C64 etc. and I believe that MPE have a commercial one for PC, but I"ve never come across anything non-commercial.

I'm quite surprised at this really, not many people nowadays are going to write code interactively on a 6502 target and store it on a local SD card or upload/download it everytime by serial port to a PC. A cross-compiler and EPROM emulator is (well, was in the 90's) surely the way forward?
P*h*i*l*l*i*p EEaattoon in real life
User avatar
pjeaton
Posts: 23
Joined: 23 Feb 2005
Location: Zurich, Switzerland

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by pjeaton »

I just spotted this thread about meta-compiling from not too long ago, I think that's referring to the same thing:
viewtopic.php?f=9&t=4599

It seems that no-one's quite done it yet?
P*h*i*l*l*i*p EEaattoon in real life
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by whartung »

Do you have an application in mind?

Garth has his Forth on his bench top computer (I think). I don't know how he loads the runtime (or if it's in ROM on the board), but he basically does what you said -- simply send the Forth source over the serial line to run it.

Apparently the combination of the serial speed and his Forth program sizes don't make the process slow enough for him to bother with anything else.

F83 does, indeed, have a meta-compiler. It can be ported (as demonstrated by the fact that they have both 8080/Z80 versions and 8086 versions), but as good as the system is (in terms of source availability and other documentation), porting it is not a trivial affair to be sure.

From a hobbyist POV, most folks are happy just writing them from scratch in assembly around here.
User avatar
pjeaton
Posts: 23
Joined: 23 Feb 2005
Location: Zurich, Switzerland

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by pjeaton »

Currently I'm using 6809 CamelForth and cross compiling to a Vectrex games console, the general idea is to make some new games for it eventually. I'm using an EPROM emulator to run on the target and a serial interface for interactive testing. When finished, I can burn the game onto a real EPROM and make a standard cartridge out of it. Additionally, I can run it on a Vectrex emulator with a single step machine code debugger.

If I had an interesting project to do on a 6502 or '816, I'd hope to do it the same way. I guess you could compile on the 6502 machine, send the RAM/ROM content back up the serial port and blow it to a ROM, but that's a bit fiddly.

My Vectrex project happened partly because I knew I could use the 6809 CamelForth cross-compiler!

In the mid 80's, I cut my teeth with assembly on Vic-20 and C64, but it the 90's it was Forth for a living and that's a prerequisite for me now, really.
P*h*i*l*l*i*p EEaattoon in real life
User avatar
GARTHWILSON
Forum Moderator
Posts: 8774
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by GARTHWILSON »

whartung wrote:
Do you have an application in mind?

Garth has his Forth on his bench top computer (I think). I don't know how he loads the runtime (or if it's in ROM on the board), but he basically does what you said -- simply send the Forth source over the serial line to run it.
Yes; you can read about it on my workbench computer page, http://wilsonminesco.com/BenchCPU/ . Go down to the heading, "How it is controlled."
Quote:
Apparently the combination of the serial speed and his Forth program sizes don't make the process slow enough for him to bother with anything else.
Right. Instant compilation like Samuel Falvo (forum name kc5tja) talks about would b nice, but it's not that big a deal. Run speed is more important than load speed. If I'm just sending a few lines over, it's basically instant. If it's lots of pages, I'll have a little thumb-twiddling to do. I started the topic here "dictionary hashing before I realized that what's taking most of the compiling time on my system is not the searching itself but rather a lot of other stuff I should re-write as primitives, and should also do the RS-232 interrupt service in assembly. I give a little more detail in this post.

pjeaton, it's nice to see you back. What you're talking about regarding developing in RAM and then transferring to ROM is what I did for the automated test equipment at work around 1990 on the 65c02-powered Cubit 7540 STD-bus SBC. I guess I ought to post an article about the method on my website. I used a metacompiler to get the initial kernel going so there would be a Forth system in EPROM, then developed new code in RAM, on the target itself. After accumulating some amount of new working code, I'd run it through the metacompiler and put it in the EPROM with the earlier code, and get back to developing more in RAM. One change I had to make of course is the way variables' data is kept. There is a THERE that's separate from HERE, and THERE keeps the next available address for variables' data space which is separate from the variables' headers which go into ROM.
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?
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by BitWise »

I've been playing with a Java based cross-compiler for multiple targets for a while but its not finished. It optimises both at the Forth level and at the generated assembly level. The output is subroutine threaded code. The intermediate representation is designed to be interpretable.

The PIC24 back end turns this:

Code: Select all

hex
0220 constant U1MODE inline
0222 constant U1STA inline
0224 constant U1TXREG inline
0226 constant U1RXREG inline
0228 constant U1BRG inline

0100 constant UTXBF inline
0001 constant URXDA inline 

: emit ( ch -- )
  begin U1STA @ UTXBF and until
  U1TXREG !
;

: key? ( -- flag )
  U1STA @ URXDA and
;

: key ( -- ch )
  begin key? until
  U1RXREG @
;

\ ==============================================================================

: boot
	1 2 + key 5 lshift
; external
Into this

Code: Select all

; Generated code do not change

                .global boot
boot:                                   ; : boot
                mov.w   #3,w0           ; 3
                mov.w   w0,[++w14]
                call    key             ; key
                mov.w   [w14--],w0
                sl.w    w0,#5,[++w14]   ; 5 lshift
                return                  ; ;

lshift:                                 ; code lshift
                mov.w   [w14--],w0 
                mov.w   [w14--],w1 
                sl.w    w1,w0,w0 
                mov.w   w0,[++w14] 
                return                  ; end-code

keyquery_:                              ; : key?
                mov.w   546,w0          ; 546 @
                and.w   w0,#1,[++w14]   ; 1 and
                return                  ; ;

key:                                    ; : key
.L1:
                call    keyquery_       ; key?
                cp0     [w14--]
                bra     z,.L1           ; (?branch)
                mov.w   550,w0          ; 550 @
                mov.w   w0,[++w14]
                return                  ; ;
All of the runtime routines are defined in an include file and only the required ones are actually generated. The comments show where multiple words have been optimised into a single operation (e.g. '550 @' or '1 and'). In keyquery_ the intermediate stack pushes and pulls are removed and w0 is used as the top of stack.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by JimBoyd »

pjeaton wrote:
I just spotted this thread about meta-compiling from not too long ago, I think that's referring to the same thing:
viewtopic.php?f=9&t=4599

It seems that no-one's quite done it yet?
I used a metacompiler to build my Forth but you'll be disappointed. I didn't metacompile it from a PC, I metacompiled it from the Commodore 64. Starting with an existing Forth, I wrote the metacompiler and the source for the new Forth then rewrote the metacompiler to work with the new Forth.
User avatar
pjeaton
Posts: 23
Joined: 23 Feb 2005
Location: Zurich, Switzerland

Re: Is there a non-commercial 6502 Forth cross-compiler for

Post by pjeaton »

Thanks for your thoughts, guys.

So it still looks like there is no freeware Forth cross compilers for 6502 on the PC, but various people are doing their own thing.
P*h*i*l*l*i*p EEaattoon in real life
Post Reply