# The Hitachi HD6309: a 6809 superset, and whether this core should model it The HD6309 is the part a 6809 core actually meets in arcade hardware more often than its own documentation suggests. It is pin-compatible with the 6809, executes 6809 object code, and was fitted to boards whose schematics and MAME drivers name a 6809. It also contains four extra registers, 168 extra opcode encodings and a second execution mode that Hitachi never documented. This page says what it is, what it adds, where it stops being a 6809, what the evidence for each claim is worth, and — at the end — whether this repository should grow a 6309 mode. [start-here](start-here.md) is the 6809; nothing here restates it. Read it first for the register file, the CC byte, the indexed postbyte and the instruction table this page adds to. ## Sources, and what each one is worth The tier rule of [validation](validation.md) applies unchanged: hardware-captured > hardware-corrected > emulator-derived, and a low-tier oracle is a detector, never a judge. **No hardware-captured 6309 source was found.** There is no single-step corpus (SingleStepTests has none; `neetandev/m6809` is 6809 only), no logic-analyser study of native mode comparable to hoglet67's 6809 work, and no manufacturer document that describes native mode at all. Every account of the 6309's extra behaviour below is **community reverse engineering**, and where three such accounts disagree the disagreement is recorded rather than resolved. This is a weaker evidence base than the 6809 has, and it is the main reason the recommendation at the bottom is "later, as a mode, and without a conformance claim". | Source | Tier | What it covers | Licence | | --- | --- | --- | --- | | **HD63B09E / HD63C09E datasheet** (Hitachi America, "CMOS MPU"), scan and OCR text: ; also in the 1987 Hitachi 8/16-bit microprocessor data book, (41 MB; bitsavers refuses a bare `curl`, send a browser user-agent) | **datasheet** | The 6809-compatible part only. Read for this page (the OCR text): it says "just compatible with the conventional HD6809E", "Object Code Compatible with the HD6809E", gives E and Q inputs, 0.5-3 MHz, SYNC/CWAI low-power modes, and a programming model of exactly A, B, D, DP, X, Y, U, S, PC, CC. It contains **no** mention of E, F, W, Q, V or MD, of MULD, DIVD, DIVQ or TFM, of native mode, or of a vector at `$FFF0` | Hitachi copyright; cited, not reproduced | | Hirotsugu Kakugawa, *A Memo on the Secret Features of 6309*, `comp.sys.m6809`, February 1992: | community, first publication outside Japan | The announcement that started the Western documentation effort. Not used for any number on this page | usenet archive | | Chet Simpson, additions by Alan DeKok, *HD63B09EP Technical Reference Guide*: (plain text, fetched 2026-09-12) and ; HTML copy at | community reverse engineering | Registers, MD bits, the mode and FIRQ questions, the four TFM forms, an opcode table with cycles in both modes. The document MAME's `hd6309.cpp` header cites. Has typos, listed below | none stated | | Chris Burke, *The 6309 Book: Inside the 6309 Microprocessor*, 2nd edition, Burke & Burke, 1992-1993: | community reverse engineering | The fullest prose account: per-instruction pages, the trap chapter, native-mode interrupt stacking, patching advice for OS-9. Its `SEXW` page is wrong (below) | Burke & Burke copyright; cited | | Darren Atkinson, *Motorola 6809 and Hitachi 6309 Programming Reference*, 2010: (already cited by [undocumented-behavior](undocumented-behavior.md)) | community reverse engineering, the most careful | Part II "6309 Specifics" and the Part III quick reference, whose cycle column is printed as *emulation / native*. The best single table of encodings, cycles, bytes and flags, and the source of every cycle count below unless another is named | free distribution PDF | | **MAME 0.285**, `src/devices/cpu/m6809/hd6309.cpp`, `hd6309.lst`, `hd6309.h`, `6x09dasm.cpp`, shared `base6x09.lst` | emulator-derived | A working model of everything above. Header: "copyright-holders:Nathan Woods,Tim Lindner", "Copyright John Butler", "Copyright Tim Lindner", references the *HD63B09EP Technical Reference Guide*. **BSD-3-Clause: transcription into this repository is permitted with attribution**, and a 6309 mode here may follow its structure as long as the licence header and the copyright holders are carried over | BSD-3-Clause | Where MAME's own comments say the timing is a guess (`AIM`/`OIM`/`EIM`/ `TIM`: "this is just a guess"; `TFM`: "I have no information on the precise sub-instruction timing here"; `JSR` indexed in native mode: "this is dubious, but the old core did this") the claim is marked `[unverified]` here too. ## What the part is A CMOS 6809 made by Hitachi under licence from Motorola, pin-compatible and object-code compatible, sold in the same packages and speed grades: `HD6309` with an on-chip divide-by-four oscillator, `HD6309E` with E and Q as inputs, in B (2 MHz) and C (3 MHz) grades, so `HD63B09EP` and `HD63C09EP` are the parts found on boards. Everything in [start-here](start-here.md)'s 6809/6809E table about clocking applies unchanged. Hitachi found spare silicon after implementing the licensed 6809 core and filled it with extra registers, an extra instruction set, an illegal-instruction trap and a faster **native mode** — and, the community accounts agree, could not publish any of it under the terms of the Motorola licence. The datasheet quoted above is consistent with that: it documents a 6809 and nothing more. The features were described first in *Oh!FM* (a Japanese Fujitsu-machine magazine) in April 1988, then by Kakugawa on `comp.sys.m6809` in 1992, and then by the three community documents in the table. The two modes: - **Emulation mode** (MD bit 0 = 0, the state after RESET). Cycle counts and interrupt stacking are the 6809's. **All of the new instructions and registers still work**; only the timing and the interrupt frame are 6809-shaped. This is the mode that made 6309s look like "flaky 6809s": a program that ran into a 6809 undocumented opcode found a real instruction, or a trap, instead of the 6809's quiet behaviour. - **Native mode** (MD bit 0 = 1, set only by `LDMD`). Most instructions lose a cycle; interrupts stack E and F as well, which moves every offset in an interrupt frame by two bytes. The practical fact for anyone reading old hardware: **a 6309 in a 6809 socket is invisible until something looks**. Hitachi sold the part as a 6809 second source, and boards were populated with whichever was to hand. MAME 0.285 carries explicit 6309 variants of home machines for exactly this reason — `cocoh` "Color Computer 1/2 (HD6309)", `coco2bh`, `coco3h`, `dragon64h`, `tanodr64h` — and names an `hd6309`/`hd6309e` on 27 parent arcade drivers, below. Atkinson prints a `TSTNM` subroutine whose trick is `TFR W,Y`: on a 6309 that copies W, on a 6809 the undefined register code 6 reads as `$FFFF`, so the program can tell which chip it is running on. ## Which systems used it, measured From `mame -listxml` (MAME 0.285), every machine with a `` whose name begins "Hitachi HD6309": ```text /usr/games/mame -listxml > listxml.xml # 314 MB, about 90 s # then: machines with a chip named "Hitachi HD6309*" ``` **106 machines, of which 27 are parents; 109 CPU instances (99 `HD6309E`, 10 `HD6309`).** The 27 parents, plus the five home-computer machines (which are clones of `coco` and `dragon32`, not parents): | Driver file | Machines named (year, maker) | Tag and clock | | --- | --- | --- | | `technos/ddragon.cpp` | `ddragon` Double Dragon (1987, Technos/Taito), `ddragon2` (1988), plus `darktowr`, `ddungeon`, `tstrike`, `toffy`, `stoffy` (1991-1994 conversions) — 23 machines with clones | `maincpu` HD63C09EP at 3 MHz | | `technos/chinagat.cpp` | `chinagat` China Gate (1988) | `maincpu` **and** `sub`, both `HD6309` at 6 MHz | | `konami/contra.cpp` | `contra` (1987) — 10 machines | `maincpu` at 24 MHz/8 | | `konami/mainevt.cpp` | `mainevt` The Main Event (1988), `devstors` Devastators (1988) | `maincpu` 3 MHz | | `konami/lethal.cpp` | `lethalen` Lethal Enforcers (1992) | `maincpu` 24 MHz/8, "verified on pcb" | | `konami/combatsc.cpp` | `combatsc` Combat School (1988) | `maincpu` 3 MHz | | `konami/battlnts.cpp` | `battlnts` Battlantis (1987), `rackemup` Rack 'em Up (1987) | `maincpu` 3 MHz | | `konami/bladestl.cpp` | `bladestl` Blades of Steel (1987) | `maincpu` 3 MHz | | `konami/bottom9.cpp` | `bottom9` Bottom of the Ninth (1989) | `maincpu` 3 MHz | | `konami/flkatck.cpp` | `mx5000` (1987) | `maincpu` 3 MHz | | `konami/labyrunr.cpp` | `tricktrp` Trick Trap (1987) | `maincpu` 3 MHz | | `konami/rockrage.cpp` | `rockrage` Rock'n Rage (1986) | `maincpu` 3 MHz | | `konami/fastlane.cpp` | `fastlane` Fast Lane (1987) | `maincpu` 3 MHz | | `konami/ajax.cpp` | `ajax` Ajax (1987) | **`sub`** 3 MHz (the main CPU is the Konami-1 custom) | | `dataeast/dec8.cpp` | `ghostb` The Real Ghostbusters (1987), `gondo` Gondomania (1987), `garyoret` (1987), `meikyuh` (1987) | `maincpu` HD63C09EP 3 MHz | | `itech/itech8.cpp` | `rimrockn` Rim Rockin' Basketball (1991, Strata/Incredible Technologies) | `maincpu` non-E `HD6309` at 12 MHz (divided by four on chip); its sound CPU is a plain MC6809 | | `trs/coco12.cpp`, `trs/coco3.cpp`, `trs/dragon.cpp` | `cocoh`, `coco2bh`, `coco3h`, `dragon64h`, `tanodr64h` (clones of `coco`/`dragon32`) | `maincpu` HD6309E at 894,886 Hz (888,625 Hz for the PAL Dragon) | **Do those arcade programs use the 6309?** Measured, not assumed. Twelve of the drivers above were run headless for 4 emulated seconds each with the recipe from [mame-oracle](mame-oracle.md) (`-video none -sound none -nothrottle -debug -debugger none -seconds_to_run 4`) and a Lua script that traced every instruction and read the CPU's `MD` state entry each frame: ```text ddragon 3,381,155 contra 2,803,040 ghostb 3,537,110 gondo 2,823,666 rimrockn 3,012,106 lethalen 3,162,696 combatsc 3,161,892 bottom9 2,956,596 mainevt 2,974,752 chinagat 1,638,018 battlnts 3,103,205 bladestl 2,853,891 ``` **35,408,127 instructions in total. `MD` stayed `$00` in every one of the twelve, and MAME's 6309 disassembler emitted no 6309-exclusive mnemonic anywhere in the traces** (grepped for all 83 of them: `TFM`, `MULD`, `DIVD`, `DIVQ`, `ADDR`/`ADCR`/`SUBR`/`SBCR`/`ANDR`/`ORR`/`EORR`/`CMPR`, the `B*` bit group, `LDMD`, `BITMD`, `AIM`/`OIM`/`EIM`/`TIM`, `SEXW`, and every E/F/W/Q/D form). So these boards have a 6309 in the socket and run plain 6809 code through it. Limit of that measurement: 4 seconds is boot, self-test and the start of attract mode, not gameplay, and `ajax`'s 6309 is a `sub` CPU that was not traced. It is evidence, not proof, and it is emulator-derived: it says MAME sees no 6309 instruction, not that the ROM contains none. ## The added state | Register | Width | Notes | | --- | --- | --- | | **E**, **F** | 8 | Two more accumulators, behaving as A and B do | | **W** | 16 | E:F, exactly as D is A:B. Also usable as an index base and as the `TFM` counter | | **Q** | 32 | D:W = A:B:E:F. The destination of `MULD`, the dividend of `DIVQ`, loadable and storable as one operand | | **V** | 16 | A value register reachable only through the inter-register instructions (`TFR`, `EXG`, `ADDR`, ...). **Not cleared by RESET**, so it can hold a constant across a reset; never stacked by an interrupt. MAME initialises it to `$FFFF` at startup, which is an emulator choice, not a hardware fact `[unverified]` | | **0** | 8/16 | A zero register: reads as zero, ignores writes. Two codes (12 and 13) name it | | **MD** | 8 | Mode and status, below | `MD` bits, in Atkinson's names (the bit numbers agree across all three documents): ```text bit: 7 6 5 4 3 2 1 0 /0 IL - - - - FM NM ``` - **NM** (bit 0), write-only: 0 = emulation mode, 1 = native mode. - **FM** (bit 1), write-only: 1 makes FIRQ stack the entire register set, as IRQ does, so that a FIRQ handler can use every register. E in the stacked CC is set accordingly, and the same `RTI` unwinds it. - **IL** (bit 6), read/clear: set when an illegal-instruction trap occurred. - **/0** (bit 7), read/clear: set when a divide-by-zero trap occurred. - Bits 2-5 unused. RESET clears MD to `$00`, i.e. a 6309 always wakes as a 6809. `LDMD #n` is the only way to write MD; `BITMD #n` is the only way to read it, and it can see only bits 6 and 7 — reading NM or FM is impossible, which is why Atkinson's `TSTNM` routine exists. Atkinson and Burke both state that **`BITMD` clears the status bits it tested**; MAME implements `BITMD` as a plain `BIT8` against MD and clears nothing (`hd6309.lst`, `case 0x3C`), so a trap handler written to the documents would loop under MAME. `[MAME choice differs from both documents]` ### TFR, EXG and the extended register codes The 6309 fills in the postbyte codes [start-here](start-here.md) lists as undefined: | Code | 6809 | 6309 | | --- | --- | --- | | 0-5 | D, X, Y, U, S, PC | unchanged | | 6 | undefined (reads `$FFFF`) | **W** | | 7 | undefined | **V** | | 8-B | A, B, CC, DP | unchanged | | C, D | undefined | **0** (zero register) | | E, F | undefined | **E**, **F** | Mixed-width `TFR`/`EXG` is *defined* on the 6309, where on the 6809 it is undocumented and the sources still disagree ([undocumented-behavior](undocumented-behavior.md)): an 8-bit register read into a 16-bit one is placed in **both halves**, and a 16-bit register written into an 8-bit one supplies its **high** byte for A, E and DP and its **low** byte for B, F and CC (Atkinson, with a diagram; MAME's `read_exgtfr_register`/`write_exgtfr_register` implement exactly this). `TFR` costs 6 cycles in emulation mode and 4 in native mode; `EXG` costs 8 and 5. The **inter-register** instructions use the same postbyte but a different promotion rule, because the operation size follows the *destination*: | Destination size | Source register | Operand actually used | | --- | --- | --- | | 8 | any 16-bit register | its low 8 bits | | 16 | A or B | **D** | | 16 | E or F | **W** | | 16 | CC | `$00`:CC | | 16 | DP | DP:`$00` | (Atkinson, p. 143. MAME's `register_register_op` promotes CC and DP to the **zero** register instead of `$00`:CC and DP:`$00`, so the two disagree for `ADDR CC,X` and friends. `[MAME choice differs from Atkinson]`) Atkinson also warns that naming PC in an inter-register instruction gives an unpredictable PC value because the 6309's pipeline is not synchronised for it — `TFR`/`EXG` with PC are fine. Do not model the inter-register PC case; mark it and move on. ## The added instruction set MAME 0.285's disassembler table (`6x09dasm.cpp`) is the cleanest count: **274 encodings shared with the 6809, 168 flagged `HD6309_EXCLUSIVE`, and 52 flagged `M6809_UNDOCUMENTED`** (which the 6309 mostly turns into traps). The 168 encodings carry **83 new mnemonics**. Cycle columns below are **emulation / native**; a single number means both modes cost the same. "+" means add the indexed postbyte's cost as [start-here](start-here.md) defines it. All counts are Atkinson's quick reference unless noted. ### Where they live in the opcode map - **Page 1** gains six instructions, in fourteen encodings, at bytes the 6809 leaves undocumented: `01`/`61`/`71` `OIM`, `02`/`62`/`72` `AIM`, `05`/`65`/`75` `EIM`, `0B`/`6B`/`7B` `TIM`, `14` `SEXW`, `CD` `LDQ #`. - **Page 2** (`10`) gains the inter-register group, the W push/pull group, the 16-bit register operations on D and W, and `LDQ`/`STQ`. - **Page 3** (`11`) gains the bit-manipulation group, `TFM`, `LDMD`, `BITMD`, the E and F operations, and `MULD`/`DIVD`/`DIVQ`. - Every other byte on page 2 or page 3 **traps** instead of falling through to page 1 the way the 6809 does. ### Memory-immediate logic (page 1) An 8-bit immediate operated against a memory byte, read-modify-write, with the immediate byte *before* the address operand. | Mnemonic | Direct | Indexed | Extended | Cycles (dir/idx/ext) | Bytes | Flags | | --- | --- | --- | --- | --- | --- | --- | | `OIM #i8,ea` | 01 | 61 | 71 | 6 / 7+ / 7 | 3 / 3+ / 4 | N Z, V=0, C unchanged | | `AIM #i8,ea` | 02 | 62 | 72 | 6 / 7+ / 7 | 3 / 3+ / 4 | as `OIM` | | `EIM #i8,ea` | 05 | 65 | 75 | 6 / 7+ / 7 | 3 / 3+ / 4 | as `OIM` | | `TIM #i8,ea` | 0B | 6B | 7B | 6 / 7+ / 7 | 3 / 3+ / 4 | as `OIM`; memory not written | These are the 6309's cheapest win over the 6809 (`OIM #$01,0,S` in the trap handler example in Burke's book sets a bit in a stacked CC in one instruction) and they cost the same in both modes. MAME's sub-cycle placement for all four is commented "this is just a guess" `[unverified]`. ### Inter-register operations (page 2, `10 30`-`10 37`) | Mnemonic | Opcode | Cycles | Bytes | Effect | Flags | | --- | --- | --- | ---: | --- | --- | | `ADDR r0,r1` | 10 30 | 4 | 3 | r1 = r1 + r0 | N Z V C (**not** H) | | `ADCR r0,r1` | 10 31 | 4 | 3 | r1 = r1 + r0 + C | N Z V C (**not** H) | | `SUBR r0,r1` | 10 32 | 4 | 3 | r1 = r1 - r0 | N Z V C | | `SBCR r0,r1` | 10 33 | 4 | 3 | r1 = r1 - r0 - C | N Z V C | | `ANDR r0,r1` | 10 34 | 4 | 3 | r1 = r1 & r0 | N Z, V=0 | | `ORR r0,r1` | 10 35 | 4 | 3 | r1 = r1 \| r0 | N Z, V=0 | | `EORR r0,r1` | 10 36 | 4 | 3 | r1 = r1 ^ r0 | N Z, V=0 | | `CMPR r0,r1` | 10 37 | 4 | 3 | r1 - r0, discarded | N Z V C | The additions are the exception to the 6809 rule that an 8-bit add writes H: Atkinson's table leaves H unaffected for `ADDR` and `ADCR`, and MAME agrees (`add8_sets_h()` in `hd6309.cpp` returns false for opcodes `10 30` and `10 31`). Atkinson's caution about CC as a destination is worth transcribing into any implementation too: the result is written to CC *and then* the flags for that result are written over it, in that order. ### W on the stacks (page 2) | Mnemonic | Opcode | Cycles | Bytes | | --- | --- | ---: | ---: | | `PSHSW` / `PULSW` | 10 38 / 10 39 | 6 | 2 | | `PSHUW` / `PULUW` | 10 3A / 10 3B | 6 | 2 | No postbyte and no flags: they move W and nothing else. W is **not** in the `PSHS`/`PULS` register mask. ### Single-bit operations (page 3, `11 30`-`11 37`) Direct addressing only. One postbyte selects the register (A, B or CC), the register bit and the memory bit; the third byte is the direct-page offset. | Mnemonic | Opcode | Cycles | Bytes | Effect | | --- | --- | ---: | ---: | --- | | `BAND r,sBit,dBit,addr` | 11 30 | 7 / 6 | 4 | r.dBit = M.sBit AND r.dBit | | `BIAND` | 11 31 | 7 / 6 | 4 | r.dBit = NOT M.sBit AND r.dBit | | `BOR` | 11 32 | 7 / 6 | 4 | OR | | `BIOR` | 11 33 | 7 / 6 | 4 | OR with the complement | | `BEOR` | 11 34 | 7 / 6 | 4 | EOR | | `BIEOR` | 11 35 | 7 / 6 | 4 | EOR with the complement | | `LDBT r,sBit,dBit,addr` | 11 36 | 7 / 6 | 4 | r.dBit = M.sBit | | `STBT r,sBit,dBit,addr` | 11 37 | 8 / 7 | 4 | M.dBit = r.sBit | Flags: none, *unless* CC is the named register, in which case only the destination bit of CC changes (Atkinson, note 3). ### Block transfer (page 3, `11 38`-`11 3B`) | Form | Opcode | Assembler | Effect | | --- | --- | --- | --- | | 1 | 11 38 | `TFM r0+,r1+` | forward block move | | 2 | 11 39 | `TFM r0-,r1-` | backward block move (overlapping blocks) | | 3 | 11 3A | `TFM r0+,r1` | block out to a fixed address (a port) | | 4 | 11 3B | `TFM r0,r1+` | block in from a fixed address | **6 + 3n cycles, 3 bytes**, n = the byte count in W. W counts down to zero, and each pointer that increments or decrements ends up n bytes above or below where it started. The postbyte holds two 4-bit register codes, and **only X, Y, U, S and D are legal**: anything else is an illegal instruction and traps. Z is set; no other flag changes. `TFM` is the only interruptible instruction on the part. Atkinson: the CPU interrupts after reading the source byte but before updating any register or storing, and stacks a PC still pointing at the `TFM`, so the instruction restarts and re-reads that byte — which is why form 4 (reading a port) must run with interrupts masked. MAME models the restart by backing PC up three bytes; its per-byte cycle placement is explicitly a guess `[unverified]`. ### Multiply and divide (page 3) | Mnemonic | Imm | Direct | Indexed | Extended | Cycles, emulation / native | Bytes | | --- | --- | --- | --- | --- | --- | --- | | `DIVD` | 11 8D | 11 9D | 11 AD | 11 BD | imm 25, dir 27/26, idx 27+, ext 28/27 | 4 / 3 / 3+ / 4 | | `DIVQ` | 11 8E | 11 9E | 11 AE | 11 BE | imm 34, dir 36/35, idx 36+, ext 37/36 | 4 / 3 / 3+ / 4 | | `MULD` | 11 8F | 11 9F | 11 AF | 11 BF | imm 28, dir 30/29, idx 30+, ext 31/30 | 4 / 3 / 3+ / 4 | - **`MULD`**: signed 16x16, `Q = D * operand`. Flags: N and Z from the result, C cleared, V unaffected (Atkinson's table and Burke agree). Atkinson's note 6 adds that **Z is set when the high word (D) is zero even if W is not** — MAME sets Z from all 32 bits and also clears V. `[two divergences from Atkinson]` - **`DIVD`**: signed 16/8. **Quotient in B, remainder in A**; the remainder takes the sign of the dividend. N from bit 7 of B, Z from B, C = bit 0 of the quotient, V on overflow. (The Simpson/DeKok guide says quotient in W and remainder in D for `DIVD`; that is its description of `DIVQ` pasted into the `DIVD` entry, and Atkinson, Burke and MAME all disagree with it.) - **`DIVQ`**: signed 32/16. Quotient in W, remainder in D, same flag rules. - **Two kinds of overflow**, which an implementation must not collapse into one: a *two's complement overflow* (the quotient's sign is wrong) sets V, leaves the result in place and costs one cycle less; a *range overflow* (the quotient will not fit) **aborts the division, leaves the destination registers unmodified, sets V and clears N, Z and C**, and costs 13 fewer cycles for `DIVD`, 21 fewer for `DIVQ` (Atkinson, note 12; Burke agrees the operands are unchanged). MAME's `divd()`/`divq()` instead write back `abs(old_d)` (`divd`) or set N or Z from the old dividend (`divq`) on the hard-overflow path and charge the same cycles either way. `[MAME choice differs from Atkinson and Burke]` - A zero divisor takes the trap, below, and is **not** an overflow. ### Mode register, sign extension, and the 32-bit loads | Mnemonic | Opcode | Cycles | Bytes | Effect | Flags | | --- | --- | ---: | ---: | --- | --- | | `LDMD #n` | 11 3D | 5 | 3 | MD = n (the only write to MD) | none | | `BITMD #n` | 11 3C | 4 | 3 | Z from MD & n, bits 6-7 only; clears the bits tested | Z | | `SEXW` | 14 | 4 | 1 | Q = sign-extension of W (D becomes `$0000` or `$FFFF`) | N Z | | `LDQ #n32` | CD | 5 | 5 | Q = immediate | N Z, V=0 | | `LDQ` / `STQ` | 10 DC/DD dir, 10 EC/ED idx, 10 FC/FD ext | dir 8/7, idx 8+, ext 9/8 | 3 / 3+ / 4 | Q to and from four consecutive bytes | N Z, V=0 | `SEXW` is where the sources visibly disagree: Burke's book describes it as sign-extending **F into E** (an 8-to-16 operation). Atkinson and MAME both make it **W into Q** (16 to 32). Atkinson and MAME agree, Burke's own example on his `SEX` page ("`TFR D,W` / `SEXW`" to reach a 32-bit value) contradicts his `SEXW` page, and this is the clearest illustration on this page of why a 6309 mode would need an oracle before it could claim anything. ### New loads, stores and arithmetic on the new registers The pattern is regular enough not to need a full table: **E and F get the A/B treatment on page 3** and **W and D get the X/D treatment on page 2**. | Family | Page | Opcode pattern | Cycles, emulation / native | | --- | --- | --- | --- | | `SUBE` `CMPE` `LDE` `STE` `ADDE` | `11` | `11 x0/x1/x6/x7/xB`, where `x` is 8 imm, 9 dir, A idx, B ext (`STE` has no immediate form) | imm 3, dir 5/4, idx 5+, ext 6/5 | | `SUBF` `CMPF` `LDF` `STF` `ADDF` | `11` | `11 x0/x1/x6/x7/xB`, where `x` is C imm, D dir, E idx, F ext | imm 3, dir 5/4, idx 5+, ext 6/5 | | `LDW` `STW` | `10` | `10 x6` / `10 x7`, `x` = 8 imm, 9 dir, A idx, B ext | imm 4, dir 6/5, idx 6+, ext 7/6 | | `SUBW` `CMPW` `ADDW` | `10` | `10 x0/x1/xB` | imm 5/4, dir 7/5, idx 7+/6+, ext 8/6 | | `SBCD` `ANDD` `BITD` `EORD` `ADCD` `ORD` | `10` | `10 x2/x4/x5/x8/x9/xA` | imm 5/4, dir 7/5, idx 7+/6+, ext 8/6 | | `NEG` `COM` `LSR` `ROR` `ASR` `ASL` `ROL` `DEC` `INC` `TST` `CLR` on **D** | `10` | `10 40/43/44/46/47/48/49/4A/4C/4D/4F` | 3 / 2, 2 bytes | | the same on **W** | `10` | `10 50/53/54/56/57/58/59/5A/5C/5D/5F` | 3 / 2, 2 bytes | | `COM` `DEC` `INC` `TST` `CLR` on **E** and **F** | `11` | `11 43/4A/4C/4D/4F` (E), `11 53/5A/5C/5D/5F` (F) | 3 / 2, 2 bytes | Three of the W forms are themselves contested: Burke's opcode map and MAME both define `10 50` `NEGW`, `10 57` `ASRW` and `10 58` `ASLW`/`LSLW`, while Atkinson's tables omit all three. `[unresolved]` Flags follow the 8-bit originals, widened: N from the top bit of the result, Z from the whole register, V and C as the 6809 defines them for that operation. ### New indexed postbytes The 6309 fills in postbytes the 6809 leaves undefined ([start-here](start-here.md) lists them as undefined; MAME's 6809 gives them an effective address of zero and no extra cycles). The columns are Atkinson's Indexed Addressing Mode Table, in the same "+ cycles / + bytes" convention [start-here](start-here.md) uses, emulation / native where they differ: | Postbyte | Assembler | Effective address | + cycles | + bytes | Indirect postbyte | + cycles | | --- | --- | --- | ---: | ---: | --- | ---: | | `1RR00111` | `E,R` | R + sign-extended E | 1 | 0 | `1RR10111` `[E,R]` | 4 | | `1RR01010` | `F,R` | R + sign-extended F | 1 | 0 | `1RR11010` `[F,R]` | 4 | | `1RR01110` | `W,R` | R + W | 1 | 0 | `1RR11110` `[W,R]` | 4 | | `10001111` | `,W` | W | 0 | 0 | `10010000` `[,W]` | 3 | | `10101111` | `n,W` | W + 16-bit signed n | 2 | 2 | `10110000` `[n,W]` | 5 | | `11001111` | `,W++` | W; then W += 2 | 1 | 0 | `11010000` `[,W++]` | 4 | | `11101111` | `,--W` | W -= 2; then W | 1 | 0 | `11110000` `[,--W]` | 4 | In the four `W` rows the RR bits are not a base selector at all: those are fixed postbyte values. Note that `E,R`, `F,R` and `W,R` occupy exactly the postbytes [undocumented-behavior](undocumented-behavior.md) lists as undefined on the 6809 (`1RR00111`, `1RR01010`, `1RR01110`), so a 6809 program that strays onto one gets a different effective address on a 6309 rather than MAME's zero. Every postbyte still undefined after this table is an **illegal instruction** on the 6309 and takes the trap, including the `[,R+]` and `[,-R]` forms the 6809 leaves undefined. ## Native mode: what changes The rule of thumb in the community documents is "15 % faster" (Burke) to "30 % faster" (the Simpson/DeKok guide). Mechanically, in MAME's model and in Atkinson's table, native mode removes one dead bus cycle from most instruction shapes: | What | Emulation | Native | | --- | ---: | ---: | | Every **direct** and **extended** operand fetch | +1 dead cycle | none, so `LDA 3, `LDA n` 5 -> 4, `NEG 5 | | Inherent 8-bit register operations (`NEGA`, `CLRB`, `TSTA`, ...) | 2 | 1 | | The page-2/3 16-bit register operations (`CLRD`, `TSTW`, ...) | 3 | 2 | | `TFR` / `EXG` | 6 / 8 | 4 / 5 | | `RTS` | 5 | 4 | | `MUL` | 11 | 10 | | `LBRA` / `BSR` / `LBSR` | 5 / 7 / 9 | 4 / 6 / 7 | | `PSHS`/`PULS`/`PSHU`/`PULU` base | 5 + n | 4 + n | | `DAA`, `SEX`, `ORCC`, `ANDCC`, `NOP`, `ABX` | as 6809 | one less | | Indexed `,R+` / `,-R` | +2 | +1 | | Indexed `,R++` / `,--R` | +3 | +2 | | Indexed 16-bit constant offset | +4 | +3 | | Indexed `D,R` | +4 | +2 | | Indexed 16-bit `n,PCR` | +5 | +3 | | Extended indirect `[n]` | +5 | +4 | | A **taken** conditional long branch | 6 | 5 | The 6309-only indexed modes in the table above cost the same in both modes. And native mode makes four things **longer**, because E and F join the stacked frame: | What | Emulation | Native | | --- | ---: | ---: | | `RTI` with E set | 15 | **17** | | `SWI` | 19 | **21** | | `SWI2`, `SWI3` | 20 | **22** | | IRQ / NMI entry (and FIRQ with MD.FM set) | 19 | **21** | The stacked frame in native mode, lowest address first, is `CC A B E F DP X Y U PC`: **E and F sit between B and DP**. Every interrupt handler that reaches into its own frame by offset — and OS-9 Level II's does, which is the warning both the Simpson/DeKok guide and Burke's book lead with — moves by two bytes, so `STX 10,S` becomes `STX 12,S`. Timing loops written for a 6809 also run short. Neither is a CPU-core problem, but both explain why so little software ever switched: native mode is not a free speed-up, it is a recompilation. One disagreement to record: Atkinson's note 11 says the extra cycle for a taken conditional long branch is "6809 only", i.e. a 6309 takes 5 cycles in **both** modes; MAME charges the extra cycle in emulation mode and drops it only in native mode (`base6x09.lst`, `LBRANCH`). `[unresolved]` ## The traps The 6809's reserved vector at **`$FFF0`** becomes the 6309's trap vector, shared by two causes: | Cause | MD bit set | Vector | | --- | --- | --- | | Illegal instruction (`ILLOP`) | bit 6 (IL) | `$FFF0` | | Divide by zero in `DIVD` or `DIVQ` (`DIV0`) | bit 7 (/0) | `$FFF0` | Entry, per Burke's per-instruction pages for `_ILLOP` and `_DIV0`: PC is advanced past the offending opcode, E is set, the **entire** register set is stacked (with E and F in native mode), I and F are **set**, and PC is loaded from `$FFF0`. The handler distinguishes the two with `BITMD #$40`, which also clears what it tested, and returns with `RTI`. MD bits 6 and 7 stay set until cleared by `BITMD`, by `LDMD`, or by RESET. MAME routes both through the same path as `SWI2`/`SWI3` (`base6x09.lst`, `SOFTWARE_INTERRUPT`), which sets E, stacks everything and **does not set I or F**, at 20 cycles in emulation mode and 22 in native mode. That contradicts Burke on I and F, and no source gives a measured cycle count for trap entry: `[unverified]`. The hazard for real hardware is stated in both community documents and is worth carrying into any host: a 6809 machine's ROM often leaves `$FFF0` holding `$0000`, `$FFFF` or garbage, because Motorola called it reserved. On a 6309, the first stray opcode then jumps somewhere arbitrary with the whole register set stacked. ## What breaks naive 6809 compatibility This is the section that matters to a 6809 core, because it is where "the board has a 6309 in it" stops being trivia. **1. The 6809's undocumented opcodes are gone.** Every rule on [undocumented-behavior](undocumented-behavior.md) is a 6809 rule. On a 6309: | 6809 opcode(s) | 6809 behaviour (hardware-captured) | 6309 | | --- | --- | --- | | `01`/`41`/`51`/`61`/`71` | `NEG` aliases | `01`/`61`/`71` are `OIM`; `41`/`51` **trap** | | `02`/`42`/`52`/`62`/`72` | `XNC` (NEG or COM by C) | `02`/`62`/`72` are `AIM`; `42`/`52` **trap** | | `05`/`45`/`55`/`65`/`75` | `LSR` aliases | `05`/`65`/`75` are `EIM`; `45`/`55` **trap** | | `0B`/`4B`/`5B`/`6B`/`7B` | `XDEC` (DEC that writes C) | `0B`/`6B`/`7B` are `TIM`; `4B`/`5B` **trap** | | `14`, `15`, `CD` | halt and catch fire | `14` is `SEXW`, `CD` is `LDQ #`; `15` **traps** | | `18` | the CC-rewriting oddity | **traps** | | `1B` | a second `NOP` | **traps** | | `38` | `XANDCC` (4-cycle `ANDCC`) | **traps** | | `3E`, `10 3E`, `11 3E` | `XRES`/`XSWI2`/`XFIRQ` | **trap** | | `4E`, `5E` | `XCLRA`/`XCLRB` (C unchanged) | **trap** | | `87`, `8F`, `C7`, `CF` and prefixed forms | store-immediate, flags depending on the previous instruction | **trap** | | `10 C3`/`D3`/`E3`/`F3`, `11 C3`/... | `XADDD`, `XADDU` | **trap** | | any other `10 xx` / `11 xx` | prefix discarded, page-1 opcode runs one cycle slower | **trap** — including `10 20` (`XLBRA`), which both the Simpson/DeKok guide and Burke's book name as the example | | undefined indexed postbytes | MAME gives EA = 0 | `E,R`, `F,R`, `W,R` and the `,W` group are real modes; the rest **trap** | So a program that relies on any 6809 undocumented behaviour diverges on a 6309 — usually into a trap through a vector the machine never initialised. That is exactly the "flaky chip" reputation the Simpson/DeKok guide opens with. **2. Documented-instruction flag differences: none found.** No source consulted claims that a documented 6809 instruction sets a different flag on a 6309 in emulation mode. The differences are in *which* opcodes exist, in the cycle counts under native mode, in the mixed-width `TFR`/`EXG` rules (undocumented on the 6809, documented on the 6309, and not the same rule: the 6309 copies an 8-bit register into **both** halves of a 16-bit one where every 6809 account puts `$FF` in the high byte for A and B), and in the trap. A future reader should treat "no difference" as the current state of the search, not as a proof. **3. Timing.** In emulation mode the counts are the 6809's; in native mode they are not, and a host that counts E cycles per scanline would need the mode flag threaded through every count. ## Where the accounts disagree Collected, because any 6309 mode built here will have to choose: | Question | Atkinson | Burke | Simpson/DeKok | MAME 0.285 | | --- | --- | --- | --- | --- | | `SEXW` | W -> Q | F -> E | (lists the mnemonic only) | W -> Q | | `MULD` flags | N, Z (Z from the high word), C=0, V unchanged | N, Z, C=0, V unchanged | not stated | N, Z from all 32 bits, V=0, C=0 | | `DIVD` result registers | quotient B, remainder A | quotient B, remainder A | quotient W, remainder D (wrong) | quotient B, remainder A | | Range overflow in `DIVD`/`DIVQ` | operands unchanged, V=1, N Z C = 0, 13/21 cycles fewer | operands unchanged, V=1 | not stated | writes back `abs(D)` / sets N or Z, same cycles | | `BITMD` | clears the bits it tests | clears the bits it tests | not stated | clears nothing | | Trap entry sets I and F | not stated | yes | not stated | no | | Inter-register CC/DP promotion | `$00`:CC and DP:`$00` | not stated | "results are unknown" | zero for both | | Taken conditional long branch | 5 cycles on a 6309 in both modes | not stated | not stated | 6 in emulation, 5 in native | | `LDW` immediate | 4 cycles both modes | not stated | 5 / 4 (an arithmetic-row typo) | 4 both modes | | `DIVQ` immediate | 34 | not stated | 36 in the opcode table, 34 in the mnemonic table | (state machine; not read off) | | `LDQ`/`STQ` indexed and extended | `10 EC/ED`, `10 FC/FD` | same | prints `10DC/10DD` for all three modes (a typo) | `10 EC/ED`, `10 FC/FD` | | `NEGW` (`10 50`), `ASRW` (`10 57`), `ASLW` (`10 58`) | absent from both tables | present in the opcode map | absent | present | Ten of those twelve rows would be settled by one hardware capture of a `HD63C09EP` running a few hundred instructions; the other two are typos that reading the tables settles. None of the ten can be settled by reading more documents. ## Should this core support it **Recommendation: yes, as an optional mode in this repository, after the 6809 ladder passes — and never with a conformance claim attached.** **What it would cost.** 168 new opcode encodings and 83 new mnemonics (counted from MAME 0.285's disassembler table), four new registers (E, F, V, MD) plus the W/Q views and the zero register, fourteen new indexed postbytes (seven modes with their indirect forms), a second register-code table for `TFR`/`EXG` and the inter-register group, a trap path that is a fourth kind of interrupt entry, and — the part that touches everything — a `native_mode` flag that changes the cycle count of most of the instructions already written. In the shape this repository plans (`_alu`, `_loads`, `_index`, `_interrupts`, explicit dispatch), that is roughly: one new module for the new families, an extended dispatch for pages 2 and 3, four attributes, and one conditional in the cycle accounting of the existing handlers. Perhaps a 40 % increase in core size, on top of a core that does not exist yet. **What it would buy.** For the arcade target this repository is aimed at: **nothing, measured**. Twelve of the 27 MAME parents that name an `hd6309`/`hd6309e` were traced for 35.4 million instructions and never left emulation mode or executed one 6309-exclusive opcode. Those boards have a 6309 fitted because Hitachi's part was available, and run 6809 code through it. What a 6309 mode does buy is (a) the home-computer software that was written for it — CoCo 3 and Dragon 6309 upgrades, NitrOS-9's 6309 build, the reason `cocoh`, `coco2bh`, `coco3h`, `dragon64h` and `tanodr64h` exist in MAME; (b) correctness for any program that runs into a 6809 undocumented opcode on 6309 silicon, which is a *different* answer, not a nuance; and (c) the ability to say what a board with a 6309 socket actually does. **Why a mode here rather than a separate repository.** The 6309 shares the register file, the CC byte, the two stacks, the postbyte, the addressing modes, the interrupt structure, the reset rules, the host embedding contract, the MAME tracing tooling and the entire validation ladder with the 6809. MAME itself makes the same judgement: `hd6309.cpp` is a subclass of `m6809_base_device`, and both parts share `base6x09.lst`. A separate project would duplicate all of that to gain one flag and one dispatch table — and would immediately need this repository's oracles anyway, since the only way to test 6309 emulation mode is to test a 6809. **Conditions.** Do not start it before rungs 1-5 of [validation](validation.md) pass: an unverified 6309 mode grafted onto an unverified 6809 core is two unknowns multiplied. When it is written, its claim ceiling is lower than the 6809's and the README must say so: there is **no** hardware-captured or hardware-corrected 6309 oracle at any tier, the three community documents disagree with each other and with MAME in the twelve places tabulated above, and MAME's own comments call several of its 6309 timings guesses. The honest claim available would be "agrees with MAME 0.285's `hd6309` over cases X, and follows Atkinson where MAME and Atkinson differ, with each difference listed" — a detector agreeing with a detector. Raising that ceiling needs what the 6809 needs: a bus capture of a real `HD63C09EP`, which a Dragon, a CoCo 3 or any of the Konami boards above could supply.