# Validation: the oracles, their tiers, and the four things that cannot be proven ## The tier rule Oracles are ranked by **where their expected values came from**, never by how convenient they are: 1. **hardware-captured** — expected values read off silicon by a harness. 2. **hardware-corrected** — a model whose disagreements with silicon were found and fixed against real measurements. 3. **emulator-derived** — expected values produced by another emulator. 4. **documentation** — expected values read out of a manual. A low-tier oracle is a **detector, never a judge**. When a core and MAME disagree, MAME does not win; the datasheet decides, and where the datasheet is silent the disagreement is recorded as unresolved. ## The honest headline **There is no hardware-captured MB88xx test corpus, and the search for one was not cursory.** - The SingleStepTests organisation, which is where a corpus like this would live, has 22 repositories (enumerated 2026-09-12): `r3000`, `80386`, `sh4`, `tlcs900h`, `ares_tcls900h_ssts`, `z80`, `ares_r3000_ssts`, `80286`, `8086`, `8088`, `v20`, `huc6280`, `ARM7TDMI`, `80186`, `65x02`, `65816`, `m68000`, `ProcessorTests` (archived), `680x0`, `spc700`, `sm83`, `GameboyCPUTests`. **No 4-bit part of any manufacturer, and no Fujitsu part at all.** - Web searches for an MB88xx / MB8843 / MB8844 conformance suite or test vectors (2026-09-12) return MAME forks, the datasheet mirrors, and nothing resembling a corpus. - The reason is structural, not an oversight. The harnesses that produce these corpora drive a CPU's external bus and read back its pins. An MB88xx has no external bus: its program and data memory are on the die and its only observable surface is four I/O ports. There is no way to present it with an arbitrary instruction and observe an arbitrary final state without decapping it. So this project's certification ladder cannot end with "N million vectors passed". It ends somewhere more useful for the actual purpose: **the real programs, running, producing what the real games expect.** ## The oracles ### 1. Fujitsu MB8840/MB8840H datasheet — tier: documentation | | | | --- | --- | | Document | *MB8840/MB8840H Series NMOS Single-Chip 4-Bit Microcomputer*, Fujitsu Microelectronics, TM336-A871, January 1987, 39 pages | | URL used | `https://web.archive.org/web/2023/https://original.sharpmz.org/download/mb8843.pdf` (the live `sharpmz.org` and `old.sharpmz.org` copies 404 as of 2026-09-12) | | Status | Fujitsu copyright. Cited by table and row; not redistributed, not committed. `*.pdf` is gitignored. | **Covers:** the instruction set summary (Table 5) with mnemonic, opcode, operation, the ZF/CF/ST effect columns and the byte/cycle column for every instruction; the EN/DIS operand bit map (Table 5 note `*3`); pin functions including the /IRQ falling-edge rule and the /TC falling-edge rule (Table 1); the mask options including the two O-port PLA modes and the clock prescaler (Table 4); reset entry at address 0 of page 0 and the two-cycle /12-clock-period reset pulse (Table 1); stack depth, ROM/RAM sizes, I/O line counts, serial availability and instruction counts per variant (Table 7). **Does not cover, and this is the crux:** interrupt vector addresses, the number of cycles an interrupt entry costs, what the stack stores during an interrupt, the internal timer's prescale ratio, and the internal serial clock's rate. This is the short-form datasheet; a fuller *MB8840 series user's manual* presumably states them and was not found. **Quality caveat:** the scan is OCR'd and imperfect. Two readings are flagged in [start-here.md](start-here.md) (the `*4` note against `OUTO`, and "Process: CMOS" on an NMOS part). Anything transcribed from it here was cross-checked against MAME's implementation; the two agree everywhere except in the places listed under "MAME's guesses" below, where the datasheet is silent rather than contradictory. ### 2. The real programs in their real games — tier: behavioural, hardware-defined | | | | --- | --- | | Material | `51xx.bin` and `54xx.bin` inside a MAME `galaga` ROM set, read in place through `-rompath`; never copied into this repository | | Hashes | [namco-customs.md](namco-customs.md) | This is the judge, and it is a strange one: it does not check instructions, it checks *consequences*. Namco's programmers exercised the parts of this chip that mattered to them, in the order the hardware produces, for 45 years of machines that worked. A core that gets `ADC`'s carry polarity backwards will not miscount a flag in a test report; it will make Galaga give the wrong number of credits, or make the explosion silent. Concretely, three consequences a core can be held to: - **Credits.** Insert a coin at a known frame; the 51xx's reply byte 0 must become `0x01` in BCD, on the frame emu-galaga measured (three frames after the input, through its two-frame sample pipeline). - **The reply stream.** emu-galaga's `oracle/reference/game-2400` records every byte the main CPU read from the 06xx window across 2,400 frames of a scripted game with coins, starts, joystick and fire. A core running `51xx.bin` under the same input schedule must produce that stream. - **The noise.** The 54xx's channel-1 nibble stream must be a random bit times the stepped envelope emu-galaga measured — 13 for about 120 updates, then 15, 11, 8, 6, 4, 3, 2, 1 for about 784 updates each, then 0; 6,377 updates in 2.66 s, one every 106.8 cycles on average. The limit of this oracle is coverage: two programs do not execute 256 opcodes. A 2,500-frame Galaga trace visits 360 distinct (page, PC) pairs in the 54xx and touches 8 of its 16 pages. Whatever they do not reach is covered only by the datasheet. ### 3. MAME 0.285's `mb88xx` core — tier: emulator-derived (a detector) | | | | --- | --- | | Source | `src/devices/cpu/mb88xx/mb88xx.cpp`, `.h`, `mb88dasm.cpp`; BSD-3-Clause, copyright-holders Ernesto Corvi | | Binary | MAME 0.285 at `/usr/games/mame` on this machine | | Recipe | [mame-oracle.md](mame-oracle.md), verified by a real run | The only public model of this processor. It produces, on demand, one line per executed instruction with PA, PC, A, Y, the six flags and a running cycle count — which is a per-instruction lockstep oracle for as long as a core is willing to follow a real program. Its value is that it is *dense*: 406,856 instructions from 800 Galaga frames, 7.3 million from 2,500. Its limit is that agreement with it is agreement with it. Everything below is a place where following MAME means inheriting a guess. #### MAME's guesses, named These are the four places a core **cannot be proven right**, listed with the exact source text that marks them: | # | Guess | MAME's own words | Consequence | | --- | --- | --- | --- | | 1 | Internal timer prescale = **32** instruction cycles per tick | `#define TIMER_PRESCALE 32 /* guess */` | Any program using the internal timer runs its timebase 32× slower or faster than the truth if the guess is wrong. No Namco part in scope uses it. | | 2 | Internal serial clock = **clock ÷ 6**, one bit per instruction cycle | `#define SERIAL_PRESCALE 6 /* guess */` | Serial baud rate. No Namco part in scope uses the serial port for data. | | 3 | Interrupt entry costs **3 cycles** | `burn_cycles(3); // ?` | Every interrupt shifts the MCU's timeline by an unproven amount. Both Namco parts in scope are interrupt-driven, so this one **is** on the critical path. | | 4 | Interrupt vectors are **0x002 / 0x004 / 0x006** | `// the datasheet doesn't mention interrupt vectors but the Arabian MCU program expects the following` | Wrong vectors would break every program, so these are almost certainly right — but the evidence is inference from a third program (Sun Electronics' *Arabian*, an MB8841 game), not documentation. | Two lesser ones, for completeness: the `SERIAL_DISABLE_THRESH 1000` shut-off and restart-on-`TSTS` is pure emulator housekeeping with no hardware counterpart, and MAME's `set_pla_bits(8)` / `set_pla_bits(4)` naming is inverted with respect to the datasheet's mask-option table (see [start-here.md](start-here.md)); neither changes behaviour for the chips in scope. #### One thing MAME's core *is* hardware-corrected on `mb88xx.cpp`'s header TODO reads: "Verify timer, Bosconian voice samples are currently a good test case, and they match PCB recordings." So the timer path — as exercised by Bosconian's 52xx sample player — has been compared against recordings of a real board, and matched. That is a tier-2 data point for one code path, recorded by the emulator's own authors, and it is the strongest hardware evidence this processor has in public. It is also explicitly marked as not finished ("Verify timer"). ### 4. emu-galaga's reference runs — tier: emulator-derived, second hand | | | | --- | --- | | Material | `../emu-galaga/oracle/reference/{boot-720,attract-1800,game-2400}`, produced by `oracle/mame_dump.lua` against MAME 0.285 | | Status | Another project's working tree on this machine. Read, cited, not copied. | Per-frame RAM windows and every main-CPU access to the 06xx window, including the bytes the 51xx replied with, across three scripted runs. Deterministic: the same command twice produces byte-identical JSONL (SHA-256 recorded in that project's `docs/mame-oracle.md`). This is the cheapest way to ask "does my 51xx say what Galaga needs to hear" without building a whole board, and it is the acceptance test for milestone (d) of [handoff-brief.md](handoff-brief.md). ### 5. Chris Kilgour's independent 54xx model — tier: emulator-derived, independent | | | | --- | --- | | Source | `http://www.whiterocker.com/blog/namco-54xx-application.html` (retrieved 2026-09-12) | | Status | A third party's analysis and Python code. Cited, not vendored; its licence was not stated on the page and must be checked before any code is used. | An independent reverse engineering of `54xx.bin` for Pole Position: the author instrumented MAME's `namco54.cpp`, read the command stream, and wrote a high-level Python synthesiser rather than an MB88xx core — deleting channel A, fixing channel B's parameters (attack 6, decay 3, sustain amplitude 6) and dropping channel C's envelope state machine, keeping the LFSR and the command interface. Its value here is a **cross-check on the one number both projects measured**: the author reports the 54xx's main loop running at 2,478 Hz with cycle counts between 90 and 164 and a mean of **103.3 cycles**; emu-galaga, measuring a different game with different channels active, reports **106.8 cycles** per output update. Two independent measurements of the same mask ROM's inner loop, from different games, within 3 %. A core that runs `54xx.bin` and produces a loop of a wildly different length has a bug in its cycle counts, and that is a genuine, pre-existing, external check. The page also confirms from the other side that a full core is avoidable if all you want is the sound — the author says as much. This project wants the core anyway, because a core settles the 51xx as well, and because "fitted to a recording" is the exact state emu-galaga is trying to leave. ## What is *not* an oracle - Another hand-written high-level model of the 51xx protocol (MAME's own pre-2020 one, or emu-galaga's). Those are what a core replaces; agreeing with them proves nothing about the instruction set, and where the real program disagrees with them the real program is right. emu-galaga already found four such places (switch-mode byte 2 reads `0xff` not `0x00`; credit-mode bytes 1-2 read `0xff` until a start is accepted; the sampling is one frame late for levels and two for edges; coins are ignored outside credit mode). - Audio similarity. "It sounds like Galaga" is not a gate. ## The gates, in order Tier order, each one's failure cheapest to diagnose before the next. | # | Gate | Tier | Acceptance | | --- | --- | --- | --- | | 1 | Per-opcode unit tests transcribed from DS Table 5 and [start-here.md](start-here.md): all 256 opcodes, each with its cycle count and its ST/ZF/CF effect, plus reset state, the stack word layout, the interrupt sequence, the PLA modes, both timer clocks | documentation | every opcode has a test; every test names the table row it encodes | | 2 | Instruction-for-instruction lockstep against a MAME trace of `54xx.bin`, from reset through Galaga's 12-byte boot burst | emulator-derived (detector) | N instructions with PA, PC, A, Y, all six flags and the cycle total identical; N stated; every divergence decided from DS and recorded | | 3 | The same for `51xx.bin` through coin, credit and start | emulator-derived (detector) | as above, over a run that includes the /TC timer path | | 4 | `51xx.bin` on this core replies with emu-galaga's `game-2400` byte stream | behavioural | byte-identical over the scripted run | | 5 | `54xx.bin` on this core produces the measured envelope and a loop of ~103-107 cycles | behavioural, cross-checked | envelope steps and update rate match both independent measurements | Gates 2 and 3 are detectors: a divergence is a bug in *one* of the two implementations, and which one is decided by the datasheet. Gates 4 and 5 are the ones that mean something, because a game either works or it does not. ## Stating a claim A claim in this project carries the MAME version and the trace length, or the datasheet table, or the reference run name — or it is not a claim. "Verified against hardware" is a phrase this project may not use about the instruction set, because no hardware oracle exists for it. "Agrees with MAME 0.285 for 7,328,972 instructions of `54xx.bin`" is a sentence it may use, and means exactly that.