passport/src/patchers/555.a
2023-07-27 11:38:16 -07:00

862 lines
17 KiB
Plaintext

;-------------------------------
; #555
; RWTS reads 5 sectors from
; three consecutive half-tracks
;
; module by qkumba
;
; tested on
; - Addition Magician
; - Adventure Double Feature Vol. II
; - Agent USA
; - Algebra
; - Bugbyter
; - Bumble Games v1.3
; - Bumble Games v1.4
; - Bumble Plot v1.1
; - Con-Putation
; - Cosmic Combat
; - Crosscountry Rallye
; - Crush, Crumble and Chomp v1981-06-22
; - Disk Director
; - Drinks On a Disk
; - Friends or Lovers
; - Funbunch College Prep
; - Game of the U.S.
; - Gertrude's Puzzles v1.0
; - Gertrude's Secrets v1.0
; - Guardian
; - Jumble Jet
; - Jumpman
; - Keyboard Golf
; - L.A. Land Monopoly
; - Lazersilk
; - Logic Builders
; - Microzine 3
; - Microzine 4
; - Microzine 5
; - Microzine 6
; - Moptown Parade v1.0
; - Number Stumper
; - Reader Rabbit v1.0
; - Rocky's Boots v1.0
; - Supermap
; - Tales of Discovery
; - Temple of Apshai
; - The Final Frontier
; - The Game Show
; - Trap-a-Zoid
; - Volcanoes
; - Zenith
;-------------------------------
!zone {
Do555
; find entrypoint for second stage
lda $802
cmp #$76
beq .setfixed
cmp #$7A
beq .setfixed2
lda #8
ldy #3
jsr SearchSector
!byte $A9,WILDCARD ; LDA #$xx
!byte $48 ; PHA
lda $801,x
bcc .setpage
lda #8
ldy #4
jsr SearchSector
!byte $45,WILDCARD ; EOR $xx
!byte $91,$26 ; STA ($26),y
lda #4
bcc .setenc
tay
asl
jsr SearchSector
!byte $45,WILDCARD ; EOR $xx
!byte $99,$00 ; STA $xxxx,y
bcs .jmpexit
lda $804,x
.setenc
sec
.setpage
sta .patch+1
bcs .findkey
txa
tay
iny
iny
iny
jsr search
ldy $801,x
iny
lda #0
bcc .setPC
.jmpexit
jmp FatalError
.setfixed
lda #1
!byte $2C
.setfixed2
lda #3
sta .curtrk+1
lda #$FF
sta .cmpsect+1
jmp .dofixed
.findkey
lda #8
ldy #3
jsr SearchSector
!byte $A0,WILDCARD ; LDY #$xx
!byte $A2 ; LDX #$xx
bcs .jmpexit
lda $803,x
ldy #0
.setPC
sta .xorkey+1
sty .initPC+1
.loopsect
inc gSector
jsr ReadSector
bcs .jmpexit
jsr .decode
.initPC
; skip lightly variable init
ldx #0 ; SMC
lda $800,x
cmp #$46
bne .nolsr
inx
inx
.nolsr
lda $800,x
cmp #$A0 ; LDY #$xx
bne .noldy
inx
inx
lda $800,x
cmp #$98 ; TYA
bne .isldy
inx
.isldy
lda #8
ldy #6
jsr CompareMemory
!byte $20,WILDCARD,WILDCARD ; JSR $xxxx
!byte $88 ; DEY
!byte $D0,$FA ; BNE *-4
bcs +
jmp .nohalf
+ jsr CompareMemory
!byte $99,$02,$08 ; STA $802,y
!byte $88 ; DEY
!byte $D0,$FA ; BNE *-4
bcs .loopsect
inx
inx
inx
.skipjsr
inx
inx
inx
.noldy
lda $800,x
cmp #$A9 ; LDA #$xx
bne .nolda
inx
inx
.nolda
lda $800,x
cmp #$20 ; JSR $xxxx
bne .loopsect
lda $802,x
eor .patch+1
bne .skipjsr
sta .curtrk+1
;search for seek routine
;in highly variable main
;so we can count calls to whole-track seek
; static boot tracer!
.skip2jsr
ldy $801,x
lda $800,y
cmp #$A9 ; LDA
bne .maybehalf
lda $803,y
cmp #$0B ; [JMP] $xx0B
beq .incx3
cmp #$20 ; JSR $xxxx
bne .nohalf
lda $808,x
eor .patch+1
bne .nohalf
lda $806,x
cmp #$20 ; JSR $xxxx
bne .nohalf
lda $808,x
eor .patch+1
bne .nohalf
txa
adc #5 ; try the next JSR instead
tax
bcc +
.incx3
inx
inx
inx ; try the next JSR instead
+ inc .curtrk+1
inc .curtrk+1
bne .skip2jsr ; always taken
.maybehalf
lda $801,y
tay
lda $800,y
cmp #$48 ; PHA
beq .foundseek
lda $801,y
tay
lda $800,y
cmp #$E6 ; INC $xx
beq .nohalf
cmp #$48 ; PHA
beq .foundseek2
inc .curtrk+1
lda $801,y
tay
lda $800,y
cmp #$48 ; PHA
beq .foundseek
.jmpexit2
jmp FatalError
.nohalf
lda #$FF
sta .curtrk+1
lda #0
sta .hookseek+1
ldx #$94
lda $801,x
cmp #$B7
bne .not_e7
ldx #$A2
.not_e7
jmp .foundpart
.foundseek2
stx $3A
lda $801,x
tax
lda $803,x
cmp #$A2 ; LDX #$xx
bne .foundseek
ldx $3A
.foundseek
dey
dey
sty .hookseek+1
dey
sty .patch
inc .curtrk+1
lda #8
sta $3B
inx
inx
inx
.walkcode
stx $3A
ldy #0
lda ($3A),y
cmp #$4C ; JMP $xxxx
beq .nohalf
cmp #$AA ; TAX
beq .isldx
cmp #$A2 ; LDX #$xx
bne .tryseek
iny
.isldx
iny
lda ($3A),y
cmp #$20 ; JSR $xxxx
bne .sizeinst
iny
.skipjsr2
iny
.skipjsr1
tya
bne .skipinst ; always
.tryseek
cmp #$20 ; JSR $xxxx
bne .trylda
iny
iny
lda ($3A),y
cmp .patch+1
bne .skipjsr1
dey
lda ($3A),y
tax
cmp .patch
beq .inctrack
lda $800,x
bcs .checkinc
cmp #$20 ; JSR
bne .skipjsr2
lda $801,x
cmp .patch
bne .skipjsr2
beq .inctrack
.checkinc
cmp #$A9
bne .walkcode
inc .curtrk+1
.inctrack
inc .curtrk+1
bne .skipjsr2 ; always
.trylda
ldx $3A
lda $800,x
cmp #$66 ; ROR $xx
bne .sizeinst
lda #$A9 ; LDA #$xx
inx
inx
cmp $800,x
beq .foundpart
inc .curtrk+1
inx
inx
inx
cmp $800,x
beq .foundpart
.sizeinst
ldy #0
lda ($3A),y
jsr $F88E ; INSDS2
lda $2F
.skipinst
sec
adc $3A
tax
bcc .walkcode
jmp FatalError
; success!
; found where the partial tracks start
; read whole tracks to this point
; then the partial tracks
; and then the rest of the disk
.foundpart
stx $3A
jsr IncProgress
.donohalf
lda gSector
sta .cmpsect+1
.dofixed
lda #BASEPAGE
sta gAddress+1
lda #8
ldx #$AD
ldy #4
jsr CompareMemory
!byte $A9,$0F ; LDA #$0F
!byte $85,$3D ; STA $3D
ldx #0
bcs .forwards
ldx #<.forwards3-<.forwards1
.forwards
lda #1
sta .forwards1+1,x
lda #6
sta .forwards1+3,x
txa
eor #<.forwards3-<.forwards1
tax
lda #11
sta .forwards1+1,x
lda #16
sta .forwards1+3,x
.copytracks
ldx #0
stx gSector
ldy #$10
jsr .readwrite
lda gTrack
cmp #1
bne .curtrk
ldx #$AC
stx $BDEF
ldx #$90
stx $BDF2
.curtrk
cmp #00 ; SMC
beq .ispartial
jmp .notpartial
.ispartial
ldy #$CD
sty $BE2B
.forwards1
ldx #1
ldy #6
jsr .readsectors
sec
rol gTrack
dec dct+1 ; half-track stepping!
ldx #6
ldy #11
jsr .readsectors
jsr IncProgress
inc gTrack
lsr gTrack
inc dct+1 ; back to normal
.forwards3
ldx #11
ldy #16
jsr .readsectors
dec gTrack
lda #1
ldx #$44
jsr compare3
!byte $20,$76,$08 ;JSR $0876
bcs .notfixed
jsr modify1
!byte $2C ;BIT
ldx #$64
jsr modify3
!byte $20,$76,$08 ;JSR $0876
.notfixed
lda #$0F
ldx #$38
jsr compare3
!byte $20,$5F,$08 ;JSR $085F
bcs .notfixed2
jsr modify1
!byte $2C ;BIT
ldx #$4B
jsr modify1
!byte $C1
ldx #$C1
ldy #9
jsr modify
!byte $20,$5F,$08 ;JSR $085F
!byte $20,$5F,$08 ;JSR $085F
!byte $4C,$5F,$08 ;JMP $085F
.notfixed2
jsr ReorderLogicalToPhysical
jsr .writesectors
inc gTrack
ldy #$B9
sty $BE2B
.notpartial
lda gTrack
cmp #$23
bcc .jmpcopy
jsr IncProgress
jsr .cleanup
jmp .exit
.jmpcopy
jmp .copytracks
.cancel
jsr .cleanup
jmp Cancel
.readwrite
jsr .readsectors
lda gTrack
bne .writesectors
ldx #2
jsr compare1
!byte $76
bcs .checkfixed2
ldx #$B2
jsr compare
!byte $00
bcc .patchfixed
ldx #$B6
.patchfixed
jsr modify1
!byte 1
ldx #2
.checkfixed2
jsr compare
!byte $7A
bcs .writesectors
ldx #$16
jsr modify4
!byte $1A,$08
!byte $E6,$41 ; INC $41
lda #$0B
ldx #$0D
jsr modify1
!byte $EA
ldx #$64
jsr modify1
!byte $2C ; BIT
ldx #$86
jsr modify4
!byte $8A,$04
!byte $E6,$41 ; INC $41
ldx #$EA
ldy #6
jsr modify
!byte $20,$85,$04 ; JSR $0485
!byte $4C,$85,$04 ; JMP $0485
.writesectors
jsr WriteTrack
jsr IncProgress
lda KEY
bmi .cancel
ldx gTrack
inx
txa
jmp ChangeTrackNW
.maybefatal
ldx $BDF2
jsr .cleanup
lda $478
sta $47E ; restore track number replaced by DOS
cpx #$F0
bne .retryread
lda gError
cmp #$40 ; sector not found
bne .reallyfatal
lda gTrack
cmp .curtrk+1
bcc .jmpnotpatch2 ; cross fingers
rts
.reallyfatal
jmp FatalError
.readsectors
sty .endsector+1
.readsector
txa
jsr ChangeSector
.retryread
jsr ReadSector
bcs .maybefatal
lda gTrack
bne .jmpnotpatch2
lda gSector
.cmpsect
eor #$00 ; SMC
beq .checkpatch
.jmpnotpatch2
jmp .notpatch2
.checkpatch
jsr .decode
ldy #$37
lda ($3E),y
cmp #$41 ; [INC] $41
beq .jnotpatch1
ldy $3A
iny
lda ($3E),y
cmp #$4C
beq .jnotpatch1
tya
clc
adc #$0D
.hookseek
ldy #00 ; SMC
beq .nohook
sta ($3E),y
.nohook
sbc #3
tax
lda $3F
sbc #BASEPAGE
ldy #8
jsr modify
.patch
!byte $00,$04 ; [JSR] $04xx
!byte $B0,$0B ; BCS *+$0D
!byte $E6,$41 ; INC $41
!byte $EA ; NOP
!byte $4C ; JMP $xxxx
ldy .curtrk+1
bpl .skipnohalf
clc
txa
adc #4
sta $3C
lda $3F
sta $3D
ldy #6
jsr SearchSector
!byte $20,WILDCARD,WILDCARD ; JSR $xxxx
!byte $48 ; PHA
!byte $98 ; TYA
!byte $48 ; PHA
stx $3E
ldy #1
lda ($3E),y
ldy #4
sta ($3C),y
ldy #1
lda $3C
sta ($3E),y
iny
lda ($3E),y
ldy #5
sta ($3C),y
lda #0
sta $3E
.jnotpatch1
beq .notpatch1
.skipnohalf
sec
txa
sbc #5
tay
lda #$0F
sta ($3E),y
tya
sbc #9
tay
lda ($3E),y
cmp #$41
bne .notpatch1
lda #$EA
sta ($3E),y
.notpatch1
jsr .decode
.notpatch2
ldx gSector
inx
.endsector
cpx #00 ; SMC
beq .rescanall
jmp .readsector
.rescanpro
clc
.rescanall
php
ldy #12
jsr SearchTrack
!byte $C9,$FF ; CMP #$FF
!byte $D0,WILDCARD ; BNE *+$xx
!byte $EA ; NOP
!byte $BD,$8C,$C0 ; LDA $C08C,X
!byte $10,$FB ; BPL *-3
!byte $C9,$FF ; CMP #$FF
bcs .notadrpro
inx
pha
jsr modify1
!byte $DE
txa
clc
adc #10
tax
pla
jsr modify1
!byte $AA
plp
bcs .rescanpro
!byte $A9 ; mask PLP
.notadrpro
plp
ldy #9
jsr SearchTrack
!byte $BD,$8C,$C0 ; LDA $C08C,X
!byte $10,$FB ; BPL *-3
!byte $C9,$FF ; CMP #$FF
!byte $F0,$02 ; BEQ *+4
bcs .notadrepi
pha
txa
adc #6
tax
pla
jsr modify1
!byte $DE
.notadrepi
ldy #8
jsr SearchTrack
!byte $A9,$20 ; LDA #$20
!byte $D0,$E1 ; BNE *-$1D
!byte $A0,$05 ; LDY #$05
!byte $B1,$48 ; LDA ($48),Y
bcs .novol
inx
inx
inx
jsr modify1
!byte $00
.novol
ldy #5
jsr SearchTrack
!byte $20,$87,$07 ; JSR $0787
!byte $A6,$2B ; LDX $2B
bcs .notfixed3
ldy #5
jsr modify
!byte $20,$89,$07 ; JSR $0789
!byte $E6,$41 ; INC $41
.notfixed3
ldy #8
jsr SearchTrack
!byte $01,$30,$28
!byte $24,$20,$1E
!byte $1D,$1C
bcs .notseek
pha
sec
txa
sbc #$6D
tax
pla
sbc #0
ldy #10
jsr compare
!byte $0A ; ASL
!byte $85,WILDCARD ; STA $xx
!byte $CD,WILDCARD,WILDCARD ; CMP $xxxx
!byte $F0,$53 ; BEQ *+$55
!byte $A9,$00 ; LDA #$00
bcs .notseek
pha
txa
adc #8
tax
pla
jsr modify2
!byte $D0,$73 ; BNE *+$75
pha
clc
txa
adc #$23
tax
pla
jsr modify1
!byte $08
pha
ldy #$15
sec
lda (moddest),y
sbc #4
sta (moddest),y
iny
lda (moddest),y
sbc #0
sta (moddest),y
clc
txa
adc #$4A
tax
pla
adc #0 ; DOS seek spans a page
jsr modify4
!byte $70,$2C,$26
!byte $22
pha
lda (moddest),y
tay
pla
cpy #$70
beq .nocross ; Pollywog seek spans a page
sec
sbc #1
.nocross
inx
inx
inx
inx
ldy #11
jsr modify
!byte $1F,$1E,$1D
!byte $1C
!byte $4A ; LSR
!byte $85,$41 ; STA $41
!byte $A9,$00 ; LDA #$00
!byte $F0,$86 ; BEQ *-$78
.notseek
rts
.decode
ldy #0
- lda ($3E),y
.xorkey
eor #$D1 ; SMC
sta ($3E),y
iny
bne -
rts
.cleanup
lda #1
sta dct+1
lda #$CC
sta $BDEF
lda #$F0
sta $BDF2
lda #$B9
sta $BE2B
lda #$50
sta $47E ; blow away track number to force full recalibration
rts
.exit
jmp Pass
.exit2
}