diff --git a/src/dos_m65/sdcard/sdcard_helpers.s b/src/dos_m65/sdcard/sdcard_helpers.s index 94acd3db..053af35f 100644 --- a/src/dos_m65/sdcard/sdcard_helpers.s +++ b/src/dos_m65/sdcard/sdcard_helpers.s @@ -75,6 +75,8 @@ sdcard_helper_fail: sdcard_wait_ready: + ; XXX if card does not get ready, try to reset it + lda SD_CTL ; Sometimes we see this result, i.e., sdcard.vhdl thinks it is done, ; but sdcardio.vhdl thinks not. This means a read error. diff --git a/src/dos_m65/sdcard/sdcard_writesector.s b/src/dos_m65/sdcard/sdcard_writesector.s index 180f198f..b355c4b4 100644 --- a/src/dos_m65/sdcard/sdcard_writesector.s +++ b/src/dos_m65/sdcard/sdcard_writesector.s @@ -42,23 +42,50 @@ sdcard_writesector_try_loop: jsr sdcard_writesector_copy_data + ; Wait till card is ready + jsr sdcard_wait_ready + bcs sdcard_writesector_fail + ; Write command + lda #CARD_CMD_WRITE ; $03 + sta SD_CTL + ; Wait for command completion + jsr sdcard_wait_ready + bcs sdcard_writesector_fail + ; Check result + lda SD_CTL + and #$67 + bne sdcard_writesector_verify + ; Write failed - retry + jsr sdcard_reset + dec CARD_TMP_RETRIES + bne sdcard_writesector_try_loop - + ; FALLTROUGH sdcard_writesector_fail: sec rts +sdcard_writesector_verify: + + ; There is a bug in the SD controller; you have to read between writes, + ; or it gets really upset + + ; XXX + + + +