1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-08 14:28:05 +11:00
collapseos/recipes/rc2014/sdcard/sdinit.asm
Virgil Dupras 12ca2bd53e parts/z80/sdc: add sdcInitialize
Also, adjust SD card recipe. Straightforward initialization and read!
2019-05-08 16:03:54 -04:00

71 lines
1.3 KiB
NASM

#include "jumptable.inc"
.org 0x9000
call JUMP_SDCINITALIZE
or a
jp nz, .error
; Alright, normally we should configure block size and all, but this is
; too exciting and we'll play it dirty: we'll read just enough bytes
; to fetch our "Hello World!" and print it and we'll leave the SD card
; hanging. Yeah, I know, not very polite.
out (5), a
ld hl, sCmd
call JUMP_PRINTSTR
ld a, 0b01010001 ; CMD17
ld hl, 0 ; read single block at addr 0
ld de, 0
call JUMP_SDCCMD
cp 0
jr nz, .error
ld hl, sCmd
call JUMP_PRINTSTR
; Command sent, no error, now let's wait for our data response.
ld b, 20
.loop1:
call JUMP_SDCWAITRESP
; 0xfe is the expected data token for CMD17
cp 0xfe
jr z, .loop1end
cp 0xff
jr nz, .error
djnz .loop1
jr .error
.loop1end:
ld hl, sGettingData
call JUMP_PRINTSTR
; Data packets follow immediately
ld b, 12 ; size of "Hello World!"
ld hl, sDest ; sDest has null chars, we'll be alright
; printing it.
.loop2:
call JUMP_SDCWAITRESP
ld (hl), a
inc hl
djnz .loop2
out (6), a
ld hl, sDest
call JUMP_PRINTSTR
ret
.error:
call JUMP_PRINTHEX
ld hl, sErr
call JUMP_PRINTSTR
ret
sCmd:
.db "CMD", 0xa, 0xd, 0
sGettingData:
.db "Data", 0xa, 0xd, 0
sOk:
.db "Ok", 0xa, 0xd, 0
sErr:
.db "Err", 0xa, 0xd, 0
sDest:
.fill 0x10