From a8248952cc95ac5070bb178896ee87f6d02d1de4 Mon Sep 17 00:00:00 2001 From: MattEqualsCoder Date: Thu, 29 Jun 2023 20:51:24 -0400 Subject: [PATCH 1/4] MSU-1 fixes for SD2SNES/FXPAK --- alttp_sm_combo_randomizer_rom/src/sm/msu.asm | 40 +++++++++++++++++-- alttp_sm_combo_randomizer_rom/src/sram.asm | 4 +- .../src/z3/randomizer/msu.asm | 19 +++------ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/alttp_sm_combo_randomizer_rom/src/sm/msu.asm b/alttp_sm_combo_randomizer_rom/src/sm/msu.asm index 68fe8dd83..95a4a0ff1 100644 --- a/alttp_sm_combo_randomizer_rom/src/sm/msu.asm +++ b/alttp_sm_combo_randomizer_rom/src/sm/msu.asm @@ -82,6 +82,12 @@ macro CheckMSUPresence(labelToJump) BEQ + : jmp : + endmacro +macro CheckMSUPresence16(labelToJump) + lda.w !MSU_ID + cmp.w #$2D53 + BEQ + : jmp : + +endmacro + ; Init MSU and check for missing tracks org $C08564 jsl init_msu1 @@ -91,12 +97,36 @@ org $C08F27 base $808F27 jsr SM_MSU_Main -org $C0FA00 -base $80FA00 +org $C0F900 +base $80F900 init_msu1: + %CheckMSUPresence16(.exit) + + ; Check if SRAM seed data matches ROM seed data. + ; If it does then there's no need to check the track data + ldx #$0000 +.check_seed + lda.l rando_seed_data+$10, x ; Seed guid + cmp.l !SRAM_MSU_SEED_DATA, x + bne .do_init + inx : inx + cpx #$0020 + bne .check_seed + bra .exit + +.do_init jsl MSUInit + ldx #$0000 +.store_seed + lda.l rando_seed_data+$10, x ; Seed guid + sta.l !SRAM_MSU_SEED_DATA, x + inx : inx + cpx #$0020 + bne .store_seed + ; original hooked code +.exit jsl $808261 ; Check for non-corrupt SRAM rtl @@ -242,11 +272,11 @@ SM_MSU_Main: .TryExtended CPX #00 : BNE + TYA - bra .CheckFallbacks + jmp .CheckFallbacks + CPX #$FF : BNE + TYA - bra .OriginalCode + jmp .OriginalCode + PHX @@ -297,6 +327,8 @@ SM_MSU_Main: stz.w !MSU_AUDIO_TRACK_HI .CheckAudioStatus + lda.w !MSU_STATUS : bit.b #!MSU_STATUS_AUDIO_BUSY : bne .CheckAudioStatus + ;; Play the song and add repeat if needed jsr TrackNeedLooping sta.w !MSU_AUDIO_CONTROL diff --git a/alttp_sm_combo_randomizer_rom/src/sram.asm b/alttp_sm_combo_randomizer_rom/src/sram.asm index 4e6872b41..e8a2e4ecd 100644 --- a/alttp_sm_combo_randomizer_rom/src/sram.asm +++ b/alttp_sm_combo_randomizer_rom/src/sram.asm @@ -27,7 +27,9 @@ !SRAM_ALTTP_SPC_BUF = $a17e00 ; to $a17eff !SRAM_ALTTP_STATS_BUF = $a17f00 ; to $a17f47 !SRAM_ALTTP_SMALLKEY_BUF = $a17f50 ; to $a17f5f + !SRAM_MSU_FALLBACK = $a17f60 ; to $a17f7f +!SRAM_MSU_SEED_DATA = $a17f80 ; to $a17f9f !SRAM_RANDOLIVE = $a17700 ; to $a178f0 @@ -45,4 +47,4 @@ !SRAM_MW_ITEMS_SENT_WPTR = $a26682 !SRAM_MW_ITEMS_SENT = $a26700 ; [worldId, itemId, itemIndex] (need unique item index to prevent duping) -!SRAM_MW_SEED_DATA = $a266a0 +!SRAM_MW_SEED_DATA = $a266a0 \ No newline at end of file diff --git a/alttp_sm_combo_randomizer_rom/src/z3/randomizer/msu.asm b/alttp_sm_combo_randomizer_rom/src/z3/randomizer/msu.asm index f5b836ea8..fae728375 100644 --- a/alttp_sm_combo_randomizer_rom/src/z3/randomizer/msu.asm +++ b/alttp_sm_combo_randomizer_rom/src/z3/randomizer/msu.asm @@ -163,7 +163,7 @@ CheckMusicLoadRequest: STA.w MusicControl : STZ.w MusicControlRequest REP #$30 : PLY : PLX : PLA : PLD : PLB : PLP RTL - + .continue LDA.l TournamentSeed : BNE +++ LDA.w MSUPackRequest @@ -243,11 +243,11 @@ CheckMusicLoadRequest: AND.b #$07 : TAY PLA : LSR #3 : TAX LDA.l MSUFallbackTable,X : BEQ .secondary_fallback : CMP.b #$FF : BEQ .mute - + - : CPY #$00 : BEQ + LSR : DEY : BRA - + - + AND.b #$01 : BEQ .secondary_fallback .mute @@ -401,7 +401,7 @@ StoreMusicOnDeath: ;-------------------------------------------------------------------------------- MSUInit: PHP - + SEP #$30 LDA.b #$00 STA.w MSULoadedTrack @@ -421,15 +421,8 @@ MSUInit: REP #$20 - LDA.w MSUID : CMP.w #!VAL_MSU_ID_01 : BEQ + : JMP .done - LDA.w MSUID+2 : CMP.w #!VAL_MSU_ID_23 : BEQ + : JMP .done - LDA.w MSUID+4 : CMP.w #!VAL_MSU_ID_45 : BEQ + : JMP .done - .done - PLP - RTL -+ ; Count the number of available MSU-1 packs LDA.w #$0000 LDX.b #$00 @@ -575,7 +568,7 @@ MSUMain: + LDA.b #!VAL_VOLUME_FULL STA.w TargetVolume - + LDA.w MSUResumeControl : BIT.b #!FLAG_RESUME_FADEIN : BEQ + EOR.b #!FLAG_RESUME_FADEIN : STA.w MSUResumeControl LDA.b #$00 @@ -585,7 +578,7 @@ MSUMain: ++ STA.w CurrentVolume STA.w MSUVOL - + LDA.w CurrentMSUTrack : DEC : PHA AND.b #$07 : TAY PLA : LSR #3 : TAX From 842eafe0fd64d0f3a59e7031651abb866207d67f Mon Sep 17 00:00:00 2001 From: MattEqualsCoder Date: Thu, 29 Jun 2023 21:49:41 -0400 Subject: [PATCH 2/4] Fix credits MSU-1 code for fallback/sd2snes --- alttp_sm_combo_randomizer_rom/src/credits.asm | 22 +++++--- .../src/spc_play.asm | 55 ++++++++----------- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/alttp_sm_combo_randomizer_rom/src/credits.asm b/alttp_sm_combo_randomizer_rom/src/credits.asm index cd71850d4..43a7e89f3 100644 --- a/alttp_sm_combo_randomizer_rom/src/credits.asm +++ b/alttp_sm_combo_randomizer_rom/src/credits.asm @@ -77,18 +77,24 @@ init: lda #$0000 tcd - ; Start SPC song - jsl playmusic + ; Check if MSU-1 is available + lda.w $2002 : cmp.w #$2D53 : bne .playspc - ; If MSU music is previously playing, play the combo credits MSU track + ; Play MSU-1 track 99 if available sep #$30 - lda $2002 : cmp.b #'S' : bne + - lda #99 : sta $2004 : stz $2005 ; Play track 99 - lda #1 : sta $2007 ; Sets the track to not repeat - lda #$FF : sta $2006 ; Set to max volume - + + lda.b #99 : sta.w $2004 : stz.w $2005 + - lda.w $2000 : bit.b #$40 : bne - ; Wait for MSU-1 BUSY + lda.w $2000 : bit.b #$08 : bne .playspc ; Check MSU-1 Track missing otherwise fall back to SPC + lda.b #1 : sta.w $2007 ; Sets the track to not repeat + lda.b #$FF : sta.w $2006 ; Set to max volume + bra .load_graphics + +.playspc + ; Start SPC song + jsl playmusic ; Load credits fonts and palettes into VRAM/CGRAM +.load_graphics %ai16() jsr load_graphics jsr load_tilemap diff --git a/alttp_sm_combo_randomizer_rom/src/spc_play.asm b/alttp_sm_combo_randomizer_rom/src/spc_play.asm index 3f6aeb903..88049a79e 100644 --- a/alttp_sm_combo_randomizer_rom/src/spc_play.asm +++ b/alttp_sm_combo_randomizer_rom/src/spc_play.asm @@ -92,23 +92,17 @@ loadspc: ; Copy $02-ef to SPC RAM ; sendmusicblock $e0 $c002 $0002 $00ee - ; Only begin playing if there is no MSU track playing - sep #$30 - lda $2002 : cmp.b #'S' : beq + - rep #$30 - sep #!A_8BIT - lda #$f6 ; 1 - sta $14 - rep #!A_8BIT - lda #$0002 ; 2 - sta $12 - - rep #!XY_8BIT - ldx #$0002 ; 3 - ldy #$00ee ; 4 - jsr copyblocktospc - + + sep #!A_8BIT + lda #$f6 ; 1 + sta $14 + rep #!A_8BIT + lda #$0002 ; 2 + sta $12 + rep #!XY_8BIT + ldx #$0002 ; 3 + ldy #$00ee ; 4 + jsr copyblocktospc ; sendmusicblock $f6 $0100 $0100 $7f00 sep #!A_8BIT @@ -124,22 +118,17 @@ loadspc: jsr copyblocktospc ; sendmusicblock $f7 $0000 $8000 $7fc0 - ; Only begin playing if there is no MSU track playing - sep #$30 - lda $2002 : cmp.b #'S' : beq + - rep #$30 - sep #!A_8BIT - lda #$f7 ; 1 - sta $14 - rep #!A_8BIT - lda #$0000 ; 2 - sta $12 - - rep #!XY_8BIT - ldx #$8000 ; 3 - ldy #$7fc0 ; 4 - jsr copyblocktospc - + + sep #!A_8BIT + lda #$f7 ; 1 + sta $14 + rep #!A_8BIT + lda #$0000 ; 2 + sta $12 + + rep #!XY_8BIT + ldx #$8000 ; 3 + ldy #$7fc0 ; 4 + jsr copyblocktospc ; Create SPC init code that sets up registers jsr makespcinitcode @@ -453,4 +442,4 @@ credits_sm_spc_data: db $8f, $00, $f3 ; KOFF db $8f, $80, $f1 ; Enable IPL ROM db $5f, $c0, $ff ; jmp $ffc0 - dw $0000, $1500 + dw $0000, $1500 \ No newline at end of file From bf3e55bb96ddfa68e9a78e5b7c302cf5b86aa187 Mon Sep 17 00:00:00 2001 From: MattEqualsCoder Date: Thu, 29 Jun 2023 21:50:27 -0400 Subject: [PATCH 3/4] Mute MSU-1 if credits track is missing --- alttp_sm_combo_randomizer_rom/src/credits.asm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/alttp_sm_combo_randomizer_rom/src/credits.asm b/alttp_sm_combo_randomizer_rom/src/credits.asm index 43a7e89f3..a068f92a3 100644 --- a/alttp_sm_combo_randomizer_rom/src/credits.asm +++ b/alttp_sm_combo_randomizer_rom/src/credits.asm @@ -84,11 +84,16 @@ init: sep #$30 lda.b #99 : sta.w $2004 : stz.w $2005 - lda.w $2000 : bit.b #$40 : bne - ; Wait for MSU-1 BUSY - lda.w $2000 : bit.b #$08 : bne .playspc ; Check MSU-1 Track missing otherwise fall back to SPC + lda.w $2000 : bit.b #$08 : bne .fallback ; Check MSU-1 Track missing otherwise fall back to SPC lda.b #1 : sta.w $2007 ; Sets the track to not repeat lda.b #$FF : sta.w $2006 ; Set to max volume bra .load_graphics +.fallback + ; Mute any currently playing MSU-1 track + stz.w $2007 : stz.w $2006 + stz.w $2004 : stz.w $2005 + .playspc ; Start SPC song jsl playmusic From e3957d0ad0670efb524b7c4464f24a91d7327972 Mon Sep 17 00:00:00 2001 From: MattEqualsCoder Date: Thu, 29 Jun 2023 23:30:08 -0400 Subject: [PATCH 4/4] Adding in built zsm.ips file --- src/Randomizer.App/Patches/zsm.ips | Bin 1453866 -> 1453896 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/Randomizer.App/Patches/zsm.ips b/src/Randomizer.App/Patches/zsm.ips index 3f1e87061af0f26ceeed87eda7a386f9cd835068..c12c5a483713c59602cd5042fc40899b2905deab 100644 GIT binary patch delta 1412 zcmZ`&ZERCj7=BNC+gr-n+KsJS_T_2OjPYT%ImW=Da}Zo+1AfG~OoB7cIK~eJNhCwp z3#1t$g_)6@8J19%H15t-+%&1d%#tQ3_Xp$tbtX87jI9p1$UaZ&uIIMwhZ=A4-1DC2 zdCzmteb0LaZ#G@K+0^|KTKe2uWvX2oK8^}~OJLd(HWB5uO`6%eWvL$^+M-|iP4Zn- zS4~Y#5KtdTF3+*a?;k4{xRT}{dfq-R9cUPDwtaTHT$UQXO4)FiVHVzQE%T{nFJ+3L zRbKa6c|6P%OZnECY0E(Pk=PG4)8=mTl-hHnP~3c(Nq)FZhC$8SOPSOV?p>u6XhIub z-zKlyThAoLt~r%8TB+jFo>TI)U7YJ#T~xa^H!&D=NjQ8#92_m=ah?PdpbEX-dN!dO zBV|2pMYT`8py(RD0-DfxQd%rST1DGH{{Gg0K>92s4CK=~b&0rpVnsVDX4rkEu}5r< z&9eoz$d(vmNw&;%W=aSNOTw10Co&S52}i=2$Vy}2^`e`KiD2j}jV{w5eD|0g=dhz)B=%pGf+wq%T!y55Qckocw4ad(5QLDg*GI zx&T^dx}WAqDIL6nzeBV1tx25knnj^1zYr={E%MkQ$t>SLJ?2V05*ScVV4Y2-PV!3o@+Z&-$a z+Z`Qi&;uTK^afo&h3n94fe+ba zh`tfWo2(s{RD3Fq-L}jR^)IR*`ZWD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