Difference between revisions of "Port the Sonic 2 Clone Sound Driver to the HG version of Sonic 2"
From Sonic Retro
ValleyBell (talk | contribs) m (made music/sound constants look better) |
|||
Line 22: | Line 22: | ||
Also delete s2.sounddriver.asm. That's the Sonic 2 Sound Driver, so it's not necessary. | Also delete s2.sounddriver.asm. That's the Sonic 2 Sound Driver, so it's not necessary. | ||
− | and then extract "Sonic 2 Clone | + | and then extract "Sonic 2 Clone Driver.7z" into the main folder of your dissasembly. |
==Step 2 - Deleting leftovers== | ==Step 2 - Deleting leftovers== | ||
Line 72: | Line 72: | ||
<asm>; Music IDs | <asm>; Music IDs | ||
− | |||
; $80 is reserved for silence, so if you make idstart $80 or less, | ; $80 is reserved for silence, so if you make idstart $80 or less, | ||
; you may need to insert a dummy zMusIDPtr in the $80 slot | ; you may need to insert a dummy zMusIDPtr in the $80 slot | ||
− | + | MusID__First = $81 | |
− | MusID__First = | + | MusID_2PResult = $81 |
− | MusID_2PResult = | + | MusID_EHZ = $82 |
− | MusID_EHZ = | ||
MusID_MCZ_2P = $83 | MusID_MCZ_2P = $83 | ||
− | MusID_OOZ = | + | MusID_OOZ = $84 |
− | MusID_MTZ = | + | MusID_MTZ = $85 |
− | MusID_HTZ = | + | MusID_HTZ = $86 |
− | MusID_ARZ = | + | MusID_ARZ = $87 |
MusID_CNZ_2P = $88 | MusID_CNZ_2P = $88 | ||
− | MusID_CNZ = | + | MusID_CNZ = $89 |
− | MusID_DEZ = | + | MusID_DEZ = $8A |
− | MusID_MCZ = | + | MusID_MCZ = $8B |
MusID_EHZ_2P = $8C | MusID_EHZ_2P = $8C | ||
− | MusID_SCZ = | + | MusID_SCZ = $8D |
− | MusID_CPZ = | + | MusID_CPZ = $8E |
− | MusID_WFZ = | + | MusID_WFZ = $8F |
− | MusID_HPZ = | + | MusID_HPZ = $90 |
− | MusID_Options = | + | MusID_Options = $91 |
− | MusID_SpecStage = | + | MusID_SpecStage = $92 |
MusID_Boss = $93 | MusID_Boss = $93 | ||
− | MusID_EndBoss = | + | MusID_EndBoss = $94 |
MusID_Ending = $95 | MusID_Ending = $95 | ||
− | MusID_SuperSonic = | + | MusID_SuperSonic = $96 |
− | MusID_Invincible = | + | MusID_Invincible = $97 |
− | MusID_ExtraLife = | + | MusID_ExtraLife = $98 |
− | MusID_Title = | + | MusID_Title = $99 |
− | MusID_EndLevel = | + | MusID_EndLevel = $9A |
− | MusID_GameOver = | + | MusID_GameOver = $9B |
− | MusID_Continue = | + | MusID_Continue = $9C |
− | MusID_Emerald = | + | MusID_Emerald = $9D |
− | MusID_Credits = | + | MusID_Credits = $9E |
− | MusID_Countdown = | + | MusID_Countdown = $9F |
− | MusID__End = | + | MusID__End = $A0</asm> |
The music is all fixed, now all that's left is the sound effects: | The music is all fixed, now all that's left is the sound effects: | ||
Line 117: | Line 115: | ||
<asm>; Sound IDs | <asm>; Sound IDs | ||
− | |||
− | |||
SndID__First = idstart | SndID__First = idstart | ||
− | SndID_Jump = $ | + | SndID_Jump = $A0 |
− | SndID_Checkpoint = | + | SndID_Checkpoint = $A1 |
− | SndID_SpikeSwitch = | + | SndID_SpikeSwitch = $A2 |
− | SndID_Hurt = $ | + | SndID_Hurt = $A3 |
− | SndID_Skidding = | + | SndID_Skidding = $A4 |
− | SndID_BlockPush = | + | SndID_BlockPush = $A5 |
− | SndID_HurtBySpikes = | + | SndID_HurtBySpikes = $A6 |
− | SndID_Sparkle = | + | SndID_Sparkle = $A7 |
− | SndID_Beep = | + | SndID_Beep = $A8 |
− | SndID_Bwoop = | + | SndID_Bwoop = $A9 |
− | SndID_Splash = | + | SndID_Splash = $AA |
− | SndID_Swish = | + | SndID_Swish = $AB |
− | SndID_BossHit = | + | SndID_BossHit = $AC |
− | SndID_InhalingBubble = | + | SndID_InhalingBubble = $AD |
− | SndID_ArrowFiring = | + | SndID_ArrowFiring = $AE |
− | SndID_LavaBall = | + | SndID_LavaBall = $AE |
− | SndID_Shield = | + | SndID_Shield = $AF |
− | SndID_LaserBeam = | + | SndID_LaserBeam = $B0 |
− | SndID_Zap = | + | SndID_Zap = $B1 |
− | SndID_Drown = | + | SndID_Drown = $B2 |
− | SndID_FireBurn = | + | SndID_FireBurn = $B3 |
− | SndID_Bumper = | + | SndID_Bumper = $B4 |
− | SndID_Ring = | + | SndID_Ring = $B5 |
− | SndID_RingRight = | + | SndID_RingRight = $B5 |
− | SndID_SpikesMove = | + | SndID_SpikesMove = $B6 |
− | SndID_Rumbling = | + | SndID_Rumbling = $B7 |
− | SndID_Smash = | + | SndID_Smash = $B9 |
− | SndID_DoorSlam = | + | SndID_DoorSlam = $BB |
− | SndID_SpindashRelease = | + | SndID_SpindashRelease = $BC |
− | SndID_Hammer = | + | SndID_Hammer = $BD |
− | SndID_Roll = | + | SndID_Roll = $BE |
− | SndID_ContinueJingle = | + | SndID_ContinueJingle = $BF |
− | SndID_CasinoBonus = | + | SndID_CasinoBonus = $C0 |
− | SndID_Explosion = | + | SndID_Explosion = $C1 |
− | SndID_WaterWarning = | + | SndID_WaterWarning = $C2 |
− | SndID_EnterGiantRing = | + | SndID_EnterGiantRing = $C3 |
− | SndID_BossExplosion = | + | SndID_BossExplosion = $C4 |
− | SndID_TallyEnd = | + | SndID_TallyEnd = $C5 |
− | SndID_RingSpill = | + | SndID_RingSpill = $C6 |
− | SndID_Flamethrower = | + | SndID_Flamethrower = $C8 |
− | SndID_Bonus = | + | SndID_Bonus = $C9 |
− | SndID_SpecStageEntry = | + | SndID_SpecStageEntry = $CA |
− | SndID_SlowSmash = | + | SndID_SlowSmash = $CB |
− | SndID_Spring = | + | SndID_Spring = $CC |
− | SndID_Blip = | + | SndID_Blip = $CD |
− | SndID_RingLeft = | + | SndID_RingLeft = $B5 |
− | SndID_Signpost = | + | SndID_Signpost = $CF |
− | SndID_CNZBossZap = | + | SndID_CNZBossZap = $D0 |
− | SndID_Signpost2P = | + | SndID_Signpost2P = $D3 |
− | SndID_OOZLidPop = | + | SndID_OOZLidPop = $D4 |
− | SndID_SlidingSpike = | + | SndID_SlidingSpike = $D5 |
− | SndID_CNZElevator = | + | SndID_CNZElevator = $D6 |
− | SndID_PlatformKnock = | + | SndID_PlatformKnock = $D7 |
− | SndID_BonusBumper = | + | SndID_BonusBumper = $D8 |
− | SndID_LargeBumper = | + | SndID_LargeBumper = $D9 |
− | SndID_Gloop = | + | SndID_Gloop = $DA |
− | SndID_PreArrowFiring = | + | SndID_PreArrowFiring = $DB |
− | SndID_Fire = | + | SndID_Fire = $DC |
− | SndID_ArrowStick = | + | SndID_ArrowStick = $DD |
− | SndID_Helicopter = | + | SndID_Helicopter = $DE |
− | SndID_SuperTransform = | + | SndID_SuperTransform = $DF |
− | SndID_SpindashRev = | + | SndID_SpindashRev = $E0 |
− | SndID_Rumbling2 = | + | SndID_Rumbling2 = $E1 |
− | SndID_CNZLaunch = | + | SndID_CNZLaunch = $E2 |
− | SndID_Flipper = | + | SndID_Flipper = $E3 |
− | SndID_HTZLiftClick = | + | SndID_HTZLiftClick = $E4 |
− | SndID_Leaves = | + | SndID_Leaves = $E5 |
− | SndID_MegaMackDrop = | + | SndID_MegaMackDrop = $E6 |
− | SndID_DrawbridgeMove = | + | SndID_DrawbridgeMove = $E7 |
− | SndID_QuickDoorSlam = | + | SndID_QuickDoorSlam = $E8 |
− | SndID_DrawbridgeDown = | + | SndID_DrawbridgeDown = $E9 |
− | SndID_LaserBurst = | + | SndID_LaserBurst = $EA |
− | SndID_Scatter = | + | SndID_Scatter = $EB |
− | SndID_LaserFloor = | + | SndID_LaserFloor = $EB |
− | SndID_Teleport = | + | SndID_Teleport = $EC |
− | SndID_Error = | + | SndID_Error = $ED |
− | SndID_MechaSonicBuzz = | + | SndID_MechaSonicBuzz = $EE |
− | SndID_LargeLaser = | + | SndID_LargeLaser = $EF |
− | SndID_OilSlide = | + | SndID_OilSlide = $F0 |
− | SndID__End = | + | SndID__End = $F7</asm> |
The following are the lines you should NOT have deleted, just for reference: | The following are the lines you should NOT have deleted, just for reference: | ||
Line 366: | Line 362: | ||
Puto - Fixes for underwater palette stuff, as well as special stage ring stuff, and various other fixes to the original guide. | Puto - Fixes for underwater palette stuff, as well as special stage ring stuff, and various other fixes to the original guide. | ||
Tweaker - Wrote the orignal guide to port Sonic 1's sound driver into Sonic 2. | Tweaker - Wrote the orignal guide to port Sonic 1's sound driver into Sonic 2. | ||
− | ShadowsofYesterday - Telling me the fix for the SEGA sound. | + | ShadowsofYesterday - Telling me the fix for the SEGA sound. (old version of the guide) |
ValleyBell - In addition to his original work on the Clone Driver, he showed me numerous things I could do to fix the guide! | ValleyBell - In addition to his original work on the Clone Driver, he showed me numerous things I could do to fix the guide! | ||
Caverns4 - I wrote and updated the guide. | Caverns4 - I wrote and updated the guide. |
Revision as of 03:22, 19 September 2013
(Original guide by Caverns4)
Contents
Summary
The guide is fixed and updated as of September 11th, 2013. It should now work on real hardware! ~ Caverns4
The Sonic 2 Clone Driver is simply a modified version of the Sonic 1 Sound driver, designed to work with Sonic 2. The advantages to using this over the Sound Driver in Sonic 2 normally are numerous; It will be easier to modify existing songs as you won't have to worry about compressing and decompressing the music, and your music will be supported by more up to date Music editor programs.
There are a few bugs I have noticed. One is that the spin dash sound will not raise pitch. The music is not a perfect adaptation of Sonic 2's music, particularly sometimes the PSG channels sound slightly different. This is most noticeable in Emerald Hill's music. Besides this, there are no problems.
If the above bugs will not bother you too badly, then you'll like using the Sonic 2 Clone Driver after working with Sonic 2's own sound driver. The Clone Driver is much easier to port music to, and in fact, Sonic 1 music can even just be bincluded into the ROM. This is because it's based on the Sonic 1 sound driver, and uses similar (if not the same) formatting. With this out of the way, now it's time to edit the Sonic 2 HG Dissasembly!
Before begining, you will need the following file:
Download Sonic 2 Clone Driver Files
File: Sonic 2 Clone Driver.7z (78 kB) (info)
|
Step 1 - getting started
Back up your dissasembly if you haven't already.
To start, go into your sound folder, where you'll have a DAC folder, a music folder, and a PCM folder.
DELETE THEM ALL!
Also delete s2.sounddriver.asm. That's the Sonic 2 Sound Driver, so it's not necessary.
and then extract "Sonic 2 Clone Driver.7z" into the main folder of your dissasembly.
Step 2 - Deleting leftovers
Now open up s2.asm, and find the label 'SoundDriverLoad:'. Delete everything from that, up to and including:
<asm>'Mus_Continue: BINCLUDE "sound/music/Continue.bin"'</asm>
What we have done here is deleted the routines to load and decompress the Sound Driver. We don't need this anymore.
Next up, find this line:
<asm>cnop -Size_of_SEGA_sound, $8000</asm>
and delete everything from there up to (but not including) the line:
<asm> ; end of 'ROM'</asm>
Also, on the line above the 'EndOfRom:' label, you should see this:
<asm> shared word_728C_user,Obj5F_MapUnc_7240,off_3A294,MapRUnc_Sonic,movewZ80CompSize</asm>
Change it to this:
<asm> shared word_728C_user,Obj5F_MapUnc_7240,off_3A294,MapRUnc_Sonic</asm>
Finally, find the label 'sndDriverInput:'
Delete the entire function, which starts there, and ends at this line:
<asm>; End of function sndDriverInput</asm>
Now search in your assembly for "sndDriverInput", and delete any lines that point to it. There will be quite a few, but it won't hurt anything.
We've effectively deleted the old sound driver entirely from our game... Now it's time we implemented a new one.. But first, we need to prepare S2.Constants.asm
Step 3 - Overhauling Constants, fixing RAM
Open s2.constants.asm, and find the following line:
Find the line "; Music IDs". You'll see this:
<asm>; Music IDs offset := zMasterPlaylist ptrsize := 1 idstart := $81
- $80 is reserved for silence, so if you make idstart $80 or less,
- you may need to insert a dummy zMusIDPtr in the $80 slot</asm>
delete everything from there down to "MusID__End = id(zMusIDPtr__End) ; A0", and paste the following where it used to be:
<asm>; Music IDs
- $80 is reserved for silence, so if you make idstart $80 or less,
- you may need to insert a dummy zMusIDPtr in the $80 slot
MusID__First = $81 MusID_2PResult = $81 MusID_EHZ = $82 MusID_MCZ_2P = $83 MusID_OOZ = $84 MusID_MTZ = $85 MusID_HTZ = $86 MusID_ARZ = $87 MusID_CNZ_2P = $88 MusID_CNZ = $89 MusID_DEZ = $8A MusID_MCZ = $8B MusID_EHZ_2P = $8C MusID_SCZ = $8D MusID_CPZ = $8E MusID_WFZ = $8F MusID_HPZ = $90 MusID_Options = $91 MusID_SpecStage = $92 MusID_Boss = $93 MusID_EndBoss = $94 MusID_Ending = $95 MusID_SuperSonic = $96 MusID_Invincible = $97 MusID_ExtraLife = $98 MusID_Title = $99 MusID_EndLevel = $9A MusID_GameOver = $9B MusID_Continue = $9C MusID_Emerald = $9D MusID_Credits = $9E MusID_Countdown = $9F MusID__End = $A0</asm>
The music is all fixed, now all that's left is the sound effects:
Find the line "; Sound IDs", and delete everything down to the line "; Special sound IDs". Leave the special IDs alone.
In place of the text you deleted, just paste this:
<asm>; Sound IDs SndID__First = idstart SndID_Jump = $A0 SndID_Checkpoint = $A1 SndID_SpikeSwitch = $A2 SndID_Hurt = $A3 SndID_Skidding = $A4 SndID_BlockPush = $A5 SndID_HurtBySpikes = $A6 SndID_Sparkle = $A7 SndID_Beep = $A8 SndID_Bwoop = $A9 SndID_Splash = $AA SndID_Swish = $AB SndID_BossHit = $AC SndID_InhalingBubble = $AD SndID_ArrowFiring = $AE SndID_LavaBall = $AE SndID_Shield = $AF SndID_LaserBeam = $B0 SndID_Zap = $B1 SndID_Drown = $B2 SndID_FireBurn = $B3 SndID_Bumper = $B4 SndID_Ring = $B5 SndID_RingRight = $B5 SndID_SpikesMove = $B6 SndID_Rumbling = $B7 SndID_Smash = $B9 SndID_DoorSlam = $BB SndID_SpindashRelease = $BC SndID_Hammer = $BD SndID_Roll = $BE SndID_ContinueJingle = $BF SndID_CasinoBonus = $C0 SndID_Explosion = $C1 SndID_WaterWarning = $C2 SndID_EnterGiantRing = $C3 SndID_BossExplosion = $C4 SndID_TallyEnd = $C5 SndID_RingSpill = $C6 SndID_Flamethrower = $C8 SndID_Bonus = $C9 SndID_SpecStageEntry = $CA SndID_SlowSmash = $CB SndID_Spring = $CC SndID_Blip = $CD SndID_RingLeft = $B5 SndID_Signpost = $CF SndID_CNZBossZap = $D0 SndID_Signpost2P = $D3 SndID_OOZLidPop = $D4 SndID_SlidingSpike = $D5 SndID_CNZElevator = $D6 SndID_PlatformKnock = $D7 SndID_BonusBumper = $D8 SndID_LargeBumper = $D9 SndID_Gloop = $DA SndID_PreArrowFiring = $DB SndID_Fire = $DC SndID_ArrowStick = $DD SndID_Helicopter = $DE SndID_SuperTransform = $DF SndID_SpindashRev = $E0 SndID_Rumbling2 = $E1 SndID_CNZLaunch = $E2 SndID_Flipper = $E3 SndID_HTZLiftClick = $E4 SndID_Leaves = $E5 SndID_MegaMackDrop = $E6 SndID_DrawbridgeMove = $E7 SndID_QuickDoorSlam = $E8 SndID_DrawbridgeDown = $E9 SndID_LaserBurst = $EA SndID_Scatter = $EB SndID_LaserFloor = $EB SndID_Teleport = $EC SndID_Error = $ED SndID_MechaSonicBuzz = $EE SndID_LargeLaser = $EF SndID_OilSlide = $F0 SndID__End = $F7</asm>
The following are the lines you should NOT have deleted, just for reference:
<asm>MusID_StopSFX = $78+$80 ; F8 MusID_FadeOut = $79+$80 ; F9 SndID_SegaSound = $7A+$80 ; FA MusID_SpeedUp = $7B+$80 ; FB MusID_SlowDown = $7C+$80 ; FC MusID_Stop = $7D+$80 ; FD MusID_Pause = $7E+$80 ; FE MusID_Unpause = $7F+$80 ; FF</asm>
Now, find these lines:
<asm>Underwater_palette_2: ds.w palette_line_size ; not sure what it's used for but it's only used when there's water Underwater_palette_2_line2: ds.w palette_line_size Underwater_palette_2_line3: ds.w palette_line_size Underwater_palette_2_line4: ds.w palette_line_size
Underwater_palette: ds.w palette_line_size ; main palette for underwater parts of the screen Underwater_palette_line2: ds.w palette_line_size Underwater_palette_line3: ds.w palette_line_size Underwater_palette_line4: ds.w palette_line_size</asm>
Copy these lines to the clipboard (Or better yet, to a separate text document), we are going to be moving them in a moment.
Immediately below where those lines used to be is a line like this:
<asm> ds.b $500 ; $FFFFF100-$FFFFF5FF ; unused, leftover from the Sonic 1 sound driver (and used by it when you port it to Sonic 2)</asm>
Change it to this:
<asm> ds.b $600 ; $FFFFF000-$FFFFF5FF ; Used by the Sonic 2 Clone Driver.</asm>
The underwater palettes were overwriting some RAM that the Sonic 1/Sonic2 Clone Driver use, so we need to move them somewhere safer. Fortunately, such a place in RAM exists.
What we need, are $100 free bytes. So, first off, find the line:
<asm>Normal_palette: ds.w palette_line_size</asm>
Paste the underwater_palette lines right above it.
Right above the lines you just pasted, you should see the following:
<asm>Sprite_Table: ds.b $280 ; Sprite attribute table buffer ds.b $80 ; unused, but SAT buffer can spill over into this area when there are too many sprites on-screen</asm>
Replace them both with just this:
<asm>Sprite_Table: ds.b $200 ; Sprite attribute table buffer</asm>
Step 4 - Introducing the new Sound Driver!
Go back to s2.asm, and right above this line:
<asm> ; end of 'ROM'</asm>
Paste this:
<asm> include "Sonic 2 Clone Driver.asm"</asm>
Now, before anything else, open up Sonic 2 Clone Driver.asm, and find and replace (CRTL+H usually) all instances of "INCBIN" with "BINCLUDE" (Without the quotes).
Repeat the process, replacing all intances of "@loc" with "Lloc". The HG dissasembly does not like local routines, so this converts them into normal routines to avoid errors.
At this point, you can build your ROM if you want. You wont get any sound, but the game will run.
Step 5 - Let the music play!
Go back to S2.asm, and find the label "VintRet:"
In that function, right after the label, paste this line:
<asm> jsr Init_Sonic1_Sound_Driver</asm>
If you were to build your ROM again now, you still wouldn't have sound. We're going to fix that now. Go back to s2.constants.asm, and find these lines:
<asm>Music_to_play: ds.b 1 SFX_to_play: ds.b 1 ; normal SFX_to_play_2: ds.b 1 ; alternating stereo unk_FFE3: ds.b 1 Music_to_play_2: ds.b 1 ; alternate (higher priority?) slot</asm>
Replce theme with this:
<asm> ds.b 1
ds.b 1 ds.b 1
unk_FFE3: ds.b 1
ds.b 1</asm>
If you want to, you can also move the line with 'unk_FFE3' down one line and replace the four resulting "ds.b 1"s with a single "ds.l".
Now, we need to remake the music_to_play and SFX_to_play constants, but a bit differently. Anywhere in s2.constants.asm you deem appropriate (for example, right before the block of RAM equates we just modified, paste this code:
<asm>Music_Pause = $FFFFF003 Music_to_play = $FFFFF00A SFX_to_play = $FFFFF00B</asm>
Go back to S2.asm; we've got more changes to make.
First off, search for and replace all instances of "SFX_to_play_2" with just "SFX_to_play", and "Music_to_play_2" with "Music_to_play".
This fixes most things, but if were to play the game, both the Sega Sound and pausing the game are... REALLY messed up. Lets fix this, too.
Find this line, again, in s2.asm
<asm> move.b #MusID_Pause,(Music_to_play).w ; pause music</asm>
Replace it with this:
<asm> move.b #1,(Music_Pause).w ; pause music</asm>
And replace all instances of this line:
<asm> move.b #MusID_Unpause,(Music_to_play).w</asm>
With this:
<asm> move.b #$80,(Music_Pause).w ; resume music</asm>
Step 6 - Saaay-Gaaah!
Now, lets fix the last problem: The SEGA Sound. You can close s2.constants and s2.asm now, we're done with those.
Our target this time is Sonic 2 Clone Driver.asm.
Search for the label 'SegaPCM:'.
Now, replace
<asm> cnop $0, (((((*+$6978)>>$10)+$01)*$10000)-$6978) SegaPCM: binclude sound\segapcm.bin even</asm>
with
<asm> align $8000 SegaPCM: binclude sound\segapcm.bin SegaPCM_End:</asm>
Next, find the label 'PCM_Table:', and immediately before:
<asm>;-------------------------------------------------------- Kos_Z80: BINCLUDE sound\z80_new.bin</asm>
Paste this:
<asm> dc.l $A00200, SegaPCM dc.w (SegaPCM_End-SegaPCM)/2 dc.b $09, 0</asm>
Finally, go to "Sound_E1:" and replace
<asm> move.b #$88,($A01FFF).l</asm>
with:
<asm> move.b #$88, d0 jsr Calculate_PCM move.b #$81, ($A01FFF).l ; can't use #$88, because that one uses hardcoded offsets</asm>
And we're done! Build it, test out your fixed Sega Sound and pause screen, and have fun!
Credits
Varion Icaria - Puto's sound driver port. Esrael - Tweakers driver port, plus fixes for things broken in Puto's port, such as hanging on the title card. Extra thanks for fixing the Sega sound. Puto - Fixes for underwater palette stuff, as well as special stage ring stuff, and various other fixes to the original guide. Tweaker - Wrote the orignal guide to port Sonic 1's sound driver into Sonic 2. ShadowsofYesterday - Telling me the fix for the SEGA sound. (old version of the guide) ValleyBell - In addition to his original work on the Clone Driver, he showed me numerous things I could do to fix the guide! Caverns4 - I wrote and updated the guide.