It's a bit more inconvenient in terms of register protection (BC is much more generally useful than IY), but it makes tight spots such as next and execute much faster, so I think it's worth it.master
@@ -4,8 +4,8 @@ This assembles the boot binary. It requires the Z80 assembler | |||||
(B200) and cross compilation setup (B260). It requires some | (B200) and cross compilation setup (B260). It requires some | ||||
constants to be set. See B420 for details. | constants to be set. See B420 for details. | ||||
RESERVED REGISTERS: At all times, IX points to RSP TOS and IY | |||||
is IP. SP points to PSP TOS, but you can still use the stack\ | |||||
RESERVED REGISTERS: At all times, IX points to RSP TOS and BC | |||||
is IP. SP points to PSP TOS, but you can still use the stack | |||||
in native code. you just have to make sure you've restored it | in native code. you just have to make sure you've restored it | ||||
before "next". | before "next". | ||||
@@ -10,7 +10,6 @@ lblnext BSET PC ORG @ 0x1b + ! ( next ) | |||||
DE RS_ADDR LDdn, | DE RS_ADDR LDdn, | ||||
DE SUBHLd, | DE SUBHLd, | ||||
JRC, lblofl BWR ( IX < RS_ADDR? abortUnderflow-B285 ) | JRC, lblofl BWR ( IX < RS_ADDR? abortUnderflow-B285 ) | ||||
E 0 IY+ LDrIXY, | |||||
D 1 IY+ LDrIXY, | |||||
IY INCd, IY INCd, | |||||
LDA(BC), E A LDrr, BC INCd, | |||||
LDA(BC), D A LDrr, BC INCd, | |||||
( continue to execute ) | ( continue to execute ) |
@@ -2,13 +2,12 @@ | |||||
( 1. Push current IP to RS | ( 1. Push current IP to RS | ||||
2. Set new IP to the second atom of the list | 2. Set new IP to the second atom of the list | ||||
3. Execute the first atom of the list. ) | 3. Execute the first atom of the list. ) | ||||
IY PUSH, HL POP, ( <-- IP ) | |||||
IX INCd, IX INCd, | IX INCd, IX INCd, | ||||
0 IX+ L LDIXYr, | |||||
1 IX+ H LDIXYr, | |||||
0 IX+ C LDIXYr, | |||||
1 IX+ B LDIXYr, | |||||
EXDEHL, ( HL points to PFA ) | EXDEHL, ( HL points to PFA ) | ||||
( While we inc, dereference into DE for execute call later. ) | ( While we inc, dereference into DE for execute call later. ) | ||||
LDDE(HL), | LDDE(HL), | ||||
HL INCd, | HL INCd, | ||||
HL PUSH, IY POP, ( --> IP ) | |||||
B H LDrr, C L LDrr, ( --> IP ) | |||||
JR, lblexec BWR ( execute-B287 ) | JR, lblexec BWR ( execute-B287 ) |
@@ -1,9 +1,9 @@ | |||||
CODE (br) | CODE (br) | ||||
L1 BSET ( used in ?br and loop ) | L1 BSET ( used in ?br and loop ) | ||||
PC ORG @ 0x3d + ! ( stable ABI JP ) | PC ORG @ 0x3d + ! ( stable ABI JP ) | ||||
E 0 IY+ LDrIXY, D 0 LDri, | |||||
7 E BIT, IFNZ, D DECr, THEN, | |||||
DE ADDIYd, | |||||
LDA(BC), H 0 LDri, L A LDrr, | |||||
RLA, IFC, H DECr, THEN, | |||||
BC ADDHLd, B H LDrr, C L LDrr, | |||||
;CODE | ;CODE | ||||
CODE (?br) | CODE (?br) | ||||
PC ORG @ 0x41 + ! ( stable ABI JP ) | PC ORG @ 0x41 + ! ( stable ABI JP ) | ||||
@@ -11,5 +11,5 @@ PC ORG @ 0x41 + ! ( stable ABI JP ) | |||||
HLZ, | HLZ, | ||||
JRZ, L1 BWR ( br + 1. False, branch ) | JRZ, L1 BWR ( br + 1. False, branch ) | ||||
( True, skip next byte and don't branch ) | ( True, skip next byte and don't branch ) | ||||
IY INCd, | |||||
BC INCd, | |||||
;CODE | ;CODE |
@@ -6,7 +6,7 @@ PC ORG @ 0x45 + ! ( stable ABI JP ) | |||||
A 1 IX+ LDrIXY, 1 IX- CP(IXY+), JRNZ, L1 BWR ( branch ) | A 1 IX+ LDrIXY, 1 IX- CP(IXY+), JRNZ, L1 BWR ( branch ) | ||||
( don't branch ) | ( don't branch ) | ||||
IX DECd, IX DECd, IX DECd, IX DECd, | IX DECd, IX DECd, IX DECd, IX DECd, | ||||
IY INCd, | |||||
BC INCd, | |||||
;CODE | ;CODE | ||||
@@ -5,8 +5,7 @@ CODE EXECUTE | |||||
CODE EXIT | CODE EXIT | ||||
PC ORG @ 0x0d + ! ( stable ABI JP ) | PC ORG @ 0x0d + ! ( stable ABI JP ) | ||||
L 0 IX+ LDrIXY, | |||||
H 1 IX+ LDrIXY, | |||||
C 0 IX+ LDrIXY, | |||||
B 1 IX+ LDrIXY, | |||||
IX DECd, IX DECd, | IX DECd, IX DECd, | ||||
HL PUSH, IY POP, ( --> IP ) | |||||
JPNEXT, | JPNEXT, |
@@ -3,8 +3,7 @@ PC ORG @ 0x25 + ! ( stable ABI JP ) | |||||
( Literal value to push to stack is next to (n) reference | ( Literal value to push to stack is next to (n) reference | ||||
in the atom list. That is where IP is currently pointing. | in the atom list. That is where IP is currently pointing. | ||||
Read, push, then advance IP. ) | Read, push, then advance IP. ) | ||||
E 0 IY+ LDrIXY, | |||||
D 1 IY+ LDrIXY, | |||||
IY INCd, IY INCd, | |||||
DE PUSH, | |||||
LDA(BC), L A LDrr, BC INCd, | |||||
LDA(BC), H A LDrr, BC INCd, | |||||
HL PUSH, | |||||
;CODE | ;CODE |
@@ -3,9 +3,9 @@ PC ORG @ 0x2d + ! ( stable ABI JP ) | |||||
( Like (n) but instead of being followed by a 2 bytes | ( Like (n) but instead of being followed by a 2 bytes | ||||
number, it's followed by a string. When called, puts the | number, it's followed by a string. When called, puts the | ||||
string's address on PS ) | string's address on PS ) | ||||
IY PUSH, HL POP, ( <-- IP ) | |||||
E (HL) LDrr, D 0 LDri, | |||||
DE INCd, | |||||
DE ADDIYd, | |||||
HL PUSH, | |||||
BC PUSH, | |||||
LDA(BC), C ADDr, | |||||
IFC, B INCr, THEN, | |||||
C A LDrr, | |||||
BC INCd, | |||||
;CODE | ;CODE |
@@ -1,6 +1,6 @@ | |||||
CODE ROT ( a b c -- b c a ) | CODE ROT ( a b c -- b c a ) | ||||
HL POP, ( C ) DE POP, ( B ) BC POP, ( A ) chkPS, | |||||
DE PUSH, ( B ) HL PUSH, ( C ) BC PUSH, ( A ) | |||||
HL POP, ( C ) DE POP, ( B ) IY POP, ( A ) chkPS, | |||||
DE PUSH, ( B ) HL PUSH, ( C ) IY PUSH, ( A ) | |||||
;CODE | ;CODE | ||||
CODE DUP ( a -- a a ) | CODE DUP ( a -- a a ) | ||||
HL POP, chkPS, | HL POP, chkPS, | ||||
@@ -1,4 +1,4 @@ | |||||
CODE S= | |||||
CODE S= EXX, ( protect BC ) | |||||
DE POP, HL POP, chkPS, | DE POP, HL POP, chkPS, | ||||
LDA(DE), | LDA(DE), | ||||
(HL) CPr, | (HL) CPr, | ||||
@@ -12,4 +12,4 @@ CODE S= | |||||
DJNZ, AGAIN, | DJNZ, AGAIN, | ||||
THEN, | THEN, | ||||
PUSHZ, | PUSHZ, | ||||
;CODE | |||||
EXX, ( unprotect BC ) ;CODE |
@@ -1,5 +1,5 @@ | |||||
( Computes n into crc c with polynomial 0x1021 ) | ( Computes n into crc c with polynomial 0x1021 ) | ||||
CODE _crc16 ( c n -- c ) | |||||
CODE _crc16 ( c n -- c ) EXX, ( protect BC ) | |||||
HL POP, ( n ) DE POP, ( c ) | HL POP, ( n ) DE POP, ( c ) | ||||
A L LDrr, D XORr, D A LDrr, | A L LDrr, D XORr, D A LDrr, | ||||
B 8 LDri, | B 8 LDri, | ||||
@@ -11,4 +11,4 @@ CODE _crc16 ( c n -- c ) | |||||
THEN, | THEN, | ||||
DJNZ, AGAIN, | DJNZ, AGAIN, | ||||
DE PUSH, | DE PUSH, | ||||
;CODE | |||||
EXX, ( unprotect BC ) ;CODE |