How We Verified the Rules
Between 2026-12-01 and 2026-12-02 every routine on Spirit of Excalibur’s
game-logic list was run on the shipped 68000 code and on this project’s
TypeScript with the same generated inputs, and the two agreed on every
vector. “Verified” on this page means exactly that, with a deliberately
broken copy of the rule caught by the same inputs beside every result. The
method is the one already used for War in Middle Earth;
this page covers what is specific to Spirit. Raw notes:
docs/spirit/amiga/logic-harness.md and docs/tooling/m68k-oracle.md in the
main repo (not part of this site).
Verified is not playable. No Spirit screen in the browser consumes these rules yet. The army round plays in the viewer’s battle sandbox; everything else (the duel, map movement, encounters, items, scenes, saves and the animation VM) is a pure, tested module waiting for the screen that will call it. That wiring is the open row
spirit-wire-verified-ruleson Status & Open Work.
The harness, as Spirit uses it
Section titled “The harness, as Spirit uses it”The WIME harness was generalised on 2026-12-01 so that one C binary (musashi, a plain 68000 core, behind a HUNK loader) runs all three Amiga executables. The per-game part is a short config; everything else is shared.
Spirit (Excal) |
|
|---|---|
| CODE hunk | 0x2B8AC bytes |
| A4 (SAS/C small-data base) | 0x57FFE, i.e. DATA + 0x7FFE, proven by the _Rand seed landing at -17200(A4) |
| SAS/C jump table | 171 JMP.L trampolines at the start of DATA, every one resolving to a named CODE symbol |
| Symbols | the executable keeps its HUNK_SYMBOL names (about 570 CODE and 500 DATA), so verifiers call _Rand or stub _OpenMenu by name |
| Runtime library | .divs to .mulu at the end of CODE; a divide by zero inside it is a CPU exception the harness reports as a fault, as the original would crash |
A call into an allow-list runs for real (_Rand, the arithmetic library,
small leaf helpers such as _SectRect); every other call is stubbed,
returns a scripted value, and is logged with its stack arguments. Most of
the later routines run through a window oracle: the real routine executes
over random bytes in declared memory windows, the TypeScript model reads the
same windows and throws on any access outside them, and every window, the
_Rand argument sequence and the full stub log (twelve argument words per
call, sixteen where _OpenMenu takes that many) are compared.
Null controls and fixtures
Section titled “Null controls and fixtures”Every result below has at least one null control: a deliberately wrong copy of the rule (sides swapped, a threshold off by one, a compare made signed) run on the same vectors. It must be caught, and the count it was caught on is published. A control caught on 0 vectors would mean the inputs never exercise that rule.
Each verifier writes its full vector set to build/oracle/vectors/
(gitignored) and commits a deterministic stratified sample under 64 KB to
src/engine/__tests__/fixtures/excalibur-oracle/. Spirit has 73 committed
fixture files, 1.88 MB in total, numbers only, so no game data is
committed. The replay test runs without the CPU core, on the full set when it
is present and the sample otherwise, and asserts that each null control is
still caught.
Two harness corrections
Section titled “Two harness corrections”Both were found while verifying Spirit, and both are published in
docs/tooling/m68k-oracle.md:
Correction (2026-12-01): a call straight after a stubbed call was not intercepted. musashi fetches the instruction at the PC the hook leaves behind without calling the hook for it, so a
jsrimmediately following a stubbedjsrran for real and vanished from the stub log. It surfaced in_WinScenario(_CloseMenuthen_FadeOut,_FadeOutthen_HideCursor). The harness now keeps intercepting at the new PC. Every one of the 80 verifiers across Spirit, Vengeance and WIME was re-run with the old and new binary at 2,500 vectors: every result and null-control count is identical apart from the new_WinScenariolines, which the old binary got wrong (2,500 of 2,500).
Correction (2026-12-02): allowing a routine also runs its callees. The hook skips a call when the caller’s address lies in an allowed range as well as the target’s, so allowing
_CloseBuildpulled the memory manager’s_DisposHandleand_HValidin with it. Only leaf helpers are allowed now; a routine with heavy callees is stubbed, given its effect by a scripted memory write, and verified on its own.
Two smaller limits are recorded too: a scripted stub holds at most 64 return
values (a first _MoveMapIcons run with 2,000 scripted terrain bytes
disagreed exactly on the vectors that made more than 64 _MapChar calls),
and the twelve-word log could not compare the last four of _Encounter’s
sixteen _OpenMenu arguments; a sixteen-word log was added for _Trade.
The results
Section titled “The results”Every row is the original routine against this project’s rule, with 0 mismatches. Addresses are CODE-relative. Where several controls exist the strongest one or two are shown; the raw notes list them all.
Random numbers and the army battle
Section titled “Random numbers and the army battle”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_Rand |
_Rand |
6,180 | tick dropped (4,885) |
| One army round | _ArmyCombat span 0x20648-0x217B2 |
5,993 (246 divide-by-zero faults matched by a TypeScript throw) | one roll against 64 (1,852); no tick (1,934) |
_ArmyCombatEndMessage |
0x1FD2E |
30,000 (820 faults matched) | fort words ignored (5,282) |
_GetTotals |
0x1FC9A |
3,000 | sides swapped (2,860) |
_Charge, _Engage, _Flank, _Retreat |
0x1EF8A-0x1F248 |
20,000 | class masks swapped (3,014) |
_ArmyCombatFrontLine |
0x1ED16 |
10,000 | gate never cleared (5,513) |
_ArmyCombatInitForces |
0x1F7A4 |
5,000 | leader chain not followed (4,682) |
The duel
Section titled “The duel”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_Reaction |
0x3C7C |
20,000 | grudge memory dropped (17,052); personality from the wrong participant (18,217) |
_HandleDeath |
0xA2E6 |
6,000 | a different record dying (6,000) |
_FightDone |
0xA738 |
20,000 | refusing record types ignored (8,104); threshold 50 (85) |
_DoCombAction, codes 0-8 |
0xAEEE |
20,000 | third _Reaction call given a clean mode (601); signed rolls (675) |
_IndvCombat |
0xA680 |
5,000 | clamp to 6 (3,747) |
Map movement, challenges and encounters
Section titled “Map movement, challenges and encounters”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_CoordToLoc, _MapChar |
0x604E, 0x1B598 |
5,000 each | words read signed (1,475); fixed 73-cell row (473) |
_Agenda |
0x15840 |
8,000 | queue left unshifted (4,784) |
_MoveTogether |
0x160D4 |
8,000 | pair order swapped (7,901) |
_SelectMoveDest |
0x169D4 |
8,000 | agenda left uncleared (7,097) |
_MoveMapIcons |
0x1DB88 |
10,000 | flat step cost (3,499); shift taken mod 32 (1,550) |
_AtDestination |
0x15A76 |
15,000 | ring not shifted (4,601); location state not advanced (4,500) |
_FindFollowers, _FindForces |
0xE328, 0xE7FA |
20,000 each | depth-first descent dropped (1,764); faction test as “any” (10,926) |
_Challenge |
0xBFBC |
20,000 | roster objects not indexed (12,999); no fighters-first partition (6,527) |
_CheckEncounters |
0x1E6D8 |
20,000 | expiry sweep dropped (9,844) |
_Encounter |
0x16284 |
20,000 | faction gate dropped (7,692); ambush roll dropped (708) |
_PreventEncounter, _AllowEncounter |
0x1E5D2, 0x1E63C |
6,000 | in-order pair only (861) |
_CheckFaith |
0x690A |
3,000 | location 0x261 not a faith site (429) |
Items, trade and the menus
Section titled “Items, trade and the menus”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_TestMagDefense |
0x12B7E |
20,000 | strength ignored (2,503) |
_AddItemToInven |
0xF2D2 |
20,000 | stack not decremented (7,501) |
_GiveItem |
0x117CC |
20,000 | reaction pair swapped (16,452); refuse at 31 (1,360) |
_SeizeItem |
0x10EDE |
20,000 | rank test dropped (877) |
_ApplyEffect |
0x123C4 |
20,000 | no 0-100 clamp (10,182) |
_UseItem, all 67 dispatch entries |
0x12C5E |
60,000 in three groups | weight compared signed (10,016); effect-slot lookup ignored (4,874) |
_Trade |
0x104C0 |
20,000 | reaction pair swapped (11,086); accept on equal value (2,755) |
| The item, place, person and spell lists | _ListItemsInInven 0xFA1C and 13 more |
3,000 to 20,000 each | exclude mask ignored (10,880); held bit ignored (16,456) |
Scenes, events and saves
Section titled “Scenes, events and saves”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_OpenScene |
0x6B18 |
20,000 | seed from (y << 10) + x (10,190); hidden figures drawn (12,824) |
_MapLevel, _SceneLevel |
0x69A8, 0x7A72 |
20,000 each | copy-protect gate dropped (10,245) |
_WinScenario |
0x56C6 |
20,000 | merge mask inverted (14,002); episode index from zero (20,000) |
_CheckEvents |
0x1A112 |
20,000 | key tests joined with AND (13,998) |
_TestRegions |
0x1A396 |
20,000 | menu-block priority test dropped (3,321) |
_Save, _Restore |
0x1EAA, 0x2750 |
20,000 each | records swapped (11,875 / 11,826); save reports success on failure (19,226) |
The FSME animation VM
Section titled “The FSME animation VM”| Routine | Original code | Vectors | Null control (caught on) |
|---|---|---|---|
_Anim_Wait, Face, Until, Manip, Volume, Sound, Draw, Ctrl, Move |
0xA04-0x1A64 |
20,000 each | ctrl push without shift (13,492); draw flag (5,247) |
_Anim_If with the real _WithinRange |
0x10B6 |
20,000 | skip first only (2,584) |
_Anim_Spawn, _Anim_SetAnim |
0x1500, 0x1800 |
20,000 each | pc resolved instead of raw (4,026); no shift (8,726) |
_DoAnim, _CloseBuild |
0x6, 0x1B5C |
20,000 ticks, 2,000 | no alignment (11,386); y compared unsigned (8,928) |
_DoImagScript |
0x63E |
20,000 | pc counted in bytes (19,978) |
_DoFrmlScript |
0x70A |
20,000 | no frame header (20,000); deadline signed (4,204) |
What running the code found
Section titled “What running the code found”Each of these was a reading of the disassembly that the real code overturned or sharpened. They are published here as corrections because an earlier note, or the earlier battle code, said otherwise.
- The army round’s threshold is the opposing firepower, not a constant
64:
(Rand(8) + 12) * tally / otherTroops, with one hit roll per 128 points of it. The two-round windup for every unordered slot was wrong too: each slot runs its own state machine, and an unordered slot never fights. - The battle-over test was inverted in the first port. The original asks
_ArmyCombatEndMessageonly when the round counter exceeds 1 or a side has no fighters, and an army also breaks on the strength-ratio tests (8 or 11, 14 with a fort), not only when a side has no troops. The viewer’s sandbox now plays the verified round. - A retreat costs an eighth of a slot’s strength only at the near edge
(
x <= 0xB9); further out it just starts the slot running. - Code 5 of the duel passes
_Reactionone argument too few, which makes the character who backs away from a fight think very highly of their opponent. See The Reaction Quirk. _Challengeis the encounter set-up, not the duel prompt alone, and its-0xA(A5)local is the value 50 left by the clearing loop, which gates a retry search. The “50-entry clear against a 40-slot model” discrepancy is settled: the list is two 20-slot rosters and the loop clears ten bytes more.- A terrain scene is a function of where the party stands.
_OpenScenere-seeds the random generator with(x << 10) + ybefore rolling the terrain scene, so every later roll in it follows from the position. - The save layout comes from the code.
_Saveand_Restoreare one chain of 23 transfers: 9,238 bytes, which with 22 unwritten trailing bytes is the 9,260 of everyEPISODE<n>.DAT. - Troop counts and the castle guards were not missing formulas: see Status & Open Work § “Corrections”.
- Death is script entry 12, not the
Spawn(SELF->INCED)marker the character gallery’s labels were built on: see Characters & Creatures § “Correction: death animations”.
What could still be hiding
Section titled “What could still be hiding”- Stubs are stubs. A stubbed callee returns what the vector scripts. Where a callee changes state, the effect is scripted with a memory write and the callee is verified on its own.
- Some input spaces are bounded.
_UseItemwas run with item ids below 50, slot counts of at most0x58, rosters of at most 20 and stat-kind nibbles 0-6._ApplyEffect’s scale table holds zeros for six of its sixteen slots, which divide by zero in the original, so the vectors avoid them. - The interpreters were run with their handlers stubbed. The sixteen
_Anim_*handlers are verified one by one, and the interpreters are verified with each handler’s return byte and side effects scripted; the combination has not been run as one piece. - Frame locals read before they are written (
-17(A5)in_FightDone,-14(A5)in_DoCombActioncode 6) are taken as inputs. Each is pinned by a null control that treats it as 0.
Read next
Section titled “Read next”- The Reaction Quirk: one original-engine bug measured in play.
- Vengeance: How We Verified the Rules: the same routines at the sequel’s revision, and where they differ.
- Status & Open Work: what is still open, including the wiring.