2020-03-21 21:23:13 -04:00
|
|
|
( Z80 assembler )
|
|
|
|
|
|
|
|
( Splits word into msb/lsb, lsb being on TOS )
|
|
|
|
: SPLITB
|
|
|
|
DUP 0x100 /
|
|
|
|
SWAP 0xff AND
|
|
|
|
;
|
|
|
|
|
2020-03-22 12:08:50 -04:00
|
|
|
( To debug, change C, to .X )
|
|
|
|
: A, C, ;
|
2020-03-21 21:23:13 -04:00
|
|
|
7 CONSTANT A
|
|
|
|
0 CONSTANT B
|
|
|
|
1 CONSTANT C
|
|
|
|
2 CONSTANT D
|
|
|
|
3 CONSTANT E
|
|
|
|
4 CONSTANT H
|
|
|
|
5 CONSTANT L
|
|
|
|
6 CONSTANT (HL)
|
|
|
|
0 CONSTANT BC
|
|
|
|
1 CONSTANT DE
|
|
|
|
2 CONSTANT HL
|
|
|
|
3 CONSTANT AF
|
|
|
|
3 CONSTANT SP
|
|
|
|
|
2020-03-24 14:44:10 -04:00
|
|
|
( As a general rule, IX and IY are equivalent to spitting an
|
|
|
|
extra 0xdd / 0xfd and then spit the equivalent of HL )
|
|
|
|
: IX 0xdd A, HL ;
|
|
|
|
: IY 0xfd A, HL ;
|
2020-03-26 14:11:22 -04:00
|
|
|
: _ix+- 0xff AND 0xdd A, (HL) ;
|
|
|
|
: _iy+- 0xff AND 0xfd A, (HL) ;
|
|
|
|
: IX+ _ix+- ;
|
|
|
|
: IX- 0 -^ _ix+- ;
|
|
|
|
: IY+ _iy+- ;
|
|
|
|
: IY- 0 -^ _iy+- ;
|
2020-03-24 14:44:10 -04:00
|
|
|
|
2020-03-21 21:23:13 -04:00
|
|
|
( -- )
|
|
|
|
: OP1 CREATE C, DOES> C@ A, ;
|
|
|
|
0x76 OP1 HALT,
|
2020-03-25 22:51:23 -04:00
|
|
|
0xc9 OP1 RET,
|
|
|
|
0x17 OP1 RLA,
|
|
|
|
0x07 OP1 RLCA,
|
|
|
|
0x1f OP1 RRA,
|
|
|
|
0x0f OP1 RRCA,
|
|
|
|
0x37 OP1 SCF,
|
2020-03-21 21:23:13 -04:00
|
|
|
|
|
|
|
( r -- )
|
|
|
|
: OP1r
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ ( r op )
|
|
|
|
SWAP ( op r )
|
|
|
|
8 * ( op r<<3 )
|
|
|
|
OR A,
|
|
|
|
;
|
|
|
|
0x04 OP1r INCr,
|
2020-03-25 22:51:23 -04:00
|
|
|
0x05 OP1r DECr,
|
2020-03-21 21:23:13 -04:00
|
|
|
0x46 OP1r LDr(HL),
|
|
|
|
|
2020-03-24 22:09:52 -04:00
|
|
|
( r -- )
|
|
|
|
: OP1r0
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ ( r op )
|
|
|
|
OR A,
|
|
|
|
;
|
2020-03-25 17:52:51 -04:00
|
|
|
0x70 OP1r0 LD(HL)r,
|
2020-03-24 22:09:52 -04:00
|
|
|
0xa0 OP1r0 ANDr,
|
2020-03-25 17:18:29 -04:00
|
|
|
0xb0 OP1r0 ORr,
|
2020-03-25 17:24:46 -04:00
|
|
|
0xa8 OP1r0 XORr,
|
2020-03-26 12:05:48 -04:00
|
|
|
0xb8 OP1r0 CPr,
|
2020-03-24 22:09:52 -04:00
|
|
|
|
2020-03-21 21:23:13 -04:00
|
|
|
( qq -- also works for ss )
|
|
|
|
: OP1qq
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ ( qq op )
|
|
|
|
SWAP ( op qq )
|
|
|
|
16 * ( op qq<<4 )
|
|
|
|
OR A,
|
|
|
|
;
|
|
|
|
0xc5 OP1qq PUSHqq,
|
|
|
|
0xc1 OP1qq POPqq,
|
|
|
|
0x03 OP1qq INCss,
|
2020-03-25 22:51:23 -04:00
|
|
|
0x09 OP1qq ADDHLss,
|
2020-03-21 21:23:13 -04:00
|
|
|
|
2020-03-26 14:11:22 -04:00
|
|
|
: _1rr
|
2020-03-21 21:23:13 -04:00
|
|
|
C@ ( rd rr op )
|
|
|
|
ROT ( rr op rd )
|
|
|
|
8 * ( rr op rd<<3 )
|
|
|
|
OR OR A,
|
|
|
|
;
|
2020-03-26 14:11:22 -04:00
|
|
|
|
|
|
|
( rd rr )
|
|
|
|
: OP1rr
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
_1rr
|
|
|
|
;
|
2020-03-21 21:23:13 -04:00
|
|
|
0x40 OP1rr LDrr,
|
|
|
|
|
2020-03-26 14:11:22 -04:00
|
|
|
( ixy+- HL rd )
|
|
|
|
: LDIXYr,
|
|
|
|
( dd/fd has already been spit )
|
|
|
|
LDrr, ( ixy+- )
|
|
|
|
A,
|
|
|
|
;
|
|
|
|
|
|
|
|
( rd ixy+- HL )
|
|
|
|
: LDrIXY,
|
|
|
|
ROT ( ixy+- HL rd )
|
|
|
|
SWAP ( ixy+- rd HL )
|
|
|
|
LDIXYr,
|
|
|
|
;
|
|
|
|
|
2020-03-21 21:23:13 -04:00
|
|
|
( n -- )
|
|
|
|
: OP2n
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ A, A,
|
|
|
|
;
|
2020-03-26 12:05:48 -04:00
|
|
|
0xd3 OP2n OUTnA,
|
2020-03-21 21:23:13 -04:00
|
|
|
0xdb OP2n INAn,
|
|
|
|
|
|
|
|
( r n -- )
|
|
|
|
: OP2rn
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ ( r n op )
|
|
|
|
ROT ( n op r )
|
|
|
|
8 * ( n op r<<3 )
|
|
|
|
OR A, A,
|
|
|
|
;
|
|
|
|
0x06 OP2rn LDrn,
|
|
|
|
|
|
|
|
( b r -- )
|
|
|
|
: OP2br
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
0xcb A,
|
|
|
|
C@ ( b r op )
|
|
|
|
ROT ( r op b )
|
|
|
|
8 * ( r op b<<3 )
|
2020-03-25 17:07:15 -04:00
|
|
|
OR OR A,
|
2020-03-21 21:23:13 -04:00
|
|
|
;
|
|
|
|
0xc0 OP2br SETbr,
|
|
|
|
0x80 OP2br RESbr,
|
|
|
|
0x40 OP2br BITbr,
|
|
|
|
|
2020-03-25 22:51:23 -04:00
|
|
|
( bitwise rotation ops have a similar sig )
|
|
|
|
( r -- )
|
|
|
|
: OProt
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
0xcb A,
|
|
|
|
C@ ( r op )
|
|
|
|
OR A,
|
|
|
|
;
|
|
|
|
0x10 OProt RLr,
|
|
|
|
0x00 OProt RLCr,
|
|
|
|
0x18 OProt RRr,
|
|
|
|
0x08 OProt RRCr,
|
|
|
|
0x20 OProt SLAr,
|
|
|
|
0x38 OProt SRLr,
|
|
|
|
|
2020-03-25 17:07:15 -04:00
|
|
|
( cell contains both bytes. MSB is spit as-is, LSB is ORed with r )
|
|
|
|
( r -- )
|
|
|
|
: OP2r
|
|
|
|
CREATE ,
|
|
|
|
DOES>
|
|
|
|
@ 256 /MOD ( r lsb msb )
|
|
|
|
A, ( r lsb )
|
|
|
|
SWAP 8 * ( lsb r<<3 )
|
|
|
|
OR A,
|
|
|
|
;
|
|
|
|
0xed41 OP2r OUT(C)r,
|
2020-03-25 17:13:10 -04:00
|
|
|
0xed40 OP2r INr(C),
|
2020-03-25 17:07:15 -04:00
|
|
|
|
2020-03-25 22:51:23 -04:00
|
|
|
( ss -- )
|
|
|
|
: OP2ss
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
0xed A,
|
|
|
|
C@ SWAP ( op ss )
|
|
|
|
16 * ( op ss<< 4 )
|
|
|
|
OR A,
|
|
|
|
;
|
|
|
|
0x4a OP2ss ADCHLss,
|
|
|
|
0x42 OP2ss SBCHLss,
|
|
|
|
|
2020-03-21 21:23:13 -04:00
|
|
|
( dd nn -- )
|
|
|
|
: OP3ddnn
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ ( dd nn op )
|
|
|
|
ROT ( nn op dd )
|
|
|
|
16 * ( nn op dd<<4 )
|
|
|
|
OR A,
|
|
|
|
SPLITB A, A,
|
|
|
|
;
|
2020-03-25 22:51:23 -04:00
|
|
|
0x01 OP3ddnn LDddnn,
|
2020-03-21 21:23:13 -04:00
|
|
|
|
|
|
|
( nn -- )
|
|
|
|
: OP3nn
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ A,
|
|
|
|
SPLITB A, A,
|
|
|
|
;
|
|
|
|
0xcd OP3nn CALLnn,
|
|
|
|
0xc3 OP3nn JPnn,
|
|
|
|
|
2020-03-25 22:51:23 -04:00
|
|
|
: OPJR
|
|
|
|
CREATE C,
|
|
|
|
DOES>
|
|
|
|
C@ A, 2 - A,
|
|
|
|
;
|
|
|
|
0x18 OPJR JRe,
|
|
|
|
0x38 OPJR JRCe,
|
|
|
|
0x30 OPJR JRNCe,
|
|
|
|
0x28 OPJR JRZe,
|
|
|
|
0x20 OPJR JRNZe,
|
|
|
|
0x10 OPJR DJNZe,
|
|
|
|
|
2020-03-21 21:23:13 -04:00
|
|
|
( Specials )
|
2020-03-27 15:25:20 -04:00
|
|
|
: JPNEXT, [ ROUTINE N LITN ] JPnn, ;
|
2020-03-24 13:46:05 -04:00
|
|
|
|
|
|
|
: CODE
|
|
|
|
( same as CREATE, but with ROUTINE V )
|
|
|
|
(entry)
|
2020-03-27 15:25:20 -04:00
|
|
|
[ ROUTINE V LITN ] ,
|
2020-03-24 13:46:05 -04:00
|
|
|
;
|
|
|
|
|
|
|
|
: ;CODE JPNEXT, ;
|
|
|
|
|
2020-03-24 22:09:52 -04:00
|
|
|
|
|
|
|
( Routines )
|
2020-03-27 15:25:20 -04:00
|
|
|
: chkPS, [ ROUTINE P LITN ] CALLnn, ;
|