# m6809-python **Status: documents and oracles only. There is no core code yet.** `m6809-python` will be a readable, dependency-free Python 3.12+ instruction core for the Motorola **MC6809 / MC6809E**, built to the same embedding contract as [z80-python](https://github.com/alewman/z80-python) and 6502-python: the host owns memory and I/O and supplies `read_byte` / `write_byte`; the core owns registers, flags and the instruction-boundary lifecycle (RESET, NMI, FIRQ, IRQ, SWI, CWAI, SYNC); `step()` executes one instruction or one interrupt entry and returns its E-cycle count; the host schedules everything else. This repository is the groundwork: the primer, the timing and host notes, the undocumented-behaviour record, the oracle inventory with its tiers and pins, the fetch and trace scripts, and a handoff brief for the session that writes the core. ## The chip and where it ran The 6809 is the CPU of Williams's first-generation arcade boards (Defender, Stargate, Robotron: 2084, Joust, Bubbles, Sinistar, Blaster) and their second generation (Mystic Marathon, Inferno, Joust 2), of Konami's 6809 sub and sound CPUs in the Gyruss / Time Pilot era, of Namco System 86 (two 6809s), of many Data East boards, of the Vectrex, the Dragon and the TRS-80 Color Computer, and of the FLEX and OS-9 operating systems. | Variant | What differs | Here | | --- | --- | --- | | MC6809 | On-chip clock generator: crystal at 4x the bus rate, E and Q outputs | in scope | | MC6809E | E and Q are inputs; adds LIC, AVMA, BUSY, TSC pins for board-level bus control. Same instruction set and cycle counts. The part Williams, Konami and Namco used | in scope (the primary target) | | MC68A09(E), MC68B09(E) | 1.5 MHz and 2 MHz speed grades of the same silicon | in scope (no difference to an instruction core) | | Hitachi HD6309 | Pin-compatible superset: E, F, W, Q, V and MD registers, 168 extra opcodes, a `$FFF0` trap, and a faster "native" mode. MAME 0.285 names one on 27 arcade parents (Double Dragon, Contra, The Real Ghostbusters, Lethal Enforcers, ...) and on the HD6309 CoCo and Dragon variants | **out of scope** for the first core; [docs/hd6309.md](docs/hd6309.md) says what it is, what it would cost, and why it belongs here as a mode rather than as a separate project | | Konami-1 (052001) | A Konami custom 6809 with a re-mapped opcode set (Ajax, TMNT era) | **out of scope**, noted; distinct from the plain 6809 on Gyruss | [docs/start-here.md](docs/start-here.md) has the full comparison. ## Documents - [docs/start-here.md](docs/start-here.md): the 6809 primer with the complete instruction table, postbyte costs, stack masks, interrupts. - [docs/timing.md](docs/timing.md): cycle rules and the Williams host contract, restated from MAME 0.285 and measured. - [docs/undocumented-behavior.md](docs/undocumented-behavior.md): illegal opcodes and undefined flags, each with a source and its tier. - [docs/hd6309.md](docs/hd6309.md): the Hitachi HD6309 superset, what it would cost to support as a mode, and the recommendation. - [docs/validation.md](docs/validation.md): every oracle found, its tier, licence, revision and limits; the plan. - [docs/mame-oracle.md](docs/mame-oracle.md): MAME 0.285 as an emulator-derived oracle, with the verified trace recipe. - [docs/handoff-brief.md](docs/handoff-brief.md): what the build session does, in order. - [docs/README.md](docs/README.md): index. ## Oracles, in one paragraph There is **no hardware-captured single-step corpus for the 6809** (SingleStepTests has none, confirmed 2026-09-12). What exists: a MAME-generated corpus in SingleStepTests format (`neetandev/m6809`, 315 opcodes, 249,871 cases, MIT-0 data, pinned at `9dd7b59` and fetched by `scripts/fetch_m6809_vectors.py`; emulator-derived, so a detector); David Banks's and David Flamand's **hardware-captured** records of the undocumented opcodes and undefined flags (judges for what they cover, cited not fetched, unlicensed repositories); MAME 0.285 itself, traced headlessly from Robotron and Joust with `scripts/mame_trace.sh` (emulator-derived); and XRoar and vecx as independent emulators for a three-way cross-check. The judge for the documented instruction set is therefore the Motorola datasheet and programming manual; agreement with emulators will be stated as agreement, never as verification against silicon. ## Scripts ```text python scripts/fetch_m6809_vectors.py # pinned corpus into tests/vectors/ (gitignored) scripts/mame_trace.sh robotron 20 work/ # MAME 0.285 trace, see docs/mame-oracle.md ``` Neither ROMs, traces, nor the corpus are committed. ## License MIT (see `LICENSE`). Cited documents and external test material keep their own licences and are not bundled.