# Undocumented behaviour, quirks, and contradictions WDC's datasheet (DS, 2024-03-13) and Eyes & Lichty's *Programming the 65816* (WDC's own manual, not fetched here: sold in print, no free copy found) are the manufacturer's word. Where they are silent or wrong, the rules below rest on test ROMs run on SNES hardware, emulator authors' research, and the SingleStepTests corpus; each item names which, with its tier ([validation.md](validation.md)). No transistor-level 65C816 model exists to settle anything (searched 2026-10-21: visual6502 covers the 6502 and 6800 only; the FPGA 65C816s, srg320's P65C816 and others, are written from documentation and tests). Measured numbers below come from `scripts/datasheet_timing.py` over all 5,080,400 SingleStepTests cases ([timing.md](timing.md)). ## Behaviour items (U) **U1. Emulation-mode direct page wraps within its page only when D.l = 0, and only for the 6502's modes.** With E = 1 and D.l = 0, `d`, `d,x`, `d,y`, `(d)`, `(d,x)` and the pointer of `(d),y` stay in page D.h (the 6502's "zero page wraps"); `[d]`, `[d],y` and `PEI` do not wrap and carry into the next page; with D.l ≠ 0 nothing wraps (16-bit, bank 0). *Manufacturer:* DS §7.2.1-7.2.3 (p. 50). *Research:* 6502.org *65C816 Opcodes* ("old" instructions wrap, "new" ones do not). *Emulator:* bsnes wraps the old modes and not the new ones (HYPOTHESIS: read from its GPL source before the 2026-11-14 rule, not observed running; for review, 2026-11-24); SST: the 1,095 address disagreements with a literal Table 5-7 are all this item or U2 (e.g. `15.e` 25 cases, `b6.e` 17). *Coverage gap:* SST has **no** case of `(d)`, `(d),y` or `[d]` with E = 1, D.l = 0 and the operand at $FF (0 of 10,000 in `b2.e`, `b1.e`, `a7.e`, `b7.e`; 2 in `d4.e` PEI, which correctly does not wrap); gilyon's cputest-full covers them ("wrapping behavior ... with and without emulation mode", its README). *Rung 5:* P65C816 wraps the emulation-mode direct page within D.h's page whatever D.l is (its `DX(15 downto 8) & low byte + increment`), so it alone differs from the datasheet, the corpus and the core on cases with D.l ≠ 0 whose sum crosses a page (about half of `15.e`, `b5.e`, `01.e`). **U2. Emulation-mode stack: the 6502's instructions wrap S in page one, the new ones step a 16-bit S and may leave it, then SH is forced back to $01.** BRK, COP, interrupts, JSR a, RTS, RTI, PHA/PHP/PHX/PHY, PLA/PLP/PLX/PLY wrap ($0100 - 1 = $01FF). JSL, JSR (a,x), PEA, PEI, PER, PHD, PLD, RTL do not: SST `22.e` at S = $0100 writes $0100, $00FF, $00FE and ends with S = $01FD; `2b.e` (PLD) at S = $01FE reads $01FF, $0200 and ends with S = $0100. *Manufacturer:* DS §7.1 lists exactly those eight. *Emulator:* bsnes treats the eight apart from the rest (HYPOTHESIS: read from its GPL source before the 2026-11-14 rule; for review, 2026-11-24); SST agrees on all its cases. PLB and PHB/PHK are C5. **U3. `(d,x)` with E = 1 and D.l ≠ 0 reads the pointer's high byte from the same page as its low byte.** Low byte at D + d + X (no page wrap), high byte at ((D + d + X) & $FF00) | ((D + d + X + 1) & $FF). gilyon's example: E = 1, D = $011A, X = $EE, `LDA ($F7,X)`: low from $02FF, high from $0200. Contested: **C4**. **U4. Bank boundaries.** PC wraps within PBR (`$xxFFFF` + 1 = `$xx0000`); absolute indexed, `(d),y`, `(d,s),y`, `al,x` and `[d],y` carry the index into the bank (DS §7.3); `JMP (a)` and `JML [a]` read their pointer in bank 0 and `JMP/JSR (a,x)` in PBR, with the 16-bit pointer address wrapping within the bank (Table 5-7 rows 2-3); direct page, stack and `d,s` accesses wrap at $FFFF within bank 0 in native mode. *Manufacturer* + SST (no disagreement in 5 million cases); gilyon tests PC and pointer wrapping ("test PC wrapping from $FFFF", test 0000). **U5. Register widths.** With M = 1 the accumulator's high byte B survives every 8-bit operation and is swapped in by `XBA` (which sets N and Z from the new low byte). With X = 1, XH and YH are 0 and stay 0; setting X (SEP, PLP, RTI, XCE into emulation) clears them. `TCD`, `TDC`, `TCS`, `TSC` move all 16 bits whatever M is; `TCS` in emulation mode keeps SH = $01; `TXS` copies X to S (in emulation mode only the low byte); `TSX` and the other transfers follow the destination's width. `XCE` into emulation mode forces M = X = 1, XH = YH = 0, SH = $01. In emulation mode `REP` cannot clear M or X (bits 5 and 4 of P read 1 and B). *Manufacturer:* DS §2, Table 5-5. SST covers every width combination. **U6. MVN/MVP.** C counts all 16 bits even with M = 1; X and Y step in 8 bits when X = 1; DBR becomes the destination bank on the first pass; each byte refetches the opcode and is interruptible, the return address being the MVN itself. SST cases are whole moves of at most 1,000 bytes (a corpus choice), all agreeing with Table 5-7's 7 cycles per byte. *Manufacturer* + SST. **U7. Decimal mode.** N and Z are valid (reflect the result), C is the decimal carry, no extra cycle (the 65C02 adds one; the 65816 does not: 6502.org *Decimal Mode* §3.2.3). V, and every flag and result for invalid BCD digits, are undocumented: Bruce Clark's Appendix A gives the 65C816's algorithm (research), SST encodes Clock Signal's (emulator), gilyon's cputest tests valid and invalid inputs ("The behavior of decimal mode isn't fully documented. See appendix A", its README). 16-bit decimal is the 8-bit operation on the low bytes, then on the high bytes with the carry between (Clark's Appendix C); Z reads all 16 bits. `_alu.py`'s decimal paths are written from Clark's appendices A and C (DOC) and pass every SST decimal case, valid and invalid BCD (TEST ROM; rewritten clean-room 2026-11-25, docs/provenance.md item 2). A reused NMOS adder is **wrong** here (NMOS N/V/Z come from the binary sum, 6502-python `_alu.add`). **U8. Interrupts, BRK, COP.** All clear D and set I (NMOS leaves D), set PBR = 0, push PBR only in native mode; emulation mode pushes P with B = 0 for IRQ/NMI and B = 1 for BRK/COP (DS note 11; SST `00.e`: P | $30 pushed in every case). BRK and COP read their signature byte as a program fetch (VPA) and push PC + 2. RTI pulls PBR only in native mode. *Manufacturer* + SST. **U9. bsnes: an implied instruction's IO cycle becomes a read of PC when an interrupt is about to be taken.** For CLC CLD CLI CLV SEC SED SEI, the transfers, INC/DEC/INX/INY/DEX/DEY, the accumulator shifts, NOP and XCE, the IO cycle reads PC without incrementing it. On the SNES this lengthens the cycle from 6 to 8 master clocks in slow ROM. HYPOTHESIS: read from bsnes's GPL source before the 2026-11-14 rule, never observed running; for review (2026-11-24). No test ROM or capture found that shows it; SST has no interrupt cases. Not implemented. Note for rung 6. **U10. Emulation-mode read-modify-write writes twice.** The modify cycle has RWB low with the old value on the bus and VDA = VPA = 0 (DS note 17; SST: e.g. `0e.e` `['---wemxl']` at the operand address with the unmodified byte). Contested: **C3**. **U11. WAI and STP.** WAI stops after its third cycle (RDY driven low) until NMI, IRQ, ABORT or reset; with I = 1 an IRQ ends the wait without an interrupt and execution continues after the WAI (DS §2.24, p. 14). STP stops the clock until reset (DS §2.25: "STP and WAI instructions are cleared" by reset). bsnes adds one IO cycle after waking (HYPOTHESIS: read from its GPL source before the 2026-11-14 rule; for review, 2026-11-24). The core makes that cycle a program read at PBR,PC with the byte dropped, so a 5A22 times it by the address (8 master clocks in SlowROM, 6 in FastROM): Aubrey's Super Famicom (CPU version 1) latches H after a WAI wake one dot later from SlowROM than from FastROM, which an IO cycle (always 6) cannot give (snes-python's probe suite, HVLT/IRQN/CRSH, 2026-10-25) [hw-observed]. The 5A22 keeps running DMA/HDMA while the core waits (board). **U12. Reset.** Three stack cycles are reads (RWB high, DS note 10), S decreases by 3; D = 0, DBR = PBR = 0, SH = $01, XH = YH = 0, E = M = X = I = 1, D flag 0; A, XL, YL, SL, N V Z C keep their values (DS §2.25). bsnes spends 132 master clocks before the reset sequence (`CPU::main`, "step(132)", board). **U13. `WDM` ($42)** is a two-byte no-op reserved by WDC; its second byte's cycle kind is contested (**C2**). MAME calls a `m_wdm_w` hook with the operand (a debugging aid of MAME's, not chip behaviour). **U14. IO cycle addresses** are driven but declared invalid where Table 5-7 says so (DS §7.5); the SST corpus agrees with Table 5-7's expressions on every IO cycle outside U1/U2 (5,080,202 of 5,080,400 cases). On the SNES the 5A22 gives every IO cycle 6 master clocks without decoding its address, so the address matters only to a board that watches the bus (none known); the core reports it anyway. ## Contradictions between sources (C) **C1. `JMP (a,x)` / `JSR (a,x)` pointer reads: VPA or VDA?** DS Table 5-7 rows 2a/2b mark the two pointer reads VDA = 0, VPA = 1 (program reads from PBR). SST marks them `d--r` (VDA = 1, VPA = 0) in all 40,000 cases of `7c.*` and `fc.*`; the addresses agree. Manufacturer vs emulator, no hardware capture. On the SNES both are accesses of the same length, so the board's timing is the same either way. *Recommendation:* the core follows the datasheet (higher tier); rung 1 masks VDA/VPA on those two cycles of those two opcodes and records it. *Rung 5 (srg320's P65C816 under GHDL, 2026-10-23):* VPA, with the datasheet and the core, in all 4,000 cases run of `7c.*` and `fc.*`. **C2. `WDM` second cycle: program read or IO?** SST: IO (`---r`, no value) in all 20,000 cases of `42.*`. bsnes: a read of PC + 1 (VPA) (HYPOTHESIS: read from its GPL source before the 2026-11-14 rule; for review, 2026-11-24; rung 5 below observes the same in P65C816). Table 5-7 has no WDM row; Table 5-4 says 2 bytes, 2 cycles. On the SNES this changes the cycle from 6 clocks to 8 (slow ROM) or 6 (fast ROM). No licensed game is known to execute WDM. *Recommendation:* follow bsnes (a read: WDC reserves WDM as a prefix to a future opcode, which implies the byte is fetched); rung 1 masks the kind of that cycle. *Rung 5:* P65C816 reads the byte (VPA), with bsnes and the core, in all 2,000 cases run of `42.*`. **C3. Emulation-mode RMW modify cycle: a write, or IO?** DS note 17 ("RWB is low during both write and modify cycles") and SST (RWB low, old value, VDA = 0, every `.e` RMW case) say write; ares (ISC, read) does an IO cycle with no write, and bsnes, of the same lineage, the same (HYPOTHESIS for bsnes: read from its GPL source before the 2026-11-14 rule; for review, 2026-11-24). On the SNES a write of the old value to an I/O register (e.g. an `INC $2118` in emulation mode) would be a second register write. Whether the 5A22 asserts its write strobe on a cycle with RWB low but VDA = VPA = 0 is a board question. *Recommendation:* the core reports the cycle as the datasheet says (a write, flagged VDA = 0, MLB low); the board decides whether it reaches the bus. Settle on hardware later (rung 6). *Rung 5:* P65C816 sides with neither: its emulation-mode modify cycle is an IO cycle (no write, VDA = 0) at the address **plus one**, and only the final write follows; 28,001 cases in 29 `.e` RMW files. That is bsnes's and ares's reading (no second write) with an address of its own, from an HDL that also departs from the datasheet and the corpus together elsewhere (U1, RTI, MLB on `a,x` RMW: validation.md, rung 5). So the votes stand at datasheet + corpus against bsnes + ares + P65C816, none of them hardware: C3 stays the console probe's to settle. **C4. `(d,x)` with E = 1, D.l ≠ 0 (U3).** gilyon's cputest-full tests the page-wrapped high byte; ares (ISC, read) implements it, bsnes and Mesen2 were read to do the same (HYPOTHESIS for those two: read from their GPL source before the 2026-11-14 rule; for review, 2026-11-24), and MAME 0.285 passes all of cputest-full (OBSERVED, run here). SST reads the high byte from the next page (e.g. `a1.e`: D = $2D57, pointer at $2DFF, reads $2DFF then $2E00; 28 cases in that file alone). No hardware capture here, but gilyon's ROM is written to run on a SNES and its README calls the behaviour "undocumented behavior tested", and three independent emulators agree. *Recommendation:* implement the quirk; rung 1 excludes the affected cases of `01 21 41 61 81 A1 C1 E1 .e` (those with D.l ≠ 0 and the pointer's low byte at $FF), counted, as the sm83 rung 1 excluded internal addresses. *Rung 5:* P65C816 reads the high byte from the same page, with gilyon, the emulators and the core, in all 26 C4 cases among the 1,000 run of each `(d,x)` file. **C5. `PLB`, `PHB`, `PHK` in emulation mode.** DS §7.1 does not list PLB among the instructions that leave page one; gilyon: "In emulation mode with S=$1FF, the PLB instruction should read from $200 instead of $100. This is despite the fact that the CPU manual doesn't list it"; SST agrees with gilyon (`ab.e` at S = $01FF reads $0200 and ends with S = $0100) after ReverendGumby's correction (SST PR #2, 2024-09-22). bsnes was read to agree (HYPOTHESIS: read from its GPL source before the 2026-11-14 rule; for review, 2026-11-24). PHB, PHK and PHP push one byte, so no wrap can show. *Recommendation:* follow gilyon and SST (two agreeing detectors, one of them stating a hardware observation). **C6. Datasheet misprints and simplifications.** Table 5-4 prints `STA [d]` ($87) as 2 cycles (row 15: 6); Table 5-7 prints the RMW modify cycle at `AA+1` for 8-bit data (corpus: `AA`); row 2a writes `PBR-PC+1` for `PBR,PC+1`. None affects a measured cycle count. Use Table 5-7 with these readings. **C7. The corpus's own history.** SST 65816 was corrected four times after outside reports: `[d],y`, PEI, PLB (2024-09-22), JSR (a,x) stack wrapping (2025-06-04, 2026-10-16), `(d,x)` page wrapping with D.l = 0 (2026-10-15), MVN/MVP whole moves (2026-10-15). Any core certified against an earlier revision was certified against known-wrong cases; this repository pins `307c63f` (2026-10-16), and the pin must move only with a re-run of `datasheet_timing.py`. **C8. Interrupt sampling point.** The datasheet does not state it. bsnes, ares and Mesen2 sample one cycle before the end (timing.md), as 6502-python does for the NMOS part from visual6502 evidence. Consistent among emulators, unconfirmed by any 65C816 hardware capture here; the SNES timing tests that depend on it (undisbeliever's, blargg-style IRQ timing) are board rungs. **C9. When RTI's pulled P reaches the M/X pin.** DS §2.20: the MX output "reflects the state of" the M and X flags; nothing says when a pulled P takes effect. SST (`40.n`: the 7,486 of 10,000 cases whose pulled M or X differs from the old) keeps the old M/X on the pin for the three cycles after the P pull (PCL, PCH, PBR) and shows the new P only after the instruction; the core shows P as it stands, from the cycle after the pull. Found 2026-10-23 when rung 1 began comparing the E/M/X columns; every other opcode agrees, including REP, SEP, PLP and XCE, whose change lands on or after their last cycle. Manufacturer silent, emulator-derived detector only. On the SNES the 5A22 does not bring MX out, so no board behaviour depends on it. *Decision:* keep the core (the pin follows the register); rung 1 masks the E/M/X pins of `40`'s cycles after the pull, counted under the masks. A P65C816 testbench (rung 5) can give a second opinion. *Rung 5:* no opinion: P65C816 has no M/X output. ## Open items - Hardware evidence for C1-C5 and U9: none in reach. srg320's MiSTer folder `hw/LA captures` holds logic-analyser screenshots from a real SNES (reset timing, WAI with Mode 7, HDMAEN latch); they show 5A22 bus phases, not these instructions. A SNES with a logic analyser on VDA/VPA/RWB would settle C1-C3 in an afternoon. - MAME's g65816 on C1-C3 and the decimal V flag: not checked (its per-cycle kinds are not observable from its trace). - Eyes & Lichty: not in reach for free; the 2015 reprint's errata (SnesLab wiki "E&L") could be pinned if the user buys the book.