Replacing music and sounds

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Re: Replacing music and sounds

Postby Shekel » Thu Jun 09, 2016 11:43 am

I doubt anyone's testing this out but here's a list of mpeg addresses if you want to use custom mp2s. Note that there's a few shared ones, meaning it's only possible to have one or the other.

Code: Select all
   //Daytona USA 2 / Power Edition
   LoadMP2File(0x109e8, "Daytona USA 2 - Attract.mp2"); //shared address
   LoadMP2File(0x1214aa, "Daytona USA 2 - Beginner.mp2");
   LoadMP2File(0x2bc7ac, "Daytona USA 2 - Advanced.mp2");
   LoadMP2File(0x3cddae, "Daytona USA 2 - Expert.mp2");
   LoadMP2File(0xd80e02, "Daytona USA 2 - Attract (Japanese).mp2");
   LoadMP2File(0x5177b0, "Daytona USA 2 - Beginner (Japanese).mp2");
   LoadMP2File(0x7cd0b4, "Daytona USA 2 - Advanced (Japanese).mp2");
   LoadMP2File(0x8df436, "Daytona USA 2 - Expert (Japanese).mp2");
   LoadMP2File(0xa29978, "Daytona USA 2 - How To.mp2");
   LoadMP2File(0xb1427a, "Daytona USA 2 - Select.mp2");
   LoadMP2File(0xc4213e, "Daytona USA 2 - Name Entry.mp2");
   LoadMP2File(0xcc9380, "Daytona USA 2 - Ending (Beginner).mp2");
   LoadMP2File(0xcc9380, "Daytona USA 2 - Ending (Advanced).mp2");
   LoadMP2File(0xe8de44, "Daytona USA 2 - Ending (Expert).mp2");
   LoadMP2File(0xf458c6, "Daytona USA 2 - Ending (Expert2).mp2");
   LoadMP2File(0x76ff34, "Daytona USA 2 - Goal (Beginner.)mp2");
   LoadMP2File(0x78c136, "Daytona USA 2 - Goal (Advanced).mp2");
   LoadMP2File(0x7a7c78, "Daytona USA 2 - Goal (Expert).mp2");
      
   //Scud Race / Scud Race Plus
   LoadMP2File(0x463745, "Scud Race - Select.mp2");
   LoadMP2File(0x2afa83, "Scud Race - Super Beginner.mp2");
   LoadMP2File(0x1d4b42, "Scud Race - Beginner (Day).mp2");
   LoadMP2File(0x0e7e41, "Scud Race - Beginner (Night).mp2");
   LoadMP2File(0x000000, "Scud Race - Medium.mp2");
   LoadMP2File(0x37a4c4, "Scud Race - Expert.mp2");
   LoadMP2File(0x58efc8, "Scud Race - Goal.mp2");
   LoadMP2File(0x4f5fc7, "Scud Race - Name Entry.mp2");
   LoadMP2File(0x5c6f49, "Scud Race - Ending.mp2");
   
   //Sega Rally 2
   LoadMP2File(0x109e8, "Sega Rally 2 - Attract.mp2"); //shared address
   LoadMP2File(0x1e576a, "Sega Rally 2 - Attract Japanese.mp2");
   LoadMP2File(0xcf517a, "Sega Rally 2 - Select.mp2");
   LoadMP2File(0xade038, "Sega Rally 2 - Desert.mp2");
   LoadMP2File(0x3452ac, "Sega Rally 2 - Mountain.mp2");
   LoadMP2File(0x5d1ab0, "Sega Rally 2 - Snowy.mp2");
   LoadMP2File(0x109e8, "Sega Rally 2 - Riviera.mp2"); //shared address
   LoadMP2File(0x51a02e, "Sega Rally 2 - Goal.mp2");
   LoadMP2File(0x976934, "Sega Rally 2 - Ending.mp2");
   LoadMP2File(0xa60ff6, "Sega Rally 2 - Ranking.mp2");
   LoadMP2File(0xf95fbe, "Sega Rally 2 - Game Over.mp2");
   LoadMP2File(0xd9f87c, "Sega Rally 2 - Desert Practise.mp2");
   LoadMP2File(0x7b22f2, "Sega Rally 2 - Mountain Practise.mp2"); //shared address
   LoadMP2File(0x7b22f2, "Sega Rally 2 - Snowy Practise.mp2"); //shared address
   LoadMP2File(0x109e8, "Sega Rally 2 - Riviera Practise.mp2"); //shared address
User avatar
Shekel
 
Posts: 345
Joined: Wed Mar 16, 2016 12:45 pm

Re: Replacing music and sounds

Postby Bart » Thu Jun 09, 2016 12:14 pm

Shekel wrote:Would you be able to change just one thing for this music hack? :) No rush, though.

Somehow just load files on a per-game basis? Doesn't seem like I can work around 2 games using the same address, unless there's already a way.


The right way to do it is to pass the game object down to the DSB but that would require you to modify more than one file each time you pull from SVN. So a hackier way to do it is use an if-statement that tests the loaded MPEG ROM for signature bytes.

You can do it using a hex editor on the first of the two ROMs. Or you can print out the first few bytes by inserting this handy-dandy piece of code anywhere in CDSB1::Reset() and CDSB2::Reset():

Code: Select all
for (int i = 0; i < 16; i++)
{
  printf("mpegROM[0x%02x] == 0x%02x\n", i, mpegROM[i]);
}


This will print out the first 16 bytes of the MPEG ROM space. Dollars to donuts these will be unique based on the game. Find a series of bytes (maybe only a single byte is needed) to identify the game. Let's pretend it's bytes 5 and 6. You would then enclose your LoadMP2File() calls like this:

Code: Select all
if (mpegROM[0x05] == 0xaa && mpegROM[0x06] == 0xbb) // if byte 5 is 0xaa AND byte 0x06 is 0xbb, then Daytona 2 detected
{
  LoadMP2File(...);
  ...
} else if (mpegROM[0x05] == 0x12 && mpegROM[0x06] == 0x13) // Sega Rally 2 detected
{
  ...
}
else
  printf("Unable to detect game. Not loading any custom music.\n");


I don't have the emulator handy right now so you'll have to find the real values yourself. These were just made up as examples. You may also only need to check a single byte if you can find one that is unique to each game. Then your test will simply be something like:

Code: Select all
if (mpegROM[0x03] == 0x59)


Hope that makes sense. This is a hideous hack but if it works it works :)
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Replacing music and sounds

Postby Shekel » Thu Jun 09, 2016 12:48 pm

They're the same :) Scud's different, though.

Image

Image

Edit: Added this as well just to show

Image

Edit 2: Sega Rally 2, Daytona 2, Star Wars and Spikeout all share the same numbers.
User avatar
Shekel
 
Posts: 345
Joined: Wed Mar 16, 2016 12:45 pm

Re: Replacing music and sounds

Postby Bart » Thu Jun 09, 2016 1:08 pm

Whoa. That's weird. You have a few options: try searching further into the ROM until you see some differences. Hex editor might help here. To search from the first megabyte onwards (1024*1024 bytes = 1 megabyte), you could do:

Code: Select all
for (int i = 1024*1024; i < 1024*1024+16; i++)


Alternatively, you could try poking around progROM rather than mpegROM for unique signature bytes. The programs are likely to be the same but if you pop it open in a hex editor, you will likely see some ASCII strings identifying the ROM program and there may be a difference at some address.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Replacing music and sounds

Postby Shekel » Thu Jun 09, 2016 1:15 pm

These numbers further on are different, thanks.

I'll see what I can do with this now.
User avatar
Shekel
 
Posts: 345
Joined: Wed Mar 16, 2016 12:45 pm

Re: Replacing music and sounds

Postby Shekel » Thu Jun 09, 2016 1:34 pm

Been trying to work out why this gives an undeclared identifier error but can't. It says the errors are on the mpegROM lines or word.

Code: Select all
   if (mpegROM[0x10000] == 0x77)
   {
      LoadMP2File(0x109e8, "Daytona USA 2 - Attract.mp2");
   }
   else if (mpegROM[0x10000] == 0x6c)
   {
      LoadMP2File(0x109e8, "Sega Rally 2 - Attract.mp2");
   }
   else
      printf("Unable to detect game. Not loading any custom music.\n");
User avatar
Shekel
 
Posts: 345
Joined: Wed Mar 16, 2016 12:45 pm

Re: Replacing music and sounds

Postby Bart » Thu Jun 09, 2016 1:50 pm

Ah I forgot that LoadCustomMusic() is a static function and does not have access to the DSB's internal variables. Easily rectified. Three steps:

1. You need to move the call to LoadCustomMusic() out of CDSB1::CDSB1() and CDSB2::CDSB2() and into CDSB1::Reset() and CDSB2::Reset(). The reason for this is that the mpegROM memory has not yet been attached at this point. By the time Reset() is called, it has been.
2. Change it to be called like this:

Code: Select all
LoadCustomMusic(mpegROM);


3. Finally, change the function signature itself to accept this new param:

Code: Select all
static void LoadCustomMusic(const uint8_t *mpegROM)
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Replacing music and sounds

Postby Shekel » Thu Jun 09, 2016 1:55 pm

Bart wrote:3. Finally, change the function signature itself to accept this new param:

Code: Select all
static void LoadCustomMusic(const uint8_t *mpegROM)

With you, fella, right up to this bit :) Where does this go?
User avatar
Shekel
 
Posts: 345
Joined: Wed Mar 16, 2016 12:45 pm

Re: Replacing music and sounds

Postby Bart » Thu Jun 09, 2016 1:58 pm

Shekel wrote:
Bart wrote:3. Finally, change the function signature itself to accept this new param:

Code: Select all
static void LoadCustomMusic(const uint8_t *mpegROM)

With you, fella, right up to this bit :) Where does this go?


The first line of that function is the signature and right now, it accepts no parameters:

Code: Select all
static void LoadCustomMusic()


You need to change it to what I put above.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Replacing music and sounds

Postby terminator2k2 » Thu Jun 09, 2016 2:00 pm

reading this with interest...but oh my its way above my head lol :shock:
terminator2k2
 
Posts: 35
Joined: Sat Apr 02, 2016 5:30 am

PreviousNext

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest

cron