A level script is a statically defined array ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/n64decomp/sm64/llms.txt
Use this file to discover all available pages before exploring further.
LevelScript (i.e. uintptr_t) values that drives the entire lifecycle of loading a level — from decompressing ROM data into RAM segments, through spawning every object and warp node, to handing control over to the game loop. The interpreter lives in src/engine/level_script.c and is entered through level_script_execute().
The command interpreter
level_script_execute() is called each game frame while the script is running. It dispatches on type, advances sCurrentCmd by size << CMD_SIZE_SHIFT after each command, and returns when the script pauses (waiting for a DMA transfer) or halts. A 32-entry uintptr_t stack (sStack) supports JUMP_LINK / RETURN subroutine calls between script arrays.
sRegister) and comparison operators (OP_AND, OP_EQ, OP_LT, etc.) allow conditional branching inside a script without needing separate C functions.
Command reference
Memory and segment loading
EXECUTE / EXIT_AND_EXECUTE — load a segment and jump to a new script
EXECUTE / EXIT_AND_EXECUTE — load a segment and jump to a new script
levels/scripts.c is a chain of EXECUTE commands.LOAD_MIO0 / LOAD_RAW / LOAD_MIO0_TEXTURE — segment DMA
LOAD_MIO0 / LOAD_RAW / LOAD_MIO0_TEXTURE — segment DMA
ALLOC_LEVEL_POOL / FREE_LEVEL_POOL — level memory pool
ALLOC_LEVEL_POOL / FREE_LEVEL_POOL — level memory pool
Level initialization
Model loading
LOAD_MODEL_FROM_GEO / LOAD_MODEL_FROM_DL
LOAD_MODEL_FROM_GEO / LOAD_MODEL_FROM_DL
MODEL_MARIO, MODEL_BOB_BUBBLY_TREE, etc. are defined in model_ids.h.Area definition
geo argument points to the GeoLayout array that builds the scene graph for that area. Areas are identified by a 1-based index; the level script interpreter stores the current area in sCurrAreaIndex.
Object placement
OBJECT — place a game object
OBJECT — place a game object
bhv is a pointer to a behavior script array. bhvParam is a packed 32-bit value read by the behavior; helpers like BPARAM1() / BPARAM2() pack individual bytes.MACRO_OBJECTS — bulk object list
MACRO_OBJECTS — bulk object list
OBJECT commands and are loaded in a batch from a MacroObject array embedded in the level geometry segment.Warp nodes
WARP_NODE — define a warp destination
WARP_NODE — define a warp destination
flags is either WARP_NO_CHECKPOINT (0x00) or WARP_CHECKPOINT (0x80). WARP_NODE_SUCCESS and WARP_NODE_DEATH are the reserved IDs for star-collection and death exits.Collision and terrain
Audio
Flow control
Miscellaneous
Level organization
Each level lives underlevels/<shortname>/ and contains at minimum:
| File | Purpose |
|---|---|
script.c | The LevelScript array(s) — loading order, areas, warps |
geo.c | Includes all geo.inc.c files for the level’s areas and actors |
leveldata.c | Collision meshes, display lists, macro object tables |
header.h | Extern declarations for all geo layouts and data symbols |
Real example: Bob-omb Battlefield (levels/bob/script.c)
Loading sequence walkthrough
Segment loads
LOAD_MIO0 and LOAD_RAW stream data from ROM into N64 RAM segments. MIO0 data is decompressed on the fly; RAW data is a straight DMA copy. Each segment number is a 4-bit key into the CPU’s segment table.Pool and Mario
ALLOC_LEVEL_POOL() carves out the level heap. MARIO(...) spawns the Mario object with its behavior and model.Global actor groups
JUMP_LINK(script_func_global_N) calls shared scripts that load commonly used actors (goombas, coins, Bob-ombs) via LOAD_MODEL_FROM_GEO from segment 0x0C / 0x0D.Level-specific models
LOAD_MODEL_FROM_GEO calls for models unique to BoB (trees, the gate, the seesaw) fill remaining model slots.Area block
AREA(1, bob_geo_000488) passes the area’s root geo layout to the interpreter, which calls process_geo_layout() to build the scene graph. Everything inside the block (objects, terrain, warps) is scoped to area 1.Subroutines for object groups
JUMP_LINK(script_func_local_N) calls local script arrays that contain dense batches of OBJECT / OBJECT_WITH_ACTS commands, keeping the main entry array readable.Warp graph
WARP_NODE entries define a directed graph of teleport destinations. Each warp object in the world carries a WARP_NODE_* ID; when Mario touches it, the engine looks up that ID in the area’s warp table to find destLevel, destArea, and destNode.Terrain and audio
TERRAIN uploads the collision mesh, MACRO_OBJECTS spawns small objects in bulk, and SET_BACKGROUND_MUSIC queues the level’s music sequence.The warp system
WARP_NODE_0B in BoB sends Mario to WARP_NODE_0C, and WARP_NODE_0C sends him back to WARP_NODE_0B — the two-way shortcut between mountain base and summit.WARP_NODE command records:
| Field | Description |
|---|---|
id | Source warp ID (matches the bhvParam of a warp object) |
destLevel | Target level number |
destArea | Target area index within that level |
destNode | ID of the warp node to spawn Mario at in the destination |
flags | WARP_CHECKPOINT saves a checkpoint; WARP_NO_CHECKPOINT does not |
WARP_NODE_SUCCESS and WARP_NODE_DEATH are always present and route Mario back to the castle after collecting a star or dying.
PAINTING_WARP_NODE works identically but signals the engine to play the painting warp-in animation. INSTANT_WARP teleports Mario within the same level with a position displacement (used for the Tiny-Huge Island size transition).
The global level list
The filelevels/scripts.c contains the top-level entry script that all levels ultimately branch from. It is a sequence of JUMP_LINK_IF / EXIT_AND_EXECUTE commands that selects the appropriate level_*_entry array based on VAR_CURR_LEVEL_NUM:
level_script_entry (declared in level_script.h and defined in levels/scripts.c) is the very first array executed when the game boots.
Multi-area levels
Levels like Shifting Sand Land (3 areas: outside, pyramid interior, Eyerok boss) define multipleAREA / END_AREA blocks, each with its own geo layout and object list. The engine loads only the active area’s geo and collision; switching areas calls CLEAR_LEVEL() on the old area and re-runs the relevant portion of the level script.