# Start here: the CMOS 65C02 family What the part is, which makers' parts this core covers and how they differ, what the core owns and what it does not. Bus cycles are in [timing.md](timing.md); everything uncertain is numbered in [undocumented-behavior.md](undocumented-behavior.md) (U = unknown, C = sources contradict each other); every source's tier and pin is in [validation.md](validation.md). ## Sources, and how they are cited | Key | Source | Tier | | --- | --- | --- | | CAP | Logic-analyser captures of real chips (David Banks's `6502Decoder` test data): a BBC Master (GTE/CMD **G65SC12**) and a BBC B fitted with a **Rockwell R65C02**, each running a reset and boot, Dormann's 65C02 test and Bruce Clark's full decimal test. Data bus, RnW, SYNC, RDY, RST per cycle; **no address bus** | 1, hardware-captured | | DS | WDC W65C02S data sheet, 8 April 2022 (sections 3.x, Tables 5-2, 6-4, 7-1) | 2, manufacturer | | RDS | Rockwell R65C02/R65C102/R65C112 data sheet (scan; Table 4 "Operational Enhancements", p. 1-10) | 2 | | GDS | GTE/CMD G65SCXXX family data sheet (Tables II and V), and CMD G65SC02-A, March 2000 | 2 | | VDS | VLSI Technology VL65NC02 data sheet, 1988 ASIC data book, printed pp. 225-238 | 2 | | NDS | NCR65C02 data sheet, NCR 1985 data book, PDF pp. 430-439 | 2 | | LS | Epyx/Atari Lynx hardware specification, chapters 4, 8, 10, 11 | 2 (for the Lynx) | | LT | drhelius, "Lynx Hardware Tests" 1.4.9, `cpu` suite: expected values "made by analyzing actual hardware", on a Lynx I and a Lynx II | 3, hardware-derived expectations | | CL | Bruce Clark and Jeff Laughton, "65C02 Opcodes" (6502.org) | 3, research | | LK | Jeff Laughton, "KimKlone: Op-Code Mapping" (his bench observations) | 3, stated measurement | | GF | George Foot's bench notes on `WAI`/`STP`, 6502Decoder issue #10 | 3, stated measurement | | BC | Bruce Clark, "Decimal Mode" (6502.org), Appendix A | 3 | | GW | Garth Wilson, "NMOS-CMOS 6502 differences" and "Investigating Interrupts" | 3 | | SST | SingleStepTests 65x02: `wdc65c02`, `rockwell65c02`, `synertek65c02` | 5, emulator-generated | | MAME | MAME 0.285 `w65c02`, `r65c02`, `w65c02s`, `g65sc02` | 5 | ## The part The 65C02 is Western Design Center's CMOS redesign of the NMOS 6502 (1982), licensed to Rockwell, GTE (later California Micro Devices), NCR, Synertek and VLSI Technology. To software it is the 6502 with: - the 105 undefined NMOS opcodes replaced: 27 new documented opcodes on every part, and every remaining one a NOP of a fixed length and cycle count; - `BRA`, `PHX` `PHY` `PLX` `PLY`, `STZ`, `TSB` `TRB`, `INC A` `DEC A`, `BIT` immediate / `zp,X` / `abs,X`, the `(zp)` addressing mode for the eight accumulator instructions, and `JMP (abs,X)`; - on some parts `RMB0-7` `SMB0-7` `BBR0-7` `BBS0-7` (32 more opcodes), and on WDC's also `WAI` and `STP`; - the NMOS bugs fixed (DS Table 7-1, p. 30; the same table is in RDS, GDS, NDS): `JMP ($xxFF)` crosses the page (one more cycle); read-modify-write makes two reads and one write, not one read and two writes; decimal `ADC`/`SBC` give valid N, V and Z (one more cycle); D is cleared by reset and by every interrupt entry and `BRK`; an interrupt that arrives as `BRK` is fetched no longer swallows the `BRK`; an indexed access that crosses a page re-reads the last instruction byte instead of reading a wrong address; RDY stops the processor on write cycles too. Registers are the 6502's: A, X, Y, S (stack in page one), PC, and P = `N V 1 B D I Z C`. Bit 5 has no flip-flop and B exists only in the pushed byte, exactly as on the NMOS part; the core keeps bit 5 set and B clear in `p`, as `6502-python` does. ## The rows The differences between parts are **data**: one core (`w65c02_python.CMOS65C02`), one row of settings per part, each row a class of the same name as its column below; the Lynx II's cell is a fourth class, `Lynx2Cell` (see "The Lynx's cell"). Each cell names its best evidence. | | `W65C02S` | `R65C02` | `G65SC02` | | --- | --- | --- | --- | | Parts | WDC W65C02S (1990s on) | Rockwell R65C02, R65C102, R65C112; in instruction set, **the Lynx II's cell** (C12) | GTE/CMD G65SC02, G65SC12, G65SC102, G65SC112; NCR65C02; VLSI VL65NC02; **the Lynx I's cell** | | Documented opcodes | 212 (DS section 1.1) | 210 (RDS matrix) | 178 (GDS, VDS, NDS "178 operational codes") | | `x7`: `RMB`/`SMB` | yes, 5 cycles (DS Table 5-2) | yes (RDS Table 2; CAP: `RMB0` 5 cycles) | **one-byte, one-cycle NOP** (CAP on the G65SC12: `$07 $17` 1 cycle each; GDS Table V; VDS Table 2; NDS). SST disagrees (C2) | | `xF`: `BBR`/`BBS` | yes, 5 to 7 cycles | yes (CAP: 5 not taken, 6 taken) | **one-byte, one-cycle NOP** (CAP: `$0F $1F` 1 cycle; same tables). SST disagrees (C2) | | `$CB` | `WAI` | one-byte, one-cycle NOP (RDS has no `WAI`; CL section 9). Not captured (U3); SST and MAME disagree (C3, C5) | one-byte, one-cycle NOP (GDS/VDS/NDS "XB: 1 byte, 1 cycle"). Not captured (U3) | | `$DB` | `STP` | as `$CB` | as `$CB` | | Reset | seven cycles (DS 3.11); stack cycles read or write: **unknown** (U1) | seven cycles, three stack **reads** (CAP) | seven cycles, three stack **writes** of PCH, PCL, P (CAP on the G65SC12; GDS Table V "Writes program counter and status register to stack"). The data sheets say six cycles (C4) | | Other NOPs | `x2` 2 bytes 2 cycles; `x3`, `xB` 1 byte 1 cycle; `$44` 2/3; `$54 $D4 $F4` 2/4; `$5C` 3/8; `$DC $FC` 3/4 (DS Table 7-1) | the same (CAP: `$5C` 8 cycles) | the same (CAP: `$02` 2, `$03` 1, `$44` 3, `$54` 4, `$5C` 8, `$DC` 4) | Notes on the rows: - **WDC's own history** (GW): the W65C02S data sheet of August 1992 offered the part without the bit instructions (W65C02S) and with them (W65C02SB); by July 1996 all had them. An "old WDC 65C02" (the Apple IIc's and enhanced IIe's NCR/GTE/WDC parts of 1984-85) is the `G65SC02` row plus, on WDC's own early parts, possibly `WAI`/`STP`: not researched (U8). MAME's "WDC W65C02" device (Apple IIe) has neither bit instructions nor `WAI`/`STP`. - **Synertek.** No Synertek SY65C02 data sheet was found. SST's `synertek65c02` set gives `x7` and `xF` as two- and three-byte NOPs of 3 or 4 cycles; every manufacturer document for a part without bit instructions (GDS, VDS, NDS) and the capture of a real G65SC12 say one byte, one cycle (C2). The corpus's set is the nearest volume detector for the `G65SC02` row, with those 32 opcodes excluded and counted. - **The G65SC12** (BBC Master) is the G65SC02 with a different clock-pin arrangement (GDS p. 1 table); the captures of it stand for the row. ### The Lynx's cell LS chapter 4: "The CPU is a 65C02 cell imbedded in the Mikey IC. The specifics of its instruction set and register operations are found in the VTI specification." VTI is VLSI Technology Inc.; its 65C02 megacell is the VL65NC02 (VDS): 178 opcodes, 27 new, "All of the op codes in column 7 and column F are interpreted as a NOP in the 65NC02" (VDS printed p. 234), Table 2 giving `X2` 2/2, `X3 X7 XB XF` 1/1, `$44` 2/3, `$54 $D4 $F4` 2/4, `$5C` 3/8, `$DC $FC` 3/4, and a six-cycle reset (C4). That the cell in Mikey *is* the VL65NC02 megacell is an inference from "VTI specification" (U10): no die photograph, netlist or logic-analyser capture of a Mikey was found. **Two Lynx cells, not one** (reconciled with `lynx-python`'s Phase 0, whose sources were checked here): - **Lynx I: the `G65SC02` row.** LT `cpu` test 7 (`cpu/tests.s` lines 633-720, `main.c` lines 45-49 and the `k_lynx_i_results` table) executes `$07 $EA`, `$87 $EA`, `$0F $EA ` and expects, on a Lynx I, memory unchanged and no branch: the bit opcodes are NOPs, and one byte long (the `$EA` after each runs as its own instruction). That agrees with VDS, and with CAP's G65SC12. - **Lynx II: the bit instructions work.** The same test expects bit 0 cleared, bit 0 set and both branches taken on a Lynx II, and prints "LYNX 1" or "LYNX 2" from the difference. 42Bastian says the same in AtariAge thread 283383 ("The Lynx model 1 does not have BBR BBS RMB ... but Lynx Model 2 has it"; pinned by `lynx-python`). This contradicts VDS's note and MAME, which uses one `G65SC02` for both models (C12). Nothing found says what else the later cell changed: its reset (U2) and `$CB`/`$DB` are unknown. `WAI`/`STP` on either model: 42Bastian's post says the Lynx has neither; no test executes them (U3, C8). So the board needs two rows: Lynx I = `G65SC02`; Lynx II = the same settings with the bit instructions on, which is the `R65C02` row except for the reset default. The core ships that fourth row as the class **`Lynx2Cell`** (decided 2026-11-12, docs/handoff-brief.md, open decision 3): named for what it is, because no part number is known for the later cell. MAME instantiates "GTE G65SC02" for both. Emulators disagree about `$CB`/`$DB` (C8: Handy treats them as `WAI`/`STP`). LT's other `cpu` tests are evidence from real Lynxes for things no other source measures: `CLI` lets a pending IRQ in only after the next instruction (test 1), D is cleared on interrupt entry (2), decimal results and flags (3), `BRK` is two bytes (4), `JMP (abs)` is fixed (5), undefined opcodes are 1-, 2- and 3-byte NOPs (6), and **one-byte NOPs do not take a pending IRQ** (8). Other oddities of the cell itself: none documented. What is odd on the Lynx is around the cell, and is the board's (LS chapter 4): a CPU cycle lasts 4 system ticks for a "page mode" op-code read, 5 for any other RAM/ROM access and 5 to 128 for hardware; Mikey can take the bus from the CPU for video and refresh; the CPU "sleeps" by writing `CPUSLEEP` (`$FD91`), which is Mikey's bus-request flip-flop, not an instruction; the NMI pin reaches the cell through clocked delays. The start-up code clears decimal mode itself (LS chapter 10), which says nothing either way about reset. ## What the core owns, and does not The core owns: the instruction set of each row, every cycle as one bus callback in chip order, the interrupt inputs and their poll (through `6502-python`'s `CPUFrame`), reset, `WAI`/`STP` state, decimal arithmetic, and the tooling (state, trace, debugger, disassembler). The core does not own: memory, devices, how long a cycle lasts, RDY and bus arbitration (a host stretches or holds a cycle inside its callback and tells the core with `note_stall()`), the Lynx's `CPUSLEEP`, the output pins SYNC, VPB and MLB as signals (SYNC is offered as an attribute a callback may read, because the Lynx's page-mode timing needs it; see docs/handoff-brief.md), and the SOB input (U13). ## Modelling level, and the contract boards rely on **Modelling level: cycle** (the charter's axis B). Every bus cycle of the chip is modelled as one access, a read or a write, at its address, in the chip's order, dummy reads included; nothing below the cycle (phases, the address bus between accesses, pin timing within a cycle) and nothing above it (no instruction-level shortcut) is modelled. The evidence for each cycle is tagged in `src/` (MEASURED, DOC, TEST ROM, OBSERVED, HYPOTHESIS); timing.md lists every sequence. This is the level the transcription `w65c02-rust` must match cycle for cycle (address, value, direction). **The interface contract** (detail and history in docs/handoff-brief.md, "The bus contract" and "The contract as built"). A board that pins this core may rely on exactly this: - `Row(read_byte, write_byte)` for `Row` in `W65C02S`, `R65C02`, `G65SC02`, `Lynx2Cell` (or a board's own subclass of `CMOS65C02` with the row attributes set on the class). `read_byte(address) -> int` is called for every read cycle and `write_byte(address, value)` for every write cycle: one callback per cycle, no idle callback. The core keeps no time; the board advances its devices inside the callbacks. - `step()` runs one instruction, one interrupt entry, one reset, or one waiting cycle of `WAI`/`STP`, and returns the number of callbacks it made. - Inside a callback the board may read: - **`cpu.sync`**: True in an opcode fetch, and in the first cycle of an interrupt entry and of reset (the dropped opcode fetch); else False. - **`cpu.fetch`**: True in every read whose address is the program counter (opcode, operand bytes, a one-byte instruction's dropped read, a taken branch's reads of the next opcode, the decimal cycle, `RTS`'s last cycle, the two reads at PC of an entry or reset, each `WAI`/`STP` waiting cycle); False for data, stack and vector accesses, every write, and the cycles that re-read an instruction byte after PC has moved on. - **`cpu.opcode`**: the instruction in progress, from its second cycle on (the opcode fetch's own callback still sees the previous one; an entry or reset leaves it unchanged). - A callback may take as long as the board likes and may change interrupt requests (`request_maskable_interrupt()` / `clear_maskable_interrupt()`: a level; NMI: an edge; `request_reset()`; 6502-python's `CPUFrame` API). - **A held cycle**: a board that holds the CPU inside a callback (RDY, another chip taking the bus, the Lynx's Suzy drawing inside the `CPUSLEEP` write) calls **`cpu.note_stall()`** as the hold begins and after each held cycle, in a read **or a write** callback (RDY stops the CMOS part on writes too: DS Table 7-1 and 3.10). A request raised during the hold is then polled as at the end of the stretched access. For writes this is U12's default (HYPOTHESIS: the data sheet does not say in which cycle a stretched write samples the interrupt lines); it is held by `tests/test_directed.py`'s U12 test. - `capture_state()` / `restore_state()` with `CPUState`, at a step boundary. Not in the contract: any pin beyond SYNC (RDY, SOB, VPB, MLB, BE), the instance attributes the handlers use internally, and the class attributes of the U-entry defaults beyond their documented values. ## Reset and interrupts, in one place - **Reset**: seven cycles (CAP, both captured parts): two reads, three stack cycles (reads or writes by row) that leave S three lower, the vector at `$FFFC`/`$FFFD`. I is set and D cleared; nothing else is initialised (DS 3.11). Reset ends `WAI` and `STP`. - **IRQ, NMI**: seven cycles (CAP: 9,563 interrupts on the G65SC12 and 9,264 on the R65C02 in the Dormann captures, all seven cycles with writes in cycles 3 to 5): two reads, push PCH, PCL, P with B clear, vector `$FFFE`/`$FFFF` or `$FFFA`/`$FFFB`. I is set **and D cleared** after P is pushed. - **BRK**: the same seven cycles with B set in the pushed byte, the return address two past the opcode, D cleared. An NMI or IRQ that arrives during it does not take over its vector: "BRK is executed, and then interrupt is executed" (DS Table 7-1; GDS, RDS, NDS the same). - **The poll**: U5. Nothing found describes the CMOS part's poll points at the level NESdev and visual6502 describe the NMOS part's. The default is the frame's rule (requests as they stood at the end of the second-to-last cycle; `CLI`, `SEI`, `PLP` act one instruction late) with no NMOS branch exception, and one addition: a **one-cycle NOP does not poll** (CL section 9; LT `cpu` test 8 on real Lynxes; U7). - **`WAI`** (W65C02S row): three cycles, then the processor holds with RDY pulled low until IRQ, NMI or reset. An IRQ ends the wait even with I set, and execution then continues with the next instruction without vectoring (DS 3.4, 3.10; GW). If IRQ is already asserted, `WAI` is a three-cycle instruction (GF). While waiting the bus shows the next opcode's address (GF: "the next opcode repeated"). Wake timing: U6. - **`STP`** (W65C02S row): three cycles, then stopped until reset; the bus shows the next opcode's address (GF).