# Changelog All notable changes to `6502-python` are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -- 0.2.0 The family release: the core rebuilt in the shape of z80-python 0.4.0, the family's reference core, and made correct to the bus cycle. ### Breaking - **`MOS6502(read_byte, write_byte)` replaces `CPU(memory, lines=, state=)`.** The bus is two callables, the embedding contract z80-python and m6800-python share; `MemoryBus`, `InterruptLines`, `InterruptBoundary`, the `Register8`/`StatusFlags` wrappers and the `*Step` result objects are gone. Migration: `CPU(bus)` becomes `MOS6502(bus.read_byte, bus.write_byte)` (passing the old object raises a `TypeError` that says so); `cpu.state.a.value` becomes `cpu.a`, and likewise `x`, `y`, `s` (was `sp`), `pc`, `p` (P as one int, bit 5 set, B clear); `step()` returns the cycle count instead of a step object, and the host keeps its own cycle total. - **Interrupt inputs take z80-python's names.** `request_reset()`, `request_maskable_interrupt()` / `clear_maskable_interrupt()` (IRQ, a level), `request_non_maskable_interrupt()` (an edge latch). Migration: `set_irq(True/False)` becomes the request/clear pair; `set_nmi(True)` on a rising edge, or `signal_nmi()`, becomes `request_non_maskable_interrupt()`; `set_reset(True)` followed by a step becomes `request_reset()`. - **The package lives in `src/`.** An editable install must be redone (`pip install -e .`). ### Changed - **Every bus cycle is made, in the chip's order.** Dummy reads of indexed and implied modes, the read-modify-write dummy write, the stack reads of JSR, RTS, RTI, PLA and PLP, the taken-branch reads, and the reset sequence's three stack reads now reach the host's bus, so memory-mapped devices see what they would on a board. `step()` calls the bus exactly once per cycle it returns. - **The SingleStepTests host compares the whole `cycles` array**, address, value and direction per cycle, where it compared only its length: 2,560,000 of 2,560,000 cases agree (emulator-derived tier). The quick loop (`pytest -m "not slow"`, ~10 s) runs 100 cases per opcode; `-m slow` runs all of them and both Dormann exercisers. - **10-16x faster on CPython, 44-97x on PyPy**, measured in one process against the old core: CPython 3.14 base workload 0.137 -> 2.24 M instr/s, PyPy 3.11 0.465 -> 44.9 M instr/s; the full table is in docs/validation.md, "Speed". The 1,421-line if-chain became one 256-entry table routing to handler methods by instruction family, P became one int, and N and Z come from a 256-entry table. - **Every claim names its oracle's tier** (docs/validation.md): Dormann's programs are self-checking, SingleStepTests is emulator-derived, the manuals are documentation; nothing is hardware-captured, and the claims say so. - The test suite is rebuilt around the new API: one shared host (`tests/conftest.py`), the corpus and exerciser gates, and tests for interrupts, state, disassembly, the debugger, traces, the console, the command line and the public API. The five `test_phase_*_regressions` files and the other old-API unit tests are gone; the CPU behaviour they covered is covered by SingleStepTests or by `tests/test_interrupts.py`, and the API they tested no longer exists. - ruff is pinned (0.16.8, z80-python's), line length 100, z80-python's rule set, and CI checks formatting. ### Added - **`CPUFrame`, the frame other 65xx-family cores subclass.** The bus callables, the interrupt requests and their poll, `step()`'s skeleton and the state's poll fields and `note_stall()` move out of `MOS6502` into `sixfiveohtwo.frame.CPUFrame`, with hooks for reset, a halted CPU, an interrupt entry and one instruction; `MOS6502` is the frame plus the NMOS instruction set. Its subclassing surface is semver-covered (docs/api-stability.md) and held by `tests/test_frame.py`, a toy CPU with no NMOS code. NMOS behaviour is unchanged: SingleStepTests `6502` and `nes6502` (2,560,000 cases each) and Dormann pass as before. First user: `65816-python`. - **`RP2A03`, the NES and Famicom CPU**: `MOS6502` with the decimal adjust disconnected, as on the die (the Breaks wiki). D is still a flag; ADC, SBC, USBC, RRA, ISC and ARR compute in binary whatever it says. Certified against SingleStepTests' "nes6502" set, which `fetch_test_vectors.py` now fetches beside "6502" from the same pinned revision. The decimal adjust is one class attribute, `_decimal_mode`, which the arithmetic handlers pass to `add`/`subtract`; no handler is duplicated. - **`ane_constant` and `lxa_constant`, per CPU.** ANE and LXA's magic constant varies between chips (NMS pp. 60-64), so it is now an attribute a host sets on its CPU instead of a module constant; both default to $EE, SingleStepTests' value. famicom-python found the need: blargg's `instr_test-v5` `03-immediate`, whose CRCs were taken on an NES, passes only with LXA's constant at $FF. - **`dma_stalled`, the host's word that a DMA stretched a read.** SHA, SHX, SHY and TAS then store their value without the AND (H + 1), the page-crossed address keeping it (NMS p. 48). The core has no RDY input; a board running DMA inside its read callback sets it on that read and clears it on the next. famicom-python found the need: AccuracyCoin's unofficial opcode tests (error code 7) check it against hardware. - **`note_stall()`: interrupts raised during a stalled read are polled.** A host whose read callback runs a DMA calls it as the stall begins and after each halted cycle: a request raised during the stall counts as raised before the read, whichever cycle was stalled, the last one and a taken branch's included, except that a taken branch's next-opcode read ignores one raised in the stall's last cycle (AccuracyCoin "Interrupt flag latency" test A). perfect6502 with RDY held low shows it (an NMI falling during a 4-cycle halt of a JMP's last cycle, or of a taken branch's operand or next-opcode read, is taken at the next boundary). famicom-python found it in lockstep with Mesen2: Kirby's Adventure, VBL's NMI during a DMC DMA inside a `BEQ`. - **Interrupts polled at the end of the second-to-last cycle, as the chip does**: a request a bus callback makes in an instruction's last cycle waits for the next instruction's poll; an IRQ the poll saw is taken though released in the last cycle; BRK, interrupt entries and reset do not poll; the NMI hijack of BRK or an IRQ is decided after cycle 4, not 5; a taken branch polls at the end of cycle 1, and across a page also at the end of cycle 3, not at the end of cycle 2. A request made between steps is still taken at the next boundary. `CPUState` (and trace schema 1) gains `polled_maskable_interrupt`, `polled_non_maskable_interrupt` and `skipped_poll`. The core watches the bus only after a mid-step request, so the cost is two checks a step (CPython about x0.92, PyPy about x0.97). - **Interrupt timing the chip has and the old core did not**: CLI, SEI and PLP delay a waiting IRQ by one instruction; RTI's restored I counts at once; an NMI arriving during BRK or an IRQ entry takes it over; IRQ is a level and stays asserted after it is taken. `CPUState.polled_i` carries the delay across capture and restore. - **Tooling at z80-python's level**: `CPUState` with `capture_state()` / `restore_state()`; a structured disassembler built from the core's own opcode table; `DebugSession` with breakpoints, bounded runs, history, bus-access tracking and watchpoints; trace schema version 1 with `write_trace`, `read_trace` and lazy divergence search; `CommandDebugger`; `python -m sixfiveohtwo` for stepping a binary. `py.typed`. - **Every handler cites its source**: its page of MOS's programming manual (Appendix B) or of *No More Secrets* v0.99, and the addressing modes their hardware-manual (Appendix A) and NMS pages. `tests/test_readability.py` checks each page against the documents' own layout; `scripts/fetch_reference_docs.py` fetches all three with SHA-256 pins. - **The Dormann decimal exerciser runs**, assembled with cc65 (locally from source; in CI from Ubuntu's package). It had never run: the old suite skipped it without cc65. Both exercisers were checked to fail on a deliberately broken core. - `benchmarks/core_benchmark.py` (four workloads) and `benchmarks/compare_revisions.py`, the same-process A/B. - CI runs both Dormann exercisers on every push and builds the wheel with an installed-package smoke test; `oracles.yml` runs the full SingleStepTests corpus weekly and on demand. - docs: start-here, validation (tiers, results, pins, divergences, limits, speed), CPU state, disassembly, debug sessions, trace schema, undocumented behaviour, API stability. ### Fixed - The README and SECURITY.md said the package was on PyPI; it is not. The install instructions are from a checkout until it is published. - The repository description claimed the Dormann decimal test as a passed oracle while it was always skipped; it now runs and passes. - The README said the core followed z80-python's shape and contract; it did not, and now does. ### Not done in this release - z80-python's conformance kit (manifests, a reference-trace command line) exists for its Rust port; no 6502 port exists, so it is not ported. Traces and `first_trace_divergence` are, which is what a port would diff with. - No publish workflow: nothing is published yet. Add z80-python's `publish.yml` when the package goes to PyPI, and put the install line back in the README then. - The import name stays `sixfiveohtwo` rather than the family's `_python` pattern; renaming it is a decision for its own release. ## [0.1.0] -- never tagged or published The pure-Python NMOS 6502 core as it stood at `e7a9b09` (2026-09-21): all 256 opcodes, validated against the SingleStepTests 65x02 corpus (cycle counts, not bus cycles) and Dormann's functional exerciser.