more work on SD card support

This commit is contained in:
FeralChild64 committed 2020-10-02 17:58:08 +02:00
1 parent 32a73bb5f8
commit 7452d683aa
4 files changed
+77 -30

No files matched your search

+27 -2
View File
@@ -54,13 +54,38 @@ sdcard_set_addr_sdsc:
lda CARD_SECNUM+2
rol
sta SD_ADDR+3
bcs sdcard_set_addr_fail ; branch if sector number too large for SD card
bcs sdcard_helper_fail ; branch if sector number too large for SD card
lda CARD_SECNUM+3
beq sdcard_set_addr_done ; do not branch if sector number too large for SD card
; FALLTROUGH
sdcard_set_addr_fail:
sdcard_helper_fail:
sec
rts
;
; Wait till card is ready
;
; Input: none
; Output: Carry set = error
; Preserves: .Y, .Z
sdcard_wait_ready:
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.
cmp #$01
beq sdcard_helper_fail
tax
and #$40
bne sdcard_helper_fail
txa
and #$03
bne sdcard_wait_ready
clc
rts
+3 -27
View File
@@ -16,7 +16,7 @@ sdcard_readsector:
; Set read address
jsr sdcard_set_addr
bcs sdcard_readsector_fail
bcs sdcard_readsector_fail
; FALLTROUGH
@@ -33,7 +33,7 @@ sdcard_readsector_try_loop:
; Wait till card is ready
jsr sdcard_readsector_wait
jsr sdcard_wait_ready
bcs sdcard_readsector_fail
; Read command
@@ -43,7 +43,7 @@ sdcard_readsector_try_loop:
; Wait for command completion
jsr sdcard_readsector_wait
jsr sdcard_wait_ready
bcs sdcard_readsector_fail
@@ -96,27 +96,3 @@ sdcard_readsector_copy_data:
clc
rts
sdcard_readsector_wait:
; Wait till card is ready
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.
cmp #$01
beq sdcard_readsector_wait_fail
tax
and #$40
bne sdcard_readsector_wait_fail
txa
and #$03
bne sdcard_readsector_wait
clc
rts
sdcard_readsector_wait_fail:
sec
rts
+21 -1
View File
@@ -17,7 +17,7 @@ sdcard_writesector:
and #$03
bne sdcard_writesector ; XXX add a timer here
; End reset
; End reset XXX should this be done for sector reading too?
lda #$01
sta SD_CTL
@@ -25,12 +25,20 @@ sdcard_writesector:
; Set write address
jsr sdcard_set_addr
bcs sdcard_writesector_fail
; FALLTROUGH
sdcard_writesector_write:
; Set number of retries
lda #$0A
sta CARD_TMP_RETRIES
; FALLTROUGH
sdcard_writesector_try_loop:
jsr sdcard_writesector_copy_data
@@ -43,6 +51,18 @@ sdcard_writesector:
sdcard_writesector_fail:
sec
rts
;
; Helper routines
;