Actions

SCHG How-to

Difference between revisions of "Port Sonic 3's Sound Driver to Sonic 2"

From Sonic Retro

(Upgrading the Load Driver Routine)
(Upgrading the Load Driver Routine)
Line 75: Line 75:
 
; End of function sndDriverInput
 
; End of function sndDriverInput
 
</asm>
 
</asm>
 +
and remove it.  we don't need it anymore.

Revision as of 16:47, 24 May 2014

(Original guide by Kram1024)

You probably saw my method of placing the sonic3 sound driver in sonic 1. Well, we are going to put it in sonic2 Rev01 this time. The changes are very similar to that of the sonic1 port. over the years I found that the s3 driver actually works without a sonic game with minimal hacking (it just needs a wait routine to time it.) Thus it is actually possible to put it into sonic2 with rather ease as well and into a homebrew too, though in homebrew it might not be legal anyways due to IP laws but sega no longer enforces them on genesis games anyways, thus why nobody gets sued for sonic hacks, but lets get back to the hack.

Overview

First off, Sonic 3's sound driver has the V_Int reloader built into it so it is not needed, some routines need replacement, sounds need fixing, and we need to replace the sounds and music. We will be using the latest github version, if you wish to do it via a different version, I am sure you can come up with a way that works by seeing what changes I made in the github version.

Preparing to use Sonic 3/K/3K sound system

The Vertical Interrupt and Horizontal Interrupt need to be fixed, since the sonic 1/2 system uses them but the Sonic 3/K/3K system doesn't.

Removal of all callbacks to the s2 driver in the vertical interupt

Unlike the s1 driver, sonic2 actually calls the driver over and over again after stopping the z80 then restarting the z80. The playsound routine of our new driver will do that automatically, so we do not really need any of that kind of code. we will search for all instances of: <asm> stopZ80 ; stop the Z80 bsr.w sndDriverInput ; give input to the sound driver startZ80 ; start the Z80 </asm> and comment it out or just plain remove it. I prefer to replace it with a nop instruction, but even comments or removal work as well. In case you are a little lazy, here is a list of routines with this code:
VintSub0
Loc_54A
Vint0_noWater (only touch the " bsr.w sndDriverInput ; give input to the sound driver" line)
loc_748 (only touch the " bsr.w sndDriverInput ; give input to the sound driver" line)
Vint10_specialStage (only touch the " jsr (sndDriverInput).l)
loc_92A+++++ (only touch the " jsr (sndDriverInput).l)
loc_BD6 (only touch the " jsr (sndDriverInput).l)
VintSub18 (only touch the " bsr.w sndDriverInput)
VintSub16 (only touch the " bsr.w sndDriverInput)
Loc_EFE (only touch the " bsr.w sndDriverInput)

Upgrading the Load Driver Routine

Okay, we disabled the sonic2 z80 sound driver junk, wouldn't we want now to use the sonic3 driver instead? Here is where we start installing it. Locate: <asm> sndDriverInput: lea (Music_to_play&$00FFFFFF).l,a0 lea (Z80_RAM+zComRange).l,a1 ; $A01B80 cmpi.b #$80,8(a1) ; If this (zReadyFlag) isn't $80, the driver is processing a previous sound request. bne.s loc_10C4 ; So we'll wait until at least the next frame before putting anything in there. _move.b 0(a0),d0 beq.s loc_10A4 _clr.b 0(a0) bra.s loc_10AE

---------------------------------------------------------------------------

loc_10A4: move.b 4(a0),d0 ; If there was something in Music_to_play_2, check what that was. Else, just go to the loop. beq.s loc_10C4 clr.b 4(a0)

loc_10AE: ; Check that the sound is not FE or FF move.b d0,d1 ; If it is, we need to put it in $A01B83 as $7F or $80 respectively subi.b #$FE,d1 bcs.s loc_10C0 addi.b #$7F,d1 move.b d1,3(a1) bra.s loc_10C4

---------------------------------------------------------------------------

loc_10C0: move.b d0,8(a1)

loc_10C4: moveq #4-1,d1 ; FFE4 (Music_to_play_2) goes to 1B8C (zMusicToPlay), - move.b 1(a0,d1.w),d0 ; FFE3 (unk_FFE3) goes to 1B8B, (unknown) beq.s + ; FFE2 (SFX_to_play_2) goes to 1B8A (zSFXToPlay2), tst.b 9(a1,d1.w) ; FFE1 (SFX_to_play) goes to 1B89 (zSFXToPlay). bne.s + clr.b 1(a0,d1.w) move.b d0,9(a1,d1.w) + dbf d1,- rts

End of function sndDriverInput

</asm> and remove it. we don't need it anymore.