From 8f3a1a596832d3d7f520d63824f3e03e003c0e0d Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sun, 23 Jul 2023 18:43:39 -0700 Subject: [PATCH] res1_cmd assembly rewrite --- sw/bootloader/devices/sd_card.c | 2 ++ sw/bootloader/devices/sd_card.h | 2 ++ sw/bootloader/devices/sd_card_asm.s | 34 ++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/sw/bootloader/devices/sd_card.c b/sw/bootloader/devices/sd_card.c index 1c72a0a..55b4341 100644 --- a/sw/bootloader/devices/sd_card.c +++ b/sw/bootloader/devices/sd_card.c @@ -67,6 +67,7 @@ uint8_t SD_init() return SD_SUCCESS; } +/* // Send a command with starting end ending clock pulses uint8_t res1_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) { @@ -89,6 +90,7 @@ uint8_t res1_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) return res1; } +*/ /******************************************************************************* Run power up sequence diff --git a/sw/bootloader/devices/sd_card.h b/sw/bootloader/devices/sd_card.h index 6488e8b..3e9304d 100644 --- a/sw/bootloader/devices/sd_card.h +++ b/sw/bootloader/devices/sd_card.h @@ -75,4 +75,6 @@ uint8_t SD_sendOpCond(); uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error); uint8_t SD_writeSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *res); +uint8_t res1_cmd(uint8_t cmd, uint32_t arg, uint8_t crc); + #endif \ No newline at end of file diff --git a/sw/bootloader/devices/sd_card_asm.s b/sw/bootloader/devices/sd_card_asm.s index 99aa055..f377964 100644 --- a/sw/bootloader/devices/sd_card_asm.s +++ b/sw/bootloader/devices/sd_card_asm.s @@ -3,6 +3,7 @@ .export _SD_readRes2 .export _SD_readRes3 .export _SD_readBytes +.export _res1_cmd .importzp sp, ptr1 @@ -52,7 +53,7 @@ tryread: dex bne tryread -end: +end: ; x will be 0 here anyway rts .endproc @@ -120,4 +121,35 @@ read: @L1: rts +.endproc + +; uint8_t res1_cmd(uint8_t cmd, uint32_t arg, uint8_t crc) + +.proc _res1_cmd: near + + pha ; push crc to processor stack + lda #$ff + jsr _spi_exchange + lda #$00 ; this gets ignored anyway + jsr _spi_select + lda #$ff + jsr _spi_exchange + + pla + jsr _SD_command ; rely on command to teardown stack + + jsr _SD_readRes1 + tay ; spi doesn't touch y + + lda #$ff + jsr _spi_exchange + lda #$00 ; this gets ignored anyway + jsr _spi_deselect + lda #$ff + jsr _spi_exchange + + tya + ldx #$00 ; Promote to integer + rts + .endproc \ No newline at end of file