Actions

SCHG How-to

Fix the SEGA Sound

From Sonic Retro

Revision as of 12:30, 26 December 2007 by Tweaker (talk | contribs) (Migrating final source code line)

Let's fix a problem that causes a great deal of pain to anyone adding code to Sonic 1: The SEGA sound.

Thanks to Esrael, we can now fix it properly, without having it garbled every time a line of code is added behind it.

So go to SoundDriverLoad, and after this line:

<asm> bsr.w KosDec ; decompress</asm>

Add this:

<asm> move.b #(SegaPCM/$10000),$A00019.l</asm>

Similarly, go to where SegaPCM is, and right before that, add the following line:

<asm> cnop -$6978,$10000</asm>

And before the "even", add this:

<asm>EndSegaPCM:</asm>

So the final result should look like this:

<asm> cnop -$6978,$10000 SegaPCM: incbin sound\segapcm.bin EndSegaPCM: even</asm>


And the SoundDriverLoad routine should look like this:

<asm>SoundDriverLoad: ; XREF: GameClrRAM; TitleScreen nop move.w #$100,($A11100).l ; stop the Z80 move.w #$100,($A11200).l ; reset the Z80 lea (Kos_Z80).l,a0 ; load sound driver lea ($A00000).l,a1 bsr.w KosDec ; decompress move.b #(SegaPCM/$10000),$A00019.l move.w #0,($A11200).l nop nop nop nop move.w #$100,($A11200).l ; reset the Z80 move.w #0,($A11100).l ; start the Z80 rts </asm>

Finally, the compile time calculation that's done at Kos_Z80 is stupid, as it relies on the SegaPCM being at the end of the ROM, which isn't the case anymore.
So go to Kos_Z80, and replace all instances of EndOfRom with EndSegaPCM. The end result will then be this:

<asm>Kos_Z80: incbin sound\z80_1.bin dc.w ((SegaPCM&$FF)<<8)+((SegaPCM&$FF00)>>8) dc.b $21 dc.w (((EndSegaPCM-SegaPCM)&$FF)<<8)+(((EndSegaPCM-SegaPCM)&$FF00)>>8) incbin sound\z80_2.bin even</asm>