I've done it! I've successfully spent about 8 hours writing a full-featured 65816 assembler, in Forth, for Forth. Below's a sample of how it's used. The only things to add onto it are words to save the binary images in Commodore PRG and/or raw-binary format. S-Record or iHex formats ought not be too hard to implement, should the need arise. Source code will be on my website soon.
The assembler is written for use with GForth, but it ought to be
trivially ported to other, even non-ANSI, Forth environments.
Code:
decimal
include 65816.fs
create temp 65536 allot
temp 65536 0 fill
\ Set host base (hbase) so assembler knows what buffer to
\ stuff bytes into. Set target base (tbase) and current location
\ counter (*) so JMP and other absolute addresses are correct.
temp hbase ! 0 tbase ! $1C01 *!
\ clear screen for Commodore 128
*@ CONSTANT SCNCLR ( I need a convenience word for defining labels )
$fc dp, lda, pha,
$fd dp, lda, pha,
0 #b, lda, $fc dp, sta, tay, tax,
4 #b, lda, $fd dp, sta,
32 #b, lda,
begin,
begin,
$fc (),y, sta,
iny,
untileq,
$fd dp, inc,
inx,
4 #b, cpx,
untileq,
pla, $fd dp, sta,
pla, $fc dp, sta,
rts,
temp $1c00 + 256 dump
bye
Are you looking to bring up a 65816 into native mode and launch the FTS/Forth port for it?
Code:
decimal
include 65816.fs
create ROM-image 8192 allot
ROM-image 8192 $42 fill \ fill with WDM opcodes by default
\ Set host base (hbase) so assembler knows what buffer to
\ stuff bytes into. Set target base (tbase) and current location
\ counter (*) so JMP and other absolute addresses are correct.
ROM-image hbase ! $E000 tbase !
\ ...
$FFC0 *!
*@ CONSTANT COLDBOOT
clc, xce, $30 #b, rep,
$01FF #w, lda, tas,
$00FF #w, ldx,
WARMBOOT $, jmp,
$FFE4 *!
CopHandler *,w
BrkHandler *,w
AbtHandler *,w
NmiHandler *,w
0 *,w
IrqHandler *,w
$FFF4 *!
CopHandler *,w
0 *,w
AbtHandler *,w
NmiHandler *,w
COLDBOOT *,w
IrqHandler *,w