Port limited retries when searching for sector start during disk write

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

View file

@ -525,11 +525,12 @@ wr_err_return:
dii_write_sector:
RETRIES$: .equ 0xff
; Note that the following buffers MUST be at the start of a page for write timing to be respected
__BUF2S: .equ 0x9D00 ; Default to this, it'll be overwritten when modifying this code. 86 entries.
__BUF6S: .equ 0x9C00 ; 256 entries.
__NIBTAB: .equ 0x9D56 ; This will contain the translation table for writing nibbles. 63 entries.
__BUF2S: .equ 0xBD00 ; Default to this, it'll be overwritten when modifying this code. 86 entries.
__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.