improve detection of unformatted tracks and nibble count tracks (fixes Thunderbombs, Hi-Res Football, and many others)

This commit is contained in:
4am 2017-12-27 23:53:41 -05:00
parent 1b9a1c847e
commit 9d9146382b
2 changed files with 78 additions and 117 deletions

View File

@ -6,55 +6,37 @@
!zone { !zone {
SkipTrack SkipTrack
; ;
; 1) $EEEF protection track (EEEFBBBAFAAE nibble sequence) ; Electronic Arts protection track?
; [must come first because track would otherwise pass the IsUnformatted test below]
; [speed optimization: only check on track $22]
; ;
.checkeeef jsr IsEATrack6
lda gTrack lda #s_eatrk6
cmp #$22 bcc .print
bne .checkunformat
jsr IsEEEF
bcs .checkunformat
lda #s_eeef
bcc .skiptrack ; always taken
; ;
; 2) unformatted track ; Unformatted track?
; ;
.checkunformat
jsr IsUnformatted jsr IsUnformatted
bcs .checkf7f6 bcs +
+ lda #s_unformat
bcc .skiptrack ; always taken
; ;
; 3) $F7F6 protection track (F7F6EFEAAB nibble sequence) ; $F7F6EFEAAB protection track?
; (initially presents as unformatted, needs separate test because it
; triggers special handling)
; ;
.checkf7f6
jsr IsF7F6 jsr IsF7F6
bcs .checksync lda #s_unformat
bcs .print
lda #s_f7
bit gMode bit gMode
bpl .checksync bpl .print
bvc .checksync bvc .print
; if we're in 'crack' mode, restart the scan to find the protection code ; if we're in 'crack' mode, restart the scan to find the protection code
jmp SetupF7F6SecondRound jmp SetupF7F6SecondRound
; ;
; 4) nibble count track (mostly $FF sync bytes) ; Nibble count track?
; ;
.checksync + jsr JustTheSameDamnThingOverAndOver
jsr IsSyncBytes bcs .donotskip
bcs .checktrack6
lda #s_sync lda #s_sync
bcc .skiptrack ; always taken .print
;
; 5) track simply does not exist (Electronic Arts in particular)
;
.checktrack6
jsr IsEATrack6
bcs .fail
lda #s_eatrk6
; note: execution falls through here
.skiptrack
jsr PrintByID jsr PrintByID
; ;
; Skipping T22 on a ProDOS disk might indicate the presence of a ; Skipping T22 on a ProDOS disk might indicate the presence of a
@ -73,7 +55,7 @@ SkipTrack
sta gPossibleGamco sta gPossibleGamco
+ clc + clc
!byte $24 ; hides next SEC !byte $24 ; hides next SEC
.fail .donotskip
sec sec
rts rts
} }
@ -93,7 +75,7 @@ IsF7F6
lda $C0E9 lda $C0E9
lda #$00 lda #$00
jsr WAIT jsr WAIT
lda #$20 lda #$19
sta nibcount sta nibcount
ldy #$00 ldy #$00
- lda $C0EC - lda $C0EC
@ -162,108 +144,87 @@ SetupF7F6SecondRound
jmp RestartScan jmp RestartScan
;------------------------------- ;-------------------------------
; IsEEEF ; JustTheSameDamnThingOverAndOver
; check for a specific nibble sequence ; check if track has a large sequence of repeated bytes
; ("EE EF BB BA FA AE") that is used by a
; whole-track protection scheme
; ;
; in slot 6, drive 1 is on track to test ; in slot 6, drive 1 is on track to test
; out C clear if sequence was found ; out C clear if found
; C set if sequence was not found ; C set otherwise
;------------------------------- ;-------------------------------
!zone { !zone {
IsEEEF JustTheSameDamnThingOverAndOver
lda $C0E9 lda $C0E9
lda #$00
jsr WAIT jsr WAIT
lda #$20 lda #$19
sta nibcount sta unform+1
ldy #$00 ldx #$00
- lda $C0EC ;
bpl - ; Timing-sensitive code! Cycle counts in margin for worst case path
cmp #$EE ;
beq + .reset ldy #$00 ; 2
.restart iny sta .cmp+1 ; 4
bne - .loop lda $C0EC
dec nibcount bpl .loop ; 3 when not taken
bne - dex ; 2
beq .fail bne .cmp ; 3 when not taken
+ dec unform+1 ; 5
- lda $C0EC beq .notfound ; 3 when not taken
bpl - .cmp cmp #$d1 ; 2
cmp #$EF bne .reset ; 3 when not taken
bne .restart iny ; 2
- lda $C0EC bne .loop ; 2 when taken
bpl -
cmp #$BB
bne .restart
- lda $C0EC
bpl -
cmp #$BA
bne .restart
- lda $C0EC
bpl -
cmp #$FA
bne .restart
- lda $C0EC
bpl -
cmp #$AE
bne .restart
clc clc
!byte $24 ; hides SEC !byte $24
.fail sec .notfound
sec
lda $C0E8 lda $C0E8
rts rts
} }
;-------------------------------
; IsSyncBytes
; check if track is mostly $FF bytes
;
; in slot 6, drive 1 is on track to test
; out C clear if track is mostly just $FF bytes
; C set otherwise
;-------------------------------
IsSyncBytes
lda #$FD
sta gNIBTableFF
jsr IsUnformatted
lda #$3F
sta gNIBTableFF
rts
;------------------------------- ;-------------------------------
; IsUnformatted ; IsUnformatted
; check if track is unformatted ; 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 ; in slot 6, drive 1 is on track to test
; out C clear if track is unformatted ; out C clear if track is unformatted
; C set if track is formatted ; C set if track is formatted
;------------------------------- ;-------------------------------
!zone {
IsUnformatted IsUnformatted
lda #$FD
sta gNIBTableFF
lda $C0E9 lda $C0E9
jsr WAIT
lda #$00 lda #$00
sta unform sta unform
lda #$19
sta unform+1 sta unform+1
jsr WAIT ;
lda #$20 ; Timing-sensitive code! Cycle counts in margin for worst case path
sta nibcount ;
ldy #$00 .reset ldy #$00
nibloop ldx $C0EC .loop ldx $C0EC
bpl nibloop bpl .loop ; 3 when not taken
lda gNIBTable,x dec unform ; 5
bpl + bne + ; 3 when not taken
inc unform dec unform+1 ; 5
bne + beq .unformatted;3 when not taken
inc unform+1 + lda gNIBTable,x; 4
+ iny bmi .reset ; 3 when not taken
bne nibloop iny ; 2
dec nibcount bne .loop ; 2 when taken
bne nibloop sec
!byte $24
.unformatted
clc
lda $C0E8 lda $C0E8
lda #$18
cmp unform+1 lda #$3F
sta gNIBTableFF
rts rts
}
;------------------------------- ;-------------------------------
; xHeredityDog ; xHeredityDog

View File

@ -137,7 +137,7 @@ StringTable
; can be set directly before calling PrintByID. ; can be set directly before calling PrintByID.
; ;
.header .header
!text "Passport by 4am 2017-12-26",$00 !text "Passport by 4am 2017-12-27",$00
.mainmenu .mainmenu
!text "________________________________________",$8D,$8D,$8D,$8D,$8D,$8D,$8D !text "________________________________________",$8D,$8D,$8D,$8D,$8D,$8D,$8D
!text " " !text " "
@ -370,7 +370,7 @@ StringTable
.eatrk6 .eatrk6
!text "T06 Found EA protection track",$8D,$00 !text "T06 Found EA protection track",$8D,$00
.eeef .eeef
!text "T%t Found $EEEFBBBA protection track",$8D,$00 !byte $00
.poke .poke
!text "T%t,S%0 BASIC program POKEs protection",$8D !text "T%t,S%0 BASIC program POKEs protection",$8D
!text "check into memory and CALLs it.",$8D,$00 !text "check into memory and CALLs it.",$8D,$00