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

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

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: