there are no words for what I just did

This commit is contained in:
Peter Ferrie 2020-02-28 15:33:10 -08:00
parent 2c11528172
commit 6f70a34940
12 changed files with 303 additions and 153 deletions

View File

@ -40,7 +40,6 @@ FirstMover
;------------------------------------------------------------------------------
Reenter
cld
cli
ldx #$ff
txs ; so that we never trash the reset vector
jsr SwitchToBank2
@ -49,15 +48,17 @@ Reenter
jsr CloseHandles ; close any open handles to restore ProRWTS
ldx #5
- lda ResetVector,x ; copy reentry wrapper to bottom of stack
sta $100,x ; (used as reset vector because ][+ always
sta $100,x ; (used as reset vector because //e always
dex ; switches to ROM on Ctrl-Reset)
bpl -
inx
stx $3F2 ; page 3 reset vector to ($100)
sei
stx $3FE ; page 3 IRQ vector to ($100)
inx
stx $3F3
stx $3FF
cli
stx $3F3
ldx #$A4
stx $3F4
RestoreStackNextTime
@ -128,10 +129,10 @@ SwitchToBank2
rts
!source "src/prodos.path.a" ; paths end up on the same page
; MockingboardSlot (label is in constants.a so prelaunchers can use it)
; slot number where Mockingboard was detected + $C0
; MockingboardStuff (label is in constants.a so prelaunchers can use it)
; slot number where Mockingboard was detected and type of board
; #$00 if no Mockingboard detected
!byte $FD ; MockingboardSlot ($FFF8)
!byte $FD ; MockingboardStuff ($FFF8)
; MachineStatus (label is in constants.a so prelaunchers can use it)
; 7 6 5 4 3 2 1 0
; | | | | | | | +- bit 0 reserved

View File

@ -168,8 +168,8 @@
bpl -
jsr DisableAccelerator ; cycle counting requires 1MHz
jsr GetMockingboardSlot
stx MockingboardSlot ; save mockingboard slot in LC RAM
jsr GetMockingboardStuff
stx MockingboardStuff ; save mockingboard slot and type in LC RAM
jsr EnableAccelerator
jmp OneTimeSetup

View File

@ -109,7 +109,10 @@ gVal = $1F81
; LC RAM 1
gCheatsAvailable = $D000 ; master cheats table, indexed by game index in gGamesListStore
; 1 byte per game, so max size = 256 games
MockingboardSlot = $FFF8
MockingboardStuff = $FFF8 ; bit 7 = 1 if speech chip present (Mockingboard "C")
; bit 6 = 1 if Mockingboard "B" (stereo) found (else Mockingboard "A")
; bit 4-5 unused
; bits 0-3: slot number
MachineStatus = $FFF9
; LC RAM 2

View File

@ -1,12 +1,12 @@
;license:MIT
; By Andrew Roughan
;(c) 2019-20 by Andrew Roughan, qkumba
; in the style of 4am for Total Replay
;
; Mockingboard support functions
;
;------------------------------------------------------------------------------
; GetMockingboardSlot
; GetMockingboardStuff
; detect Mockingboard card by searching for 6522 timers across all slots 7->1
; access 6522 timers with deterministic cycle counts
;
@ -17,24 +17,25 @@
; in: none
; accelerators should be off
; out:
; if card was found, X = #$Cn where n is the slot number of the card, otherwise #$00
; if card was found, X = #$?n where n is the slot number of the card, otherwise #$00
; and bit 6 = 0 if Mockingboard Sound I found
; or bit 6 = 1 if Mockingboard Sound II or "A" found
; and bit 7 = 1 if Mockingboard Sound/Speech I or "C" found
; flags clobbered
; zp $80-$82 clobbered
; A/Y clobbered
;------------------------------------------------------------------------------
GetMockingboardSlot
GetMockingboardStuff
lda #$00
sta $80
sta $82 ; type
ldx #$C7
@slotLoop
stx $81
ldy #$04 ; 6522 #1 $Cx04
jsr timercheck
bne @nextSlot
ldy #$84 ; 6522 #2 $Cx84
jsr timercheck
bne @nextSlot
rts ; found
jsr @timercheck
beq @foundI
@nextSlot
dex
cpx #$C0
@ -42,13 +43,126 @@ GetMockingboardSlot
ldx #$00 ; not found
rts
timercheck
lda ($80),y ; read 6522 timer low byte
sta $82
lda ($80),y ; second time
@foundI ; sound I or better
ldy #$84 ; 6522 #2 $Cx84
jsr @timercheck
beq @foundII
ldy #$0c
sty @mb_smc3 + 1
iny
sty @mb_smc8 + 1
iny
sty @mb_smc7 + 1
sty @mb_smc11 + 1
+HIDE_NEXT_2_BYTES
@foundII ;stereo
ror $82
lda $81
sta @mb_smc1 + 2
sta @mb_smc2 + 2
sta @mb_smc3 + 2
sta @mb_smc4 + 2
sta @mb_smc5 + 2
sta @mb_smc6 + 2
sta @mb_smc7 + 2
sta @mb_smc8 + 2
sta @mb_smc9 + 2
sta @mb_smc10 + 2
sta @mb_smc11 + 2
sta @mb_smc12 + 2
sta @mb_smc13 + 2
; detect speech chip
sei
lda #<@mb_irq
sta $3fe
sta $fffe
lda #>@mb_irq
sta $3ff
sta $ffff
lda #0
@mb_smc1
sta $c403
@mb_smc2
sta $c402
lda #$0c
@mb_smc3
sta $c48c
lda #$80
@mb_smc4
sta $c443
lda #$c0
@mb_smc5
sta $c440
lda #$70
@mb_smc6
sta $c443
lda #$82
@mb_smc7
sta $c48e
ldx #0
ldy #0
sec
sbc $82
cmp #$F8 ; looking for (-)8 cycles between reads
cli
@wait_irq
lda $80
bne @got_irq
iny
bne @wait_irq
inx
bne @wait_irq
clc
@got_irq
sei
ror $82
@onlyI
lda $81
and #7
ora $82
tax
lda #<Ignore
sta $fffe
lda #>Ignore
sta $ffff
rts ; found
@timercheck
sec
lda ($80),y ; read 6522 timer low byte
sbc ($80),y ; second time
cmp #5 ; looking for (-)8 cycles between reads
beq +
cmp #$F7 ; FastChip //e clock is different
cmp #6 ; FastChip //e clock is different
+ rts
@mb_irq
lda #2
@mb_smc8
sta $c48d
lda #0
@mb_smc9
sta $c440
lda #$70
@mb_smc10
sta $c443
sta $80
lda #2
@mb_smc11
sta $c48e
lda #$ff
@mb_smc12
sta $c403
lda #7
@mb_smc13
sta $c402
lda $45
rti

View File

@ -167,19 +167,38 @@
+READ_ROM_NO_WRITE
}
!macro GET_MOCKINGBOARD_SLOT {
!macro GET_MOCKINGBOARD_SPEECH { ;carry set if present
+READ_RAM2_NO_WRITE
ldx MockingboardSlot
lda MockingboardStuff
asl
+READ_ROM_NO_WRITE
}
!macro GET_MACHINE_STATUS_AND_MOCKINGBOARD_SLOT {
!macro GET_MOCKINGBOARD_SPEECH_AND_MACHINE_STATUS { ;carry set if present
+READ_RAM2_NO_WRITE
lda MockingboardStuff
asl
lda MachineStatus
ldx MockingboardSlot
+READ_ROM_NO_WRITE
}
!macro GET_MOCKINGBOARD_SLOT { ;carry set if present
+READ_RAM2_NO_WRITE
lda MockingboardStuff
cmp #1
ora #$C0
+READ_ROM_NO_WRITE
}
!macro GET_MOCKINGBOARD_SLOT_AND_MACHINE_STATUS { ;carry set if present
+READ_RAM2_NO_WRITE
lda MockingboardStuff
cmp #1
ora #$C0
tax
lda MachineStatus
+READ_ROM_NO_WRITE
}
!macro USES_TEXT_PAGE_2 {
lda ROM_MACHINEID
cmp #$06

View File

@ -12,9 +12,11 @@
sta $2027
jsr $2000 ; decompress
callback
+GET_MACHINE_STATUS
and #CHEATS_ENABLED
+GET_MOCKINGBOARD_SPEECH_AND_MACHINE_STATUS
bcs +
ldy #$60
sty $8FE6 ; no speech chip, pretend no MB
+ and #CHEATS_ENABLED
beq +
lda #$a5
sta $A22 ; patch - don't decrease lives

View File

@ -1,6 +1,5 @@
;license:MIT
;(c) 2019 by qkumba
;mockingboard patch by Andrew Roughan
;(c) 2019-2020 by qkumba
!cpu 6502
!to "build/PRELAUNCH/BERZAP",plain
@ -9,83 +8,46 @@
!source "src/prelaunch/common.a"
+ENABLE_ACCEL
lda #<cheat1
lda #<callback1
sta $871
lda #>cheat1
lda #>callback1
sta $872
jmp $800 ; decompress
cheat1
callback1
lda #$4c
sta $b20b
lda #<cheat2
lda #<callback2
sta $b20c
lda #>cheat2
lda #>callback2
sta $b20d
jmp $b000
cheat2
+GET_MACHINE_STATUS_AND_MOCKINGBOARD_SLOT
and #CHEATS_ENABLED
beq +
lda #$ad
sta $3d94 ; patch - don't decrease lives
sta $6573 ; patch - don't increase lives
sta $76ba ; patch - don't increase lives
callback2
lda #0
sta $b20c
lda #2
sta $56 ; ldrhi
sta $b20d
+READ_RAM2_WRITE_RAM2
lda $D401
pha
lda $D403
pha
lda #<berzap_mb
ldy #>berzap_mb
jsr $DAF1 ; ahem, LoadFileInternal+4
pla
sta $D403
pla
sta $D401
jsr DisableAccelerator
jmp $200
+ txa
beq skipmb
stx $3FCD ;Replace #$C4 with detected slot
stx $3FD5 ;Page $3F is relocated to $1F
stx $3FE1
stx $3FE6
stx $3FEB
stx $3FF0
stx $AB1D
firstPage
ldy #$32 ;Start scan at first patch $9743
- lda $9711,Y ;Find #$C4's in code (24 locations)
cmp #$C4
bne +
txa
sta $9711,Y ;Replace #$C4 with detected slot
+ iny ;Finish scan at $9811
bne -
secondPage
- lda $9811,Y ;Find #$C4's in code (17 locations)
cmp #$C4
bne +
txa
sta $9811,Y ;Replace #$C4 with detected slot
iny ;Skip next 2 bytes after a match because there is never another match so close
iny
+ iny ;Finish scan at $9911 = (last patch 990E)+3
;Check math: 9911-9743=1CE code length; 00 index end - CE code length = 32 index start
bne -
berzap_mb
!byte 19
!text "PRELAUNCH/BERZAP.MB"
thirdPage
ldy #$7B ;Start scan at first patch $ACE0
- lda $AC65,Y ;Find #$C4's in code (21 locations)
cmp #$C4
bne +
txa
sta $AC65,Y ;Replace #$C4 with detected slot
iny ;Skip next 2 bytes after a match because there is never another match so close
iny
+ iny ;Finish scan at $AD65 = (last patch AD62)+3
;Check math: AD65-ACE0=85 code length; 00 index end - 85 code length = 7B index start
bne -
skipmb
lda #$6C ;Remove patch from code so it is only run once
sta $B20B
lda #$CE
sta $B20C
lda #$B2
sta $B20D
+DISABLE_ACCEL
jmp ($b2ce)
!if * > $1F0 {
!if * > $1C0 {
!error "code is too large, ends at ", *
}

63
src/prelaunch/berzap.mb.a Normal file
View File

@ -0,0 +1,63 @@
;license:MIT
;(c) 2020 by qkumba
!cpu 6502
!to "build/PRELAUNCH/BERZAP.MB",plain
*=$200
!source "src/constants.a" ; no code in these
!source "src/macros.a"
+GET_MOCKINGBOARD_SLOT_AND_MACHINE_STATUS
and #CHEATS_ENABLED
beq ++
php
lda #$ad
ldy $3d94
cpy #$ce
bne +
sta $3d94 ; patch - don't decrease lives
sta $6573 ; patch - don't increase lives
sta $76ba ; patch - don't increase lives
+ ldy $684e
cpy #$ee
bne +
sta $684e ; patch - don't increase lives
sta $735f ; patch - don't increase lives
+ ldy $6a70
cpy #$ee
bne +
sta $6a70 ; patch - don't increase lives
sta $72d7 ; patch - don't increase lives
+ plp
++ bcc skipmb
cpx #$C4
beq skipmb
txa
ldy #0
- ldx $3FCD,Y ;find #$C4s
cpx #$C4
bne +
sta $3FCD,Y ;Replace #$C4 with detected slot
+ ldx $9743,Y ;find #$C4s
cpx #$C4
bne +
sta $9743,Y ;Replace #$C4 with detected slot
+ ldx $988D,Y ;find #$C4s
cpx #$C4
bne +
sta $988D,Y ;Replace #$C4 with detected slot
+ ldx $ACE0,Y ;find #$C4s
cpx #$C4
bne +
sta $ACE0,Y ;Replace #$C4 with detected slot
+ iny
bne -
sta $9A63
sta $9A6B
sta $AB1D
skipmb
jmp ($b2ce)

View File

@ -1,5 +1,5 @@
;license:MIT
;(c) 2019 by qkumba
;(c) 2019-2020 by qkumba
!cpu 6502
!to "build/PRELAUNCH/LANCASTER",plain
@ -7,10 +7,6 @@
!source "src/prelaunch/common.a"
+GET_MACHINE_STATUS_AND_MOCKINGBOARD_SLOT
and #CHEATS_ENABLED
sta cheat+1
stx mbslot+1
lda #<cheat
sta $10da
lda #>cheat
@ -18,29 +14,36 @@
jmp $1000
cheat
lda #0 ; SMC (will be non-zero if cheats are enabled)
beq +
+GET_MOCKINGBOARD_SLOT_AND_MACHINE_STATUS
and #CHEATS_ENABLED
beq mbslot
; lives in $0ED7
lda #$ad
sta $1661
sta $1476
+
mbslot
ldx #0 ; SMC (will be non-zero if mockingboard slot is valid)
beq skipmb
stx $6609 ;Replace #$C4 with configured slot
ldy #$20 ;Start scan at $6720
-
lda $6700,Y ;Find #$C4's (21 locations) in code
cmp #$C4
bne +
bcs +
lda #$60
sta $16A1 ; no MB, don't write to random slot
sta $671A ; no MB, don't write to random slot
bne skipmb
+ cpx #$C4
beq skipmb
stx $6609 ; Replace #$C4 with configured slot
txa
sta $6700,Y ;Replace #$C4 with configured slot
; iny ;potential optimisation to finish quicker
; iny ;not tested
+ iny ;Finish scan at $67FF
bne -
ldy #00
- ldx $16AD,Y ; Find #$C4s
cpx #$C4
bne +
sta $16AD,Y ; Replace #$C4 with configured slot
+ ldx $6720,Y ; Find #$C4s
cpx #$C4
bne +
sta $6720,Y ; Replace #$C4 with configured slot
+ iny
bne -
skipmb
jmp $1000

View File

@ -11,27 +11,6 @@
lda #$60
sta $3D34
jsr $0800 ; decompress
+GET_MOCKINGBOARD_SLOT
txa
beq skipmb
stx $2E5B ;Replace #$C4 with detected slot
stx $2E5E
stx $2E67
stx $2E6A
ldy #$92 ;Start scan at first patch $2F1C
- lda $2E8A,Y ;Find #$C4's in code (20 locations)
cmp #$C4
bne +
txa
sta $2E8A,Y ;Replace #$C4 with detected slot
iny ;Skip next 2 bytes after a match because there is never another match so close
iny
+ iny ;Finish scan at $2F8A = (last patch 2F87)+3
;Check math: 2F8A-2F1C=6E code length; 00 index end - 6E code length = 92 index start
bne -
skipmb
+RESET_VECTOR reset
+DISABLE_ACCEL
jmp $6000 ;612A copies pages 2E & 2F to AE & AF for final location

View File

@ -16,6 +16,11 @@
jsr $BFC8
lda #$4C
sta $4047
+GET_MOCKINGBOARD_SPEECH
bcs +
lda #$60
sta $40FB ; no speech chip, pretend no MB
+
+DISABLE_ACCEL ; otherwise Mockingboard detection fails
lda #0
jsr $4000

View File

@ -1,5 +1,5 @@
;license:MIT
;(c) 2019 by 4am & qkumba
;(c) 2019-2020 by 4am & qkumba
;
; Pseudo-ProDOS environment
;
@ -518,19 +518,18 @@ promote
bit $c083
jmp ProDOS_enter
ProDOS_exit
sta $c082
bmi ProDOS_savedX ;always
!if * != $bf12 {
!error "$BF12 misplaced (",*,")"
}
!word $c1d1, $c2d1, $c3d1, $c4d1, $c5d1, $c6d1, $c7d1
ProDOS_savedX
ldx #$d1
plp
clc
bcc ProDOS_savedY
!if * != $bf13 {
!error "$BF13 misplaced (",*,")"
}
!byte $c1
!word $c2d1, $c3d1, $c4d1, $c5d1, $c6d1, $c7d1
ProDOS_savedY
ldy #$d1
sta $c082
plp
clc
lda #0
rts