mirror of
https://github.com/a2-4am/passport.git
synced 2024-09-27 17:56:32 +00:00
271 lines
7.1 KiB
Plaintext
Executable File
271 lines
7.1 KiB
Plaintext
Executable File
;-------------------------------
|
|
; SkipTrack
|
|
; out: C clear if we should skip this track
|
|
; C set if we should not skip this track
|
|
;-------------------------------
|
|
SkipTrack
|
|
; don't look for whole-track protections on track 0, that's silly
|
|
lda gTrack
|
|
sec
|
|
beq @linknoskip
|
|
;
|
|
; Electronic Arts protection track?
|
|
;
|
|
jsr IsEATrack6
|
|
lda #s_eatrk6
|
|
bcc @print
|
|
;
|
|
; Nibble count track?
|
|
;
|
|
jsr JustTheSameDamnThingOverAndOver
|
|
lda #s_sync
|
|
bcc @print ; always branches
|
|
;
|
|
; Unformatted track?
|
|
;
|
|
jsr IsUnformatted
|
|
@linknoskip
|
|
bcs @donotskip
|
|
;
|
|
; $F7F6EFEAAB protection track?
|
|
; (initially presents as unformatted, needs separate test because it
|
|
; triggers special handling)
|
|
;
|
|
jsr IsF7F6
|
|
lda #s_unformat
|
|
bcs @print
|
|
lda #s_f7
|
|
bit gMode
|
|
bpl @print
|
|
bvc @print
|
|
; if we're in 'crack' mode, restart the scan to find the protection code
|
|
jmp SetupF7F6SecondRound
|
|
|
|
@print
|
|
jsr PrintByID
|
|
;
|
|
; Skipping T22 on a ProDOS disk might indicate the presence of a
|
|
; Gamco Industries protection elsewhere on the disk. Different
|
|
; Gamco disks present as different types of weirdness on T22 --
|
|
; EEEF, sync, or even unformatted. (The actual protection is just
|
|
; a bad block check, so putting the code here will catch all
|
|
; possible cases.)
|
|
;
|
|
lda gTrack
|
|
cmp #$22
|
|
clc
|
|
bne @donotskip
|
|
lda gIsProDOS
|
|
bne @donotskip
|
|
sta gPossibleGamco
|
|
@donotskip
|
|
rts
|
|
|
|
;-------------------------------
|
|
; IsF7F6
|
|
; check for a specific nibble sequence
|
|
; ("F7 F6 EF EE AB") that is used by a
|
|
; whole-track protection scheme
|
|
;
|
|
; in slot 6, drive 1 is on track to test
|
|
; out C clear if sequence was found
|
|
; C set if sequence was not found
|
|
;-------------------------------
|
|
IsF7F6
|
|
lda $C0E9
|
|
lda #$00
|
|
jsr WAIT
|
|
tay
|
|
lda #$19
|
|
sta nibcount
|
|
- jsr ReadNib
|
|
cmp #$F7
|
|
beq +
|
|
@restart iny
|
|
bne -
|
|
dec nibcount
|
|
bne -
|
|
sec
|
|
beq @driveoff
|
|
+ jsr ReadNib
|
|
cmp #$F6
|
|
bne @restart
|
|
jsr ReadNib
|
|
cmp #$EF
|
|
bne @restart
|
|
jsr ReadNib
|
|
cmp #$EE
|
|
bne @restart
|
|
jsr ReadNib
|
|
cmp #$AB
|
|
bne @restart
|
|
clc
|
|
@driveoff
|
|
lda $C0E8
|
|
rts
|
|
|
|
;-------------------------------
|
|
; SetupF7F6SecondRound
|
|
;
|
|
; Print that we found the F7F6 protection track,
|
|
; then restart the scan so we can search every sector
|
|
; for the protection code.
|
|
; Never returns.
|
|
; Exits via RestartScan.
|
|
;-------------------------------
|
|
SetupF7F6SecondRound
|
|
; Mark in the sector map that we should ignore
|
|
; this protection track the second time around.
|
|
lda checksector+1
|
|
sta @a+1
|
|
lda checksector+2
|
|
sta @a+2
|
|
ldy gSector
|
|
lda #kSectorIgnore
|
|
@a sta $D1D1 ; modifed at runtime
|
|
ldx @a+1
|
|
bne +
|
|
dec @a+2
|
|
+ dec @a+1
|
|
dey
|
|
bpl @a
|
|
lda #s_f7 ; print that we found the protection track
|
|
jsr PrintByID
|
|
lda #TRUE
|
|
sta gIsF7F6 ; set global to activate expensive patcher
|
|
jmp RestartScan
|
|
|
|
;-------------------------------
|
|
; JustTheSameDamnThingOverAndOver
|
|
; check if track has 512 repeated nibbles
|
|
;
|
|
; in slot 6, drive 1 is on track to test
|
|
; out C clear if found
|
|
; C set otherwise
|
|
;-------------------------------
|
|
JustTheSameDamnThingOverAndOver
|
|
lda $C0E9 ; turn on drive motor, but we assume it's already spun up from previous reads so no waiting
|
|
lda #$60
|
|
sta tmp
|
|
lda #$19
|
|
sta unform+1
|
|
ldx #$00
|
|
;
|
|
; Timing-sensitive code! Cycle counts in margin for worst case path
|
|
;
|
|
@reset clv ; 2
|
|
ldy #$00 ; 2
|
|
sta @cmp+1 ; 4
|
|
@loop lda $C0EC ; 4
|
|
bpl @loop ; 2 when not taken
|
|
dex ; 2
|
|
bne @cmp ; 2 when not taken
|
|
dec unform+1 ; 5
|
|
beq @notfound ; 2 when not taken
|
|
@cmp cmp #$d1 ; 2
|
|
bne @reset ; 2 when not taken
|
|
iny ; 2
|
|
bne @loop ; 2 when not taken (3 when taken)
|
|
bvs @found ; 2 when not taken
|
|
bit tmp ; 3 (sets overflow flag)
|
|
bvs @loop ; 3 (always taken)
|
|
@found
|
|
clc
|
|
!byte $24
|
|
@notfound
|
|
sec
|
|
lda $C0E8
|
|
rts
|
|
|
|
;-------------------------------
|
|
; IsUnformatted
|
|
; check if track is unformatted by counting
|
|
; the number of valid nibbles in a row
|
|
;
|
|
; in slot 6, drive 1 is on track to test
|
|
; out C clear if track is unformatted
|
|
; C set if track is formatted
|
|
;-------------------------------
|
|
IsUnformatted
|
|
lda #$FD
|
|
sta gNIBTableFF
|
|
|
|
lda $C0E9 ; turn on drive motor, but we assume it's already spun up from previous reads so no waiting
|
|
lda #$00
|
|
sta unform
|
|
lda #$19
|
|
sta unform+1
|
|
;
|
|
; Timing-sensitive code! Cycle counts in margin for worst case path
|
|
;
|
|
@reset ldy #$00
|
|
@loop ldx $C0EC ; 4
|
|
bpl @loop ; 2 when not taken
|
|
dec unform ; 5
|
|
bne + ; 2 when not taken
|
|
dec unform+1 ; 5
|
|
beq @unformatted;2 when not taken
|
|
+ lda gNIBTable,x; 4
|
|
bmi @reset ; 2 when not taken
|
|
iny ; 2
|
|
bne @loop ; 3 when taken
|
|
sec
|
|
!byte $24
|
|
@unformatted
|
|
clc
|
|
lda $C0E8
|
|
|
|
lda #$3F
|
|
sta gNIBTableFF
|
|
rts
|
|
|
|
;-------------------------------
|
|
; IsEATrack6
|
|
; check if track 6 even exists
|
|
; in the case of EA, track 6 reads as track 5
|
|
;
|
|
; in slot 6, drive 1 is on track to test
|
|
; out C clear if read track does not match expected track
|
|
; C set otherwise
|
|
;-------------------------------
|
|
IsEATrack6
|
|
lda gTrack
|
|
cmp #6
|
|
sec
|
|
bne +
|
|
lda $2E ;DOS read track number
|
|
sbc #5
|
|
cmp #1
|
|
+ rts
|
|
|
|
;-------------------------------
|
|
; ReadNib
|
|
; read a single nibble from S6,D1
|
|
;
|
|
; in: S6,D1 must be spun up and ready to read
|
|
; out: A contains nibble value
|
|
;-------------------------------
|
|
ReadNib
|
|
- lda $C0EC
|
|
bpl -
|
|
rts
|
|
|
|
;-------------------------------
|
|
; Read4x4
|
|
; read a 4-4-encoded value from S6,D1
|
|
;
|
|
; in: S6,D1 must be spun up and ready to read
|
|
; out: A contains decoded value
|
|
; @tmp clobbered
|
|
;-------------------------------
|
|
Read4x4
|
|
- lda $C0EC
|
|
bpl -
|
|
sec
|
|
rol
|
|
sta tmp
|
|
- lda $C0EC
|
|
bpl -
|
|
and tmp
|
|
rts
|