Metadata-Version: 2.5 Name: w65c02-python Version: 0.1.0.dev0 Summary: Readable, pure-Python CMOS 65C02 core (WDC W65C02S, Rockwell R65C02, GTE G65SC02, the Atari Lynx cells), correct to the bus cycle 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@741419a33d1de400a63f7c24c7916bb600694ca2 Provides-Extra: dev Requires-Dist: pytest>=8; extra == 'dev' Requires-Dist: ruff==0.16.8; extra == 'dev' Description-Content-Type: text/markdown # w65c02-python A readable, pure-Python core for the CMOS 65C02 family, correct to the bus cycle, in the shape of the family's other CPU cores (`6502-python`, `65816-python`, `huc6280-python`). It is built on `6502-python`'s `CPUFrame` (bus callables, interrupt requests, the poll, `step()`), with its own instruction handlers and the family's tooling by subclassing. The first consumer is the Atari Lynx board (`lynx-python`), whose Mikey chip holds a 65C02 cell. Later consumers could be Apple IIe/IIc-class machines, the BBC Master and arcade boards. ```python from w65c02_python import G65SC02 # or W65C02S, R65C02, Lynx2Cell memory = bytearray(0x10000) cpu = G65SC02(memory.__getitem__, memory.__setitem__) cpu.request_reset() cycles = cpu.step() # one instruction, entry or reset; == callbacks made ``` Every cycle is exactly one callback, a read or a write, in the chip's order, dummy reads included. The core keeps no time. Inside a callback the host can read `cpu.sync` (the opcode fetch), `cpu.fetch` (a read of the instruction stream at PC) and `cpu.opcode`. `docs/handoff-brief.md`, "The bus contract", is the whole interface. ## The parts, as data rows One instruction core (`CMOS65C02`), one class per part; a row is class attributes, so a board can make its own (docs/start-here.md has the evidence for every cell): | Class | Part | Bit instructions (`RMB` `SMB` `BBR` `BBS`) | `WAI` / `STP` | Reset's three stack cycles | | --- | --- | --- | --- | --- | | `W65C02S` | WDC W65C02S | yes | yes | reads (unknown: U1) | | `R65C02` | Rockwell R65C02 | yes | no | reads (captured) | | `G65SC02` | GTE/CMD G65SC02 and G65SC12; NCR65C02; VLSI VL65NC02; **the Lynx I's cell** | no: one-byte, one-cycle NOPs (captured) | no | writes (captured) | | `Lynx2Cell` | **the Lynx II's cell**: no part number is known | yes (a hardware test ROM says so: C12) | no | writes (assumed: U2) | ## What is claimed, and on what `docs/validation.md` has every judge, its tier and the measured counts; `docs/undocumented-behavior.md` every unknown (U1 to U13) and every place where sources contradict each other (C1 to C19). - **Tier 1, real chips.** Logic-analyser captures of a G65SC12 and a Rockwell R65C02 replay through the `G65SC02` and `R65C02` rows in lockstep: 168 million instructions, 65,772 interrupt entries and two resets, with every cycle's direction, SYNC, written byte and read byte agreeing. That fixes the cycle counts, the read/write shapes and, through the data each read returns, almost every dummy-read address. - **The `W65C02S` row has no tier-1 judge of its own** beyond a data-bus-only capture of a part with bit instructions (1.5 million instructions, agreeing, unable to tell it from the R65C02). Its `WAI` and `STP` rest on WDC's data sheet and bench notes (tiers 2 and 3). **The `Lynx2Cell` row has none**: it is the `G65SC02` row plus the bit instructions of the `R65C02` row, and the Lynx board's own test ROM (rung 9, with `lynx-python`) is its judge. - **Tier 5, a detector.** SingleStepTests' three CMOS sets: all 7,660,000 cases run, none fails; 1,882,157 of them are counted under ten named contradictions, in each of which a higher tier decides against the corpus. MAME 0.285: 5.09 million instructions on four machines with no register or written byte differing. - **Not claimed.** When the real chips poll for interrupts (U5: the frame's NMOS rule, with one-cycle NOPs not polling; what real hardware evidence there is agrees), `WAI`'s wake timing (U6), anything about RDY beyond `note_stall()`, the SOB, VPB, MLB and BE pins. ## What is here - `src/w65c02_python/`: `cpu.py` (the classes and their rows), `_core.py` (registers, fetch helpers, addressing modes cycle by cycle), `_dispatch.py` (the opcode table and the rows' replacements), `_alu.py`, `_loads.py`, `_shifts.py`, `_bits.py`, `_control.py`, `_nops.py` (one mnemonic per handler, its source cited in the docstring), and the tooling: `state.py`, `disasm.py`, `debug.py`, `trace.py`, `console.py`, `harness.py`, `python -m w65c02_python`. - `docs/`: `start-here.md` (the part, the rows), `timing.md` (every cycle as a bus access), `undocumented-behavior.md`, `validation.md` (oracles, rungs, what was measured), `mame-oracle.md`, `handoff-brief.md` (the bus contract and what the Lynx board can pin), `build-progress.md` (state and traps for whoever continues). - `tests/`: one file per rung, and the judges' harnesses (`single_step.py`, `capture_replay.py`, `mame_replay.py`, `programs.py`, `datasheet.py`). - `scripts/`: `fetch_references.py` and `build_tools.py` (every outside source by URL + SHA-256 or repository + commit, into the gitignored `reference/`, about 2 GB), and the whole-corpus runners: `run_single_step.py`, `run_programs.py`, `run_capture.py`, `run_mame_replay.py`, `seeded_faults.py`. ## Working on it python3 -m venv .venv && .venv/bin/pip install -e ".[dev]" pypy3.11 -m venv .venv-pypy && .venv-pypy/bin/pip install -e ".[dev]" .venv/bin/python -m pytest -m "not slow" # the quick loop .venv/bin/ruff check . && .venv/bin/ruff format --check . CPython and PyPy, Python 3.11 and later. Run anything that reads `reference/` with `python -I`. Tests that need a corpus, a capture or a trace skip with a hint when it is not there. ## Licence MIT (see `LICENSE`). Nothing fetched into `reference/` is committed; GPL programs there are run as external programs and never copied from.