Metadata-Version: 2.5 Name: 65816-python Version: 0.1.0.dev0 Summary: Readable, pure-Python WDC 65C816 core, cycle by cycle, for the SNES and other 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 :: System :: Emulators Requires-Python: >=3.11 Requires-Dist: 6502-python @ git+https://github.com/alewman/6502-python@9dc34bd74ca86773fe5c1df8d2a16b87a2ad0c29 Provides-Extra: dev Requires-Dist: pytest>=8; extra == 'dev' Requires-Dist: ruff==0.16.8; extra == 'dev' Description-Content-Type: text/markdown # 65816-python A readable, pure-Python **WDC 65C816** CPU core: the 8/16-bit processor inside the SNES/Super Famicom's Ricoh **5A22** (S-CPU), the Apple IIGS, and WDC's W65C816S. This repository is only the CPU. The 5A22's on-chip extras (DMA and HDMA, the multiplier and divider, the H/V timers, joypad auto-read, the per-address memory speed) and everything else on the console belong to the board, [snes-python](../snes-python). **Status (2026-10-21): groundwork only, no core code.** The documents in [`docs/`](docs/README.md) gather what the build needs, every fact with its source and tier: registers, the E/M/X modes, 24-bit addressing, every addressing mode's bus cycles with VDA/VPA/VPB/MLB/RWB, interrupts, WAI, STP, MVN/MVP, decimal mode, the emulation-mode wrapping rules and the places the sources contradict each other, the oracles with measured results, a verified MAME recipe that boots commercial games with a free substitute sound boot ROM, and the brief for the session that builds the core ([docs/handoff-brief.md](docs/handoff-brief.md)). **Decided (2026-10-21, narrowed 2026-10-22):** the core builds on [6502-python](https://github.com/alewman/6502-python)'s frame: the bus callables, the interrupt requests and their poll, and `step()`'s skeleton, split out of `MOS6502` by one PR there. It stays its own repository, depends on a pinned 6502-python, has its own addressing modes and handlers, and never copies files. The core will follow the family's shape: host-owned memory passed in as callables, `step()` returning cycles, no dependencies beyond 6502-python, CPython and PyPy (Python 3.11+). Like 6502-python it makes **one bus callback per CPU cycle, in chip order**, and unlike it, internal cycles are callbacks too, each with its address and VDA/VPA kind, because the 5A22 times every cycle by what it is (6, 8 or 12 master clocks) and the board must decide that length cycle by cycle. ## What is fetched Nothing third-party is committed. `scripts/fetch_references.py` rebuilds `reference/` from `scripts/pinned_files.json` (15 files pinned by SHA-256: WDC's datasheets, fullsnes, five SNESdev wiki revisions, three 6502.org tutorials, gilyon's and undisbeliever's release ROMs, a GHDL tool bundle) and `scripts/pinned_repos.json` (10 repositories at full commit SHAs, sparse where large): SingleStepTests 65816 and the emulator that generated it, bsnes, ares, MAME 0.285's source, Mesen2, srg320's P65C816 VHDL with logic-analyser captures, and krom's, gilyon's and undisbeliever's test ROMs. ```sh python -I scripts/fetch_references.py # everything missing (~3.5 GB) python -I scripts/fetch_references.py --skip 65816 # without the 2.8 GB corpus python -I scripts/fetch_references.py --no-tools # without the 750 MB GHDL bundle python -I scripts/fetch_references.py --verify # check what is present python -I scripts/build_referees.py # GHDL analysis of P65C816, MAME IPL python -I scripts/datasheet_timing.py # WDC Table 5-7 vs SingleStepTests ``` They need `git`, `curl`, and `7z` for games kept as `.7z`. No sudo. ## Scripts | Script | What | | --- | --- | | `scripts/fetch_references.py` | the pinned references, test ROMs and tool bundle | | `scripts/build_referees.py` | unpacks GHDL and analyses srg320's P65C816 VHDL; writes the substitute S-SMP boot ROM for MAME | | `scripts/datasheet_timing.py` | WDC's Table 5-7 transcribed literally as per-cycle schedules, compared with every SingleStepTests case ([docs/timing.md](docs/timing.md)) | | `scripts/mame_trace.py` | MAME 0.285 per-instruction 5A22 trace of a SNES ROM, with a free substitute S-SMP boot ROM ([docs/mame-oracle.md](docs/mame-oracle.md)) | ## Licence MIT (see `LICENSE`), for what is in this repository. The fetched material keeps its own terms, recorded per entry in the pin lists.