Port SPC engine patches to ASAR

This commit is contained in:
qwertymodo
2019-11-17 19:26:03 -08:00
parent 6259a813b1
commit 605a344368
3 changed files with 105 additions and 110 deletions

View File

@@ -207,6 +207,9 @@ incsrc stats/main.asm
org $308000 ; bank #$30 org $308000 ; bank #$30
incsrc tables.asm incsrc tables.asm
org $348000
incsrc spc.asm
; uncomment for inverted adjustments ; uncomment for inverted adjustments
;incsrc sandbox.asm ;incsrc sandbox.asm

208
spc.asm
View File

@@ -1,106 +1,102 @@
// Build with bass v15 ; WARNING: THIS CODE IS EXTREMELY FRAGILE
// This code apparently triggers a pathalogical edge case
// which breaks forward labels, necessitating db-style branches macro copybin(source, length)
// but the code is really only for documentation anyway, we're !copycount #= 0
// using a compiled .bps patch for actual patch generation. while !copycount+3 < <length>
dd read4(pctosnes(<source>+!copycount))
architecture wdc65816 !copycount #= !copycount+4
endif
macro rom_seek(variable address) {
origin ((address & $7F0000) >> 1) | (address & $7FFF) while !copycount < <length>
base address db read1(pctosnes(<source>+!copycount))
} !copycount #= !copycount+1
endif
rom_seek($400000) // Pad ROM to 0x200000 endmacro
rom_seek($008901) ;@ pushpc
lda.b #(SPC.IntroSongBank & 0xFF); sta $00 org $008901
lda.b #((SPC.IntroSongBank >> 8) & 0xFF); sta $01 LDA.b #SPCData : STA $00
lda.b #((SPC.IntroSongBank >> 16) & 0xFF); sta $02 LDA.b #SPCData>>8 : STA $01
LDA.b #SPCData>>16 : STA $02
rom_seek($348000) // Seek to ROM offset 0x1A0000 ;@ pullpc
architecture spc700 SPCData:
;@ check bankcross off
namespace SPC { %copybin($0C8000, $7BCA)
constant ENGINE_ENTRYPOINT = $0800
constant NEW_CODE_LENGTH = (EngineStart - NewCodeSection) !SPCEngineStart = $0800
constant CODE_START = (ENGINE_ENTRYPOINT - NEW_CODE_LENGTH) !SPCCodeStart = $07A7
macro spc_seek(variable address) { dw ($0F9E+(!SPCEngineStart-!SPCCodeStart))
origin (address & $FFFF) + (((START & $7F0000) >> 1) | (START & $7FFF)) - CODE_START dw !SPCCodeStart
base address
} ;@ pushpc
;@ pushbase
// Insert the original SPC transfer blocks up to the main engine code
insert IntroSongBank, "alttp.sfc", 0x0C8000, 0x7BCA arch spc700
dw NEW_CODE_LENGTH + $0F9E // New code is prepended to the original upload base !SPCCodeStart
dw CODE_START // of length $0F9E to destination $0800 org $34FBCE;-(!SPCEngineStart-!SPCCodeStart)
NewSPCCode:
START: SpecialCommand_Mute:
spc_seek(CODE_START) CMP A,#$F0 ; The thing we overwrote
if pc() < $0700 { BNE +
error "SPC code out of bounds (PC < $0700)" JMP $0A81 ; SilenceSong
} +
CMP A,#$FA ; New mute command $FA
// Any new code goes here. DON'T DELETE THIS LABEL BNE +
// Labels not forward-declared (e.g. '+/++') don't work here MOV $F4,A
NewCodeSection: MOV A,#$00
MOV $0A4A,A ; $0A49: MOV A,#$70 -> MOV A,#$00
SpecialCommand_Mute: MOV $0AF3,A ; $0AF2: MOV $059,#$C0 -> MOV $059,#$00
cmp #$F0 // The thing we overwrote MOV $0C32,A ; $0C32: MOVW $058,YA -> NOP #2
// bne + MOV $0C33,A
db $D0, $03 MOV A,#$C4 ; $0D19: MOVW $058,YA -> MOV A,$058
jmp $0A81 // SilenceSong MOV $0D19,A
+; cmp #$FA // New mute command $FA MOV A,#$58
// bne + MOV $0D1A,A
db $D0, $1C BRA +++
sta $F4 +
lda #$00 CMP A,#$FB ; New unmute command $FB
sta $0A4A // $0A49: lda #$70 -> lda #$00 BEQ +
sta $0AF3 // $0AF2: MOV $059,#$C0 -> MOV $059,#$00 JMP $0A9D ; NewSongInput
sta $0C32 // $0C32: MOVW $058,YA -> NOP #2 +
sta $0C33 MOV $F4,A
lda #$C4 // $0D19: MOVW $058,YA -> lda $058 MOV A,#$70
sta $0D19 MOV $0A49,A ; $0A49: MOV A,#$70
lda #$58 MOV A,#$C0
sta $0D1A MOV $0AF3,A ; $0AF2: MOV $059,#$C0
// bra ++ MOV A,#$DA
db $2F, $23 MOV $0C32,A ; $0C32: MOVW $058,YA
+; cmp #$FB // New unmute command $FB MOV $0D19,A ; $0D19: MOVW $058,YA
// beq + MOV A,#$58
db $F0, $03 MOV $0C33,A
jmp $0A9D // NewSongInput MOV $0D1A,A
+; sta $F4 +++
lda #$70 CALL $0A81 ; SilenceSong
sta $0A4A // $0A49: lda #$70 - : MOV A,$F4
lda #$C0 BNE -
sta $0AF3 // $0AF2: MOV $059,#$C0 CMP A,$F4
lda #$DA BNE -
sta $0C32 // $0C32: MOVW $058,YA MOV $F4,$00
sta $0D19 // $0D19: MOVW $058,YA RET
lda #$58
sta $0C33 org !SPCEngineStart
sta $0D1A
+; jsr $0A81 // SilenceSong arch 65816
-; lda $F4 SPCEngineStart:
bne - ;@ pullbase
cmp $F4 ;@ pullpc
bne - skip !SPCEngineStart-!SPCCodeStart
str $F4=$00 // ACK the CPU %copybin($0CFBCE, $57B2)
rts SPCEngineEnd:
;@ check bankcross on
EngineStart:
// Upload the main engine, along with the rest of the original transfer block ; Change track 15 (unused) to point to 13 (Death Mountain) so dark woods can be track 15
insert "alttp.sfc", 0x0CFBCE, 0x57B2 org $359F6E ; PC 0x1A9F6E ; SPC $D01C
dw #$2B00 ; Set track 15 pointer to track 13's data
// Hook to check for new special mute commands FA, FB
spc_seek($0A73) // $0A73: CMP A,#$F0 arch spc700
jmp SpecialCommand_Mute org $34FE9A ; PC 0x1A7E9A ; SPC $0A73
nop JMP !SPCCodeStart : NOP
arch 65816
rom_seek($0C8000)
fill 0xD380
} // namespace SPC

View File

@@ -731,10 +731,6 @@ org $06C93B ; PC 0x3493B
PyramidPotion: PyramidPotion:
db #$2C ; #$2C = Green Potion db #$2C ; #$2C = Green Potion
;-------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------
; Change track 15 (unused) to point to 13 (Death Mountain) so dark woods can be track 15
org $1A9F15 ; PC 0xD1F15
dw #$2B00 ; Set track 15 pointer to track 13's data
;--------------------------------------------------------------------------------
org $308140 ; PC 0x180140 - 0x18014A [encrypted] org $308140 ; PC 0x180140 - 0x18014A [encrypted]
HeartPieceOutdoorValues: HeartPieceOutdoorValues:
HeartPiece_Spectacle: HeartPiece_Spectacle: