~vdupras/collapseos

6a11add9e947792ebc5c94b5b19fb5bc13181540 — Virgil Dupras 18 days ago 4d26f1c
sms: implement (spix) in z80 asm

Doing SPI bit-banging through a controller port is already really
slow, but doing so with the Forth version of (spix) was really,
really slow.

With this pure z80 version of (spix), it's more bearable.
1 files changed, 13 insertions(+), 9 deletions(-)

M arch/z80/sms/blk.fs
M arch/z80/sms/blk.fs => arch/z80/sms/blk.fs +13 -9
@@ 151,15 151,19 @@ TL. When the '164 is full, TL is low. Port A TL is bit 4 )
	2 _THB! ( TH input ) ;
( ----- 622 )
: (spie) DROP ; ( always enabled )
: (spix) ( x -- x, for port B )
    0 SWAP ( rx tx ) 8 0 DO
        ( send current bit to TRB, TR's output bit )
        DUP 7 I - RSHIFT 1 AND _TRB!
        1 _THB! ( CLK hi )
        ( read into rx ) SWAP 1 LSHIFT _D1@ ( tx rx<< x )
        0 _THB! ( CLK lo )
        ( out bit is the 6th ) 6 RSHIFT 1 AND OR
    SWAP LOOP ( rx tx ) DROP ;
CODE (spix) ( x -- x, for port B ) HL POP, chkPS,
    ( TR = DATA TH = CLK )
    CPORT_MEM LDA(i), 0xf3 ANDi, ( TR/TH output )
    H 8 LDri, BEGIN,
        0xbf ANDi, ( TR lo ) L RL, ( --> C )
        IFC, 0x40 ORi, ( TR hi ) THEN, 0x80 ORi, ( TH hi )
        CPORT_CTL OUTiA, ( clic! )
        EXAFAF', CPORT_D1 INAi, ( Up Btn is B6 ) RLA, RLA,
            E RL, EXAFAF',
        0x7f ANDi, ( TH lo ) CPORT_CTL OUTiA, ( cloc! )
    H DECr, JRNZ, AGAIN, CPORT_MEM LD(i)A,
    L E LDrr, HL PUSH,
;CODE
( ----- 625 )
( Routines for interacting with SMS controller ports.
  Requires CPORT_MEM, CPORT_CTL, CPORT_D1 and CPORT_D2 to be