Author Topic: ASM: Battle Music Bugfix (aka Meowing Sword Bugfix)  (Read 3592 times)

PowerPanda

  • Guru of Time
  • Earthbound (+15)
  • *
  • Posts: 43
    • View Profile
ASM: Battle Music Bugfix (aka Meowing Sword Bugfix)
« on: December 11, 2022, 12:08:04 am »
This is a vanilla bug that never actually shows up in the original game. As such, it's main use is for hackers and people who want to use my other ASM that allows you to set random battle music on a map-by-map basis. Anyway, the bug is that if your random battle music matches the music already playing on the field, and the battle itself is not set to use the field music, the game never switches sound effect banks. Credit to Reld on this one. I found the bug itself, but he found the cause of the bug.

It's easy to reproduce. In Temporal Flux, set Guardia Forest (Present) to have the field music of "$45 - Battle 1" and get into a random battle. Make sure to bring Frog, not because it's important for recreating the bug, but because his sword strike sound effect gets turned into a cat's meow. 8)

To fix this, we just need to compare the battle music with the field music, and say that if they match the game should treat it like the random battle had the flag set to not use battle music. That flag causes the code to skip to a seperate routine that loads the sound effects, but not the music.

Code: [Select]
;Starting at C0/1BBF
JML $46/1EFC 5C FC 1E 46 ;C0/1BBF Jump to "Music Check"
NOP EA ;C0/1BC3 This byte is never called
;Music Check
LDA $FA A5 FA ;46/1EFC Load the battle music index number
CMP $7E/29AE CF AE 29 7E ;46/1EFE Is it the same as the current song?
BEQ $1F11 F0 0D ;46/1F02 If so, jump to "Same Song"
CMP $C7/0AE9 CF E9 0A C7 ;46/1F04 Is it outside the maximum song range?
BCS $1F11 B0 07 ;46/1F08 If so, jump to "Same Song"
STA $1E01 8D 01 1E ;46/1F0A Save the (different) battle music
JML C0/1BC4 5C C4 1B C0 ;46/1F0D Jump to "Different Song"
;Same Song
LDA #$40 A9 40 ;46/1F11 Flag: Skip Battle Music Transition
STA $7E/2A1F 8F 1F 2A 7E ;46/1F13 Save to correct RAM value
JML C0/1BD5 5C D5 1B C0 ;46/1417 Process like battle with no music change
;Different Song
LDA #$FF A9 FF ;C0/1BC4 Original code, relocated
STA $1E10 8D 10 1E ;C0/1BC6 Original code, relocated
« Last Edit: December 12, 2022, 11:47:18 am by PowerPanda »

ZeaLitY

  • Entity
  • End of Timer (+10000)
  • *
  • Posts: 10797
  • Spring Breeze Dancin'
    • View Profile
    • My Compendium Staff Profile
Re: ASM: Battle Music Bugfix (aka Meowing Sword Bugfix)
« Reply #1 on: December 11, 2022, 01:39:49 am »
Got it added to the Tutorial page.

PowerPanda

  • Guru of Time
  • Earthbound (+15)
  • *
  • Posts: 43
    • View Profile
Re: ASM: Battle Music Bugfix (aka Meowing Sword Bugfix)
« Reply #2 on: December 12, 2022, 11:50:57 am »
Got it added to the Tutorial page.

I ended up re-writing this ASM, based on a suggestion by Reld. I found that even though the music was continuing into the battle, it was still re-setting at the end. Additionally, it wasn't covering use cases where the song # was outside of the allowable range, like setting the battle music to "$FF - Null".

Now, the ASM checks to see if the battle music either matches the field music OR is above the allowable range, and if so, it sets the battle flag for "Use Map Music" as "True", even if your event code didn't specify that.