# The CPU: which 65C02, and how the board drives it ## Reuse: w65c02-python, no new core The family already has the CMOS 65C02 as a core, `../w65c02-python` (HEAD `fca677f`), with four rows (`W65C02S`, `R65C02`, `G65SC02`, `Lynx2Cell`), tier-1 captures behind `G65SC02` and `R65C02`, and a Rust transcription (`../w65c02-rust`, `9023b24`). The Supervision needs **no new CPU core**: it needs a row choice, the ASIC's wait and stall behaviour on the bus (done in the board's callbacks), and perhaps one new row if a hardware probe ever shows a mix nobody has listed. ## Which variant | Evidence | What it says | Tag | | --- | --- | --- | | KH "System Overview" | "65C02 CPU running at 4MHz" (no part number: the core is inside the glop-top ASIC) | DOC (tier 3) | | CC65 `supervision.inc` | "supervision 65c02s ; in cc65 up to 2.9.1 65c02 means 65sc02" | DOC (tier 3, a comment) | | MAME `-listxml svision` | "WDC W65C02" at 4,000,000 Hz: MAME's base CMOS device, **without** the bit instructions and without `WAI`/`STP` (w65c02-python mame-oracle.md) | OBSERVED (tier 5) | | Three games traced in MAME (mame-oracle.md) | CMOS-only opcodes executed and relied on: `BRA` (57,944 times in Alien), `PHX PLX PHY PLY`, `STZ` (four modes), `LDA (zp)`. **No** bit instruction (`$x7`, `$xF`), no `WAI` (`$CB`), no `STP` (`$DB`) | OBSERVED (games that work on hardware, run in a detector) | So: **a CMOS 65C02 for certain** (an NMOS part would take `$80` as a two-byte NOP and Alien's `BRA` would fall through). Whether the cell has the Rockwell bit instructions or `WAI`/`STP` is **U6**: no source says, and the traced games do not use them. **Recommendation (provisional, open decision 1):** the `G65SC02` row, the base CMOS instruction set without bit instructions, as MAME runs it and as cc65 targets it. It is the choice no known Supervision program can contradict, and it is the row with the strongest judge (a captured G65SC12). If a homebrew or a hardware probe ever shows `RMB`/`SMB`/`BBR`/ `BBS` working, the row changes to `R65C02` (bit instructions, and see w65c02-python C5 on `WAI`/`STP`); nothing else in the board depends on it. The cheapest probe, for Aubrey's probe queue (no hardware on hand, so queued only): a cartridge that executes `SMB0 $10` with `$10 = 0` and shows the result on the LCD (G65SC02: one-byte NOP, then `$10` executes as `BPL`; R65C02: `$10` becomes 1). Writable flash carts for the Supervision exist; none is in hand. ## Reset, vectors and the stack (DOC KH; CC65 `crt0.s`) The CPU fetches its vectors from FFFA-FFFF, i.e. from the last 16 KB of the cartridge (fixed at C000-FFFF). There is no boot ROM. Every NI image's vectors point into 8000-FFFF (census.md); 46 of 73 reset to C000, eight to a `FFF0`/`FFF2` stub like cc65's `reset32kcode` (which writes 2026 before anything else). One 32 KB image, Dancing Block, resets to 9890 and two (Penguin Hideout, Pyramid) have their NMI in 8000-BFFF: they rely on what the banked window holds at power-on, i.e. on 2026's reset value and on how a 32 KB ROM is wired (**U11**). A 32 KB ROM sees A0-A14 and ignores A15-A16, so the fixed window shows its second half and the banked window its first half whenever the bank number is even: Dancing Block works if 2026 resets to an even bank (0 is the natural guess: HYPOTHESIS). MAME's list stores these images as 32 KB, so the mirroring is the board's job. ## Bus timing the board owes the core w65c02-python makes exactly one callback per cycle and keeps no time; the board counts. What the ASIC does to the CPU's cycles: - **WRAM and the cartridge:** no wait states are described (KH lists none). **U7**: whether the cartridge ROM is slower. - **VRAM:** "0 wait states" for the CPU (KH "System Overview"). The CPU's access takes one of the LCD controller's six fetch slots; the LCD shows stale data only if the CPU takes all six in a row, which normal code cannot (KH "VRAM Timing"). Executing code from VRAM is KH's untested "fun test" (**U8**). - **Video DMA (200D):** copies 5 bytes every 6 clocks, the sixth slot being the LCD's; "on the idle cycle (every 6 clocks) the CPU is allowed to run for that cycle" (KH "DMA Timing"). The exact sentence leaves open whether the CPU runs one cycle in six during the DMA or is halted throughout (**U9**). The core's `note_stall()` hook (one held cycle per call, from inside the callback) is how the board charges it. - **Sample DMA:** one cycle per fetched byte (KH "Audio DMA Timing": "the DMA fetch only takes a single cycle"); whether it steals a CPU cycle is **U10**. - **Interrupts:** NMI and IRQ go to the core's request lines; the core samples them per its row (w65c02-python's poll). Throughput, observed in MAME (a model, not the hardware): 2.69, 3.03 and 3.35 cycles per instruction in the three games, i.e. **1.2 to 1.5 M instructions per emulated second**; the ceiling is 2.0 M (no 65C02 instruction is shorter than 2 cycles).