# Lockstep scenarios and expected results ## Scenarios A scenario is a program, a host and a number of boundaries, run on both cores: `target/release/trace` here and `scripts/reference_trace.py` on 65816-python (its own `W65C816Session`, access tracking on, each record its own `step_record_to_dict`, written with sorted keys and no spaces, less the disassembly text). `scripts/lockstep.py` streams both traces into SHA-256 digests; a scenario passes when the digests and the line counts are equal, so every boundary's kind, cycles, instruction bytes, state before and after, and every bus cycle (address, value, `r`/`w`/`i` with its VDA/VPA/VPB/MLB pins) are equal. On a difference both traces are written out and the reference's `first_trace_divergence` says where. `scenarios/` holds the generated ones (`scripts/make_scenarios.py`; nothing third-party in them): the interrupt workouts and the random-memory programs. The ROM scenarios name fetched files by path and are written to the gitignored `external/scenarios/`. ```json { "memory": [{"address": 32768, "hex": "58ea78"}, {"address": 0, "file": "image.bin", "length": 4096}], "fill": [{"seed": 12345, "address": 0, "length": 16777216}], "rom": "cputest-full.sfc", "registers": {"pc": 32768, "e": 0, "p": 0}, "reset": true, "steps": 20000, "events": [{"step": 20, "action": "reset"}, {"access": 77, "action": "irq"}], "stalls": [{"access": 90, "halted": 3, "during": [{"cycle": 2, "action": "nmi"}]}], "accesses": true, "until_spin": true, "reset_on_stop": 1 } ``` | Key | Meaning | | --- | --- | | `memory` | 16 MiB, zero except these blocks (after `fill`): `hex` bytes, or a `file` (relative to the scenario), optionally its first `length` bytes. | | `fill` | Bytes from a 32-bit xorshift (`x ^= x << 13; x ^= x >> 17; x ^= x << 5`, starting from `seed | 1`; each byte is the top byte after a step), written from `address`. | | `rom` | Run this cartridge in the harness (`harness.rs`, the reference's `w65c816.harness`) instead of flat memory; `memory`, `fill`, `events` and `stalls` are not used. | | `registers` | Any of `a x y s d dbr pbr pc p e` set before the first step (in that order). | | `reset` | Request a reset before the first step (a harness requests one itself). | | `steps` | Boundaries to run and record (at most, with `until_spin`). | | `events` | Host actions: `irq`, `irq_clear`, `nmi`, `nmi_clear`, `abort`, `reset`. With `step: n`, made before boundary `n` (from 0). With `access: k`, made inside the callback of cycle `k` (counted from 0 over the whole run: reads, writes and IO cycles), before it completes; several at one cycle run in the order listed. | | `stalls` | Cycles held by RDY: the callback of cycle `k` calls `note_stall()`, then for each of the `halted` cycles makes that cycle's `during` actions and calls `note_stall()` again. | | `accesses` | Record every bus cycle in the trace (default true). | | `until_spin` | With `rom`: stop where the harness's `run` stops, after STP or a jump to itself. | | `reset_on_stop` | With `until_spin`: this many times, an STP requests a reset instead of stopping (krom's CPUMSC: "Please Reset To PASS STP"). | ## SingleStepTests-shaped lockstep Rungs 0 and 5 run cases in the SingleStepTests format on both cores with nothing masked: `target/release/sst DIR --dump OUT` and `scripts/reference_sst.py DIR --out OUT`, one line per case: the name, the final `pc s p a x y dbr d pbr e`, the number of cycles, every memory byte the case holds or wrote, and every cycle as `address:value:pins` (`-` for an IO cycle's value; the pins `dpvwlemx` as SingleStepTests spells them). The files must be equal byte for byte. ## Expected results `expected/` holds the reference's results, measured at the pin (docs/status.md): - `sst.txt`: the reference's rung 1 total line (its docs/validation.md); - `roms.txt`: `scripts/reference_roms.py`'s lines for rungs 2 and 3; - `mame/*.txt`: `scripts/reference_mame.py`'s summary for each rung 4 game (counts and addresses only).