diff --git a/blk/580 b/blk/580 index b1b7b7f..3b21188 100644 --- a/blk/580 +++ b/blk/580 @@ -4,4 +4,5 @@ Support code for the RC2014 recipe. Contains drivers for the ACIA, SD card and AT28 EEPROM. 581 ACIA 590 AT28 EEPROM -600 SD card 618 Xcomp unit +595 SPI relay 600 SD card +618 Xcomp unit diff --git a/blk/595 b/blk/595 new file mode 100644 index 0000000..93f8d18 --- /dev/null +++ b/blk/595 @@ -0,0 +1,12 @@ +SPI relay driver + +This driver is designed for a ad-hoc adapter card that acts as a +SPI relay between the z80 bus and the SPI device. Sending any- +thing on SPI_CSLOW and SPI_CSHIGH is expected to select/deselect +the device, and writing to SPI_DATA is expected to initiate a +byte exchange. The result of the exchange is excpected to be re- +trieved by reading SPI_DATA. + +Provides (spie) (enable), (spid) (disable), (spix) (xchange). + +Load driver with "596 LOAD". diff --git a/blk/596 b/blk/596 new file mode 100644 index 0000000..2fd9846 --- /dev/null +++ b/blk/596 @@ -0,0 +1,12 @@ +CODE (spix) ( n -- n ) + HL POP, + chkPS, + A L LDrr, + SPI_DATA OUTiA, + NOP, NOP, ( let SPI relay breathe ) + SPI_DATA INAi, + L A LDrr, + HL PUSH, +;CODE +CODE (spie) SPI_CSLOW OUTiA, ;CODE +CODE (spid) SPI_CSHIGH OUTiA, ;CODE diff --git a/blk/600 b/blk/600 index 2d7374c..511e952 100644 --- a/blk/600 +++ b/blk/600 @@ -1,13 +1,11 @@ SD Card driver -Load range: 602-616 +Load range: 603-616 This driver is designed for a ad-hoc adapter card that acts as a -SPI relay between the z80 bus and the SD card. That adapter is -expected to pull CS low when something is written to SDC_CSLOW, -high on SDC_CSHIGH and to initiate a SPI exchange when a byte is -written to SDC_SPI, the result of that exchange being fetched -with a read to SDC_SPI. +SPI relay between the z80 bus and the SD card. It requires a SPI +driver providing (spix), (spie) and (spid), which oh surprise! +is included in Collapse OS at B595. -Through that layer, this driver implements the SDC protocol +Through that layer, this driver implements the SDC protocol allowing it to provide BLK@ and BLK!. diff --git a/blk/602 b/blk/602 deleted file mode 100644 index 7fa35a9..0000000 --- a/blk/602 +++ /dev/null @@ -1,12 +0,0 @@ -( Initiate SPI exchange with the SD card. n is the data to - send. ) -CODE _sdcSR ( n -- n ) - HL POP, - chkPS, - A L LDrr, - SDC_SPI OUTiA, - NOP, NOP, - SDC_SPI INAi, - L A LDrr, - HL PUSH, -;CODE diff --git a/blk/603 b/blk/603 index 554ff56..978520e 100644 --- a/blk/603 +++ b/blk/603 @@ -1,5 +1,3 @@ -CODE _sdcSel SDC_CSLOW OUTiA, ;CODE -CODE _sdcDesel SDC_CSHIGH OUTiA, ;CODE ( Computes n into crc c with polynomial 0x1021 ) CODE _crc16 ( c n -- c ) HL POP, ( n ) DE POP, ( c ) diff --git a/blk/604 b/blk/604 index 0d34578..4537302 100644 --- a/blk/604 +++ b/blk/604 @@ -1,8 +1,8 @@ ( -- n ) -: _idle 0xff _sdcSR ; +: _idle 0xff (spix) ; ( -- n ) -( _sdcSR 0xff until the response is something else than 0xff +( spix 0xff until the response is something else than 0xff for a maximum of 20 times. Returns 0xff if no response. ) : _wait 0 ( cnt ) diff --git a/blk/607 b/blk/607 index c9a4146..0d944fe 100644 --- a/blk/607 +++ b/blk/607 @@ -1,3 +1,3 @@ ( send-and-crc7 ) ( n c -- c ) -: _s+crc SWAP DUP _sdcSR DROP _crc7 ; +: _s+crc SWAP DUP (spix) DROP _crc7 ; diff --git a/blk/608 b/blk/608 index 3b252b3..d97a8e0 100644 --- a/blk/608 +++ b/blk/608 @@ -11,6 +11,6 @@ SWAP 256 /MOD ROT ( h l crc ) _s+crc _s+crc ( crc ) 0x01 OR ( ensure stop bit ) - _sdcSR DROP ( send CRC ) + (spix) DROP ( send CRC ) _wait ( wait for a valid response... ) ; diff --git a/blk/609 b/blk/609 index 885a3a7..1b89810 100644 --- a/blk/609 +++ b/blk/609 @@ -1,15 +1,15 @@ ( cmd arg1 arg2 -- r ) ( Send a command that expects a R1 response, handling CS. ) -: SDCMDR1 _sdcSel _cmd _sdcDesel ; +: SDCMDR1 (spie) _cmd (spid) ; ( cmd arg1 arg2 -- r arg1 arg2 ) ( Send a command that expects a R7 response, handling CS. A R7 is a R1 followed by 4 bytes. arg1 contains bytes 0:1, arg2 has 2:3 ) : SDCMDR7 - _sdcSel + (spie) _cmd ( r ) _idle 8 LSHIFT _idle + ( r arg1 ) _idle 8 LSHIFT _idle + ( r arg1 arg2 ) - _sdcDesel + (spid) ; diff --git a/blk/610 b/blk/610 index 12b7c44..8066197 100644 --- a/blk/610 +++ b/blk/610 @@ -1,4 +1,4 @@ -: _err _sdcDesel ABORT" SDerr" ; +: _err (spid) ABORT" SDerr" ; ( Tight definition ahead, pre-comment. diff --git a/blk/612 b/blk/612 index 134dd9d..b5799bf 100644 --- a/blk/612 +++ b/blk/612 @@ -1,5 +1,5 @@ : _sdc@ ( dstaddr blkno -- ) - _sdcSel 0x51 ( CMD17 ) 0 ROT ( a cmd 0 blkno ) _cmd + (spie) 0x51 ( CMD17 ) 0 ROT ( a cmd 0 blkno ) _cmd IF _err THEN _wait 0xfe = NOT IF _err THEN 0 SWAP ( crc a ) @@ -11,5 +11,5 @@ LOOP DROP ( crc1 ) _idle 8 LSHIFT _idle + ( crc2 ) - _wait DROP _sdcDesel + _wait DROP (spid) = NOT IF _err THEN ; diff --git a/blk/614 b/blk/614 index 9123593..6d8aebf 100644 --- a/blk/614 +++ b/blk/614 @@ -1,16 +1,16 @@ : _sdc! ( srcaddr blkno -- ) - _sdcSel 0x58 ( CMD24 ) 0 ROT ( a cmd 0 blkno ) _cmd + (spie) 0x58 ( CMD24 ) 0 ROT ( a cmd 0 blkno ) _cmd IF _err THEN - _idle DROP 0xfe _sdcSR DROP + _idle DROP 0xfe (spix) DROP 0 SWAP ( crc a ) 512 0 DO ( crc a ) C@+ ( crc a+1 n ) ROT OVER ( a n crc n ) _crc16 ( a n crc ) SWAP ( a crc n ) - _sdcSR DROP ( a crc ) + (spix) DROP ( a crc ) SWAP ( crc a ) LOOP DROP ( crc ) 256 /MOD ( lsb msb ) - _sdcSR DROP _sdcSR DROP - _wait DROP _sdcDesel ; + (spix) DROP (spix) DROP + _wait DROP (spid) ; diff --git a/blk/618 b/blk/618 index a0979c5..f0d294e 100644 --- a/blk/618 +++ b/blk/618 @@ -1,8 +1,6 @@ 0xff00 CONSTANT RS_ADDR 0xfffa CONSTANT PS_ADDR RS_ADDR 0x80 - CONSTANT SYSVARS 0x8000 CONSTANT HERESTART -4 CONSTANT SDC_SPI -5 CONSTANT SDC_CSLOW 6 CONSTANT SDC_CSHIGH 582 LOAD ( acia decl ) 212 LOAD ( z80 assembler ) 262 LOAD ( xcomp ) 282 LOAD ( boot.z80.decl ) diff --git a/recipes/rc2014/sdcard/README.md b/recipes/rc2014/sdcard/README.md index bfb8f56..d98f92a 100644 --- a/recipes/rc2014/sdcard/README.md +++ b/recipes/rc2014/sdcard/README.md @@ -71,11 +71,17 @@ instead. ## Building your binary The binary built in the base recipe doesn't have SDC drivers. Using the same -instructions as in the `eeprom` recipe, you'll need to insert those drivers. +instructions as in the `eeprom` recipe, you'll need to assemble a binary with +those drivers. First, we need drivers for the SPI relay. This is done by +declaring `SPI_DATA`, `SPI_CSLOW` and `SPI_CSHIGH`, which are respectively `4`, +`5` and `6` in our relay design. You can then load the driver with `596 LOAD`. +This driver provides `(spix)`, `(spie)` and `(spid)` which are then used in the +SDC driver. + The SDC driver is at B600. It gives you a load range. This means that what you need to insert in `xcomp` will look like: - 602 616 LOADR ( sdc ) + 603 616 LOADR ( sdc ) You also need to add `BLK$` to the init sequence. @@ -104,7 +110,7 @@ If there is no error message, we're fine. Then, we need to hook `BLK@*` and And thats it! You have full access to disk block mechanism: - 102 LOAD + 105 LOAD BROWSE (at this moment, the driver is a bit slow though...)