Merge pull request #40 from peterferrie/master

support some Sierra 13-sector protections
This commit is contained in:
4am 2017-12-04 09:37:40 -05:00 committed by GitHub
commit 283fa4ce8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 190 additions and 31 deletions

View File

@ -49,6 +49,11 @@
; compile-time flag, no way to change at runtime
FIRSTFILTER
;gIsSierra13
!byte FALSE ; 0=true, 1=false
; reset before each operation
; set in sierra13 patcher after patching
; used to avoid an expensive search
;gIsDatasoft
!byte FALSE ; 0=true, 1=false
; reset before each operation

View File

@ -79,9 +79,10 @@ gIsMilliken1 = gIs8b3-$01 ; byte
gAdventureInternational = gIsMilliken1-$01 ; byte
gIsLaureate = gAdventureInternational-$01 ; byte
gIsDatasoft = gIsLaureate-$01 ; byte
gIsSierra13 = gIsDatasoft-$01 ; byte
;LASTFILTER ; add new gIs* above this line
gOnAClearDayYouCanReadForever = gIsDatasoft-$01 ; byte
gOnAClearDayYouCanReadForever = gIsSierra13-$01 ; byte
gUsingRAMDisk = gOnAClearDayYouCanReadForever-$01 ; byte
gRAMDiskRef = gUsingRAMDisk-$01 ; byte
gDisplayBytes = gRAMDiskRef-$0A ; 10 bytes
@ -139,6 +140,7 @@ ConstructStandardDelivery = jConstructStandardDelivery
!warn "gAdventureInternational=",gAdventureInternational
!warn "gIsLaureate=",gIsLaureate
!warn "gIsDatasoft=",gIsDatasoft
!warn "gIsSierra13=",gIsSierra13
!warn "gOnAClearDayYouCanReadForever=",gOnAClearDayYouCanReadForever
!warn "gUsingRAMDisk=",gUsingRAMDisk
!warn "gRAMDiskRef=",gRAMDiskRef

View File

@ -362,53 +362,51 @@ checksector
jsr SwitchToUniv
+ jsr ReadSector
bcc nextsector
pla
pha
;
; Uh oh, we got a read error. But do we care?
; Maybe we marked this sector as optional based
; on markers in the bootloader.
;
cmp #kSectorOptional
beq .optional
;
; (13-sector only)
; If we just got to this track, check for whole-track protections.
;
ldx #$0F ;16-sector
lda gIsDOS32
bne +
lda gSector
cmp #$0C
beq .tryskip
;
; If we're in the middle of a track, try switching to the
; universal RWTS and see if that helps. (Many disks contain
; an RWTS that can't read the early tracks or sectors that
; contain the RWTS code, since those are loaded by the
; disk controller firmware.)
;
+ lda gSector
cmp #$0F
bne .tryuniversal
;
; We just got to this track, so check for a variety
; of whole-track conditions that might indicate we should
; just skip the entire track
.tryskip
sta .sub+1
ldx #$0C ;13-sector
+ cpx gSector
bne .checkoptional
stx .sub+1
jsr SkipTrack
bcs .tryuniversal
bcs .checkoptional
; Skip this track (we already printed the reason)
lda #$00
jsr ChangeSector
lda checksector+1
sec
.sub sbc #$0F
.sub sbc #$0F ;self-modified according to sectors per track
sta checksector+1
bcs +
dec checksector+2
+ jmp nextsector
; do this only *after* checking for track-skip
; to avoid fatal errors on unformatted tracks
.checkoptional
pla
pha
;
; Maybe we marked this sector as optional based
; on markers in the bootloader.
;
cmp #kSectorOptional
beq .optional
;
; Otherwise we're in the middle of a track, so try switching to
; the universal RWTS and see if that helps. (Many disks contain
; an RWTS that can't read the early tracks or sectors that
; contain the RWTS code, since those are loaded by the
; disk controller firmware.)
;
.tryuniversal
lda gIsDOS32 ; is this a DOS 3.2 disk?
beq .fatal ; yes, so read error is fatal
@ -710,6 +708,7 @@ _applyToAll
!source "patchers/jmpb4bb.a" ; T02 only
!source "patchers/dos32muse.a" ; T01 && gIsDOS32 only
!source "patchers/sra.a" ; gIsDOS32 or gIsRWTS only
!source "patchers/sierra13.a" ; gIsDOS32 only
lda gPatchCount
beq .nopatches

153
src/patchers/sierra13.a Normal file
View File

@ -0,0 +1,153 @@
;-------------------------------
; #SIERRA13
; search and disable a self-decrypting
; protection check used on some Sierra
; disks
;
; Cranston Manor
; Jawbreaker ][
; Missile Defense
; Pegasus ][
; Threshold
;
; module by qkumba
;-------------------------------
!zone {
lda gIsDOS32
bne .jmpexit
;Cranston Manor/Wizard and the Princess
;secondary protection
ldy #10
jsr SearchTrack
!byte $A9,$24 ;LDA #$24
!byte $8D,$1E,$B9 ;STA $B91E
!byte $A9,$00 ;LDA #$00
!byte $8D,$7F,$89 ;STA $897F
bcs +
inx
inx ;patch the STA
ldy #$01
jsr modify
!byte $AD ;LDA
.jmpexit
jmp .exit
;Cranston Manor/Wizard and the Princess
;tertiary protection
+ ldy #10
jsr SearchTrack
!byte $A9,$1E ;LDA #$1E
!byte $8D,$7D,$BE ;STA $BE7D
!byte $A9,$BA ;LDA #$BA
!byte $8D,$7E,$BE ;STA $BE7E
bcs +
pha
tay
txa
pha
tya
pha
txa
pha
tya
ldy #10
jsr modify
!byte $A9,$A0 ;LDA #$A0
!byte $8D,$8C,$BE ;STA $BE8C
!byte $A9,$B9 ;LDA #$B9
!byte $8D,$8D,$BE ;STA $BE8D
pla
sec
sbc #$0B
tax
pla
ldy #8
jsr compare
!byte $8D,$7D,$BE ;STA $BE7D
!byte $A9,$6B ;LDA #$6B
!byte $8D,$7E,$BE ;STA $BE7E
bcs ++
ldy #8
jsr modify
!byte $8D,$8C,$BE ;STA $BE8C
!byte $A9,$6B ;LDA #$6B
!byte $8D,$8D,$BE ;STA $BE8D
++ pla
clc
adc #$48
tax
pla
ldy #2
jsr modify
!byte $A0,$B9
jmp .exit
;Missile Defense
+ ldy #17
jsr SearchTrack
!byte $20,$00,$8F ;JSR $8F00
!byte $20,$00,$90 ;JSR $9000
!byte $20,$00,$8F ;JSR $8F00
!byte $A9,$00 ;LDA #$00
!byte $85,$03 ;STA $03
!byte $A9,$20 ;LDA #$20
!byte $85,$02 ;STA $02
bcs +
pha
lda #s_sierra
jsr PrintByID
pla
inx
inx
inx ;patch the second JSR
ldy #$01
jsr modify
!byte $2C ;LDA
jmp .exit
;Cranston Manor, etc.
+ ldy #14
jsr SearchTrack
!byte $A0,$00 ;LDY #$00
!byte $A9,$55 ;LDA #$55
!byte $59,WILDCARD,WILDCARD ;EOR $xxxx,Y
!byte $99,WILDCARD,WILDCARD ;STA $xxxx,Y
!byte $88 ;DEY
!byte $D0,$F5 ;BNE *-9
!byte $EA ;NOP
bcs .exit
cpx #$50
bcc +
tay
dey ;Pegasus code spans pages
tya
clc
+ sta .adjust+1
adc #BASEPAGE
pha
lda #s_sierra
jsr PrintByID
pla
ldy #8
jsr SearchSector
!byte $85,WILDCARD ;encoded BNE *+xx
!byte $DD ;encoded DEY
!byte WILDCARD,$A0 ;encoded Bxx *-9
!byte $E8,$DD,$95 ;encoded LDA $C088,X
bcs .exit
inx
.adjust lda #$d1
ldy #$01
jsr modify
!byte $55 ;encoded zero
lda #TRUE
sta gIsSierra13
.exit
}