pico6502 Technical Guide
Overview
The pico6502 technical architecture is identical to the picoZ80 in all respects except the CPU bus interface. The same RP2350B dual-core processor, PSRAM memory model, Flash layout, ESP32 co-processor, and driver framework are shared between the two products. This guide focuses on the differences specific to the 6502 and refers to the picoZ80 Technical Guide for topics that are fully shared.
Hardware Architecture
Block Diagram
┌─────────────────────────────────────────────────────────────────────────┐ │ pico6502 Board (v2.3a) │ │ │ │ ┌───────────────┐ PIO 0: A0–A15, D0–D7 ┌───────────────────┐ │ │ │ │◄──────────────────────────►│ DIP-40 Interface │ │ │ │ RP2350B │ PIO 1: cycle/ctrl/irq │ (6502 socket) │ │ │ │ (300 MHz) │◄──────────────────────────►│ A0–A15, D0–D7 │ │ │ │ │ PIO 2: PHI1/PHI2 clock ──►│ PHI0/RNW/SYNC │ │ │ │ Core 0 │ │ IRQ/NMI/RDY/SO │ │ │ │ (USB/IO/ESP) │ └───────────────────┘ │ │ │ │◄──QSPI──►[ 8MB PSRAM ] │ │ │ Core 1 │◄──SPI───►[ 16MB Flash ] │ │ │ (6502 loop) │ │ │ │ │◄──FSPI──►┌───────────┐ │ │ │ │◄──UART──►│ ESP32 │◄──SPI──►[ SD Card ] │ │ └───────────────┘ │ (WiFi) │──────────[ Web Server ] │ │ └───────────┘ │ │ [ USB Hub ]──USB──►[ RP2350 USB Bridge ] │ └─────────────────────────────────────────────────────────────────────────┘
Key Components
| Component | Part | Specification |
|---|---|---|
| Main processor | RP2350B | Dual Cortex-M33, up to 300 MHz, 512KB SRAM, 48 GPIO |
| PSRAM | SPI PSRAM | 8MB, QSPI interface, up to 133 MHz |
| Flash | SPI NOR Flash | 16MB, XIP (execute-in-place) |
| Co-processor | ESP32-S3 | WiFi, SD card, web server, 460.8kbaud UART to RP2350 |
| SD card | FAT32 | ROM images, disk images, config.json, web files |
| Bus interface | 74AHCT244 / 74AHCT245 | Buffered interface (v2.3): 74AHCT244s drive address/control out, a 74AHCT245 handles the data bus, with 5V-tolerant thresholds for clean level translation |
| Power supply | TLV62569DBVR | Synchronous buck, 5V (VCC pin) → 3.3V, all board power |
| USB | On-board hub | RP2350 USB mass-storage bridge for firmware flashing |
GPIO Assignment
The GPIO assignments below are those of the v2.3 buffered interface, taken from
src/M6502.pio — the firmware's pin definitions are the working reference, with the KiCad schematic (kicad/PICO6502/) as the hardware source. Note the separate outward and return clock paths (CLK1/CLK2 driven out; CLK1_IN/CLK2_IN read back from the socket side of the buffers) — see the Buffered Bus Interface section below for why.
| GPIO | Signal | Direction | Notes |
|---|---|---|---|
| 0–15 | A0–A15 | Output | 6502 address bus |
| 16–23 | D0–D7 | Bidir | 6502 data bus, via the 74AHCT245 |
| 24 | R/~W | Output | Read/Not-Write — the 6502’s single read/write line (no separate /RD and /WR) |
| 25 | SYNC | Output | Opcode-fetch indicator |
| 26 | CLK1_IN | Input | PHI1 as present at the socket (return path) |
| 27 | /OE_CLK | Output | Clock buffer output enable |
| 28 | DBE | Input | Data Bus Enable from the host socket (pulled high by R26) |
| 29 | CLK2_IN | Input | PHI2 as present at the socket — all bus state machines sync on this |
| 30 | /SO | Input | Set Overflow |
| 31 | CLK1 | Output | PHI1 outward drive |
| 32 | CLK2 | Output | PHI2 outward drive |
| 33 | /IRQ | Input | Maskable interrupt (active low) |
| 34 | RDY | Input | Ready — wait-state stretching |
| 35 | CLK0 | Input | PHI0 reference clock from the host (6502 mode) |
| 36 | /NMI | Input | Non-maskable interrupt (active low) |
| 38 | /RES | Bidir | System reset (active low) |
DBE_OVR — the firmware-driven override companion to DBE — deliberately does not live on the RP2350 at all: it is on ESP32 GPIO38, saving a scarce RP2350 GPIO. It is set from the dbeoverride configuration key via the ESP32 (see the Configuration Reference).
Buffered Bus Interface (v2.3)
The v2.3 board replaces the earlier passive interface with a fully buffered one — the change that motivated the revision, since the v2.2 board got precisely the bus and clock timing wrong that buffering fixes. v2.3a is the board on which every hardware result in this guide was obtained. The buffer complement:
- 74AHCT244s drive the address and control lines out to the host socket.
- A 74AHCT245 handles the bidirectional data bus.
- The clocks have separate outward and return paths: the firmware drives
CLK1/CLK2(GPIO 31/32) into the buffers, and readsCLK1_IN/CLK2_IN(GPIO 26/29) back from the socket side. Comparing the driven phase against the returned phase tells a dead buffer apart from a dead clock — exactly the distinction the v2.2 board could not make, and the reason the debug shell'sbusdiag clkcommand exists.
All bus state machines synchronise on
CLK2_IN — the phase actually present at the socket in both clocking modes — so a single PIO program serves the 6502 and the 6512 alike, with no mode-dependent variant.
Buffer tri-state follows the socket's DBE (Data Bus Enable) pin, gated by U13A: ~EN = NOR(DBE, DBE_OVR). R26 pulls DBE high, so a plain 6502 host that leaves pin 36 unconnected needs nothing — the buffers enable by default. A host that actively drives DBE gets authentic tri-state behaviour, and the firmware can force the matter through DBE_OVR (ESP32 GPIO38) when the configuration requires it.
Firmware Architecture
Flash Memory Layout
Identical to the picoZ80 layout:
| Partition | Address Range | Size | Contents |
|---|---|---|---|
| Bootloader | 0x10000000–0x1001FFFF |
128KB | USB bridge, firmware update, partition selector |
| App Slot 1 | 0x10020000–0x1051FFFF |
5MB | Main 6502 firmware (partition 1) |
| App Slot 2 | 0x10520000–0x10A1FFFF |
5MB | Main 6502 firmware (partition 2) |
| App Config 1 | 0x10A20000–0x10C9FFFF |
2.5MB | ROM images + minified config JSON (slot 1) |
| App Config 2 | 0x10CA0000–0x10F1FFFF |
2.5MB | ROM images + minified config JSON (slot 2) |
| General Config | 0x10F20000–0x10FFEFFF |
892KB | Core settings, scratch space |
| Partition Table | 0x10FFF000–0x11000000 |
4KB | Active slot, checksums, metadata |
The 6502 firmware now uses the flash configuration store exactly as the Z80 models do (
M6502CPU_configFromFlash mirrors Z80CPU_configFromJSON). The ESP32's CFG<n> command reads config.json from the card, minifies it, stores the blob together with the parsed machine definition and the core clock/voltage into the partition's App Config region, points the partition table at the app and reboots; the next boot reads everything from flash with no ESP32 dependency, which is what persists a non-default cpufreq/voltage. Early boot applies the stored clock before PSRAM initialisation; a boot that hangs on the watchdog restarts in a 150 MHz safe mode. The BBC-B driver's "persist": "flash" option carves a non-volatile region per partition from the tail of the General Config area, just below the partition table: one meta sector (magic, valid mask, 64-byte CMOS image) plus 16 × 16K sideways-RAM slots — 65 sectors, ~260KB per partition. Core 0 writes it on a MSG_WRITE_NVRAM inter-core message while holding Core 1 in a RAM-resident spin, since flash_range_* stalls XIP.
Dual-Core Design
| Core | Responsibilities |
|---|---|
| Core 0 | USB mass-storage bridge; firmware partition management; file I/O relay to ESP32; ESP32 UART command dispatch; inter-core queue service |
| Core 1 | 6502 bus emulation hot loop — services PIO FIFOs for every bus cycle, resolves addresses against the memory map, dispatches to PSRAM / PHYSICAL / FUNC handlers, calls driver poll callbacks |
CPU Emulation Core
The 6502 core is bespoke:
src/M6502.c is a MOS 6502 emulator written in ANSI C, modelled after the Z80-side engine for drop-in compatibility within the pico6502 firmware. It implements all 151 official instructions and all of the undocumented opcodes — including the KIL/JAM group, which halts the emulated processor exactly as it jams a real NMOS 6502. The core has no RP2350 dependency (only standard C headers), which is what allows it to be compiled natively for the host-side conformance tests and the pico6502sim simulator. src/M6502CPU.c is the Core 1 bus orchestrator, mirroring Z80CPU.c: FIFO handshake, hold/hold-acknowledge with a barrier before the ack, forced reset, driver polling, and the single-step/breakpoint/trace hooks the debug shell uses. The emulation loop services M6502_CYCLES_PER_LOOP (1024) cycles per pass; the slice-limit arithmetic is wrap-safe after a 32-bit cycle-counter wrap was found to freeze the machine after exactly 42 minutes. The hot functions are __not_in_flash_func (RAM-resident) and the N/Z flag lookup lives in RAM: XIP stalls from Core 0's flash traffic were found both to throttle throughput and, once, to corrupt bus envelopes. The core keeps retire counters (g_m6502InstrCount, g_m6502CycleCount) that the shell's cpustat turns into a percentage of the measured host clock.
Two CPU variants are supported — 6502 and 6512 — and they differ only in clocking: the two are the same processor above the pins, with identical registers, an identical instruction set (undocumented opcodes included) and identical cycle timing, so nothing in the emulation core varies between them. The 6502 has an on-chip clock generator — PHI0 arrives on socket pin 37 and the processor (here, the firmware) drives PHI1/PHI2 out; the 6512 has no generator and the host supplies both phases. A CMOS overlay (m6502CmosOp, enabled by cpu->cmos) is selected by cputype "65C02" (6502 clocking) or "65C12" (6512 clocking), and is forced on by the BBC-B driver's Master mode because MOS 3.x is 65C12 code. It adds the (zp) addressing mode, PHX/PHY/PLX/PLY, INC/DEC A, STZ, TSB/TRB, BIT #/zp,X/abs,X, BRA, the fixed page-crossing JMP (abs) and JMP (abs,X); the $x2 KIL column becomes 2-byte NOPs and the $x3/$x7/$xB/$xF columns 1-cycle NOPs, and decimal-mode N/Z come from the adjusted result. The Rockwell bit instructions are deliberately absent, as the 65SC12 lacks them. The disassembler follows the selected core. An unrecognised cputype logs a warning and falls back to the NMOS 6502.
Interrupts: /IRQ is level-sensitive and sampled once per instruction — the SERVICE_REQUESTS() macro takes a single snapshot of the PIO IRQ flags at each opcode fetch, and the core ORs the physical line with a virtual IRQ line (g_m6502VirtIrq) that virtual devices such as the UEF tape deck's ACIA raise. /NMI is edge-detected in the Core 1 loop, with the previous state seeded from the live pin at start and at every reset so that a pre-existing low level is not taken as an edge (the cold-boot "NMI into $0D00" fault). Both take seven cycles and drain any live prefetch — the real chip's discarded dummy fetch.
PIO Bus Interface
The 6502 bus interface is implemented in
M6502.pio and driven from M6502CPU.c. The key difference from the Z80 interface is the 6502's two-phase non-overlapping clock scheme in place of the Z80's single clock, and a single R/W̄ line in place of /RD and /WR. Which side generates the phases depends on the configured CPU variant (see below) — but in both modes every bus state machine synchronises on CLK2_IN, the PHI2 phase actually present at the host socket, so one PIO program serves both variants.
The engine was rebuilt during the September 2026 BBC Model B bring-up around one principle: the PIO makes every timing decision. Seven iterations of C-side "fast issue" logic all corrupted data under real execution while passing every synthetic test, because the defect was in the state-machine interleave and unreachable from C timing; the fix was to move the phase decision into the address state machine itself. The C side now contains no bus timing at all — timing safety is structural, in the "ladder" described below.
PIO Programs
| PIO Block | Program | State Machine | Function |
|---|---|---|---|
| PIO 0 | m6502_addr |
SM 0 | Address engine v3 (“ladder + gated + burst unified”). Drives A0–A15; owns R/W and SYNC as its SET group. |
| PIO 0 | m6502_latch |
SM 2 | Transparent input latch v4 for reads — free-running, one capture word per address drive. |
| PIO 1 | m6502_cycle |
SM 0 | Exec-driven cycle sequencer for the gated (serialised) path; RDY is its jmp pin. |
| PIO 1 | m6502_so |
SM 1 | Monitors the SO pin; sets PIO IRQ 6. |
| PIO 1 | m6502_irq |
SM 2 | Mirrors /IRQ into PIO IRQ 5. |
| PIO 1 | m6502_nmi |
SM 3 | Mirrors /NMI into PIO IRQ 4. |
| PIO 2 | m6502_clock_6502 / m6502_clock_6512 |
SM 0 | Generates PHI1/PHI2 from PHI0 (6502), or parks (6512 — host-supplied phases). |
| PIO 2 | m6502_data |
SM 1 | Write data driver, slaved purely to R/W (moved from PIO 0 to free program space). |
Eight state machines are loaded, all at a clock divider of 1.0. The
m6502_fetch, m6502_read and m6502_write programs remain in the file as the reference bus-cycle sequences; their instructions are what the C side pushes into the cycle SM as out exec words on the gated path.
IRQ Signal Conventions
| PIO IRQ Flag | Signal | Triggered By | Consumed By |
|---|---|---|---|
| IRQ 0 | Gated park | m6502_addr at addr_gated — parks until Core 1 pushes the word and clears the flag |
Core 1 (I/O, serialised and slow-block operations) |
| IRQ 4 (PIO 0) | Address valid | m6502_addr — a read address has been driven |
m6502_latch — begins a capture |
| IRQ 5 | /IRQ | m6502_irq — pin low (level) |
Core 1 SERVICE_REQUESTS() snapshot, once per instruction |
| IRQ 4 (PIO 1) | /NMI | m6502_nmi — pin low |
Core 1 edge detector |
| IRQ 6 | SO | m6502_so — pin asserted |
Core 1 (the V-flag side effect is not yet wired — the hosts tested do not use SO) |
PHI1 / PHI2 Clock Generation — 6502 vs 6512
The 6502 requires two non-overlapping clock phases, and the two supported CPU variants split the responsibility differently:
- 6502 mode (
cputype "6502"/"65C02") — the real chip contains the clock generator, so the pico6502 plays that role: the host's PHI0 reference arrives at socket pin 37 (CLK0, GPIO 35) and the firmware generates and drives PHI1/PHI2 out through the clock buffers (CLK1/CLK2, GPIO 31/32) with the correct non-overlap timing. - 6512 mode (
cputype "6512"/"65C12") — the 6512 has no on-chip generator; the host supplies both phases, and the firmware only listens. A DBE bus-release hold is honoured in this mode.
Either way the bus state machines take their timing from
CLK1_IN/CLK2_IN (GPIO 26/29) — the phases read back from the socket side of the buffers, i.e. what the host actually sees — so the same PIO program serves both modes, and clock generation in PIO means the 6502 bus timing is never affected by Core 1 activity or FIFO stalls. At boot the firmware measures the host clock on both PHI0 and PHI2_IN; the measured figure is what cpustat reports speed against.
Wait States and RDY
The 6502
RDY signal inserts wait states — holding RDY low during a read cycle pauses the processor until it returns high. The pico6502 honours RDY on the gated path only, through the cycle SM's wait-state loop (jmp pin after each PHI2 rise); the fast pipelined path does not stretch, because neither the BBC nor the Apple I ever toggles RDY. A host that does use RDY is served correctly by routing its stretched regions through the gated path (any block that ever fails shadow verification is quarantined there automatically — see below). SYNC is likewise best-effort on the fast path and exact on serialised fetches; a persona-selectable SYNC-accurate mode is designed but not yet needed by any tested host.
PIO Architecture — How 6502 Bus Cycles Are Recreated
A real 6502 changes its address 110–225 ns after the PHI2 fall, holds it for the whole cycle, writes in a single cycle with R/W low across one PHI2 high and the device latching at the fall, and presents read data that is valid only at the end of the PHI2 high. The BBC Model B — whose video system takes the RAM bus at exactly the PHI2 fall — is unforgiving about every one of these, and the engine below is the result of making each of them true.
The Address Engine — Ladder, Gated and Burst
Every word Core 1 pushes to
m6502_addr is {instr:16 | ~addr:16}: the inverted address goes to X and the top half-word is executed with out exec, 16. A read word carries set y, count-1 and falls through to the read path; a write word carries jmp wdrive. The state machine itself has three ways of becoming visible to the bus:
- Ladder — the free-running default. After each genuine PHI2 fall the SM waits tADS (
[15]cycles), restores R/W high, then polls its FIFO on four rungs (jmp !osrewith delays of 12, 12 and 24 cycles — polls at roughly cycles 17/30/43/68). A word that arrives in time is driven at that rung; the asymmetric shape keeps the worst-case drive at ~206–215 ns, inside the real chip's envelope, and the window closes at the last poll. Below a 250 MHz system clock the loader zeroes the delays ("fresh-fall mode"). No work queued means idling to the next fall. - Burst — a read word can request up to six consecutive addresses. PIO has no adder, so X holds the inverted address,
mov pins, !xdrives it andjmp x--makes it ascend; each byte is driven on the next fall-plus-tADS grid point and strobes the latch, so instruction bytes stream at one cycle per byte with zero C in the loop. - Gated (
addr_gated) — the classic PIO IRQ 0 handshake, now three instructions: the SM parks, Core 1 pushes the word and releases, and the drive happens at the next genuine fall with the ladder's own timing. I/O accesses, serialised operations and quarantined slow blocks use it.
wdrive drives the write address with R/W low for exactly one cycle and raises no address-valid flag, so the latch never captures a write — "one cycle, one strobe". The two-strobe write envelope that pre-dated the address-setup fixes double-wrote I/O registers and is retained only as the writestrobes 2 A/B knob. A no-capture read path (rdrive) also exists; A/B testing showed it cost Elite four points of speed, so it is used only by the I/O chase.
m6502_data (PIO 2 SM 1) is slaved purely to the R/W line: wait 0 gpio RNW, drive D0–D7, wait 1 gpio RNW, release. Core 1 queues the data word before the matching address word, so FIFO order pairs them by construction and there are no cross-state-machine edge races; the data is held for the real chip's tHW (15 PIO cycles, ~44 ns at 340 MHz).
m6502_latch (PIO 0 SM 2) replaces the earlier "sample some cycles after the rise" scheme. It waits for the address-valid flag, for PHI2 to rise, spins while PHI2 is high and samples after the detected fall — synchroniser delay puts the sample at true-fall +9–12 ns, deterministically. Logic-analyser forensics proved that the BBC's read-after-write cycles deliver data only between rise+227 ns and the fall, so the fall is the correct sample point; data hold plus the pico-side pin capacitance (the 74AHCT245 disables at ~fall+6 ns and the pins then hold their charge) keep the value valid there. The earlier sample-then-test order could capture up to one loop before the fall and read slow sideways-socket silicon with bits still low — the ~10 ppm "bits only ever drop" corruption that the shadow verifier caught in Galaxians. A hardware sweep at 330 MHz put a 0–1 cycle settle at 2 RAM errors in 4096 against 16 for a 4-cycle settle, hence the fixed one-cycle readsettle.
Everything in this subsection is gated on
m6502IoKnown() — the persona (or the JSON, or the shell's buspipe iorange) having declared the host's I/O window. Without it the engine never speculates and a vanilla host runs conservatively; with it, the BBC Model B runs at 97% of a real 2 MHz 6502 in PHYSICAL mode — Elite steady at 97%, Galaxians at 97–98% — with the bus byte-identical throughout. That figure is the result of two rounds of hot-path micro-optimisation in October 2026, after new features had added per-instruction and per-byte checks to the hot paths: hot code found in flash by LTO placement was moved to RAM, m6502PushAddr's common case was inlined, the CMOS overlay is called only for the 96 opcodes it handles, an on-chip handler bitmap (g_m6502MemioMap) is tested before the PSRAM handler table, and the operand fetch skips tests the fast path has already done. pipetest ran 42.5 million mixed operations with no mismatch, and the shadow verifier checked 69 million bytes with no mismatch. Board A/B testing set the BBC driver's default burst depth to 3.
- Opcode burst and harvest buffer —
g_burstSpec(default 3 from the BBC driver) bytes of speculative opcode burst. Bytes that were already fetched when a bus operation broke the stream are kept in an 8-entry harvest buffer and served to later fetches with no bus operation; it is invalidated by writes into its range, stream jumps, resets and memory-map barriers. - Shadow — a 64KB write-through shadow plus a validity bitmap. ROM fills lazily from the bus stream; the I/O window is never shadowed. A write to the paging register (ROMSEL, matched through
pageregmaskbecause it is partially decoded across$FE30–$FE3F) invalidates the paged region. Writes outside the declared shadow-write window only invalidate — the Galaxians finding that sideways ROM ignores writes. Every byte popped from the bus is compared with the shadow;g_shadowMismatchmust be zero, and any 256-byte block that mismatches is quarantined to the gated path for the rest of the session. - Serve — once proven (1.38 billion served bytes at zero mismatches across soaks,
pipetestand games), a shadow-valid byte is returned to the core immediately while the real bus cycle still runs. The bus stays byte-identical to a real 6502; the core stops waiting for it. - Native writes — writes are fire-and-forget ladder words with a write-pending fence and FIFO back-pressure, oracle-clean under
pipetest. - Fused fetches —
m6502FetchOpcodeFusedand the operand fetches are direct calls replacing issue/collect callback pairs, force-inlined under partial link-time optimisation. - Unknown-map mode — with no window declared,
pipelineFetchstill overlaps the next opcode fetch with the current instruction's tail.
PHYSICAL mode is bus-bound: every RAM access, opcode fetch, stack and zero-page access is a real bus cycle, and a bus operation costs more than one real 6502 cycle. The BBC-B driver's
"type": "VIRTUAL" removes the bus from all of them, and on the board runs at more than three times the speed of a real 2 MHz BBC when unpaced: between 304% and 344% on average, with peaks above 350%.
- RAM window —
[0, g_virtRamHi): the existing 64K SRAM shadow becomes the machine's RAM. Arming marks$0000–$7FFFvalid and zeroes it, as the MOS clears RAM at power-on. Reads are a bare array load at every access site ofm6502_run, and writes a small inline routine. Bursts cannot start inside the window.M6502CPU_readMem/writeMemare pinnednoinline, because inlining their switch at every site would cost about 50K of RAM. - Video write-through — the only thing that reads BBC RAM behind the CPU is the video system, so only writes into the displayed region reach the bus (about 0.1% of RAM writes in BASIC with MODE 4 scrolling). A tracker (
BBCVirt.c) reads CRTC R12/R13, the video ULA control register and the System VIA IC32 screen-size bits from an I/O write snoop (g_ioWriteSnoop). A mode change installs the new screen region at once. CRTC spans then replace the map until the new start address is written, after which they accumulate. A display the tracker cannot decode fails open to all of$3000–$7FFF. - ROM capture — once, after the power-on reset hold and before the first instruction, the OS ROM (
$C000–$FBFF,$FF00–$FFFF) and each sideways bank with no enabled virtual socket are read into their PSRAM socket slots. A bank is captured only if it carries a valid sideways-ROM header and a non-destructive write test does not stick. Physical sideways RAM and empty banks stay physical. The reset vector is then fetched again from the captured OS. - On-chip page image — virtual ROM and VIRTUAL RAM are served one 256-byte page at a time from SRAM, tagged with the membank entry they were validated under (
g_pageMbp). The inline cost at each fetch site is one load and one compare, and the tags of the paged region drop at every paging-register write. - Pacing — the 1024-cycle slice runs as 64-cycle chunks against a Q32 microseconds-per-cycle schedule when the speed is
real;maxruns unpaced. Graded multipliers were tried and removed, because the RP2350 lacks the headroom to hold a fixed acceleration steady. An IRQ the CPU would take, or a new NMI edge, ends the wait, and falling more than 20 ms behind rebases rather than sprinting. Within a chunk,g_ioAccessHookruns before every I/O-window access. For a 1 MHz device (FRED/JIM, and SHEILA$FE00,$FE40/$FE60and$FEC0) it charges the BBC's1 + (cycles & 1)clock-stretch cycles, then callsM6502CPU_paceSync. Each I/O access therefore happens when it would on a real BBC, which keeps the SN76489's roughly 8 µs write timing and the keyboard scan correct. PHYSICAL mode never installs the hook, because the real bus stretches the cycle itself. Withtiminglockedin PHYSICAL mode the pacer runs without debt (g_paceNoDebt, BBC6502 1.172): time lost to the real bus is no longer repaid by letting the pico-served code that follows sprint — repaying it shrank the MOS's sound-chip write, made from the virtual OS ROM, from 8.25 µs to about 3 µs, and the SN76489 dropped bytes — and it rebases whenever it is behind. The sound chip's /WE minimum-pulse guard is armed in every mode and checked after the access is placed (12 µs unpaced, 8 µs paced);bbc virtcounts the pulses it held.
Simulator verification covered boots with the OS, DFS and BASIC captured, video verify in MODE 0–7 with no differing pages (including hardware scrolling, a moved CRTC start and a disc
I/O Discipline — Chase and Parking
*LOAD into screen memory), and the Master persona flipping between shadow and main screen. The simulator measured real at 2.00 MHz. The design record is docs/BBC_VIRTUAL_MODE_DESIGN.md, and the PHYSICAL speed work is recorded in docs/PHYSICAL_SPEED_PLAN.md.
A real 6502 leaves its address bus holding the last address across idle cycles, and a vanilla passthrough does the same. On a BBC with a PiCoPro co-processor on the Tube, that re-decoded the Tube ULA's FIFO registers — one character in five of the PiCoPro banner, then protocol desync and a dead keyboard. The I/O chase (default on) follows every access inside the I/O window with a no-capture park read of the park address, so no side-effect register is ever decoded twice. The older address parking (
6512-Type Hosts — the BBC Master 128
iopark, default off) parked the bus after each I/O access; a necessity A/B on the BBC showed no difference once the IRQ-delivery fixes were in, so it is retained as a diagnostic. When a PHYSICALHW region is declared the park target follows the memory map and defaults to $FFFC — the reset vector, mapped ROM on any bootable 6502 — overridable with ioparkaddr.
The BBC Master's 65SC12 is a 6512-type part: it is given PHI2 on pin 37 (an inverted 2 MHz clock from a 74S00), never stretched, and slows for 1 MHz devices through RDY — a cycle is accepted only if RDY is high at the PHI2 fall. Pin 39 (PHI2 OUT) feeds the CPU's own DBE through R43/C19. Everything below loads only when
cputype is 6512 or 65C12 (applyCpuModel); a 6502 host loads none of it.
- Flywheel PHI2 copy (
m6502_clock_6512_fly) — the bus state machines cannot see pin 37, so the firmware drives a copy of PHI2 onto the pin-39 node. Pin 37 chatters in 5–30% of cycles while the pico's flash or PSRAM bus is busy, so the copy predicts: after each fall it drives low forflylow(254 ns), then high, and samples the real pin only in aflywin(60 ns) window around the expected next fall. A glitch can shift an edge but never add or lose a cycle. Its fall trails the host's byflyfall(35 ns), like a real 65SC12's PHI2 OUT, which keeps write data valid for the VIAs.clkfly offselects a plain edge follower (phi2rise,clklock). - RDY-gated clock (
m6502_rdyclk) — a state machine samples RDY about 100 ns after each rise of the copy and produces a clock edge on CLK1_IN (the unused pin-3 return) only for accepted cycles, its fallgclkfall(9 ns) after the host's. The address and data state machines and the read latch are re-timed onto this clock (m6502RetargetWaits), so a held cycle does not happen for them — exactly as on the real chip, with no CPU-core involvement and no knowledge of the I/O map. A budget of three held cycles stops a misread RDY from hanging the bus. - Pre-fall read latch (
m6502_latch_6512) — a 6522 releases the bus 10 ns after the fall, so on a 6512 host the read is sampled about 33 ns before the host's fall (latchage5). The path also uses an address setup of 0, a one-rung ladder and address-then-R/W write order, and reads that would take the gated route usem6502LadderRead6512. - DBE and SYNC — the board's buffers follow DBE, which on a Master follows PHI2; that is harmless because the Master reads the address only in PHI2, and
dbedrivecan hold it high. The address state machine now side-sets SYNC on opcode fetches, because the Master's memory controller uses SYNC to steer shadow RAM. - Steered shadow windows —
$3000–$7FFF(main RAM or LYNNE: LYNNE when ACCCON X is set, or E is set and code runs in$C000–$DFFF) and$C000–$DFFF(MOS or HAZEL, by ACCCON Y). An I/O write snoop observes ACCCON (bbcAccConObserve);M6502CPU_steerWindowparks the primary RAM's shadow valid bits while the host steers a window away and restores them, minus anything written meanwhile, on the way back — about 640 words per switch, no data copied. LYNNE is shadowed write-through and HAZEL is bus-only by default; both windows stay unshadowed after power-on and BREAK until the first ACCCON write. With the MOS served from the pico, an opcode fetch entering or leaving$C000–$DFFFwhile ACCCON E is set is echoed on the bus as a SYNC read (fetchecho). A recent-write fill guard (M6502_FEAT_WRGUARD) never stores in the shadow a bus capture of an address written in the last eight operations. ROMSEL's page-write mask is0xFFFC, so ACCCON and INTOFF/INTON writes do not invalidate the sideways shadow (BBCMaster_Tuning).
BBC-Master maps to BBCModelB_Init with BBCModelB_SetHostMaster(1): the Master memory model applies (ROMSEL mask 0x8F, ANDY on bit 7, the 1770 at $FE24/$FE28), but LYNNE, HAZEL, ANDY, ACCCON, the CMOS and the VIAs are the host's, so there is no virtual CMOS, no VIA tap and no alias mask. A BBC-FDC entry without chip on any Master (host or mastermode) becomes the 1770 on the Master board. Econet on a Master has no station-link overlay ($FE18 is the ADC); BBCNet adopts the source station of the ROM's own frames. Verified on hardware, PHYSICAL mode, 340 MHz: with the MOS served from the pico, the prompt runs at 225–232% and a BASIC loop at 165–182% of a real Master. The design records are docs/PICO6502_6512_HOST_DESIGN.md and docs/PICO6502_MASTER_PERSONA_PLAN.md.
BBCMMC.c now has two modes. In directory mode (a path not ending in .mmb, or "format": "dir") it presents a folder on the pico's SD card as a synthetic FAT32 card to MMFS2 (hoglet67's MM32 code): a catalogue in PSRAM (at 0x3E0000, up to 1024 entries) gives every file and sub-directory a contiguous cluster run and an 8.3 name, long names shortened Windows-style; the geometry is fixed at 4K clusters, a 1024-sector FAT and the root at cluster 2; short images are padded to 200K or 400K; and a BEEB.MMB in the root is listed first so the original MMFS works from the same folder. Writes are supported, TurboMMC builds (shift-register mode 6) included; lock, unlock and rename are held in RAM until the next scan. Limits: 1024 entries, paths of 111 characters, about 131070 clusters (roughly 1000 DSDs). The catalogue scan runs on Core 0 as a MSG_CORE0_JOB, the card reporting "initialising" meanwhile, and uses the ESP32's paged directory listing (IPCF_CMD_DIR with a start index). An .mmb path keeps the original FAT16 single-file card. Design record: docs/PICO6502_BBC_MMFS2_DESIGN.md.
src/drivers/Acorn/BBCSCSI.c is the model for every device on the BBC's 1 MHz bus (the design record for all of them is docs/PICO6502_BBC_1MHZ_AND_PORTS_PLAN.md). FRED and JIM ($FC00–$FDFF) fall inside the declared I/O window, so every access there is already a parked and chased bus cycle, and on the Master the RDY stretch for 1 MHz devices is honoured by the ladder path; a virtual device is therefore the ADLC pattern — FUNC entries with per-byte handlers — with one addition: the block is physical until a device lives in it, so BBCSCSI_Remap promotes it to a per-byte PTR block with every other byte still the bus. The overlay is reinstalled at the two sites that rebuild the host window.
SCSI front end (chip "scsi", $FC40–$FC43) — the Acorn host adapter in front of an Adaptec ACB-4000, as ADFS 1.30/1.50 drive it: $FC40 is the data bus (a write latches a byte onto it; a read returns the bus, or the latch when the target drives nothing — the ADFS presence test writes $5A/$A5 and reads them back), $FC41 status (b7 C/D, b6 I/O, b5 REQ, b4 interrupt flag, b1 BSY, b0 MSG), a write to $FC42 asserts SEL with the latched byte as the target ID, and $FC43 b0 enables the interrupt (/IRQ follows REQ while enabled). Phases run bus free → selection → command (6- or 10-byte CDB by opcode group) → data in/out → status → message → bus free. Commands: Test Unit Ready, Request Sense (the ADFS "Disc error NN" code), Format Unit, Read(6), Write(6), Seek, Translate, Mode Select, Mode Sense, Start/Stop and Verify — a ten-byte command, which SuperForm steps in 65536-block strides until the controller answers "illegal block address". Drives :0–:3 are LUNs 0–3 of one target. BeebEm's "write to $FC40 selects" reading was wrong for ADFS 1.50, which polled for bus free for ever; the model follows the hardware description.
IDE front end (chip "ide", $FC40–$FC47, $FC48–$FC4F aliased because the 8-bit boards do not decode A3 — HDInit compares the two to detect a 16-bit board) — the ATA task file of J.G. Harston's BBC IDE board and the RetroClinic CompactFlash kits: data, error/features, sector count, sector number, cylinder low/high, drive/head, status/command. ADFS 1.33/1.53 program CHS with Initialize Device Parameters (4 heads × 64 sectors), then per sector set count 1 and poll DRQ before every byte of a 256-byte transfer, reading each sector twice (JGH's "DRQ bug" work-around); the drive bit of the ADFS drive number lands in cylinder bit 13 and its device bit in the drive/head register, so :0/:1 are device 0 and :2/:3 device 1, and one 256-byte ADFS sector occupies one IDE sector (the 8-bit path carries the low byte of each word) — hence the identical image layout. Commands: Read/Write Sectors (both grow a writable image like Write(6)), Read Verify, Identify (model "pico6502 virtual IDE drive", 16 heads × 16 sectors so HDInit's 8-bit size heuristics are right), Initialize Device Parameters, Set Features, Recalibrate, Seek, Flush, NOP and diagnostics; the rest abort. A failed read or write raises ERR with DRQ and a dummy sector, because HDInit and the IDE ADFS wait for DRQ before testing ERR. Outside a transfer the data register reads $00, so the SCSI ADFS's presence test fails on an IDE board and the two ROMs never fight. Both front ends drive one phase engine: data in/out is DRQ, a cache fetch is BSY, status is idle or complete with ERR.
Storage. A direct-mapped PSRAM block cache — 512-byte blocks (two ADFS sectors, one SD sector), cache KB (64–512, default 128), write-back with the floppy controller's 300 ms settle — filled and flushed by Core 0 through MSG_READ_SECTOR / MSG_WRITE_SECTOR. REQ (BSY on IDE) is the only timing the ROM watches: a block not in the cache holds REQ low until Core 0 has fetched it, so Core 1 never blocks and no timing budget is needed. Format Unit (zero-fill in 128 KB chunks so the other drivers keep being served), the .dsc store and the mount are MSG_CORE0_JOBs, during which BSY stays up and REQ down. Images are sized with the new IPCF_CMD_STAT file-size command (ESP32 3.86+); an older ESP32 answers "unknown opcode" and the mount falls back to a doubling-and-bisection probe at 512-byte granularity. A drive's declared capacity is the largest of the file size, the ADFS free-space map's disc size (sector 0, &FC–&FE) and the .dsc geometry, capped at the 21-bit LBA (512 MB): a block beyond the file is zero-filled in the cache without an SD read, a flush beyond the file grows it (FatFs extends on write), a Write beyond the capacity raises the capacity so HDINIT can lay sectors 0–6 on a tiny fresh file, and Mode Select raises it at once. Until one image has mounted the adapter is absent — reads return $FF and SEL is ignored — so ADFS falls back to the floppy instead of waiting on Test Unit Ready for ever. The cache is the last allocation from the PSRAM arena (src/psramArena.c): first-fit above the persona's slots (0x070000; 0x06C000 on the BBC) to the top of the 4 MB pool, 4 KB aligned, handed out in driver-init order and reported at boot, replacing the fixed carve-up BBCFDC, BBCCMT and BBCMMC used. A 256-entry trace ring (commands, phases, fetches, flushes, register accesses, ATA commands) backs bbc scsi trace, and bbc scsi dump reads a sector from the cache or the file and applies ADFS's map checksum (the running sum with carry over bytes &FE..&00 must equal byte &FF) to sectors 0 and 1.
Web GUI plumbing (BBC6502 1.148, ESP32 3.89, filepack 4.05) — the Floppy menu's mechanism, mirrored. The INF payload (t_FlashInfoPayload) gained hdDrives (4 with the card enabled, 0 for no card; absent on older firmware, which the ESP32 detects with an offsetof guard and hides the menu), hdMode (0 virtual, 1 real), hdChip (0 SCSI, 1 IDE) and hdFile[4][64], filled through g_hdNameHook and the g_hd* globals BBCSCSI_Init sets; /data/wifistatus carries them as hd1..hd4, hdDrives, hdMode, hdChip, and %SK_HD1%..%SK_HD4% are substituted into the pages. Two reverse commands run on Core 0 with the 6502 held, like CHGD: CHGH,<slot>,<file> → BBCSCSI_ChangeDrive (flush the slot's dirty blocks to the old image, drop its cache tags, mark a fetch in flight for discard, bus-free a command on that drive, size and mount the new file; an empty name empties the slot) and HDDM,<0|1> → BBCSCSI_SetReal (real: every byte of $FC40–$FC4F back to PHYSICAL and the handlers off, so the host's own 1 MHz-bus Winchester answers; virtual: remap). The ESP32 serves tasks/changehd?diskno=n through the shared image picker (drive type HARD_DISK), ejecthd, hdmode?set=0|1 and createhd?file=&size=&title=&boot=&dsc=&slot=&overwrite=. WiFi::createHdImage writes a formatted, empty ADFS old-map disc of eight sectors: the free-space map in sectors 0–1 (first free space at sector 7, disc size at &FC–&FE, a random disc id, the boot option, one map entry and the running-sum checksums) and the empty root directory in sectors 2–6 ("Hugo" markers, name $, parent sector 2, the title at &4D9); because the card reports the map's disc size and grows the file on write, a 512 MB disc costs 2 KB until used. The optional .dsc carries the Acorn 4 × 33 geometry with enough cylinders to cover the disc, for the SCSI ADFS's Mode Sense.
The RAM discs, the JIM paged RAM, the printer, the RS423 port and the Teletext adapter need no bus-engine work of their own; they are built from a handful of mechanisms worth knowing.
RAM discs (
What the BBC Bring-up Found
ram:<size>[:<persist>], parsed by AcornDisc_ParseRam in the new src/drivers/Acorn/AcornDisc.c, shared by both storage drivers and compiled on every 6502 model). The region comes from the arena through a small pool (PsramArena_PoolAlloc / PoolFree): the arena cannot free, so a swapped-out RAM disc's region is kept and handed to the next request that fits, best fit, twelve entries, cleared by a reset. The region is formatted empty at mount with AcornDisc_BlankDfs / BlankAdfs — the same blank the ESP32's Create Image writes — then overwritten from the persist file when it exists. The floppy engine serves sectors straight from the region (fdcSectorPtr: no cache, never PENDING), a write sets a dirty flag and a format fills the track in place; the geometry follows the slot's kind or the size class. The Winchester serves the region likewise with a fixed capacity: Format Unit zeroes in place, Mode Select keeps the geometry in RAM unless a persist path gives the .dsc a home. Persist: the load at mount runs on Core 0 — at boot inside the floppy driver's deferred remount, which became a MSG_CORE0_JOB (fdcResolveJob) in 1.156 after the image-size probes and a 400K load were found running from the poll, on Core 1, freezing the Master for twelve seconds at power-on; sector lookups answer PENDING while "remounting", and the Winchester reports a RAM disc present only once its file is in. Saves (BBCFDC_RamSave + BBCSCSI_RamSave) run on Core 0 with the 6502 held, from the RAMS reverse command (menus, tasks/ramsave), bbc ramdisc save, and the CFG apply path before the reboot; unchanged images are skipped. INF carries ramDiscs so the menus show the item only while one is mounted. SD loads read 8 KB per call, one link burst.
JIM paged RAM (BBCJim.c): plain FUNC entries — $FCFD bits 16–23, $FCFE bits 8–15 ($FCFF latched, unused), the window $FD00–$FDFF, optional byte mode at $FC00–$FC03 with auto-increment — over an arena region of 64 KB to 2 MB, addresses wrapping at the size; the init image is loaded by the Core 0 service once the SD link is up. Nothing is virtualised beyond address arithmetic.
Layered overlays. The printer and RS423 each share a chip with another interface, and neither is a facade: each is a handler that takes the whole window and owns a few registers, sending every other access downstream to the previous owner's accessor or, failing that, to the real chip. BBCPrinter.c takes $FE60–$FE7F after BBCMMC_Remap at every remap site and owns ORA ($FE61 with the CA2 handshake is the byte; $FE6F is latch only), DDRA, the PCR and bit 1 of IFR/IER; everything else goes to BBCMMC_ViaAccess() when the card is on, else to the bus. The data byte never reaches the bus (it would print on a physical printer too); DDRA and the PCR do. The ACK is raised by the fast tick 50 µs after the byte — IFR bit 1 and, with IER bit 1, the IRQ — and an ORA access or an IFR write clears it, as on a 6522. BBCRS423.c takes the ACIA ($FE08–$FE0F) and ULA ($FE10–$FE17) windows after BBCCMT_Remap; while ULA bit 6 is clear every access goes to BBCCMT_AciaAccess / BBCCMT_SerProcAccess (new accessors on the cassette model, which still pass writes to the real chips) or to the real chips, and while it is set the ACIA is the RS423 model: TDRE drops on a data write and returns one byte-time later, received bytes land one per byte-time while RTS (CR bits 6–5 ≠ 10) is asserted, CTS asserted, DCD clear, never OVRN (the ring holds). Control-register writes are mirrored into both models so a switch of bit 6 lands on a consistent chip. Baud is BeebEm's ULA table {19200, 1200, 4800, 150, 9600, 300, 2400, 75} by rate field through the ACIA divider (/16 normal, /64 = /4, /1 = ×16); pace 0 is 20 µs per byte. Two 6850 facts the model must honour: the interrupt-enable bits (RIE/TIE, CR bits 7–5) must be masked on the real ACIA while the virtual line is selected, or the real chip, with nothing to send and TDRE set, holds the physical /IRQ low with no cause in the virtual status and the MOS loops; and status bit 7 and the IRQ line come from enabled sources only (RDRF with RIE, TDRE with TIE), because the MOS tests bit 7 alone and a byte that arrived with receive interrupts off sent it round its handler for ever; RTS reads as high during master reset. The interrupt lines of the 1 MHz-bus and port devices are bits of one bus-devices IRQ word (g_m6502BusIrq: bit 0 the Winchester, bit 1 the printer, bit 2 RS423, bit 3 the Teletext adapter), ORed into the virtual IRQ.
Transports and the Core 0 service. The RS423 usb transport rides the USB bridge's serial pump (g_usbSerialPump, chained to any previous owner) on CDC port 2 — the pico's third serial port, the picoZ80 serial card's — through two 4 KB rings in the arena (on-chip RAM is full); tcp://:port and tcp://a.b.c.d:port use ESP32 socket 1, for which the ESP32 (3.92) gained the network op 0x20 STATUS: on a listening TCP socket it performs the non-blocking accept and the client takes the socket over, and a peer close now closes the descriptor so STATUS reads closed and the RP2350 listens or reconnects again. The printer's forward uses socket 2 (Econet keeps 3), opening and connecting, streaming 1 KB per pass from the job file and disconnecting at the end so the printer sees EOF; a failure leaves the file on the card. All of this — the spooler, the forward, the JIM init load, the RS423 TCP transport, Econet — runs from one Core 0 service hook (g_core0ServiceHook) that the persona fans out (bbcCore0Service), after the finding that the driver polls (BBCModelB_Poll and everything it calls) run on Core 1 every ~250 ms of host time, so an SD or socket call there stalls the emulation. The rule now: nothing that touches the SD link or a socket may run from a driver's Poll or FastTick. Job files are named <yyyymmdd-hhmmss>.prn when ESP_getTime reports a synced clock, else printNNNN.prn; INF carries prnMode (0 none, 1 virtual, 2 real) and prnJobs, and the reverse commands PRNM,<0|1> and PRNF serve the Printer menu (tasks/prnmode, tasks/prnflush). BBCPrinter_SetReal(1) hands the window back (the MMFS card re-overlays, else physical).
The Teletext adapter — a device with a clock of its own. BBCTeletext.c is a 1 MHz-bus device like the Winchester (plain FUNC entries at $FC10–$FC13, reinstalled by the same two remap sites) but, unlike every device before it, it is driven by time rather than by the 6502: a real adapter produces a field every 20 ms whether or not the ROM is listening. The field machine runs in the fast tick from the raw timer — field sync (FSYN latched), 300 µs to the data entry window (DEW live for its 1088 µs, the 17 lines of a real SAA5030), the 16 rows filled from the next field in the ring, INT latched at the window's end and raised on bit 3 of g_m6502BusIrq when the control latch's interrupt enable is set, DOR if INT was still standing when the window opened — and it falls back into step after a hold rather than bursting. The register model is BeebEm's (Teletext.cpp, derived from the service manual): status bits 0–3 read as the option links left open, $FC11 sets the row (masked to 0–15) and homes the column, $FC12 steps the column and wraps at 64, either access to $FC13 clears the latches; the 16 × 64 row buffer is on-chip (1 KB), each row the $27 framing code then the 42 packet bytes. Sync and INT exist only while the selected channel has a signal — BeebEm's rule: no aerial, no field syncs — which the ATS ROM relies on at reset (it clears $FC13, waits three fields and tests FSYN and the link nibble before enabling its commands). Sources are Core 0's, for the selected channel only — one ESP32 socket was spare, socket 0: a file reader (BeebEm captures of 860-byte fields, packets 3–18 of 20 kept; raw .t42 streams, 16 packets of 42 bytes per field, as the packet servers frame them; eight fields per SD read, 6880 bytes, one link burst, looping) or a TCP client (a 2688-byte receive window every 40 ms into a staging area, whole fields into the ring, liveness by the status op each second, reconnect every 5 s, fields dropped when the ring is full so the picture stays within 0.6 s of live). The ring is 32 fields of 688-byte slots plus the staging area and a 256-entry register trace, 32 KB from the arena; lock-free, Core 0 owning the head and Core 1 the tail, with a generation byte per slot so a channel change bumps the generation and the drain steps over stale fields. bbc ttx prints the registers, the counts and the trace tail (register, value, 6502 PC). The web GUI follows the Winchester's plumbing: BBCTeletext_Init sets g_ttxChannels and two hooks, and the INF payload gained ttxChannels, ttxChannel (the control latch's channel bits) and ttxFile[4][64], which the ESP32 reads behind an offsetof guard — zero channels, or an older firmware, hides the Teletext menu; /data/wifistatus carries them as ttxChannels, ttxChannel and ttx1..ttx4. The reverse command CHGT,<channel>,<file> (tasks/changettx?diskno=n through the shared picker, drive type TELETEXT; ejectttx sends an empty name) needs no hold on the 6502, because the sources are Core 0's own: BBCTeletext_ChangeChannel closes the channel if it is the one on air, stores the new spec and lets the service reopen it, the ring draining under a new generation (BBC6502 1.163, ESP32 3.96, filepack 4.11).
Virtual keyboard and mouse (BBCInput.c, BBC6502 1.177). The MOS scans the keyboard through the System VIA: with IC32 bit 3 clear it writes a key number (row × 16 + column) to port A and reads PA7 back as "down"; with it set the keyboard's own counter autoscans and CA2 interrupts on any key. The keyboard rides the persona's System VIA tap at $FE40–$FE4F (the virtual CMOS's tap; on a plain Model B the $FE00 block is promoted to a per-byte block so the tap entries take effect): a virtual key is OR-ed into PA7 for the key just selected and into the IFR CA2 flag whenever the hardware would have raised it, and the CA2 interrupt goes out on the virtual /IRQ line (bit 4 of g_m6502BusIrq) while the MOS has it enabled — the IER is re-read from the chip at each key event, because the host-reset hook can run after the MOS has re-armed it. Every access still reaches the real VIA. Events come from Core 0 (the KBD / KBT reverse commands from the web GUI, or the shell) through a 256-entry ring in the PSRAM arena; the fast tick applies them, holding a live key at least 40 ms and pacing typed text 30 ms an event. The AMX mouse (MSE) is a further layer over the User VIA, above the printer and MMFS overlays: port B reads carry the virtual direction and button lines, the IFR carries its CB1 (X) and CB2 (Y) flags and its IER mirror says when they interrupt (bit 5), and the real chip's CB1/CB2 enables stay masked so a floating user port cannot fire; a floating bus ($FF) is treated as no chip. One step per axis is issued per fast tick once the driver has acknowledged the last (read port B or cleared the flags). The INF report gains vinput (bit 0 keyboard, bit 1 mouse), which shows the Keyboard & Mouse page, and for 5 s after any input the RP2350 polls the ESP32 every 20 ms.
PSRAM budget. RAM[] is 4 MB of the 8 MB PSRAM (the rest is memPtr and friends); the arena is 0x070000–0x400000, 3648 KB, 4 KB aligned, never freed (the pool reuses), with 24 entries. Fixed takers: BBC-FDC 516 KB (512 cache + trace), BBC-MMC 388 KB (256 cache + 128 catalogue + trace), BBC-SCSI its cache (128 default + trace, shrinking to what is left, minimum 64), BBC-PRN 20 KB, BBC-RS423 12 KB, BBC-TTX 32 KB (field ring, staging area, trace), BBC-JIMRAM its size. The cassette deck takes only what its tape needs: the Core 0 service reads the tape file (ESP_fileSize + ESP_readFileAt) into a pool region sized to it in 64 KB classes (2 MB cap), a plain UEF plays from it, a gzipped one inflates into a second region sized from the gzip ISIZE trailer and the compressed region is released; the record areas (128 KB + 160 KB) are taken at the first motor-on; an idle cassette costs 4 KB (its trace ring). The arena's bookkeeping sits in a critical section because Core 0 loads and Core 1 allocations overlap, and owner names must be string literals — the arena keeps the pointer. The drivers' trace rings and, on the debug-shell firmware, the shell's own state and scratch buffers (~10 KB) also live in the arena, the latter taken on the first poll after the persona has set the arena up (PsramArena_Generation), because on-chip RAM is full: the rest of the debug image's surplus is ICE code compiled into the RAM-resident 6502 engine. Design record for all of it: docs/PICO6502_BBC_1MHZ_AND_PORTS_PLAN.md, sections 2 to 5.
The fix stack that took the v2.3a board from "nothing on the bus" to a working Model B (firmware v1.964, 14 September 2026), each item restoring a real-6502 behaviour, is worth recording for the next host:
- Address discipline — address changes only on a fresh PHI2 fall plus tADS shaping, giving a full host cycle of address setup before every read sample.
- Writes — data SM slaved to R/W (no cross-SM edge races); one strobe per write.
- Reads — the transparent latch: zero hold, stretch-proof, immune to post-write hold collapse and video bus turnaround.
- Interrupts — IRQ/NMI delivery had never been implemented; /IRQ is now sampled live per instruction with level semantics (fixing a phantom IRQ through an invalid vector on BREAK); /NMI edge seeding fixed the cold-boot vector into
$0D00. - Reset — /RES debounced over 5 ms with the reset sequence run after release (fixing "first BREAK ignored"); a power-on supervisor holds the host in reset until Core 0's services are up (15 s ceiling); R/W is parked high at init; Core 1 is parked in RAM before any flash write.
- Cycle counter — a 32-bit wrap froze the machine after exactly 42 minutes; the slice arithmetic is now wrap-safe.
- Clocks and voltage — the Model B persona ships at 340 MHz / 1.20 V; another unit needed ~1.35 V for 330 MHz (1.30 V hung). Voltage headroom is per board. A boot that hangs falls back to 150 MHz.
The evidence for all of it is in the repository: Kingst LA5016 captures (
*.kvdat, timing/) of a real 6502 and the pico6502 in the same BBC with the same PiCoPro — boot, Elite, Galaxians, write tests and BREAK sequences — and the Python analysis tools (kvdat.py, kvtiming.py, rdgrid.py/wrgrid.py, wrcheck.py, zoom.py and others) that produce timing cards from them, together with PIPELINE_REDESIGN.md, the campaign's design record, and the Visual6502 timing-state notes (6502_TIMING.txt).
pico6510 Board Differences
The PICO6510 v2.3 board keeps the pico6502's address, data, R/W, IRQ, NMI, RDY, PHI0 and RESET pins and re-uses the pins the 6510 does not have for its I/O port. One net swap during the board review put PHI2 on GPIO29, the pin every 6502 bus state machine waits on, so
M6502.pio's bus programs and defines are unchanged.
| GPIO | PICO6502 v2.3 | PICO6510 v2.3 | Firmware handling (cputype 6510) |
|---|---|---|---|
| 25 | SYNC (out) | P0 (LORAM) | SET group cut to R/W only |
| 26 | CLK1_IN | P1 (HIRAM) | 6512 programs not loaded |
| 28 | DBE (in) | P2 (CHAREN) | DBE sampler skipped; bus always ours |
| 29 | CLK2_IN (PHI2 return) | PHI2 (out) | m6502_clock_6510 drives it from PHI0 |
| 30 | ~SO (in) | P4 (cassette sense) | m6502_so not loaded |
| 31 | CLK1 (out) | P5 (cassette motor) | port pin |
| 32 | CLK2 (out) | P3 (cassette write) | port pin |
| ESP32 IO43 | DBE_OVR | AEC_OVR | dbeoverride defaults off |
AEC (socket pin 5) feeds only the buffer-enable NOR (
~EN = NOR(AEC, AEC_OVR)), tri-stating A0–A15 and R/W; it reaches no GPIO. The C64's BA reaches RDY on GPIO34, and the VIC-II lowers BA three cycles before it takes the bus with AEC, so the existing RDY handling halts the CPU first. In PHI1, AEC is low on every cycle, which only keeps the address buffers off while the next address is set up. The port is implemented on Core 1 with gpio_put_masked / gpio_set_dir_masked, behind the M6502_FEAT_PORT6510 gate; see the project page for its read and write behaviour.
Memory Model
The pico6502 memory model is structurally identical to the picoZ80 model with one critical difference: the 6502 has no separate I/O address space. There is no
ioPtr[] array in t_6502PSRAM and no iomap JSON section. All peripheral registers are mapped into the 64KB memory address space using FUNC-type blocks.
Tier 1 — RP2350 SRAM (Fast Dispatch Table)
128 × 32-bit entries in
_membankPtr[], one per 512-byte block of the 64KB address space. Each entry encodes the block type, PSRAM bank number, and block base address in a single 32-bit word for O(1) dispatch on every bus cycle:
// 32-bit membankPtr encoding // Bits 31–24: MEMBANK_TYPE_xxx constant (bit flags) // Bits 23–0: 24-bit PSRAM pool address of the block (bank × 64KB + block base) // — for PTR blocks, the memPtr[] table index; for PHYSICAL, the host address // e.g. 16K virtual RAM at $4000 in bank 0: // membankPtr[blk] = (MEMBANK_TYPE_RAM << 24) | (blk * MEMORY_BLOCK_SIZE);
Tier 2 — PSRAM (8MB)
The 8MB PSRAM is divided between the RAM/ROM area and the function-pointer tables:
typedef struct {
uint8_t RAM[MAX_MEMORY_BANKS * MEMORY_PAGE_SIZE]; // 64 banks × 64KB = 4MB RAM/ROM area
MemoryFunc memPtr[MEMORY_PAGE_SIZE]; // 64K per-byte read redirect (PTR type)
MemoryFunc memioPtr[MEMORY_PAGE_SIZE]; // 64K memory-mapped handler array (FUNC type)
// Note: no ioPtr[] — 6502 has no separate I/O space
} t_6502PSRAM;
Within
RAM[] the persona's own slots (RAM image, sideways sockets, OS socket, shadow banks) sit at the bottom; everything above them is the PSRAM arena (src/psramArena.c), from which the Acorn drivers take their buffers first-fit in init order — the floppy and MMFS block caches, the Econet rings, the printer and RS423 rings, the JIM RAM and, last, the Winchester cache — with RAM discs and the cassette's tape regions coming and going through a small best-fit pool on top, so a disabled interface leaves its room to the others. The allocations are reported on the console at boot and by the shell's psram command; see [RAM Discs, Printer and RS423](#bbc-ports) for the budget.
Tier 3 — Flash (16MB)
The 16MB Flash holds the bootloader, two 5MB application firmware slots, two configuration slots for ROM images and minified JSON, general configuration, and the partition table. See the Flash Memory Layout table in the Firmware Architecture section above.
Memory Block Types
| Constant | Value | Behaviour |
|---|---|---|
MEMBANK_TYPE_PHYSICAL |
0x01 | Pass-through to real host hardware |
MEMBANK_TYPE_PHYSICAL_VRAM |
0x02 | Host video RAM with configurable wait states |
MEMBANK_TYPE_PHYSICAL_HW |
0x04 | Host hardware (I/O window) — never speculated into; enables config-driven I/O parking (JSON PHYSICALHW) |
MEMBANK_TYPE_RAM |
0x08 | Read/write — backed by PSRAM |
MEMBANK_TYPE_VRAM |
0x10 | PSRAM video RAM mirror with wait states |
MEMBANK_TYPE_ROM |
0x20 | Read-only — backed by PSRAM; writes are silently discarded |
MEMBANK_TYPE_FUNC |
0x40 | Virtual device — memioPtr[addr] handler called on every access |
MEMBANK_TYPE_PTR |
0x80 | Per-byte redirect through memPtr[] to physical, RAM or ROM |
Memory-map entries may carry a
task of COPYTOPHYSICAL or COPYTORAM to copy a region between host memory and PSRAM at initialisation. The BBC-B driver uses PSRAM pool banks 1–4 (SW_POOL_BASE = 0x10000, 16K per socket) for its sixteen virtual sideways sockets and bank 0 for the live address space; the map is re-pointed on every ROMSEL write while the latch write itself still reaches the hardware.
Configuration Reference
The pico6502 uses the same JSON configuration mechanism as the picoZ80. The top-level keys are
"esp32" and "rp2350". The CPU-specific section uses the key "6502" (rather than "z80") and, exactly like the Z80's z80[], it is an array indexed by flash partition — index 0 is the unused bootloader slot, indices 1 and 2 configure the two application partitions. Because the 6502 has no I/O space there is no "io" array — only a "memory" array inside each partition entry.
esp32.core
| Key | Type | Description |
|---|---|---|
device |
string | CPU device type — one of "Z80", "6502" or "6512". On the pico6502 this drives the DBE_OVR line (ESP32 GPIO38), so it must agree with the cputype configured on the RP2350 side. |
mode |
integer | Default boot mode: 0 = client (station), 1 = Access Point. |
esp32.wifi
| Key | Type | Description |
|---|---|---|
override |
0/1 | 1 = apply all wifi settings from this block; 0 = use NVS settings. |
wifimode |
string | "ap" or "client". |
ssid |
string | Network name to create (AP) or join (client). |
password |
string | WiFi passphrase. |
ip |
string | Fixed IP address. |
netmask |
string | Subnet mask. |
gateway |
string | Default gateway. |
dhcp |
0/1 | Client mode only. 1 = DHCP, 0 = fixed IP. |
webfs |
string | Web filesystem root directory on SD card (default "webfs"). |
persist |
0/1 | 1 = write resolved settings back to NVS each boot. |
rp2350.core
| Key | Type | Description |
|---|---|---|
cpufreq |
integer | RP2350 system clock in Hz (e.g. 300000000). |
psramfreq |
integer | PSRAM SPI clock in Hz (e.g. 133000000). |
voltage |
float | RP2350 core voltage (e.g. 1.10). |
rp2350.6502[ ] — CPU Partitions
Each of the two active partition entries carries the CPU-level keys alongside its
memory and drivers arrays:
| Key | Type | Description |
|---|---|---|
cputype |
string | "6502", "6512", "65C02" or "65C12" — selects the clocking mode (see PHI1/PHI2 Clock Generation above) and, for the C variants, the CMOS instruction overlay. Any other value logs Warning: unknown 'cputype' and defaults to 6502. |
dbeoverride |
0/1 | 1 = force the data-bus buffers enabled via DBE_OVR, for hosts that do not drive the socket’s DBE pin. The supplied 6502 personas set it; the BBC Master persona and the GUI’s 6512 default clear it. The RP2350 reports the resolved value in its INF payload and the ESP32 drives DBE_OVR (ESP32 GPIO38) from it. |
phi2wired |
boolean | 6512-type host whose socket has pin 37 linked to pin 39. Default false. Never fit that link in a 6502 machine, and never use it on a BBC Master. |
clkfly |
boolean | 6512 host: use the predictive “flywheel” PHI2 copy (default true) rather than a plain edge follower. |
flylow |
ns, 100–400 | Flywheel copy: width of the low phase after each fall (default 254). |
flywin |
ns, 12–200 | Flywheel copy: the window around the expected next fall in which the real clock is looked at (default 60). |
flyfall |
ns, 0–90 | Flywheel copy: how far its fall trails the host’s (default 35), matching a real 65SC12’s PHI2 OUT delay. |
gclkfall |
ns, 0–90 | RDY-gated clock: its fall after the host’s (default 9). |
phi2rise |
ns, 0–240 | Edge follower: its rise after the host’s fall (default 30); 0 = a plain level repeater. |
clklock |
ns, 0–230 | Edge follower: how long pin 37 is ignored after each edge (default 190), rejecting ground bounce. |
dbedrive |
boolean | The RP2350 drives the socket’s DBE node high (default false: sensed only). |
core |
object | Per-partition cpufreq / psramfreq / voltage override; the global rp2350.core is the fallback. This is where the web GUI stores a partition’s clock and voltage. |
ioparkaddr |
hex string | Park address for I/O address parking / chase; defaults to 0xFFFC once a PHYSICALHW region is declared. |
device[] / interlink[] |
array | Virtual chips from the shared catalogue and the netlist wiring them — see Virtual Devices on the 6502. Empty in the supplied personas. |
rp2350.6502[n].memory[ ]
Defines the 6502 memory map. All peripherals must appear here as
FUNC-type entries — there is no separate I/O map.
| Key | Type | Description |
|---|---|---|
enable |
0/1 | Whether this entry is active. |
addr |
hex string | Start address in the 6502 address space (e.g. "0xE000"). |
size |
hex string | Region size in bytes (e.g. "0x2000"). |
type |
string | PHYSICAL, PHYSICALVRAM, PHYSICALHW, RAM, VRAM, ROM, or FUNC. |
bank |
integer | PSRAM bank number for RAM/ROM types (0–63). |
task |
string | COPYTOPHYSICAL / COPYTORAM, or a named handler for FUNC-type blocks. |
file |
string | SD-card path to a ROM image to load at boot (ROM type). |
rp2350.6502[n].drivers[ ]
Each entry activates a named machine driver (matched to the firmware's
virtualFuncMap[] table — Open6502 in both 6502 models, BBC-B in the BBC6502 model), optionally loads ROM images into PSRAM at boot, and may carry bus-engine tuning overrides and machine options. The driver's own tuning (BBCModelB_Tuning) is applied at config-parse time before the JSON keys, so any key in the driver object overrides a built-in default; the web GUI's Bus Engine Tuning panel emits only the keys you set.
| Key | Type | Description |
|---|---|---|
enable |
0/1 | Whether this driver entry is active. |
name |
string | Driver name — matched case-insensitively to virtualFuncMap[]. |
rom[] |
array | ROM images to load at boot. Each entry: enable, file, loadaddr[]. |
ioregionlo / ioregionhi |
integer | The host’s I/O window (g_ioRegionLo/Hi). Declaring it enables speculation. BBC-B: 0xFC00–0xFF00. |
shadowwrlo / shadowwrhi |
integer | Write-through shadow window — memory this CPU alone writes. BBC-B: 0x0000–0x8000. |
pageregaddr / pageregmask |
integer | Paging register and decode mask. BBC-B: ROMSEL 0xFE30 / 0xFFF0. |
pageregionlo / pageregionhi |
integer | Region the paging register banks. BBC-B: 0x8000–0xC000. |
burstspec |
1–6 | Speculative opcode burst depth. BBC-B: 3. |
busserve / buspipe / fastfetch |
boolean | Tri-state overrides (absent = driver default) for shadow serve, pipelined issue and fast fetch. |
vkbd, mouse |
— | BBC-B / BBC-Master virtual input: vkbd (default true) the virtual keyboard on the System VIA; mouse none (default), amx or 512 (Master 512 / GEM wiring) on the User VIA — refused while BBC-MMC holds the user port (see the User Manual). |
type, speed, timing, romcapture |
— | BBC-B mode keys: type PHYSICAL (default) or VIRTUAL; speed real (default) or max (VIRTUAL pacing); timing locked (default) or free (PHYSICAL pacing); romcapture (default true) and per-socket "capture": false (see VIRTUAL Mode). |
terminal, usb |
— | AppleI options: terminal physical (default), virtual (virtual 6821 PIA at $D010–$D013 on a USB serial port) or mirror (USB serial joined to the real keyboard and display); usb = 2, 3 or 4; if[] binds CMT-ACI (the virtual ACI cassette card: rom = its 256-byte PROM at $C100, param[] = up to six WAV/AIFF/BIN tapes, leader = minimum leader in seconds). Apple I tuning defaults: I/O window 0xC000–0xE000, shadow-write 0x0000–0x8000, no paging register. |
modelaram, mastermode, ossocket, sockets[], presetdiscroms, persist, if[] |
— | BBC-B machine options — see the project page for each key. if[] binds interfaces: CMT-UEF (speed, up to six param[].file tape slots), BBC-FDC (chip “8271” or “1770”; board “acorn”, “master” or “watford” for the 1770, defaulting to master when mastermode is set; speed 0/1; four param[] slots — drive 0 side A, drive 0 side B, drive 1 side A, drive 1 side B — each { "file", "type": "auto|ssd|dsd|mmb|adf|adl|dds|ddd", "enable" }) BBC-MMC (param[0].file = an image folder, default mmfs, or an .mmb bundle; format “dir” or “mmb”), BBC-NET (station 0–253, 0 = low byte of our IP; net; aunport, default 32768; server “ip” or “ip:port”; serverstation, default 254; servernet; hosts[] of { station, net, ip, port }; clock) and BBC-SCSI (chip “scsi” — the Acorn SCSI host adapter at $FC40–$FC43, default — or “ide” — the 8-bit IDE / CF task file at $FC40–$FC47; cache KB 64–512, default 128; four param[] slots = ADFS drives :0–:3, each { "enable", "file", "readonly" }, raw 256-byte-sector images with an optional .dsc beside them — see Winchester). A floppy or Winchester slot’s file may be ram:<size>[K|M][:<persist>] — a RAM disc (see RAM Discs, Printer and RS423). BBC-JIMRAM (size KB 64–2048, default 512; bytemode 0/1; param[0].file an optional init image), BBC-PRN (param[0].file the spool folder, default prn/BBC; idle seconds, default 3; splitff 0/1; forward “” or raw://a.b.c.d:port) BBC-RS423 (param[0].file the transport: usb, tcp://:port or tcp://a.b.c.d:port; pace 1/0) and BBC-TTX (four param[] slots = channels 0–3 of the control latch, each { "enable", "file" }: a .t42 or 860-byte-field capture on the card, or tcp://a.b.c.d:port for a teletext packet server; no rom[] — the Teletext ROM goes in a sideways socket). |
rom[] entry:
| Key | Type | Description |
|---|---|---|
enable |
0/1 | Whether to load this ROM image. |
file |
string | SD-card path to ROM binary. |
loadaddr[] |
array | One or more load-address descriptors: enable, position, addr, bank, size. |
Virtual Device Framework
The virtual device framework is structurally identical to the picoZ80 framework described in the picoZ80 Technical Guide. The key difference is that all virtual devices are registered in
memioPtr[] — there is no ioPtr[] equivalent for the 6502. Two kinds of virtual hardware coexist: a machine driver's own handlers (described below, and how the BBC persona's interfaces work) and the device catalogue shared with the picoZ80 (next section).
Virtual Devices on the 6502
src/devices.c — the catalogue of register-accurate chip models and the interlink netlist — is compiled into every 6502 model. devicesConfigFromJSON() runs after the memory map and the persona, so a device's decode is authoritative over a blanket region; devicesReset() follows every /RES and devicesPoll() runs in the Core 1 loop whenever devices are present. Because the 6502 has only a memory space, every device is of type MEMORY: for each address it decodes, m6502InstallFunc() splits the enclosing 512-byte block into per-address pointers (MEMBANK_TYPE_PTR, each keeping the block's own type and base) and makes the device's addresses FUNC entries, so neighbouring bytes keep their RAM, ROM or physical behaviour.
The cpu.* pseudo-device presents the 6502's pins to the netlist: IRQ (level, open drain — driving g_m6502DevIrq, which the core ORs with the physical /IRQ sample on every instruction), NMI (falling edge, setting the core's NMI edge flag), RESET, RDY and SO (declared; nothing virtual drives them yet) and the outputs SYNC and CLK (PHI2). There is no bus-request handshake, no I/O space and no interrupt-acknowledge cycle, so the IM2 daisy chain is not built, Z80-family parts raise plain interrupt lines, and the Z80 DMA and WD1773 are excluded from the 6502 catalogue. Three 6502-only entries reuse the Acorn engines in device mode: MC6854 (BBCNet's Econet-over-AUN engine), WD1770 and I8271 (BBCFDC's controller engine) — the framework decodes their registers wherever the user places them, their interrupt and request lines are netlist pins, and for the 1770 the drive-control latch becomes pins a Latch device can drive. Each engine holds one instance, so one such device per board and not alongside the persona's matching interface. The full 6502 catalogue:
| Device | What it is | 6502 notes |
|---|---|---|
MC6850 |
Serial port (68B50 ACIA) | Bytes travel over a USB serial port on the host PC. |
I8251 |
Serial port (8251 USART) | Asynchronous mode over a USB serial port. |
Z80DART |
Dual serial port (Z80 DART) | Two channels over USB serial; the interrupt joins cpu.IRQ (no vectored mode on a 6502). |
Z80CTC |
Counter / timer (CTC) | Periodic interrupts and baud rates; interrupt joins cpu.IRQ. |
Z80PIO |
Parallel I/O (PIO) | Two 8-bit handshaked ports; interrupt joins cpu.IRQ. |
PIT8253 |
Interval timer (8253 / 8254) | Three counters, six modes. |
PPI8255 |
Parallel interface (8255) | Three 8-bit ports, bit set/reset on port C. |
MSM5832 |
Real-time clock | Takes its time from the ESP32 once the network has set it. |
Centronics |
Printer port | Output appears on a dedicated USB serial channel. |
Latch |
Latch / port | A write drives eight wires, a read samples eight wires: banking and control glue. |
SignalPort |
Signal port | Maps eight netlist wires onto one address for test and bridging. |
MC6854 |
Econet (68B54 ADLC over AUN/IP) | The Econet engine in device mode; one per board, not alongside the BBC persona’s BBC-NET interface. |
WD1770 |
Floppy controller (WD1770) | DFS/ADFS images from the SD card; drive, side, density and reset are pins. One per board. |
I8271 |
Floppy controller (Intel 8271) | DFS images from the SD card. One per board. |
The web GUI marks a 6502 partition's devices as memory-decoded, ties unused
IEI inputs high ("no interrupt chain on a 6502"), wires a new chip's interrupt output to cpu.IRQ and offers the 6502's cpu.* pins in the connection builder. Pin lists, the JSON shape and the netlist operators are documented once, in the picoZ80 Technical Guide. The Acorn-engine devices take the same settings as the interfaces they share an engine with: MC6854 the BBC-NET keys (station, net, server, serverstation, servernet, aunport, clock, hosts[]), and WD1770 / I8271 a drives[] list of up to four {file, type} sides plus speed; the WD1770's pins are DRIVE, SIDE, DDEN (low = MFM) and RESET in, INTRQ and DRQ out, and the I8271's RESET in, INT and DRQ out. A device that clashes with the persona's own interface refuses and says so in the boot log.
Device budgets are set per model in src/include/devices.h (DEVICES_TIER), trading instances against the RAM each model's drivers need:
| Firmware | Device tier | Chips | Serial devices | Printer ports |
|---|---|---|---|---|
Open6502 |
open-6502 | 12 | 6 | 4 |
Base6502 |
full-6502 | 8 | 4 | 2 |
Apple6502, BBC6502 |
small | 4 | 1 | 1 |
The design record for the 6502 device work is
docs/VIRTUAL_6502_DEVICES.md, and the Apple I driver's is docs/APPLE_I_DRIVER.md, both in the firmware repository.
Handler Signatures
// Memory / peripheral handler — installed in memioPtr[addr] // Called for every access to a MEMBANK_TYPE_FUNC block typedef uint8_t (*MemoryFunc)(M6502CPU *cpu, bool read, uint16_t addr, uint8_t data); // Driver init function — registered in virtualFuncMap[] // Called twice: pass=0 (validation), pass=1 (configuration) typedef int (*VirtualFunc)(M6502CPU *cpu, t_drvConfig *drvConfig, int pass);
Writing a Peripheral Driver
To add a virtual peripheral for the pico6502:
- Create a handler function with the
MemoryFuncsignature. The handler receivesread=truefor 6502 read cycles (RNW=1) andread=falsefor write cycles (RNW=0). - Create an init function with the
VirtualFuncsignature. In the configuration pass (pass=1), install your handler incpu->_6502PSRAM->memioPtr[addr]for each address your peripheral occupies. - Register the driver name and init function in the
virtualFuncMap[]table inM6502CPU.c. - Add a
FUNC-type entry in thememoryarray ofconfig.jsonfor the address range. - Add a driver entry in
config.jsonwith the matching"name"field.
See the pico6502 Developer's Guide for a complete worked example including a VIA6522 peripheral implementation.
The Apple I's virtual cassette,
src/drivers/Apple/AppleACI.c (the CMT-ACI interface), works at the waveform level, as the BBC's UEF deck does. It replaces the ACI card's $C000–$C0FF with FUNC handlers. Any access toggles the output flip-flop, reads return PROM bytes, and reads in $C080–$C0FF return the PROM byte with A0 forced low while the tape input is high, which is what the Woz ACI firmware samples by comparing $C081 with its previous read. The firmware times everything in CPU cycles at the Apple I's 1.0227 MHz: 592-cycle leader halves, a 180+238-cycle start bit, and 238-cycle (0) or 473-cycle (1) bit halves. Playback therefore synthesises an ideal waveform from each record's bytes in emulated CPU cycles rather than wall-clock time, which is why it loads correctly at any speed, PHYSICAL or VIRTUAL. The tape moves only while the input is polled. A leader lasts at least leader seconds and until the firmware's ~3.3 s settle delay ends, recognised because its slow output toggles stop. A record abandoned part way (RESET) plays again, and a record not read for 0.6 s is treated as abandoned. WAV and AIFF images (PCM 8/16-bit, any rate and length) are streamed through a 2.5 MB PSRAM buffer a window at a time and demodulated by zero crossings against an adaptive threshold, with half-cycles classified against the recording's own leader. Recording times the output edges, classifies them as the firmware wrote them, and turns each W range into a record. After 0.4 s of quiet the session is written as an 8-bit mono WAV, with a 10-second leader per record, plus a raw .bin, and loaded back into the deck. Buffers sit in PSRAM through the uncached alias: 2.5 MB for the raw image, 256K for the tape and 128K for the recorder.
Two framework features arrived with the first real virtual device, the BBC's UEF tape deck (src/drivers/Acorn/BBCCMT.c). A handler may raise the virtual interrupt line g_m6502VirtIrq, which the core ORs with the physical /IRQ at its per-instruction sample — the deck virtualises the 6850 ACIA ($FE08/09) and Serial ULA ($FE10) with per-byte FUNC entries, feeds bytes and DCD carrier events at real 1200/300-baud pacing from a g_fastTickHook that runs in the Core 1 loop, and raises the line exactly as the real ACIA would; writes still pass to the physical chips so the real motor relay clicks, with the physical ACIA's interrupt-enable bits masked so it cannot storm the host. And a driver can declare bus-engine tuning for its machine (BBCModelB_Tuning): the I/O window, shadow-write window, paging register and burst depth — the "machine knowledge" that lets the engine speculate safely, applied before the JSON so the configuration can override it.
The floppy and MMFS interfaces set the pattern for block-backed virtual storage. Two host-independent chip models live in src/drivers/: I8271.c, the Intel 8271 (register interface, full command set, status/result semantics, drive-control ports, INT output), and WD177x.c, the Western Digital WD1770/1772/1773 (Type I–IV commands with step rates, spin-up, settling and verify; Read Address, Read Track and Write Track with the raw track laid out as the datasheet describes, so *FORMAT works; Force Interrupt; motor timing), both with optional mechanical timing and both behind an abstract media callback table. src/drivers/Acorn/BBCFDC.c is the Model B glue, selectable per configuration: the 8271 at $FE80–$FE9F, or a 1770 behind a drive-control latch whose layout was read out of the DFS ROM written for each board — the Acorn Model B upgrade (latch $FE80, chip $FE84), the Watford Electronics board (same addresses, different latch bits) and the Master 128 (latch $FE24, chip $FE28, which on a Model B host would otherwise decode to the video ULA, so the writes must never reach the bus). FUNC entries overlay the window with writes never passed to the bus; the chip's INT (8271) or INTRQ|DRQ (1770) becomes an /NMI edge on the emulated core through the core's device timer, so status and NMI change together one byte-time (FM 64 µs, MFM 32 µs) after the host consumed the previous byte and a filing system whose NMI handler itself touches the chip never sees the next event nested inside the handler. Two drives map their sides onto image files — DFS SSD/DSD, double-density DDS/DDD (16 or 18 sectors by size), ADFS ADF (S/M, or L side-after-side) and ADL (L interleaved), or an MMB-bundle disc; a second single-sided file in a drive's B slot makes it double-sided, a single-sided disc answers side 1 with sector-not-found, and the kind is configured per slot or deduced from extension and file size probed at mount on Core 0. While the interface is enabled it sets g_m6502NmiPhysMask, so the physical controller's /NMI edges are counted and ignored — the virtual device owns the line. src/drivers/Acorn/BBCMMC.c virtualises the MMFS card: a partial User VIA overlay (port B, the shift register, the SR mode bits of ACR and IFR/IER bit 2 are virtual; port A, CA1/CA2, both timers and the other interrupt bits pass through, with port-B writes never echoed to the bus), an SPI SD-card state machine advertising SDHC, and a FAT16 façade whose root directory holds a contiguous BEEB.MMB mapping straight onto the MMB file's byte offsets. Both use the same engine: a direct-mapped PSRAM block cache (the FDC's 512K and the MMC's 384K, now allocated from the PSRAM arena rather than at fixed offsets) filled through MSG_READ_SECTOR with one fetch in flight, write-back with dirty blocks flushed 300 ms after their last update, responses peeked from the inter-core queue and removed only when they are the driver's own. The stack rule inherited from the tape deck applies throughout: handlers and the fast tick run inside m6502_run on Core 1 and only record events; the driver's poll, on the top-level stack, reports them.
The Econet interface, src/drivers/Acorn/BBCNet.c, takes the pattern onto the network. src/drivers/MC6854.c is a host-independent, frame-level model of the Motorola MC6854 ADLC — receive and transmit FIFOs that fill and drain at the line byte rate, ADDRESS PRESENT / FRAME VALID / RDA / TDRA / FRAME COMPLETE semantics in 1- and 2-byte transfer modes, and interrupt enables where each condition that rises while enabled asserts IRQ, so a standing condition never masks a new one — written to what NFS 3.60 and ANFS 4.x actually do (CR1 $C1 → CR4 $1E, CR3 $00, CR1 $82, CR2 $67 at init; receive with RIE and two-byte transfers; transmit two bytes per NMI with TIE/RTS). The glue overlays the ADLC at $FEA0–$FEBF and the station links at $FE18–$FE1F, turns the ADLC IRQ into an /NMI edge, and runs the Econet four-way handshake (scout, ack, data, ack) frame by frame against the ROM on Core 1's fast tick, translating it to AUN exactly as a bridge does: a scout is acknowledged locally after a frame time, the data frame becomes an AUN unicast (8-byte header — type, port, control, pad, 32-bit sequence — in a UDP datagram to port 32768), the peer's AUN ack becomes the final frame; an incoming unicast is presented as a scout, the ROM's ack brings the data frame, the ROM's final ack returns as an AUN ack; immediates and broadcasts map to their AUN types. Core 0's main loop (BBCNet_Core0Service) moves datagrams between two PSRAM rings (8 out, 16 in, 1600-byte slots at 0x0F0000) and a UDP socket on the ESP32, through the same network IPC the Celestite board uses, extended with datagram sockets, broadcast and addressed sends. Stations map to IP by the AUN convention (station = low byte of the address, port 32768) with explicit entries for the file server and any host that does not follow it, and incoming datagrams are attributed to a station the same way. In Master mode the station and file-server numbers are also written into the virtual CMOS.
The Winchester, src/drivers/Acorn/BBCSCSI.c, is a 1 MHz-bus device with two register maps over one engine: the Acorn SCSI host adapter at $FC40–$FC43 and the 8-bit IDE task file at $FC40–$FC47, selected by the chip key, both serving the same ADFS Winchester images through the block-cache engine above with REQ (or BSY) as the only flow control. It is described under Winchester — the SCSI Host Adapter and the IDE Task File. JIM paged RAM, the parallel printer layered over the MMFS card's User VIA overlay, RS423 layered over the cassette's ACIA/ULA model, the Teletext adapter at $FC10–$FC13 with its 50 Hz field machine, and the RAM discs of both storage drivers are under RAM Discs, JIM RAM, Printer, RS423 and Teletext.
ESP32 Co-processor
The ESP32 co-processor is identical in function and implementation to the picoZ80 ESP32 — refer to the picoZ80 Technical Guide — ESP32 Co-processor for the full description of the SD card interface, web server structure, and RP2350–ESP32 command protocol.
SD Card
The SD card is managed exclusively by the ESP32 over SPI. The RP2350 requests file reads and writes by posting messages to the inter-core queue; Core 0 relays these requests to the ESP32 over UART and returns the results. The SD card directory layout for the pico6502 is identical to the picoZ80:
webfs/ for web files, ROM/ for ROM images, and config.json in the root. Since ESP32 4.06 the SPI file handlers keep up to four files open (closed after 30 s idle, and around every web or file operation that can change the card) and use FATFS fast seek, so a seek no longer walks the cluster chain: the BBC's MMFS boot wait fell from 1864 ms to 159 ms, a sector read from 51 ms to 11 ms and a file read from 73 ms to 5 ms. Answers served from the cache carry IPCF_FLAG_CACHED, which ipcstat uses to split the ESP32's service time.
Web Server
The same eight-page Bootstrap 4 web server runs on the ESP32, and since the CPU-aware update the interface adapts itself to the processor it is actually serving: the server substitutes a
%SK_PROCESSOR% template variable from the running firmware's device type, and the JavaScript adjusts accordingly — the persona page shows only personas tagged for the detected CPU, the configuration GUI offers the 6502 driver list (Open6502, BBC-B) and pin names (with Z80-only concepts such as I/O regions and the refresh divisor hidden, and the CMT/QD media menus suppressed through %SK_Z80MEDIAVISIBLE%), adds the 65C02/65C12 CPU types, per-partition core voltage/clock, the per-driver Bus Engine Tuning panel, the BBC-B options with the sideways-socket table, the six-slot CMT-UEF carousel and the Acorn interface cards (floppy, MMFS, Econet, and from filepack 4.02 the Winchester card with its Controller selector — Acorn SCSI or 8-bit IDE / CF — cache size and four drive slots), the Hard Disc menu and its Create Image modal on every page (filepack 4.05; shown only while the status poll reports hdDrives > 0), the Printer menu and Dashboard row (prnMode > 0), the Teletext menu and Dashboard row (ttxChannels > 0; filepack 4.11), the Save RAM discs to SD item (ramDiscs > 0), the JIM RAM, Printer and RS423 configuration cards and the File Manager's Refresh button (filepack 4.09), and p6502.css applies the 6502-specific colour scheme over the shared common-ui.css layout. An unexpanded template variable (older firmware) is treated as Z80. The Keyboard & Mouse page (input.htm, filepack 4.26) is listed in the menus while /data/wifistatus reports vinput, and posts to /tasks/kbd, kbt and mse, which the ESP32 forwards to the RP2350 as the KBD, KBT and MSE reverse commands; and every page's header shows the running RP2350 firmware as a badge after the title — version, active partition and driver set, e.g. (v1.177 p2 Acorn,dbgsh).
Command Protocol
The RP2350–ESP32 command protocol is identical for both the picoZ80 and pico6502: binary IPC frames with a CRC32 trailer over the 60MHz FSPI link, every response validated against the command's opcode and sequence number, with the 460.8kbaud UART serving as the USB-to-ESP32 console bridge. It is defined in
ipc_protocol.h and ESP.c / FSPI.c and documented in the picoZ80 Developer's Guide. On a 6502 host the INF report carries the UEF tape queue in place of the Z80 cassette queue and reports floppySides = 2 so the Dashboard's Floppy menu renders Drive 0/1 × Side A/B (the CHGD command then carries a fourth and fifth field, side and kind); the web interface hides the Quick Disk menu, while the CMT menu serves the 6502 tape carousels — the BBC's CMT-UEF and the Apple I's CMT-ACI — with select, Add Tape and the Real/Virtual deck switch, through the same /cmt endpoints the Z80 decks use; the Econet module's AUN datagrams travel over the `NET_SOCK` / `NET_SEND` / `NET_RECV` commands, which now support UDP datagram sockets with broadcast and addressed sends; the TIME command and MSM5832 synchronisation are Z80-only today. The Winchester added IPCF_CMD_STAT (0x16, ESP32 3.86+): a file-size query answering a 32-bit size and a directory flag, or NOTFOUND — until then the RP2350 could size a file only by probe reads. The INF report gained the Winchester fields (hdDrives, hdMode, hdChip, hdFile[4]) and the reverse channel the commands CHGH,<slot>,<file> and HDDM,<0|1> for the Hard Disc menu (see Winchester); then ramDiscs, prnMode and prnJobs with the reverse commands RAMS, PRNM,<0|1> and PRNF, and the network op 0x20 STATUS with the listening-socket accept for the RS423 TCP transport (ESP32 3.92; see RAM Discs, Printer and RS423). ESP32 3.88 also moved the HTTP server's internal control socket off UDP 32768 (to 32700), which had been blocking the Econet station's bind of the standard AUN port.
SWD Debugging — RP2350
The SWD debugging setup for the pico6502 is identical to the picoZ80 — refer to the picoZ80 Technical Guide — SWD Debugging for the full description of hardware connections, the custom
rp2350_tzpu.cfg OpenOCD target, and global GDB initialisation. The differences from the picoZ80 are:
- The main firmware ELF is
build/bin/model/Base6502/Base6502_0x10020000.elf(notBaseZ80). - The
add-auto-load-safe-pathentry in~/.gdbinitmust referenceBase6502.
OpenOCD Setup
sudo cp rp2350_tzpu.cfg /usr/local/share/openocd/scripts/target/ openocd -f interface/cmsis-dap.cfg -f target/rp2350_tzpu.cfg -c "adapter speed 5000"
GDB Configuration
set history save on set history filename ~/.gdb_history set history size 65536 add-auto-load-safe-path build/bin/model/Base6502/.gdbinit:build/bin/model/Bootloader/.gdbinit
# Bootloader — Core 0 cd build/bin/model/Bootloader cp ../../../../.gdbinit.bootloader.3333 .gdbinit gdb-multiarch Bootloader.elf # Bootloader — Core 1 (separate terminal) cd build/bin/model/Bootloader cp ../../../../.gdbinit.bootloader.3334 .gdbinit gdb-multiarch Bootloader.elf
# Main firmware — Core 0 cd build/bin/model/Base6502 cp ../../../../.gdbinit.3333 .gdbinit gdb-multiarch Base6502_0x10020000.elf # Main firmware — Core 1 (separate terminal) cd build/bin/model/Base6502 cp ../../../../.gdbinit.3334 .gdbinit gdb-multiarch Base6502_0x10020000.elf
ESP32 — USB Debugging
Identical to the picoZ80 — connect USB to the ESP32 USB port and use the ESP32-S3 built-in USB-JTAG interface (no external probe required).
openocd -f board/esp32s3-builtin.cfg xtensa-esp32s3-elf-gdb esp32/build/main.elf (gdb) target extended-remote :3333
Build System
The build system is identical to the picoZ80 — CMake with Pico SDK 2.x targeting the RP2350. The pico6502 does not require the Zeta Z80 emulator library. Refer to the picoZ80 Technical Guide — Build System for the full description of prerequisites, Docker setup for ESP-IDF, and the build script. The pico6502-specific differences are noted below.
Build Targets
| Target | Output | Description |
|---|---|---|
Base6502 |
Base6502_0x10020000.uf2 |
Main 6502 firmware — Slot 1 load address |
Base6502 |
Base6502_0x10520000.uf2 |
Main 6502 firmware — Slot 2 load address |
Base6502_DBGSH |
Base6502_0x10020000_DBGSH.uf2 / _0x10520000_DBGSH.uf2 |
Debug-shell (ICE) builds of the two slots |
Open6502 |
Open6502_0x10020000[_DBGSH].uf2 / _0x10520000[_DBGSH].uf2 |
The Open6502 driver only (TARGET_MODEL_OPEN): the experimenter target for your own board or an undriven machine, with virtual devices |
Apple6502 |
Apple6502_0x10020000[_DBGSH].uf2 / _0x10520000[_DBGSH].uf2 |
Open6502 plus the Apple driver (INCLUDE_APPLE_DRIVERS, TARGET_MODEL_APPLE): the AppleI persona with its virtual or mirrored PIA terminal and the CMT-ACI virtual cassette interface, plus the aci shell command |
BBC6502 |
BBC6502_0x10020000[_DBGSH].uf2 / _0x10520000[_DBGSH].uf2 |
Base6502 plus the Acorn drivers: the BBC-B and BBC-Master (real Master 128 host) personas, (INCLUDE_ACORN_DRIVERS): BBC-B persona, UEF tape deck, virtual 8271 / WD1770 floppy controller (DFS, DDFS, ADFS), virtual MMFS card, virtual Econet module (AUN over IP), bbc shell command |
Bootloader |
Bootloader.uf2 |
Shared bootloader (same as picoZ80) |
| ESP32 | main.bin |
ESP32 firmware (shared with picoZ80) |
Like every model in the shared tree, each 6502 model builds four variants — two flash partitions, each with and without the debug shell — through the
add_m6502_model_targets CMake macro, which defines TARGET_CPU_M6502, compiles M6502.c and M6502CPU.c with partial link-time optimisation and links at -O3. Base6502 (v2.309) compiles only the Open6502 driver set (INCLUDE_OPEN6502_DRIVERS): a vanilla MOS 6502/6512 replacement with no machine-specific drivers. Open6502 (v1.084) is the same driver set marked as the experimenter family (TARGET_MODEL_OPEN). Apple6502 (v1.085) adds INCLUDE_APPLE_DRIVERS (TARGET_MODEL_APPLE) and the AppleI driver. BBC6502 (v1.134, TARGET_MODEL_BBC) is identical in core and defaults and adds INCLUDE_ACORN_DRIVERS (which also pulls in the generic I8271.c, WD177x.c and MC6854.c chip models); it reuses Base6502/main.c, differing only in which machine drivers are compiled in and in handling the CHGD,<drive>,<file>[,<side>,<kind>] floppy-change command from the ESP32. The BBCFDC and BBCNet engines are compiled into every 6502 model, because they also serve the WD1770, I8271 and MC6854 catalogue devices. Each firmware names its driver family in its description (for example MOS6502 CPU Emulator (Apple drivers, dbgsh)), and the web GUI offers that family's drivers only. build_tzpuPico.sh 6502 builds Base6502; Open6502, Apple6502 and BBC6502 are produced by the full build. Binaries are named with the model version (Apple6502_0x10020000_DBGSH_1.000.bin).
Build Commands
# Set up (once) — from project root
export PICO_PATH=/path/to/pico-sdk
./get_and_build_sdk.sh
# Standard release build of the 6502 model
./build_tzpuPico.sh 6502
# Debug build
./build_tzpuPico.sh 6502 DEBUG
# ESP32 only (using Docker idf54 alias)
cd projects/tzpuPico/esp32
idf54 build
# Flash RP2350 via USB mass-storage (BOOTSEL mode)
cp build/bin/model/Bootloader/Bootloader.uf2 /media/$USER/RPI-RP2/
cp build/bin/model/Base6502/Base6502_0x10020000.uf2 /media/$USER/RPI-RP2/
# Flash ESP32 (initial, via esptool)
esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 460800 \
write_flash 0x0 esp32/build/bootloader/bootloader.bin \
0x8000 esp32/build/partition_table/partition-table.bin \
0x10000 esp32/build/main.bin
Debug Shell Architecture
The debug shell (ICE) is one source file —
src/dbgsh.c — compiled once per firmware image and made CPU-neutral through a t_CpuOps vtable defined in src/include/cpu.h. The vtable covers identity (CPU name; the flags string, NV-BDIZC for the 6502 against the Z80's SZYHXPNC), capability flags, register-file access, instruction encoding (disasmOne/asmOneLine/instrLen/isCall) and bus operations, while shared CPU_MEMBANKPTR()/CPU_PSRAM() macros keep the memory commands genuinely CPU-neutral. Breakpoint limits and related constants moved to src/include/dbghooks.h so both CPUs share one definition. The shell banner announces which personality is running: --- pico6502 Debug Shell ---.
The capability flags — hasIoSpace, hasM1Cycle, hasInterruptModes, all false on the 6502 — are what shape the command set: the Z80 build carries 67 commands, the 6502 build 88 (89 on BBC6502, which adds bbc, and on Apple6502, which adds aci). cpustat and the pcprof profiler (Core 1 PC sampled at 20 kHz into 32-byte bins of SRAM) are now shared by both CPUs. Sixteen 6502 commands came with the BBC Master bring-up: addrsetup, rungdelay, wrorder, latchbelt, latch6512 and latchage (bus-timing knobs), phi2rise, clkfly, flyfall, clklock, clkdrive and dbedrive (6512 host clocking), clkcap (pulse-width histograms of a clock pin), pin39probe (what the host does to the pin-39 node), bustrace (a two-channel logic-analyser view of one held write and read) and fetchecho (the BBC Master's SYNC echo of pico-served opcode fetches); every setter except fetchecho and clkcap needs the CPU held. Eight Z80-only commands are compiled out on the 6502 (iomap, in, out, fwait, iowait, intcount, stall, dma); the virtual-device commands dev, sig, ctc, pio, ser, rtc and prn are present on both CPUs now that the device framework is part of the 6502 build; and busdiag is not removed but replaced — each CPU gets its own implementation matched to its bus.
Video — a session on the debug shell: information commands, the PSRAM map and interface reports on the console, memory dump, disassembly and search, the ICE (break, step, next, go, trace), SD card listing, bus diagnostics and the profiler.
Bring-up Diagnostics — busdiag and piodbg
The 6502-specific diagnostics were written ahead of the hardware for board bring-up, and grew through the bring-up and speed campaign into the instrument the engine was tuned with:
busdiag— a snapshot of every socket and buffer-control signal plus the address and data buses;busdiag clkmeasures PHI0 / PHI1_IN / PHI2_IN and compares them (telling a dead buffer from a dead clock);busdiag watch [n]takes n rapid snapshots.busprobe <addr> [count]— repeat-reads one address to expose unstable data lines;busverify <addr> <len> [passes]— ROM-safe re-read of a range, flagging flaky reads and fetch/read mismatches;memtestwith adecaymode for refresh faults.bustest [loops]andwrtest [secs] [mode] [addr]— drive marked patterns against R/W, PHI2 phase and OE_CLK for logic-analyser characterisation;busstate— live state-machine PCs, FSTAT and IRQ flags for hang forensics (it proved the failed C-side pipeline experiments parked cleanly — the defect was data corruption, not deadlock);piodbg— the PIO dump.writestrobes <1|2>,iopark on|off,readsettle <0-31>,readphase latch|hi|lo— the live A/B knobs;buspipewithon|off,fetch,rungs <1-4>,burst <1-6>,iochase,iorange <lo> <hi>,serve,natwr,wrregion,wrhold <0-31>,wrverify <lo> <hi>|off,slowclr,stats;pipetest <iters>— the Core 1 mixed bus-operation oracle harness.cpustat— instructions/s and emulated cycles/s against the measured host clock (call twice for a rate);cpuprof— per-instruction time histogram by bus class. The optional statistics (g_dbgStats, op-class census, miss reasons, latency histograms) cost 3–5% and are off by default; without the debug shell they compile out.bbc(BBC6502 only) — persona state;mask <0|1>,socket <n> <0|1>,cmosdef,oscheck,tape sel|next|rew|trace|on|off,fdc(status, including which chip and board) /fdc <drive> <file|eject> [A|B] [auto|ssd|dsd|mmb|adf|adl|dds|ddd]/fdc trace on|off,mmc(status) /mmc trace on|off,net(status: frames, UDP in/out, acks, timeouts, SPI cost per datagram, reply latency) /net trace on|off/net tick <us>.
The 6502 register dump shows
A/X/Y/S (with the stack rendered as $01nn), PC, then P with its flag string, then IRQ/NMI/halted state and the cycle count. set flags accepts either a positional NV-BDIZC letter mask or a bare hex value.
Assembler / Disassembler
src/M6502dis.c provides both directions. Its 256-entry opcode table is generated from the case labels in M6502.c itself, so the disassembly always matches what the emulator actually executes. All 13 addressing modes are covered, undocumented opcodes are prefixed with *, and the matching one-line assembler accepts the disassembler's own output verbatim (the * included) plus $hex, %binary, decimal, trailing-h and 0x operand forms. The pairing is verified over 2048 round-trip cases — the invariant is a text round trip, not byte identity, because 35 NMOS encodings are duplicates and cannot survive a byte-for-byte trip. The API is CPU-handle-free (callback-based reads), which is what makes it testable standalone on the host.
Conformance Tests
Because
M6502.c and M6502dis.c have no RP2350 dependency, they carry a host-side conformance suite in src/test/M6502/ (m6502_test.c, m6502dis_test.c), built with the native compiler:
make -C src/test/M6502 run
Coverage is exhaustive where exhaustive is cheap:
- Binary
ADC/SBCover all 256 × 256 × 2 operand/carry combinations, checked against plain C arithmetic. - Decimal (BCD)
ADC/SBCover all valid BCD pairs. CMPover all 256 × 256 pairs.- The full 256-opcode disassemble → assemble round trip, with explicit, listed exemptions for the duplicate encodings.
The suite exists because it caught real faults during development — an
SBC off-by-one, decimal ADC dropping the low nibble, decimal SBC unimplemented, and CMP never setting Z — each wrong in every case, which is precisely what an exhaustive sweep exposes instantly.
On hardware the bus engine carries its own oracle: the shadow verifier compares every byte popped from the bus with the write-through shadow and the mismatch count must stay at zero across every soak (Elite, Aviator, Galaxians, MMFS, long idle sessions); pipetest runs mixed bus operations against the same oracle; busverify and memtest check the raw bus; and the Kingst LA5016 captures of a real 6502 and the pico6502 in the same BBC are the final arbiter of what the socket actually sees. Hosts verified so far: BBC Model B (v2.3a, 340 MHz) and the RC6502 Apple I replica (150 MHz; Woz monitor and BASIC, minor RAM memtest errors noted on the early serialised build). Not yet verified on hardware: the Model A RAM overlay's screen behaviour, Master mode on a real Master, the 6512/DBE clocking mode, and the SO pin.
Reference Sites
| Resource | Link |
|---|---|
| pico6502 project page | /pico6502/ |
| pico6502 User Manual | /pico6502-usermanual/ |
| pico6502 Developer’s Guide | /pico6502-developersguide/ |
| picoZ80 Technical Guide | /picoz80-technicalguide/ |
| picoZ80 project page | /picoz80/ |
| RP2350 Datasheet | datasheets.raspberrypi.com |
| Pico SDK Multicore API | raspberrypi.github.io/pico-sdk-doxygen |
| MOS 6502 Datasheet | archive.org |
| esptool documentation | docs.espressif.com |
| cJSON Library | github.com/DaveGamble/cJSON |
Wireless Regulatory Notice
This device incorporates an ESP32-S3-PICO-1 wireless module that transmits in the 2.4 GHz ISM band, making it an intentional radiator under radio-frequency regulations worldwide (including FCC Part 15 Subpart C in the United States, and the Radio Equipment Directive 2014/53/EU in the European Union).
Although the ESP32-S3-PICO-1 module itself carries pre-existing regulatory certifications (FCC, CE, and others), those module-level certifications do not automatically extend to a finished product that incorporates the module. The pre-certified module exemption permits individual hobbyists to build a limited number of devices for personal, experimental, or educational use without obtaining separate equipment authorisation.
Important Limitations
It is the builder’s sole responsibility to ensure that any device constructed from these designs complies with all applicable radio-frequency regulations in their jurisdiction. The author provides these designs for personal, educational, and hobbyist use and makes no representation that a device built from them satisfies the regulatory requirements for commercial distribution.
- Assembled devices must not be sold, offered for sale, gifted, or otherwise distributed to third parties unless the finished product has been independently tested and granted its own equipment authorisation (e.g. FCC ID, CE marking with a Notified Body assessment) in the relevant jurisdiction.
- Building this project for personal use in limited quantities is generally permitted under hobbyist and experimental-use provisions (e.g. FCC § 15.23), provided the device does not cause harmful interference.
- Regulatory requirements vary by country. Builders outside the United States should consult their national radio-frequency authority for applicable rules.
It is the builder’s sole responsibility to ensure that any device constructed from these designs complies with all applicable radio-frequency regulations in their jurisdiction. The author provides these designs for personal, educational, and hobbyist use and makes no representation that a device built from them satisfies the regulatory requirements for commercial distribution.