Music Engines

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
xamboni
Posts: 38
Joined: Sat Apr 27, 2019 11:56 am

Music Engines

Post by xamboni » Wed Jul 08, 2020 10:41 pm

I spent a good amount of time reversing the implementation of the Taito music engine for Bubble Bobble last year. There was a ton of input from the community and it was a great deal of success and fun on my end. Semi-unfortunately the Taito engine music for Bubble Bobble is extremely basic. It only makes use of the first four channels on the NES sound chip which leaves a lot to be desired. I am happy to port music into the game on those channels but adding the sample channel would be amazing.

Is it possible to do a brain transplant on an NES cartridge for the sound engine? If I know where the sound engine's init routine is can we erase those bytes and put in something a bit more standard? No worries if this sounds like an undertaking. I can always port music over without the sample channel.

lidnariq
Posts: 9491
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Music Engines

Post by lidnariq » Wed Jul 08, 2020 11:09 pm

xamboni wrote:
Wed Jul 08, 2020 10:41 pm
Is it possible to do a brain transplant on an NES cartridge for the sound engine?
Yes, but it's more involved than this:
can we erase those bytes and put in something a bit more standard?
The existing ROM on the cartridge is a "mask" ROM, and its contents cannot be changed.

However, it's pretty easy to disable or remove the ROM on the cartridge and put a new one in its place, holding the values you want instead.

User avatar
tokumaru
Posts: 11742
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Music Engines

Post by tokumaru » Wed Jul 08, 2020 11:13 pm

Replacing a game's sounds engine is possible but it can be a lot of work. Adding the code for the new engine is the simplest part, specially if you can simply increase the size of the PRG-ROM. Identifying the RAM used by the old engine and remapping the variables of the new engine could be hard, specially if the new engine is more complex and needs more RAm, which might not be available. Then again, you could just cheat again and add PRG-RAM to the cartridge. If you plan on adding DPCM samples, then that could be a real challenge. Since samples have to be mapped to $C000-$FFFF during the whole time they're playing, you're gonna have a hard time opening up space for them. This would most likely require expanding the PRG-ROM and remapping some of the game's data.

xamboni
Posts: 38
Joined: Sat Apr 27, 2019 11:56 am

Re: Music Engines

Post by xamboni » Wed Jul 08, 2020 11:22 pm

lidnariq wrote:
Wed Jul 08, 2020 11:09 pm
xamboni wrote:
Wed Jul 08, 2020 10:41 pm
Is it possible to do a brain transplant on an NES cartridge for the sound engine?
Yes, but it's more involved than this:
can we erase those bytes and put in something a bit more standard?
The existing ROM on the cartridge is a "mask" ROM, and its contents cannot be changed.

However, it's pretty easy to disable or remove the ROM on the cartridge and put a new one in its place, holding the values you want instead.
I have read through your response several times and I think I used the terms "cartridge" and "ROM" too loosely. As a first step I am doing everything through a debugger digitally. Does this change your perspective here or am I misreading still?

xamboni
Posts: 38
Joined: Sat Apr 27, 2019 11:56 am

Re: Music Engines

Post by xamboni » Wed Jul 08, 2020 11:26 pm

tokumaru wrote:
Wed Jul 08, 2020 11:13 pm
Replacing a game's sounds engine is possible but it can be a lot of work. Adding the code for the new engine is the simplest part, specially if you can simply increase the size of the PRG-ROM. Identifying the RAM used by the old engine and remapping the variables of the new engine could be hard, specially if the new engine is more complex and needs more RAm, which might not be available. Then again, you could just cheat again and add PRG-RAM to the cartridge. If you plan on adding DPCM samples, then that could be a real challenge. Since samples have to be mapped to $C000-$FFFF during the whole time they're playing, you're gonna have a hard time opening up space for them. This would most likely require expanding the PRG-ROM and remapping some of the game's data.
As far as additions to the game I am pretty comfortable there is a ton of room to work. Bubble Bobble was extremely simple in implementation. I could be wrong of course. Can you expand on remapping variables or point me to something I can read on a standard engine's variables?

lidnariq
Posts: 9491
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Music Engines

Post by lidnariq » Wed Jul 08, 2020 11:40 pm

xamboni wrote:
Wed Jul 08, 2020 11:22 pm
I have read through your response several times and I think I used the terms "cartridge" and "ROM" too loosely. As a first step I am doing everything through a debugger digitally. Does this change your perspective here or am I misreading still?
I was only talking about the hardware.

xamboni
Posts: 38
Joined: Sat Apr 27, 2019 11:56 am

Re: Music Engines

Post by xamboni » Wed Jul 08, 2020 11:44 pm

lidnariq wrote:
Wed Jul 08, 2020 11:40 pm
xamboni wrote:
Wed Jul 08, 2020 11:22 pm
I have read through your response several times and I think I used the terms "cartridge" and "ROM" too loosely. As a first step I am doing everything through a debugger digitally. Does this change your perspective here or am I misreading still?
I was only talking about the hardware.
That is epic! Thank you for the response. Is this a feature built into the hardware or a work around the community came up with? Given the expansion pins on the NES and SNES I am wondering if there is a "patch at runtime" feature.

User avatar
Memblers
Site Admin
Posts: 3855
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Music Engines

Post by Memblers » Thu Jul 09, 2020 12:09 am

xamboni wrote:
Wed Jul 08, 2020 11:44 pm
lidnariq wrote:
Wed Jul 08, 2020 11:40 pm
xamboni wrote:
Wed Jul 08, 2020 11:22 pm
I have read through your response several times and I think I used the terms "cartridge" and "ROM" too loosely. As a first step I am doing everything through a debugger digitally. Does this change your perspective here or am I misreading still?
I was only talking about the hardware.
That is epic! Thank you for the response. Is this a feature built into the hardware or a work around the community came up with? Given the expansion pins on the NES and SNES I am wondering if there is a "patch at runtime" feature.
The Game Genie does patches at runtime, but only for 3 bytes (genie gives you three wishes, get it?). lidnariq was referring to replacing the ROM chip with a new ROM chip, you'd have to do that (or just use a modern reproduction board for MMC1, there's probably one that matches the config).

Transplanting a music engine is a job that ranges from extremely difficult, to slightly difficult. You can do a feasibility check by taking an NSF of the sound engine you want to use, run it in an emulator with a debugger and note how much RAM it uses compared to the original sound engine. The location doesn't matter, you can change those when you build the engine from source, but probably needs to be consecutive. Compare zeropage usage separately, of course. If that looks good, go through a similar process with ROM usage. You really need that memory to be consecutive, too. But it usually possible to expand the ROM to a larger size, if needed. RAM usage is the real limiting factory (other than CPU time, if it's close enough to matter).

User avatar
Bregalad
Posts: 7889
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Music Engines

Post by Bregalad » Thu Jul 09, 2020 11:52 am

Memblers wrote:
Thu Jul 09, 2020 12:09 am
The Game Genie does patches at runtime, but only for 3 bytes (genie gives you three wishes, get it?).
Wow, after all those years in the community, I finally understand what was the original meaning of "Game Genie". Makes sense. Thanks, Memblers !!
Is it possible to do a brain transplant on an NES cartridge for the sound engine? If I know where the sound engine's init routine is can we erase those bytes and put in something a bit more standard? No worries if this sounds like an undertaking. I can always port music over without the sample channel.
Depending on what you aim to do, you could either add DPCM implementation in the existing sound engine, or transplant another more powerful sound engine by the use of bankswitching (that other sound engine could use or not use DPCM).

The problem is that DPCM samples needs to be there permanently somewhere in the $c000-$ffff range, and there's good chances the whole game is designed to have program data here. And then transplanting sound engine is not exactly easy either.

Post Reply