passport/src/universalstyle.a

196 lines
5.3 KiB
Plaintext
Raw Permalink Normal View History

2021-07-11 04:51:32 +00:00
; /!\ execution falls through here from Trace
2021-06-17 22:06:06 +00:00
;-------------------------------
; UseUniversal
; Caller has decided to use the built-in RWTS to read
; this disk (possibly already patched with disk-specific
; parameters). Now we check for protections that require
; additional patches or callbacks before we start.
;
; in: $0800..$08FF contains boot0
; $B600..$BFFF contains boot1
; out: all registers clobbered
; exits via ReadWithRWTS
;-------------------------------
2021-04-20 03:48:41 +00:00
UseUniversal
2021-06-17 22:06:06 +00:00
;
; Copy built-in RWTS into place ($B800..$BFFF)
;
2021-04-20 03:48:41 +00:00
jsr StartWithUniv
;
2021-06-17 22:06:06 +00:00
; On pure 13-sector disks, we just hijack the read routine to perform a
; verification instead.
;
lda gIs13Sector
2021-07-11 18:00:10 +00:00
bne @not13Sector
lda #0
sta $47E ; restore track number replaced by DOS
lda #<seekread13
2021-06-17 22:06:06 +00:00
sta jCallRWTS+1
lda #>seekread13
2021-06-17 22:06:06 +00:00
sta jCallRWTS+2
bne @doneUnivPatching ; always branches
2021-07-11 18:00:10 +00:00
@not13Sector
2021-06-17 22:06:06 +00:00
;
2021-07-11 18:00:10 +00:00
; On 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.
;
ldy #$09
- lda _adaptiveAddressEpilogue, y
sta $B994, y
lda _adaptiveDataEpilogue, y
sta $B938, y
dey
bpl -
;
; On Dinkey-DOS disks (e.g. Ultima V, Times of Lore), we don't use the
; adaptive RWTS we just copied into place. Instead, we use the same space
; to create a hybrid RWTS that alters the sector number in the
2021-04-20 03:48:41 +00:00
; 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
2021-07-11 18:00:10 +00:00
bne @notDinkeyDOS
2021-06-17 22:06:06 +00:00
ldy #$0F
- lda _originAddressEpilogue, y
sta $B990, y
2021-07-11 17:41:12 +00:00
lda _originDataEpilogue, y
2021-06-17 22:06:06 +00:00
sta $B92F, y
dey
bpl -
2021-07-11 18:00:10 +00:00
@notDinkeyDOS
2021-04-20 03:48:41 +00:00
;
; On TSR disks (e.g. Dawn Patrol, Dungeon), we start with the universal
; RWTS then apply a patch in memory.
;
2021-06-17 22:06:06 +00:00
lda gIsTSR
2021-07-11 18:00:10 +00:00
bne @notTSR
2021-06-17 22:06:06 +00:00
lda #<_tsrCallback
sta $BE8C
lda #>_tsrCallback
sta $BE8D
2021-07-11 18:00:10 +00:00
@notTSR
2021-04-20 03:48:41 +00:00
;
; Disable drive recalibration on bad sectors so we give up on bad sectors
; faster and detect unformatted or specially structured tracks faster.
;
2021-06-17 22:06:06 +00:00
lda #$B0
sta $BDD2
lda #$30
sta $BDD3
2021-04-20 03:48:41 +00:00
;
; 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.
2021-07-11 18:06:03 +00:00
; (This is implemented by recopying the entire built-in RWTS into place
; which wipes out all the above patches, but track 0 of Dinkey-DOS and
; TSR disks is readable, so it's OK that they fall through to here.)
2021-04-20 03:48:41 +00:00
;
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
sta +
2021-04-20 03:48:41 +00:00
jsr PrintByID
+ !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
pha
jsr MoveT00PakLow ; move T00 modules out of the way if necessary
pla
2021-04-20 03:48:41 +00:00
; /!\ 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
2021-06-17 22:06:06 +00:00
_adaptiveAddressEpilogue ; to $B994
2021-04-20 03:48:41 +00:00
!byte $8D,$91,$B9
!byte $A9,$AE
!byte $8D,$93,$B9
!byte $D0,$00
2021-06-17 22:06:06 +00:00
_adaptiveDataEpilogue ; to $B938
2021-04-20 03:48:41 +00:00
!byte $8D,$35,$B9
!byte $A9,$0A
!byte $8D,$37,$B9
!byte $18
!byte $60
2021-06-17 22:06:06 +00:00
_originAddressEpilogue ; to $B990
2021-04-20 03:48:41 +00:00
!byte $C9,$AB
!byte $D0,$0A
!byte $EA
!byte $BD,$8C,$C0
!byte $C9,$AB
!byte $F0,$95
!byte $D0,$00
!byte $18,$60
2021-06-17 22:06:06 +00:00
_originDataEpilogue ; to $B92F
2021-04-20 03:48:41 +00:00
!byte $18
!byte $60
!byte $38
!byte $A5,$2D
!byte $E9,$11
!byte $85,$2D
!byte $18
!byte $60
2021-07-11 17:41:12 +00:00
; next 5 bytes are also copied into $B93A..$B93E
; which is harmless
2021-04-20 03:48:41 +00:00
2021-06-17 22:06:06 +00:00
_tsrCallback
2021-04-20 03:48:41 +00:00
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