How We Verified the Rules
Every rule on the Movement & Time,
Combat & Events and Items pages was
first read from the disassembly. Since 2026-11-30 “verified” on this site
means something stronger: the shipped 68000 code and this project’s
TypeScript were run on the same generated inputs and agreed on every one,
and a deliberately broken copy of the rule was caught by the same inputs.
This page explains how, so that the numbers on the other pages can be
checked. Raw notes: docs/wime/amiga/logic-harness.md in the main repo (not
part of this site).
The harness in one paragraph
Section titled “The harness in one paragraph”A small C program wraps musashi, a plain 68000 core, loads the Amiga
WarInMiddleEarth executable as the AmigaOS loader would (HUNK format, with
HUNK_RELOC32 applied), and runs one routine, or one span of a routine, at
a time. The operating system is never loaded. Instead an instruction hook
inspects every JSR/BSR before it executes: calls into an allow-list run
for real (the random-number routines, the 32-bit multiply and divide
library, abs(), the terrain probe), and everything else is stubbed,
skipped with D0 = 0 and logged with its caller and four stack words. An
unhandled addressing mode, a PC outside CODE, or a memory access outside
the 4 MB image faults the run. Nothing is silently ignored.
CODE hunk 0x020000 (0x1C014 bytes, relocated)DATA hunk 0x040000 (0x5A04 bytes: the shipped initial state)A4 0x047FFE (DATA + 0x7FFE, the SAS/C small-data base)BSS hunk 0x050000scratch 0x100000-0x1FF000 (fake A5 frames, map buffers)stack top 0x200000 (return sentinel 0x001000 is a NOP)A TypeScript client (OracleScript) queues commands for one process launch:
seed any DATA, BSS or heap state, then either call a routine with stack
arguments or run a region from a mid-routine CODE offset until the PC
reaches one of two stop offsets. Regions are how the big UI-entangled
routines are exercised: the battle routine LAB_0A47 is one 3,600-line
function, so only its arithmetic span is run, with a hand-built A5 frame.
reset restores pristine DATA through dirty-page tracking, which makes
thousands of runs a second possible.
For the drawing routines the harness also answers the Amiga custom-chip
window (0xDFF000-0xDFF1FF): reads return 0 and every store is logged.
The log is replayed through tools/shared/amiga-blitter.ts, a software model
of the area-mode blitter, so a blit routine’s output can be compared pixel
for pixel without emulating the chip in C.
Null controls: proving a test can fail
Section titled “Null controls: proving a test can fail”A comparison that reports 0 mismatches proves nothing if it could never have reported any. So every routine has at least one null control: a deliberately wrong version of the rule (a heading parity shifted, an order swapped, a coordinate off by a tile) run against the same vectors. The control must be caught, and the count it is caught on is published beside the result. A control caught on 2,995 of 3,000 vectors means the vectors exercise that rule; a control caught on 0 would mean they do not.
The controls are kept in the replay tests too: each logs how many vectors it still catches and asserts that the count stays above a floor, so a fixture that stopped exercising a rule fails the build.
Full vectors and committed samples
Section titled “Full vectors and committed samples”Each verifier writes two gzipped JSON files, both numbers only (plus the movement tables and the shipped location coordinates), so no game data is committed:
| File | Holds | In git |
|---|---|---|
build/oracle/vectors/<name>.json.gz |
the full set the verifier ran, about 25 MB for all of them | no |
src/engine/__tests__/fixtures/wime-oracle/<name>.json.gz |
a deterministic stratified sample, each well under 100 KB gzipped | yes |
The sample is chosen with no randomness, so a regenerated sample is byte-identical. Every vector gets a class key built from the branch and outcome it exercises and from which null controls catch it, so no class can lose a control’s detections or a rare outcome (the 145 game-ending corners, the third-Nazgûl summons). Within a class the picks are evenly spaced through generation order, and the per-class quota is the largest (capped at 24) that fits a 64 KB budget. The committed fixtures went from 6.7 MB in 18 files to 0.57 MB in total. The replay test uses the full set when it is present and the sample otherwise (a fresh checkout and CI), and is exact on both: 0 mismatches.
Three examples of the sampling:
| Fixture | Full -> sample | Null control still caught on the sample |
|---|---|---|
combat |
95,660 -> 571 | Charge/Engage swapped 288; clock dropped 283 |
turn |
30,000 -> 216 | wake window shifted 48; locations dropped 24 |
ending |
32,000 -> 1,212 | bearer position 360; Barad-dûr coordinates 528 |
The live-engine check: a whole turn
Section titled “The live-engine check: a whole turn”Verifying routines one at a time can still miss how they are wired
together. So the whole movement turn (CODE+0xE868-0xF028) was also run
on the original code and compared with this project’s live
MovementSystem.takeTurn, not with an isolated rule: position, heading,
state, stamina, accumulator, destination, trigger, route queue, event bits
and timestamps, and the final random seed, over 30,000 turns. It found
4,629 mismatches the isolated checks had missed, for four reasons:
- Speed samples the tile centre. The rule reads terrain at
x + 8, y + 8(CODE+0xEBF8). The isolated check had always planted its byte there; the live caller read the position itself. - Arrival is exact, tested after the step, and camps even on a route pop, where the live code arrived by tile and kept marching.
- The Rivendell escort retires (entities
0x4F-0x57on location 22). - Position-triggered event bits run on every step that ends on a corner, and bit 7 at Dagorlad is for non-evil units; the live code scanned once a day and tested the wrong faction.
After the fixes: 0 of 30,000. The same approach was used for the encounter scan, run as one piece with its dispatch and the loop that carries on after a pair comes to nothing (16,000 vectors, 0 mismatches).
The results
Section titled “The results”Every row is the original routine against this project’s rule, with 0 mismatches after any fixes. “Before” is the first comparison’s count where an older rule existed to compare; “new” means no rule existed and this one was written from the code.
Clock, random numbers and movement
Section titled “Clock, random numbers and movement”| Routine | Original code | Vectors | Before | Null control (caught on) |
|---|---|---|---|---|
rand, randBits |
CODE+0x320C, 0x31C2 |
14,688 | 6,528 (every randBits with clock ≠ 0) |
clock term dropped (6,528) |
| End-of-sweep clock | 0xE7A6-0xE7C6 |
980 | new | 24-tick day (750) |
| Camp/wake gate | 0xE868-0xE94A |
18,288 | new | wake window shifted 0x20 (1,084) |
| Base heading | 0xE9A4-0xEA64 |
23,881 | new | rule perturbed (8,654) |
| Steering | 0xE94A-0xEBB6 |
30,000 | new | bias weights 69/39 swapped (8,030) |
| Speed increment | 0xEBB6-0xEC92 |
42,864 | new | heading parity shifted (35,713) |
| Position step | 0xEC92-0xED26 |
6,192 | new | second step dropped (4,095) |
| Route queue | LAB_E420 |
3,156 | new | location index off by one (2,233) |
| Corner and arrival block | 0xED3C-0xF028 |
24,000 | new | every corner arrives (7,997); obedience swapped (3,110) |
| Entity activation | 0xE82A-0xE868, LAB_090A |
24,000 | structural only | chain’s first link as bearer (34); morning-only dropped (1,380) |
| Whole movement turn, vs the live engine | 0xE868-0xF028 |
30,000 | 4,629 | wake window shifted (1,085); locations dropped (264) |
Encounters
Section titled “Encounters”| Routine | Original code | Vectors | Before | Null control (caught on) |
|---|---|---|---|---|
| Encounter trigger | 0xF028-0xF27E |
24,000 | new (the live code met within 16 px) | mover seen 9 px away (7,811); no swap (2,139) |
| Evasion roll | 0xF382-0xF58A |
12,000 | the old rule differed on five points | cloak bonus ignored (59) |
| Encounter dispatch | 0xF27E-0xFEC2 |
13,389 | 186 (the cast’s nod) | evasion skipped (2,684); no pause (4,489); conversation leaves the wise unit alone (356) |
| Scan as one piece | 0xF028 onwards |
16,000 | new | no continuation after a failed pair (729); resume skips a candidate (18) |
| Follow button | 0x843E-0x8592 |
12,000 | new | second unit follows the first (12,000); Gollum never cut loose (3,998) |
Battle
Section titled “Battle”| Routine | Original code | Vectors | Before | Null control (caught on) |
|---|---|---|---|---|
| Force builder | LAB_03DA (0x4DDE), LAB_03CE |
4,000 | not comparable (a different rule) | battle position moved one tile (2,483) |
| Cast seating | 0xA35C-0xA41C, 0xD08A-0xD0D6 |
4,000 | 810 | the other site’s rule (2,292); cast only when side B is empty (810) |
| One battle round | LAB_0A47 span 0x10E5A-0x123D0 |
95,660 | 10,599 of the first 16,920 | Charge/Engage swapped (31,243); clock dropped (28,144) |
| Message wording | 13 call sites 0x11784-0x12218 |
16,864 rounds | 4,611 | old pick (4,611); every figure on side A (1,812) |
| Swing and death clips | LAB_0740 (0xA5CE) |
16,864 rounds | new | game mode ignored (5,231); odd figure counts kept (2,315) |
| Wound-reaction clips | LAB_0740 codes 0x4C, 0x1A, 0 |
22,864 | new | codes swapped or dropped (3,198 each) |
| Army-stack placement | LAB_0603 (0x9FFA) |
6,000 | new | spacing bound 29 (1,739); jitter never redrawn (1,468) |
| Slot-layout driver | 0xA41C-0xA5CC |
4,000 | new | incremental redraw ignored (1,276) |
| Whole layout driver | LAB_072B (0xA316-0xA5CC) |
2,000 | new | figure count not carried (1,145); cast dropped (569) |
| Scene set-up dispatch | 0xAE08-0xB0FE |
3,000 | new | sub-mode read as a pass-by (2,522) |
| Scene arrival block | 0xB336-0xB57C |
3,000 | new | an assumed arrival (1,224) |
| Prop loop | 0xAB7A-0xAC84 |
2,000 | new | no cap (1,374); x matched alone (521) |
| Fireball spawn | 0xC52C-0xC644 |
4,000 | new | the cast’s own threshold word (4,000) |
| Post-battle write-back | 0x1286E-0x13098 |
4,000 | 1,128 | every slot side A (1,666); every mode as the battle screen (620) |
| Battlefield pickup | 0x130A0-0x134CC |
12,000 | new | fixed scatter (2,516); Gollum exception ignored (148) |
Campaign, items and endings
Section titled “Campaign, items and endings”| Routine | Original code | Vectors | Before | Null control (caught on) |
|---|---|---|---|---|
| Hourly day panel | LAB_089E (0xD894), whole routine |
12,000 + 6,000 dates | calendar, timing and council all wrong in the live code | Gandalf ignored (2,886); hourly events (2,819); >= days (4,180); no teleport (927); fixed 60-day skip (864); 24-hour clock (6,000) |
| Item buttons | sub_06826 from 0x6B5C |
30,000 | new (the live game had none) | recruits anywhere (29,273); drop keeps the item (9,953); rope heals (2,347) |
| Mount Doom victory | 0xDD88-0xDDE8 |
20,000 | new | bearer’s own position (6,887); Barad-dûr coordinates (10,282); one commander hop (4,201) |
| Military endings | 0x134CC-0x1352C |
12,000 | new | two garrisons lose (3,413); host tested as a byte (2,141) |
| Ending scenes | 0x2F3A-0x3042, 0x2A28-0x2CB2 |
4,000 (138,000 blits) | new | draw order swapped (2,000); slots ascending (4,000) |
Scenes and sprites
Section titled “Scenes and sprites”| Routine | Original code | Vectors | Before | Null control (caught on) |
|---|---|---|---|---|
SynthSceneObjects |
LAB_D3C (0xD3C) |
9,216 | reset terrains 93 and 188 lost their flags | terrain + 1 (1,656) |
| Scene context and object list | LAB_396, LAB_58E |
6,000 | objects 233 | position + 16 rows (5,816 and 5,883) |
| FRML colour remap | LAB_0D66 (0x17204), blits replayed |
3,000 (24,000 blits) | 64 of 1,913 on mode 0 | mode-table entry + 1 (2,995) |
| Scene sprite draw | LAB_16398 |
400 on 79 real IMAGs | new | mirrored about the 16-padded width (over 80% of mirrored sprites whose width is not a multiple of 16) |
What running the code found
Section titled “What running the code found”Reading the disassembly carefully had already produced every rule above. Running it still turned up these, each now fixed and published on the page it belongs to:
- Withdraw is inert in battle, and the mop-up is
pool / defence, not pass 1’s formula (Combat & Events). randBitsmixes in the interrupt clock, so a battle cannot be replayed from its seed alone.- The calendar starts on 23 September 1418 S.R. and the events fire at
08:00 with
==(Movement & Time). - The meeting range is 7 px, not 16, and the Follow button makes the first unit follow the second.
- Ignored battles are fought and written back, and cast monsters keep their strength.
- The coil of rope changes nothing, statically and dynamically (Items).
- Two scene-generator details: on terrains 93 and 188 the placed
objects keep the previous object’s flags, and overlay selectors
0xA0and0xE0add one more object that reuses the previous object’s image. An earlier symbolic-executor check over 15,872 combinations could not see either. - The FRML colour remap’s “sticky clear”: the blit loop switches to a clear operation at the first mode field of 4 and never switches back, so 17 of the 48 mode-table entries draw differently from the idealised rule. No entity uses any of them (see Characters & Mobs).
- The ending “credits scroll” is a row of nine figures (Combat & Events § “The ending scenes”).
What could still be hiding
Section titled “What could still be hiding”- Stubs return 0. Every stubbed call (UI draws, string building, sound;
about 10 per battle round) returns
D0 = 0. If one of them changed slot state or drew a random number, the seed and strength comparisons would show it; across 95,660 rounds they did not. - The interrupt clock is constant per vector. The real value changes
between calls; this project’s
WimeRngtakes a clock callback for that. - Spans are spans. Where only part of a routine is run, the A5 frame is hand-built. The post-battle check fills the whole 210-byte frame with random noise before writing its inputs, so a read of an unset local would show up as a mismatch.
- The turn comparison has a domain. Positions at least 20 px from the map’s west and north edges (the steering window wraps into the neighbouring row near the edge), and route queues that are either empty or the scripted queue the activation loaded.
- Real time is not reproducible. The battle scene’s per-tick animation draws random numbers on frames paced by the vertical blank, so the number of draws between the figure placement and round 1 depends on real time on the original too.
The DOS ports: read, not run
Section titled “The DOS ports: read, not run”The harness runs the Amiga executable only. DOS VGA (START.EXE) and DOS
EGA (LORD.EXE) are held to a different standard: their x86 consumers were
read, found by byte signature in both executables, and every table was
compared with the Amiga’s. The 382-byte movement, calendar and terrain block
is byte-identical on all three builds, the speed, steering, step, arrival
and day-panel code has the Amiga’s structure instruction for instruction,
and no logic difference was found; 28 signature tests pin the consumers.
The real differences are in the data: pooled name strings, 80 of 196
sprite-set bytes on VGA, and scripted-march slots (11 differ on VGA, 35 on
EGA). Details are on Movement & Time § “DOS VGA and
DOS EGA run the same rules”; raw notes in
docs/wime/dosvga/exe-gameplay-data.md.
A common pitfall
Section titled “A common pitfall”“Verified against the disassembly” is not verification. The movement speed rule had been checked in isolation on 42,864 vectors with 0 mismatches, and the game still moved units wrongly, because the isolated check planted its terrain byte where the original reads it and the live caller read it somewhere else. The FRML remap’s sticky clear and the scene generator’s stale flags passed careful reading and a symbolic executor, and fell over on the first real run. Compare against the shipped code, compare the code as it is wired, and keep a null control beside every comparison.