# Handoff: start `famicom-rust`, a Rust NES/Famicom board proven equivalent to famicom-python ## What you are inheriting `famicom-python` (PUBLIC, github alewman/famicom-python, local clone `/data/emu/famicom-python`) is the family's reference NES/Famicom board: readable, cited, judged by hardware test ROMs and die models, never tuned to another emulator. Transcribe it at the tag **`famicom-rust-pin-1`** (commit `fe89099`, 2026-11-07). Fixes after the pin queue for `pin-2`; do not chase `main`. State at the pin: AccuracyCoin 147/147 (AccuracyCoin `66e8711`), PPU test ROMs 42/42, slow suite 198 + quick suite ~266, Visual 2C02 goldens 14 (13 match + 1 KNOWN), 294 mappers, PAL and Dendy rows, about 30 controllers (`peripherals.py`), Mesen2 sweeps every difference classified. The CPU already exists: **`/data/emu/6502-rust`** (crate `sixfiveohtwo`, transcribed from 6502-python `741419a`). famicom-python pins 6502-python `9dc34bd`; the only differences between the two are tooling (`console.py`, `debug.py`, `trace.py`), the CPU core is identical. 6502-rust already carries the NES hooks: the RP2A03 (decimal disconnected), `Frame::note_stall`, `Frame::dma_stalled` (SHA/SHX/SHY/TAS drop their AND), `ane_constant`/`lxa_constant`, IRQ/NMI raised from inside a bus cycle. Read before writing any Rust, in this order: 1. `docs/start-here.md` (machines table, controllers, power and reset). 2. `docs/timing.md` (the board's cycle model, DMA, the APU). 3. `docs/undocumented-behavior.md` (contradictions C1-C74 and how the board settles each; the open items at the end). 4. `docs/validation.md` (what judges what, and the exact numbers). 5. `src/famicom_python/` module by module: `board.py`, `ppu.py`, `apu.py`, `machine.py`, `system.py`, `peripherals.py`, `cartridge/`. ## The task, in rungs (do not reorder) 1. **Skeleton:** board + 6502-rust + NROM; run nestest and compare its log. 2. **Lockstep gate:** run the Python board and the Rust board side by side and compare per CPU cycle (address, value, read/write, master tick `t`) plus the frame picture. The bus-observer hook (`board.bus_observers`) is the Python side's tap. Build the gate first and keep it as the arbiter, as megadrive-rust did (`/data/emu/megadrive-rust`, its lockstep 80/80). 3. **PPU and APU:** the PPU is dot-based (`run_to`), the APU per CPU cycle; the test ROM suites (`pytest -m slow`) are the acceptance, picture and sample for sample. 4. **AccuracyCoin 147/147** (`scripts/accuracycoin.py`; ROM at `tests/test_roms/AccuracyCoin`). 5. **Mappers:** all 294, each under the lockstep gate on a dump that uses it. 6. **Machines and peripherals:** the PAL and Dendy rows, `peripherals.py`. ## Traps the Python board has already paid for - **One bus call per CPU cycle.** DMA (OAM and DMC) runs *inside* the CPU's stalled read (`board.read_byte`), not as a separate step. Keep that shape. - **Ordering inside a cycle matters to the tick.** `_begin_cycle` sets `t` to the cycle's end (M2's fall); the APU clocks; OUT0-2 reach the devices only on the get -> put transition; the PPU runs to `t` at the end; IRQ/NMI are sampled in `_end_cycle`. blargg's `4-scanline_timing` fails one master tick either side (C74). - **Controllers:** on the NES-001 and AV Famicom, back-to-back reads of the same port clock the pad once; on the RF Famicom every read cycle does (`Machine.joypad_oe_per_cycle`). Tests that read a port in a tight loop must interleave another read. - **Peripherals are two protocols:** controller-port devices (`set_strobe`/`read`/`clock`) and expansion devices (`set_out`/`read(port)`/`clock(port)`). The Zapper reads the PPU's picture and beam position; R.O.B. reads the finished frames. - **PPU attribute count:** the Python PPU must stay at 79 attributes or fewer (PyPy); that limit does not bind Rust, but do not "tidy" the Python side to match the Rust struct. - **Never copy GPL code** (Mesen2, MesenCE under `reference/`). MAME's NES sources are BSD-3 and usable with citation. PPUSim/APUSim (Breaknes) are CC0. - **Never commit ROMs, traces or BIOS.** Test runs must not write into the No-Intro folders. ## Rules (Aubrey's) - Commits: `git -c user.name=alewman -c user.email=alewman@gmail.com commit`, with your model's Co-Authored-By trailer and a Claude-Session trailer. - Push only on Aubrey's OK; nothing external without Aubrey's OK on the exact text. - At most 16 processes; kill by PID, never pkill. No `sed -i`, `rm -rf` or `ln -sfn` one-liners. - Smoke sweeps before full sweeps. The Python board is the spec: if you think it is wrong, stop, show the divergence and its judge, and ask; fix it in famicom-python for `pin-2`. - Deferred, not part of this port: the Vs. System and PlayChoice-10, and the controllers no source describes (famicom-python `docs/undocumented-behavior.md` open item 25). Before starting, tell Aubrey in a few sentences how you read this brief and what you will do first.