# Methodology How the work behind the [charter](charter.md) is done: evidence, gates, measurement, documents, provenance and the house rules. The charter says what we promise; this says how we keep the promise. Where a practice was learned the hard way, the lesson is named. ## Evidence in the specification Every constant, rule and quirk in an `x-python` specification carries its evidence in the comment beside it, using one of these tags: | Tag | Meaning | | --- | --- | | `MEASURED` | hardware measurement or capture (a scope, a logic analyser, a probe ROM on our own console) | | `DIE` | die-level analysis or a die-derived model | | `TEST ROM` | a hardware test ROM with verdicts captured on real units (name the test) | | `DOC` | primary or community documentation (name it: Pan Docs, fullsnes, GBCTR) | | `OBSERVED` | another emulator's behaviour, run as a black box (name it and its revision) | | `FITTED` | a value chosen because it makes named tests pass; say which and what else was tried | | `HYPOTHESIS` | a reasoned guess with no direct evidence; say what experiment would settle it | `FITTED` is already the family's habit (gameboy-python's PPU constants); the others give it company. A fitted value is honest; an untagged one is not. Larger findings go in the project's `docs/validation.md` (results tables, dated, with the commit) and `docs/undocumented-behavior.md` (behaviours no document describes, with the evidence). What remains unknown is written down where the behaviour is, not hidden. ### When real units overrule the die The charter's evidence order is the default; disagreements about one observable are settled this way (accepted 2026-11-19; the reasoning and cases are in [proposals/2026-11-die-against-hardware.md](proposals/2026-11-die-against-hardware.md)): - **Directness first.** Evidence that observes the behaviour directly on real units (measurements, test-ROM verdicts captured on several units) outranks evidence that reaches it by inference through a mechanism, whatever their kinds. - **Races go to real units.** A die result that turns on the order of events within one clock edge or phase is decided by real-unit evidence on that observable where it exists. A netlist simulation decides races by its own delay model (zero or unit delay, or one evaluation per phase as in Breaknes' PPUSim); a redrawn schematic by the phase label its author wrote. Tag the behaviour `TEST ROM` or `MEASURED` "over DIE (race)" and cite the die reading. - **Grade the die.** `DIE` names its kind: a netlist run in simulation, or a schematic read by eye. A read schematic sits below a simulated netlist, and on a race below a test ROM. - **Scope the die.** Write down the conditions a die result was taken under; applied beyond them it is a `HYPOTHESIS` until checked. - **Keep the loser.** The overruled reading stays as a counted departure in the die-trace test, a switch, or a machine row, never deleted, and the entry names the experiment that would settle it (a probe ROM on a real unit, a deeper die trace). - **Units that disagree become revision rows, not a vote**; the die may be the tie-breaker for which revision it shows. - **Die models are corrected too.** A die-derived model is a model: when our evidence shows it wrong, the finding goes to its author (Breaknes took ours and rewrote it in its own gate-level style). Unchanged: the die still beats documents, emulators and fits; where no real-unit evidence touches an observable, the die decides; a test ROM whose verdicts were not captured on real units is only a document. Lessons: the 2600's HMOVE-on-cycle-74 tie (a2600-python C27, seven consoles over Sim2600); POKEY's first 64 kHz interrupt (pokey-python U1, Acid800 over ijor's schematic, 2026-11-19); sm83's HALT rule, measured on timer interrupts and wrongly widened to STAT (gameboy-python); the `nuked-md` machine row. ## Gates A gate is the command whose passing is the proof. Every tier step has one, and it runs on every kept commit (`scripts/ladder.sh` in the Rust tiers). - **Lockstep:** both sides run the same case table and write one line per slice (CPU state, board time, a CRC of every bus cycle, a CRC of the finished picture, the APU's sample CRC with `--audio`, a Super Game Boy's picture and state with `--sgb`); the lines must be identical. The reference's traces are cached (`--reference-cache`), keyed by case, so a Rust change re-runs only the Rust side. When the reference changes, its traces are moved aside, never deleted, and regenerated. - **Save states in the gate:** `--save-at-half` saves half way, loads into a fresh console and must continue identically. This is what makes rewind and run-ahead trustworthy. - **Case tables** grow by need: test ROMs from the real boot ROMs, commercial dumps with a scripted input, every machine row, every mapper class, the suites a change touches. - **A gate that cannot fail proves nothing.** Seeded one-line faults (`seeded_faults.py`), each run through the gate, each caught, including faults in every shortcut a `-fast` or `-turbo` adds. A fault that changes nothing observable is an equivalent mutant: note it, do not count it. A real fault the gate misses is a recorded blind spot. Lesson (2026-11-13): a fault script that copied sources with their old timestamps could let cargo reuse a stale build; copies get fresh timestamps. - **The hardware suites still run directly** on every tier that changes timing structure (the Gambatte pass lists, Mealybug pictures), so a tier is judged against hardware and not only through the chain. - **Smoke before sweep:** iterate on a curated smoke list (problem ROMs plus perfect classics); run full sweeps at commit points; a full sweep's failures become the next smoke list. ## Measuring speed - **Measure CPU time, alternate builds, keep the best.** On a shared machine other work only slows a run down, so each side's best of many alternating short runs is its speed (`scripts/ab.py`). - **Measure across code layouts.** Two builds of the same source differed by 5 % here from where the linker placed hot code; one single-build "win" was layout luck and was reverted (gameboy-rust-fast, 2026-11-13). A change counts only if it wins on every layout (`scripts/ab.sh`: default, 32- and 64-byte block alignment). - **Measure the target that matters.** Native numbers guide; the browser's wasm, the phone, and run-ahead's multiplied cost decide. A site shows its milliseconds per frame. - **Prune what does not pay.** A change that does not measurably win is removed, and goes in `docs/not-kept.md` with its numbers so nobody tries it again blind. - **Profile before guessing** (`x-profile` with `scripts/profile.py`: self time by function, inlining resolved). When the profile is flat, small tweaks are exhausted and the next gain is structural. - **A host crate repeats the release profile** (fat LTO, one codegen unit): Cargo uses the top crate's. ## Documents - Every project keeps `README.md` (what it is, its lineage line, how to run it, measured status) and `docs/status.md` (every rung, its command, its count, the commit and date it was measured). Numbers carry the commit they were measured at. - **Stale documents look like slop.** A pass that changes behaviour updates the numbers in the same commit or the next one; before a repository goes public, a docs-freshness pass. - A new agent's first read is the project's handoff brief or status document; a finishing agent leaves one (`docs/status.md`, or `docs/phase0-status.md` for groundwork). - Lineage edges (pins, forks, copies, evidence) are recorded in this repository's manifests, so the report can say what has not travelled. ## Provenance in practice - **Licence files and headers.** Every repository has a LICENSE file. Every source file starts with its SPDX header (`# SPDX-License-Identifier: MIT` in Python and shell, `// SPDX-License-Identifier: MIT` in Rust and JavaScript); a file holding anything taken from elsewhere adds a line naming the source, its licence and its notice. New files get the header when they are written; existing repositories get theirs in one pass each (owed across the family, see families.md). - **Which files** (added 2026-11-19 at Aubrey's request): everything that is code or runs as code: source, tests, examples, binaries, scripts (shell, Python, the gate's tools), build glue, HDL and shaders, and the CI workflows (`# SPDX-License-Identifier: MIT` as the first line of the YAML). Not required on documents (README, docs/, CHANGELOG, NOTICE), data (case tables, traces, fixtures, images), lockfiles, manifests that state the licence themselves (`Cargo.toml`'s `license`, `pyproject.toml`'s), or the LICENSE file; a Markdown file may carry it as ``. Vendored third-party files keep their own header untouched. - **Where**: within the first five lines, after a shebang, an encoding line or a doctype. The line under it names a source and its notice when the file holds anything taken (`src/seek.rs` in pcenginecd-rust: Shadoff's MIT `seektime.c`, notice in NOTICE.md). - **The check**: `python3 lineage.py` reports, for every manifested repository, how many of those files lack the header (`spdx_missing`); a header pass is done when its repository reads zero. Run it before calling a repository ready to publish. - **A file holding permissively licensed material from elsewhere** (code or a table copied or ported, not facts learned from it) names both licences on the SPDX line with `AND`, and the next line names the source and where its notice is kept (Aubrey, 2026-11-19; provenance-audit-2026-11.md, decision 11): ```rust // SPDX-License-Identifier: MIT AND BSD-3-Clause // The volume table is MAME's src/devices/sound/c6280.cpp (BSD-3-Clause, Charles MacDonald): notice in NOTICE.md. ``` Tools read the first line (REUSE, ScanCode, GitHub's detection); people read the second. A file that only records facts read in such a source (register values, a behaviour, with the source cited) stays `MIT`, with the source credited in NOTICE.md as before. The same form serves any permissive licence (`MIT AND Expat`, `MIT AND ISC`, `MIT AND Zlib`); a copyleft licence never appears in an MIT project's header, because nothing copyleft is taken (charter, licences point 3). - **Before moving code between projects,** read both headers: MIT code may go into a GPL project; GPL code may never go into an MIT one. - **A GPL project** (a fork of a GPL tool, or a core relicensed to honour a GPL source) keeps upstream's LICENSE and notices untouched, says what it is in its README's first lines, and publishes its full source wherever it is distributed, including the source of a compiled build a site serves. - Before writing code informed by another implementation, check its licence. GPL/LGPL: run it, measure it, do not open its source while writing. Permissive: read, cite, keep the notice with anything taken (a table, a formula). - Run `provenance_check.py` (in pcengine-python) before a release and after work done with any emulator source open; record the result in the project (`docs/provenance.md`, or the validation document's provenance section). - Agents report anything they wrote with an emulator's source open. - **Author respect, kept apart from licence** (Aubrey, 2026-11-26; charter, licences point 8). Two questions are asked of every source: what does its licence allow, and what does its author wish? They are recorded separately, so a licence finding never hides a respect finding or the reverse. - **In sources.md** a source whose author objects to AI use, or one in that author's lineage (derived from their work, or a tool or simulation built on such a work), carries both its licence verdict and "set aside (author's wishes: lineage, date)". - **In each project's docs/provenance.md**, a section "Author respect" lists every fact, constant, rule or test verdict that came through a set-aside lineage: where it is, the set-aside source, what other evidence backs it, and what replaced it. Behaviour stays as it is until new evidence (a hardware-run test ROM, a measurement, a respect-clean implementation's own research) is in hand; meanwhile its evidence tag says honestly what is left (FITTED or HYPOTHESIS). - **Lineage is checked before a source is adopted**: a candidate replacement must not itself be built on the set-aside work. - Set-aside trees and builds are moved out of the repositories (to /data/backup), not deleted, and their pins removed. - Romsets and firmware are found through environment variables (`NO_INTRO_DIR`, `MAME_ROMPATH`), never a machine path or a mirror's name in a repository; private sets never go into sweeps or reports. ## Repositories, pushing and deploying - New remotes are private by default; chip cores go public (free CI) after a history audit. CI is minimal (main and pull requests, superseded runs cancelled; by hand only on a private repository, whose minutes cost money). - Commit locally at good points without asking. Pushes to public repositories, tags and deploys are Aubrey's call unless he has said otherwise for that project; agents give him the exact command. - CI's toolchain may be newer than the machine's: run clippy from the rustup stable toolchain and avoid patterns a newer clippy flags (an index-only range loop failed gameboy-rust's CI on 2026-11-13). ## House rules - No `rm -rf`, `sed -i` or `ln -sfn` one-liners; edit files with the editor tool; move aside instead of deleting. - PyPy is the floor for the Python tiers (its newest supported Python, 3.11 now); keep classes under about 80 attributes (PyPy devolves larger instances to dictionaries). `PYPY_GC_NURSERY=1M` and `nice` for parallel PyPy runs; the machine is shared. - External posts name the Claude model that wrote them, read [community.md](community.md) first, and go in [contributions.md](contributions.md) the day they go out. - Chip-level technical choices: take the recommendation, mark it provisional, move on. Policy choices go to Aubrey.