From 8cfe834edb03eac93aa59888b2e6c1779fedaa2d Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 28 May 2019 11:01:17 -0400 Subject: [PATCH] recipes/rc2014/sdcard: use "sdci" and blockdev rather than user prog --- kernel/sdc.asm | 6 ++-- recipes/.gitignore | 1 + recipes/rc2014/sdcard/Makefile | 15 +++++++--- recipes/rc2014/sdcard/README.md | 20 ++++++-------- recipes/rc2014/sdcard/cfsin/hello.txt | 1 + recipes/rc2014/sdcard/glue.asm | 12 ++++---- recipes/rc2014/sdcard/sdinit.asm | 52 ----------------------------------- 7 files changed, 30 insertions(+), 77 deletions(-) create mode 100644 recipes/rc2014/sdcard/cfsin/hello.txt delete mode 100644 recipes/rc2014/sdcard/sdinit.asm diff --git a/kernel/sdc.asm b/kernel/sdc.asm index c171b6a..814ebc1 100644 --- a/kernel/sdc.asm +++ b/kernel/sdc.asm @@ -5,7 +5,8 @@ ; ; Note that SPI can't really be used directly from the z80, so this part ; assumes that you have a device that handles SPI communication on behalf of -; the z80. This device is assumed to work in a particular way. +; the z80. This device is assumed to work in a particular way. See the +; "rc2014/sdcard" recipe for details. ; ; That device has 3 ports. One write-only port to make CS high, one to make CS ; low (data sent is irrelevant), and one read/write port to send and receive @@ -305,8 +306,7 @@ sdcReadBlk: sdcInitializeCmd: .db "sdci", 0, 0, 0 call sdcInitialize - call sdcSetBlkSize - ret + jp sdcSetBlkSize ; return ; *** blkdev routines *** diff --git a/recipes/.gitignore b/recipes/.gitignore index a8a0dce..9452281 100644 --- a/recipes/.gitignore +++ b/recipes/.gitignore @@ -1 +1,2 @@ *.bin +*.cfs diff --git a/recipes/rc2014/sdcard/Makefile b/recipes/rc2014/sdcard/Makefile index ba9ef5c..7ebacbc 100644 --- a/recipes/rc2014/sdcard/Makefile +++ b/recipes/rc2014/sdcard/Makefile @@ -1,9 +1,16 @@ -TARGETS = os.bin sdinit.bin -ZASM = ../../../tools/emul/zasm/zasm +TARGETS = os.bin +TOOLS = ../../../tools +ZASM = $(TOOLS)/emul/zasm/zasm +CFSPACK = $(TOOLS)/cfspack/cfspack .PHONY: all -all: $(TARGETS) +all: $(TARGETS) sdcard.cfs os.bin: glue.asm -sdinit.bin: sdinit.asm $(TARGETS): $(ZASM) < $< > $@ + +$(CFSPACK): + make -C $(TOOLS)/cfspack + +sdcard.cfs: cfsin $(CFSPACK) + $(CFSPACK) $< > $@ diff --git a/recipes/rc2014/sdcard/README.md b/recipes/rc2014/sdcard/README.md index b0fab4e..080f60d 100644 --- a/recipes/rc2014/sdcard/README.md +++ b/recipes/rc2014/sdcard/README.md @@ -81,26 +81,22 @@ should have [glue code that looks like this](glue.asm). Initially, when you don't know if things work well yet, you should comment out the block creation part. -## Testing CD card initialization - -This receipes contains a little [user program](sdinit.asm) that initializes a -SD card, reads the first 12 bytes from its first sector and prints it. +## Reading from the SD card The first thing we'll do is fill the SD card's first 12 bytes with "Hello World!": echo "Hello World!" > /dev/sdX -Then, you can run `make` from within this folder to compile `sdinit.bin` and -then [upload and run][run-from-mem] that code from memory. You might need to -call the routine more than once (On my local tests, I need to call it twice). +Then, insert your SD card in your SPI relay and boot the RC2014. -If all goes well, you should see your "Hello World!" printed to the console! +Run the `sdci` command which will initialize the card. Then, run `bsel 1` to +select the second blockdev, which is configured to be the sd card. -## Create a block device from the SD card reader - -TODO +Set your memory pointer to somewhere you can write to with `mptr 9000` and then +you're ready to load your contents with `load d` (load the 13 bytes that you +wrote to your sd card earlier. You can then `peek d` and see that your +"Hello World!\n" got loaded in memory! [schematic]: spirelay/spirelay.pdf [inspiration]: https://www.ecstaticlyrics.com/electronics/SPI/fast_z80_interface.html -[run-from-mem]: ../../../doc/load-run-code.md diff --git a/recipes/rc2014/sdcard/cfsin/hello.txt b/recipes/rc2014/sdcard/cfsin/hello.txt new file mode 100644 index 0000000..980a0d5 --- /dev/null +++ b/recipes/rc2014/sdcard/cfsin/hello.txt @@ -0,0 +1 @@ +Hello World! diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index 58e7b11..a0a6470 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -41,14 +41,14 @@ jp aciaInt #include "stdio.asm" .equ SHELL_RAMSTART STDIO_RAMEND -.equ SHELL_EXTRA_CMD_COUNT 3 +.equ SHELL_EXTRA_CMD_COUNT 4 #include "shell.asm" -.dw sdcInitializeCmd, blkBselCmd, blkSeekCmd +.dw sdcInitializeCmd, blkBselCmd, blkSeekCmd, sdcInitializeCmd -.equ SDC_RAMSTART SHELL_RAMEND -.equ SDC_PORT_CSHIGH 6 -.equ SDC_PORT_CSLOW 5 -.equ SDC_PORT_SPI 4 +.equ SDC_RAMSTART SHELL_RAMEND +.equ SDC_PORT_CSHIGH 6 +.equ SDC_PORT_CSLOW 5 +.equ SDC_PORT_SPI 4 #include "sdc.asm" init: diff --git a/recipes/rc2014/sdcard/sdinit.asm b/recipes/rc2014/sdcard/sdinit.asm deleted file mode 100644 index 4fd8945..0000000 --- a/recipes/rc2014/sdcard/sdinit.asm +++ /dev/null @@ -1,52 +0,0 @@ -.equ JUMP_PRINTSTR 0x03 -.equ JUMP_PRINTHEX 0x06 -.equ JUMP_SDCINITALIZE 0x09 -.equ JUMP_SDCSENDRECV 0x0c -.equ JUMP_SDCWAITRESP 0x0f -.equ JUMP_SDCCMD 0x12 -.equ JUMP_SDCCMDR1 0x15 -.equ JUMP_SDCCMDR7 0x18 -.equ JUMP_SDCREAD 0x1b -.equ JUMP_SDCSETBLKSIZE 0x1e -.org 0x9000 - - call JUMP_SDCINITALIZE - or a - jp nz, error - - ld hl, sOk - call JUMP_PRINTSTR - - call JUMP_SDCSETBLKSIZE - or a - jp nz, error - - ld hl, sOk - call JUMP_PRINTSTR - - ; read sector 0 - xor a - call JUMP_SDCREAD - or a - jp nz, error - - push hl - ld hl, sOk - call JUMP_PRINTSTR - pop hl - ; SDC buffer address is in HL - ; YOLO! print it! - call JUMP_PRINTSTR - - ret - -error: - call JUMP_PRINTHEX - ld hl, sErr - call JUMP_PRINTSTR - ret - -sOk: - .db "Ok", 0xa, 0xd, 0 -sErr: - .db "Err", 0xa, 0xd, 0