Actions

SCHG How-to

Difference between revisions of "Fix the SEGA Sound"

From Sonic Retro

m
m
Line 3: Line 3:
 
Let's fix a problem that causes a great deal of pain to anyone adding code to Sonic 1: The SEGA sound.  
 
Let's fix a problem that causes a great deal of pain to anyone adding code to Sonic 1: The SEGA sound.  
  
So go to Sound_E1, and replace this:
+
So go to ''Sound_E1'', and replace this:
 
<asm>Sound_E1: ; XREF: Sound_ExIndex
 
<asm>Sound_E1: ; XREF: Sound_ExIndex
 
move.b #$88,($A01FFF).l
 
move.b #$88,($A01FFF).l
Line 17: Line 17:
 
rts</asm>
 
rts</asm>
  
with this:
+
With this:
 
<asm>Sound_E1:    
 
<asm>Sound_E1:    
 
lea (SegaPCM).l,a2 ; Load the SEGA PCM sample into a2. It's important that we use a2 since a0 and a1 are going to be used up ahead when reading the joypad ports  
 
lea (SegaPCM).l,a2 ; Load the SEGA PCM sample into a2. It's important that we use a2 since a0 and a1 are going to be used up ahead when reading the joypad ports  
Line 38: Line 38:
 
rts</asm>
 
rts</asm>
  
If using the SVN community disassembly, the line above
+
== SVN disassembly continuation ==
 +
If you are using the SVN community disassembly you need to do the following steps as well.
 +
 
 +
The line:
 
<asm>jsr (Joypad_Read).w</asm>
 
<asm>jsr (Joypad_Read).w</asm>
should be changed to
+
Needs to be changed to:
 
<asm>jsr (ReadJoypads).w</asm>
 
<asm>jsr (ReadJoypads).w</asm>
or you will get an error when you build. However, the SEGA sound may play slowly for some reason.
+
Or else you'll get an error when building. However, the SEGA sound may play slowly for some reason. To fix this (or at least circumvent it) you can edit this line:
 
 
To fix this (or at least circumvent it) you can change the line:
 
 
<asm>move.w #$14,d0 ; Write the pitch ($14 in this case) to d0</asm>
 
<asm>move.w #$14,d0 ; Write the pitch ($14 in this case) to d0</asm>
and change the #$14 value to any other value (try it with #$2 or #$3). If this value is high, the pitch gets lower, and viceversa. Tweak it to your taste.
+
Change the #$14 value to any other value (try it with ''#$2'' or ''#$3''). If this value is high, the pitch gets lower, and viceversa. Tweak it to your taste.
 
 
 
[[Category:SCHG How-tos|Fix the SEGA Sound]]
 
[[Category:SCHG How-tos|Fix the SEGA Sound]]

Revision as of 15:51, 21 November 2009

(Original guide by Puto)

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

So go to Sound_E1, and replace this: <asm>Sound_E1: ; XREF: Sound_ExIndex move.b #$88,($A01FFF).l move.w #0,($A11100).l ; start the Z80 move.w #$11,d1 loc_71FC0: move.w #-1,d0 loc_71FC4: nop dbf d0,loc_71FC4 dbf d1,loc_71FC0 addq.w #4,sp rts</asm>

With this: <asm>Sound_E1: lea (SegaPCM).l,a2 ; Load the SEGA PCM sample into a2. It's important that we use a2 since a0 and a1 are going to be used up ahead when reading the joypad ports move.l #$6978,d3 ; Load the size of the SEGA PCM sample into d3 move.b #$2A,($A04000).l ; $A04000 = $2A -> Write to DAC channel PlayPCM_Loop: move.b (a2)+,($A04001).l ; Write the PCM data (contained in a2) to $A04001 (YM2612 register D0) move.w #$14,d0 ; Write the pitch ($14 in this case) to d0 dbf d0,* ; Decrement d0; jump to itself if not 0. (for pitch control, avoids playing the sample too fast) sub.l #1,d3 ; Subtract 1 from the PCM sample size beq.s return_PlayPCM ; If d3 = 0, we finished playing the PCM sample, so stop playing, leave this loop, and unfreeze the 68K lea ($FFFFF604).w,a0 ; address where JoyPad states are written lea ($A10003).l,a1 ; address where JoyPad states are read from jsr (Joypad_Read).w ; Read only the first joypad port. It's important that we do NOT do the two ports, we don't have the cycles for that btst #7,($FFFFF604).w ; Check for Start button bne.s return_PlayPCM ; If start is pressed, stop playing, leave this loop, and unfreeze the 68K bra.s PlayPCM_Loop ; Otherwise, continue playing PCM sample return_PlayPCM: addq.w #4,sp rts</asm>

SVN disassembly continuation

If you are using the SVN community disassembly you need to do the following steps as well.

The line: <asm>jsr (Joypad_Read).w</asm> Needs to be changed to: <asm>jsr (ReadJoypads).w</asm> Or else you'll get an error when building. However, the SEGA sound may play slowly for some reason. To fix this (or at least circumvent it) you can edit this line: <asm>move.w #$14,d0 ; Write the pitch ($14 in this case) to d0</asm> Change the #$14 value to any other value (try it with #$2 or #$3). If this value is high, the pitch gets lower, and viceversa. Tweak it to your taste.