Browse Source

recipes/rc2014/sdcard: use "sdci" and blockdev rather than user prog

pull/10/head
Virgil Dupras 5 years ago
parent
commit
8cfe834edb
7 changed files with 30 additions and 77 deletions
  1. +3
    -3
      kernel/sdc.asm
  2. +1
    -0
      recipes/.gitignore
  3. +11
    -4
      recipes/rc2014/sdcard/Makefile
  4. +8
    -12
      recipes/rc2014/sdcard/README.md
  5. +1
    -0
      recipes/rc2014/sdcard/cfsin/hello.txt
  6. +6
    -6
      recipes/rc2014/sdcard/glue.asm
  7. +0
    -52
      recipes/rc2014/sdcard/sdinit.asm

+ 3
- 3
kernel/sdc.asm View File

@@ -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 ***



+ 1
- 0
recipes/.gitignore View File

@@ -1 +1,2 @@
*.bin
*.cfs

+ 11
- 4
recipes/rc2014/sdcard/Makefile View File

@@ -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) $< > $@

+ 8
- 12
recipes/rc2014/sdcard/README.md View File

@@ -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).

If all goes well, you should see your "Hello World!" printed to the console!
Then, insert your SD card in your SPI relay and boot the RC2014.

## Create a block device from the SD card reader
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.

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

+ 1
- 0
recipes/rc2014/sdcard/cfsin/hello.txt View File

@@ -0,0 +1 @@
Hello World!

+ 6
- 6
recipes/rc2014/sdcard/glue.asm View File

@@ -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:


+ 0
- 52
recipes/rc2014/sdcard/sdinit.asm View File

@@ -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

Loading…
Cancel
Save