From bf2b11974823d23f3ff9a563d506b7628e68b0d6 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sat, 16 Dec 2017 14:44:17 -0500 Subject: [PATCH 1/4] 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 +;-------------------------------------------------------------------------------- From 55473a4d0117c73ddb07be5484b3edb70ad54c7b Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sat, 16 Dec 2017 14:57:45 -0500 Subject: [PATCH 2/4] GT in Kakariko music fix This fixes music stopping partway up GT when the player encounters a "PsychoSoldier" (MathOnNapkin's name). Both types of this sprite sharethe same audio code. They have code to play special music if chasing link in Kakariko. That is fine in vanilla or item rando, but if they try to play this music in a dungeon located in kakariko, this will cause the music to just stop, because that song is not avaiulable in the dungeon music bank. This patch fixes this by adding an extra check to make sure we are in the overworld before playing this song. --- hooks.asm | 4 ++++ music.asm | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/hooks.asm b/hooks.asm index 3c2558b..636ded4 100644 --- a/hooks.asm +++ b/hooks.asm @@ -1950,6 +1950,10 @@ org $0282F4 ; <- Bank02.asm:654 (LDY.b #$58 ...) JML.l PreOverworld_LoadProperties_ChooseMusic org $028389 ; <- Bank02.asm:763 PreOverworld_LoadProperties_SetSong: +;-------------------------------------------------------------------------------- +org $05CC58 ; <- Bank05.asm:1307 (LDA $040A : CMP.b #$18) +JSL PsychoSolder_MusicCheck +NOP #1 ;================================================================================ ;================================================================================ diff --git a/music.asm b/music.asm index 2f3eeb5..c1d96d0 100644 --- a/music.asm +++ b/music.asm @@ -77,3 +77,13 @@ PreOverworld_LoadProperties_ChooseMusic: JML.l PreOverworld_LoadProperties_SetSong ;-------------------------------------------------------------------------------- + +;-------------------------------------------------------------------------------- +;0 = Is Kakariko Overworld +;1 = Not Kakariko Overworld +PsychoSolder_MusicCheck: + LDA $040A : CMP.b #$18 : BNE .done ; thing we overwrote - check if overworld location is Kakariko + LDA $1B ; Also check that we are outdoors + .done +RTL +;-------------------------------------------------------------------------------- From 29b44e4167e5bd38bdf8677b3ac691c4df58adb1 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sat, 20 Jan 2018 13:05:08 -0500 Subject: [PATCH 3/4] Create a flag to toggle off Fake Worlds Add a new rom flag to disable fake Light/Dark worlds from occurring as a result of underworld travel. (Other methods of fake worlds like YBA Fake Flute are not changed). Entrance Randomizer intends to use this flag to fix the Fake Light world from traveling though sewers when Hyrule Castle is in the dark world, as well as to implement new shuffle modes that involve deliberate cross-world caves without needing to grant pearl and mirror like the current insanity mode does. --- darkworldspawn.asm | 6 ++++++ inventory.asm | 1 + tables.asm | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/darkworldspawn.asm b/darkworldspawn.asm index 9a87948..65e8583 100644 --- a/darkworldspawn.asm +++ b/darkworldspawn.asm @@ -61,6 +61,12 @@ SetDeathWorldChecked: PLA RTL ;-------------------------------------------------------------------------------- +FakeWorldFix: + LDA FixFakeWorld : BEQ + + LDA $8A : AND.b #$40 : STA $7EF3CA + + +RTL +;-------------------------------------------------------------------------------- MasterSwordFollowerClear: LDA $7EF3CC CMP #$0E : BEQ .clear ; clear master sword follower diff --git a/inventory.asm b/inventory.asm index 60abf0e..34e66ad 100644 --- a/inventory.asm +++ b/inventory.asm @@ -830,6 +830,7 @@ RTL ;-------------------------------------------------------------------------------- ClearOWKeys: PHA + JSL.l FakeWorldFix LDA.l GenericKeys : BEQ + PLA : LDA $7EF38B : STA $7EF36F RTL diff --git a/tables.asm b/tables.asm index 045f65b..4626ea9 100644 --- a/tables.asm +++ b/tables.asm @@ -728,6 +728,13 @@ org $308173 ; PC 0x180173 Bob: db #$01 ; #00 = Off - #$01 = On (Default) ;================================================================================ +org $308174 ; PC 0x180174 +; Flag to fix Fake Light World/Fake Dark World as caused by leaving the underworld +; to the other world (As can be caused by EG, Certain underworld clips, or Entance Randomizer). +; Currently, Fake Worlds triggered by other causes like YBA's Fake Flute, are not affected. +FixFakeWorld: +db #$00 ; #00 = Fix Off (Default) - #$01 = Fix On +;================================================================================ org $308190 ; PC 0x180190 TimerStyle: db #$00 ; #$00 = Off (Default) - #$01 Countdown - #$02 = Stopwatch From b3d8c23d8921b6d6eac08a32c3e5160c0d819ffa Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sun, 21 Jan 2018 14:48:16 -0500 Subject: [PATCH 4/4] Add door frame data for the multi-entrance caves. This will support mixing single and multi-entrance caves. I also added the alternate door frame table, which is needed for having single entrance caves at Sanctuary and Hyrule castle. (Added as a table rather than hard coding the ids in order to be more friendly to level editors). Updated the comments and function name to be clear that we are tracking the overworld door id, not the entrance id. Remove the code that attempts to clear the entrance because the code is broken (it lacked a needed ".w" suffix, so xkas miscompiled it) meaning the value was never cleared, which has not caused any issues. Also having the entrance ID around is generally useful. --- doorframefixes.asm | 23 +++++++++-------------- hooks.asm | 5 ++--- tables.asm | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/doorframefixes.asm b/doorframefixes.asm index fef6d2e..921dee5 100644 --- a/doorframefixes.asm +++ b/doorframefixes.asm @@ -3,17 +3,12 @@ ;================================================================================ ;-------------------------------------------------------------------------------- -; StoreLastEntranceID +; StoreLastOverworldDoorID ;-------------------------------------------------------------------------------- -StoreLastEntranceID: - CPX #$003a : BCC .noStore - TXA : SBC #$3a - BRA .done - .noStore - LDA #$00 - .done - STA $7F5099 - LDA $1BBB73, X : STA $010E +StoreLastOverworldDoorID: + TXA : INC + STA $7F5099 + LDA $1BBB73, X : STA $010E RTL ;-------------------------------------------------------------------------------- @@ -24,13 +19,12 @@ CacheDoorFrameData: LDA $7F5099 : BEQ .originalBehaviour DEC : ASL : TAX LDA EntranceDoorFrameTable, X : STA $0696 + LDA EntranceAltDoorFrameTable, X : STA $0698 BRA .done .originalBehaviour LDA $D724, X : STA $0696 - .done STZ $0698 - LDA #$00 - STA $7F5099 + .done RTL ;-------------------------------------------------------------------------------- @@ -39,6 +33,7 @@ RTL ;-------------------------------------------------------------------------------- WalkDownIntoTavern: LDA $7F5099 - CMP #$08 + ; tavern door has index 0x42 (saved off value is incremented by one) + CMP #$43 RTL ;-------------------------------------------------------------------------------- diff --git a/hooks.asm b/hooks.asm index 598d92b..a065440 100644 --- a/hooks.asm +++ b/hooks.asm @@ -1926,12 +1926,12 @@ JSL.l SetOverlayIfLamp ; Overworld Door Frame Overlay Fix ; ; When entering an overworld entrance, if it is an entrance to a simple cave, we -; store the entrance id, then use that (instead of the cave id) to determine the +; store the overworld door id, then use that (instead of the cave id) to determine the ; overlay to draw when leaving the cave again. We also use this value to ; identify the tavern entrance to determine whether link should walk up or down. ;-------------------------------------------------------------------------------- org $1BBD5F ; <- Bank1b.asm:296 (LDA $1BBB73, X : STA $010E) -JSL.l StoreLastEntranceID +JSL.l StoreLastOverworldDoorID NOP #3 ;-------------------------------------------------------------------------------- org $02D754 ; <- Bank02.asm:10847 (LDA $D724, X : STA $0696 : STZ $0698) @@ -1979,4 +1979,3 @@ org $00DF62 ; <- Bank00.asm:4672 (LDX.w #$0000 : LDY.w #$0040) org $00DF6E ; <- A few instructions later, right after JSR Do3To4High16Bit ReloadingFloorsCancel: ;================================================================================ - diff --git a/tables.asm b/tables.asm index 5a6987e..8e0b3bf 100644 --- a/tables.asm +++ b/tables.asm @@ -1288,7 +1288,7 @@ dw #9999 ; Rupee Limit ; $7F5096 - Dialog Offset Pointer Return (Low) ; $7F5097 - Dialog Offset Pointer Return (High) ; $7F5098 - Water Entry Index -; $7F5099 - Last Entered Entrance +; $7F5099 - Last Entered Overworld Door ID ; $7F50A0 - Event Parameter 1 @@ -1331,8 +1331,18 @@ db $83, $21, $EB, $6E, $0A, $71, $B0, $11, $85, $C7, $A1, $FD, $E5, $16, $48, $F db $F2, $23, $2F, $28, $9B, $AA, $AB, $D0, $6A, $9D, $C6, $2D, $00, $FE, $E1, $3F db $A0, $4A, $B8, $4E, $74, $1F, $8E, $A9, $F5, $CD, $60, $91, $DB, $D8, $52, $E2 ;================================================================================ -org $30A100 ; PC 0x182100 - 0x18218C +org $30A100 ; PC 0x182100 - 0x182304 EntranceDoorFrameTable: +; data for multi-entrance caves +dw $0816, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000, $0000, $05cc, $05d4, $0bb6, $0b86 +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 +dw $0000, $0000, $0000 +; simple caves: dw $0000, $0000, $0DE8, $0B98, $14CE, $0000, $1C50, $FFFF dw $1466, $0000, $1AB6, $0B98, $1AB6, $040E, $9C0C, $1530 dw $0A98, $0000, $0000, $0000, $0000, $0000, $0000, $0816 @@ -1342,6 +1352,24 @@ dw $041A, $0000, $091E, $09AC, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000 dw $0000, $0AA8, $07AA, $0000, $0000, $0000, $0000, $0000 dw $0000, $0000, $0000, $0000, $0000, $0000 +EntranceAltDoorFrameTable: +dw $0000, $01aa, $8124, $87be, $8158, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $82be, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, +dw $0000 ;=============================================================================== org $30B000 ; PC 0x183000 - 0x183054 StartingEquipment: @@ -1371,4 +1399,4 @@ db $FF, $AF, $50, $00 db $FF, $27, $0A, $00 db $FF, $12, $F4, $01 db $FF, $FF, $FF, $FF -;================================================================================ \ No newline at end of file +;================================================================================