Actions

SCHG How-to

Port Sonic 1's Sound Driver to Sonic 2

From Sonic Retro

Revision as of 22:34, 15 November 2019 by Shadow05 (talk | contribs) (Instructions: Updated)

(Original guide by Tweaker)

Introduction

For anyone who's worked with Sonic 2 before, you'll notice that managing music can be a bit of a hassle. Music has to be in a specific location, has to stay within a certain sound bank... and there's a limited number of sounds you can have in the game. However, the sound driver in Sonic 1 is entirely written in 68k (except for the DAC driver), making it much easier to edit, and much easier to manage music with. There are no limitations on where you can place music data, as the pointers use relative addressing.

So, when Puto comes to me with his own port of the Sonic 1 sound driver, and said he had problems, I showed him a personal port that Esrael made for Sonic 2 Megamix. Together, we were able to fully patch up all the issues that the driver has when ported to Sonic 2. Therefore, we decided we'd make a guide, that, when followed correctly, allows anybody to use the Sonic 1 sound driver in their hack! Included below is the Sonic 1 sound driver in its own separate ASM file, which you can edit freely, along with the original folder structure for the sound driver's music data, sound data, etc.

Anyway, on with the guide!

This doesn't seem to work in Kega Fusion.

Instructions

Okay, first we're going to get the actual driver to load. Go to VintRet, which should be this:

VintRet:
	addq.l	#1,($FFFFFE0C).w
	movem.l	(sp)+,d0-a6
	rte

And change it to this...

VintRet:
	jsr	Init_Sonic1_Sound_Driver	; init Sonic 1 sound driver
	addq.l	#1,($FFFFFE0C).w
	movem.l	(sp)+,d0-a6
	rte

Next, go to JmpTo_SoundDriverLoad, which should be this:

JmpTo_SoundDriverLoad 
	nop
	jmp	(SoundDriverLoad).l
; End of function JmpTo_SoundDriverLoad

And change the whole surrounding area to this, including the unused Sonic 1 sound driver loading code...

JmpTo_SoundDriverLoad 
	move.w	#$100,(Z80_Bus_Request).l ; stop the Z80
	move.w	#$100,(Z80_Reset).l ; reset the Z80
	lea	(Kos_Z80).l,a0
	lea	(Z80_RAM).l,a1
	bsr.w	KosDec
	move.b	#$F3,(a1)+
	move.b	#$F3,(a1)+
	move.b	#$C3,(a1)+
	move.b	#0,(a1)+
	move.b	#0,(a1)+
	move.w	#0,(Z80_Reset).l
	nop
	nop
	nop
	nop
	move.w	#$100,(Z80_Reset).l ; reset the Z80
	move.w	#0,(Z80_Bus_Request).l ; start the Z80
	rts

Next, find PlayMusic, which should be this:

PlayMusic:
	tst.b	(Music_to_play).w
	bne.s	+
	move.b	d0,(Music_to_play).w
	rts
+
	move.b	d0,(Music_to_play_2).w
	rts
; End of function PlayMusic

And change it to this...

PlayMusic:
	move.b	d0,($FFFFF00A).w
	rts
; End of function PlayMusic

Next find PlaySound, and find this:

PlaySound:
	move.b	d0,(SFX_to_play).w
	rts
; End of function PlaySound

And replace it with this...

PlaySound:
	move.b	d0,($FFFFF00B).w
	rts
; End of function PlaySound

Now, we're going to fix the broken sound effects, such as rings. Look for amything that references PlaySoundStereo, and change it to PlayMusic. You can also remove PlaySoundStereo all together.

Now, look for PlaySoundLocal. It should be this:

PlaySoundLocal:
	tst.b	render_flags(a0)
	bpl.s	+
	move.b	d0,(SFX_to_play).w
+
	rts
; End of function PlaySoundLocal

Replace it with this:

PlaySoundLocal:
	tst.b	render_flags(a0)
	bpl.s	+
	move.b	d0,($FFFFF00B).w
+
	rts

Next, we're going to fix the music so it stops correctly when you pause. Find the "+" after PauseGame, which should be this:

+
	move.w	#1,(Game_paused).w	; freeze time
	move.b	#-2,(Music_to_play).w	; pause music

And replace it with this...

+
	move.w	#1,(Game_paused).w	; freeze time
	move.b	#1,($FFFFF003).w	; pause music

Next, go to loc_13F2, which should be this:

loc_13F2:
	move.b	#-1,(Music_to_play).w

And replace it with this...

loc_13F2:
	move.b	#$80,($FFFFF003).w

Now, find Pause_SlowMo, which should be this:

Pause_SlowMo:
	move.w	#1,(Game_paused).w
	move.b	#-1,(Music_to_play).w
	rts

And replace it with this...

Pause_SlowMo:
	move.w	#1,(Game_paused).w
	move.b	#1,($FFFFF003).w
	rts

Next, find loc_541A, which should be this:

loc_541A:
	move.b	#-1,(Music_to_play).w
	move.b	#8,(Delay_Time).w
	bra.w	DelayProgram

And replace it with this...

loc_541A:
	move.b	#1,($FFFFF003).w
	move.b	#8,(Delay_Time).w
	bra.w	DelayProgram

Now, we're going to fix the underwater palettes, since the sound driver uses some space in RAM that, in S2, is used for underwater palettes. Do a search and replace (ctrl+h) and replace all instances of "$FFFFF080" with "$FFFFFA80" - what this will do is make the game read from the Sonic 1 location for underwater palettes, which is unused in S2, and unaffected by the sound driver. Also replace $FFFFF000 and $FFFFF0E0 with $FFFFFA00 and $FFFFFAE0 respectively.

Next, go to PalLoad4_Water. What we're going to do is change a line in it to match the Sonic 1 routine, so the underwater palettes load to the correct address. The routine should look like this:

PalLoad4_Water:
	lea	(PalPointers).l,a1
	lsl.w	#3,d0
	adda.w	d0,a1
	movea.l	(a1)+,a2
	movea.w	(a1)+,a3
	suba.l	#$B00,a3
	move.w	(a1)+,d7

-	move.l	(a2)+,(a3)+
	dbf	d7,-
	rts
; End of function PalLoad4_Water

Change it to this:

PalLoad4_Water:
	lea	(PalPointers).l,a1
	lsl.w	#3,d0
	adda.w	d0,a1
	movea.l	(a1)+,a2
	movea.w	(a1)+,a3
	suba.l	#$80,a3
	move.w	(a1)+,d7

-	move.l	(a2)+,(a3)+
	dbf	d7,-
	rts
; End of function PalLoad4_Water

What this does is change how much the game subtracts from $FB00, in order to calculate the location to move underwater palettes to.

The final step is to grab a slightly modified version of the Sonic 1 sound driver from Hivebrain's 2005 Sonic 1 disassembly (link below), and insert it into the Sonic 2 disassembly - the location does not matter, though I personally recommend the end of the ROM. You can also delete the Sonic 2 sound driver now, if you wish, though it is not required to do so.

You can either use the include directive to insert S1 Sound Driver.asm, or you can simply copy/paste what's in there. Either will be sufficient.

Note

Certain sound effects and music from Sonic 2 WILL be missing, and you WILL need to add these yourself if you wish to still have them in game. To add a sound effect/music, simply tack it at the end of SoundIndex or MusicIndex. You can also get rid of SoundD0Index (and related setup) if you wish, as Sonic 2 does not have any sound effects that require it.

Sound Driver Files

Download.svg Download The Sonic 1 sound driver files
File: S1SoundDriverFiles.zip (66 kB) (info)

Credits

  • Varion Icaria - Puto's sound driver port.
  • Esrael - My 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.
  • StephenUK - Hints on how to fix the underwater stuff.
  • drx - Hacking CulT's VDP calculator.
  • Myself - I helped Puto fix the underwater stuff, and I wrote the guide. =P

And that's it! Enjoy! Let me or Puto know if there's any issues left, and we'll try and patch them up.

SCHG How-To Guide: Sonic the Hedgehog 2 (16-bit)
Fixing Bugs
Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix Super Sonic Bugs | Use Correct Height When Roll Jumping | Fix Jump Height Bug When Exiting Water | Fix Screen Boundary Spin Dash Bug | Correct Drowning Bugs | Fix Camera Y Position for Tails | Fix Tails Subanimation Error | Fix Tails' Respawn Speeds | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix Rexon Crash | Fix Monitor Collision Bug | Fix EHZ Deformation Bug | Correct CPZ Boss Attack Behavior | Fix Bug in ARZ Boss Arrow's Platform Behavior | Fix ARZ Boss Walking on Air Glitch | Fix ARZ Boss Sprite Behavior | Fix Multiple CNZ Boss Bugs | Fix HTZ Background Scrolling Mountains | Fix OOZ Launcher Speed Up Glitch | Fix DEZ Giant Mech Collision Glitch | Fix Boss Deconstruction Behavior | Fix Speed Bugs | Fix 14 Continues Cheat | Fix Debug Mode Crash | Fix 99+ Lives | Fix Sonic 2's Sega Screen
Design Choices
Remove the Air Speed Cap | Disable Floor Collision While Dying | Modify Super Sonic Transformation Methods & Behavior | Enable/Disable Tails in Certain Levels | Collide with Water After Being Hurt | Retain Rings When Returning at a Star Post | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Insert LZ Water Ripple Effect | Restore Lost CPZ Boss Feature | Prevent SCZ Tornado Spin Dash Death | Improve ObjectMove Subroutines | Port S3K Rings Manager | Port S3K Object Manager | Port S3K Priority Manager | Edit Level Order with ASM‎ | Alter Ring Requirements in Special Stages | Make Special Stage Characters Use Normal DPLCs | Speed Up Ring Loss Process | Change spike behaviour in Sonic 2
Adding Features
Create Insta-kill and High Jump Monitors | Create Clone and Special Stage Monitors | Port Knuckles
Sound Features
Expand Music Index to Start at $00 | Port Sonic 1 Sound Driver | Port Sonic 2 Clone Driver | Port Sonic 3 Sound Driver | Port Flamewing's Sonic 3 & Knuckles Sound Driver | Expand the Music Index to Start at $00 (Sonic 2 Clone Driver Version) | Play Different Songs Per Act
Extending the Game
Extend the Level Index Past $10 | Extend the Level Select | Extend Water Tables | Add Extra Characters | Free Up 2 Universal SSTs


|Port Sonic 1's Sound Driver to Sonic 2]]