2021-04-20 03:48:41 +00:00
|
|
|
UseUniversal
|
|
|
|
jsr IncProgress
|
|
|
|
jsr StartWithUniv
|
|
|
|
;
|
|
|
|
; On Dinkey-DOS disks (e.g. Ultima V, Times of Lore), we start with the
|
|
|
|
; universal RWTS then apply a patch in memory.
|
|
|
|
; These disks use a hybrid RWTS that alters the sector number in the
|
|
|
|
; address field based on the address epilogue. Once we normalize the
|
|
|
|
; sector numbers, no further patches are required, since the RWTS can also
|
|
|
|
; read unprotected disks. A separate patcher finds the actual code that
|
|
|
|
; alters the sector number to print it to the log.
|
|
|
|
;
|
|
|
|
lda gIsDinkeyDOS
|
|
|
|
bne +
|
|
|
|
jsr PatchUniversalRWTSForOrigin
|
|
|
|
bmi @doneUnivPatching ; always branches
|
|
|
|
;
|
|
|
|
; On TSR disks (e.g. Dawn Patrol, Dungeon), we start with the universal
|
|
|
|
; RWTS then apply a patch in memory.
|
|
|
|
;
|
|
|
|
+ lda gIsTSR
|
|
|
|
bne +
|
|
|
|
jsr PatchUniversalRWTSForTSR
|
|
|
|
;
|
|
|
|
; On pure 13-sector disks, we just hijack the read routine to perform a
|
|
|
|
; verification instead.
|
|
|
|
;
|
|
|
|
+ lda gIs13Sector
|
|
|
|
bne +
|
|
|
|
lda #<read13
|
|
|
|
sta jCallRWTS+1
|
|
|
|
lda #>read13
|
|
|
|
sta jCallRWTS+2
|
|
|
|
bne @doneUnivPatching ; always branches
|
|
|
|
;
|
|
|
|
; On other disks that use the universal RWTS for the entire disk, we use
|
|
|
|
; an adaptive RWTS that accepts any epilogue on the first sector but then
|
|
|
|
; enforces all other sectors to have the same epilogue.
|
|
|
|
;
|
|
|
|
+ jsr PatchUniversalRWTSForAdaptive
|
|
|
|
;
|
|
|
|
; Disable drive recalibration on bad sectors so we give up on bad sectors
|
|
|
|
; faster and detect unformatted or specially structured tracks faster.
|
|
|
|
;
|
|
|
|
jsr PatchUniversalRWTSForNoRecal
|
|
|
|
;
|
|
|
|
; Some disks have different epilogues on track 0, so we stop using the
|
|
|
|
; adaptive RWTS so we don't falsely accuse those disks of being damaged.
|
|
|
|
;
|
|
|
|
lda #kSectorResetAdaptiveRWTS
|
|
|
|
sta T00S0F
|
|
|
|
;
|
|
|
|
; Some disks have an intentionally invalid checksum on T00,S00 (read by
|
|
|
|
; the drive firmware, which doesn't verify it).
|
|
|
|
;
|
|
|
|
lda #kSectorIgnoreAddressChecksum
|
|
|
|
sta T00S00
|
|
|
|
@doneUnivPatching
|
|
|
|
jmp ReadWithRWTS
|
|
|
|
|
|
|
|
SwitchToUniv
|
|
|
|
lda gSector
|
|
|
|
sta gDisplayBytes
|
|
|
|
lda #s_switch
|
|
|
|
!byte $2C ; hide next LDA
|
|
|
|
; /!\ execution falls through here
|
|
|
|
|
|
|
|
StartWithUniv
|
|
|
|
lda #s_builtin
|
2021-06-13 02:07:26 +00:00
|
|
|
sta +
|
2021-04-20 03:48:41 +00:00
|
|
|
jsr PrintByID
|
2021-06-13 02:07:26 +00:00
|
|
|
+ !byte $FD ; SMC
|
2021-04-20 03:48:41 +00:00
|
|
|
lda #TRUE
|
|
|
|
sta gTriedUniv
|
|
|
|
lda #FALSE
|
|
|
|
sta gIsProtDOS
|
|
|
|
; /!\ execution falls through here
|
|
|
|
|
|
|
|
CopyUniversal
|
|
|
|
lda #$B8
|
|
|
|
; /!\ execution falls through here
|
|
|
|
|
|
|
|
CopyUniversalAnywhere
|
|
|
|
sta universalrwts
|
|
|
|
clc
|
|
|
|
adc #$02
|
|
|
|
sta .cu+2
|
|
|
|
lda #>universalrwts
|
|
|
|
sta _byte_hi
|
|
|
|
lda #<universalrwts
|
|
|
|
sta _byte_lo
|
|
|
|
jsr decrunch
|
|
|
|
sty jCallRWTS+1
|
|
|
|
lda #$BD
|
|
|
|
sta jCallRWTS+2
|
|
|
|
ldy #$96
|
|
|
|
.culoop lda gNIBTable,y
|
|
|
|
.cu sta $d100,y ; set at runtime
|
|
|
|
iny
|
|
|
|
bne .culoop
|
|
|
|
rts
|
|
|
|
|
|
|
|
PatchUniversalRWTSForNoRecal
|
|
|
|
lda #$B0
|
|
|
|
sta $BDD2
|
|
|
|
lda #$30
|
|
|
|
sta $BDD3
|
|
|
|
rts
|
|
|
|
|
|
|
|
PatchUniversalRWTSForAdaptive
|
|
|
|
; out: N flag set
|
|
|
|
ldy #$09
|
|
|
|
- lda @addressepilogue, y
|
|
|
|
sta $B994, y
|
|
|
|
lda @dataepilogue, y
|
|
|
|
sta $B938, y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
@addressepilogue ; to $B994
|
|
|
|
!byte $8D,$91,$B9
|
|
|
|
!byte $A9,$AE
|
|
|
|
!byte $8D,$93,$B9
|
|
|
|
!byte $D0,$00
|
|
|
|
@dataepilogue ; to $B938
|
|
|
|
!byte $8D,$35,$B9
|
|
|
|
!byte $A9,$0A
|
|
|
|
!byte $8D,$37,$B9
|
|
|
|
!byte $18
|
|
|
|
!byte $60
|
|
|
|
|
|
|
|
PatchUniversalRWTSForOrigin
|
|
|
|
; out: N=1
|
|
|
|
ldy #$0F
|
|
|
|
- lda @addressepilogue, y
|
|
|
|
sta $B990, y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
ldy #$0A
|
|
|
|
- lda @dataepilogue, y
|
|
|
|
sta $B92F, y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
rts
|
|
|
|
@addressepilogue ; to $B990
|
|
|
|
!byte $C9,$AB
|
|
|
|
!byte $D0,$0A
|
|
|
|
!byte $EA
|
|
|
|
!byte $BD,$8C,$C0
|
|
|
|
!byte $C9,$AB
|
|
|
|
!byte $F0,$95
|
|
|
|
!byte $D0,$00
|
|
|
|
!byte $18,$60
|
|
|
|
@dataepilogue ; to $B92F
|
|
|
|
!byte $18
|
|
|
|
!byte $60
|
|
|
|
!byte $38
|
|
|
|
!byte $A5,$2D
|
|
|
|
!byte $E9,$11
|
|
|
|
!byte $85,$2D
|
|
|
|
!byte $18
|
|
|
|
!byte $60
|
|
|
|
|
|
|
|
PatchUniversalRWTSForTSR
|
|
|
|
; out: Z=0
|
|
|
|
lda #<@tsr_callback
|
|
|
|
sta $BE8C
|
|
|
|
lda #>@tsr_callback
|
|
|
|
sta $BE8D
|
|
|
|
rts
|
|
|
|
@tsr_callback
|
|
|
|
pha
|
|
|
|
ldy gTrack
|
|
|
|
cpy #$05
|
|
|
|
bcc @normal
|
|
|
|
lda $F800, y
|
|
|
|
and #$42
|
|
|
|
bne +
|
|
|
|
lda #$42
|
|
|
|
+ ora #$B5
|
|
|
|
!byte $2C
|
|
|
|
@normal lda #$AD
|
|
|
|
sta $B8FC
|
|
|
|
pla
|
|
|
|
jmp $B9A0
|