Sonic 2 Hacking Guide
Binary - Sound & Music
Music is a great interest to many people. This is one of the difficult areas of the Sonic 2 ROM. The reason is due to the compression used. This doesn't mean that you can't put your own midis into Sonic 2, but you will need to port the Sonic 2 beta music into the ROM instead since that doesn't use compression. So, to port the Sonic 2 beta music into the final ROM, simply copy everything from 0EC000 to 0FFFFF. Once this information is put into the final ROM, you can begin modifying the music.
0F8000 - Song pointers
Each pointer is 16-bits in size. All pointers are in little-endian format (Intel, Z80, etc). They point to the song data per song, in the order that they're listed on the Sonic 2 beta sound test.
The format for the songs is a bit complex. Read carefully and follow along. I will number the important bytes from the start of the song data.
HEADER:
#1 #2 #3 #4 #5 #6 #7 #8
6 - Tempo (4-bit only)
11 + 12 - FM channel 1 pointer
14 - FM channel 1 volume resistance
15 + 16 - FM channel 2 pointer
18 - FM channel 2 volume resistance
19 + 20 - FM channel 3 pointer
22 - FM channel 3 volume resistance
23 + 24 - FM channel 4 pointer
26 - FM channel 4 volume resistance
27 + 28 - FM channel 5 pointer
30 - FM channel 5 volume resistance
31 + 32 - FM channel 6 pointer
34 - FM channel 6 volume resistance
37 + 38 - DAC pointer
43 + 44 - PSG pointer
Now, here are some things you should know for editing music.
00-7F - Note duration
80-DF - Notes (80 is a rest)
E0-FF - Cordination flags
Whenever you need to change the duration of a note, you simply type a number ranging from 00 to 7F. These define how many beats the note will be held for. So, for example, one note with a duration of 06 is the same as 6 notes with a duration of 01.
Not all the cordination flags are known yet, but here are the ones I do know of.
E6xx - subtract xx from channel volume
F6yyyy - jump to position yyyy (little endian)
F7aaxxyyyy - repeat xx times at position yyyy before moving on
If aa is 1, it will reset the repeat values (never-ending loop)
003EA0 - Music playlist for 1 player levels
003EB2 - Music playlist for 2 player levels
These playlists use a single byte for every level to tell the game what music to play for each level. The song values are equivelent to those listed in the sound test, except 80 is added to the value. The following also add 80 to the actual value.
00392B - Sound to play for Sega logo
0051E5 - Sound to play for special stage
009765 - Sound to play for level select and debug codes
009795 - Sound to play for 14 continues code
0097A5 - Sound to play for Super Sonic code
00E731 - Sound to play for EHZ boss
00E827 - Sound to play for MZ boss
00F019 - Sound to play for HTZ boss
00F11D - Sound to play for OOZ boss
00F237 - Sound to play for MCZ boss
00F349 - Sound to play for CNZ boss
00F42B - Sound to play for CPZ boss
00F583 - Sound to play for ARZ boss
011FD7 - Sound to play for ring
012145 - Sound to play for loosing rings
0129CD - Sound to play for super ring
012A25 - Sound to play for super sneakers on
012A37 - Sound to play for shield
012A81 - Sound to play for invincibility
018A69 - Sound to play for spring up
018BBF - Sound to play for spring side
018D63 - Sound to play for spring down
018E97 - Sound to play for spring diag-up
018FA3 - Sound to play for spring diag-down
01926B - Sound to play for Sonic passing end-level sign
0192F9 - Sound to play for Tails passing end-level sign
0192CD - Sound to play for Sonic passing end-level sign (winner)
019349 - Sound to play for Tails passing end-level sign (winner)
01A153 - Sound to play for super sneakers off
01AAAF - Sound to play for Sonic jumping
01AB9D - Sound to play for Super Sonic
01C68B - Sound to play for Tails jumping
01F191 - Sound to play for starpost
0210FB - Sound to play for objects being destroyed (enemies, monitors, etc)
021C55 - Sound to play for seesaw
0223D8 - Sound to play for tire-spring
023D8F - Sound to play for jet-platform spring
024271 - Sound to play for upward pressure-spring
0244C9 - Sound to play for side pressure-spring
02BAA9 - Sound to play for using elevator
02BAFB - Sound to play for elevator returning
What's interesting is the 14 continues code. If you look at the initial value given in the ROM, you'll see why the sound doesn't play properly. They forgot to add 80 to the value! Add 80 to it and it'll play the "continue" sound.
0ED100 - Start of DAC sample data
DAC samples are the drum beats you hear in the music. The format is very simple and easy to understand. Each set of 4-bits represents a pitch. All pitches are played in the piano C key. 'F' represents the highest pitched C you can have, and '1' represents the lowest. Zero is a null, which means that it won't play a note. Here are the locations to the samples I know of so far.
0ED100-0ED394 - Base drum
0ED395-?????? - Hit
0F1E8C-0F7FFF - Sega PCM sound
You can replace the Sega PCM sound easily. You simply need a WAV file that is encoded in 16kHz 8-bit mono format. Then, copy the data in the WAV file starting at address 000038, and put it in place of the Sega PCM sound already in the game.
0ECF36 - Master playlist definitions
The master playlist tells the game exactly what value will play what song. This is different from the regular music playlist because when changing these, it affects any point in the game that uses the specific sound value being changed. Here is the list of songs and their values.
Sound #01 - 92
Sound #02 - 81
Sound #03 - 85
Sound #04 - 8F
Sound #05 - 82
Sound #06 - 94
Sound #07 - 86
Sound #08 - 80
Sound #09 - 83
Sound #0A - 87
Sound #0B - 84
Sound #0C - 91
Sound #0D - 8E
Sound #0E - 8C
Sound #0F - 90
Sound #10 - 9B
Sound #11 - 89
Sound #12 - 88
Sound #13 - 8D
Sound #14 - 8B
Sound #15 - 9A
Sound #16 - 93
Sound #17 - 95
Sound #18 - B5
Sound #19 - 96
Sound #1A - 97
Sound #1B - B8
Sound #1C - ??
Sound #1D - BA
Sound #1E - BD
Sound #1F - 9C
The master playlist goes in order from sound #01 and goes up to #1F. If you see an 'FF', ignore it and move to the next byte.