Actions

SCHG

Difference between revisions of "Sonic the Hedgehog (8-bit)"

From Sonic Retro

m (Channel Data: various minor fixes)
(Channel Data: added info about envelope and vibrato commands)
Line 1: Line 1:
This is the '''[[Sonic Community Hacking Guide]] for ''[[Sonic the Hedgehog (8-bit)|Sonic the Hedgehog]]'''''. The Guide is based on notes by [[David Declerck]].
+
This is the '''[[Sonic Community Hacking Guide]] for ''[[Sonic the Hedgehog (8-bit)|Sonic the Hedgehog]]'''''. The Guide is based on notes by [[David Declerck]], the Music Hacking Guide is based on notes by [[ValleyBell]].
  
 
===ROM Map===
 
===ROM Map===
Line 1,006: Line 1,006:
 
|-
 
|-
 
|}
 
|}
The only difference in the music section of the SMS and GG version is, that the GG version of song 13 has an inserted 83-command.
+
The only difference in the music section of the SMS and GG version is, that the GG version of song 13 has an additional 83 (vibrato) command.
  
 
====Song Format====
 
====Song Format====
Line 1,048: Line 1,048:
 
*bb = Tempo Multipler
 
*bb = Tempo Multipler
 
*aa gets copied to $DC08 and bb gets copied to $DC0A and $DC0C<br>collecting a Speed Shoe increases the Tempo Multipler at $DC0A by 1
 
*aa gets copied to $DC08 and bb gets copied to $DC0A and $DC0C<br>collecting a Speed Shoe increases the Tempo Multipler at $DC0A by 1
*BPM = 120 * aa / bb (120 BPM for 30 Ticks per Quarter)
+
*BPM = 120 * aa / bb (120 for 30 Ticks per Quarter)
 
|-
 
|-
 
|81 aa||Set volume (0F = max, 00 = min)
 
|81 aa||Set volume (0F = max, 00 = min)
 
|-
 
|-
|82 aa bb cc dd ee ff||Unknown (only present in channels 1-3)
+
|82 aa bb cc dd ee ff||Envelope Setup (only present in channels 1-3)
*aa is always FF
+
*aa = attack rate (usually FF)
 +
*bb = decay 1 rate (00 - slow, FF - fast)
 +
*cc = decay 1 level (00 - min, FF - max)
 +
*dd = decay 2 rate
 +
*ee = decay 2 level
 +
*ff = decay 3 rate
 
|-
 
|-
 
|83 aa bb cc dd ee||Vibrato/Pitch Bend (only present in channels 1-3)
 
|83 aa bb cc dd ee||Vibrato/Pitch Bend (only present in channels 1-3)
 +
*aa = Delay
 +
*bb = Speed
 +
*cc = Step Count + 1
 +
**Note: Step 0 (dd=01) stops instead of reversing the counter's direction
 +
*dd = Change per Step
 +
*ee = Vibrato Type (only the 4 lower bits are used)
 +
**Note: some vibrato types sound really weird, so it seems to be intended for SFX only and it's best to leave it at zero
 
|-
 
|-
 
|84 aaaa||Set Detune value to aaaa (aaaa is a signed byte that modifies the FNum)
 
|84 aaaa||Set Detune value to aaaa (aaaa is a signed byte that modifies the FNum)

Revision as of 14:24, 5 September 2011

This is the Sonic Community Hacking Guide for Sonic the Hedgehog. The Guide is based on notes by David Declerck, the Music Hacking Guide is based on notes by ValleyBell.

ROM Map

Here is a small ROM Map. It lists the general sections of the Sonic 1 GG ROM.

Offset Description
$00000 - $10000 Main Game Code, musics, sounds...
$10000 - $14D00 32x32 Mappings
$14D00 - $15200 Unknown
$15200 - $15600 Blinking Items Art (Box, etc...)
$15600 - $1564A Level Headers Pointers
$1564A - $15B34 Level Headers
$15B34 - $16200 Sprite Layout
$16200 - $16738 Unknown
$16738 - $17430 Misc Mappings
$17430 - $1F600 Level Layout
$1F600 - $20000 Sega Screen Art / Mappings
$20000 - $23400 Sonic Art / Mappings
$23400 - $23450 Palettes Pointers
$23450 - $23C00 Palettes
$23C00 - $25500 'Sega' sound
$25500 - $30000 Art : Title Screen / Map / Levels / Stats / Sprites
$30000 - $40000 Art : Sega Screen / Map / Levels
$3DA28 - $40000 Contains sprite art and/or sprite mappings

32x32 Mappings

The floor layout for each level is comprised of a 32x32 tiles. Each of these 32x32 tiles are composed of 16 smaller 8x8 tiles. From the begining of the data, each set of 16 bytes contains the mappings for a single 32x32 tile.

Here is a 32x32 tile:

32x32.png

And the corresponding data is:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

Game Gear Version

Description
$10000 - $10BB0 Green Hill (187 tiles)
$10BB0 - $11510 Bridge (150 tiles)
$11510 - $11FE0 Jungle (128 tiles)
$11FE0 - $12A10 Labyrinth (208 tiles)
$12A10 - $135B0 Scrap Brain (186 tiles)
$135B0 - $14330 Sky Base 1-2 (216 tiles)
$14330 - $149B0 Sky Base 3 (104 tiles)
$149B0 - $14D00 Bonus Stage (53 tiles)

Master System Version

Description
$10000 - $10B80 Green Hill (184 tiles)
$10B80 - $11480 Bridge (144 tiles)
$11480 - $11E80 Jungle (160 tiles)
$11E80 - $12980 Labyrinth (176 tiles)
$12980 - $13580 Scrap Brain (192 tiles)
$13580 - $14300 Sky Base 1-2 (216 tiles)
$14300 - $14980 Sky Base 3 (104 tiles)
$14980 - ? Bonus Stage (? tiles)

Level Headers / Level Headers Pointers

Each level has a header. This header contains several pieces of data, such as starting position, music location, etc. Each level header is 37 bytes long and is referenced by a pointer.

Level Headers Pointers

A level header pointer is comprised of two bytes. The data for the pointer is stored in little endian format. The value stored by this pointer specifies the number of bytes away a level header is from 15600.

In the Game Gear Version, Level Header Pointers are located at: $15600 - $1564A

In the Master System Version, Level Header Pointers are located at: $15580 - $155CA

Example: The two first bytes are 4A 00. So, at $15600 + $004A, we will find the level header for the first level (Green Hill 1).

Level Headers

Each level header use 37 bytes. Here is the format (partial):

SP TW TW TH TH ?? ?? LW LH ?? ?? ?? ??
SX SY FL FL FS FS ML ML LA LA ?? SA SA
IP ?? CC CP SL SL ?? ?? ?? ?? MU
  • SP (Solidity Pointer): Indicates what solidity data to use
  • TW,TH (Tiles Wide, Tiles High): Rough level dimension, in other words how many tiles wide and high the level is (low byte is first)
  • LW,LH (Level Width, Level Height): Real level dimensions (divided by 32), used to limit the view
  • SX,SY (Start X, Start Y): Player starting position (divided by 32)
  • FL (Floor Location): How many bytes away from 14000 the floor is located (Little Endian)
  • FS (Floor Size): Floor data size, in bytes (Little Endian)
  • ML (Mappings Location): How many bytes away from 10000 the mappings for this level are located (Little Endian)
  • LA (Level Art): How many bytes away from 30002 the level art is located (Little Endian)
  • SA (Sprite Art): How many bytes away from ????? is the sprite art located (Little Endian)
  • IP (Initial Palette): Indicates the number of the initial palette pointer to use, in the pointer order of appearance (so, indicates the palette)
  • CC (Color Cycles): Indicates the number of color cycles for the level palette (see 8. Level Palettes)
  • CP (Cyclic Palette): Indicates the number of the cyclic palette pointer to use, in the pointer order of appearance (so, indicates the palette)
  • SL (Sprites Location): How many bytes away from 15580 (SMS) / 15600 (GG) the sprite layout is located (Little Endian)
  • MU (Music):
    • 00-05: Level Music
    • 06: Title Music
    • 08: Invincibility
    • 09: Level Complete
    • 0A: Dead
    • 0B/0C/0D: Boss
    • 0E: Credits
    • 10: Bonus Stage

In the Game Gear version, Level Headers are located at $1564A - $15B34

In the Master System version, Level Headers are located at $155CA

Level Order

There are 37 Level Headers in total. These are the levels they point to. Some levels have more than one pointer because they can be accessed from different locations, and Sonic's starting position differs at level start.

Index Zone
00 Green Hill Act 1
01 Green Hill Act 2
02 Green Hill Act 3
03 Bridge Act 1
04 Bridge Act 2
05 Bridge Act 3
06 Jungle Act 1
07 Jungle Act 2
08 Jungle Act 3
09 Labyrinth Act 1
10 Labyrinth Act 2
11 Labyrinth Act 3
12 Scrap Brain Act 1
13 Scrap Brain Act 2
14 Scrap Brain Act 3
15 Sky Base Act 1
16 Sky Base Act 2
17 Sky Base Act 3
18 Ending Sequence
19 ??? (same as 36)
20 Scrap Brain Act 2 (Emerald Maze), from corridor
21 Scrap Brain Act 2 (Ballhog Area)
22 Scrap Brain Act 2, from transporter
23 Scrap Brain Act 2 (Emerald Maze), from transporter
24 Scrap Brain Act 2, from Emerald Maze
25 Scrap Brain Act 2, from Ballhog Area
26 Sky Base Act 2 (Interior)
27 Sky Base Act 2 (Interior), this one is identical
28 Special Stage 1
29 Special Stage 2
30 Special Stage 3
31 Special Stage 4
32 Special Stage 5
33 Special Stage 6
34 Special Stage 7
35 Special Stage 8
36 ??? (same as 19)

Sprite Layout

Sprites are special parts of a level. They can move, attack, give you rings, and do a lot of other things, even if they are not visible.

Sprite Layout Data begins with one byte, which is the total number of sprites in the zone plus one. Immediately following is the sprite data itself. Each sprite uses 3 bytes. Here is the format:

OO XX YY

XX and YY are the object's coordinates divided by 32. OO is one of the object listed below. (Both the GG and SMS version share the same Sprite Layout Data.)

ID Description
00 Empty (no object)
01 Super Ring monitor
02 Power Sneakers monitor
03 One-Up monitor
04 Shield monitor
05 Invincibility monitor
06 Chaos Emerald
07 End sign
08 Badnik "Crabmeat" (GH)
09 Wooden platform - Swinging (GH)
0B Wooden platform (GH)
0C Wooden platform - Falls when touched (GH)
0E Badnik "Buzz Bomber" (GH/B)
0F Wooden platform - Sliding left-right (GH)
10 Badnik "Moto Bug" (GH)
11 Badnik "Newtron" (GH)
12 Robotnik - Green Hill Boss (GH)
16 Flame Thrower (SB)
17 Door - Opens from left only (SB)
18 Door - Opens from right only (SB)
19 Door - Two ways (SB)
1A Electric sphere (SB)
1B Badnik "Ball Hog" (SB)
1C Unknown - Ball from the "Ball Hog" ?
1D Switch (SB, L, others ?)
1E Switch Activated Door (SB)
1F Badnik "Caterkiller" (SB)
21 Bumper - Sliding left-right (Bonus Stage ?)
22 Robotnik - Scrap Brain Boss (SB)
23 Free animal - Rabbit
24 Free animal - Bird
25 Animal Cell
26 Badnik "Chopper" (J, B)
27 Vertical Step - Falling from a waterfall (J)
28 Horizontal Step - Falling from a waterfall (J)
29 Floating Step - Sonic can travel with it (J)
2C Robotnik - Jungle Boss (J)
2D Badnik "Yadrin" (B)
30 Passing Clouds (SKYB)
31 Propeller (SKYB)
32 Badnik "Bomb" (SKYB)
33 Large Cannons in Sky Base Act 2 (SKYB)
35 Badnik "Unidus" (SKYB)
37 Rotating cannon (SKYB)
38 Flying platform (SKYB)
39 Spiked wall slowly moving right (SKYB)
3A Small cannon in Sky Base Act 1 (SKYB)
3B Flying platform moving up-down (SKYB)
3C Badnik "Jaws" (L)
3D Rotating spiked ball (L)
3E Spear, shifting up-down (L)
3F Fire ball thrower (L)
40 Water Level Object (L)
41 Bubble Maker (L)
44 Badnik "Burrobot" (L)
45 Platform, move up when touched (L)
46 Electrical Hazard for the Sky Base Boss (SKYB)
48 Robotnik - Bridge Boss (SB)
49 Robotnik - Labyrinth Boss (L)
4A Robotnik - Sky Base Boss (SKYB)
4B Zone that makes you fall (like in GH2)
4C Flipper (Bonus Stage)
4D Reset!
4E Balance (B)
4F Reset!
50 Flower (GH)
51 Box - Starpost
52 Box - Continue
53 Final animation in GH, when Sonic falls on Robotnik (then, goes to the next level)
54 Emeralds animation (on the map), when Sonic has them all (and goes to the next level)
55 Makes Sonic blink for a short time

It seems that no more sprites are defined.

Sprite Layout Data Locations

You can use the Level Headers to determine where are the sprites located at. Or you can use this table.

Zone Offset (SMS) Offset (GG)
Green Hill Act 1 $15AB4 $15B34
Green Hill Act 2 $15B00 $15B80
Green Hill Act 3 $15B43 $15BC3
Bridge Act 1 $15B56 $15BD6
Bridge Act 2 $15B9C $15C1C
Bridge Act 3 $15BD6 $15C50
Jungle Act 1 $15BEC $15C66
Jungle Act 2 $15C44 $15CC1
Jungle Act 3 $15C8D $15D04
Labyrinth Act 1 $15CA3 $15D1A
Labyrinth Act 2 $15CF2 $15D5A
Labyrinth Act 3 $15D4A $15DB2
Scrap Brain Act 1 $15D69 $15DD1
Scrap Brain Act 2 $15DAC $15E20
Scrap Brain Act 2 (Emerald Maze) $15DE9 $15E60
Scrap Brain Act 2 (Ballhog Area) $15E35 $15EAC
Scrap Brain Act 3 $15E4E $15ECE
Sky Base Act 1 $15E9A $15F1A
Sky Base Act 2 $15ED4 $15F54
Sky Base Act 2 (Interior) $15F21 $15FAD
Sky Base Act 3 $15F17 $15FA3
Special Stage 1 $15F26 $15FB1
Special Stage 2 $15F2C $15FC1
Special Stage 3 $15F36 $15FCB
Special Stage 4 $15F40 $15FD2
Special Stage 5 $15F53 $15FE5
Special Stage 6 $15F66 $15FFE
Special Stage 7 $15F7F $16014
Special Stage 8 $15F95 $1602A
Final "Cutscene" $15FBA $16046

The compression format

Some data in the ROM is compressed using a rather weird but easy to understand format. This compression format is used to compress levels and some mappings (see section 7).

The compression format is based on a simple principle : if several successive bytes are identical, space can be saved by specifying how many times that byte is repeated.

The algorithm for compressing data is as follows :

-> While two successive bytes are different
-> Bytes are stored without any compression
-> If two or more successive bytes are the same
-> The byte repeated is written twice
-> The number of times the byte is repeated, minus 1, is calculated. The result is written as a third byte.

An explanation about this 'minus 1':

During decompression, when the game finds two identical bytes, it writes the first one, and then it writes the second one X times, where X is the value of the third byte.

Example:

06 7C 32 2E 2E 01 D1 -> 06 7C 32 2E 2E D1
6B 3F 3F 02 51 2D C0 -> 6B 3F 3F 3F 51 2D C0
05 07 5A 5A 03 08 B2 -> 05 07 5A 5A 5A 5A 08 B2

As you can see, this format wastes one byte of space if a byte is only repeated twice. If a byte is repeated three times, there is no size difference. Only when a byte is repeated four or more times is there a savings in space usage.

Floor Layout

The floor layout is composed of multiple 32x32 tiles. Each byte indicates the number of the tile to which to use. However, the data is compressed, so you will have to decompress it first (see 5. The compression format). Be careful when compressing and decompressing a level, because it's easy to make it corrupt.

Floor layouts are located at: 17430 - 1F600 You'll have to use the pointers (Level Headers), in order to determine their starting address.

Misc Mappings

This section contains the mappings for some screens. It looks like the 32x32 Mappings, except that the 8x8 tiles are written to the screen, so there is more than 16 tiles. Another thing is that they are compressed (see 5. The compression format).

Mappings Offset Description
$16738 - $16865 Title Screen
$16962 - $163F6 Map 1 Background
$163F6 - $16AFD Map 1 Foreground

Level Palettes / Level Palettes Pointers

Level Palettes Pointers

This is an easy section, but reading the Level Headers section may help you a bit. Well, you probably noticed that levels generally have the same palettes for the three acts (the exception is Sky Base). If you use MEKA, you can see that a palette is composed of 32 colors. We can divide this palette into two 16 colors sub-palettes (the first one for colors 1-16, the second one for colors 17-32). When the GG loads a level, it loads the initial palette, which contains 16 colors (colors are applied to the second sub-palette). Then, while you are playing, you can see that there are color cycles. In fact, the GG switch between several palettes, so you think that there is a cycle. These palettes contains only 16 colors, and are applied on the first sub-palette only. All these palettes are all referenced by a pointer, which is 2 bytes long, and little endian. There are 8 pointers (16 bytes, little endian). They point to the level color cycles. The 16 next pointers are still unknown. The 8 next are blank pointers. Finally, The 8 next pointers point to the level initial palette. Pointers represent how many bytes away from 23400 are the palettes located at.

Palettes Pointers are located at : $24000 - $24350

Initial level palettes pointers:

Offset Description
$23440 Green Hill
$23442 Bridge
$23444 Jungle
$23446 Labyrinth
$23448 Scrap Brain
$2344A Sky Base 1/2A
$2344C Sky Base 2B/3
$2344E Special Stage

Level palettes color cycle pointers:

Offset Description
$23400 Green Hill
$23402 Bridge
$23404 Jungle
$23406 Labyrinth
$23408 Scrap Brain
$2340A Sky Base 1/2A
$2340C Sky Base 2B/3
$2340E Special Stage

Level Palettes

Now that you know everything about palettes pointers, you can start the palettes. There is just one thing you must remember : initial palettes always contain an half-palette (16 colors). Color cycles can contain a variable quantity of half-palettes (16 colors applied to the first sub-palette). This variable quantity corresponds to the CC parameter in the level header. OK, now, let's start.

The GG uses 9-bit colors, so, each color use two bytes (the first nibble of the second byte is 0, and values for a nibble are set 2 by 2). This color can be defined like that : R(0-7), G(0-7), B(0-7). So, there are only 8 possible values for each primary color. Here are the RGB correspondence : 0=1=0, 2=3=36, 4=5=72, 6=7=109, 8=9=145, A=B=182, C=D=218, E=F=255. So, you can have a maximum of 512 colors.

The format for the two bytes is : GR 0B

Blinking Items Art

In the game, there are some blinking items. The most common are the box items. You can easily edit them. Each of these items is 16x16, but you must understand that it is composed of four 8x8 tiles. The tiles are displayed from up to down and from left to right. The format is the same as the art in savestates (32 bytes for each 8x8 tile, 128 bytes for the item). For more information, refer to the S1 SMS Savestates Hacking Guide.

Blinking items are located at : 15200 - 15600

Here are the items you can edit :

ID Description
1 Super Rings
2 Power Sneakers
3 One-Up
4 Shield
5 Invincible
6 Chaos Emerald
7 Starpost
8 Continue

Level Art

This is a quite difficult section, because the level art is compressed in a very strange way. The compression format itself is not so difficult to apply, but learning it is not a piece of cake. First, I'll describe each part of the level art, then I'll give more details.

The level art starts at : 32ED5

The level art is composed of 8x8 tiles, which are used by the 32x32 mappings. These 8x8 tiles are composed of 8 lines of art data. In other terms, the compression format relies on the fact that these lines can be used by several different tiles. So, these lines will be written to the art data only once. During decompression, the game will use two methods to write the lines to the tile. One is bit-based, but doesn't allow to choose what line of art data to write to the tile; the second one is byte-based, and it allows to choose the line of art data to write to the tile. The game use both methods. It is very important that you understand this paragraph, so read it again.

From what I said, you can guess that there will be 3 sections for each level. But, there is also an 8 bytes header at the beginning (for each level too). The second section is what I call "Line Pre-load" (the most complex section, containing bit-based compressed data), the third one is "Line Selection" (containing the byte-based compressed data), and the last one is "Art Data".

The header contains infos on all the data, but I haven't figured out how it works. I know that the fith byte has something to do with colors.

The Art Data section simply contains the lines of art data. Each line is 8 pixels wide, and uses 4 bytes. The format is described in the S1 SMS Savestates Hacking Guide. Note that there won't be two identical lines of art data here (it's evident if you followed what I said).

Now, the most complex section, the Line Pre-load. It's 256 bytes (one byte for each tile). A 1 byte number can be converted to a 8-bit number. Yeah, 8-bit, and there are 8 lines in a tile. So, each bit will be associated with a line of the tile. The rightmost bit will be associated to the topmost line of the tile. So, the byte will be read from right to left. Note that before starting to load the art, the GG puts a pointer at the begining of the Art Data. While reading the byte, each time the GG meets a 0, it will write the pointed line of art data to the tile, at the position indicated by the position of the 0, and move the pointer to the next line of art data (don't forget that 1 line of art data = 4 bytes). The process repeats until all the bytes were read. As for now, we have 256 partial tiles.

The last section is the Line Selection. As you know, we have partial tiles. We need to put something in the blank lines. For each tile, there is a certain quantity of lines that were not defined. We will call that quantity L. To calculate L, simply count the number of 1's there is in the corresponding byte in the Line Pre-Load section. Well, now you can start reading the data in Line Selection. This section contains line numbers. You must read L line numbers for each tile (remember that L depends on the tile). Each line number indicates a line of art data to write to the tile. These lines must be written were no lines were defined. To determine where to write the lines in the tile, use the positions of the 1's in the corresponding byte in the Line Pre-Load section. The last thing you must know is the format for each line number. This is a bit special. For line numbers 00 to EF (0 to 239), there is only one byte, indicating the line number. However, for tiles after EF, there are two bytes. The first one starts with an F, so the actual line number is the two bytes number minus F0 00. Ex : F3 A2 is for art line number 3A2. Note that you can also write line numbers 00 to EF using two bytes numbers, but this is a waste of space (that's why they are stored with one byte !).

Well, that was hard to explain. And it is hard to understand, yeah. I have another method, I'll give you it soon.

Offset Description
$32ED5 - $32EDD Header for Green Hill Art
$32EDD - $32FDD Line Pre-Load for Green Hill
$32FDD - $3364E Line Selection for Green Hill
$3364E - $344AE Green Hill Art Data

RAM Editing

To convert offset values to Gens Plus 0.0.9.61 savestate values, add $00A4.

Offset Description
$0000 Tile Layout Data
$1400 Object Status Table (?)
$1403 Sonic's X speed
$1406 Sonic's Y speed
$202C Palette
$206C Tile Graphics Data

Tile Layout Data

Unlike in the ROM, the data here is uncompressed. Each byte directly corresponds to one 32x32 tile.

The number of tiles in a horizontal line before they wrap around differs depending on the width of the Zone. Here is table of the values.

Zone Tile Line Data Size in Bytes
Green Hill Act 1 256
Green Hill Act 2 128
Green Hill Act 3 128
Bridge Act 1 256
Bridge Act 2 128
Bridge Act 3 128
Jungle Act 1 256
Jungle Act 2 16
Jungle Act 3 64
Labyrinth Act 1 64
Labyrinth Act 2 64
Labyrinth Act 3 64
Scrap Brain Act 1 256
Scrap Brain Act 2 128
Scrap Brain Act 2 (Emerald Maze) 64
Scrap Brain Act 2 (Ballhog Area) 32
Scrap Brain Act 3 64
Sky Base Act 1 128
Sky Base Act 2 64
Sky Base Act 2 (Interior) 64
Sky Base Act 3 64

Music Hacking

Music Locations

  • Music Pointers (These add to $8000): $C716
    • Specifics...
Song ID Location (SMS) Location (GG) Song
00 C7D0 C7D0 Green Hill Zone
01 D74A D74A Bridge Zone
02 D24A D24A Jungle Zone
03 F60C F60C Labyrinth Zone
04 DB4F DB4F Scrap Brain Zone
05 E1A7 E1A7 Sky Base Zone
06 E4C3 E4C3 Title Screen
07 E63C E63C Map Screen (Act Intro)
08 E704 E704 Invincible
09 E8B4 E8B4 Act Complete
0A E991 E991 Death
0B EAC0 EAC0 Boss Theme
0C EAC0 EAC0 Boss Theme
0D EAC0 EAC0 Boss Theme
0E ED54 ED54 Ending
0F C7D0 C7D0 Green Hill Zone
10 F12C F12C Bonus Zone
11 C7D0 C7D0 Green Hill Zone
12 C7D0 C7D0 Green Hill Zone
13 F98C F98C Unused (some SFX)
14 FA26 FA32 Chaos Emerald

The only difference in the music section of the SMS and GG version is, that the GG version of song 13 has an additional 83 (vibrato) command.

Song Format

All pointers in a song are absolute (i.e. relative to the beginning of the song) 16-bit pointers stored in Little Endian (Intel) format.

Song Header
Offset Size Description
00 Word Pointer to Channel 1 Data (usually points to 000A)
02 Word Pointer to Channel 2 Data
04 Word Pointer to Channel 3 Data
06 Word Pointer to Channel 4/Noise Data
08 Word unused (always zero)
Channel Data

There's no header for channel data. Channel setup is done via commands.
The commands start directly at the offset specified in the header.

Command Description
00-7F xx Play Note with length xx
  • if dd is 0, the value set by 8A is used
  • Note Values:
    • Tone: first nibble is the octave, second nibble is the key
      Key is a signed value with A = -3 .. C = -0, C = +0 .. B = +11 (-0 is the same C as +0)
    • Noise: 70 - Bass Drum, 71 - Snare Drum, others are maybe used for SFX
    • 7F - Rest
80 aaaa bbbb Set song tempo (only present in channel 1)
  • aa = Tempo Divider
  • bb = Tempo Multipler
  • aa gets copied to $DC08 and bb gets copied to $DC0A and $DC0C
    collecting a Speed Shoe increases the Tempo Multipler at $DC0A by 1
  • BPM = 120 * aa / bb (120 for 30 Ticks per Quarter)
81 aa Set volume (0F = max, 00 = min)
82 aa bb cc dd ee ff Envelope Setup (only present in channels 1-3)
  • aa = attack rate (usually FF)
  • bb = decay 1 rate (00 - slow, FF - fast)
  • cc = decay 1 level (00 - min, FF - max)
  • dd = decay 2 rate
  • ee = decay 2 level
  • ff = decay 3 rate
83 aa bb cc dd ee Vibrato/Pitch Bend (only present in channels 1-3)
  • aa = Delay
  • bb = Speed
  • cc = Step Count + 1
    • Note: Step 0 (dd=01) stops instead of reversing the counter's direction
  • dd = Change per Step
  • ee = Vibrato Type (only the 4 lower bits are used)
    • Note: some vibrato types sound really weird, so it seems to be intended for SFX only and it's best to leave it at zero
84 aaaa Set Detune value to aaaa (aaaa is a signed byte that modifies the FNum)
  • positive value = higher FNum = lower note
85 aa Unknown (only present in channel 1)
  • aa is always FF (with very few excpetions)
86 Loop Start Marker
  • increases Loop Stack Pointer
87 aa bbbb Loop back
  • aa - number of times to repeat
  • bbbb - Position to loop back to (usually points to the byte after the 86 command)
  • Note: When leaving the loop, the Loop Stack Pointer is decreased.
88 Master Loop Start
  • sets the master loop address for this channel
8A aa Set default note length to aa
8B Increase volume by 1
8C Decrease volume by 1
8D no attack for next note
FF Track End
  • When this command is enountered and the master loop address is set, the driver jumps back to the address set by the 88 command.
Note on 86/87

The 86 command is used the make nested loops possible.
Example: 86 86 ... 87 04 aaaa ... 87 02 bbbb

Note on 88/FF

There's no need for an 88 command in non-looping songs.
However every jingle (with exception of the Death-Jingle) has a master loop, consisting of a rest.


Sonic Community Hacking Guide
General
SonED2 Manual | Subroutine Equivalency List
Game-Specific
Sonic the Hedgehog (16-bit) | Sonic the Hedgehog (8-bit) | Sonic CD (prototype 510) | Sonic CD | Sonic CD (PC) | Sonic CD (2011) | Sonic 2 (Simon Wai prototype) | Sonic 2 (16-bit) | Sonic 2 (Master System) | Sonic 3 | Sonic 3 & Knuckles | Chaotix | Sonic Jam | Sonic Jam 6 | Sonic Adventure | Sonic Adventure DX: Director's Cut | Sonic Adventure DX: PC | Sonic Adventure (2010) | Sonic Adventure 2 | Sonic Adventure 2: Battle | Sonic Adventure 2 (PC) | Sonic Heroes | Sonic Riders | Sonic the Hedgehog (2006) | Sonic & Sega All-Stars Racing | Sonic Unleashed (Xbox 360/PS3) | Sonic Colours | Sonic Generations | Sonic Forces
Technical information
Sonic Eraser | Sonic 2 (Nick Arcade prototype) | Sonic CD (prototype; 1992-12-04) | Dr. Robotnik's Mean Bean Machine | Sonic Triple Trouble | Tails Adventures | Sonic Crackers | Sonic 3D: Flickies' Island | Sonic & Knuckles Collection | Sonic R | Sonic Shuffle | Sonic Advance | Sonic Advance 3 | Sonic Battle | Shadow the Hedgehog | Sonic Rush | Sonic Classic Collection | Sonic Free Riders | Sonic Lost World
Legacy Guides
The Nemesis Hacking Guides The Esrael Hacking Guides
ROM: Sonic 1 | Sonic 2 | Sonic 2 Beta | Sonic 3

Savestate: Sonic 1 | Sonic 2 Beta/Final | Sonic 3

Sonic 1 (English / Portuguese) | Sonic 2 Beta (English / Portuguese) | Sonic 2 and Knuckles (English / Portuguese)
Move to Sega Retro
Number Systems (or scrap) | Assembly Hacking Guide | 68000 Instruction Set | 68000 ASM-to-Hex Code Reference | SMPS Music Hacking Guide | Mega Drive technical information