Replacing a soundtrack.

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Replacing a soundtrack.
by on (#239440)
Hey everyone, first time posting here.
I apologise in advance for anything in this thread, I'm extremely unexperienced with modding NES games (Or any games for that matter), I don't really know anything about HEX etc.

okay, that's out of the way. I'll cut to the chase so as to not waste anyone's time.

I recently made a graphical mod for an old NES game called "Lode Runner", I'm sure some of you have heard of it.
Yesterday I composed a soundtrack in NFL format using Famitracker, and I would like to know how to take the current soundtrack for the game and replace it with the newly composed soundtrack.

Some things to consider:
- The song isn't that long, so memory shouldn't be an issue.
- I'm fully aware of the difficulty of this task, it is possible to do, it's just very tedious and pain staking.
- I'm also aware that this requires you to know how to HEX edit, as well as learning about the game's engine. (Or something of that nature)
- I'm not asking for handouts, in other words, I'm not asking people to just take the two files and do all this for me. (Unless offered)
- I'm asking for advice, a direction, things to consider and how to actually do it.I'm willing to learn because this is something I genuinely want to do.

Thank you very much for your time, I look forward to some responses.
Kind regards,
-L0ST :beer:

Ps. If anybody needs access to the modified NES file or NSF file (if for some reason that helps) I'd be happy to attach them if necessary,
Re: Replacing a soundtrack.
by on (#239441)
Do you know 6502 assembly language? Knowing 6502 assembly language would help you understand our instructions on how to track down the game's music code.
Re: Replacing a soundtrack.
by on (#239450)
Nothing famitracker can output will be compatible with Lode Runner's music code.

You would either have to reverse engineer the Lode Runner's code, and write a conversion tool (minimum 1 month of time),

or, gut all the music code out of Lode Runner, and replace it with a format that famitracker can output... NSF is the easiest, presumably you would disassemble the game code and reassemble it with the NSF code and data... or, use one of the homebrew music engines (famitone2, for example)...which is more reasonable due to the large size of native famitracker music engine. And reassemble the game with the famitone2 code in place.

The size of the song wouldn't change the time involved.

Another thought. Some game hackers just hex edit the music data until it sounds right. Trial and error. Knowing exactly where the music data is is the tricky part, and likely it won't sound nearly as good as your famitracker version.

Hacking advice isn't really the focus of this forum, and should be directed to the Romhacking.net forum.
Re: Replacing a soundtrack.
by on (#239452)
tepples wrote:
Do you know 6502 assembly language? Knowing 6502 assembly language would help you understand our instructions on how to track down the game's music code.

I don't know any coding languages, I vaguely know C++ and other bits and bobs.
dougeff wrote:
Nothing famitracker can output will be compatible with Lode Runner's music code.

You would either have to reverse engineer the Lode Runner's code, and write a conversion tool (minimum 1 month of time),

or, gut all the music code out of Lode Runner, and replace it with a format that famitracker can output... NSF is the easiest, presumably you would disassemble the game code and reassemble it with the NSF code and data... or, use one of the homebrew music engines (famitone2, for example)...which is more reasonable due to the large size of native famitracker music engine. And reassemble the game with the famitone2 code in place.

The size of the song wouldn't change the time involved.

Another thought. Some game hackers just hex edit the music data until it sounds right. Trial and error. Knowing exactly where the music data is is the tricky part, and likely it won't sound nearly as good as your famitracker version.

Hacking advice isn't really the focus of this forum, and should be directed to the Romhacking.net forum.


That's a lot of info. Okay so, could you break down step by step what I'd have to do and learn?

I'm guess something along the lines of:
Learn hex, just straight up, since I have no idea where to find the music part of the code in a jumble of Hexademical characters.
How would I write a conversion tool? using a total separate coding language?
also when you say "gut all the music code out of Lode Runner, and replace it with a format that famitracker can output... NSF is the easiest" what exactly do you mean by that? You mean locate the music in lode runner, take out the code that is the in-game music, then open the NSF for my song, copy all the code there and paste it in? That doesn't sound right, so you'll probably have to correct me on that one.

Also I apologise if this is not the correct forum to post such a topic, I was sent here by a friend, I didn't know and am sorry if it was rude at all for me to post this here.


I'd really appreciate a response, hopefully you can tell me everything I'd need to know in order to do this.
Again, I'm a total beginner so I apologise for my ignorance of coding.

Either way I'm willing to learn whatever is warranted to do this, I'm willing to commit, I'm a musician and have studied music theory for over a year now, and nothing can be harder than that, so I'm willing to take on as many coding languages as necessary.
Thank you very much for the helpful reply.
Kind regards,
-L0ST
Re: Replacing a soundtrack.
by on (#239453)
1. Learn enough 6502 assembly to understand what's going on in a debugger
2. Learn which I/O addresses represent audio commands
3. Run the program while watching for writes to those addresses
4. Find where the program reads the data that it proceeds to write to those addresses
5. Based on the structure of the program, find out how the data is organized
6. Poke in new data

Steps 1 and 2 might take a month or two. Steps 3 through 6 took about a day when I made a patch to put Doom music in Klax. I tried to describe my thought processes in the notes accompanying that patch (click "Readme File" on the patch's description page).

To get started, work through Easy 6502 until you understand most of what is presented.
Re: Replacing a soundtrack.
by on (#239454)
tepples wrote:
1. Learn enough 6502 assembly to understand what's going on in a debugger
2. Learn which I/O addresses represent audio commands
3. Run the program while watching for writes to those addresses
4. Find where the program reads the data that it proceeds to write to those addresses
5. Based on the structure of the program, find out how the data is organized
6. Poke in new data

Steps 1 and 2 might take a month or two. Steps 3 through 6 took about a day when I made a patch to put Doom music in Klax. I tried to describe my thought processes in the notes accompanying that patch (click "Readme File" on the patch's description page).

To get started, work through Easy 6502 until you understand most of what is presented.

I see. Thank you! What debugger would you recommend?
Edit: My mistake, the debugger is or is included with Easy 6502, correct?
Re: Replacing a soundtrack.
by on (#239456)
The most commonly used debugging NES emulators are Mesen and FCEUX.
Re: Replacing a soundtrack.
by on (#239462)
tepples wrote:
The most commonly used debugging NES emulators are Mesen and FCEUX.

Cheers. I'll be on my way then. unless anyone else wants to add something to this topic.(?)
Re: Replacing a soundtrack.
by on (#239998)
If I was sticking a different sound engine into a game, I'd see what RAM the game uses, and ensure the replacement sound engine doesn't use the same memory. Since you can build the sound engine, you can change what memory is used for the music code.
Note that changing the sound engine means you need to remake the sound effects too.
Re: Replacing a soundtrack.
by on (#240142)
Hello, L0ST5ILVER!

Replacing music in a nes game is not so difficult. It took me only some minutes to figure out how the music data works in Lode Runner.
Use FCEUX, Open Hex editor -> View -> ROM file, Open Data Logger -> click "Start" and you will see all the bytes highlighted that were read. Use Pause on your keyboard to pause / resume the emulation.

I made a demonstration video for you:
https://streamable.com/y1y7q