Level

From ZAMN Hacking

The number of regular levels is located at $9F:8000. This count includes level 0 and the credit level, but not any of the bonus levels. The level data pointers are located at $9F:8002. In a regular ROM, these are 16-bit pointers relative to bank $9F. In a Necrofy built ROM, these are 24-bit pointers padded to 4 bytes each.

Level data structure[edit]

Header[edit]

Offset Length Type Description
0x00 4 pointer32 Pointer to the tileset tilemap
0x04 4 pointer32 Pointer to the level background data
0x08 4 pointer32 Pointer to the tileset collision data
0x0C 4 pointer32 Pointer to the tileset graphics
0x10 4 pointer32 Pointer to the tileset palette
0x14 4 pointer32 Pointer to the sprite palette
0x18 4 optional pointer32 Pointer to the palette animation entity
0x1C 2 pointer16 Pointer to the respawning monster data
0x1E 2 pointer16 Pointer to the victim/one-shot monster data
0x20 2 pointer16 Pointer to the item pickup data
0x22 2 uint16 Level background width
0x24 2 uint16 Level background height
0x26 2 uint16 Priority tile count
0x28 2 uint16 Visible tiles end
0x2A 2 int16 Player 1 start X position
0x2C 2 int16 Player 1 start Y position
0x2E 2 int16 Player 2 start X position
0x30 2 int16 Player 2 start Y position
0x32 2 uint16 Music ID
0x34 2 uint16 Extra sounds ID
0x36 2 pointer16 Pointer to the first level title page data
0x38 2 pointer16 Pointer to the second level title page data
0x3A 2 optional pointer16 Pointer to the bonus data
0x3C 2 pointer16 Necrofy ROMs only. Pointer to the secret item bonus subroutine
0x3E 2 uint16 Necrofy ROMs only. Bonus level number

Immediately following the header is the boss monster data

Boss monster data[edit]

Offset Length Type Description
0x00 4 pointer32 Boss monster entity pointer
0x04 4 byte[4] Properties

This data is repeated for each boss monster. The list is terminated with four consecutive zero bytes.

The format of "Properties" depends on the type of boss monster. For UFO, giant baby, snakeoid, giant spider, and giant head, it is:

Offset Length Type Description
0x00 2 int16 X position
0x02 2 int16 Y position

For palette fade and tile animator, it is:

Offset Length Type Description
0x00 4 pointer32 Pointer to additional data

For the format of the additional data, see the page for the given boss monster.

Respawning monster data[edit]

Offset Length Type Description
0x00 1 byte Respawn delay
0x01 2 int16 X position
0x03 2 int16 Y position
0x05 1 byte Respawn area size
0x06 4 pointer32 Respawning monster entity pointer

This data is repeated for each respawning monster. The list is terminated with two consecutive zero bytes.

Victim/one-shot monster data[edit]

Offset Length Type Description
0x00 2 int16 X position
0x02 2 int16 Y position
0x04 2 byte[2] Extra data
0x06 2 uint16 bcd Victim number
0x08 4 pointer32 Entity pointer

This data is repeated for each victim and one-shot monster. The list is terminated with two consecutive zero bytes.

Typically the victims are all listed first, in order from 1 to 10, then all of one-shot monsters, but this is not required. "Extra data" provides 2 bytes of arbitrary data that can be used by the entity for any purpose. In the original game, this is only used by the developer credit. Victim number is 0 for one-shot monsters.

Item pickup data[edit]

Offset Length Type Description
0x00 2 int16 X position
0x02 2 int16 Y position
0x04 1 byte Item pickup ID

This data is repeated for each item pickup. The list is terminated with two consecutive zero bytes.

Bonus data[edit]

Offset Length Type Description
0x00 2 uint16 Bonus ID

This data is repeated for each bonus. The list is terminated with two consecutive zero bytes.

Level title page data[edit]

Offset Length Type Description
0x00 1 byte X position (in 8x8 tiles)
0x01 1 byte Y position (in 8x8 tiles)
0x02 1 byte Palette
0x03 1 byte Page
0x04 X byte[X] Characters
X+4 1 byte Continue

This is repeated until the continue value is zero. This value is set to 0xFF otherwise.

Page is set to 0x01 on the first title page, and 0x00 on the second title page. Palette is generally set to a multiple of two since level title palettes use two palette rows each.

Level background data[edit]

Offset Length Type Description
0x00 2 uint16 Tile ID

This is repeated for each 64x64 tile in the background, up to "width * height" of the level. Tiles are listed in row-major order.

Necrofy enhancements[edit]

Necrofy changes the level pointers from 16-bit to 24-bit (padded to 4 bytes each). This allows an arbitrary amount of level data to be stored in the ROM. 16-bit pointers within the level data itself are made relative to the bank in which the level data is located.

Necrofy also adds two additional values to the level header: the secret item bonus subroutine and the the secret level number. These are replacements of the tables at $82:D1EE and $82:D17E respectively. This was done to support more than 55 levels in a ROM without having to expand these tables.