1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 04:38:05 +11:00

z80: protect or avoid BC wherever it's used

For the IY->BC move, of course.
This commit is contained in:
Virgil Dupras 2020-07-05 23:12:17 -04:00
parent a6e987b5f7
commit bf4ab0f1b4
13 changed files with 57 additions and 71 deletions

View File

@ -1,4 +1,4 @@
CODE PICK
CODE PICK EXX, ( protect BC )
HL POP,
( x2 )
L SLA, H RL,
@ -10,6 +10,6 @@ CODE PICK
EXDEHL,
HL PS_ADDR LDdn,
DE SUBHLd,
CC lblofl @ JPc, ( abortUnderflow-B298 )
IFC, EXX, lblofl @ JP, THEN,
BC PUSH,
;CODE
EXX, ( unprotect BC ) ;CODE

24
blk/319
View File

@ -1,16 +1,16 @@
CODE * ( DE * BC -> DE (high) and HL (low) )
CODE * EXX, ( protect BC )
( DE * BC -> DE (high) and HL (low) )
DE POP, BC POP, chkPS,
HL 0 LDdn,
A 0x10 LDri,
( loop )
HL ADDHLd,
E RL, D RL,
JRNC, 4 A, ( noinc )
BC ADDHLd,
JRNC, 1 A, ( noinc )
DE INCd,
( noinc )
A DECr,
JRNZ, -14 A, ( loop )
BEGIN,
HL ADDHLd,
E RL, D RL,
IFC,
BC ADDHLd,
IFC, DE INCd, THEN,
THEN,
A DECr,
JRNZ, AGAIN,
HL PUSH,
;CODE
EXX, ( unprotect BC ) ;CODE

23
blk/320
View File

@ -1,16 +1,15 @@
( Borrowed from http://wikiti.brandonw.net/ )
( Divides AC by DE and places the quotient in AC and the
remainder in HL )
CODE /MOD
DE POP,
BC POP,
chkPS,
A B LDrr,
B 16 LDri,
CODE /MOD EXX, ( protect BC )
DE POP, BC POP, chkPS,
A B LDrr, B 16 LDri,
HL 0 LDdn,
( cont. )
BEGIN,
SCF, C RL, RLA,
HL ADCHLd, DE SBCHLd,
IFC, DE ADDHLd, C DECr, THEN,
DJNZ, AGAIN,
B A LDrr,
HL PUSH, BC PUSH,
EXX, ( unprotect BC ) ;CODE

15
blk/321
View File

@ -1,15 +0,0 @@
BEGIN, ( loop )
SCF,
C RL,
RLA,
HL ADCHLd,
DE SBCHLd,
IFC,
DE ADDHLd,
C DECr,
THEN,
DJNZ, AGAIN, ( loop )
B A LDrr,
HL PUSH,
BC PUSH,
;CODE

View File

@ -1,13 +1,13 @@
CODE PC!
CODE PC! EXX, ( protect BC )
BC POP,
HL POP,
L OUT(C)r,
;CODE
EXX, ( unprotect BC ) ;CODE
CODE PC@
CODE PC@ EXX, ( protect BC )
BC POP,
chkPS,
H 0 LDri,
L INr(C),
HL PUSH,
;CODE
EXX, ( unprotect BC ) ;CODE

10
blk/329
View File

@ -3,13 +3,13 @@ CODE CMP
DE POP,
chkPS,
DE SUBHLd,
BC 0 LDdn,
DE 0 LDdn,
IFNZ, ( < or > )
BC INCd,
DE INCd,
IFNC, ( < )
BC DECd,
BC DECd,
DE DECd,
DE DECd,
THEN,
THEN,
BC PUSH,
DE PUSH,
;CODE

View File

@ -1,12 +1,13 @@
CODE RSHIFT ( n u -- n )
BC POP, ( u )
DE POP, ( u )
HL POP, ( n )
chkPS,
B C LDrr,
B INCr, B DECr, IFNZ,
A E LDrr,
A ORr, IFNZ,
BEGIN,
H SRL, L RR,
DJNZ, AGAIN,
A DECr,
JRNZ, AGAIN,
THEN,
HL PUSH,
;CODE

View File

@ -1,12 +1,13 @@
CODE LSHIFT ( n u -- n )
BC POP, ( u )
DE POP, ( u )
HL POP, ( n )
chkPS,
B C LDrr,
B INCr, B DECr, IFNZ,
A E LDrr,
A ORr, IFNZ,
BEGIN,
L SLA, H RL,
DJNZ, AGAIN,
A DECr,
JRNZ, AGAIN,
THEN,
HL PUSH,
;CODE

View File

@ -3,14 +3,14 @@ CODE (key)
0x28 RST,
PUSHA,
;CODE
CODE (emit)
CODE (emit) EXX, ( protect BC )
BC POP, ( c == @DSP arg ) chkPS,
A 0x02 LDri, ( @DSP )
0x28 RST,
;CODE
CODE AT-XY
EXX, ( unprotect BC ) ;CODE
CODE AT-XY EXX, ( protect BC )
DE POP, H E LDrr, ( Y )
DE POP, L E LDrr, ( X ) chkPS,
A 0x0f LDri, ( @VDCTL ) B 3 LDri, ( setcur )
0x28 RST,
;CODE
EXX, ( unprotect BC ) ;CODE

View File

@ -3,10 +3,10 @@ CODE BYE
HL 0 LDdn,
A 0x16 LDri, ( @EXIT )
0x28 RST,
CODE @DCSTAT ( drv -- f )
CODE @DCSTAT ( drv -- f ) EXX, ( protect BC )
BC POP,
chkPS,
A 0x28 LDri, ( @DCSTAT )
0x28 RST,
PUSHZ,
;CODE
EXX, ( unprotect BC ) ;CODE

View File

@ -1,4 +1,4 @@
CODE @RDSEC ( drv cylsec addr -- f )
CODE @RDSEC ( drv cylsec addr -- f ) EXX, ( protect BC )
HL POP,
DE POP,
BC POP,
@ -6,4 +6,4 @@ CODE @RDSEC ( drv cylsec addr -- f )
A 0x31 LDri, ( @RDSEC )
0x28 RST,
PUSHZ,
;CODE
EXX, ( unprotect BC ) ;CODE

View File

@ -1,4 +1,4 @@
CODE @WRSEC ( drv cylsec addr -- f )
CODE @WRSEC ( drv cylsec addr -- f ) EXX, ( protect BC )
HL POP,
DE POP,
BC POP,
@ -6,7 +6,7 @@ CODE @WRSEC ( drv cylsec addr -- f )
A 0x35 LDri, ( @WRSEC )
0x28 RST,
PUSHZ,
;CODE
EXX, ( unprotect BC ) ;CODE
CODE @GET ( a -- c f )
DE POP,
chkPS,

View File

@ -1,8 +1,8 @@
CODE @PUT ( c a -- f )
CODE @PUT ( c a -- f ) EXX, ( protect BC )
DE POP,
BC POP,
chkPS,
A 0x04 LDri, ( @PUT )
0x28 RST,
PUSHZ,
;CODE
EXX, ( unprotect BC ) ;CODE