Sonic the Hedgehog (8-bit)
From Sonic Retro
This is the Sonic Community Hacking Guide for Sonic the Hedgehog. The Guide is based on notes by David Declerck[1][2] & Kroc Camen. The Music Hacking Guide is based on notes by ValleyBell.
Contents
ROM Map
Master System
Offset | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
$00000 – ? | Main Game Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0122D – $01286 | Zone Titles:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0197E – $019AD | Final Score Titles: The text used for the score bonuses given on the completion of the game
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$02095 – $02AD5 | Credits Text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0627C – $0628B | Palette Pointers:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0628C – $0629E | Palette Cycle Pointers:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0629E – $065EE | Palettes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$0C7F0 – $0FFFF | Music, sounds, and other stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$10000 – $14CA0 | 32×32 Mappings:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$14CA0 – $1517F | UNKNOWN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$15180 – $1557F | Blinking Items Art (Box, etc...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$15580 – $155C9 | Level Header Pointers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$155CA – $15AB3 | Level Headers:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$15AB4 – $15FFF | Sprite Layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$16000 – $16DE9 | Misc Mappings:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$16DEA – $1FFFF | Level Layout:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$20000 – $32FE5 | Contains sprite art and/or sprite mappings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$32FE6 – $3DA27 | Level Art:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$3DA28 – $40000 | Contains sprite art and/or sprite mappings |
Game Gear
Offset | Description |
---|---|
$00000 – $10000 | Main Game Code, musics, sounds... |
$10000 – $14D00 | 32×32 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 |
General Compression
Some data (level layouts, misc. mappings) in the ROM is compressed using a form of Run-Length-Encoding, where bytes that repeat themselves many times in a row are reduced by specifying the number of times to repeat a byte.
In practice, the ROM stores this data normally byte-for-byte but indicates a value to repeat by a duplicate byte followed by another byte that specifies the number of successive bytes to repeat.
A bug / oversight made by the developers means that the byte that specifies the number of times to repeat is off-by-one (causing an overflow (255 → 0). This means that a repeating-value of 01 means zero repeats (therefore wasting space!), 02 means 1 repeat, FF means 255 repeats, but 00 actually means 256 repeats! Be keenly aware of this when de/compressing!
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
- 05 07 5A 5A 03 08 B2 → 05 07 5A 5A 5A 5A 08 B2
- 29 EF 00 00 00 BB D2 → 29 EF 00 00 […00x256…] BB D2
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.
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 ?? UW ?? ?? 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
- 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)
- UW (Under Water flag): Controls the under-water effect (slow movement / water colour / drowning) in Labyrinth (80 is on, 00 is off). Appears to only affect Labyrinth, using this flag on other levels does not create the water effect so either it's hard-coded to Labyrinth or some other undocumented data controls it
- 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
This is a table of the complete level headers for the Master System version: (all values are hexadecimal)
Name | SP | TW | TH | ?? | ?? | LW | LH | ?? | ?? | ?? | ?? | SX | SY | FL | FS | ML | LA | ?? | SA | IP | ?? | CC | CP | SL | ?? | UW | ?? | ?? | MU | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Green Hill Act 1 | 0 | 0100 | 0010 | 40 | 0 | C0 | 18 | 20 | 0 | 40 | 01 | 08 | 0B | 2DEA | 083E | 0000 | 2FE6 | 9 | 612A | 0 | A | 3 | 0 | 0534 | 04 | 0 | 20 | 0 | 0 | ||||||
Green Hill Act 2 | 0080 | 0020 | 01 | A0 | 0C | 01 | 0 | 40 | 03 | 02 | 03 | 3628 | 0661 | 0580 | 04 | 20 | |||||||||||||||||||
Green Hill Act 3 | 0080 | 0020 | 01 | 00 | 0A | E8 | 0 | 40 | 03 | 07 | 16 | 3C89 | 032D | 05C3 | 00 | 00 | |||||||||||||||||||
Bridge Act 1 | 1 | 0100 | 0010 | 01 | 0 | 00 | 1F | 01 | 0 | 40 | 01 | 03 | 0C | 7ED1 | 0694 | 0B80 | 4578 | 9 | 6C3D | 1 | 8 | 3 | 1 | 05D6 | 04 | 0 | 20 | 0 | 1 | ||||||
Bridge 2 | 0080 | 0020 | 0F | 01 | 0 | 40 | 03 | 02 | 1C | A2A8 | 0499 | 061C | 0C | 20 | |||||||||||||||||||||
Bridge 3 | 0080 | 0020 | 0F | 00 | 3 | 40 | 03 | 06 | 1B | B301 | 0140 | 0656 | 00 | 00 | |||||||||||||||||||||
Name | SP | TW | TH | ?? | ?? | LW | LH | ?? | ?? | ?? | ?? | SX | SY | FL | FS | ML | LA | ?? | SA | IP | ?? | CC | CP | SL | ?? | UW | ?? | ?? | MU | ||||||
Jungle Act 1 | 2 | 0100 | 0010 | 01 | 0 | 00 | 1F | 01 | 0 | 20 | 01 | 02 | 0B | 3FB6 | 0AAC | 1480 | 5B00 | 9 | 77CD | 2 | 5 | 3 | 2 | 066C | 04 | 0 | 20 | 0 | 2 | ||||||
Jungle Act 2 | 0010 | 0100 | 01 | 01 | 0 | 20 | 1F | 02 | FA | 4A62 | 08DB | 06C4 | 84 | 20 | |||||||||||||||||||||
Jungle Act 3 | 0080 | 0020 | 0F | 00 | 3 | 40 | 03 | 06 | 1B | B301 | 0140 | 0656 | 00 | 00 | |||||||||||||||||||||
Labyrinth Act 1 | 3 | 0040 | 0040 | 01 | 0 | 00 | 07 | 01 | 0 | 40 | 07 | 02 | 05 | 8565 | 08C2 | 1E80 | 71BF | 9 | 83B6 | 3 | 5 | 3 | 3 | 0723 | 04 | 80 | 20 | 0 | 3 | ||||||
Labyrinth Act 2 | 0040 | 0040 | 03 | 09 | 8E27 | 0D13 | 0772 | 04 | 20 | ||||||||||||||||||||||||||
Labyrinth Act 3 | 0040 | 0040 | 03 | 25 | AFF6 | 030B | 07CA | 00 | 10 | ||||||||||||||||||||||||||
Name | SP | TW | TH | ?? | ?? | LW | LH | ?? | ?? | ?? | ?? | SX | SY | FL | FS | ML | LA | ?? | SA | IP | ?? | CC | CP | SL | ?? | UW | ?? | ?? | MU | ||||||
Scrap Brain Act 1 | 4 | 0100 | 0010 | 01 | 0 | 00 | 1E | 01 | 0 | 20 | 01 | 03 | 0B | 533D | 069A | 2980 | 884B | 9 | 8F75 | 4 | 6 | 4 | 4 | 07E9 | 04 | 0 | 20 | 0 | 4 | ||||||
Scrap Brain Act 2 | 0080 | 0020 | 0F | 01 | 0 | 40 | 03 | 04 | 16 | 59D7 | 0904 | 082C | 20 | ||||||||||||||||||||||
Scrap Brain Act 3 | 0040 | 0040 | 07 | 20 | 2 | 40 | 07 | 03 | 36 | 7282 | 08B2 | 08CE | 00 | ||||||||||||||||||||||
Sky Base Act 1 | 5 | 0080 | 0020 | 01 | 0 | 00 | 0F | 01 | 0 | 40 | 03 | 02 | 1D | 9B3A | 076E | 3580 | 9CEE | 9 | 99E0 | 5 | 6 | 4 | 5 | 091A | 04 | 0 | 22 | 0 | 4 | ||||||
Sky Base Act 2 | 5 | 0040 | 0040 | 07 | 40 | 06 | 0A | 17 | 7B34 | 039D | 3580 | 9CEE | 5 | 6 | 8 | 0954 | 40 | 20 | 5 | ||||||||||||||||
Sky Base Act 3 | 7 | 0040 | 0040 | 07 | 20 | 01 | 02 | 01 | A741 | 04C0 | 4300 | B3B5 | 6 | 8 | 6 | 0997 | 00 | 00 | 4 | ||||||||||||||||
End Sequence | 0 | 0100 | 0010 | 40 | 1A | 00 | 1D | E0 | 0 | E8 | 00 | D9 | 0A | 2DEA | 083E | 0000 | 2FE6 | 9 | AEB1 | 0 | A | 3 | 0 | 0A3A | 00 | 0 | 00 | 0 | FF | ||||||
Name | SP | TW | TH | ?? | ?? | LW | LH | ?? | ?? | ?? | ?? | SX | SY | FL | FS | ML | LA | ?? | SA | IP | ?? | CC | CP | SL | ?? | UW | ?? | ?? | MU | ||||||
Scrap Brain Act 2 (Emerald Maze), From Corridor |
4 | 0040 | 0040 | 01 | 0 | 00 | 07 | 01 | 0 | 40 | 07 | 03 | 3D | 62DB | 08F8 | 2980 | 884B | 9 | 8F75 | 4 | 6 | 4 | 4 | 0869 | 04 | 0 | 20 | 0 | 4 | ||||||
Scrap Brain Act 2 (Ballhog Area) |
0020 | 0080 | 03 | A0 | 0A | 03 | 03 | 6BD3 | 06AF | 08B5 | |||||||||||||||||||||||||
Scrap Brain Act 2, From Transporter |
0080 | 0020 | 0F | 40 | 03 | 50 | 10 | 59D7 | 0904 | 082C | |||||||||||||||||||||||||
Scrap Brain Act 2 (Emerald Maze), From Transporter |
0040 | 0040 | 07 | 40 | 07 | 27 | 1C | 62DB | 08F8 | 0869 | |||||||||||||||||||||||||
Scrap Brain Act 2, From Emerald Maze |
0080 | 0020 | 0F | 40 | 03 | 7B | 03 | 59D7 | 0904 | 082C | |||||||||||||||||||||||||
Scrap Brain Act 2, From Ballhog Area |
0080 | 0020 | 0F | 40 | 03 | 7B | 1B | 59D7 | 0904 | 082C | |||||||||||||||||||||||||
Sky Base Act 2 (Interior) | 7 | 0040 | 0040 | 01 | 0 | 00 | 07 | 01 | 0 | 40 | 07 | 03 | 3B | A741 | 04C0 | 4300 | B3B5 | 9 | 99E0 | 6 | 8 | 4 | 6 | 09A1 | 00 | 0 | 00 | 0 | 4 | ||||||
Name | SP | TW | TH | ?? | ?? | LW | LH | ?? | ?? | ?? | ?? | SX | SY | FL | FS | ML | LA | ?? | SA | IP | ?? | CC | CP | SL | ?? | UW | ?? | ?? | MU | ||||||
Special Stage 1 | 6 | 0040 | 0040 | 01 | 0 | 00 | 07 | 01 | 0 | 40 | 02 | 02 | 06 | B441 | 0760 | 4890 | C7FE | 9 | A511 | 7 | 1 | 1 | 7 | 09A5 | 4 | 0 | 21 | 0 | 10 | ||||||
Special Stage 2 | 0040 | 0040 | 07 | 20 | 3 | C0 | 05 | 02 | 1E | B441 | 0760 | 09AC | |||||||||||||||||||||||
Special Stage 3 | 0040 | 0040 | 07 | 80 | 6 | 40 | 07 | 03 | 3B | B441 | 0760 | 09B6 | |||||||||||||||||||||||
Special Stage 4 | 0010 | 0100 | 01 | 01 | 0 | 20 | 1F | 06 | 40 | 4A62 | 08DB | 09C0 | |||||||||||||||||||||||
Special Stage 5 | 0040 | 0040 | 07 | 01 | 0 | 40 | 02 | 02 | 06 | B441 | 0760 | 09D3 | |||||||||||||||||||||||
Special Stage 6 | 0040 | 0040 | 07 | 20 | 3 | C0 | 05 | 02 | 1E | B441 | 0760 | 09E6 | |||||||||||||||||||||||
Special Stage 7 | 0040 | 0040 | 07 | 80 | 6 | 40 | 07 | 03 | 3B | B441 | 0760 | 09FF | |||||||||||||||||||||||
Special Stage 8 | 0010 | 0100 | 01 | 01 | 0 | 20 | 1F | 06 | 04 | 4A62 | 08DB | 0A15 |
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) |
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
32×32 Mappings
The floor layout for each level is comprised of 32×32 (px) tiles. Each of these 32×32 tiles are composed of 16 smaller 8×8 tiles. From the begining of the data, each set of 16 bytes contains the mappings for a single 32×32 tile.
Here is a 32×32 tile:
- And the corresponding data is:
- 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
Game Gear Version
Offset | 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
Offset | 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) |
Floor Layout
The floor layout is composed of multiple 32×32 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 The compression format). Be careful when compressing and decompressing a level, because it's easy to make it corrupt.
Floor layouts are located at: $16DEA – $1FFFF (Master System) / $17430 – $1F600 (Game Gear) You'll have to use the pointers (Level Headers), in order to determine their starting address.
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 |
Misc Mappings
This section contains the mappings for some screens. It looks like the 32×32 Mappings, except that the 8×8 tiles are written to the screen, so there is more than 16 tiles. Another thing is that they are compressed (see The compression format).
Mappings Offset | Description |
---|---|
$16738 – $16865 | Title Screen |
$16962 – $163F6 | Map 1 Background |
$163F6 – $16AFD | Map 1 Foreground |
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 16×16, 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 8×8 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: $32FE6 (Master System) / $32ED5 (Game Gear)
The level art is composed of 8×8 tiles, which are used by the 32×32 mappings. These 8×8 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). Each header is in the format of:
- FE FN LS LS AD AD X0 X8
(Note that dual-byte values "LS" and "AD" are Little-Endian, the lowest byte first. e.g. "08 01" = "0108")
- FE: "Forty-Eight". Unknown purpose, but in all headers this value is 48
- FN: "Fifty-Nine". Unknown purpose, but in all headers this value is 59
- LS: "Line Selection". An offset from the start of the level art header, to the where the Line Selection data begins. Since the Line Pre-Load is always 256 bytes, this value is always "0108" (256 + 8 in hexadecimal). Perhaps the programmers provided the ability to use less than 256 tiles, but didn't make use of it
- AD: "Art Data". An offset, from the beginning of the level art header (e.g. $32FE6), to the start of the Art Data section. This is critically important because the length of the Line Selection can vary
- X0: Unknown, but in all headers, this value is "0"
- X8: Unknown, but in all headers, this value is "8"
Here is a table of each of the level art headers together for the Master System:
Zone / Level | Address | FE | FN | LS | AD | X0 | X8 |
---|---|---|---|---|---|---|---|
Green Hill | $32FE6 | 48 | 59 | 0108 | 07C2 | 0 | 8 |
Bridge | $3457A | 48 | 59 | 0108 | 0708 | 0 | 8 |
Jungle | $35B02 | 48 | 59 | 0108 | 0677 | 0 | 8 |
Labyrinth | $371C1 | 48 | 59 | 0108 | 06A8 | 0 | 8 |
Scrap Brain | $3884D | 48 | 59 | 0108 | 07A7 | 0 | 8 |
Sky Base 1 / 2 | $39CF0 | 48 | 59 | 0108 | 06DB | 0 | 8 |
Sky Base 3 | $3B3B37 | 48 | 59 | 0108 | 0801 | 0 | 8 |
Special Stages | $3C800 | 48 | 59 | 0108 | 0756 | 0 | 8 |
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 Art Data section simply contains the lines of art data. Each line is 8 pixels wide, and uses 4 bytes. 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!).
Game Text
Strings of text in the game are stored in a simple format that begins with an X / Y location on the screen to begin printing, are terminated with FF and may contain special control-codes, such as FE to move the cursor.
Note that the character codes used for the letters are dependent on the tile map currently being used! There are two tile maps used, one for each of the map screens in the game.
The first map screen shows the overview of the island and is used for the first three zones (Green Hill, Bridge & Jungle). These are the character codes used on this screen:
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | © | ␣ |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
34 | 35 | 36 | 37 | 44 | 45 | 46 | 47 | 40 | 41 | 42 | 43 | 50 | 51 | 52 | 60 | 61 | 62 | 70 | 80 | 81 | 54 | 3C | 3D | 3E | 3F | CF | EB |
The second map screen shows the close-up of the mountain top with Robotnik's fortress, and uses the following character codes:
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | © | ␣ |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1E | 1F | 2E | 2F | 3E | 3F | 4E | 4F | 5E | 5F | 6E | 6F | 7E | 7F | 8E | 8F | 9E | 9F | AE | AF | BE | BF | CE | CF | DE | DF | AB | EB |
Zone Titles
The zone titles ("GREEN HILL", "BRIDGE", …) shown on the map screen are stored at $0122D – $01286 (Master System). Each title is padded with spaces so that all titles are always 12 bytes long.
The first three zones use the character codes from the first map screen, therefore the data looks like this:
Address | Bytes | Text |
---|---|---|
$0122D | 10 13 46 62 44 44 51 EB 47 40 43 43 EB EB FF | GREEN HILL |
$0123C | 10 13 35 62 40 37 46 44 EB EB EB EB EB EB FF | BRIDGE |
$0124B | 10 13 41 81 51 46 43 44 EB EB EB EB EB EB FF | JUNGLE |
The next three zones use the second map screen, therefore the letters appear differently:
Address | Bytes | Text |
---|---|---|
$0125A | 10 13 6F 1E 1F DE 9F 5E 7F AF 4F EB EB EB FF | LABYRINTH |
$01269 | 10 13 AE 2E 9F 1E 8F EB 1F 9F 1E 5E 7F EB FF | SCRAP BRAIN |
$01278 | 10 13 AE 6E DE EB 1F 1E AE 3E EB EB EB EB FF | SKY BASE |
Final Score Titles
Upon completion of the game, a final score screen is shown and bonuses are awarded for the number of emeralds, lives remaining and a "Special Bonus". These titles are stored at $0197E – $019AD (Master System).
Each string is padded with spaces to be 13 characters in length. The first tile set is used.
Address | Bytes | Text |
---|---|---|
$0197E | 08 0A 36 47 34 61 70 EB 44 50 44 62 34 43 37 FF | CHAOS EMERALD |
$0198E | 08 0A 70 52 51 40 36 EB 43 44 45 80 EB EB EB FF | SONIC LEFT |
$0199E | 08 0A 70 60 44 36 40 34 43 EB 35 52 51 81 70 FF | SPECIAL BONUS |
Credits Text
The text for the credits that roll at the end of the game is stored at $02095 – $02AD5 (Master System).
Additional control codes appear in the credits:
- FE XX YY: Moves the cursor to XX, YY on the screen
- FD XX 00: Pauses for XX length. Values 3C, 4B & F0 are used in the credits roll
- FC XX: Number of lines to scroll the credits screen
Note that the credits use the second tile map.
Here is a full decode of the credits roll:
$02905 14 03 AE 9E 7F 5E 2E SONIC FE 15 04 AF 4F 3E THE FE 13 05 4F 3E 2F 4E 3E 4F 9E 4E HEDGEHOG FD 3C 00 FE 12 0C 7E 1E AE AF 3E 9F MASTER FE 13 0D AE DE AE AF 3E 7E SYSTEM FE 14 0E BF 3E 9F AE 5E 9E 7F VERSION FD 3C 00 FC 09 FE 14 0B AE 9E 7F 5E 2E SONIC FE 15 0C AF 4F 3E THE FE 13 0D 4F 3E 2F 4E 3E 4F 9E 4E HEDGEHOG FD 3C 00 FE 12 0F 8E 9F 5E 4E 5E 7F 1E 6F ORIGINAL FE 13 10 2E 4F 1E 9F 1E 2E AF 3E 9F CHARACTER FE 14 11 2F 3E AE 5E 4E 7F DESIGN FD 3C 00 FC 04 FE 14 10 AB AE 3E 4E 1E ©SEGA FD B4 00 FC 09 FE 14 0E AE AF 1E 3F 3F STAFF FD B4 00 FC 09 FE 12 0B 4E 1E 7E 3E GAME FE 13 0C 8F 9F 9E 4E 9F 1E 7E PROGRAM FD 3C 00 FE 13 0E AE 4F 5E 7F 9E 1F BE SHINOBU FE 14 0F 4F 1E DE 1E AE 4F 5E HYASHI FD F0 00 FC 09 FE 12 0B 4E 9F 1E 8F 4F 5E 2E GRAPHIC FE 14 0C 2F 3E AE 5E 4E 7F DESIGN FD 3C 00 FE 13 0E 1E DE 1E 7F 9E AYANO FE 14 0F 6E 9E AE 4F 5E 9F 9E KOSHIRO FD 3C 00 FE 13 11 AF 1E CF 3E 3F BE 7F 5E TAKEFUNI FE 14 12 DE BE 7F 9E BE 3E YUNOUE FD F0 00 FC 09 FE 12 0B AE 9E BE 7F 2F SOUND FE 13 0C 8F 9F 9E 2F BE 2E 3E PRODUCE FD 3C 00 FE 13 0E 7E 1E AE 1E AF 9E MASATO FE 14 0F 7F 1E CF 1E 7E BE 9F 1E NAKAMURA FD F0 00 FC 09 FE 12 0B 9F 3E 1E 9F 9F 1E 7F 4E 3E REARRANGE FE 15 0C 1E 7F 2F AND FE 12 0D 9E 9F 5E 4E 5E 7F 1E 6F ORIGINAL FE 16 0E 7E BE AE 5E 2E MUSIC FD 3C 00 FE 13 10 DE BE DF 9E YUZO FE 14 11 6E 9E AE 4F 5E 9F 9E KOSHIRO FD F0 00 FC 09 FE 13 0D AE 8F 3E 2E 5E 1E 6F SPECIAL FE 15 0E AF 4F 1E 7F 6E AE THANKS FD B4 00 FC 02 FE 13 0E DE 8E AE 4F 5E 8E EB DE YOSHIO Y FD 3C 00 FE 13 11 6F BE 7F 1E 9F 5E 1E 7F LUNARIAN FE 1A 12 AE 4E SG FD B4 00 FC 09 FE 12 0C 8F 9F 3E AE 3E 7F AF 3E 2F PRESENTED FE 16 0E 1F DE BY FE 15 10 AE 3E 4E 1E SEGA FD B4 00 FE 19 13 3E 7F 2F END $02AD5 FF
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 32×32 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
|
80 aaaa bbbb | Set song tempo (only present in channel 1)
|
81 aa | Set volume (0F = max, 00 = min) |
82 aa bb cc dd ee ff | Envelope Setup (only present in channels 1-3)
|
83 aa bb cc dd ee | Vibrato/Pitch Bend (only present in channels 1-3)
|
84 aaaa | Set Detune value to aaaa (aaaa is a signed byte that modifies the FNum)
|
85 aa | Unknown (only present in channel 1)
|
86 | Loop Start Marker
|
87 aa bbbb | Loop back
|
88 | Master Loop Start
|
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
|
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 the Hedgehog (8-bit) | |
---|---|
Manuals |
show;hide
|