Add limited retries when searching for sector start when writing

This commit is contained in:
hkz 2025-09-01 21:46:01 +02:00
commit e1e58c1db4

View file

@ -530,6 +530,7 @@ __BUF6S: .equ 0xBC00 ; 256 entries.
__NIBTAB: .equ 0xBD56 ; This will contain the translation table for writing nibbles. 63 entries.
__OFFSETP6 .equ 0x0678
__T_RETRYC2:.equ _Zp+10
__T_VOL: .equ _Zp+9
__T_TRK: .equ _Zp+8
__T_SEC: .equ _Zp+7
@ -545,20 +546,25 @@ __P_TRACK: .equ _Zp+0
sta zp:__P_OFFSET
sta __OFFSETP6
tax
lda #RETRIES$ ; Set up the retry counters
sta zp:__T_RETRYC2
lda #RETRIES$ ; Set up the retry counter
InnerRetr$: lda #RETRIES$
sta zp:__T_RETRYC
dec zp:__T_RETRYC2
beq wr_err_return ; Out of retries
;;; Search for the address prologue (D5 AA 96)
RdSect$:
dec zp:__T_RETRYC
beq wr_err_return ; Out of retries
beq InnerRetr$ ; Out of retries
;;; Read the address prologue
RdByte1$: lda READ_SW,x
bpl RdByte1$ ; Read the first byte
ChkD5$: cmp #0xD5
bne RdByte1$ ; Not the first byte, keep searching
bne RdSect$ ; Not the first byte, keep searching
nop
RdByte2$: lda READ_SW,x
@ -615,7 +621,8 @@ RdByte7$: lda READ_SW,x
lda WRITE_SW,x ; Combination of these two in sequence checks for write protect
lda CLEAR_SW,x ; and enables the write sequence.
bmi wr_err_return ; Write protected disk. Branch on N = 1
bpl _b2add01 ; Check if Write protected disk.
jmp wr_err_return
_b2add01:
lda __BUF2S ; Get the first 2-bit encode byte
sta zp:__T_HOLDNIB ; and save it for future use.