Values passed on to other routines
Script virtual machine · Decoding status and unexpected values
In brief
No routine reached from a script checks a block, slot or index against its table: each computes the address of the entry and uses whatever lies there. This table gives, for each routine, the values it receives and what an out-of-range value does.
The routines
No routine reached from a script checks a block, slot or index against its table. Each computes the address of the entry, in 16-bit arithmetic, and uses whatever lies there. Item types are the exception: they are only compared. Where a routine hands the value on to the drawing or to memory management, the table says so and stops there; consequences marked as inferred depend on what memory holds.
| Routine | Value | What an out-of-range value does |
|---|---|---|
| Every routine that takes a block | block | Addresses the 10 bytes at the start of the block table plus 10 × block, kept to 16 bits, so every block number lands somewhere in the game's data: from 1,024 on, the variables that follow the table (block 1,034 is the pointer to the game's work area; the script timers, flying objects and monster types come after); a negative word, the monster picture pointers and the data before them. The routines below read those bytes as the four walls, the state word, the head of the item chain and the script offset. |
| Redraw if in view; block distance (block sounds, monster replacement) | block | Compared or computed only: the column is the block modulo 32 and the row the block divided by 32, modulo 256. Nothing else is read. |
Door operations (SCRIPT_OPEN_DOOR, SCRIPT_CLOSE_DOOR, the door form of SCRIPT_TOGGLE) | block | Reads the four bytes as wall references, looks each one up in the wall-property table as a signed value, and writes the stepped values back into those bytes. The block is kept in a door-operation slot, so the door timer goes on stepping the same bytes. |
| Item chains: insert, search and count, identify, delete by type | block | The head word is taken as an item number, which addresses the item table at 14 bytes per item, again anywhere in memory. Inserting writes the head and one link word in each of two records it names. Walking follows the links until it comes back to the head: a chain that never does makes the game hang (inferred). Identifying sets a bit in every record visited; deleting frees every visited record of the type. |
| Block events, through moving the party or placing a monster | block | The script-offset word starts a script run when it is not zero and the state word passes the event test. Moving the party also makes the block the party's own; the view is then drawn as that of the block number modulo 1,024, while the party's block keeps the full value; placing a monster adds one to the state word. A flying object in a block of 1,024 or more stays linked there until its first crossing into a neighbouring block, which is taken modulo 1,024 and so lies in the level. |
SCRIPT_SET_FLAGS on a monster | monster slot, −128 to 127 | Sets the bit in the byte 22 bytes into the 30-byte window of the slot and clears the byte 8 bytes into it. Slot 30 falls on the pointer to the script buffer, larger slots on the item records, negative ones on the level flags and the data before them. |
SCRIPT_SPAWN_MONSTER | type_index, unit | The type addresses 46-byte properties from the start of the monster-type table, whose extent is not established. The unit gives update group 2 × unit + (slot & 1); timed updates exist for groups 0–3 only, so a monster in another group is not moved by them (inferred). |
Duplicate an item (SCRIPT_CREATE_ITEM, the item form of SCRIPT_LAUNCH_OBJECT, a placed monster's drops) | template item | Reads 14 bytes at 14 × template from the start of the item table. If their location word is −1, no item is made; otherwise they are copied into a free entry as a new item. Only the read leaves the table. |
Item-based damage of SCRIPT_DAMAGE_CHARACTERS | item | Reads the record's type and value, and the dice of that type from the item-type table at 16 bytes per type. Nothing is written. |
Item types (SCRIPT_DELETE_ITEM, the held-item tests, inventory searches and deletions) | item type | Compared with each item's type only; no table is read, and an unknown type matches no item. |
Character routines: eligibility test, hit-point change, damage, SCRIPT_MOVE_INVENTORY_ITEM_TO_BLOCK | character slot, −128 to 127 | Addresses 345 bytes per slot from the start of the character table. Slot 6 lies on the variables after the six records: its hit points overlap the flag of the open character panel and its inventory the door shape pointers. A hit-point change or damage writes the hit points when the test passes, damage can run the death routine on those bytes, and the hit-point change then redraws the slot (not traced). The inventory move tests the given slot and, while its status byte is zero, moves on to the next one, wrapping from any slot above 5 to 0: a slot of 6 or more is tried once, a negative slot climbs through earlier memory up to 0. |
Monster-resource form of SCRIPT_LOAD_LEVEL_OR_MONSTERS | loader_index | 3 to 32 call the command handler that follows the three loaders (3 SCRIPT_SET, 4 SCRIPT_TOGGLE, … 32 SCRIPT_SPECIAL_EVENT), which decodes the 13-byte name and the bytes after it as its own operands and acts on them; the command still takes 17 bytes. Indices 33 and above take their address from the message text and other data that follow the handler table; −1 and −2 are not routine addresses; −3 to −12 call the record runner's handlers, and lower indices other data. A call into data crashes the game (inferred). |
| The same form | slot_group | Groups 0 and 1 are the two graphics banks. Group 2 releases and then fills the 4-byte words at the start of the block table, blocks 0 to 7, and the 6-byte entries that cover the visible-block list, the script stop flag, the expression-stack index and the item-type records, handing each nonzero pair to the memory release routine (not examined). Negative groups reach the data before the two tables. |
None of these values occurs in the reference scripts.1
Sources
Locations refer to the game executable reference; comparative sources are listed in the technical references.