diff --git a/sw/bootloader/devices/sd_card.c b/sw/bootloader/devices/sd_card.c index 9dab8ff..7fdfeba 100644 --- a/sw/bootloader/devices/sd_card.c +++ b/sw/bootloader/devices/sd_card.c @@ -158,6 +158,7 @@ uint8_t SD_readRes1() /******************************************************************************* Read R2 from SD card *******************************************************************************/ +/* void SD_readRes2(uint8_t *res) { // read response 1 in R2 @@ -166,6 +167,7 @@ void SD_readRes2(uint8_t *res) // read final byte of response res[1] = spi_exchange(0xFF); } +*/ /******************************************************************************* Read R3 from SD card @@ -200,10 +202,12 @@ void SD_readRes7(uint8_t *res) /******************************************************************************* Read specified number of bytes from SD card *******************************************************************************/ +/* void SD_readBytes(uint8_t *res, uint8_t n) { while(n--) *res++ = spi_exchange(0xFF); } +*/ /******************************************************************************* Command Idle State (CMD0) diff --git a/sw/bootloader/devices/sd_card_asm.s b/sw/bootloader/devices/sd_card_asm.s index 7cb5f32..c398031 100644 --- a/sw/bootloader/devices/sd_card_asm.s +++ b/sw/bootloader/devices/sd_card_asm.s @@ -1,7 +1,9 @@ .export _SD_command .export _SD_readRes1 +.export _SD_readRes2 +.export _SD_readBytes -.importzp sp +.importzp sp, ptr1 .autoimport on @@ -50,5 +52,43 @@ tryread: end: rts +.endproc + +; void SD_readRes2(uint8_t *res) + +.proc _SD_readRes2: near + + sta ptr1 ; store res in ptr1 + stx ptr1 + 1 + + jsr _SD_readRes1 ; get first response 1 + sta (ptr1) + + lda #$ff + jsr _spi_exchange ; get final byte of response + ldy #$01 + sta (ptr1),y + jsr incsp2 + rts + +.endproc + +; void SD_readBytes(uint8_t *res, uint8_t n) + +.proc _SD_readBytes: near + + tax + jsr popptr1 ; store res in ptr1 + +read: + lda #$ff ; read data first + jsr _spi_exchange + sta (ptr1) + inc ptr1 ; then increment res + bne @L1 + inc ptr1 + 1 +@L1: dex ; then decrement x + bne read ; and if x is zero we are done + rts .endproc \ No newline at end of file