Script instructions
ScriptOpcode · signed byte, first byte of every script instruction
Virtual machine · Scripts · The engine in ten minutes
Level scripts are sequences of instructions. The first byte of each
instruction selects what it does: change walls, open a door, place a monster,
move the party, show a dialogue, test a condition, jump. The interpreter
accepts 30 such bytes, from 0xe2 to 0xff; it reads the byte as a signed
value to select the handler, and does not dispatch other bytes as
instructions.1
Some operands and effects remain unknown; each instruction page says which.
typedef enum ScriptOpcode {
SCRIPT_SET = 0xff, /* Assign walls or a direction-related value. */
SCRIPT_TOGGLE = 0xfe, /* Switch walls or a door between two states. */
SCRIPT_OPEN_DOOR = 0xfd, /* Request opening the door of a block. */
SCRIPT_CLOSE_DOOR = 0xfc, /* Request closing the door of a block if it is unoccupied. */
SCRIPT_SPAWN_MONSTER = 0xfb, /* Place a monster in a free or evicted slot, or clear a slot. */
SCRIPT_MOVE_PARTY_OR_OBJECT = 0xfa, /* Move the party, monsters or items. */
SCRIPT_MOVE_INVENTORY_ITEM_TO_BLOCK = 0xf9, /* Move an item from a character's inventory to a block. */
SCRIPT_PRINT_MESSAGE = 0xf8, /* Display an indexed script message. */
SCRIPT_SET_FLAGS = 0xf7, /* Set a flag selected by a ScriptFlagTarget. */
SCRIPT_PLAY_SOUND = 0xf6, /* Play a sound, optionally associated with a block. */
SCRIPT_CLEAR_FLAGS = 0xf5, /* Clear a flag selected by a ScriptFlagTarget. */
SCRIPT_MODIFY_CHARACTER_HP = 0xf4, /* Change the hit points of selected characters. */
SCRIPT_DAMAGE_CHARACTERS = 0xf3, /* Compute and apply damage to characters. */
SCRIPT_JUMP = 0xf2, /* Continue at a script-buffer offset. */
SCRIPT_END = 0xf1, /* Stop this run and empty the shared return stack. */
SCRIPT_RETURN = 0xf0, /* Resume at the saved return position, or stop if there is none. */
SCRIPT_CALL = 0xef, /* Call a script-buffer offset if the return stack has room. */
SCRIPT_JUMP_UNLESS = 0xee, /* Evaluate a condition; jump to a buffer offset if it is zero. */
SCRIPT_DELETE_ITEM = 0xed, /* Remove the held item or items of a block. */
SCRIPT_LOAD_LEVEL_OR_MONSTERS = 0xec, /* Load a level, or monster resources. */
SCRIPT_AWARD_EXPERIENCE = 0xeb, /* Share an experience amount. */
SCRIPT_CREATE_ITEM = 0xea, /* Copy an item and place it, with optional overrides. */
SCRIPT_LAUNCH_OBJECT = 0xe9, /* Launch a magic flying object or a copy of an item. */
SCRIPT_CHANGE_DIRECTION = 0xe8, /* Turn the party or moving objects. */
SCRIPT_IDENTIFY_ITEMS = 0xe7, /* Identify the items of a block. */
SCRIPT_RUN_SEQUENCE = 0xe6, /* Run a scripted sequence. */
SCRIPT_DELAY = 0xe5, /* Wait until a shared counter reaches a target, then continue. */
SCRIPT_DRAW_SCENE = 0xe4, /* Request a scene redraw. */
SCRIPT_DIALOGUE = 0xe3, /* Run a dialogue-screen command. */
SCRIPT_SPECIAL_EVENT = 0xe2 /* Run one of the fixed special events. */
} ScriptOpcode;
Instructions
Each page gives the operands in order, the instruction length and the effects. Operands that select a branch have their own enumeration.
The flag instructions read their own selector byte after the instruction byte; the instruction byte and the selector are different bytes with different roles. The four control-flow instructions are explained in script control flow.
Sources
Locations refer to the game executable reference.