SEGA Master System format
This document describes the format of data in Prince of Persia 1 for the Sega Master System.
(A similar but slightly different version was released for the Sega Game Gear.)
Contents
General
Byte order
Little-endian (Intel) byte order is used, unless noted otherwise. This is the native endianness of the Z80 CPU in the Sega Master System.
Addresses
There are two kinds of addresses (pointers) in the ROM. Both are stored on 2 bytes.
1. Linear addresses. These are simply an address into the ROM. Linear pointers can address only the first 64 kiB of the ROM, but they can point to any byte within that area.
2. Banked addresses. These can be converted to linear addresses with the following code:
int BankedToLinear(int address) { int bank = address & 0x000F; int offset = address & 0xFFF0; // assert(0x8000 <= offset && offset <= 0xBFFF); return (bank << 14) + (offset - 0x8000); }
Banked pointers can address the whole 256 kiB of the ROM, but only in increments of 16 bytes.
Levels
The level table
The level table starts at offset 0x6A7C. (TODO: In the Game Gear version it starts at 0x719C.)
There are 14 levels. The table stores 20 bytes about each level:
Size | Contents |
---|---|
2 bytes | Always 0x60C9. |
2 bytes | Banked address of graphics tiles: 0x8003 (0x0C000) for dungeon levels, 0x94C3 (0x0D4C0) for palace levels. |
2 bytes | Linear address of level tiles (2x2 blocks of graphics tiles): 0xA5B2 for dungeon levels, 0xA8D2 for palace levels. |
2 bytes | Banked address of level's #Graphics map. |
1 byte | Level type: 0x05=dungeon, 0x85=palace. |
1 byte | Starting direction: 0x00=left, 0x20=right. |
1 byte | Starting X coordinate. |
1 byte | Starting Y coordinate. |
1 byte | Starting room. (0..23) |
1 byte | Starting animation. |
4 bytes | Unknown. Their values are frequently similar to the previous 4 bytes. |
2 bytes | Linear address of the level's #Room links and objects table. |
Graphics map
The first 64 bytes contain the list of level tiles used in the map. Unused entries are filled with 0xFF.
After that comes the map itself. Each level is 128 tiles wide and 36 tiles tall. (Levels 13 and 14 are shorter, they are only 24 and 12 tiles tall, respectively.)
Each tile index is stored on 6 bits, so the level is 128*6/8 = 96 bytes wide.
The bits are read starting from the least significant bit of each byte.
The map consists of 24 rooms arranged in 3 rows and 8 columns. (Level 13 and 14 contain only 2 and 1 rows of rooms, respectively.) Each room is 36/3=12 tiles tall and 128/8=16 tiles wide.
(TODO: Which tiles are walls or floors?)
Room links and objects table
This table is preceded by a 2-byte number which tells the length of the following chunk of data. All offsets stored within this table are interpreted as offsets within this chunk.
The data within the chunk is arranged as follows:
Size | Contents |
---|---|
24*2 bytes | The offset of the #Objects' data for each room. Zero if the room doesn't exist. |
24*4 bytes | Room links for each room. Unlike in most other versions of PoP, their order is above,right,below,left. |
the rest | #Objects' data. |
Level 14 is special: Only the first 8 rooms exist. The rest of the rooms have zero offsets. The room links are included only for the first 5 rooms.
You can detect the number of rooms from the first offset: (offset-0x30)/4 gives how many rooms have room links.
Objects' data
Each object is stored as a byte telling what kind of object it is, followed by argument bytes whose number and meaning depends on the type of the object.
(TODO: figure out the unknown argument bytes)
value | object | argument bytes | notes |
---|---|---|---|
0x27 | level door | xx yy tt 07 00 uu 00 | x*=8,y*=8; If fourth byte is not 07 then the door opens by itself. tt is 01 or 02, uu is 00 or FA |
0x29 | mirror (level 4) | xx yy tt rx ry | tt: DE, rx/ry are the reflection |
0x2B | spike | xx yy | |
0x2C | sword | xx yy | |
0x2D | red (hurt) potion | xx yy | |
0x2E | blue (heal) potion | xx yy | |
0x2F | green (life) potion | xx yy | |
0x30 | pink (slow fall) potion | xx yy | |
0x31 | chomper | xx yy | |
0x32 | gate | xx yy cl tt op uu 00 | cl: 02 or FF, tt: 01 or 07, op: 0-5 (05 or 1F), uu: 8C,FA,FE |
0x3E | skeleton wake up (level 3) | 07 01 40 xx yy | x*=32,y*=64; |
0x3F | skeleton continue (level 3) | 08 01 40 xx yy | x*=32,y*=64; |
0x40 | skeleton (level 3) | xx yy | Used after the other two skeleton objects, but why? |
0x41 | loose floor | xx yy | x*=8,y*=8; |
0x42 | falling loose floor (level 13) | xx yy | x*=8,y*=8; |
0x61 | close button | xx yy ww ln ln | x*=8,y*=8; ln: address of triggered object within the level data chunk. For some reason, exit doors are always triggered by close buttons. |
0x62 | open button | xx yy ww ln ln | x*=8,y*=8; ln: address of triggered object within the level data chunk. ww: 00 (without wall), 02 (with wall) |
0x64 | enemy | cd tp an xx yy | cd: color and direction (00-35), tp: type (00=guard,01=skel,02=Jaffar), an:animation (B5) |
0x66 | shadow steps (level 6) | xx yy | |
0x69 | shadow steals (level 5) | xx yy | |
0x6F | princess (level 14) | xx yy | object is added later? |
0x70 | mouse (level 8) | xx yy | |
0x74 | shadow fights (level 12) | xx yy | |
0xFF | end | - | Marks the end of object data for this room. |
TODO
- Tiles
- Sprites
- Texts
- (Music???)