1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-11 08:18:04 +11:00

z80: Use BC as IP register instead of IY

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.
This commit is contained in:
Virgil Dupras 2020-07-06 23:31:00 -04:00
parent a7dcb522c2
commit e4a4a9800d
11 changed files with 28 additions and 32 deletions

View File

@ -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 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\ 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".

View File

@ -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, LDA(BC), E A LDrr, BC INCd,
D 1 IY+ LDrIXY, LDA(BC), D A LDrr, BC INCd,
IY INCd, IY INCd,
( continue to execute ) ( continue to execute )

View File

@ -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, 0 IX+ C LDIXYr,
1 IX+ H 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 )

View File

@ -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, LDA(BC), H 0 LDri, L A LDrr,
7 E BIT, IFNZ, D DECr, THEN, RLA, IFC, H DECr, THEN,
DE ADDIYd, 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

View File

@ -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

View File

@ -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, C 0 IX+ LDrIXY,
H 1 IX+ LDrIXY, B 1 IX+ LDrIXY,
IX DECd, IX DECd, IX DECd, IX DECd,
HL PUSH, IY POP, ( --> IP )
JPNEXT, JPNEXT,

View File

@ -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, LDA(BC), L A LDrr, BC INCd,
D 1 IY+ LDrIXY, LDA(BC), H A LDrr, BC INCd,
IY INCd, IY INCd, HL PUSH,
DE PUSH,
;CODE ;CODE

10
blk/307
View File

@ -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 ) BC PUSH,
E (HL) LDrr, D 0 LDri, LDA(BC), C ADDr,
DE INCd, IFC, B INCr, THEN,
DE ADDIYd, C A LDrr,
HL PUSH, BC INCd,
;CODE ;CODE

View File

@ -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, HL POP, ( C ) DE POP, ( B ) IY POP, ( A ) chkPS,
DE PUSH, ( B ) HL PUSH, ( C ) BC PUSH, ( A ) 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,

View File

@ -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

View File

@ -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