Refactor and enhance documentation and tooling for Crusader USECODE
- Updated retail-debugger-entry-options.md to clarify the status of the debugger in No Remorse and No Regret, including findings from recent investigations. - Revised usecode-format-specification.md to improve clarity on opcode behavior and historical naming conventions, with added references to Japanese executable analysis. - Introduced usecode-jp-dispatch-analysis.md to document findings from the Japanese No Remorse executable, detailing opcode dispatch and search object behavior. - Added ghidra_to_dosbox_memory.py, a new tool for translating Ghidra segment:offset addresses to DOSBox physical memory offsets, including comprehensive address validation. - Created test_ghidra_to_dosbox_memory.py to ensure the correctness of address translation logic and selector base loading, with unit tests covering various scenarios.
This commit is contained in:
parent
ffb1918f35
commit
1225a3e737
28 changed files with 1776 additions and 1983 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
**Status:** Evidence-backed working specification
|
||||
**Scope:** Crusader: No Remorse and Crusader: No Regret USECODE archives, class records, event dispatch, bytecode, and runtime services
|
||||
**Last consolidated:** 2026-10-05
|
||||
**Last consolidated:** 2026-10-08
|
||||
|
||||
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.
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ The opcode called `FAR_ROUTINE_CALL` in the historical opcode-name list is decod
|
|||
|
||||
## 5. Bytecode instruction set
|
||||
|
||||
The following inventory combines the historical opcode-name table copied from the Japanese No Remorse disassembly corpus with the local decoder's operand interpretations. It is the broadest recovered opcode vocabulary currently in this workspace, **not** a claim that all instructions have fully verified execution semantics in every build.
|
||||
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.
|
||||
|
||||
Legend:
|
||||
|
||||
|
|
@ -154,6 +154,8 @@ Legend:
|
|||
- **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).
|
||||
|
||||
| Opcode | Historical name | Current behavior / status |
|
||||
|---:|---|---|
|
||||
| `00` | `ASSIGN_LOCAL_CHAR` | Pop/store byte-sized value to a BP-relative local. Decoded locally as `pop_local_byte`. |
|
||||
|
|
@ -240,15 +242,15 @@ Legend:
|
|||
| `51` | `IF` | Conditional branch; local decoder represents it as `jne` with signed relative displacement. |
|
||||
| `52` | `JUMP` | Unconditional relative branch. |
|
||||
| `53` | `SUSPEND` | Yield/suspend the current process. |
|
||||
| `54` | `IMPLIES` | Historical name; operand and runtime semantics unresolved. |
|
||||
| `55` | `AND_IMPLIES` | Name present in historical table; not currently decoded locally. |
|
||||
| `56` | `OR_IMPLIES` | Name present in historical table; not currently decoded locally. |
|
||||
| `54` | `IMPLIES` | Native handler exists; operand and runtime semantics remain unresolved. |
|
||||
| `55` | `AND_IMPLIES` | JP No Remorse pushes word `0x0402`; the historical mnemonic is unverified. |
|
||||
| `56` | `OR_IMPLIES` | JP No Remorse pushes word `0x0404`; the historical mnemonic is unverified. |
|
||||
| `57` | `SPAWN` | Spawn a class/event process; operands include argument bytes, `this` size, class id, and slot. |
|
||||
| `58` | `SPAWN_INLINE` | Spawn a class/event process using inline argument data; exact use of all operands remains partly unresolved. |
|
||||
| `59` | `THIS_PID` | Push/current-process identifier. |
|
||||
| `5A` | `INIT_ROUTINE` | Routine setup; local decoder reads local-byte count. |
|
||||
| `5B` | `LINE_NUMBER` | Debug/source line marker (`u16`). |
|
||||
| `5C` | `SYMBOL_INFO` | Debug/symbol metadata reference; includes a relative offset and fixed-width symbol text. Not ordinary executable flow in observed examples. |
|
||||
| `5B` | `LINE_NUMBER` | Consume a 16-bit line-metadata operand. |
|
||||
| `5C` | `SYMBOL_INFO` | Consume a two-byte offset and nine-byte symbol record; may emit the name. |
|
||||
| `5D` | `PUSH_RETURN_BYTE` | Push byte-sized return value. |
|
||||
| `5E` | `PUSH_RETURN_INT` | Push word-sized return value. |
|
||||
| `5F` | `PUSH_RETURN_LONG` | Push dword-sized return value. |
|
||||
|
|
@ -268,28 +270,24 @@ Legend:
|
|||
| `6D` | `RESULT` | Push process/routine result. |
|
||||
| `6E` | `MOVE_SP` | Adjust stack pointer by an operand byte. |
|
||||
| `6F` | `REL_ADDRESS_OF` | Push stack-relative address/reference. |
|
||||
| `70` | `SEARCH` | Historical name conflicts with the local decoder's `loop` interpretation; unresolved. |
|
||||
| `71` | `SEARCH_RECURSIVE` | Name present in historical table; not currently decoded locally. |
|
||||
| `72` | `SEARCH_SURFACE` | Name present in historical table; not currently decoded locally. |
|
||||
| `73` | `SEARCH_NEXT` | Historical name conflicts with local `loopnext`; unresolved. |
|
||||
| `74` | `REAL_CHAR_CONSTANT` | Historical name conflicts with local `loopscr`; unresolved. |
|
||||
| `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. |
|
||||
| `7A` | `END` | End of event/body marker in local parser; bytes after it may be non-code trailing data and must be preserved. |
|
||||
| `7B` | `REGRESS` | Historical name only; not currently decoded locally. |
|
||||
| `7A` | `END` | Event/body framing terminator in local parsing; not an executable opcode in the inspected Japanese interpreter. |
|
||||
| `7B` | `REGRESS` | Historical name only; outside the inspected Japanese interpreter's dispatch range. |
|
||||
|
||||
### Decoder coverage is not VM coverage
|
||||
|
||||
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.
|
||||
|
||||
There are important known vocabulary mismatches:
|
||||
|
||||
- The historical No Remorse opcode-name list calls `0x70..0x74` `SEARCH`, `SEARCH_RECURSIVE`, `SEARCH_SURFACE`, `SEARCH_NEXT`, and `REAL_CHAR_CONSTANT`.
|
||||
- The current local decoder calls `0x70` `loop`, `0x73` `loopnext`, and `0x74` `loopscr`; it does not decode `0x71` or `0x72`.
|
||||
- `0x55`, `0x56`, and `0x7B` have historical names but are not currently decoded by the local parser.
|
||||
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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue