From 0ab83b3d8ae3ebf6b8a59c76fee59a4d29ad4081 Mon Sep 17 00:00:00 2001 From: 4am Date: Mon, 6 Feb 2017 15:24:49 -0500 Subject: [PATCH] refactor inspect0 and applyglobals, reset globals properly, add support for EEEF protection track, add comments about it all --- src/analyze.a | 153 +++++++++++++++++++++++++++++++++++++-------- src/applyglobals.a | 130 -------------------------------------- src/id/inspect0.a | 151 ++++++++++++++++++++++++++++++++++++++++++-- src/passport.a | 79 ++++++++--------------- src/strings/en.a | 8 ++- 5 files changed, 304 insertions(+), 217 deletions(-) delete mode 100755 src/applyglobals.a diff --git a/src/analyze.a b/src/analyze.a index 93accbc..e9ebb29 100755 --- a/src/analyze.a +++ b/src/analyze.a @@ -1,3 +1,65 @@ +;------------------------------- +; SkipTrack +; out: C clear if we should skip this track +; C set if we should not skip this track +;------------------------------- +!zone { +SkipTrack +; +; 1) $EEEF protection track (EEEFBBBAFAAE nibble sequence) +; [must come first because track would otherwise pass the IsUnformatted test below] +; [speed optimization: only check on track $22] +; +.checkeeef + lda gTrack + cmp #$22 + bne .checkunformat + jsr IsEEEF + bcs .checkunformat + lda #s_eeef + bcc .skiptrack ; always taken +; +; 2) unformatted track +; +.checkunformat + jsr IsUnformatted + bcs .checkf7 + lda #s_unformat + bcc .skiptrack ; always taken +; +; 3) $F7 protection track (F7F6EFEAAB nibble sequence) +; +.checkf7 + jsr IsF7 + bcs .checksync + lda #s_f7 + bcc .skiptrack ; always taken +; +; 4) nibble count track (mostly $FF sync bytes) +; +.checksync + jsr IsSyncBytes + bcs .checktrack6 + lda #s_sync + bcc .skiptrack ; always taken + +; +; 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 + clc + !byte $24 ; hides next SEC +.fail + sec + rts +} + ;------------------------------- ; IsF7 ; check for a specific nibble sequence @@ -24,7 +86,7 @@ IsF7 bne - dec nibcount bne - - beq F7fail + beq .fail + - lda $C0EC bpl - @@ -44,10 +106,66 @@ IsF7 bne .restart clc !byte $24 ; hides SEC -F7fail sec +.fail sec lda $C0E8 rts } + +;------------------------------- +; IsEEEF +; check for a specific nibble sequence +; ("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 +; out C clear if sequence was found +; C set if sequence was not found +;------------------------------- +!zone { +IsEEEF + lda $C0E9 + lda #$00 + jsr WAIT + lda #$20 + sta nibcount + ldy #$00 +- lda $C0EC + bpl - + cmp #$EE + beq + +.restart iny + bne - + dec nibcount + bne - + beq .fail ++ +- lda $C0EC + bpl - + cmp #$EF + bne .restart +- lda $C0EC + 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 + !byte $24 ; hides SEC +.fail sec + lda $C0E8 + rts +} + ;------------------------------- ; IsSyncBytes ; check if track is mostly $FF bytes @@ -114,28 +232,18 @@ xHeredityDog adc #$04 pha ldx #$16 - ldy #$0B - jsr CompareMemory - !byte $F0,$05,$A2,$B2,$4C,$F0,$BB,$BD,$8C,$C0,$A9 - pla - bcc .maybe - jmp .no - -; don't check byte at $BB21 because it can vary - -.maybe - ldx #$22 - ldy #$3E + ldy #$4A jsr CompareMemory + !byte $F0,$05,$A2,$B2,$4C,$F0,$BB,$BD,$8C,$C0,$A9,WILDCARD !byte $8D,$00,$02,$BD,$8C,$C0,$10,$FB,$C9,$EB,$D0,$F7,$BD,$8C !byte $C0,$10,$FB,$C9,$D5,$D0,$EE,$BD,$8C,$C0,$10,$FB,$C9,$AA,$D0,$E5 !byte $A9,$4C,$A0,$00,$99,$00,$95,$88,$D0,$FA,$CE,$46,$BB,$AD,$46,$BB !byte $C9,$07,$D0,$EC,$A9,$18,$8D,$42,$B9,$A9,$0A,$8D,$ED,$B7,$D0,$05 - bcs .no -.yes + pla + bcs .exit lda #$80 sta T00S0A -.no +.exit rts } @@ -187,15 +295,8 @@ xOptimumRes ldx #$5D ldy #$0C jsr CompareMemory - !byte $68,$85,$F0,$68,$85,$F1,$A0,$01 - !byte $B1,$F0,$85,$54 - bcc .yes - lda #$08 - ldx #$5D - ldy #$0C - jsr CompareMemory - !byte $68,$85,$A0,$68,$85,$A1,$A0,$01 - !byte $B1,$A0,$85,$54 + !byte $68,$85,WILDCARD,$68,$85,WILDCARD,$A0,$01 + !byte $B1,WILDCARD,$85,$54 bcs .no .yes lda #$80 diff --git a/src/applyglobals.a b/src/applyglobals.a deleted file mode 100755 index fe29438..0000000 --- a/src/applyglobals.a +++ /dev/null @@ -1,130 +0,0 @@ -; -; initialize some variables that are used by many -; other patchers on track $00 -; -!zone { -ApplyGlobals - lda #$00 - ldx #$00 - ldy #$4A - jsr compare ; if T00,S00,$00 == - -; This needs to be pretty strict because, if it matches, -; we're going to patch the sector and trace it to capture -; the RWTS. - - !byte $01,$A5,$27,$C9,$09,$D0,$18,$A5 - !byte $2B,$4A,$4A,$4A,$4A,$09,$C0,$85 - !byte $3F,$A9,$5C,$85,$3E,$18,$AD,$FE - !byte $08,$6D,$FF,$08,$8D,$FE,$08,$AE - !byte $FF,$08,$30,$15,$BD,$4D,$08,$85 - !byte $3D,$CE,$FF,$08,$AD,$FE,$08,$85 - !byte $27,$CE,$FE,$08,$A6,$2B,$6C,$3E - !byte $00,$EE,$FE,$08,$EE,$FE,$08,$20 - !byte $89,$FE,$20,$93,$FE,$20,$2F,$FB - !byte $A6,$2B - ldx #TRUE - bcc .boot0 - ldx #FALSE -.boot0 - stx gIsBoot0 - - lda #$01 - ldx #$00 - ldy #$38 - jsr compare ; if T00,S01,$00 == - !byte $8E,$E9,$B7,$8E,$F7,$B7,$A9,$01 - !byte $8D,$F8,$B7,$8D,$EA,$B7,$AD,$E0 - !byte $B7,$8D,$E1,$B7,$A9,$02,$8D,$EC - !byte $B7,$A9,$04,$8D,$ED,$B7,$AC,$E7 - !byte $B7,$88,$8C,$F1,$B7,$A9,$01,$8D - !byte $F4,$B7,$8A,$4A,$4A,$4A,$4A,$AA - !byte $A9,$00,$9D,$F8,$04,$9D,$78,$04 - ldx #TRUE - bcc .boot1 - ldx #FALSE -.boot1 - stx gIsBoot1 - - lda #$01 - ldx #$00 - ldy #$38 - jsr compare ; if T00,S01,$00 == - !byte $8E,$E9,$37,$8E,$F7,$37,$A9,$01 - !byte $8D,$F8,$37,$8D,$EA,$37,$AD,$E0 - !byte $37,$8D,$E1,$37,$A9,$02,$8D,$EC - !byte $37,$A9,$04,$8D,$ED,$37,$AC,$E7 - !byte $37,$88,$8C,$F1,$37,$A9,$01,$8D - !byte $F4,$37,$8A,$4A,$4A,$4A,$4A,$AA - !byte $A9,$00,$9D,$F8,$04,$9D,$78,$04 - ldx #TRUE - bcc .master - ldx #FALSE -.master - stx gIsMaster - - lda #$07 - ldx #$00 - ldy #$40 - jsr compare ; if T00,S07,$00 == - !byte $84,$48,$85,$49,$A0,$02,$8C,$F8 - !byte $06,$A0,$04,$8C,$F8,$04,$A0,$01 - !byte $B1,$48,$AA,$A0,$0F,$D1,$48,$F0 - !byte $1B,$8A,$48,$B1,$48,$AA,$68,$48 - !byte $91,$48,$BD,$8E,$C0,$A0,$08,$BD - !byte $8C,$C0,$DD,$8C,$C0,$D0,$F6,$88 - !byte $D0,$F8,$68,$AA,$BD,$8E,$C0,$BD - !byte $8C,$C0,$A0,$08,$BD,$8C,$C0,$48 - ldx #TRUE - bcc .rwts - ldx #FALSE -.rwts - stx gIsRWTS - - lda #$00 - ldx #$00 - ldy #$05 - jsr compare ; if T00,S00,$00 == - -; This abbreviated signature matches all ProDOS disks -; I can find, with no false positives. -; Some disks jump to $08FF at $0804 (SOS entry point). -; Others have a modified T00,S00 but eventually load -; ProDOS (e.g. 1-2-3 Sequence Me, Alge-Blaster Plus, -; Dazzle Draw, SuperPrint II) - - !byte 01,$38,$B0,$03,$4C - ldx #TRUE - bcc .prodos - ldx #FALSE -.prodos - stx gIsProDOS - - lda #$00 - ldx #$00 - ldy #$08 - jsr compare ; if T00,S00,$00 == - -; Apple Pascal signature (version < 1.3) -; The wildcard in 7th position catches alternate jump -; addresses (e.g. Wizardry I, Sundog Frozen Legacy) - - !byte $01,$E0,$60,$F0,$03,$4C,$97,$08 - ldx #TRUE - bcc .pascal - lda #$00 - ldx #$00 - ldy #$08 - jsr compare ; or if T00,S00,$00 == - -; Pascal 1.3 signature [thanks Marco V.] - - !byte $01,$E0,$07,$B0,$04,$E0,$40,$B0 - ldx #TRUE - bcc .pascal - ldx #FALSE -.pascal - stx gIsPascal - - rts -} diff --git a/src/id/inspect0.a b/src/id/inspect0.a index a323d18..f548d2b 100755 --- a/src/id/inspect0.a +++ b/src/id/inspect0.a @@ -1,10 +1,15 @@ ;------------------------------- -; CheckT00S00 +; IDBootloader ; main entry point to identify the bootloader -; based on T00,S00 (currently in memory at $0800) +; and exit via the appropriate tracer/copier +; +; in: T00,S00 in memory at $0800 ;------------------------------- !zone { -CheckT00S00 +IDBootloader + +; reset all per-disk globals + lda #FALSE sta gIsBoot0 sta gIsBoot1 @@ -14,6 +19,8 @@ CheckT00S00 sta gIsPascal sta gIsDatasoft sta gIsProtDOS + sta gIsEA + sta gIsEEEF lda #$00 sta gLastTrack @@ -33,14 +40,81 @@ CheckT00S00 ; ; Copy the boot sector from $0800 to the track/sector buffer ; so we can reuse our standard compare functions. -; (TODO: this is probably unnecessary but I haven't ever -; refactored it since the Post-Demuffin Patcher days.) ; lda #$08 ldx #BASEPAGE ldy #$01 jsr CopyMemory - jsr ApplyGlobals + + lda #$00 + ldx #$00 + ldy #$4A + jsr compare ; if T00,S00,$00 == + +; This needs to be pretty strict because, if it matches, +; we're going to patch the sector and trace it to capture +; the RWTS. + + !byte $01,$A5,$27,$C9,$09,$D0,$18,$A5 + !byte $2B,$4A,$4A,$4A,$4A,$09,$C0,$85 + !byte $3F,$A9,$5C,$85,$3E,$18,$AD,$FE + !byte $08,$6D,$FF,$08,$8D,$FE,$08,$AE + !byte $FF,$08,$30,$15,$BD,$4D,$08,$85 + !byte $3D,$CE,$FF,$08,$AD,$FE,$08,$85 + !byte $27,$CE,$FE,$08,$A6,$2B,$6C,$3E + !byte $00,$EE,$FE,$08,$EE,$FE,$08,$20 + !byte $89,$FE,$20,$93,$FE,$20,$2F,$FB + !byte $A6,$2B + ldx #TRUE + bcc .boot0 + ldx #FALSE +.boot0 + stx gIsBoot0 + + lda #$00 + ldx #$00 + ldy #$05 + jsr compare ; if T00,S00,$00 == + +; This abbreviated signature matches all ProDOS disks +; I can find, with no false positives. +; Some disks jump to $08FF at $0804 (SOS entry point). +; Others have a modified T00,S00 but eventually load +; ProDOS (e.g. 1-2-3 Sequence Me, Alge-Blaster Plus, +; Dazzle Draw, SuperPrint II) + + !byte 01,$38,$B0,$03,$4C + ldx #TRUE + bcc .prodos + ldx #FALSE +.prodos + stx gIsProDOS + + lda #$00 + ldx #$00 + ldy #$08 + jsr compare ; if T00,S00,$00 == + +; Apple Pascal signature (version < 1.3) +; The wildcard in 7th position catches alternate jump +; addresses (e.g. Wizardry I, Sundog Frozen Legacy) + + !byte $01,$E0,$60,$F0,$03,$4C,$97,$08 + ldx #TRUE + bcc .pascal + lda #$00 + ldx #$00 + ldy #$08 + jsr compare ; or if T00,S00,$00 == + +; Pascal 1.3 signature [thanks Marco V.] + + !byte $01,$E0,$07,$B0,$04,$E0,$40,$B0 + ldx #TRUE + bcc .pascal + ldx #FALSE +.pascal + stx gIsPascal ; ; Try to identify DOS 3.3-shaped bootloader, which @@ -158,3 +232,68 @@ CheckT00S00 ; jmp UseUniversal } + +;------------------------------- +; AnalyzeT00 +; set additional flags based on contents of track $00 +; +; in: Track $00 in data buffer +; out: gIsBoot1, gIsMaster, gIsRWTS set to #TRUE or #FALSE +; all flags clobbered +; all registers clobbered +;------------------------------- +!zone { +AnalyzeT00 + lda #$01 + ldx #$00 + ldy #$38 + jsr compare ; if T00,S01,$00 == + !byte $8E,$E9,$B7,$8E,$F7,$B7,$A9,$01 + !byte $8D,$F8,$B7,$8D,$EA,$B7,$AD,$E0 + !byte $B7,$8D,$E1,$B7,$A9,$02,$8D,$EC + !byte $B7,$A9,$04,$8D,$ED,$B7,$AC,$E7 + !byte $B7,$88,$8C,$F1,$B7,$A9,$01,$8D + !byte $F4,$B7,$8A,$4A,$4A,$4A,$4A,$AA + !byte $A9,$00,$9D,$F8,$04,$9D,$78,$04 + ldx #TRUE + bcc .boot1 + ldx #FALSE +.boot1 + stx gIsBoot1 + + lda #$01 + ldx #$00 + ldy #$38 + jsr compare ; if T00,S01,$00 == + !byte $8E,$E9,$37,$8E,$F7,$37,$A9,$01 + !byte $8D,$F8,$37,$8D,$EA,$37,$AD,$E0 + !byte $37,$8D,$E1,$37,$A9,$02,$8D,$EC + !byte $37,$A9,$04,$8D,$ED,$37,$AC,$E7 + !byte $37,$88,$8C,$F1,$37,$A9,$01,$8D + !byte $F4,$37,$8A,$4A,$4A,$4A,$4A,$AA + !byte $A9,$00,$9D,$F8,$04,$9D,$78,$04 + ldx #TRUE + bcc .master + ldx #FALSE +.master + stx gIsMaster + + lda #$07 + ldx #$00 + ldy #$40 + jsr compare ; if T00,S07,$00 == + !byte $84,$48,$85,$49,$A0,$02,$8C,$F8 + !byte $06,$A0,$04,$8C,$F8,$04,$A0,$01 + !byte $B1,$48,$AA,$A0,$0F,$D1,$48,$F0 + !byte $1B,$8A,$48,$B1,$48,$AA,$68,$48 + !byte $91,$48,$BD,$8E,$C0,$A0,$08,$BD + !byte $8C,$C0,$DD,$8C,$C0,$D0,$F6,$88 + !byte $D0,$F8,$68,$AA,$BD,$8E,$C0,$BD + !byte $8C,$C0,$A0,$08,$BD,$8C,$C0,$48 + ldx #TRUE + bcc .rwts + ldx #FALSE +.rwts + stx gIsRWTS + rts +} diff --git a/src/passport.a b/src/passport.a index 601e20b..1d31afa 100755 --- a/src/passport.a +++ b/src/passport.a @@ -297,7 +297,7 @@ Action jsr PrintByID jmp TheEnd .checkt00s00 - jmp CheckT00S00 ; /src/id/inspect0 + jmp IDBootloader ; /src/id/inspect0 @@ -390,46 +390,13 @@ checksector bne .tryuniversal ; ; We just got to this track, so check for a variety -; of whole-track conditions -; -; 1) unformatted track -; - jsr IsUnformatted - bcs .checkf7 - lda #s_unformat - jsr PrintByID - jmp .skiptrack -; -; 2) $F7 protection track (F7F6EFEAAB nibble sequence) -; -.checkf7 - jsr IsF7 - bcs .checksync - lda #s_f7 - jsr PrintByID - jmp .skiptrack -; -; 3) nibble count track (mostly $FF sync bytes) -; -.checksync - jsr IsSyncBytes - bcs .checktrack6 - lda #s_sync - jsr PrintByID - -; -; 4) track simply does not exist (Electronic Arts in particular) -; -.checktrack6 - jsr IsEATrack6 +; of whole-track conditions that might indicate we should +; just skip the entire track + jsr SkipTrack bcs .tryuniversal - lda #s_eatrk6 - jsr PrintByID -; note: execution falls through here - -.skiptrack - lda #$00 ; skip rest of track +; Skip this track (we already printed the reason) + lda #$00 jsr ChangeSector lda checksector+1 sec @@ -683,7 +650,7 @@ AnalyzeTrack beq _applyToT00 jmp _applyToAll _applyToT00 - jsr ApplyGlobals + jsr AnalyzeT00 ; /src/id/inspect0 !source "patchers/sunburst.a" !source "patchers/jmpbcf0.a" !source "patchers/jmpbeb1.a" @@ -756,41 +723,47 @@ gChangedPrefs ; set to #TRUE when changing slots gLastTrack !byte 00 ; int - ; set after reading T00 + ; the last track that we should try to read + ; (assuming reading from T22 down to T00) + ; reset to 0 before each operation, but some + ; disks (like DOS3.3P) will change it because + ; they write out the first few DOS tracks + ; manually before seeking up to T22 to convert + ; the rest of the disk gIsBoot0 !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00,S00 (see IDBootloader) gIsBoot1 !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00 (see AnalyzeT00) gIsMaster !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00 (see AnalyzeT00) gIsRWTS !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00 (see AnalyzeT00) gIsProDOS !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00,S00 (see IDBootloader) gIsPascal !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00,S00 (see IDBootloader) gIsDatasoft !byte FALSE ; 0=true, 1=false - ; set after reading T00 + ; set after reading T00,S00 (see IDBootloader) gIsProtDOS !byte FALSE ; 0=true, 1=false - ; set after reading T00 - + ; set after reading T00,S00 (see IDBootloader) gIsEA !byte FALSE ; 0=true, 1=false - ; set after reading T00 - + ; set after reading T00,S00 (see IDBootloader) +gIsEEEF + !byte FALSE ; 0=true, 1=false + ; set after reading T22 gOnAClearDayYouCanReadForever !byte FALSE ; 0=true, 1=false ; compile-time flag, no way to change at runtime - !source "applyglobals.a" !source "universalrwts.a" } LastMover diff --git a/src/strings/en.a b/src/strings/en.a index ec89a78..cc34785 100755 --- a/src/strings/en.a +++ b/src/strings/en.a @@ -87,7 +87,8 @@ s_restart = $44 s_corrupter= $45 s_eab0 = $46 s_eatrk6 = $47 -STRINGCOUNT = $48 +s_eeef = $48 +STRINGCOUNT = $49 !zone { StringTable @@ -163,6 +164,7 @@ StringTable !word .corrupter !word .eaboot0 !word .eatrk6 + !word .eeef ; ; Text can contain substitution strings, which ; are replaced by current values at runtime. Each @@ -188,7 +190,7 @@ StringTable ; can be set directly before calling PrintByID. ; .header - !text "Passport by 4am 2017-01-31",00 + !text "Passport by 4am 2017-02-06",00 .mainmenu !text "________________________________________",$8D,$8D,$8D,$8D,$8D,$8D,$8D !text " " @@ -418,4 +420,6 @@ StringTable !text "T00 Found Electronic Arts bootloader",$8D,00 .eatrk6 !text "T06 Found EA protection track",$8D,00 +.eeef + !text "T%t Found $EEEFBBBA protection",$8D,00 }