This document is the central format reference for Crusader USECODE in this repository. It combines local retail-binary observations with the ScummVM and Pentagram implementations. It is deliberately explicit about confidence: a shared name or parser convention is not treated as proof of retail behavior when the local binary evidence disagrees.
“Definitive” here means the current, auditable statement of what is known and what remains unsettled. It does **not** mean every opcode, intrinsic, or event has been semantically recovered. In particular, intrinsic numbers are game/build-specific, some opcode names conflict with observed parser behavior, and parts of class-event records remain unknown.
## 1. What USECODE is
USECODE is Crusader's object-oriented, event-driven bytecode system. A class has a set of numbered event slots. When the engine or another script dispatches an event, the runtime resolves the class and event slot to bytecode, constructs an interpreter/process context, and runs the event body. Scripts use VM operations for local/member/global data, arithmetic, branching, strings and lists, and process control. They access most game-world and presentation behavior through **intrinsics**: native functions supplied by the particular game executable.
The complete behavior of a USECODE program is therefore the combination of:
1. the archive and class/event records;
2. the bytecode and its VM semantics;
3. the executable's event-dispatch rules and intrinsic table;
4. the game data and current world/process state.
Bytecode alone does not define the semantics of an intrinsic ordinal. Remorse and Regret must not be assumed to share the same intrinsic numbering or signatures.
## 2. Evidence and terminology
Use these terms when reading this specification and related analysis:
- **Observed** — directly checked in local Crusader data, bytecode, or executable/runtime evidence.
- **Cross-implementation** — present in both ScummVM and Pentagram; strong evidence for intended format design, but not conclusive where it conflicts with local samples.
- **Name hint** — a label supplied by a converter, disassembler, or inferred table. It helps navigation but is not itself proof of behavior.
- **Unresolved** — competing interpretations or insufficient direct evidence. Preserve the raw value and do not silently choose one interpretation.
- **Intrinsic** — a native executable routine called by bytecode, selected by a numeric ordinal.
- **Event** — a class-local numbered callback. An event slot is not a globally unique function address.
The strongest local format evidence is the owner-loaded `EUSECODE.FLX` extractor and sampled class records. The detailed evidence and outstanding count/base disagreement are in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md). Tool implementation differences are compared in [usecode-tooling-comparison.md](./usecode-tooling-comparison.md).
## 3. Archive and class organization
### 3.1 `EUSECODE.FLX`
The locally validated FLEX directory interpretation is:
| Non-class objects | Object 0 and object 1 are not class records in the observed layout; object 1 supplies names |
| Class object | Object index `class_id + 2` |
| Class name | A 13-byte slot in object 1 at `4 + 13 * class_id`; name text ends at NUL or the slot boundary |
These are structural interpretations of the Crusader file as used by the local extractor, not a claim that every FLEX file in other games has the same layout. The extractor validates table bounds and retains original records: [extract_eusecode_flx.py](../tools/extract_eusecode_flx.py).
### 3.2 Class record and event table
For owner-loaded Crusader class records sampled locally:
- The class header is at least 20 bytes.
- Bytes `8..11` contain a little-endian `u32` used in deriving the event-table extent and code addressing.
- A 6-byte-per-slot event table begins at class-relative offset `+20`.
- Each row has the observed shape:
| Row-relative bytes | Interpretation |
|---|---|
| `+0..+1` | Unknown little-endian word; retain as raw data |
| `+2..+5` | Little-endian `u32` event-code offset field |
- A zero code-offset field is treated by local tooling as an absent event.
- Nonzero offsets are resolved to body windows using the class code-base anchor and the next greater nonzero event offset. The end of the final body is bounded by the class-record size.
- Event names are not stored as authoritative semantic names in the row; the slot number is the stable identifier.
The exact meaning of the row's leading word has not been established. Do not discard or rewrite it when round-tripping data.
### 3.3 Event-count/base-offset disagreement
ScummVM and Pentagram both implement a Crusader class-base calculation that decrements the dword at bytes `8..11`, and an event-count formula equivalent to `(base_offset + 19) / 6`. They resolve an event's offset from `class + 20 + 6 * slot + 2`.
That shared implementation is valuable evidence, but its event-count arithmetic does **not** fit the sampled owner-loaded records used by this repository. Locally observed dwords such as `0x00d4`, `0x00da`, and `0x00e6` yield clean event-table sizes when interpreted as the first code-byte offset: `(raw_dword - 20) / 6` gives 32, 33, and 35 rows, respectively. The decremented value then acts as a `code_base_minus_one` anchor, and the event offsets behave as 1-based displacements from that anchor.
**Current local rule:** use bounds-checked event-table parsing derived from the raw owner-loaded class record; preserve both the raw bytes-8..11 dword and the derived anchor. Do not apply the shared ScummVM/Pentagram event-count formula blindly to these samples. The discrepancy and evidence are documented in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md).
**Ghidra cross-check (Remorse):** In the active `CRUSADER.EXE`, `Usecode_ItemCallEvent` (`1420:0e3a`) passes the class id and event ordinal into `EntityVmContext::CreateFromSlotIndex` (`1420:0eec`). The downstream `EntityVmRuntime` path materializes indexed owner/chunk records, including 6-byte runtime entries in `EnsureSlotChunkLoaded` (`1420:19fd`). This confirms class/event ordinal dispatch, but the inspected path consumes an already-indexed owner buffer and does not read the original `EUSECODE.FLX` bytes-8..11 field. It therefore does not decide between the competing archive event-count formulas; the local raw-record arithmetic remains the best fit for the sampled archives, and the formula disagreement remains open.
### 3.4 Event body and byte order
Integer operands in the observed Crusader bytecode are little-endian. The bytecode is a variable-length instruction stream; the opcode determines operand widths. Branch displacements are signed 16-bit relative offsets in the local decoders. Strings and body trailers require format-aware handling and must not be normalized through a lossy text conversion.
The rebuild interpreter model in this repository starts executing at body offset `14` (`usecodeEventBytecodeOffset` in [usecode_vm.h](../rebuild/remorse/include/remorse/usecode_vm.h)). That is an implementation/runtime observation, not a substitute for parsing the event body framing. Analysis and round-trip tooling should preserve the complete body window, including prologue, debug metadata, and unknown trailing bytes.
## 4. Event slots
The event number is a class-local ordinal. The common event-name tables cover `0x00..0x1f`, but local class records also contain higher ordinals. The census below covers the main local `USECODE/EUSECODE.FLX` and `USECODE/REGRET/EUSECODE.FLX` corpora, not the demo, Japanese, or 1.01 variants. A count is the number of non-empty derived class/slot body windows, not dynamic executions; `0` means no body was found in that corpus, not that the engine lacks a dispatch route.
For per-slot source labels, native callers, corpus coverage, class-local high-slot examples, and follow-up work, see the detailed [USECODE event slot catalog](./usecode-event-slots-catalog.md).
| Slot | Common label | Remorse bodies | Regret bodies | Current Crusader interpretation |
| `0A` | `equip` | 77 | 125 | Ghidra confirms the native `Item_Equip` route; scripts reuse it for applying modes, arming, setup, and actor initialization, not only wearable equipment. |
| `0B` | `unequip` | 50 | 47 | Ghidra confirms the native `Item_Unequip` route; scripts reuse it for disabling, disarming, or reversing state, not only removing wearable equipment. |
| `0C` | `combine` | 0 | 0 | Ghidra confirms an `Item_Combine` engine route, but neither inspected archive has a non-empty slot-`0C` body. |
| `0D` | `func0D` | 0 | 0 | Unknown. Preserve as an unnamed slot. |
| `0E` | `calledFromAnim` | 27 | 43 | Callback lane called from animation behavior. |
| `0F` | `enterFastArea` | 108 | 107 | Proximity/activation-region entry hook; local evidence supports trigger, spawner, and controller uses, not a movement-speed zone. |
| `15` | `unhatch` | 5 | 6 | Ghidra has an `Item_CallUnhatchEvent` route; ScummVM's label is supported, while Pentagram's `func15` is a placeholder. |
| `16` | `func16` | 0 | 0 | Unknown. |
| `17` | `func17` | 0 | 0 | Unknown. |
| `18` | `func18` | 0 | 0 | Unknown. |
| `19` | `func19` | 0 | 0 | Unknown. |
| `1A` | `func1A` | 0 | 0 | Unknown. |
| `1B` | `func1B` | 0 | 0 | Unknown. |
| `1C` | `func1C` | 0 | 0 | Unknown. |
| `1D` | `func1D` | 0 | 0 | Unknown. |
| `1E` | `func1E` | 0 | 0 | Unknown. |
| `1F` | `func1F` | 0 | 0 | Unknown. |
In Ghidra's Remorse `CRUSADER.EXE`, `Item_Equip`, `Item_Unequip`, `Item_Combine`, `Item_Cast`, and `Item_CallUnhatchEvent` dispatch `UC_Equip`, `UC_Unequip`, `UC_Combine`, `UC_Cast`, and `UC_Unhatch` through `Usecode_ItemCallEvent`. Their event masks (`0x400`, `0x800`, `0x1000`, `0x20000`, and `0x200000`) confirm ordinals `0x0A`, `0x0B`, `0x0C`, `0x11`, and `0x15`. This resolves Pentagram converter placeholders `func0A`, `func0B`, `func11`, and `func15` for those event names; raw ordinals remain the stable identifiers.
**Zero-body slots with native routes (Remorse):** A zero census count means no callback body was found, not that the native engine lacks a caller. `DList_AnimateShapes` (`1190:183d`) calls `Item_Anim` (`10a0:28e2`) for animation type 5; `Item_Anim` passes `UC_Anim` with mask `0x4` to `Usecode_ItemCallEvent`. This animation-type branch only invokes the event and does not advance the frame itself, so with no slot-`0x02` body the branch has no usecode animation behavior to run. `NPC_SetActivity` (`10e8:2ba4`) similarly offers `UC_SetActivity` with mask `0x8`; if the dispatcher does not handle it, the function calls `NPC_StartNextNPCActivityBehaviorProcess` to start the ordinary activity behavior. Thus the empty slot-`0x03` rows leave that built-in fallback in control.
The `anim()` and `setActivity()` names and ordinals are already present in Pentagram's and ScummVM's Ultima 8 event-name tables, and ScummVM's shared `Item` animation path also calls event `0x02`. That supports `anim` as inherited event machinery retained by Crusader. For `setActivity`, the name is inherited, and the original Crusader executable demonstrably dispatches it, but the inspected Ultima 8 runtime sources do not show a corresponding event-`0x03` producer; Pentagram's `Actor::I_cSetActivity` is a separate intrinsic, not that event. Whether the callback itself was live in the original Ultima 8 engine therefore remains unverified. Also, Pentagram's `Item::callUsecodeEvent` explicitly disables Crusader usecode events other than `use`; that is a limitation of that port and does not contradict the native Crusader call sites. Relevant source paths: `misc/scummvm/engines/ultima/ultima8/world/item.cpp`, `misc/scummvm/engines/ultima/ultima8/convert/u8/convert_usecode_u8.h`, `misc/pentagram/world/Item.cpp`, `misc/pentagram/world/actors/Actor.cpp`, and `misc/pentagram/convert/u8/ConvertUsecodeU8.h`.
Outside the common table, the extracted Remorse corpus has non-empty body windows at every slot `0x20..0x4B` (44 ordinals), and Regret at every slot `0x20..0x51` (50 ordinals). These higher slots remain unnamed and class-specific; do not infer a common semantic label from the ordinal alone.
### Event dispatch forms
The observed bytecode includes class/event calls (`0x11`) and spawned class/event processes (`0x57`, `0x58`). The target is a class id plus event ordinal; the VM resolves the ordinal through that class's event table. Thus the same event ordinal can mean different behavior in different classes, and a decompiler's label does not prove the target row is present.
The opcode called `FAR_ROUTINE_CALL` in the historical opcode-name list is decoded locally as this class/event dispatch. In Crusader, this is an event-number-based dispatch, not a call using a raw bytecode address.
The historical-name column is copied from the Japanese No Remorse disassembly corpus. The current-behavior column combines local decoder interpretations with verified native executable behavior. This is the broadest recovered opcode vocabulary currently in this workspace, **not** a claim that every named token is executable or fully understood in every build.
- **Decoded locally** means the map-viewer/research parser recognizes the opcode and its current operand shape.
- **Name only / unresolved** means an opcode name exists in the historical table, but local decoding or semantics are absent, conflicting, or incomplete.
- The word “stack” below refers to the VM evaluation/temporary data model; exact ownership/lifetime rules for managed strings and list variants are not fully specified here.
Detailed Japanese-executable dispatch evidence, search-selector internals, and open interpretation questions are recorded in [the JP dispatch and search analysis](./usecode-jp-dispatch-analysis.md).
| `70` | `SEARCH` | Create a typed search object from a result variable, predicate bytes, and selector type (`2..6`). Types `2/3` scan map cells, `4/5` traverse item links, and `6` searches within shape-footprint bounds. |
| `71` | `SEARCH_RECURSIVE` | Unsupported in the inspected Japanese executable; dispatches to the invalid-token path. |
| `72` | `SEARCH_SURFACE` | Unsupported in the inspected Japanese executable; dispatches to the invalid-token path. |
| `73` | `SEARCH_NEXT` | Advance the active search and store its current candidate in the selector's loop variable. |
| `74` | `REAL_CHAR_CONSTANT` | Push the following byte onto the evaluation stack; used in selector expressions. |
| `75` | `FOREACH` | Iterate a list; local decoder reads BP-relative variable, element size, and relative branch. |
| `76` | `FOREACH_STRING` | Iterate a string-list variant; same broad local operand shape as `0x75`. |
| `77` | `SET_PROCESS` | Local decoder identifies this as `set_info`, a process/world notification operation. Exact native-side contract is engine-specific. |
| `78` | `PROCESS_EXCLUDE` | Exclude current process from a subsequent process operation/selection; exact lifecycle effects depend on runtime. |
| `79` | `GLOBAL_ADDRESS_OF` | Push address/reference of global id. |
The table records the combined opcode vocabulary, not a claim that every byte is executable in every Crusader version. Current parsers stop and preserve unknown/unsupported instruction bytes rather than guessing their lengths. The local C++ interpreter is explicitly partial; its enum/results and handlers should not be mistaken for a complete retail VM implementation.
Opcode names and local parser labels do not always match native behavior. Detailed executable comparisons and unresolved mappings are kept in the [JP dispatch and search analysis](./usecode-jp-dispatch-analysis.md).
Until direct runtime/disassembly evidence reconciles these, raw opcodes and operands are authoritative. Do not rewrite or compile these operations based only on a mnemonic.
## 6. Intrinsics and native capabilities
### 6.1 Call contract
Opcode `0x0F` calls an intrinsic by ordinal. The local decoder reads:
```text
u8 argument_byte_count
u16 intrinsic_ordinal
```
The argument-byte count is important evidence for call-site shape, but does not by itself recover parameter types, ownership, or return type. Intrinsic names/signatures shown by tools are metadata hints. The native implementation selected by the running executable is authoritative.
### 6.2 Variant-specific tables
Remorse and Regret have separate intrinsic tables. Do not copy a Regret ordinal name/signature into Remorse or vice versa without matching evidence. Development builds/versions may also differ. ScummVM's source separates the runtime tables (`remorse_intrinsics.h`, `regret_intrinsics.h`) from converter naming/signature hints (`convert_usecode_crusader.h`, `convert_usecode_regret.h`). Pentagram also has a Remorse runtime table, but local notes identify it as sparse/older.
- [Map-viewer generated intrinsic hint tables](../../crusader_map_viewer/map_renderer/src/lib/usecode-intrinsic-hints.generated.js)
- Local comparison and caveats: [usecode-tooling-comparison.md](./usecode-tooling-comparison.md) and [pentagram-crusader-reference.md](./pentagram-crusader-reference.md)
The hint tables and converter names are useful for navigation, but they are not a complete substitute for validating the live executable's dispatch table and a representative call site. An intrinsic id with no current name hint remains a valid raw call, not necessarily an invalid opcode.
The hint tables and converter names are useful for navigation, but they are not a complete substitute for validating the live executable's dispatch table and a representative call site. An intrinsic id with no current name hint remains a valid raw call, not necessarily an invalid opcode.
### Corpus census
The raw `0x0F` call operands were counted from all non-empty derived event-body windows using the local parser and the variant-specific Remorse/Regret hint sets. The scan parsed 977 Remorse bodies and 1,152 Regret bodies with zero parser exceptions.
| `0x0000..0x0135` | Used; all 310 ordinals observed | Used; all 310 ordinals observed |
| `0x0136..0x015C` | Not observed | Used; all 39 ordinals observed |
Here, **used** means the raw ordinal occurs in a decoded intrinsic-call instruction; it does not assert runtime reachability or execution frequency. Ghidra's Remorse `Item_Equip` annotation identifies intrinsic ordinals `0x006`/`0x0B5`, and its `Item_Cast` annotation identifies `0x0E8`; their decompilations dispatch `UC_Equip` and `UC_Cast`, agreeing with ScummVM's Remorse runtime table. The local Remorse corpus also calls `0x134` and `0x135`, beyond Pentagram's 308-entry `RemorseIntrinsics` array configured in `GUIApp.cpp`. Treat that older sparse table's omissions as incomplete coverage, not proof that those calls are absent. Pentagram's converter intrinsic names are explicitly for Regret 1.21 and must not be used as Remorse mappings. Keep the raw ordinal authoritative and the selected variant's engine table as a naming hint; this Ghidra pass does not validate every intrinsic's semantics or Regret's native dispatch table.
### Corpus ordinal name hints
The inventory below lists each ordinal observed in either main corpus, using the ScummVM Remorse and Regret converter-name arrays linked above. Parenthesized argument lists are omitted for compactness. These are name hints, not verified native signatures or semantics; repeated labels at different ordinals remain distinct entries. `not scanned` means the ordinal is outside the Remorse corpus range counted above, not that Remorse's runtime rejects it.
| Ordinal | Remorse name hint | Regret name hint |
| 0x0137 | not scanned | CruStatusGump::I_hideStatusGump |
| 0x0138 | not scanned | Actor::I_clrInCombat |
| 0x0139 | not scanned | Item::getTypeFlagCrusader |
| 0x013A | not scanned | Item::getNpcNum |
| 0x013B | not scanned | Item::hurl |
| 0x013C | not scanned | Item::getCY |
| 0x013D | not scanned | Item::getCZ |
| 0x013E | not scanned | Item::setFrame |
| 0x013F | not scanned | AudioProcess::I_playAmbientSFX |
| 0x0140 | not scanned | AudioProcess::I_isSFXPlaying |
| 0x0141 | not scanned | World::I_clrAlertActiveRegret |
| 0x0142 | not scanned | PaletteFaderProcess::I_fadeToGivenColor |
| 0x0143 | not scanned | Actor::isDead |
| 0x0144 | not scanned | Actor::I_setDead |
| 0x0145 | not scanned | Game::I_playCredits |
| 0x0146 | not scanned | PaletteFaderProcess::I_jumpToAllGrey |
| 0x0147 | not scanned | Item::I_getFamilyOfType |
| 0x0148 | not scanned | Item::getNpcNum |
| 0x0149 | not scanned | Item::getQLo |
| 0x014A | not scanned | Item::andStatus |
| 0x014B | not scanned | Ultima8Engine::getCurrentTimerTick |
| 0x014C | not scanned | World::I_setAlertActiveRegret |
| 0x014D | not scanned | Ultima8Engine::I_getAvatarInStasis |
| 0x014E | not scanned | MainActor::I_addItemCru |
| 0x014F | not scanned | Egg::getEggXRange |
| 0x0150 | not scanned | Actor::I_clrInCombat |
| 0x0151 | not scanned | PaletteFaderProcess::I_jumpToColor |
| 0x0152 | not scanned | Item::setFrame |
| 0x0153 | not scanned | UCMachine::I_numToStr |
| 0x0154 | not scanned | Actor::I_getDir |
| 0x0155 | not scanned | UCMachine::I_numToStr |
| 0x0156 | not scanned | Item::isOn |
| 0x0157 | not scanned | Actor::I_getDir |
| 0x0158 | not scanned | Actor::I_setDead |
| 0x0159 | not scanned | Item::getQHi |
| 0x015A | not scanned | Item::getQLo |
| 0x015B | not scanned | UCMachine::I_numToStr |
| 0x015C | not scanned | Actor::I_getDir |
### 6.3 Capability families exposed through native calls
Across the Crusader runtime tables and observed scripts, intrinsic calls expose or mediate capabilities in these broad families:
- **Items and world objects:** read/write item properties; create, destroy, move, push/pop, grab, drop, and transfer objects; query shape/family/type, frame, status/quality/quantity, coordinates, map placement, overlap/reach, and containment.
- **Actors and combat:** query or set actor state and statistics, targets, direction, movement/activity, animation, hit/damage behavior, and combat state; create or teleport actors where the variant table provides the operation.
- **Processes and scheduling:** inspect process identifiers/results, spawn or coordinate work, suspend/yield, exclude processes, and schedule delayed/tick-driven behavior.
- **Map and trigger systems:** query/update eggs, trigger/controller state, map and coordinate relationships, enter/leave activation regions, and spawn or dispatch event-driven effects.
- **User interface and text:** interact with game UI, gumps, readable objects, prompts, or other presentation services where supported by that build's intrinsic table.
- **Graphics and camera:** camera movement/centering, sprite effects, palette transitions, fades, screen effects, and related presentation operations.
- **Audio and music:** play/stop sound effects and music, query sound state, or alter audio parameters where provided.
- **Time, randomness, and game state:** query or update selected game-time state, obtain random values, and access variant-specific flags or globals.
- **Global storage and VM-managed values:** read/write globals and use the VM's pointer/string/list support. A script-visible pointer is a VM/runtime reference, not an unrestricted host pointer.
These are capabilities of the **bytecode plus the installed native table**, not all built-in bytecode instructions. A particular game version may leave an ordinal unused, map it differently, or implement it only in one variant. The table is not an operating-system API.
### 6.4 Events versus intrinsics
Event slots are script entry points. Intrinsics are native callable services. For example, an event handler can be invoked by the engine for `use`, and that handler can then call item or audio intrinsics. Do not conflate:
-`equip` event slot `0x0A` with any specific intrinsic ordinal;
- event `cast` slot `0x11` with spellcasting;
-`spawn` opcode `0x57` with a native intrinsic;
- class/event dispatch opcode `0x11` with intrinsic call opcode `0x0F`.
## 7. What scripts can do
Subject to the event and intrinsic tables of the active game build, Crusader USECODE can:
- implement class-specific callbacks and call other class/event handlers;
- branch, loop, compare, perform integer/dword arithmetic and bit operations;
- use local/member/global storage, references, indirect access, and result values;
- manipulate strings, lists, string-lists, and aggregate/“huge” values;
- create and control asynchronous processes, yield/suspend, and coordinate process results;
- use native game services to inspect and mutate items, actors, world state, UI, graphics, audio, timing, and trigger behavior;
- attach behavior to engine lifecycle, interaction, movement, hit, schedule, spawn, and proximity callbacks.
This is an event/process scripting system integrated into the game engine. It can perform substantial gameplay logic because its intrinsic layer gives scripts access to native services.
## 8. What the format alone cannot establish
These are limits on what can safely be concluded from the file/bytecode representation, not absolute claims that a native executable could never provide the behavior:
- **No intrinsic implementation from an ordinal alone.** The number, argument bytes, and optional converter name do not define the native routine's full behavior or guarantee the ordinal exists in another build.
- **No class behavior from a slot label alone.** A slot can be absent, empty, repurposed, or class-specific. Event-name tables are vocabulary hints.
- **No lossless source recovery from pseudocode alone.** Decompilation can omit exact operand encodings, opaque values, padding, symbol records, and trailers. Original bytes and offsets must be retained for exact round trips.
- **No settled meaning for every header/row field.** The leading word in each 6-byte event row and the count/base mismatch remain unresolved.
- **No settled semantics for all instructions.** The opcode-name list and local decoder disagree in places; unsupported/unknown opcodes cannot safely be skipped without a proven length rule.
- **No proof of arbitrary host/OS access.** The known model calls game-provided intrinsics. No general-purpose file/network/process/OS syscall interface is established by the bytecode specification.
- **No claim that each game feature is script-owned.** Engine code performs event selection, VM process management, native operations, and state transitions. A script can request native actions but does not necessarily implement those systems itself.
- **No inheritance or virtual-method guarantee.** The established call form names a class and event ordinal. Any higher-level inheritance/dispatch claim needs separate evidence.
- **No guarantee that all listed object-oriented concepts are source-language constructs.** Names such as “class,” “member,” and “routine” describe the compiled runtime representation; a complete original source language/compiler specification has not been recovered.
## 9. Runtime execution model
The most defensible high-level model is:
1. The engine or another script selects a class and event slot.
2. Runtime class/event data resolves that slot to a code offset/body.
3. A usecode process/context is created with item and optional event/context parameters.
4. The interpreter executes variable-length bytecode against local/member/global state and a VM evaluation stack.
5. Bytecode may call another event, spawn a process, call an intrinsic, suspend/yield, or return/end.
6. The engine's process scheduler resumes suspended work and applies native/world side effects.
The local `rebuild/remorse` model records process/context layout and partial opcode semantics in [usecode_vm.h](../rebuild/remorse/include/remorse/usecode_vm.h), [usecode_vm.cpp](../rebuild/remorse/src/usecode_vm.cpp), and [usecode_vm_tests.cpp](../rebuild/remorse/tests/usecode_vm_tests.cpp). Those are explicitly partial models; passing their tests proves the model's tested behavior, not full equivalence to every retail interpreter path.
## 10. Remorse, Regret, and other version boundaries
| Area | Shared evidence | Must remain variant-specific |
|---|---|---|
| Archive/class indexing | FLEX object indexing, class object at `class_id + 2`, 6-byte event rows, event ordinals | Exact class inventory and data bytes |
| Event vocabulary | Shared Crusader event-name table `0x00..0x1f` | Presence and behavior of each class/slot |
| Bytecode | Broad shared opcode vocabulary | Actual use, edge semantics, version-specific opcodes and compiler artifacts |
| Intrinsics | Same general native-call architecture | Ordinal-to-function map, signature, availability, return semantics |
| Debug/symbol data | Symbol and line records occur in bodies | Exact trailer layout and compiler/version details |
| Runtime | Process-based interpreter model | Context fields, startup globals, scheduler details, and implementation differences |
**Remorse global-index conflict:** ScummVM's runtime source initializes global `0x003C` to avatar number `1`, while Pentagram's scratch dump for Remorse 1.01 starts at `0x003D`. The current Ghidra pass traced event dispatch and slot materialization, not a version-matched global initializer, so this remains unresolved and version-qualified. See [Pentagram's Crusader reference note](./pentagram-crusader-reference.md) for the competing evidence.
Do not infer retail Remorse behavior solely from Regret samples, or vice versa. Demo, regional, and patched executables must likewise be recorded as separate evidence targets where their tables differ.
## 11. Safe parsing and round-trip requirements
Any parser, editor, or writer claiming to preserve Crusader USECODE should:
1. preserve the original archive, entry order, sparse entries, class bytes, and unknown objects;
2. bounds-check FLEX offsets/sizes and class/event tables before reading;
3. preserve raw event-row bytes, including the unresolved leading word;
4. store raw event/body byte slices and the exact offsets used to derive them;
6. retain unsupported instruction bytes rather than discarding or guessing their lengths;
7. preserve debug/symbol data and bytes after `END`;
8. use the correct Remorse/Regret intrinsic hint table and retain the raw ordinal and argument-byte count regardless of naming;
9. require unchanged inputs to round-trip byte-for-byte before claiming a lossless format edit path;
10. write modified archives to a separate output and validate with an independent parser/runtime.
The current product/editor path and remaining round-trip milestones are in [usecode-roundtrip-ir.md](./usecode-roundtrip-ir.md). The local proof-of-concept parser is [poc_crusader_usecode_parser.py](../tools/poc_crusader_usecode_parser.py); the user-facing map-viewer implementation is [usecode-decompiler.js](../../crusader_map_viewer/map_renderer/src/lib/usecode-decompiler.js).
- [Pentagram Remorse table setup and entry count](https://github.com/pentagram-u8/pentagram/blob/master/kernel/GUIApp.cpp)
External implementation links describe those projects' code and conventions. For local owner-loaded Crusader data, the raw samples and locally validated extraction rules in this repository take precedence wherever the implementations conflict.
## 13. Open Mysteries for Investigation
These questions have plausible, testable evidence paths. Keep results qualified by game, executable version, and archive; do not promote a shared-implementation convention to a Crusader fact without local confirmation.
- [ ]**Class header and event-table extent:** Determine why ScummVM/Pentagram's event-count formula disagrees with sampled owner-loaded records. Compare bytes `8..11`, table boundaries, and code anchors across Remorse, Regret, demo, regional, and patched archives; verify any proposed formula against every class record.
- [ ]**Leading event-row word:** Establish what the unknown `u16` at the start of each six-byte row encodes. Correlate values with event presence, slot, class, and build, then trace any runtime or loader use before assigning meaning.
- [ ]**Event code-offset convention:** Confirm the `code_base_minus_one` and 1-based displacement interpretation, including zero offsets, duplicate or out-of-order offsets, and how the final body boundary is chosen. Check edge cases against raw class bytes and the runtime's indexed records.
- [ ]**Event-body framing:** Recover the fields and purpose of the 14-byte execution prefix, debug/symbol records, `END`, and trailing bytes. Compare bodies from multiple compiler/build variants and verify that parsing preserves all bytes while locating executable instructions correctly.
- [ ]**Unresolved call/process opcodes:** Determine the target and calling/return conventions of `0x10` (`NEAR_ROUTINE_CALL`), and the exact operand and inline-data layout of `0x58` (`SPAWN_INLINE`). Use representative bytecode call sites and the matching executable's interpreter paths.
- [ ]**Conflicting or undecoded opcodes:** Reconcile historical names and local decoder interpretations for `0x54..0x56`, `0x70..0x74`, and `0x7B`. Trace dispatch in each relevant retail interpreter and validate candidate instruction boundaries against real bodies; do not infer operand lengths from names.
- [ ]**VM value and stack semantics:** Specify ownership, lifetime, and representation for strings, lists, string-lists, references, and “huge” values; verify stack effects, result propagation, and cleanup behavior using interpreter code plus representative scripts, especially around suspend/return.
- [ ]**Intrinsic contracts by build:** Validate ordinal-to-native dispatch, argument types/order, return convention, and side effects independently for Remorse and Regret. Prioritize frequently used or ambiguously named ordinals, Remorse `0x134`/`0x135`, and Regret's native table, which is not validated here.
- [ ]**High event-slot meanings:** Identify behavior for class-local slots above `0x1F` (`0x20..0x4B` in Remorse and `0x20..0x51` in Regret). Cluster bodies by bytecode and class, then trace native callers and observed effects before proposing labels.
- [ ]**Event dispatch edge cases:** Determine how absent, empty, or unsupported event slots affect native fallbacks, and whether higher-level inheritance or virtual dispatch exists beyond the observed class-id/slot lookup. Trace callers and dispatcher behavior for representative slots, including `setActivity`.
- [ ]**Remorse global-index discrepancy:** Resolve whether global `0x003C` or `0x003D` holds the avatar number in each Remorse release. Inspect version-matched executable initialization and compare with the corresponding data/archive rather than relying on cross-version ScummVM/Pentagram notes.
- [ ]**Compiler and source-language model:** Establish which source-level constructs are actually supported by evidence, including class/member layout, routine calls, and any inheritance. Seek compiler-produced samples, symbol/debug metadata, or controlled runtime tests; keep representation terminology distinct from proven source-language features.