# 6809 undocumented behaviour: what the datasheet leaves open, and who measured it The 6809 has fewer undocumented corners than the Z80 or 6502, but they matter to an arcade core in two ways: real programs occasionally execute a stray illegal opcode (a bad jump into data during a crash, or deliberately as a trap), and the flags the datasheet marks "undefined" are visible to anything that later pushes CC or executes a conditional branch. This page lists every known case, says what each source claims, and states the source's **tier**: - **hardware-captured**: a logic-analyser or bus decoder watched a real 6809 execute the case. - **hardware-corrected**: a self-checking program written from the datasheet was run on a real 6809 and its assertions adjusted until they passed there. - **emulator-derived / inferred**: an emulator's choice, or an inference from the instruction decoder's regularity, with no hardware observation. A low-tier claim is marked `[unverified]`; it is a detector, never a judge. Read [start-here](start-here.md) first for the register and mode names. ## Sources | Source | Tier | Method | Licence | | --- | --- | --- | --- | | David Banks (hoglet67), *Undocumented 6809 Behaviours*, wiki of the 6809Decoder project, page revision current on 2026-09-11; repository HEAD `4f7e184` (2025-01-27): | **hardware-captured** | Test cases "carefully (sometimes exhaustively)" exercise each instruction on original devices and push the resulting state to the stack; every bus cycle is then checked against the decoder's model. The test programs are in the repository's `test/assembler/` (BBC BASIC programs `illeg1.bas`, `illeg2.bas`, `stimm.bas`, `x18.bas`, `daa.bas`, `tfr` tests, ...) | The repository has **no licence file** (GitHub API `license: null`); the wiki text is quotable as a cited source, the programs are not redistributable here | | David Flamand, *The Comprehensive Document of 6809 Undocumented and Undefined Behaviour*, August 2022, commit `3b8d5cf`: (`6809_undocumented_behavior.pdf`, `tfr.txt`, `Cycle_Analyzer.jpg`) | **hardware-captured** | Cycle analyser on a real 6809; hoglet67 credits it for the exact dependence of opcode `18` on the following byte | No licence stated | | MAME 0.285, `src/devices/cpu/m6809/m6809.lst`, `base6x09.lst`, `m6809.cpp` (tlindner, January 2023: "Add 6809 undocumented opcodes as described here: [hoglet67 wiki]") | emulator-derived, **transcribed from hoglet67** | Where MAME says "TODO" it has simplified the hardware finding; those simplifications are listed below | BSD-3-Clause | | Darren Atkinson, *Motorola 6809 and Hitachi 6309 Programming Reference*, 2010, "Undocumented opcodes" p. 153: | compiled from earlier community reports; hoglet67 calls it "the best existing description ... but even this was not completely accurate" | Free distribution PDF; not quoted here beyond the citation | | Ciaran Anscomb, *Illegal Op-codes*, Dragon Update, February 1994: | hardware-observed on a Dragon 32/64 (6809E), informal | Author's site | | *Undocumented 6809 Opcodes*, dragon32.info: | compiled | none stated | | XRoar 1.12 (2026-07-27) ChangeLog entries "6809: flesh out some illegal instruction behaviours [David Banks]" and "Implement some more 6809 undocumented behaviour" | emulator-derived, transcribed from hoglet67 | GPL-3.0 | | `neetandev/m6809` vector corpus at `9dd7b59` (2026-07-10) | emulator-derived from MAME, plus one hardware observation of its own (see TFR/EXG) | test data MIT-0 per its README | Where two hardware-captured sources agree, the rule is stated plainly. Where only MAME's choice exists it is marked `[MAME choice, unverified]`. ## Halt and catch fire: `14`, `15`, `CD` After executing any of these the processor enters a test mode in which the address bus increments by one every cycle, starting from the current PC, until RESET. It cannot be interrupted. All three are identical and any prefix before them is ignored. (hoglet67, hardware-captured. MAME: `FREERUN`, sets `m_free_run` and thereafter fetches without executing; the `neetandev` corpus skips them.) A core should model this as a halted state that RESET clears, and report it to the host; no arcade program executes it on purpose. ## `3E` XRES, `10 3E` XSWI2, `11 3E` XFIRQ `3E` behaves like `SWI` except that it takes the **RESET** vector (`$FFFE`) and does not set E in the stacked CC; all flags are unchanged, and unlike a hardware reset I and F are **not** set and DP is not cleared. 19 cycles, the same bus sequence as SWI. `10 3E` does the same through the SWI2 vector (20 cycles) and `11 3E` through the FIRQ vector (20 cycles, full state stacked, I and F still not set). (hoglet67, hardware-captured, with the cycle-by-cycle bus listing. MAME: `XRES`, `XSWI2`, `XFIRQ` in `m6809.lst`, which stack the entire state via the same `PUSH_REGISTERS` macro but, note, do *not* clear E first: MAME pushes whatever E was, which matches "E is not explicitly set".) Whether the stacked CC has E cleared, or merely left as it was, is the one detail hoglet67's wording ("does not correctly set the E flag") leaves open; `[unverified]` until a trace with E=1 beforehand is checked. ## `18` Three cycles. Reads the byte at PC+1 (the next opcode) without consuming it and rewrites CC from the AND of CC with that byte, shifted left by one, with the old Z landing in V: ```text new CC = ((CC & next_byte) << 1) | ((CC & 0x04) >> 1) ``` so E' = F&b6, F' = H&b5, H' = I&b4, I' = N&b3, N' = Z&b2, Z' = V&b1, V' = (C&b0) | Z, C' = 0. (Flamand found the dependence on the following byte; hoglet67 confirmed it; MAME `X18` implements exactly this expression.) ## `1B` A two-cycle NOP, identical to `12`. (hoglet67; MAME `NOP`.) ## `38` XANDCC `ANDCC #n` in four cycles instead of three. (hoglet67; MAME `XANDCC`, which charges one extra internal cycle with no bus access. The `neetandev` corpus README notes this is the only 6809 instruction with a bus-idle cycle in its trace, so a core that models "every cycle is a bus cycle" needs one exception.) ## `10 20` XLBRA `LBRA` with a prefix. hoglet67 gives "5 cycles rather than 4"; the datasheet gives unprefixed `LBRA` 5 cycles and MAME charges 6 for `10 20` (one more than its 5-cycle `LBRA`). The two sources count from different origins, so the safe statement is: **one cycle more than `LBRA`**, and the absolute count is `[unverified]` until measured against the same reference as the rest of the table. ## Aliases: `01/41/51/61/71` NEG, `05/45/55/65/75` LSR Bit 0 of the opcode is ignored: these are exact aliases of `NEG` and `LSR` in the corresponding mode. (hoglet67, hardware-captured; MAME dispatches both opcodes to the same handler; XRoar the same.) ## `02/42/52/62/72` XNC ("NEG or COM") Behaves as `NEG` when C=0 and as `COM` when C=1, with that instruction's flags. (hoglet67; MAME `XNC8`.) The older community name "NGC" describes the same thing. ## `0B/4B/5B/6B/7B` XDEC `DEC`, except that C is also written: C is cleared when the operand was zero and set otherwise. N, Z and V as `DEC` (V set only for operand `$80`). (hoglet67; MAME `XDEC8`.) ## `4E`, `5E` XCLRA / XCLRB `CLRA`/`CLRB` except that C is unchanged. Z=1, N=0, V=0. (hoglet67; MAME `XCLR8`. MAME also performs the dummy operand read the real `CLR` does.) ## Store immediate: `87`, `C7`, `8F`, `CF` and page-2/3 forms These are the "store" column of the immediate-mode opcodes. On hardware: - `87` (XSTA) and `C7` (XSTB): two cycles; the immediate byte is read and discarded, nothing is written. - `8F` (XSTX) and `CF` (XSTU): three cycles; the first immediate byte is read and discarded, then the **low byte of X (or U) is written over the second immediate byte**, i.e. the instruction modifies its own operand. - `10 8F` (XSTY), `10 CF` (XSTS), `11 8F` (XSTX), `11 CF` (XSTU), `10 87`, `10 C7`, `11 87`, `11 C7`: same as the unprefixed forms one cycle longer, with the simple flags N=1, Z=0, V=0. - For the **unprefixed** forms the flags depend on which of eight groups the *previous* instruction belonged to (for example after `LDA` they reflect A; after `CMPX` they are computed from the high byte of that compare's result; after most other instructions N=1, Z=0, V=0). hoglet67's page lists the eight groups in full. (hoglet67, hardware-captured. MAME `XST8`/`XST16` carry a `TODO` and set N Z V from the register value in every case, which is **wrong for the unprefixed forms after most instructions**; the `neetandev` corpus therefore encodes MAME's simplification, not the hardware. A core following the hardware rule will disagree with that corpus on `87`, `C7`, `8F`, `CF`, and that is the expected direction of the disagreement.) ## Page-2 and page-3 arithmetic: `10 C3/D3/E3/F3` XADDD, `11 C3/D3/E3/F3` XADDU XADDD computes D + operand as `ADDD` would and sets N Z V C from the sum, but does **not** write D. XADDU does the same with `(U | $FF00)` as the left operand and does not write U. (hoglet67; MAME `XADD16`. The `| $FF00` for U is hoglet67's finding; MAME uses U unmodified in `XADD16` with `set_regop16(m_u)`, so the two disagree on N and V for XADDU when U's high byte is not `$FF`: `[MAME choice differs from hardware]`.) ## Other prefixed opcodes Any `10 xx` or `11 xx` not listed here or in the documented table runs as the page-1 `xx` with one extra cycle. Chained prefixes count one cycle each and only the first is significant. (hoglet67, "Multiple Prefixes". MAME's `DISPATCH10`/`DISPATCH11` fall through to `DISPATCH01` for unknown bytes, which gives the same result; for `10 10` and `10 11` MAME re-dispatches the second prefix, i.e. the *last* prefix wins in MAME: `[MAME choice differs from hardware]`.) ## TFR and EXG with mixed widths or undefined registers The datasheet defines only same-width pairs and register codes 0-5 and 8-B. **MAME 0.285** (`read_tfr_exg_816_register`, `read_exg_168_register`, `write_exgtfr_register` in `m6809.cpp`, comment "Implemented undocumented TFR/EXG for undefined source and mixed 8/16 bit transfers (they should transfer/exchange the constant $ff)", HJB, 1999): - Undefined source codes 6, 7, C-F read as `$FFFF`; undefined destination codes write nothing. - 8-bit to 16-bit `TFR`: A or B is placed in the low byte with `$FF` in the high byte; CC or DP is **duplicated** into both bytes (`TFR CC,X` gives `X = CC:CC`). - 16-bit to 8-bit `TFR`: the low byte of the source. - `EXG` between widths: when the 16-bit register is first (`EXG X,A`) the 8-bit side is read as `$FF:A` and the 16-bit side's low byte lands in A; when the 8-bit register is first, CC/DP are read as `$FF:CC` rather than duplicated. **`neetandev/m6809`** deliberately departs from MAME here: its README says the register-transfer helpers "apply the mixed-width CC/DP behavior observed on a real FM-77AV and documented by 77AVEMU", i.e. a hardware observation (the FM-77AV is a Fujitsu machine with a 68B09) that disagrees with MAME's duplication rule. The corpus does not state the rule in words; a build session should extract it from the `1E`/`1F` vectors and compare with hoglet67's `tfr` tests and Flamand's `tfr.txt`, both hardware-captured. **Ciaran Anscomb (1994)** reports, from a Dragon, that an 8-bit to 16-bit transfer gives `$FF` in the high byte for A and B, which agrees with MAME for those two registers. Until the three hardware sources have been read side by side, the whole mixed-width table is `[hardware-captured but not yet reconciled]`, and MAME's CC/DP duplication is `[MAME choice, contradicted by neetandev's observation]`. ## Undefined flags | Instruction | Datasheet | Hardware (hoglet67, captured) | MAME 0.285 | | --- | --- | --- | --- | | `ASL`, `ASR`, `CMP`, `NEG`, `SBC`, `SUB` (8-bit) | H undefined | H **unchanged** | `set_flags` with masks that exclude H: unchanged | | `SEX` | V cleared | V **unchanged** | `CC_NZ` only: unchanged (agrees with hardware, not the datasheet) | | `DAA` | V undefined | V = new C xor new bit 7 of A | `daa()` in `m6809inl.h`: `[to be read by the build session]` | | `MUL` | N, V not affected | not stated | `mul()`: Z and C only | | `ABX` | none | none | none | | `ANDCC`/`ORCC` | writes CC directly | as datasheet | as datasheet | | `TST` | V cleared, C unaffected | as datasheet | `CC_NZV`: agrees | | `LEAX`/`LEAY` | Z only | as datasheet | `CC_Z` | | `LEAS`/`LEAU` | none | as datasheet | none | ## Indexed postbyte values the datasheet does not define `1RR10000` (`[,R+]`), `1RR10010` (`[,-R]`), `1RR00111`, `1RR01010`, `1RR01110`, and `1RR11111` except `10011111`. hoglet67's page does not cover them; MAME's `INDEXED:` switch falls to `default:` with an effective address of `$0000` and no extra cycles, then applies indirection if bit 4 is set. `[MAME choice, unverified]`. XRoar 1.12's ChangeLog mentions "an illegal indexed addressing mode accidentally used by the first ..." (a real program), which is the kind of case a Williams or Konami ROM could also contain; a build session should grep the target ROMs for these postbytes before deciding how much to care. ## Interrupt-related corners - **NMI before the stack is loaded** is ignored (datasheet; MAME `m_lds_encountered`, set by `LDS`, `LEAS` and `TFR r,S`; `EXG` with S is not marked in MAME, `[unverified]`). - **NMI edge during CWAI/SYNC** wakes the processor (datasheet). - **SYNC** costs 4 cycles per the datasheet and 3 plus the wait in MAME; `[unverified]` which is right at the bus level. - The `E` flag is left as-is, not cleared, by the undocumented `3E` family (above). ## Where the truth will live When the core exists, the order of authority for a rule on this page is: 1. hoglet67's and Flamand's hardware captures, for the cases they cover. 2. Any future bus capture of a real 6809 made for this project (the `docs/validation.md` plan says what would be needed). 3. Agreement between MAME 0.285, XRoar 1.12 and a third independent core, for everything else, stated as agreement and not as hardware truth.