Difference between revisions of "Change Default Battle Theme (Map Flag)"

From Chrono Compendium
Jump to: navigation, search
(Vanilla Bug)
 
Line 37: Line 37:
  
 
<pre>;Starting at C0/1BBF
 
<pre>;Starting at C0/1BBF
LDA $FA A5 FA ;C0/1BBF  Load the map's battle music
+
JML $46/1EFC 5C FC 1E 46 ;C0/1BBF Jump to "Music Check"
STA $1E01 8D 01 1E ;C0/1BC1  Save it to 7E/1E01
+
NOP EA ;C0/1BC3 This byte is never called
CMP $7E/29AE CF AE 29 7E ;C0/1BC4  Compare it to the field music
+
;Music Check
BEQ $1BD5 F0 0C ;C0/1BC8  If they match, treat like the battle was set to not use battle music
+
LDA $FA A5 FA ;46/1EFC Load the battle music index number
JSL $46/1EFC 22 FC 1E 46 ;C0/1BCA  Load new subroutine: relocated code
+
CMP $7E/29AE CF AE 29 7E ;46/1EFE Is it the same as the current song?
JSL $C7/0004 22 04 00 C7 ;C0/1BCE  Load pre-existing subroutine
+
BEQ $1F11 F0 0D ;46/1F02 If so, jump to "Same Song"
PLD 2B
+
CMP $C7/0AE9 CF E9 0A C7 ;46/1F04 Is it outside the maximum song range?
PLB AB
+
BCS $1F11 B0 07 ;46/1F08 If so, jump to "Same Song"
RTL 6B
+
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"
;Relocated code @46/1EFC
+
;Same Song
LDA $14 A9 14
+
LDA #$40 A9 40 ;46/1F11 Flag: Skip Battle Music Transition
STA $1E00 8D 00 1E
+
STA $7E/2A1F 8F 1F 2A 7E ;46/1F13 Save to correct RAM value
LDA $FF A9 FF
+
JML C0/1BD5 5C D5 1B C0 ;46/1417 Process like battle with no music change
STA $1E10 8D 10 1E
+
;Different Song
RTL 6B</pre>
+
LDA #$FF A9 FF ;C0/1BC4 Original code, relocated
 +
STA $1E10 8D 10 1E ;C0/1BC6 Original code, relocated</pre>
  
 
''From'':  [[Modification]]
 
''From'':  [[Modification]]

Latest revision as of 17:46, 12 December 2022

General Information

Chrono Trigger

Thanks to PowerPanda

What makes this possible: Chrono Trigger does something rather odd in its code. Rather than direct-referencing the ROM for what the random battle theme is, it instead loads the theme's Index # into a RAM Byte (7E/01FA), and refreshes this value on every map load.

I have taken advantage of that and put in a hook that checks the Map Index # against a lookup table, allowing you to define a different random battle theme on a map-by-map basis. While many of the maps in the game do not have any random battles, they are included anyway to make this ASM compatible with any future romhack.

At C0/0C58 (00x0C58), the following code is in the base rom:
A9 45      LDA #$45      ;Load song $45 - Battle 1
85 FA      STA 7E/01FA   ;Write song to the "current battle theme" RAM byte

You will want to replace those 4 bytes with the following: 22 ?? ?? ?? JSL !freespace  ;Jump to the new subroutine

Then, in the freespace area, add this code: !freespace DA PHX Store the old X value, to be safe AE 00 01 LDX $7E/0100 Load the current map number to X BF ?? ?? ?? LDA,X !battletable Look up map's battle theme in the battle table 85 FA STA $7E/01FA Save "Current battle theme" FA PLX Retrieve the old X value 6B RTL Return

!battletable [This table consists of $200 bytes, one corresponding to each map)</pre>

Vanilla Bug

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.

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.

;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

From: Modification