Sonic the Hedgehog 2 (Master System)/Level Editing
From Sonic Retro
(Redirected from SCHG:Sonic 2 SMS/Level Editing)
|SCHG: Sonic 2 (Master System)|
Each level header consists of 22 bytes:
AA BBBB CC DDDD EEEE FFFF GGGG HHHH IIII JJJJ KKKK LLLL
- AA = 32x32 mapping bank number
- BBBB = 32x32 mappings pointer
- CC = Level layout bank number
- DDDD = Level layout pointer
- EEEE = Level width in mapping blocks
- FFFF = 2's complement level width in blocks
- GGGG = Vertical offset into layout data. This is always 7 * EEEE.
- HHHH = Minimum camera x coordinate
- IIII = Minimum camera y coordinate
- JJJJ = Maximum camera x coordinate
- KKKK = Maximum camera y coordinate
- LLLL = Pointer to table of multiples of level width.
The EEEE and FFFF words are used by collision detection routines to move backwards and forwards in the level data array, whole rows at a time (e.g. for checking collisions above and below an object). The LLLL field is used to calculate the address of any given row of mappings in the level data array.
ROM addresses for the level headers:
|5635, 564B, 5661||GHZ1/2/3|
|5677, 568D, 56A3||SHZ1/2/3|
|56B9, 56CF, 56E5||ALZ1/2/3|
|56FB, 5711, 5727||UGZ1/2/3|
|573D, 5753, 5769||GMZ1/2/3|
|577F, 5795, 57AB||SEZ1/2/3|
|57C1, 57D7, 57ED||CEZ1/2/3|
First of all, the metatiles begin with an offset index containing 256 16-bit, little endian pointers. The pointers are relative to a fixed position in the ROM, which varies depending on which set of mappings you're looking at. Immediately after the offset index is the metatile data itself. Each 32x32 tile is composed of 16 8x8 tiles. A 16-bit, little endian value is used to define which 8x8 tile is pulled from VRAM, and also how that 8x8 tile is displayed. Adding certain amounts to the value cause the 8x8 tile to be flipped/mirrored:
|$0000||Nothing (no flip, use BG palette, low priority)|
|$0800||Use sprite palette|
Level Layout & compression
Each byte in the level layout represents a 32x32 tile. The level is composed of many 32x32 tiles. In a savestate, the level is easy to edit because it's simple and uncompressed. However, in the ROM it's usually compressed.
2020 2020 2020
FD means compression has occurred. 06 is the number of times a byte has been repeated. 20 is the byte which has been repeated.
Strangely, 1515 (for example) appears in the ROM as FD02 15, which wastes space. Repeated strings of bytes can be used in the ROM, and will appear correctly in the game. Compression is entirely optional, given that there is enough space in the ROM for the data.