# The 6510 (and the 8500) **Proposal: the 6510 is a variant in [6502-python](../../6502-python), not a new core repository.** It is the NMOS 6502 with an on-chip I/O port and two bus-control inputs; its instruction set, its undocumented opcodes and its bus cycles are the 6502's (DOC: 6510DS p. 1, "the internal processor architecture is identical to the MOS Technology 6502"; PRG appendix L, p. 402). 6502-python already carries a variant the same way (`RP2A03`, the NES CPU) and since its CPUFrame split (`f787293`, on `origin/main` at `828b619` through PR #9) is shaped for subclasses. The C64C's 8500 is the HMOS version of the same part (VIC 2.3 for the parallel VIC change; VICE CPU/cpuport readme names "6510/8500"); one class with a row-level setting covers both until a difference is found. ## What 6502-python already gives the board From its README and docs at the checked-out `81e0eb6` (branch `dma-stall`) and `origin/main` `828b619` (read, not modified): - all 256 opcodes, the 105 undocumented ones as groepaz's *No More Secrets* (NMS) v0.99 describes them; NMS is literally "NMOS **6510** Unintended Opcodes", written from tests on C64s, so the C64 is the machine its undocumented behaviour was measured on; - every bus cycle in the chip's order, dummy reads and RMW double writes included; passes Dormann, Bruce Clark's decimal test and SingleStepTests 6502 (2,560,000 of 2,560,000 cases) (its README, "Validation"); - `ane_constant` / `lxa_constant` (default $EE) for the chip-dependent magic constant of ANE ($8B) and LXA ($AB); - `dma_stalled`: the host's word that a DMA stretched the read before an SHA/SHX/SHY/TAS write, which drops the AND with (H+1) (NMS p. 48). On the C64 this is exactly the case of a bad line or sprite fetch landing in the cycle before the store; - `note_stall()`: a host that holds a read inside its callback (RDY low) calls it as the stall begins and after each halted cycle, so interrupts raised during the stall are polled as perfect6502 shows (its docs/start-here.md). ## What the 6510 adds 1. **The I/O port at $0000 (DDR) and $0001 (data).** DOC: 6510DS p. 1 ("Output Register at Address 0001 and the Data-Direction Register at Address 0000"); VIC 2.2. **PRG appendix L p. 402 prints the two addresses the other way round** (C1 in the handoff brief; the data sheet and every C64 program agree with the data sheet). 2. **The port is internal, but the bus cycle still happens.** VIC section 4 (tier 3): on a write to $00/$01 the 6510's data drivers stay tri-stated while R/W goes low, so the RAM underneath receives whatever the VIC read in the first half of that cycle. A read of $00/$01 returns the port. The core must therefore still call the board's bus on these cycles and tell it the access was internal (proposed: the variant calls `write_byte(0 or 1, value)` as usual and the board, which knows the floating-bus byte, decides what RAM gets; the variant answers reads from the port itself after the board has seen the cycle). 3. **Six pins, eight bits.** The package has P0-P5. The VICE CPU/cpuport readme (tier 3 at best: "partially guesswork based on observed behavior") says all eight bits of DDR and data are implemented; bits 6-7 have no pin, so a bit switched from output to input reads back the last driven value until it "fades" to 0. It gives the fade as "some hundred microseconds" in one paragraph and "~200000us (gpz, new C64)" in the next (C2). The fade time is a row constant (FITTED), with the cpuport test programs (`bitfade`, `delaytime`, `test1`, `initvalue`) as the judges. 4. **Port wiring on the C64** (DOC: PRG ch. 5 memory map and appendix L; VIC 2.4.1; PLA): P0 LORAM, P1 HIRAM, P2 CHAREN to the PLA; P3 cassette write; P4 cassette switch sense (input); P5 cassette motor (output, through a transistor). The reset value of the DDR is 0 (all inputs) so the PLA sees pulled-up lines and maps the ROMs in; the KERNAL's I/O initialisation then stores $E7 to $01 and $2F to $00 (OBSERVED in the MAME trace: `LDA #$E7` at $FDD7, store at $FDD9; `LDA #$2F` at $FDDB, store at $FDDD; about 125 cycles after reset). 5. **RDY and AEC.** RDY low during a read stops the CPU with the address held; it is ignored during writes; the VIC drives it from BA. AEC tri-states the CPU's address bus while the VIC owns phase 2. BA falls three cycles before the VIC's first stolen phase 2, because the 6510 never makes more than three writes in a row (BRK and the interrupt sequences push three bytes) (DOC: VIC 2.2, 2.3, 2.4.3). The board models this inside its read callback: if BA is low on a read cycle, the board advances the machine cycle by cycle, calling `note_stall()`, until BA is high, then completes the read. Writes in the three-cycle window proceed. No core change is needed for that. 6. **Interrupts during RDY.** VIC 2.2 says "interrupts are only recognized if the RDY line is high"; 6502-python's perfect6502 runs show the detectors keep sampling while RDY holds a read (C3). The perfect6502 netlist is the NMOS 6502's (DIE), the 6510's die has not been simulated, and the VICE `interrupts/irqdma` tests (whose readme mentions real-hardware results: a keyword hit, to read) are the judge to settle it for the C64. ## Undocumented opcodes on the C64 C64 software uses them heavily: demos and games use LAX, SAX, DCP, ISC, SLO, RLA, SRE, RRA, ANC, ALR, ARR, SBX and the NOP forms; copy protections and some loaders use the unstable ones. The core already implements all of them; what the board adds: - **ANE / LXA magic constant**: NMS reports it differs by chip and temperature; the row sets `ane_constant` / `lxa_constant` (proposal: keep 6502-python's default $EE, since NMS's C64 measurements are its source; VICE `CPU/ane`, `CPU/ane-lax`, `CPU/lax` tests judge it). - **SHA/SHX/SHY/TAS under DMA**: the board sets `dma_stalled` when BA stretched the read before the store (VICE `CPU/sha`, `CPU/shs`, `CPU/shxy`, whose readmes mention real hardware: to read per test). - **JAM**: the CPU stops; on the C64 the VIC keeps running. 6502-python models JAM. ## Judges | Tier | Judge | Decides | | --- | --- | --- | | 3 | the Lorenz suite 2.15 (VICE `general/Lorenz-2.15`, "Public Domain, no Copyright"; written to pass on a real C64) | every opcode incl. undocumented, flags, cycle counts, CPU port, IRQ/NMI timing on the C64 board | | 3 | VICE `CPU/*` tests with hardware notes (64doc, ane, lax, sha, shs, shxy, cpuport, cpujam) | the 6510's chip-dependent corners | | 2 | the 6510 data sheet (6510DS), PRG appendix L | pins, port addresses, timing diagrams | | 1-2 (inherited) | 6502-python's own ladder (perfect6502 netlist runs, SingleStepTests, Dormann) | the 6502 core | | 5 | MAME 0.285 `:u7` trace ([mame-oracle.md](mame-oracle.md)) | detector only | No die-level model of the 6510's port exists that this Phase 0 found (visual6502 and perfect6502 simulate the 6502). ## The upstream request (a fix starts upstream) To raise on 6502-python, with a repro each: 1. `MOS6510(MOS6502)`: the port registers at $00/$01 as described in 1-3 above, an input-pins callable or attribute the host sets (P0-P5 levels from outside), an output-pins value the host reads (to drive the PLA and the datasette), the fade of bits 6-7 as a setting, and the bus still called on every cycle. 2. Nothing for RDY: `note_stall()` and `dma_stalled` already cover the board's needs. C3 decides whether `note_stall()`'s sampling matches the 6510.