support SpiraDisc, extend interface

This commit is contained in:
Peter Ferrie 2019-03-09 18:30:04 -08:00
parent a2a0311477
commit 41b1ff94fa
5 changed files with 396 additions and 73 deletions

View File

@ -15,6 +15,12 @@ Tested (Gebelli):
- Russki Duck
- Zenith
Tested (Sierra):
- Frogger
- Jawbreaker ][
- Lunar Leepers
- Pest Patrol
Untested (Gebelli):
- Lazer Silk
@ -30,10 +36,6 @@ Do not work yet:
- Shuffleboard (IDSI)
- Trick Shot (IDSI)
- Quadrant 6112 (Sensible Software)
- Frogger (Sierra)
- Jawbreaker ][ (Sierra)
- Lunar Leepers (Sierra)
- Pest Patrol (Sierra)
- Beer Run (Sirius)
- Gamma Goblins (Sirius)
- Orbitron (Sirius)

View File

@ -40,6 +40,10 @@ TEXT = $FB2F
HOME = $FC58
COUT = $FDED
cmp1 = $F8 ; word
cmp2 = $FA ; word
tmp = $FC ; byte
jsr TEXT
jsr HOME
@ -65,18 +69,13 @@ MainMenu
!byte $04,$00,$00,$00,$00,$00,$00
Boot
ldx #0
- lda Tracer,x
sta $1700,x
inx
bne -
ldx #$00
- lda $C600,x
sta $1600,x
inx
bne -
lda #$00
ldx #$17
lda #<Tracer
ldx #>Tracer
ldy $16F8
cpy #$4C
bne @iigs
@ -96,67 +95,19 @@ Boot
jmp REBOOT
Tracer
!pseudopc $1700 {
; patch code to regain control after it loads 1 sector into $0300
lda #<@callback1
sta $0838
lda #>@callback1
sta $0839
jsr IDAntiM
bcc @jmpboot
jsr IDSpiraDisc
bcc @jmpboot
lda #s_unkboot
jmp PrintByID
@jmpboot
sec ;match boot-time flags and registers
lda #1
ldy #0
ldx #$60
jmp $0801
@callback1
; duplicate bootloader from $0300 to $0200
ldx #$00
- lda $0300,x
sta $0200,x
inx
bne -
; patch bootloader so it reads the pristine copy at $0200
dec $030A
dec $0310
dec $0316
dec $031C
; patch bootloader to regain control after it decrypts itself into $0100
lda #$4C
sta $0325
lda #<@callback2
sta $0326
lda #>@callback2
sta $0327
jmp $0301
@callback2
; patch bootloader to regain control after it loads 4 sectors into $0400
lda #$4C
sta $01FB
lda #<@callback3
sta $01FC
lda #>@callback3
sta $01FD
rts
@callback3
; patch bootloader so it doesn't wipe main memory
lda #$60
sta $04E2
; patch bootloader to regain control after it loads title screen and code into $2000+
lda #$4C
sta $0498
lda #<@callback4
sta $0499
lda #>@callback4
sta $049A
; restore bytes on stack page that we patched earlier because they're checksummed soon
lda #$AE
sta $01FB
lda #$65
sta $01FC
lda #$05
sta $01FD
jmp $01FB
@callback4
; patch bootloader to bypass ROM check at $6300
lda #$60
sta $0421
jmp $0400
}
PrintByID
cmp #STRINGCOUNT
@ -186,11 +137,17 @@ PrintByID
;
s_header = $00
s_mainmenu = $01
STRINGCOUNT = $02
s_bootantim = $02
s_bootspira = $03
s_unkboot = $04
STRINGCOUNT = $05
StringTable
!word @header
!word @mainmenu
!word @bootantim
!word @bootspira
!word @unkboot
@header
!text "Anti-M by 4am 2019-03-09",$00
@ -199,4 +156,18 @@ StringTable
!text $8D,$8D,$8D,$8D,$8D,$8D,$8D,$8D
!text " Insert original disk in slot 6 drive 1",$8D
!text $8D
!text " and press <RETURN> to boot",$00
!text " and press <RETURN> to boot",$8D,$00
@bootantim
!text "Found Anti-M boot sector",$00
@bootspira
!text "Found SpiraDisc boot sector",$00
@unkboot
!text "Unrecognised boot sector",$8D
!text "Exiting",$00
!src "src/compare.a"
!src "src/idantim.a"
!src "src/idspira.a"

227
src/compare.a Normal file
View File

@ -0,0 +1,227 @@
WILDCARD = $97
;-------------------------------
; SearchPages subroutine
; written by qkumba
; search for a string occurring anywhere
; in 16 consecutive pages of memory
; #WILDCARD in search string matches any 1 byte
; (like "." character in regular expressions)
; in: A = page address
; Y = string length
; stack = string to find
; out: C clear if string found
; or set if not found
; If C is clear, then
; A = page where string was found
; X = starting offset where string was found
; all other registers and flags clobbered
;-------------------------------
SearchPages
;set end point for the search
tax
clc
adc #$10
sta .endvalue+1
txa
bne SearchPageImm
;-------------------------------
; SearchPage subroutine
; written by qkumba
; same as SearchPages, but for a single page
; in: A = page address
; Y = string length
; stack = string to find
; out: C clear if string found
; or set if not found
; If C is clear, then
; X = starting offset where string was found
; all other registers and flags clobbered
;-------------------------------
SearchPage
;set end point for the search
tax
inx
stx .endvalue+1
; set high part of initial search position
SearchPageImm
sta search+2
pla
sta match_buffer1+1
sta match_all+1
pla
sta match_buffer1+2
sta match_all+2
tax
sty match_size1+1
sty match_size2+1
; fetch last byte to improve search speed
match_buffer1
lda $d1d1,y ; modified at runtime
sta check_byte1+1
sta check_byte2+1
; set low part of initial search position
tya
dey
sty cont_search+1
; set return address
clc
adc match_buffer1+1
tay
bcc plus01
inx
plus01
txa
pha
tya
pha
; set match position
inc match_all+1
bne plus02
inc match_all+2
plus02
lda #<cont_search-branch_cont-2
sta branch_cont+1
; search...
cont_search
ldy #$d1 ; modified at runtime
search
lda $d100,y ; modified at runtime
iny
beq check_end
check_byte1
cmp #$d1 ; modified at runtime
bne search
; point to first byte
sty cont_search+1
check_match
tya
match_size1
sbc #$d1 ; modified at runtime
sta match_buffer2+1
ldx search+2
bcs plus03
dex
plus03
stx match_buffer2+2
ldy #$00
match_all
lda $d1d1,y ; modified at runtime
cmp #WILDCARD
beq found_wild
match_buffer2
cmp $d1d1,y ; modified at runtime
branch_cont
bne cont_search
found_wild
iny
match_size2
cpy #$d1 ; modified at runtime
bne match_all
; point to start of match
ldx match_buffer2+1
lda match_buffer2+2
clc
rts
; cold path
check_end
inc search+2
ldx search+2
.endvalue
cpx #$D1
bne check_byte1
ldx #<all_done_set-branch_cont-2
stx branch_cont+1
check_byte2
cmp #$d1 ; modified at runtime
beq check_match
all_done_set
sec
rts
;-------------------------------
; compare subroutine
; in: A = page
; X = offset
; Y = string length
; stack = string to compare
; #WILDCARD in search string matches any 1 byte
; (like "." character in regular expressions)
; out: C clear if string matches
; or set if not matched
; A,X unchanged
; Y clobbered
; $tmp zero page clobbered
; $cmp1 zero page clobbered
; $cmp2 zero page clobbered
; stack set to first instruction after string
;-------------------------------
!zone {
compare
CompareMemory
sta cmp1+1
stx cmp1
pla
sta cmp2
pla
sta cmp2+1
tax
tya
clc
adc cmp2
bcc +
inx
+ sta tmp
txa
pha
lda tmp
pha
.cmp
lda (cmp2),y
dey
bmi .success
cmp (cmp1),y
beq .cmp
cmp #WILDCARD
beq .cmp
sec
!byte $24 ; hide CLC
.success clc
lda cmp1+1
ldx cmp1
rts
}

84
src/idantim.a Normal file
View File

@ -0,0 +1,84 @@
IDAntiM
lda #8
ldx #1
ldy #11
jsr compare
!byte $A2,$00 ;LDX #$00
!byte $BD,$00,$08 ;LDA $0800,X
!byte $9D,$00,$02 ;STA $0200,X
!byte $E8 ;INX
!byte $D0,$F7 ;BNE *-7
bcs @exit
lda #s_bootantim
jsr PrintByID
; patch code to regain control after it loads 1 sector into $0300
lda #<@callback1
sta $0838
lda #>@callback1
sta $0839
@exit
rts
@callback1
; duplicate bootloader from $0300 to $0200
ldx #$00
- lda $0300,x
sta $0200,x
inx
bne -
- lda @copysrc,x
sta $1700,x
inx
bne -
; patch bootloader so it reads the pristine copy at $0200
dec $030A
dec $0310
dec $0316
dec $031C
; patch bootloader to regain control after it decrypts itself into $0100
lda #$4C
sta $0325
lda #<@callback2
sta $0326
lda #>@callback2
sta $0327
jmp $0301
@copysrc
!pseudopc $1700 {
@callback2
; patch bootloader to regain control after it loads 4 sectors into $0400
lda #$4C
sta $01FB
lda #<@callback3
sta $01FC
lda #>@callback3
sta $01FD
rts
@callback3
; patch bootloader so it doesn't wipe main memory
lda #$60
sta $04E2
; patch bootloader to regain control after it loads title screen and code into $2000+
lda #$4C
sta $0498
lda #<@callback4
sta $0499
lda #>@callback4
sta $049A
; restore bytes on stack page that we patched earlier because they're checksummed soon
lda #$AE
sta $01FB
lda #$65
sta $01FC
lda #$05
sta $01FD
jmp $01FB
@callback4
; patch bootloader to bypass ROM check at $6300
lda #$60
sta $0421
jmp $0400
}

39
src/idspira.a Normal file
View File

@ -0,0 +1,39 @@
;-------------------------------
; SpiraDisc support
; written by qkumba
; supports:
;
; Frogger
; Jawbreaker ][
; Lunar Leepers
; Pest Patrol
IDSpiraDisc
lda #8
ldx #1
ldy #12
jsr compare
!byte $86,$0A ;STA $0A
!byte $8E,WILDCARD,WILDCARD ;STA $xxxx
!byte $8E,WILDCARD,WILDCARD ;STA $xxxx
!byte $90,$78 ;BCC *+$7A
!byte $D0,$01 ;BNE *+$03
bcs @exit
lda #s_bootspira
jsr PrintByID
; patch code to regain control after it loads sectors into $B500+
lda #<@callback1
sta $0870
lda #>@callback1
sta $0871
@exit
rts
@callback1
; disable ROM checksum-failure branching
lda #0
sta $B845
jmp $B800