Difference between revisions of "Fix Song Restoration Bugs in Sonic 1's Sound Driver"
From Sonic Retro
m (Added S1Howtos template) |
(Added section on fixing FM6, and made an optimisation to MJ's code) |
||
Line 1: | Line 1: | ||
− | {{GuideBy|MarkeyJester}} | + | {{GuideBy|MarkeyJester|Clownacy}} |
− | + | There are two bugs with the track restoration system in [[Sonic the Hedgehog (16-bit)|<i>Sonic 1's</i>]] [[sega:SMPS|sound driver]] that will be fixed here. One for the DAC, and one for FM 6, with the latter bug stemming from how they share a channel. But first, the former: | |
− | == | + | ==Fixing the DAC fade-in bug== |
+ | When collecting an extra life, the engine stores away the currently playing music track, and then plays the extra life jingle. Once the extra life jingle has finished playing, the previous track is restored at very low volume, and then fades into normal volume. The DAC (drum samples) does not have fading-in capabilities for this engine, so it does not resume until the music has finished fading into full volume. | ||
− | + | ===Explaining the issue=== | |
− | ==Fixing the issue== | + | If you pause the game while the music track is fading back in, and then unpause, the DAC channel does not resume; it remains mute. It seems that the pause routine not only sets the keys off, but it also turns off the left and right speaker panning for each channel (because of the release rate), and unpausing causes the system to reset all of the channel's panning/AMS/FMS values. Of course, if the music is going through a fade-in, then the DAC channel (occupying the FM 6 channel) must remain mute until the music has fully faded, hence, the panning/AMS/FMS value for FM 6 does not get updated while DAC is running, until of course; either a new track is played, the game is paused and unpaused again after fading, or the DAC channel changes speakers during its script. |
+ | |||
+ | ===Fixing the issue=== | ||
We need to go to "loc_726D6:" | We need to go to "loc_726D6:" | ||
Line 14: | Line 17: | ||
clr.b $24(a6) | clr.b $24(a6) | ||
rts</asm> | rts</asm> | ||
− | The first instruction clears the fade out mute bit, which was set by the "E4" flag (fade out into previous track), the second instruction clears the fading out flag (telling the system that fading out is complete), the "key on" values are resumed by the system already through natural course, all that's left is to reset the L/R/AMS/FMS of FM6 on the YM2612, like so: | + | The first instruction clears the fade out mute bit, which was set by the "E4" flag (fade out into previous track), the second instruction clears the "currently fading out" flag (telling the system that fading out is complete), the "key on" values are resumed by the system already through natural course, all that's left is to reset the L/R/AMS/FMS of FM6 on the YM2612, like so: |
<asm>loc_726D6: | <asm>loc_726D6: | ||
bclr #2,$40(a6) | bclr #2,$40(a6) | ||
clr.b $24(a6) | clr.b $24(a6) | ||
+ | |||
tst.b $40(a6) ; is the DAC channel running? | tst.b $40(a6) ; is the DAC channel running? | ||
bpl.s Resume_NoDAC ; if not, branch | bpl.s Resume_NoDAC ; if not, branch | ||
+ | |||
moveq #$FFFFFFB6,d0 ; prepare FM channel 3/6 L/R/AMS/FMS address | moveq #$FFFFFFB6,d0 ; prepare FM channel 3/6 L/R/AMS/FMS address | ||
move.b $4A(a6),d1 ; load DAC channel's L/R/AMS/FMS value | move.b $4A(a6),d1 ; load DAC channel's L/R/AMS/FMS value | ||
− | + | jmp sub_72764(pc) ; write to FM 6 | |
Resume_NoDAC: | Resume_NoDAC: | ||
rts</asm> | rts</asm> | ||
− | Now the DAC channel will resume correctly after fade in. | + | Now the DAC channel will resume correctly after fade-in. |
+ | |||
+ | ==Fixing the FM 6 restoration bug== | ||
+ | When playing through <i>Sonic 1's</i> [[Special Stage (Sonic the Hedgehog 16-bit)|special stages]], you may happen upon 100 rings and the resultant extra life. After the jingle stops playing, however, you'll find that something was lost: the special stage's theme loses a track, FM 6 to be precise. But why? And how do we fix it? | ||
+ | |||
+ | ===Explaining the issue=== | ||
+ | |||
+ | As mentioned before, FM 6 and the DAC share a channel, so you can only have one playing at a time. The is done through the changing of some variables. Now, when the extra life jingle kicks in, the DAC is set to play, and it plays. Following that, the aforementioned track restoration takes place. That's all. You see the problem? FM 6 isn't re-enabled! Because of this, the DAC will have priority of the channel, but nothing plays on the DAC track, so the song loses a channel overall. | ||
+ | |||
+ | ===Fixing the issue=== | ||
+ | |||
+ | What we need to do is find the code that restores the track data, and then make it re-enable FM 6 if needed. To do that, go to "loc_72B14:", and scroll down, until just above "loc_72B9E:". There, you will see this: | ||
+ | <asm> movea.l a3,a5</asm> | ||
+ | Directly below it, insert this: | ||
+ | <asm> tst.b $40(a6) ; is the DAC channel running? | ||
+ | bmi.s Restore_NoFM6 ; if it is, branch | ||
+ | |||
+ | moveq #$2B,d0 ; DAC enable/disable register | ||
+ | moveq #0,d1 ; Disable DAC | ||
+ | jsr sub_7272E(pc) | ||
+ | |||
+ | Restore_NoFM6:</asm> | ||
+ | Now FM 6 will be restored when needed. | ||
+ | |||
{{S1Howtos}} | {{S1Howtos}} | ||
[[Category:SCHG How-tos|((PAGENAME))]] | [[Category:SCHG How-tos|((PAGENAME))]] |
Revision as of 08:55, 30 September 2014
(Original guide by MarkeyJester and Clownacy)
There are two bugs with the track restoration system in Sonic 1's sound driver that will be fixed here. One for the DAC, and one for FM 6, with the latter bug stemming from how they share a channel. But first, the former:
Contents
Fixing the DAC fade-in bug
When collecting an extra life, the engine stores away the currently playing music track, and then plays the extra life jingle. Once the extra life jingle has finished playing, the previous track is restored at very low volume, and then fades into normal volume. The DAC (drum samples) does not have fading-in capabilities for this engine, so it does not resume until the music has finished fading into full volume.
Explaining the issue
If you pause the game while the music track is fading back in, and then unpause, the DAC channel does not resume; it remains mute. It seems that the pause routine not only sets the keys off, but it also turns off the left and right speaker panning for each channel (because of the release rate), and unpausing causes the system to reset all of the channel's panning/AMS/FMS values. Of course, if the music is going through a fade-in, then the DAC channel (occupying the FM 6 channel) must remain mute until the music has fully faded, hence, the panning/AMS/FMS value for FM 6 does not get updated while DAC is running, until of course; either a new track is played, the game is paused and unpaused again after fading, or the DAC channel changes speakers during its script.
Fixing the issue
We need to go to "loc_726D6:"
<asm> bclr #2,$40(a6) clr.b $24(a6) rts</asm> The first instruction clears the fade out mute bit, which was set by the "E4" flag (fade out into previous track), the second instruction clears the "currently fading out" flag (telling the system that fading out is complete), the "key on" values are resumed by the system already through natural course, all that's left is to reset the L/R/AMS/FMS of FM6 on the YM2612, like so:
<asm>loc_726D6: bclr #2,$40(a6) clr.b $24(a6)
tst.b $40(a6) ; is the DAC channel running? bpl.s Resume_NoDAC ; if not, branch
moveq #$FFFFFFB6,d0 ; prepare FM channel 3/6 L/R/AMS/FMS address move.b $4A(a6),d1 ; load DAC channel's L/R/AMS/FMS value jmp sub_72764(pc) ; write to FM 6
Resume_NoDAC: rts</asm> Now the DAC channel will resume correctly after fade-in.
Fixing the FM 6 restoration bug
When playing through Sonic 1's special stages, you may happen upon 100 rings and the resultant extra life. After the jingle stops playing, however, you'll find that something was lost: the special stage's theme loses a track, FM 6 to be precise. But why? And how do we fix it?
Explaining the issue
As mentioned before, FM 6 and the DAC share a channel, so you can only have one playing at a time. The is done through the changing of some variables. Now, when the extra life jingle kicks in, the DAC is set to play, and it plays. Following that, the aforementioned track restoration takes place. That's all. You see the problem? FM 6 isn't re-enabled! Because of this, the DAC will have priority of the channel, but nothing plays on the DAC track, so the song loses a channel overall.
Fixing the issue
What we need to do is find the code that restores the track data, and then make it re-enable FM 6 if needed. To do that, go to "loc_72B14:", and scroll down, until just above "loc_72B9E:". There, you will see this: <asm> movea.l a3,a5</asm> Directly below it, insert this: <asm> tst.b $40(a6) ; is the DAC channel running? bmi.s Restore_NoFM6 ; if it is, branch
moveq #$2B,d0 ; DAC enable/disable register moveq #0,d1 ; Disable DAC jsr sub_7272E(pc)
Restore_NoFM6:</asm> Now FM 6 will be restored when needed.