W65C816SXB ANS-Forth

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
Post Reply
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

W65C816SXB ANS-Forth

Post by BitWise »

I've been cleaning up my 65C816 forth for the W65C816SXB so that it can be used. Its not perfect yet but the bulk of it does work. All of the code can be found here:

https://github.com/andrew-jacobs/w65c816sxb-forth

This is a direct threaded implementation which executes in native mode with A, X and Y normally set to 16-bits. A is switched to 8-bits for C@, C! and C,. The forth instruction pointer is kept in Y and the dispatch code (TYX,INY,INY,JMP (0,X)) is inlined through out the code by means of the CONTINUE macro. The direct page register is used as the data stack pointer.

I have a version of the project for the W65C265SXB as well and will upload it tomorrow.

Portions of the code have been translated from Brad's Camel forth implementations for the Z80 and 1802.

I'll continue to add documentation and fix bugs as I find them.
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
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: W65C816SXB ANS-Forth

Post by barrym95838 »

Very nice, Andrew! A couple of respectful but off-the-cuff comments:

It looks like you forgot a PLY in CMOVE>.

Your X register seems to be underutilized, and you're doing a lot of TDC ... TCD operations to modify your data stack pointer, which is a very common activity. Have you weighed the possibility of going back to X as a data stack pointer? Or how about using X for IP, and leaving Y as a scratch register for your primitives?

Code: Select all

CONTINUE:
    inx
    inx
    jmp  (-2,x)
If you try X (or even Y) for your data stack pointer, what would TOS-in-A look like?

Code: Select all

PLUS:
    clc
    adc  1,x
    inx
    inx
    CONTINUE
    ...
MINUS:
    eor  #$ffff
    inc  a
    bra  PLUS
If you keep Y as IP:

Code: Select all

CONTINUE:
    iny
    phy
    iny
    rts
... oh, wait, that's not quite correct ... or is it? I still get confused ...

Keep the DTC candle burning brightly, my 65xx brother!

Mike B.
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: W65C816SXB ANS-Forth

Post by scotws »

Really cool! I'm looking forward to reading the code.
Post Reply