Pretty neat! Now I just need to get some kind of clue as to how to hook the music....https://www.mesen.ca/docs/hdpacks.html#replacing-audio-in-games
To replace the audio, you need to know when the game is sending the music start signal and the music stop signal to the sound engine of the game, then you need to stop that process and send a signal to special registers which is recognized by Mesen. The emulator will pick up that signal and play a music file instead.
You can either:
1. Hack the ROM so that when the sound engine receives a signal to start or stop music, send a signal to the special registers.
2. Use LUA script instead of hacking the ROM. This is not the official method and the emulator doesn't run the script automatically.
Each game has its own sound engine so you have to study the game you are working on. People who create NSF file will know more about this(http://forums.nesdev.com/viewforum.php?f=6
). For example SMB MEMORY MAP (http://www.romhacking.net/documents/345/
) says $00fb is the RAM address of the queue for primary music. So I wrote a LUA script for replacing the first track in Super Mario Bros and it looks like this:
function playMusic(address, value)
if value == 1 then
emu.write(0x4105, 0, emu.memType.cpu)
emu.addMemoryCallback(playMusic, emu.memCallbackType.cpuWrite, 0xFB)
The script listens for writes to 0xFB (addMemoryCallback), which is where the SMB sound engine picks up the track ID. Then the script calls the playMusic function to process the value of the write. When the track ID is 1, sends value 0 (the ID of the music file to be played by Mesen, matching the <bgm> tags in the hires.txt file) to special register at 0x4105 and changes the original value to 0 (silent in SMB sound engine). If the track ID is not 1, do not change the value to be written to 0xFB so that the sound engine will play that track as normal.