# Quirks (U) and contradictions between sources (C) Each entry says what it is, the evidence, and the tier of that evidence (validation.md defines them): **hw-verified** is an author's statement that he ran it on a real console (MacDonald's pcetech: no ROM published, so it cannot be re-run here), **manufacturer** is Hudson's manuals (scans, OCR read by `pdftotext`; HW and SW as in start-here.md), **research** is other documents, **emulator** is any emulator, the SingleStepTests corpus, or the MiSTer VHDL. **A low tier detects and never judges**; where only emulators speak, the entry is marked *undecidable here* and the build session picks the majority behaviour and says so. ## Quirks (U) | # | Quirk | Evidence | Tier | | --- | --- | --- | --- | | U1 | **Zero page is logical `$2000`-`$20FF`, the stack `$2100`-`$21FF`**, through MPR1 (usually $F8). Zero-page and stack accesses are never to logical page 0/1; software can read ROM through them | HW HB-3 (stack high byte $21); pcetech 2.0 | manufacturer, hw-verified | | U2 | Reset: MPR7 = $00, MPR0-6 random; A, X, Y, S random; P has I and B set, T and D clear, N V Z C random; low speed; timer stopped, counter reads 0; interrupt disable register 0; `$FFFE`/`$FFFF` read from physical `$001FFE` | HW HB-18; pcetech 2.0 ("re-tested P startup value", "re-tested MPR startup value") | manufacturer, hw-verified | | U3 | The 23 undefined/`NOP` opcodes are one-byte, two-cycle `NOP`s that change no register except to clear T; tested: $E2 $63 $33 $0B $2B $4B $6B $8B $AB $CB $EB $1B $3B $5B $7B $9B $BB $DB $FB $5C $DC $FC. The 65C02's multi-byte `NOP`s do not exist | pcetech 2.0 (the 23rd, $EA, is the documented `NOP`); the corpus has them at 2 cycles, 1 byte; MAME bills $63 four cycles (C4) | hw-verified | | U4 | **T**: `SET` sets it; the next instruction's fetch clears it; only `ORA` `AND` `EOR` `ADC` use it (the operand pair becomes `M($2000 + X)` and the immediate/memory operand, result back to `M($2000 + X)`, A untouched, +3 cycles, flags from the result); `PHP` and `PLA` read T as 0, so does `BRK`; **an interrupt between `SET` and its target pushes T = 1 and `RTI` restores it, so the target is still affected**; `PLP` and `RTI` can set T from the stack (the next instruction is then affected "as if SET came before it"); `SED` before `SET` is the way to do BCD in memory because `SET` must be immediately before the ALU instruction (any other instruction clears T). With D = 1 and T = 1 `ADC` is 2 + 3 + 1 cycles | HW HB-5; SW `ADC` entry; pcetech 2.3; corpus (ADC # 638/635/621/606 cases at 2/3/5/6 cycles); `SBC` is C5 | manufacturer, hw-verified, emulator | | U5 | **B**: reads 1 whenever P is read (PHP, `BRK`, PLA after PHP); the byte an IRQ or NMI pushes has B = 0; B in the corpus's P is always 0 (mask it) | HW HB-4; pcetech; corpus | manufacturer, hw-verified, emulator | | U6 | **A block transfer cannot be interrupted**: the interrupt is taken when it ends. Whether the interrupt entry then comes before or after the next instruction fetch is not stated by anyone | pcetech; Mesen, MAME, Mednafen all run the block to its end (Mednafen's own comment, `huc6280.cpp`: "Needed so a BMT isn't interrupted") | hw-verified (for the claim), emulator (for the detail); detail *undecidable here* | | U7 | A block transfer's **reads** of the hardware page from `$0800` to `$17FF` (PSG, timer, port, interrupt registers `$1402`/`$1403`) return **0** whatever is there, do not touch the device and do not change the I/O buffer; **writes** to them work and update the buffer; VDC and VCE are not in the range and work normally. This is CPU behaviour, so the core owns it | pcetech 2.0 | hw-verified. **MAME reads the real device here (C9)** | | U8 | `(zp),Y`, `(zp,X)` and `(zp)` pointer reads wrap within the zero page (`$20FF` then `$2000`) in Mesen and MAME; the manuals do not say and no test covers a pointer at $FF | Mesen `ReadZeroPageWrap`; MAME `program_read16z` | emulator; *undecidable here* | | U9 | `JMP (abs)` with the low byte $FF reads the high byte from the next page (`JMP [$FEFF]` reads $FF00): no NMOS wrap bug. Taking a branch across a 256- or 8192-byte boundary costs no extra cycle | pcetech 2.0 | hw-verified | | U10 | `CSL` and `CSH` take 3 cycles when the speed does not change. **The cost of an actual change is unknown**, as is when the new speed takes effect (Mesen and Mednafen: for the last cycle of the instruction; MAME: after it). Reset selects low speed | pcetech 2.0 ("It currently isn't known"); C7 | hw-verified (the 3), the rest undecidable | | U11 | `TAMi`/`TMAi` use an 8-bit **mask** operand (bit 0 = MPR0). `TAM` with several bits writes A into each; with operand $00 it writes nothing. `TMA` with operand $00 returns the last value moved by `TAM` (when at least one bit was set) or `TMA`; with several bits the result is "combined" in a way no one has worked out (C6). `TAM` is 5 cycles and `TMA` 4 | HW HB-7; SW; pcetech 2.0 | manufacturer, hw-verified | | U12 | `ST0`/`ST1`/`ST2` write **physical** `$1FE000`, `$1FE002`, `$1FE003`: the address does not go through the MPRs, and the write reaches the VDC whatever MPR7 holds | HW HB-8 (Table 2-2-3); pcetech 2.0 | manufacturer, hw-verified | | U13 | The last value read or written at `$0800`-`$17FF` sits in an 8-bit buffer; reads of PSG (`$0800`-`$0BFF`) return it in full, timer reads return it in bit 7, `$1400`/`$1401` return it in full, `$1402`/`$1403` in the upper five bits, the port returns none of it. Open-bus behaviour of the die | pcetech section 3 note 1, with its worked example | hw-verified | | U14 | **Decimal mode**: `ADC`/`SBC` with D = 1 add one cycle, take the result from the BCD adjust, set N, Z, C from it and **leave V unchanged** | HW HB-4; SW; MAME changelog 1.08 ("Fixed the decimal version of ADC/SBC to *not* update the V flag") | manufacturer, emulator | | U15 | `BRK` pushes `BRK + 2`, so the byte after it is skipped; B = 1; the vector is `$FFF6`, shared with IRQ2 | HW HB-4, HB-17; SW; pcetech | manufacturer, hw-verified | | U16 | The timer: a 7-bit down counter ticking every 1024 x 3 master clocks, **independent of the CPU speed**; `$0C00` write sets the reload (N means N + 1 ticks), `$0C01` bit 0 starts it (stopped to started loads the counter from the reload); the request is raised when the counter **underflows from 0 to $7F**, and at once it reloads and keeps counting; `$0C00`/`$0C01` read the counter in bits 6-0 (bit 7 is the I/O buffer's); read it twice, the value can be invalid mid-update; writing any value to `$1403` acknowledges the timer, and an unacknowledged request interrupts again after every instruction | HW HB-20 to HB-22; pcetech 2.2 | manufacturer, hw-verified | | U17 | The interrupt **disable register masks taking an interrupt, not requesting it**: `$1403` still shows IRQ1, IRQ2 and TIQ lines that `$1402` masks. IRQ1 and IRQ2 are level: they stay until the device is acknowledged (VDC: read its status register). NMI is not connected on any console | HW HB-15, HB-16; pcetech 2.1 | manufacturer, hw-verified | | U18 | A **VDC or VCE access costs one extra cycle**, for any instruction and any addressing mode, including an opcode fetch from there; the CD-ROM registers in the same page do not | pcetech 3 note 3; MAME `check_vdc_vce_penalty`; Mednafen and Mesen2 | hw-verified, emulator | | U19 | `BIT #imm` computes N and V from the immediate, unlike the 65C02 (where only Z is set); `TST`, `TSB`, `TRB`, `BIT` all load N from bit 7 and V from bit 6 of the **memory** operand | pcetech 2.0 ("`BIT #$C0` would set N and V"); HW HB-5; SW `TST` | hw-verified, manufacturer | | U20 | `BSR` pushes the address of its last byte and takes 8 cycles; `JSR` 7; `RTS` and `RTI` 7. `RTI` pulls P first, then PCL and PCH | SW; corpus | manufacturer, emulator | | U21 | The interrupt-disable flag changes after the poll: `CLI`, `SEI` and `PLP` delay their effect by one instruction, as on the 6502 (Mednafen samples I in `LastCycle` before the change). The same rule as the frame's `_polled_i` | Mednafen `IFlagSample`; HW HB-12 ("sampled in the last bus cycle") | emulator; undecidable here | | U22 | The 65C02 additions with the same meaning as the Rockwell part: `PHX` `PHY` `PLX` `PLY` (the pulls set N and Z), `STZ`, `TRB`, `TSB`, `BRA`, `INC A`, `DEC A`, `(zp)`, `JMP (abs,X)`, `RMB`/`SMB`/`BBR`/`BBS`. `WAI` and `STP` do not exist | HW; SW; MAME changelog 1.08 (PLX, PLY flags) | manufacturer | | U23 | The extra cycle of **decimal `ADC`/`SBC`** is a dummy read of the address the next instruction starts at (not an internal cycle); with T set `ADC` spends it among the memory-operand cycles (read, internal, internal, write: 6 in all) and `SBC`, which ignores T (C5), spends an *internal* cycle there | SingleStepTests huc6280 (every decimal case, both T states): which bus the chip drives in that cycle is unobservable except through a per-cycle capture, so this is Mesen's model (C8) | emulator | | U24 | `BRA` is `R R i i`: its two extra cycles are internal, where a taken conditional branch is `R R d i` (a dummy read at the next instruction's address, then an internal cycle). Both are 4 cycles | SingleStepTests huc6280 (all 2,500 `BRA` and every taken branch); totals SW | emulator for the shape, manufacturer for the 4 | | U25 | **Where an instruction's interrupt poll sits is not known for the HuC6280.** HW HB-12 says only "sampled in the last bus cycle". The core samples at the end of the second-to-last cycle (the 6502 frame's rule, U21), so a line that rises in the last cycle waits one instruction. `irq_poll_cycle` (class attribute): `"second_to_last"` (default), `"last"` (the levels at the boundary all count, rising or dropping in the last cycle) and `"mednafen"` (IRQ1/IRQ2 sampled as the default, the timer live). Mednafen's rule, `huc6280.cpp` `RunSub`: `if(IRQSample | IRQlow)` ... `if((IRQlow & IQTIMER & IRQMask) && !IFlagSample) tmpa = 0xFFFA; else if(IRQSample & IQIRQ1) tmpa = 0xFFF8; else if(IRQSample & IQIRQ2) tmpa = 0xFFF6;`, where `IRQSample = (IRQlow & IRQMask) & PIMaskCache` is taken in `LastCycle()` before that cycle's `ADDCYC(1)`. Issue 0003: in the board, `last` moves every Mednafen stop earlier and leaves the Covell spread at 4.2 or more; `mednafen` moves one stop (Final Soldier) and leaves Covell unchanged | HW HB-12; Mednafen `RunSub`/`LastCycle`; issue 0003 board runs | manufacturer (wording only), emulator; *undecidable here*; default kept | ## Contradictions (C) | # | The disagreement | Sources and tiers | Resolution proposed | | --- | --- | --- | --- | | C1 | `ST0`/`ST1`/`ST2`: 4 cycles or 5 | SW 4 (manufacturer); corpus 4; MAME and Geargrafx 5 (emulator, VDC stretch folded in) | 4 in the core, the +1 is U18 and the board's | | C2 | `BRK`: 1 byte or 2 | SW and HW map: 1 byte (manufacturer); SW's own text, HW HB-17, pcetech: pushes `BRK + 2` (manufacturer, hw-verified); every emulator 2 | 2 (the manual contradicts itself; U15) | | C3 | Interrupt entry: 7 or 8 cycles | MAME 7; Mesen, Mednafen, Geargrafx, ares 8 (emulator); no manual states it | 8 (four against one), flagged emulator-derived; *undecidable here* | | C4 | `NOP` $63: 2 or 4 cycles | pcetech tested 2 (hw-verified); MAME 4; others 2 | 2; MAME's is an error | | C5 | Does `SBC` honour T? | SW's `SBC` entry has no T clause (manufacturer); pcetech (hw-verified) lists ORA/AND/EOR/ADC only; Mesen, ares: no; MAME 1.10: yes ("Added T flag support to the SBC instruction") | no; MAME's is a guess | | C6 | `TMA` with several mask bits | MAME: the highest set bit wins; Mesen: the OR of them; the HDL (read from `HUC6280_CPU.vhd` `MPR_OUT`, not run): the **lowest** set bit wins; pcetech: "combined together... I have not figured out exactly how this works" | OR (a wired bus is likelier than a priority encoder, but this is reasoning, not evidence); *undecidable here* | | C7 | When a `CSL`/`CSH` takes effect | Mednafen, Mesen: for the last cycle of the instruction; MAME: after it; pcetech: unknown | the last cycle; *undecidable here* | | C8 | Position of the internal (no-bus) cycles and the address of every dummy read | Mesen/corpus is one model; Mednafen charges whole blocks of cycles with no model; manuals: totals only | the corpus's, flagged; a board sees them only through `idle` | | C9 | Block-transfer reads of `$0800`-`$17FF` | pcetech: zero, no device effect (hw-verified), but its range reads "`$0800` through `$1400`" while its parenthesis names the IRQ registers (`$1402`/`$1403`); MAME reads the device (emulator); Mednafen returns 0 for `$0800-$17FF` (`IORead` under `InBlockMove`, read from source, rung 4b); Mesen unchecked | pcetech's, ending at `$17FF` (the parenthesis, the only reading where its own examples hold; docs/issues/0001); *end of range undecidable here* | | C10 | Timer vs VDC interrupt sampling | Mesen takes a pending VDC IRQ that became active in the next-to-last cycle but not a timer IRQ acknowledged in the last cycle of its `STA $1403` ("Order of the Griffon"); "Jackie Chan" and "Final Soldier" shake otherwise; Mesen's comment: "not tested on hardware" | the frame's rule (requests as of the next-to-last cycle) for every source; the timer's acknowledge is the board's to model; *undecidable here* | | C11 | Which instruction fetch the interrupt follows | the HW manual says the interrupt is taken "when the instruction in progress is terminated"; MAME's changelog 1.10: "Taking of interrupts is delayed to respect a pending instruction already in the instruction pipeline; fixes After Burner" | the frame's one-instruction rule | | C12 | What `TSB` and `TRB` report in Z | The SingleStepTests corpus (an older Mesen) sets Z from A AND M, the 65C02 rule, in all 10,000 `TSB`/`TRB` cases (N and V from the memory byte, 10,000 of 10,000); MAME, Mednafen and Mesen2's current source set Z from the stored **result** (`M OR A` for `TSB`, `M AND NOT A` for `TRB`), and pcetech 2.0 says "Z = If result is zero" (hw-verified, but "result" is loose there: it also says N and V are "bit 7/6 of result", which no emulator and not SW's text ("memory bit 7... bit 6") follow) | the stored result (`tsb_z_from_test = False`); three current emulators and the closer reading of the hw-verified note outweigh one corpus snapshot, flagged; the 65C02 rule is a class attribute. *Undecidable here*; rung 1 does not compare Z for these four opcodes when it is the only difference (1,492 cases), and rung 1b's Rockwell corpus cannot judge it either (it is the 65C02's rule) | | C13 | Decimal `ADC` and `SBC` with an invalid BCD digit in A or the operand | **Mednafen**'s ChangeLog 2015-04-29: "Corrected decimal-mode ADC and SBC behavior(especially for "illegal" input values), per tests on a HuC6280" (an author's statement of a console test, no artefact: hardware-verified tier), with the code in `huc6280.cpp`; **Mesen**'s `ADD`/`SUB` (what the SingleStepTests huc6280 corpus records, emulator tier). All 131,072 A x operand x carry combinations differ in 9,216 results each for `ADC` and `SBC` (never with valid digits; `ADC`'s carry in 324; Mesen's `SBC` is `$10` higher with an invalid low digit, e.g. `$00 - $0A`, C clear: Mesen `$9F`, Mednafen `$8F`; `ADC` `$0A + $0F + 1`: `$10` against `$20`). The Rockwell 65C02 corpus (a different chip) matches Mednafen's `SBC` in all 44,848 decimal cases and Mesen's `ADC` in all 44,881; the earlier "38,004" was the number of cases rung 1b masked, the real differences are 3,164 (`SBC` against Mesen) and 3,195 (`ADC` against Mednafen). The second reviewer's grouping, not re-derived here: NMOS 6502 formula (Clark's sequence 3) in Mesen, Geargrafx, MAME; 65C02 (sequence 4) in Mednafen, ares and the Rockwell corpus; MiSTer's VHDL its own per-digit adder. Neither manual says. Issue 0004 | **Mednafen's** (default, `decimal_formula = "mednafen"`); Mesen's one switch away (`"mesen"`, the corpus's exact match); no capture of the chip, so the choice stands on one author's statement | | C14 | Does a block transfer push and pop A, X and Y | HW HB-6 (manufacturer): the transfer "uses three levels of stack" for them; Mesen and Mednafen (and the SingleStepTests corpus, 12,500 cases) push Y, A, X and pop them, so a transfer that overwrites the stack hands back overwritten values; MAME keeps them in the CPU and writes nothing to the stack. Rung 4 (91 transfers over RAM in six games) shows the difference only as A after `tii $2000,$2001,$1FFF` | HW's: push and pop (the core). MAME's replay adopts its A, X, Y | | C15 | `CLI` followed by a pending interrupt | MAME takes the interrupt before the next instruction (about 600 times in six games); Mesen (`ProcessCpuCycle` polls with I as it is at each cycle) and Mednafen (`IFlagSample`) run one more instruction, like the frame's `_polled_i` rule (U21) | the frame's rule; *undecidable here*; the replay forces MAME's order and counts it | | C16 | `BRK` fetched with T set | Mesen and MAME clear T in the fetch like any instruction, so `BRK` pushes T = 0 (the corpus, 1,271 of 10,000 `BRK` cases: T set, pushed 0); srg320's HDL does not clear T when the opcode is `$00` (it uses `$00` as its interrupt-entry opcode), so it pushes T as it stands; HW HB-5 says an interrupt pushes T as it stands and says nothing for `BRK`; SW's flag table gives `BRK` T = 0 | the core clears T (pushes 0), emulator-derived; *undecidable here* | | C17 | `SBC abs` with D = 1: 6 or 7 cycles | SW and the corpus: 5 + 1 = 6 (and SW gives every decimal `SBC`/`ADC` +1); the HDL takes 7 for this mode only (1,258 cases, the other seven `SBC` modes and all `ADC` modes agree) | 6 (manufacturer); the HDL's is its own microcode quirk | | C18 | An interrupt whose source has gone between the poll and the entry (issue 0002: `CLI` then `STZ $1403`, the write lowering TIQ in the instruction's last cycle) | HW HB-12 (manufacturer): interrupts are "sampled in the last bus cycle"; HW HB-15/16 and pcetech 2.1 (hw-verified) say a request stays until acknowledged and say nothing about one that goes away after the sample. Mesen2 (emulator): the timer is re-checked at entry and **dropped** if gone ("Order of the Griffon"), IRQ1/IRQ2 are taken through their own vector as polled ("Jackie Chan", "Final Soldier"), "not tested on hardware". srg320's HDL (emulator, read from `HUC6280_CPU.vhd`, not run for this): every source is latched in the last cycle (`IRQ1_INT`, `IRQT_INT` ...) and taken through its own vector. Before the fix the core fell through to IRQ2's `$FFF6` when nothing was asserted, which no source describes: After Burner II ran into data. pcengine-python M2: the other nine of the first ten titles are identical either way | `vanished_interrupt` (class attribute): `"mesen2"` (default, emulator-derived), `"latched"` (the HDL), `"drop"` (drop whenever nothing is still asserted); no mode falls through to IRQ2. *Undecidable here* (no source above tier 5 covers it) | ## Mednafen's votes (rung 4b) A third emulator-tier vote per entry, from `scripts/build_mednafen.py` and six replayed games (docs/mednafen-oracle.md has the method): C1 4 + 1 stolen by the memory handler; C3 **8**; C4 2; C5 SBC ignores T; C6 **highest bit wins**; C7 the core's order; C9 **0 for `$0800-$17FF`**; C12 result; C13 decimal `SBC` equals the Rockwell chip's, `ADC` does not (the core's default is now Mednafen's formulas, issue 0004); C14 **pushes and pops**; C15 **not early**; C16 pushes T = 0; C18 timer dropped, IRQ1/IRQ2 as polled (Mesen2's rule). No default was changed on it except C13 (decimal `ADC`/`SBC`, issue 0004, on the ChangeLog's "per tests on a HuC6280").