sdc: make sdcReadBlk return error on max retries

It previously returned success!
This commit is contained in:
Virgil Dupras 2019-06-19 13:22:07 -04:00
parent 7cdc288ef2
commit 69fc2e3bf2
1 changed files with 8 additions and 9 deletions

View File

@ -324,11 +324,12 @@ sdcInitialize:
sdcReadBlk: sdcReadBlk:
xor a xor a
ld (SDC_RETRYCNT), a ld (SDC_RETRYCNT), a
.retry:
push bc push bc
push hl push hl
out (SDC_PORT_CSLOW), a out (SDC_PORT_CSLOW), a
.retry:
ld hl, 0 ld hl, 0
; DE already has the correct value ; DE already has the correct value
ld a, 0b01010001 ; CMD17 ld a, 0b01010001 ; CMD17
@ -391,17 +392,15 @@ sdcReadBlk:
; CRC of the buffer's content doesn't match the CRC reported by the ; CRC of the buffer's content doesn't match the CRC reported by the
; card. Let's retry. ; card. Let's retry.
pop de ; from the push right before call sdcCRC pop de ; from the push right before call sdcCRC
pop hl ; Our main stack, pop it
pop bc
ld a, (SDC_RETRYCNT) ld a, (SDC_RETRYCNT)
inc a inc a
ld (SDC_RETRYCNT), a ld (SDC_RETRYCNT), a
cp SDC_MAXTRIES cp SDC_MAXTRIES
jr nz, .retry jr nz, .retry ; we jump inside our main stack push. No need
; don't continue to error/end: our stack is already popped. Let's just ; to pop it.
; deselect the card and return ; Continue to error condition. Even if we went through many retries,
out (SDC_PORT_CSHIGH), a ; our stack is still the same as it was at the first call. We can return
ret ; normally (but in error condition).
.error: .error:
; try to preserve error code ; try to preserve error code
or a ; cp 0 or a ; cp 0
@ -424,7 +423,7 @@ sdcWriteBlk:
xor a xor a
cp (ix+2) ; dirty flag cp (ix+2) ; dirty flag
pop ix pop ix
ret z ; don't write if dirst flag is zero ret z ; don't write if dirty flag is zero
push bc push bc
push de push de