Skip to main content

Decoding status and unexpected values

Script virtual machine · Values passed on to other routines · The levels

In brief​

Every command has a documented layout, and a decoder that follows the scripts from their entry points reaches 99.6% of the script bytes of the 16 original levels with no unknown layout. The interpreter checks almost nothing: offsets, blocks, slots and counts outside their ranges read or write whatever lies there. This page gives the rules an editor or an interpreter needs for such values.

The script bytes of the 16 original levels, 65,583 without the message tables. The decoder reaches 65,328, 99.6%. The 255 bytes it does not reach are 232 of dead code after level changes, 5 of repeated returns, 18 of two unreferenced routines.
Following the entry points reaches all but 255 bytes of script code.

Decoding status​

Every command has a documented operand layout, and a reachability decoder applies them to the 16 reference LEVELn.INF files of the DOS release. It starts from each distinct script offset of the cell bindings and follows jumps, calls and conditional branches; it never scans for command bytes.1

Result over the 16 reference filesValue
Distinct script references used as entry points1047
Decoded instructions10131
Script bytes (excluding the message table)65583
Script bytes reached65328 (99.6%)
Unknown layouts, truncated operands, overlapping instructions, targets outside the script area0
Commands that never occur in reachable scriptsSCRIPT_MOVE_INVENTORY_ITEM_TO_BLOCK, SCRIPT_MODIFY_CHARACTER_HP, SCRIPT_AWARD_EXPERIENCE, SCRIPT_IDENTIFY_ITEMS

The 255 unreached bytes are 232 bytes of dead code after level changes (which stop the run; the next bytes are mostly a SCRIPT_RETURN or a SCRIPT_JUMP), 5 bytes of repeated returns, and two unreferenced nine-byte routines at offset 2 of levels 12 and 14, each a SCRIPT_DAMAGE_CHARACTERS on all characters followed by SCRIPT_RETURN, which nothing executes (see how a run starts). These results apply to the DOS reference files only.

Unexpected values​

The interpreter validates almost nothing. The reference scripts use no value outside the documented sets, but an editor or an interpreter that must accept any script needs the following rules.

Positions. No script offset is checked: not a binding's offset, a jump, call or condition target, nor the end of the buffer while operands are read. Offsets are added to the buffer's start in 16-bit arithmetic, so a large one wraps round within 64 KiB of memory; past the 7,508 bytes of the buffer lies other game data. A byte below 0xe2 where a command is expected is skipped, one byte at a time.

Blocks. No command checks a block index. Block b is the 10-byte entry b of the block table, which has 1,024 entries; a larger index, or a word read as negative, addresses other memory, the product by 10 being kept to 16 bits.

Party slots. The commands that take a character slot treat −1 as the whole party and pass any other value on without a range check (character routines).

Selectors and other operands, per command (lengths include the command byte):

CommandUnknown selectorOther unchecked operands
SCRIPT_SET2 bytes, no effectside is added to the block's entry as a signed byte: values outside 0–3 write another byte of the entry or of a nearby entry, including a script offset. direction is stored whole as the party's facing.
SCRIPT_TOGGLE2 bytes, no effectside as for SCRIPT_SET, read and written.
SCRIPT_MOVE_PARTY_OR_OBJECT6 bytes; the two words are ignored, but the view is marked for redrawingBlocks and levels; see the command page.
SCRIPT_PRINT_MESSAGE—The string index; see the command page, and its anomaly when no character qualifies.
SCRIPT_SET_FLAGS2 bytes, no effectBit numbers and the monster slot; see bit numbers.
SCRIPT_CLEAR_FLAGS3 bytes, no effect: the byte after the selector is consumed, also for SCRIPT_FLAG_TARGET_MONSTERBit numbers as for SCRIPT_SET_FLAGS.
SCRIPT_LOAD_LEVEL_OR_MONSTERSEvery value other than SCRIPT_LOAD_LEVEL selects the 17-byte resource formloader_index picks one of three routines without a range check: 3 and above call the command handlers that follow the table (3 is SCRIPT_SET's), negative values the entries before it, the first two of which are not routine addresses.
SCRIPT_AWARD_EXPERIENCE2 bytes, no effect—
SCRIPT_CHANGE_DIRECTION3 bytes, no effectNone: the turn is reduced to 0–3.
SCRIPT_SPECIAL_EVENTEvents above 6, the word read as unsigned: 3 bytes, no effect—
SCRIPT_DIALOGUE2 bytes, no effectPicture frame and texts; see the command page.
SCRIPT_DELETE_ITEMNone: any other byte is an item typeThe block.
SCRIPT_JUMP_UNLESSUnknown tokens are skipped as single bytesThe expression stack has no bounds.
SCRIPT_CALL—A call made with ten positions saved is skipped.
SCRIPT_DELAY—The tick count is signed; see the command page.

The other commands have no selector, or their pages describe what other selector values do: Run a sequence, Launch an object, Create an item.2

Bit numbers. A level or global flag bit is one bit of a 32-bit mask, built by a shift whose count is the operand read as an unsigned byte, so a negative operand counts as 128 to 255. Counts 0–31 select one bit and 32–47 select none, so setting or clearing has no effect. Larger counts select no bit on an 8086 processor; later processors reduce a shift count modulo 32, and some of these counts then select one of bits 16–31. A monster flag bit is built the same way in a single byte: counts 0–7 select a bit, 8–31 none, and larger counts depend on the processor in the same way. The monster slot is multiplied by 30 without a range check.3

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references.

Footnotes​

  1. The decoder is script_decoder.py, run on the LCW-decoded INF payloads of the files listed in the file inventory; the operand layouts come from the handlers of the command table, each linked from its command page. Counts taken on 2026-11-02. ↩

  2. The dispatcher and the handlers of set, toggle, move, set a flag, clear a flag, change level with its loader table, award experience, change direction and special events; the script buffer and the block table. ↩

  3. The 32-bit shift used by the set and clear handlers; the monster bit is shifted in the set handler itself. ↩