~vdupras/collapseos

e4a4a9800ddec8e6b05deab1081947a3047910b8 — Virgil Dupras a month ago a7dcb52
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.
11 files changed, 28 insertions(+), 32 deletions(-)

M blk/280
M blk/286
M blk/289
M blk/297
M blk/298
M blk/305
M blk/306
M blk/307
M blk/308
M blk/328
M blk/603
M blk/280 => blk/280 +2 -2
@@ 4,8 4,8 @@ This assembles the boot binary. It requires the Z80 assembler
(B200) and cross compilation setup (B260). It requires some
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
before "next".


M blk/286 => blk/286 +2 -3
@@ 10,7 10,6 @@ lblnext BSET PC ORG @ 0x1b + ! ( next )
    DE RS_ADDR LDdn,
    DE SUBHLd,
    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 )

M blk/289 => blk/289 +3 -4
@@ 2,13 2,12 @@
( 1. Push current IP to RS
  2. Set new IP to the second atom of the list
  3. Execute the first atom of the list. )
    IY PUSH, HL POP, ( <-- IP )
    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 )
( While we inc, dereference into DE for execute call later. )
    LDDE(HL),
    HL INCd,
    HL PUSH, IY POP, ( --> IP )
    B H LDrr, C L LDrr, ( --> IP )
    JR, lblexec BWR      ( execute-B287 )

M blk/297 => blk/297 +4 -4
@@ 1,9 1,9 @@
CODE (br)
L1 BSET ( used in ?br and loop )
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 (?br)
PC ORG @ 0x41 + ! ( stable ABI JP )


@@ 11,5 11,5 @@ PC ORG @ 0x41 + ! ( stable ABI JP )
    HLZ,
    JRZ, L1 BWR ( br + 1. False, branch )
    ( True, skip next byte and don't branch )
    IY INCd,
    BC INCd,
;CODE

M blk/298 => blk/298 +1 -1
@@ 6,7 6,7 @@ PC ORG @ 0x45 + ! ( stable ABI JP )
    A 1 IX+ LDrIXY, 1 IX- CP(IXY+), JRNZ, L1 BWR ( branch )
    ( don't branch )
    IX DECd, IX DECd, IX DECd, IX DECd,
    IY INCd,
    BC INCd,
;CODE



M blk/305 => blk/305 +2 -3
@@ 5,8 5,7 @@ CODE EXECUTE

CODE EXIT
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,
    HL PUSH, IY POP, ( --> IP )
    JPNEXT,

M blk/306 => blk/306 +3 -4
@@ 3,8 3,7 @@ PC ORG @ 0x25 + ! ( stable ABI JP )
  ( Literal value to push to stack is next to (n) reference
    in the atom list. That is where IP is currently pointing.
    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

M blk/307 => blk/307 +5 -5
@@ 3,9 3,9 @@ PC ORG @ 0x2d + ! ( stable ABI JP )
( Like (n) but instead of being followed by a 2 bytes
  number, it's followed by a string. When called, puts the
  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

M blk/308 => blk/308 +2 -2
@@ 1,6 1,6 @@
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 DUP ( a -- a a )
    HL POP, chkPS,

M blk/328 => blk/328 +2 -2
@@ 1,4 1,4 @@
CODE S=
CODE S= EXX, ( protect BC )
    DE POP, HL POP, chkPS,
    LDA(DE),
    (HL) CPr,


@@ 12,4 12,4 @@ CODE S=
        DJNZ, AGAIN,
    THEN,
    PUSHZ,
;CODE
EXX, ( unprotect BC ) ;CODE

M blk/603 => blk/603 +2 -2
@@ 1,5 1,5 @@
( 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 )
    A L LDrr, D XORr, D A LDrr,
    B 8 LDri,


@@ 11,4 11,4 @@ CODE _crc16  ( c n -- c )
        THEN,
    DJNZ, AGAIN,
    DE PUSH,
;CODE
EXX, ( unprotect BC ) ;CODE