~vdupras/collapseos

bf4ab0f1b4cae38ad364f327a87d1713ba3d88a8 — Virgil Dupras a month ago a6e987b
z80: protect or avoid BC wherever it's used

For the IY->BC move, of course.
13 files changed, 57 insertions(+), 71 deletions(-)

M blk/310
M blk/319
M blk/320
D blk/321
M blk/324
M blk/329
M blk/334
M blk/335
M blk/493
M blk/494
M blk/495
M blk/496
M blk/497
M blk/310 => blk/310 +3 -3
@@ 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

M blk/319 => blk/319 +12 -12
@@ 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

M blk/320 => blk/320 +11 -12
@@ 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

D blk/321 => blk/321 +0 -15
@@ 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

M blk/324 => blk/324 +4 -4
@@ 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

M blk/329 => blk/329 +5 -5
@@ 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

M blk/334 => blk/334 +5 -4
@@ 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

M blk/335 => blk/335 +5 -4
@@ 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

M blk/493 => blk/493 +4 -4
@@ 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

M blk/494 => blk/494 +2 -2
@@ 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

M blk/495 => blk/495 +2 -2
@@ 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

M blk/496 => blk/496 +2 -2
@@ 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,

M blk/497 => blk/497 +2 -2
@@ 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