(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.
The bug is when sometimes when you build the ROM, at the very end of the "SEGA" sound is a static noise (probably the bat sound) so it sounds like, "SEGA-TS" . There is also another one, which sounds like "THOUGNGH-THOUGNGH" .So anyway, lets fix this!
Go to "segapcm:" and you should see:
SegaPCM: incbin sound\segapcm.bin even
now change it to this
SegaPCM: incbin sound\segapcm.bin SegaPCM_end: even
Then go to Sound_E1, and replace all of this code:
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
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 #(SegaPCM_End-SegaPCM),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
If you are using the latest version of the GitHub community disassembly, the Sega PCM will always work and you don't need to apply the above fix.
If, however, you want the ability to stop the Sega sound by pressing start, then you will need to perform the steps on the previous section. You may skip the first part (defining SegaPCM_end) as it is already done; on the remainder, search for PlaySega instead of Sound_E1. At this point, the Sonic 1 z80 sound driver does not allow interrupting the Sega PCM, which is why that is needed. In addition, you will have to go to the ReadJoypads function and change this:
ReadJoypads: ; XREF: VBlank, HBlank lea (v_jpadhold1).w,a0 ; address where joypad states are written lea ($A10003).l,a1 ; first joypad port bsr.s @read ; do the first joypad addq.w #2,a1 ; do the second joypad @read:
ReadJoypads: ; XREF: VBlank, HBlank lea (v_jpadhold1).w,a0 ; address where joypad states are written lea ($A10003).l,a1 ; first joypad port bsr.s Joypad_Read ; do the first joypad addq.w #2,a1 ; do the second joypad Joypad_Read:
or else you'll get an error when building.
|SCHG How-To Guide: Sonic the Hedgehog (16-bit)|
|Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix the SEGA Sound | Display the Press Start Button Text | Fix the Level Select Menu | Fix the Hidden Points Bug | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix the Walk-Jump Bug | Correct Drowning Bugs | Fix the Death Boundary Bug | Fix the Camera Follow Bug | Fix Song Restoration Bugs | Fix the HUD Blinking | Fix the Level Select Graphics Bug | Fix a remember sprite related bug|
|Changing Design Choices|
|Change Spike Behavior | Fix Special Stage Jumping Physics | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Remove the Speed Cap | Port the REV01 Background Effects | Port Sonic 2's Level Art Loader | Retain Rings Between Acts | Add Sonic 2 (Simon Wai Prototype) Level Select | Improve ObjectMove Subroutines | Port Sonic 2 Level Select|
|Add Spin Dash ( Part 1 / Part 2 / Part 3 / Part 4 ) | Add Eggman Monitor|
|Expand Music Index From $94 to $9F | Extend Music Slots | Play Different Songs Per Act | Expand Music Index to Start at $00 | Port Sonic 2 Final Sound Driver | Port Sonic 3's Sound Driver|
|Extending the Game|
|Load Chunks From ROM | Add Extra Characters | Make an Alternative Title Screen | Use Dynamic Tilesets | Make GHZ Load Alternate Art | Add a New Zone | Set Up the Goggle Monitor | Add New Moves | Add a Dynamic Collision System | Dynamic Special Stage Walls System | Extend Sprite Mappings and Art Limit | Enigma Credits|
|Convert the Hivebrain 2005 Disassembly to ASM68K|
|Split Disassembly Guides|
|Set Up a Split Disassembly | Basic Level Editing | Basic Art Editing | Basic ASM Editing (Spin Dash)|