Using Sonic 3 music in Sonic 3 & Knuckles

Discussion in 'Tutorials Archive' started by sonic, Aug 18, 2008.

Thread Status:
Not open for further replies.
  1. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    How do I make the game use Sonic 3 music instead of Sonic & Knuckles music?
     
  2. Nicogens

    Nicogens Actually trying this time for real Member

    Joined:
    Jul 31, 2008
    Messages:
    89
    Location:
    Argentina
    Use Esrael Sonic Editor (ESE) and edit the playlist.
     
  3. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    You have to edit the bank pointers and music pointers in the S3K rom. Since they're Kosinski-compressed, it's quite a pain to actually make the change in the ROM, and far easier to do in a savestate (such as this one, made by me, which uses the Sonic 3 sound bank instead of the S&K one). I'll explain the exact changes you have to make if you want, though it'll be quite verbose since I suck at explaining stuff.
     
  4. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    That's alright. I'm up to the challenge. You can explain the exact steps to me.
     
  5. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    K then, but don't say I didn't warn you =P The basic idea is, Sonic 3k's sound driver runs on the Z80. The Z80 can only access $8000 bytes of ROM data at one time, and to choose which $8000 bytes it wants to access it uses a technique known as bankswitching. Basically, the Z80 treats the 68k space as separate $8000 byte chunks, and by writing to a special register (6000h on the Z80 side) it can choose which chunk it wants to access.


    So for each song, there are two separate pieces of information the sound driver reads in order to locate the song - the bank pointer and the song pointer. The bank pointer, as mentioned before, tells the driver which $8000 portion to access, and the song pointer tells the driver where in this portion the song lies (for more information on the pointer format, see this).


    The basic idea therefore is to change both the bank pointers and the music pointers for certain Sonic 3k songs to make them read from the Sonic 3 sound bank. If you look at Tweaker's guide, you can see the locations for both of these in Sonic 3 and Sonic 3k savestates. Firstly, there are 6 songs which we want to modify:



    Code:
    $1F - Knux's theme
    
    $25 - Title song
    
    $2A - 1up sound
    
    $2C - Invincibility jingle
    
    $2E - Miniboss music
    
    $32 - Game end thing (don't think this one really matters, but just for completeness)


    So let's tackle the bank IDs first. If you look at the bank pointers in a Sonic 3 savestate, you'll see this initially:



    Code:
    09 09 09 09 09 09 ...
    and the equivalent in an S3K savestate is:



    Code:
    59 59 59 59 59 59 ...
    so it's pretty obvious that if we want to use an S3 bank value in S3K, we add $50 to it. Now let's look at the bank IDs for the songs we care about. The first bank ID, for song $1F, is located at $FDA in the S3 savestate and $FF7 in the S3K savestate. The S3 ID reads $0B, but the S3K one reads $1D. Therefore, we have to change the ID in the S3K savestate to $5B. You do the same thing for the other 5 songs.


    Next we have to change the actual pointers. The music pointer for song $1F will be at $1ACA in the S3 savestate and $1AC8 in the S3K savestate. The S3 pointer reads $FD97 while the S3K pointer reads $A3F5, so we change the S3K pointer to $FD97. Repeat for the other five songs. After this, whenever you load your modified savestate it'll read from the S3 sound bank for these six songs instead of from the S&K sound bank.


    If you want, I can make a small mod of the S3K rom that uses a bit of 68k code to modify the Z80 bank and music pointers after the sound driver's been loaded into Z80 RAM. Bear in mind though that whenever you load a non-modified savestate, the music and bank pointers will also be overwritten with their old values, so its usefulness is rather limited.
     
  6. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    Thanks for the info! I'll understand it after I read over it a couple of times. Sure, I'd like a modified S3K rom.
     
  7. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    K, to modify the S3K rom, first go to $133E and overwrite whatever's there with



    Code:
    4E F9 00 30 00 00
    After that, go to $300000 and once again overwrite whatever's there with



    Code:
    48 E7 C0 7C 43 F9 00 A0 0B 64 45 F9 00 A0 16 16 
    
    47 FA 00 30 49 FA 00 32 4B FA 00 34 72 05 70 00 
    
    10 1B 13 9C 00 00 D0 40 15 9D 00 00 15 9D 00 01 
    
    51 C9 FF EC 33 FC 00 00 00 A1 11 00 4C DF 3E 03 
    
    4E 75 1F 25 2A 2C 2E 32 5B 5B 5B 5B 58 5B FD 97 
    
    8F E1 95 F0 64 F3 A0 F1 FE FB
     
  8. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    Nice! I'll try it now.
     
  9. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    In case you're wondering what that code does, here's the asm equivalent:



    Code:
    		movem.l d0-d1/a1-a5,-(sp)	  &#59; backup vars   
    
    		lea	 ($A00B64).l,a1 &#59; address in Z80 RAM of bank IDs
    
    		lea	 ($A01616).l,a2 &#59; address in Z80 RAM of music pointers
    
    		lea	 SongIDs(pc),a3		 &#59; song IDs to replace
    
    		lea	 BankVals(pc),a4		&#59; replacement bank values
    
    		lea	 PointerVals(pc),a5	 &#59; replacement pointer values
    
    		moveq   #5,d1		  &#59; modify 6 songs
    
    		
    
    @loop:
    
    		moveq   #0,d0
    
    		move.b  (a3)+,d0	   &#59; load song ID
    
    		move.b  (a4)+,(a1,d0.w)&#59; change bank ID
    
    		add.w   d0,d0		  &#59; pointer = word value
    
    		move.b  (a5)+,(a2,d0.w)&#59; change music pointer
    
    		move.b  (a5)+,1(a2,d0.w)	   &#59; you can only access Z80 RAM byte-by-byte
    
    		dbf	 d1,@loop
    
    		
    
    		move.w  #0,($A11100).l		 &#59; restart Z80
    
    		movem.l (sp)+,d0-d1/a1-a5	  &#59; restore vars
    
    		rts
    
    		
    
    SongIDs:
    
    		dc.b $1F, $25, $2A, $2C, $2E, $32	  &#59; IDs of songs to replace
    
    
    
    BankVals:
    
    		dc.b $5B, $5B, $5B, $5B, $58, $5B	  &#59; replacement bank values
    
    		
    
    PointerVals:
    
    		dc.w $FD97, $8FE1, $95F0, $64F3, $A0F1, $FEFB  &#59; replacement pointers
     
  10. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    I'm thinking about making a Sonic the Hedgehog 3 beta remake. The next thing I'm going to do is give Sonic his Sonic the Hedgehog 2 sprites. Also, I have a few more questions. If you can't answer some, answer the the ones that you can:


    1. Does the combined game of Sonic 3 and Knuckles get Sonic and Tails' sprite data and palettes from Sonic 3 or Sonic and Knuckles?


    2. Does changing Knuckles' socks from yellow to green affect the HUD color? If so, does the game get Knuckles' palette data from Sonic 3 or Sonic and Knuckles? And what's Knuckles' palette location in the game that it's retrieved from?


    3. Can the surfboarding intro be restored to the game without a save state along with fixing the bugs with it (The interface doesn't show up and some sprites are messed up/invisible)?


    4. How do you edit the title cards and level select text? I want to rename Mushroom Hill to Mushroom Valley. I also want to edit the level order so Flying Battery Zone comes right after Carnival Night Zone.


    5. Can you make Sonic run down the beginning of Ice Cap Zone Act 1?


    6. Can you make the game use the Sonic 3 title screen and title cards screen so they don't say "& Knuckles"?


    7. Can you make the game use the Sonic 3 credits and put Michael Jackson's name in the credits?
     
    Last edited by a moderator: Aug 19, 2008
  11. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    1. It gets all of Sonic's data from the S&K ROM. Tails' art is loaded from the Sonic 3 ROM, but his mappings and PLCs are in the S&K ROM. Palettes are in the S&K ROM.


    2. No idea about the HUD colour, but the game gets the palette data from the S&K ROM. It's located at $A8AFC, and contains 16 colours.


    3. No idea, though if it's possible in a savestate it should be possible in the ROM as well


    4. Title cards use normal sprite mappings, so you'll have to edit those. You'll also have to edit what letters load for each level, but that's just a decompress-add stuff-recompress thing. Level select text is a plane map, and the format is pretty easy. S&K doesn't have any level order lookup table like the previous games did. Instead, each act's code contains the next act to load, and you can find this code in the TriggerEvent routine of that act.


    5. Should just be a matter of editing some code


    6. Yeah - the title screen text is just a separate object which can be disabled, and the title card mappings can be edited


    7. Yeah, it's probably just a matter of making the game read from Sonic 3's credit data rather than S&K's.


    What I'd recommend is to download Stealth's S&K disassembly from here, and take a look around it to see what changes you have to make. A lot of stuff is already labelled, so it shouldn't be too hard.
     
  12. sonic

    sonic Well-Known Member Member

    Joined:
    Mar 27, 2008
    Messages:
    62
    Location:
    Michigan
    Alright. Thanks for the help. I'll take a look at the disassembly and ASM to Hex Code reference on Sonic Retro as well.
     
  13. SonicJackson

    SonicJackson Sonic J In Limbo

    Joined:
    May 15, 2009
    Messages:
    19
    if you go on sonic cult there is a section that has the surfboarding intro into a S3 rom. if you have the Gens emulator you can download that rom and checkout the intro.


    evreything else in the rom is EXACTLY like a sonic 3 cartige minus the PAR cheats and editing


    i'm a noob at hacking but this rom should get you everything minus the S&K rom.


    EDIT: here is a link - http://www.sonic-cult.org/dispart.php?cati...=2&artid=10
     
    Last edited by a moderator: May 15, 2009
  14. SonicJackson

    SonicJackson Sonic J In Limbo

    Joined:
    May 15, 2009
    Messages:
    19
  15. Tongara

    Tongara Well-Known Member Exiled

    Joined:
    Feb 10, 2009
    Messages:
    353
    Location:
    Birmingham, UK
    Yes.


    Yes we did.
     
  16. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,067
    Location:
    Jardim Capelinha, São Paulo
    I think this is a weird (or mean, newbie) and hard way to do it... But works for me.


    Well... I made something into test source codes here. You can change the music pointers and the music locations.Just extract all music data (using the S&K disassembler), convert every songs to the S1 format (without coordination flags conversion and DAC changes). Use Music Pointer Fixer (with a test S3K ROM) to convert the song to the S3K format to the other Offset you want to add. Fix the bank (and sure, the pointer) for the music on the source of Sonic 3K, and done. Make the same proccedure with all other songs you want to re-point. You have to remember of put the s3 songs in places where has Sonic &K songs to make the thing you want.


    It's harder, and very weird... but as i said, it works for me.
     
Thread Status:
Not open for further replies.