I refactored Ragsdale's 6502 assembler so I could better understand it.
hex
create index
0909 , 1505 , 0115 , 8011 , 8009 , 1d0d , 8019 , 8080 ,
0080 , 1404 , 8014 , 8080 , 8080 , 1c0c , 801c , 2c80 ,
variable mode 2 mode !
: .a 0 mode ! ; : # 1 mode ! ; : mem 2 mode ! ;
( ...other modes... )
: upmode if mode @ 8 and 0= if 8 mode +! then then
1 mode @ f and ?dup if 0 do dup + loop then
over 1+ @ and 0= ;
: m/cpu create c, , does>
dup 1+ @ 80 and if 10 mode +! then over ff00 and
upmode upmode if mem latest id. cr 3 error then
c@ mode c@ index + c@ + c, mode c@ 7 and
if mode c@ f and 7 < if c, else , then then mem ;
1c6e 60 m/cpu adc, 1c6e 20 m/cpu and, 1c6e c0 m/cpu cmp,
1c6e 40 m/cpu eor, 1c6e a0 m/cpu lda, 1c6e 00 m/cpu ora,
( ...other instructions... )
Refactored result of UPMODE and M/CPU:
hex
\ a = m/cpu field addr, ? = optional argument.
: <asm> ( f-) if mem ." asm" cr abort then ;
: opcode, ( a-) c@ mode c@ index + c@ + c, ;
: mset ( u-) mode c@ or mode c! ;
: mmask ( u-u) mode c@ and ;
: mbad ( a-f) 1+ @ 1 f mmask lshift and 0= ;
: upmode ( af-af) if 8 mset then dup mbad ;
: multi ( ?a-) 7 mmask if \ has arg:
over ff00 and upmode upmode <asm>
opcode, 8 mmask if , else c, then
else dup mbad <asm> opcode, then mem ;
: m1/cpu create c, , does> multi ;
: m2/cpu create c, , does> 10 mset multi ;
Thoughts and lessons learned in reply.