# gsu-python A readable, pure-Python **Super FX** core (Argonaut/Nintendo's Graphic Support Unit: Mario Chip 1, GSU-1, GSU-1A, GSU-2, GSU-2-SP1), for the Super Nintendo cartridges Star Fox, Stunt Race FX, Vortex, Dirt Trax FX, Doom, Yoshi's Island, Winter Gold and Star Fox 2. Its first user is the board `snes-python` (milestone 7). **Status (2026-11-07): core built; rungs 0-4 of [docs/validation.md](docs/validation.md) passed.** Decode against fullsnes' map and MAME's disassembly; 122 directed tests from Nintendo's manual; krom's 31 `GSUTest` ROMs (1,226 rows: 1,225 with the defaults, the one left being the contested C9, all 1,226 with C9 switched); Nintendo's six worked timing examples exact; MAME 0.285 lockstep replays of Star Fox, Stunt Race FX, Vortex, Doom, Yoshi's Island and Winter Gold windows with no finding. Rung 5 (Mesen2 replay) is a follow-up; rung 6 is snes-python's milestone 7. Python 3.11+ (CPython and PyPy), no dependencies, correct rather than fast. Local git only. **There is no hardware-captured data, console route or die model for this chip.** Nintendo's *SNES Development Manual Book II* documents it, including cycle counts; fullsnes corrects the manual in four places; krom's 31 self-checking tests give 1,226 expected values (which MAME and Mesen2 both pass); the emulators agree on values and disagree on time. [docs/validation.md](docs/validation.md) ranks every oracle; [docs/claims.md](docs/claims.md) says how strongly each behaviour is claimed. ```python from gsu_python import GSU, MC1, GSU1, GSU2 gsu = GSU(rom, ram, model=GSU2) # rom: bytes (the cartridge), ram: the board's bytearray gsu.reset() # the console's reset (BK2 1.5.1) used = gsu.run(clocks) # input clocks; whole instructions (>= clocks while running) gsu.read_io(0x3030) # S-CPU read of $3000-$34FF; None where the chip is silent gsu.write_io(0x301F, 0x80) # S-CPU write; $301F starts the GSU, SFR GO = 0 stops it gsu.cpu_rom_byte(0xFFEA) # the fixed vector byte while GO and RON, else None gsu.cpu_owns_ram # False while GO and RAN gsu.irq # the /IRQ output state = gsu.capture_state() # everything inside the chip; restore_state(state) ``` Time is counted in **input clocks** (the 21.4 MHz unit: CLSR = 0 doubles every cost inside the core); the board owns the input-clock-per-master-clock fraction and the overshoot of `run`. Everything the core does is one class over the board's buffers, with a frozen `Model` per chip (`MC1`, `GSU1`, `GSU1A`, `GSU2`, `GSU2_SP1`). The contested behaviours are class attributes (`STOP_R15_PLUS_TWO`, `REGISTER_WRITE_LATCH`, `RESTRICT_ACCESS_WHILE_RUNNING`, `FMULT_R4_UNCHANGED`, `INCREMENTAL_CACHE_FILL`, `IRQ_FLAG_WHEN_MASKED`, `RAM_READS_CHARGED`, `WORD_WRITE_BUFFER`, `OVERLAPPED_PIXEL_WRITEBACK`, `CPU_R14_WRITE_PREFETCH`, `CACHE_WINDOW_BY_ADDRESS`, `TRANSPARENCY_BY_DEPTH`, `WAIT_ON_BUS`), so a comparison flips one without editing code. ## Tooling ```sh python -m gsu_python GSUADD.sfc --krom # krom's rows on the bare core python -m gsu_python GAME.sfc --start 01:8A60 --clsr 0 # run to STOP, print registers python -m gsu_python GAME.sfc --start 01:8A60 --trace t.jsonl # one JSON line per instruction python -m gsu_python GAME.sfc --start 01:8A60 --debug # the command debugger python -m gsu_python.replay tests/mame_traces/RUN --model mc1 # a MAME lockstep replay ``` `state.py` (`CPUState`), `disasm.py` (BK2 syntax, prefixes folded), `debug.py` (`DebugSession`: breakpoints exact in delay slots, RAM and register watchpoints, S-CPU access and PLOT records), `trace.py` (JSONL), `console.py` (`CommandDebugger`), `harness.py` (the scripted S-CPU and krom's protocol), `replay.py` (MAME lockstep). Tests: `pytest` (the slow MAME replays: `pytest -m slow`; BYOR oracles skip when absent). ## What is fetched Nothing third-party is committed. `scripts/fetch_references.py` fills `reference/` from `scripts/pinned_files.json` (Book II's scan and its archive.org OCR, fullsnes, the SNESdev wiki stub; by SHA-256) and `scripts/pinned_repos.json` (ares and MAME 0.285's BSD-3 files at full commit SHAs, sparse; bsnes, Mesen2, snes9x and the sd2snes GSU are pinned but marked closed box and never fetched). A pin whose local copy (a path relative to this repository, such as a sibling `../snes-python`) is at the pinned hash or revision is satisfied in place: nothing is cloned or copied. **Bring your own**: the game dumps (read in place from the No-Intro set under `NO_INTRO_DIR`) and krom's test ROMs (read in snes-python's checkout, or `GSU_KROM`; pinned as `bring_your_own`, never fetched). Never commit a ROM, trace, save or screenshot. ## Scripts | Script | What | | --- | --- | | `fetch_references.py` | fetch, verify, or find in place the pinned documents and source trees | | `survey_games.py` | every GSU dump: header, chip family from MAME's PCB, slot, RAM size | | `mame_gsu_trace.py` | MAME 0.285's per-instruction GSU trace and the S-CPU's register/cache/RAM accesses (`--host-only`, `--ram`, `--all-banks`, `--arm-on-start`, `--krom`, `--dasm`, `--press`, `--snapshots`) | | `trace_coverage.py` | which instruction forms a trace executed, in which prefix state, from which banks | | `mesen_krom.py` | krom's 31 GSU tests on Mesen2 (the family's mesen2-runner, a GPL tool run as a separate program at `$EMU_TOOLS_GPL/tools/mesen2/run.py`), PASS/FAIL per row | They need `git`, `curl`, `7z`, MAME 0.285 at `/usr/games/mame` with `snes.zip` in a folder on `MAME_ROMPATH`, and for `mesen_krom.py` `EMU_TOOLS_GPL` (a checkout of emu-tools-gpl; exit status 3 without it) and a `MesenCore.so`: the tool's own build, or famicom-python's with `--lib` or `MESEN_CORE`. Run them with `python -I`, one at a time, under `nice -n 19` (the MAME script does that itself). No sudo. ## Documents [docs/README.md](docs/README.md) is the index. MIT licensed ([LICENSE](LICENSE)); the ares (ISC) and MAME (BSD-3-Clause) notices for what the documents and comments cite are in [NOTICE](NOTICE). Provenance: [docs/provenance.md](docs/provenance.md).