Metadata-Version: 2.5 Name: gsu-python Version: 0.1.0.dev0 Summary: Readable, pure-Python Super FX (Mario Chip 1, GSU-1, GSU-2) core for SNES boards Author: alewman License: MIT License Copyright (c) 2026 alewman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License-File: LICENSE Classifier: Development Status :: 2 - Pre-Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: System :: Emulators Requires-Python: >=3.11 Provides-Extra: dev Requires-Dist: pytest>=8; extra == 'dev' Requires-Dist: ruff==0.16.8; extra == 'dev' Description-Content-Type: text/markdown # 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`, `STOP_CLEARS_POR`, `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` (bsnes, ares, MAME 0.285, Mesen2, snes9x and the sd2snes FPGA GSU at full commit SHAs, sparse). A pin whose local copy elsewhere on this machine is at the pinned hash or revision is satisfied in place (snes-python's trees and fullsnes): nothing is cloned or copied. **Bring your own**: the game dumps (read in place from the No-Intro set) and krom's test ROMs (read in snes-python's checkout; 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 (through snes-python's `mesen_run.py`), PASS/FAIL per row | They need `git`, `curl`, `7z`, MAME 0.285 at `/usr/games/mame` with `snes.zip` on its rompath, and for `mesen_krom.py` famicom-python's `MesenCore.so`. 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)).