Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: Gideon Zhi on May 23, 2017, 04:58:14 pm

Title: Looking for a hand with Masoukishin music persistence
Post by: Gideon Zhi on May 23, 2017, 04:58:14 pm
Hi everyone,

I'm hoping for a hand with the Super Robot Wars Gaiden ~ Masoukishin The Lord of Elemental music persistence hack. For an idea of what I'm trying to accomplish, here's the same hack implemented in SRW2: https://www.youtube.com/watch?v=Y6DQpHaw4cg I've been working on this for at least a week and I've made a lot of progress, but I'm sort of stuck.

Generally, the flow looks like this:
Map view, map music playing -> Combat scene initiated: character theme loads -> Combat scene ends, map music restarts [-> Character gains a level, level jingle plays, map music restarts again]

There are three scenarios which need patching:
1) The basic scenario, where the music needs to stay playing after a battle sequence ends. I've hacked this already.
2) A more complicated scenario, where the theme is already playing after #1 and needs to continue to play when the next scene starts (either two characters have the same theme, or it's the enemy turn and a character's been attacked twice in a row)
3) The third scenario is restarting the character theme after the level-up jingle plays.

#1 involved two things: preventing the current theme from stopping, and preventing the map theme from starting. I've accomplished this, but I've been banging my head against #2 for a while now. Hoping to get a fresh pair of eyes on the issue.

I've determined that code 1A is a parameterized music changer, and I *think* 27 is a parameterized wait command. (Feel free to challenging this assumption.)
Special parameters I've identified for 1A:
F4 plays the appropriate character theme
F8/F9 seem to be "stop current track." This is another assumption I'd be fine seeing challenged.

Some further points:
* The game's main instruction loop happens at $00/F10B.
* There's a jump table for each instruction at $00/F558. Each entry is 32 bits; the first 24 are an address, and I think the last 8 are how many parameters it takes.
* Current command gets written to $B6. Parameter(s) get(s) written to $B8+.
* Music load (1A) code is at $01/B90A.
* Wait(?) (27) code is at $01/BAE0.


To accomplish #1 (to help test #2), make the following changes:
Code: [Select]
;eliminate silence track from post-combat music load
org $ECF03B:
  ;db $1A,$F8
  db $27,$00
 
;elimiate map theme load from post-combat music load
org $ECE852:
  ;db $1A,$FC
  db $27,$00

(Before I go any further with this, note that the game mixes lorom and hirom addressing in execution; all the addresses I'm using in org commands are hirom but map correctly in lorom.)

The approach I've taken is as follows:
--When combat starts, write the current character theme to unused memory.
--When combat next starts and the game goes to stop the currently-playing theme, check next character theme against above-written track. If they're equal, do a <wait 0> (27 00) instead.
--When a track is queued to start, check it against currently playing track. If they're equivalent, do a <wait 0> instead.

There's a 1AF9 at hirom EC:EFE2 that I THOUGHT was the command to stop whatever music is playing on the map screen whenever a combat sequence begins, but overwriting it with 2700 causes incredible slowdown in the oncoming fade-out animation. 2701 does basically nothing; the music stops anyway. If I replace it with another music command (say, F191 to play one of the character themes) the music STILL stops but the specified theme plays for a very brief split second before itself stopping. This is where I'm stuck. If I can get the currently-playing music to not stop consistently before the character theme is scheduled to start playing, I'm pretty sure I'll be in a good position to handle the rest of the work.

In summary:
Does 1AF9 in fact stop whatever music is currently playing?
Does anything *else* stop whatever music is currently playing?
Does 27xx behave as a <wait xx> command, or do I have that wrong?

I think I've included enough info in this post; if I'm missing anything please let me know. Thanks, and thanks in advance for any aid!