pico6809 Technical Guide

pico6809 Technical Guide

This guide describes how the pico6809 works: the board's bus interface, the firmware architecture, the CPU core's cycle model, the PIO bus engine, the read shadow, the memory model, the Dragon personas and the configuration reference. For installation and everyday use see the User Manual; for the source tree, drivers and simulators see the Developer's Guide.
The PICO6809 hardware is in production but not yet tested on a Dragon 32. Bus timing figures here were measured on the cycle-accurate PIO emulator bench (sim/pio6809) against a modelled Dragon, and the data-sheet timing they are compared with is still to be checked against the Motorola and Hitachi data sheets and against the first boards.

Hardware Architecture

The board pairs the family's processor platform (RP2350B, PSRAM, Flash, ESP32, SD card, USB hub) with a 6809-specific buffered bus interface. The interface has to serve two very different hosts: on a 6809E host the host supplies the E and Q clocks and the CPU drives the LIC, AVMA and BUSY status lines; on a 6809 host the CPU generates E and Q from a crystal or EXTAL clock, and the same pins become the inputs MRDY and DMA/BREQ. JP1 sets which way the clock buffer drives.

GPIO Assignment and Buffers
GPIO Signal 6809E mode 6809 mode Path to socket
0–15 A0–A15 out out 74AHCT244 ×2, enable-gated, 22Ω
16–23 D0–D7 bidir bidir 74AHCT245, DIR = /(R/W), /CE = /(E·EN)
24 R/W out out 74AHCT244, enable-gated
25 BA out out 74AHCT244, always enabled
26 BS out out 74AHCT244, always enabled
27 LIC / EXTAL out (LIC, pin 38) in (EXTAL read-back) clock/status buffer + 2.2K return
28 AVMA / MRDY out (pin 36) in (MRDY) buffer out + 10K return
29 BUSY / DMA-BREQ out (pin 33) in (DMA/BREQ) buffer out + 10K return
30 Q in out 22Ω return; driven by the clock buffer in 6809 mode; 10K pull-down
31 E in out 1K return; driven by the clock buffer in 6809 mode; 10K pull-down
32 /FIRQ in in 0Ω
33 /IRQ in in 0Ω
34 /HALT in in 1K
35 BUSFLOAT out out NOR to the buffer enables; 10K pull-up (bus floated until driven low)
36 /NMI in in 0Ω
38 /RESET in in 0Ω
  • Data buffer enable. The '245 opens only while E is high and the bus is enabled. That is correct for reads, but it means write data reaches the socket about 10 ns after E rises rather than at Q rise plus tDDQ as on a real 6809E, and is actively held only 6–16 ns after E falls (against the specified 30 ns), after which bus capacitance holds it. These are inherent in the board and are on the bring-up list.
  • BUSFLOAT. A NOR gate combines the firmware's BUSFLOAT (GPIO35) with the socket's TSC (through JP2; TSC is tied low on the Dragon). The pull-up on GPIO35 keeps the bus floated from power-on until the firmware drives it low, once the core is configured, so the host never sees the RP2350's reset pin states.
  • JP1. In the 6809 position on a 6809E host, the board's clock buffer drives E and Q into the host's clock outputs from power-on. The firmware's E self-detect can only report this, so JP1 must be set before the board is fitted.

Firmware Architecture

The firmware follows the family layout. Core 0 handles USB, the ESP32 link (FSPI and UART), file I/O, configuration and firmware updates, and runs the drivers' Core 0 jobs. Core 1 runs the CPU core (M6809.c), the routing layer (M6809CPU.c) and the bus layer (M6809CPU_bus.inl), all resident in SRAM: an execute-in-place stall caused by Core 0's flash traffic once corrupted bus envelopes on the pico6502, so nothing on Core 1's hot path runs from flash.
At start-up parseJSONStore captures every file the persona names (driver and interface ROMs, memory-block files) into the partition's flash ROM store, so Core 1 never reads the ESP32 while initialising. A persona that needs Core 0 work before the CPU starts (the virtual DOS loading its disc images, for example) sets g_m6809StartHold, and Core 1 holds the CPU until it clears.

The CPU Core

A Bus-Cycle Generator
The pico6502's hardest lesson was that C cannot make bus-phase decisions: read data arrives at a clock edge and the next address is due a few hundred nanoseconds later. On the Dragon the window from E falling to address-valid is about 200 ns at the SAM's slow rate (about 60 RP2350 cycles at 300 MHz) and about 90 ns in fast mode. The 6809 core is therefore designed around the bus from the start:
  1. Every instruction is a cycle script. The core emits one descriptor per bus cycle: a kind (FETCH, READ, WRITE, DUMMY, VECTOR or DISCARD), the address, the data for writes, and the status that belongs to that cycle (BA/BS, LIC, BUSY). The cycle tables come from the data sheets' cycle-by-cycle flow and are checked mechanically against XRoar, never hand-tuned.
  2. The protocol has a "nothing" cycle. A 6809 "don't care" cycle drives $FFFF with R/W high and AVMA low. If the core has not queued the next descriptor when the address state machine must drive, the PIO emits exactly that. The host sees one more VMA-false cycle, the same thing the real CPU produces many times per instruction. Lateness costs speed, counted as late-dummies, and never correctness. This is the critical property on the Dragon: a dummy at any address other than $FFFF could land in $FFC0–$FFDF and silently reprogram the SAM.
  3. AVMA is announced from queue depth. AVMA has to announce cycle n+1 during cycle n, so the address state machine raises it only when the next word is already in its FIFO. In the default RELAXED mode the window keeps polling and AVMA may be false-low (the Dragon ignores AVMA); STRICT mode turns every unannounced cycle into a late-dummy, at a measured cost of 49% of cycles.

MC6809 and HD6309
One core serves both parts: cpu->h6309 selects the 6309 instruction set and cpu->native (MD bit 0) its native-mode cycle tables. In emulation mode the 6309 keeps 6809 cycle counts. Native mode adds E, F, W (E:F), Q (D:W) and V, the TFM block moves, MULD/DIVD/DIVQ, the bit operations and inter-register ALU operations, LDQ/STQ and OIM/AIM/EIM/TIM; illegal opcodes and divide-by-zero trap through $FFF0, and MD bit 1 makes FIRQ stack every register. Native mode removes many dummy cycles, so it has less slack for the bus engine; that is measured on the bench rather than assumed.

Interrupt and HALT Sampling
The real chip latches /IRQ and /FIRQ on every bus cycle, and the first version of the core sampled them once per instruction: the Dragon's field-sync IRQ, which rises during the $FFFF dummy of an LDA $FF00, was taken one instruction late. The core now latches as of each cycle (the last latch before an instruction's end is what counts), accumulates /NMI edges with the 6809's arming rule, reads /HALT at instruction boundaries and after each SYNC or CWAI idle cycle, and drops the NMI edge flag where XRoar does. Two sampling contracts are offered to the bus layer:
  • Default: the line sampler runs before every bus cycle, exact with any bus layer.
  • M6809_LINECAP_NMIEDGE + M6809_LINECAP_POSTLIC (used on the board): a PIO state machine catches /NMI edges, and the core samples the lines only at the latch-critical cycles. Because C runs ahead of the bus, "sample now" would be several cycles early, so the core flags those cycles' descriptors (M6809_DESC_SAMPLE); the bus layer marks the FIFO word (bit 31, raising PIO0 IRQ 6 as the cycle is driven) and samples GPIO32–36 at that moment, which is XRoar's "latch before each cycle" point.
The host suite changes the lines at random bus cycles mid-instruction in both contracts and compares every cycle with XRoar.

PIO Bus Interface

PIO Programs
PIO (GPIO base) SM Program Size Role
0 (0) 0 m6809_addr 20–23 One E cycle per pass: lockout Q↑ E↑ Q↓ E↓, R/W pulse, a polling window, the descriptor drive (out pins, 30) or the $FFFF late-dummy (mov pins, isr), the latch strobe and the AVMA announce (side-set)
0 (0) 1 m6809_latch / m6809_latch_fall 7 / 6 Read capture, one word per capture cycle; by default sampled 2–4 cycles before the E fall at the pad, optionally at the fall
1 (16) 0 m6809_nmi 3 /NMI falling-edge catcher
1 (16) 1 m6809_float 5 BUSFLOAT = BA·BS while the bus is on, 5–6 cycles behind the address drive
2 (16) 0 m6809_data 5 Write data, slaved to R/W
2 (16) 1 m6809_clock / m6809_clock_extal 5 / 13 6809 mode only: E and Q at E = sysclk/(8·clkdiv), or locked to EXTAL on GPIO27, with MRDY stretch
2 (16) 2 m6809_detect 3 Boot self-detect: counts E falls for 2 ms
Instruction memory use: PIO0 30 of 32 slots, PIO1 8, PIO2 at most 21.

The FIFO Word
Each word pushed to the address state machine is the pin image of GPIO0–29, so one out pins, 30 changes the address and every status line together:
Bits Content
0–15 A0–A15
16–23 zero (GPIO16–23 belong to PIO2, so PIO0’s writes never reach the data pads)
24–29 R/W, BA, BS, LIC, AVMA (0, raised by side-set), BUSY
30 K: capture this cycle’s read data
31 M: mark, raises PIO0 IRQ 6 at the drive (post-LIC sampling)
busCycle builds the word with one 128-entry table lookup on the descriptor's kind and status bits and an OR with the address. In 6809 mode GPIO27–29 are inputs (EXTAL, MRDY, DMA/BREQ), so only GPIO24–26 get PIO output directions and STRICT AVMA is forced off.

Edge-Driven Timing
The SAM can change the E period from one cycle to the next: 0.894886 MHz in slow mode (14.31818 MHz ÷ 16), 1.79 MHz in fast mode, and per-address in the address-dependent mode, which runs ROM cycles fast and RAM cycles slow. Every PIO decision therefore waits on the E and Q edges actually present at the socket, never on a count from an assumed period, which is the lesson of the BBC Master's stretched PHI2 on the pico6502. Other design points settled on the bench:
  • Run-state late pattern. A late-dummy carries the current BA/BS (00 run, 10 SYNC, 11 HALT or bus grant): the ISR holds the pattern and is reloaded at SYNC/HALT entry and exit.
  • BUSFLOAT in PIO. The float follows BA·BS from its own state machine, so floating and un-floating land in the first quarter behind the address drive, never mid-cycle.
  • Pre-fall read sampling. Sampling exactly at E's fall raced the 1K E return against the '245 closing and failed at the worst board corner, so reads are captured just before the fall.
  • No IRQ/FIRQ/HALT watchers. busLines reads GPIO32–36 directly; only /NMI needs an edge catcher.

Socket Margins (PIO Bench)
tAQ tAH read setup read hold read vs ‘245 close write setup write vs SAM CAS
6.7 ns 16.7 ns 63 ns 23 ns 17 ns 187 ns 60 ns
Minimum margins for a Dragon at a 300 MHz system clock on a typical board. The bench sweeps 250, 300 and 340 MHz, four board corners and 1, 1.5 and 2 MHz parts; the worst corner (250 MHz, slow board) has 2.0 ns of tAQ margin. The host's cycle stream equals the core's descriptor stream, with every padding cycle at $FFFF and no other address ever.

Read Shadow and Speculation

Without help, every read the core waits for costs a late-dummy once C's turnaround (capture to next push, about 150 ns per descriptor plus 100 ns after a read) passes the drive window: 32% of bus cycles, about 68% of a real Dragon. Phase 6 removed this with three mechanisms:
  • The read shadow (M6809CPU_shadow.inl): a 64 KB SRAM copy of host memory with an 8 KB validity bitmap. The first read of a byte is a real capture; later reads are served from the copy while the cycle still goes out with its own address, R/W and status (only the capture is skipped); writes go through to host and copy. Nothing then waits for the socket except I/O reads, first touches and vectors after an invalidation, so C runs ahead by up to the 8-word FIFO and the PIO drains one descriptor per E cycle. The coherency rules exclude the I/O page and the SAM registers, and Core 0's physical accesses are kept in step. Keys: "shadow": "off" | "on" | "verify".
  • Next-read speculation. After an instruction's LIC read, the next cycle is always a read at the PC (the next opcode fetch, or an interrupt entry's discarded PC read on the same pins), which the test suite confirms over 20 million LIC reads with no misses outside HALT. The bus layer queues it as soon as the waited-for I/O read is driven, so polling loops such as LDA $FF20 pay no late-dummy. A miss is an extra harmless read of code memory.
  • Dummy absorption. If a waited-for read is followed by a late-dummy and the core's next cycle is a plain DUMMY, the two are pin-identical and the bus layer does not issue it again.
Workload Shadow Late-dummies Speed vs a real Dragon
Dragon test ROM off 30.7% ~69%
Dragon test ROM on 0.7% 99.3%
Dragon 32 BASIC cold start, SAM slow on 0.3% 99.7%
Dragon 32 BASIC cold start, SAM address-dependent on 0.4% 99.6%
Dragon 32 BASIC cold start, SAM fast on 0.6% 99.4%
The same at 250 and 340 MHz and at every board corner; with the shadow on, the result stays flat up to about 400–500 ns of C time per descriptor in fast mode and beyond 600 ns in slow mode. In verify mode the Dragon simulator's regression (BASIC, DragonDOS, the Dragon 64's 64K mode, the virtual DOS and cassette, on both CPUs) gives 0 mismatches over 170 million shadow-served reads. The shadow costs 64 KB + 8 KB of SRAM and about 1.3 KB of code.

Memory Model

The address space is mapped in 512-byte blocks (MEMORY_BLOCK_SIZE) over 64 PSRAM banks of 64 KB. M6809CPU_cycle, resident in SRAM, routes each descriptor by its block's type and adds BA/BS per cycle (SYNC = 10 from the core state, HALT/grant = 11 from the bus acknowledge).
Type Physical mode Virtual mode
PHYSICAL host bus host bus
PHYSICALVRAM host bus (displayed memory) host bus
PHYSICALHW host bus, never shadowed host bus, never shadowed
RAM PSRAM; cycle goes out as DISCARD PSRAM only
VRAM reads PSRAM; writes PSRAM and host reads PSRAM; writes PSRAM and host
ROM PSRAM, writes ignored; cycle goes out as DISCARD PSRAM only
FUNC driver handler driver handler
In physical mode every cycle goes to the bus, dummies included: firmware-served reads are re-kinded DISCARD (driven, not captured) and writes go out as written, so the host's view is byte-identical. A physical snoop lets a driver attach a handler to a PHYSICAL address: it is called after the host cycle, and on a read its value replaces the host's byte. That is how the Dragon persona merges the virtual cassette and DOS bits into PIA1 reads without a second cycle, at the cost of one SRAM bitmap test per physical cycle.

The Dragon Personas

The Host
The Dragon 32 and 64 use an MC6809E clocked by the SAM (MC6883) from 14.31818 MHz. The SAM refreshes DRAM and feeds the VDG while E is low, so the CPU owns the bus while E is high; a stock machine has no DMA. RAM is at $0000–$7FFF (64K on the Dragon 64 through SAM map type 1), BASIC at $8000–$BFFF (the Dragon 64 has a second ROM switched by PIA1 PB2), the cartridge at $C000–$FEFF, PIA0 at $FF00, PIA1 at $FF20, the Dragon 64's 6551 ACIA at $FF04, and the SAM's write-only, set/clear-by-address registers at $FFC0–$FFDF. IRQ is field and line sync via PIA0, FIRQ is the cartridge CART line via PIA1, and NMI comes from the cartridge (the DragonDOS controller); DragonDOS does not use HALT for DRQ pacing.

PSRAM Layout
Offset Size Use
0x000000 64 KB Dragon RAM (virtual mode)
0x010000 16 KB ROM A (Dragon 32 BASIC, or Dragon 64 32K-mode)
0x014000 16 KB ROM B (Dragon 64 64K-mode)
0x018000 8 KB DragonDOS ROM
0x080000 4 × 768 KB Disc image slots, drives 1–4
0x380000 256 KB Tape play buffer
0x3C0000 256 KB Tape record buffer
The layout assumes the 6809 persona owns the whole 4 MB PSRAM pool.

Physical and Virtual Modes
Physical: RAM, ROM and I/O are the Dragon's. The persona shadows SAM writes, so that a virtual DOS ROM at $C000 steps aside while a Dragon 64 is in map type 1 as a real cartridge would, and shadows PIA1 for the cassette and the cartridge FIRQ.
Virtual: RAM (bank 0) and ROMs are served from PSRAM, and the I/O page $FF00–$FFDF stays on the bus. The persona performs the SAM's and the Dragon 64's mapping: TY=0 RAM/ROM/cartridge, TY=1 64K RAM, P1 paging, $FFE0–$FFFF always the selected ROM's last 32 bytes (the SAM's vector routing), and PIA1 PB2 as ROM select (an input reads as the pull-up, the 32K ROM). SAM register writes still reach the host, which uses them for the video base and mode.
Video in virtual mode ("video"): with track, the SAM shadow gives the displayed area (the F offset × 512, sized by the V mode); each 512-byte block becomes VRAM the first time it is displayed, is copied PSRAM → Dragon once, and stays VRAM (blocks below $0400 drop back to RAM when the display leaves them). A PMODE 4 page-flip test (PCLEAR 8, pages 1 and 5) gave displayed RAM identical to XRoar's own run, with 38,977 host writes in virtual mode against 1,202,217 in physical. all writes every RAM byte through; none gives no host display. The virtual personas map $0400–$1DFF (the text screen and BASIC's four default PMODE pages) as VRAM.

Virtual DragonDOS
DragonDOS.c serves the 8 KB DOS ROM at $C000 (mirrored to $FEFF), a WD2797 at $FF40 (mirror $FF50) and the latch at $FF48 (b0–1 drive, b2 motor, b3 single density, b5 NMI enable). Four .vdk / JVC .dsk images are read whole into their PSRAM slots by a Core 0 job at boot and written back per 256-byte sector from the driver poll; DSKINIT grows an image in cylinders, and a one-head VDK to two heads. The image handling lives in a shared module, src/drivers/FDImage.c, which also publishes the drives to the web GUI's Floppy menu (one row per drive, as a Dragon image holds both sides) and performs run-time changes and ejects: the outgoing disc's dirty sectors are written to the SD card before the new image is loaded.
Cartridge changes. The web GUI's Cartridge menu sends CHGC,<file> (an empty name removes the cartridge). The 6809 is held while the DOS ROM and its address windows change, BASIC's warm-start flag is cleared so the old DOS's RAM hooks cannot survive a warm restart, and the Dragon is reset as the CPU is released. With the cartridge removed, the $C000–$FEFF window and the controller registers return to the host bus, so the Dragon's own cartridge port answers.
The WD2797 is a variant (WD177X_2797) of the WD177x model in src/drivers/WD177x.c, backward compatible with the BBC's 1770: status bit 7 is NOT READY (READY tied high) instead of MOTOR ON; no spin-up or motor timeout (the latch has the motor); the side comes from the Type II/III U bit; Type I bit 5 is not reported; bytes follow the disc's byte clock (one byte time after the previous DRQ, not after the host's access, without which a Write Track came out short); and Write Track formats blank media. The chip runs in emulated time: its clock is the core's E-cycle counter, so it takes the cycles it takes on a Dragon in either bus mode.
FIRQ through PIA1 CB1. On a real Dragon the cartridge's CART line is PIA1 CB1, which the pico cannot drive. From a disassembly of DragonDOS 1.2a: the DOS sets CRB to $37 (CB1 IRQ enabled, rising edge), polls the first DRQ with LDA <$23 / BMI, then moves each byte with SYNC / LDA <$43 / LDB <$22 with FIRQ masked (SYNC wakes on /FIRQ whatever the mask; reading PRB clears the flag). The persona models exactly that flag: CRB is shadowed from the $FF23 writes (which still reach the host PIA), a DRQ edge of CRB bit 1's polarity sets it, it is ORed into bit 7 of every $FF23 read, a $FF22 read clears it, and flag AND CRB bit 0 is a soft /FIRQ. INTRQ AND latch b5 is a soft /NMI level, converted to an edge for the NMIEDGE contract.

The WD2797 Catalogue Device
The same WD177X_2797 controller model and FDImage module are offered to any 6809 board as the WD2797 device in the virtual device catalogue (src/devices.c). Its interlink pins are DS0, DS1, SIDE, DDEN, MOTOR, READY and RESET (in) and INTRQ and DRQ (out); the web editor wires INTRQ to /NMI by default and leaves DRQ to the user. Device settings are chip (2797, 1770, 1772, 1773), count (1–4 drives, 768 KB of PSRAM each), drives (an image per drive, with a write-protect flag) and speed (timing). One instance is supported per board, and it refuses to start on a Dragon persona, where the virtual DragonDOS already owns the controller. Because Base6809 now carries this device, its firmware includes the floppy-controller code and uses a little more on-chip RAM than before.

Virtual Cassette
DragonCMT.c plays the .cas bytes as the Dragon's tone, a '0' = 813 E cycles and a '1' = 435 (XRoar's CAS timing), each as a low then a high half. The tape position is a function of the core's E-cycle count while the motor (PIA1 CA2) runs; it is computed when $FF20 is read and merged into bit 0 of the host's byte, in both bus modes, which is exact for the ROM's cycle-counted bit timing at any core speed. At each motor-on in or before a leader, pad ms of synthetic $55 covers BASIC's motor delay. Recording decodes DAC writes to $FF20 while the motor runs (the ROM's sine rises through $80 at each bit start and falls half way; rise-to-fall under 300 cycles is a '1'), aligns on the first $3C after a leader, and writes the file at each motor stop. Because the timing is in E cycles, a program that runs the SAM fast during a load sees the tape too fast. The tape queue can be edited while the machine runs from the web GUI's CMT menu (CMTA add, CMTS select, CMTD remove); a selected tape is loaded at once.

Configuration Reference

ESP32 Core
esp32.core.device is "6809" or "6309" (device codes 0x30 / 0x31, shown as p6809 / p6309). The RP2350 reports CPU family 3 in its INF reply, which names the product "pico6809" in the web interface. The access point defaults to SSID p6809, password p6809p6809, address 192.168.4.4.

The rp2350."6809" Array
Key Type Description
cputype string 6809/mc6809/mc68b09, 6809e/mc6809e/mc68b09e (default), 6309/hd6309/hd63c09, 6309e/hd6309e/hd63c09e
shadow string off (default), on, verify
busmode string virtual forces virtual bus mode
core.voltage / core.cpufreq / core.psramfreq number RP2350 core voltage, system clock (Hz), PSRAM clock (Hz)
memory[] array addr, size, type (memory types above), func, bank, task, file
drivers[] array name, enable, type (PHYSICAL/VIRTUAL), rom[], video, if[]
device[], interlink[] arrays Virtual chips and their wiring, as on the pico6502; 6809 pins are IRQ, FIRQ, NMI, HALT, RESET, BA, BS and CLK

Dragon Interface Cards
Interface Key Description
DRAGONDOS rom[0] DragonDOS ROM image (8 KB)
  param[0..3] Drives 1–4: file, enable, optional readonly
  speed 1 = real drive timing
  trace 1 = log controller commands and results
CMT-CAS param[] Tape queue, up to 8 .cas files
  record File written by CSAVE
  pad Leader at each motor start, ms (default 500)
The Dragon drivers also accept Dragon with a "model" key in place of Dragon32 / Dragon64. On the Dragon 64, rom[0] is the 32K-mode ROM and rom[1] the 64K-mode ROM.

Hardware Bring-Up Plan

  1. Bench check with the bus floated, then the physical bus on a Dragon: correct cycle shape, $FFFF dummies, status lines. Watch the open risks from the bench: E glitches, the read-sample corner, write hold and the SAM's decision point.
  2. Bring the read shadow up in verify mode, then measure the real C cost per descriptor (pcprof) against the bench's sweep.
  3. The Dragon6809 firmware with the virtual DragonDOS (no cartridge fitted) and the cassette; then run-time disc and tape changes in the web GUI.
  4. Phase 8: a 6809-mode (crystal) host, with the clock rate selectable from the persona, MRDY and DMA/BREQ.