Map Files
Much of the game's content comes from data located in map files.
Map files are the .BIN
files located in the ST/*
and BOSS/*
directories of the game's filesystem.
-
/
- DRA.BIN
- ...
-
BOSS/
-
BO0/
- BO0.BIN
- F_BO0.BIN
- SD_ZKBO0.VB
- SD_ZKBO0.VH
-
-
ST/
-
ARE/
- ARE.BIN
- F_ARE.BIN
- SD_ZKARE.VB
- SD_ZKARE.VH
-
These files are loaded into address 0x80180000
in RAM.
Map Header
Each map file contains a series of pointers at the beginning of the file that determine key properties of the map.
Below is a list of pointers common between nearly all map files.
Address | Type | Name | Description |
---|---|---|---|
0x80180000 |
Function | Update Entities | Causes each entity's update function to run, which effectively populates all of the data for the entity, including how the object should behave, which sprite it should currently have, etc. |
0x80180004 |
Function | Process Entity Collision | Processes collision for each entity. |
0x80180008 |
Function | Spawn On-Screen Entities | Spawns entities that enter the screen's spawning radius. |
0x8018000C |
Function | Initialize Entities | Initializes the entities in the room using an entry in the Entity Layouts list. |
0x80180010 |
Data | Room Layouts | A pointer to a list of room structures, with each denoting the room's starting and ending X/Y coordinates, alongside graphic IDs and layout IDs for both tiles and entities. |
0x80180014 |
Data | Sprites | A pointer to a list of frames, with each frame being a pointer to a list of sprite parts that compose the frame. |
0x80180018 |
Data | CLUT Banks | A pointer to a list of Color Look-Up Table (CLUT) banks for the map, with each CLUT bank being a pointer to a list of CLUT entries. |
0x8018001C |
Data | Entity Layouts | A pointer to a list of entity layouts, with each entity layout itself being a pointer to a list of entity initialization data. |
0x80180020 |
Data | Tile Layers | A pointer to a paired list of tile layouts, with each entry having both a foreground and background entry. |
0x80180024 |
Data | Entity Graphics | A pointer to a list of graphics definitions. Each graphics definition is a pointer to a series of structures that describe where compressed sprite pages should be placed in VRAM. |
0x80180028 |
Function | Pause Entities | Processes entity update functions while the screen is paused due to some event, such as picking up a Life Max Up or using a Heart Refresh. |
Room Layouts
This is a collection of Room structures that define the properties of each room.
Each Room structure has the following layout:
- struct RoomEntry {
- byte x_start;
- byte y_start;
- byte x_end;
- byte y_end;
- byte tile_layer_id;
- byte load_flags;
- byte entity_graphics_id;
- byte entity_layout_id;
- };
The x_start
and y_start
properties dictate the map cell where the top-left part of the room is located, with each map cell being a 256x256 square.
Similarly, the x_end
and y_end
properties dictate map cell where the bottom-right part of the room is located.
The tile_layer_id
property is multiplied by 2 and then used as an index into the Tile Layers array to determine the layout of tiles in the room.
The load_flags
property is used to either load an area (0xFF
) or to dynamically load CLUTs from map data (0
< flag
< 0xFF
).
The entity_graphics_id
property is used as an index into the Entity Graphics array to load entity tilesets into VRAM.
The entity_layout_id
property is used as an index into the Entity Layouts array to determine where to place entities in the room.
Sprites
Each sprite is a pointer to an array of Frame structures.
Each Frame structure has the following layout:
- struct Frame {
- ushort num_parts;
- SpritePart parts[num_parts];
- };
- struct SpritePart {
- ushort flags;
- short offset_x;
- short offset_y;
- ushort width;
- ushort height;
- ushort clut_offset;
- ushort tileset_offset;
- ushort texture_start_x;
- ushort texture_start_y;
- ushort texture_end_x;
- ushort texture_end_y;
- };
The num_parts
property identifies the number of SpritePart entries that compose the full frame.
The flags
proprty dictates whether the sprite part should be vertically flipped (bit 0 set) or horizontally flipped (bit 1 set).
The offset_x
and offset_y
proprties determine the sprite part's X/Y offsets from the entity's actual X/Y coordinates.
The width
and height
properites determine the sprite part's width and height in pixels.
The clut_offset
property is used to determine the CLUT for the entity. Its usage depends on the type of entity being processed.
The tileset_offset
property identifies the specific quandrant offset from the entity's texture page.
The texture_start_x
and texture_start_y
properties determine the top-left coordinate of a square to copy from the entity's texture page.
Similarly, the texture_end_x
and texture_end_y
properties determine the bottom-right coordinate of a square to copy from the entity's texture page.
CLUT Banks
Each CLUT bank is a pointer a CLUT Layout, which is essentially an array of CLUT Entry structures that define how CLUTs should be loaded into VRAM.
The CLUT Layout and CLUT Entry structures have the following layout:
- struct ClutLayout {
- ushort type;
- ushort subtype;
- ClutEntry data[];
- };
- struct ClutEntry {
- int offset;
- int count;
- byte* clut_data;
- };
The type
and subtype
properties dictate how each CLUT entry is structured and how it should be copied into RAM.
0x0005
CLUT entry), which is referenced every time a new map is loaded.The offset
property dictates where the CLUT should be stored relative to the CLUT storage location in RAM (0x8006CBCC
).
The count
property identifies how many bytes should be copied to the destination identified by the offset
property.
The clut_data
property is a pointer to CLUT data in RAM.
Entity Layouts
Each entity layout is a pointer to an array of Entity Data structures that define how entities should be placed in the room.
Each Entity Data structure has the following layout:
- struct EntityData {
- short pos_x;
- short pos_y;
- ushort entity_id;
- ushort slot;
- ushort initial_state;
- };
The pos_x
and pos_y
properties determine where the entity should be placed in the room.
The entity_id
property identifies which update function should be run for the entity.
The slot
property dictates where there entity should be placed in RAM relative to the dynamic entity storage location in RAM (0x800762D8
).
The initial_state
property is used within the entity's update function to determine various properties about the entity.
Tile Layers
Each entry in this section is a pair of pointers to Layer structures, with the first being a pointer to the Foreground layer and the second being a pointer to the Background layer.
Each Layer structure has the following layout:
- struct Layer {
- ushort* tile_indices;
- TileData tile_data;
- byte dimensions[3];
- byte load_flags;
- byte z_index;
- ushort drawing_flags;
- };
- struct TileData {
- byte* tileset_ids;
- byte* tile_positions;
- byte* clut_ids;
- byte* collision_ids;
- };
The tile_indices
property is a list of indices to be used for the TileData
arrays.
The tileset_ids
property is an array of tileset IDs that indicate which tileset should be used for the given tile.
The tile_positions
property is an array of 4-bit Y/X coordinates that determine where the tile graphic is located within the tileset.
The clut_ids
property is an array of CLUT IDs that determine which CLUT should be used for the tile.
The collision_ids
property is an array of collision IDs that determine what type of collision the tile should have.
The dimensions
property is a 3-byte value that dictates the starting and ending map cells for each layer, with coordinate being a 6-bit value.
- x_start = dimensions & 0x3F;
- y_start = (dimensions >> 6) & 0x3F;
- x_end = (dimensions >> 12) & 0x3F;
- y_end = (dimensions >> 18) & 0x3F;
- width = (x_end - x_start + 1) * 16;
- height = (y_end - y_start + 1) * 16;
The load_flags
property is used to determine which type of room is currently being loaded. (e.g. Load ("CD") room, Save room, etc.)
The z_index
property dictates the Z-index of the current layer, which controls where entities are drawn in relation to the layer's tiles.
The drawing_flags
property is used to determine which CLUTs to use for the layer.
Entity Graphics
Each entity graphics entry is a pointer to an array of Entity Graphic structures that define how entity graphics should be loaded into VRAM.
Each Entity Graphic structure has the following layout:
- struct EntityGraphic {
- ushort vram_x;
- ushort vram_y;
- ushort width;
- ushort height;
- byte* compressed_data;
- };
The vram_x
and vram_y
properties determine where the decompressed graphics should be placed in VRAM.
The width
and height
properties dictate the dimensions of the decompressed graphics.
The compressed_data
property is a pointer to the compressed graphics data.