From bf2b11974823d23f3ff9a563d506b7628e68b0d6 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sat, 16 Dec 2017 14:44:17 -0500 Subject: [PATCH] Fix music in Entrance Randomizer This commit fixes the wrong music when leaving certain caves bug in Entrance Randomizer. The vanilla games decides what music to play when re-entering the overworld in code in `PreOverworld_LoadProperties`. One of the main things the game uses to decide the correct music is the overworld screen being loaded. Obviously that is ideal. But it also sometimes bases its decision on the underworld screen you are leaving. Why would they do that? Well some screens can be re-entered from houses/etc that play at half volume. Nintendo did not want to have the music restart from the begining when leaving those locations, so they explictly coded the non-half-volume locations to set the music for that screen, and let the half music volume cases fall though, and get handled by a special case later in the process. There is a better apporach though. Simply determine what music should be playing for this overworld screen, looking only at the overwold screen index. Then see if "half-volume music" is the last played song command. If so, check what the actual song playing is. If it matches song for the overworld screen we are entering, then play the full volume command. Otherwise play the song for the screen we are entering (which by virtue of being a new song will always play full volume). This patch implements that better approach. It basically moves the music selection code from `PreOverworld_LoadProperties` into the custom code bank, removes the checks for specific underworld locations, and makes sure the last bit of code run before actually setting the music is the one to handle half music, as described above. --- LTTP_RND_GeneralBugfixes.asm | 1 + hooks.asm | 9 ++++ music.asm | 79 ++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 music.asm diff --git a/LTTP_RND_GeneralBugfixes.asm b/LTTP_RND_GeneralBugfixes.asm index ed72c05..c63d121 100644 --- a/LTTP_RND_GeneralBugfixes.asm +++ b/LTTP_RND_GeneralBugfixes.asm @@ -127,6 +127,7 @@ incsrc hardmode.asm incsrc goalitem.asm incsrc compasses.asm incsrc doorframefixes.asm +incsrc music.asm ;incsrc shopkeeper.asm incsrc cuccostorm.asm incsrc roomloading.asm diff --git a/hooks.asm b/hooks.asm index 598d92b..3c2558b 100644 --- a/hooks.asm +++ b/hooks.asm @@ -1943,6 +1943,15 @@ JSL.l WalkDownIntoTavern NOP #1 ;================================================================================ +;================================================================================ +; Music fixes +;-------------------------------------------------------------------------------- +org $0282F4 ; <- Bank02.asm:654 (LDY.b #$58 ...) +JML.l PreOverworld_LoadProperties_ChooseMusic +org $028389 ; <- Bank02.asm:763 +PreOverworld_LoadProperties_SetSong: +;================================================================================ + ;================================================================================ ; Hooks for roomloading.asm ;-------------------------------------------------------------------------------- diff --git a/music.asm b/music.asm new file mode 100644 index 0000000..2f3eeb5 --- /dev/null +++ b/music.asm @@ -0,0 +1,79 @@ +;-------------------------------------------------------------------------------- +PreOverworld_LoadProperties_ChooseMusic: + ; A: scratch space (value never used) + ; Y: set to overworld animated tileset + ; X: set to music track/command id + + LDY.b #$58 ; death mountain animated tileset. + + LDX.b #$02 ; Default light world theme + + LDA $8A : ORA #$40 ; check both light and dark world DM at the same time + CMP.b #$43 : BEQ .endOfLightWorldChecks + CMP.b #$45 : BEQ .endOfLightWorldChecks + CMP.b #$47 : BEQ .endOfLightWorldChecks + + LDY.b #$5A ; Main overworld animated tileset + + ; Skip village and lost woods checks if entering dark world or a special area + LDA $8A : CMP.b #$40 : !BGE .notVillageOrWoods + + LDX.b #$07 ; Default village theme + + ; Check what phase we're in + LDA $7EF3C5 : CMP.b #$03 : !BLT + + LDX.b #$02 ; Default light world theme (phase >=3) + + + + ; Check if we're entering the village + LDA $8A : CMP.b #$18 : BEQ .endOfLightWorldChecks + ; For NA release would we also branch on indexes #$22 #$28 #$29 + + LDX.b #$05 ; Lost woods theme + + ; check if we've pulled from the master sword pedestal + LDA $7EF300 : AND.b #$40 : BEQ + + LDX.b #$02 ; Default light world theme + + + + ; check if we are entering lost woods + LDA $8A : BEQ .endOfLightWorldChecks + + .notVillageOrWoods + ; Use the normal overworld (light world) music + LDX.b #$02 + + ; Check phase ; In phase >= 2 + LDA $7EF3C5 : CMP.b #$02 : !BGE + + ; If phase < 2, play the legend music + LDX.b #$03 + + + + .endOfLightWorldChecks + ; if we are in the light world go ahead and set chosen selection + LDA $7EF3CA : BEQ .lastCheck + + LDX.b #$0D ; dark woods theme + + ; This music is used in dark woods, and dark death mountain + LDA $8A + CMP.b #$40 : BEQ + : CMP.b #$43 : BEQ + : CMP.b #$45 : BEQ + : CMP.b #$47 : BEQ + + LDX.b #$09 ; dark overworld theme + + + + ; Does Link have a moon pearl? + LDA $7EF357 : BNE + + LDX.b #$04 ; bunny theme + + + + .lastCheck + LDA $0132 : CMP.b #$F2 : BNE + + CPX $0130 : BNE + + ; If the last played command ($0132) was half volume (#$F2) + ; and the actual song playing ($0130) is same as the one for this area (X) + ; then play the full volume command (#F3) instead of restarting the song + LDX.b #$F3 + + + + JML.l PreOverworld_LoadProperties_SetSong +;--------------------------------------------------------------------------------