# Validation plan and oracle record ## The claim to be earned `mcs48-python` will claim to be a **manual-complete, T48-clean pure-Python MCS-48 instruction core**: every defined opcode implemented with the bytes, cycles and flag effects Intel's manual specifies; the 102 self-checking programs of the T48 verification suite all reporting PASS; a boot-to-gameplay lockstep against MAME's Donkey Kong sound MCU with no undecided divergence; and the two published real-silicon timer/interrupt measurements reproduced. It will **not** claim to be hardware-verified in the sense the author's `z80-python` and `6502-python` are, because for this processor that is not available to anyone. That sentence belongs in the README, not in a footnote. Nothing here is yet earned. This page is the plan, and the record of what was searched for, found, and not found on 2026-09-12. ## The rule for ranking oracles Rank an oracle by where its expected values came from: 1. **hardware-captured** — a real chip ran the instruction and its outputs were logged; 2. **hardware-corrected** — a model whose disagreements with hardware were found and fixed; 3. **emulator-derived** — another program's opinion. A lower-tier oracle is a **detector**, never a **judge**: it may raise a difference for investigation, and the higher-tier source decides. Documentation is not an oracle in this sense; it is the source of unit tests, and it is right only if the manual is right and the reading is right. For this processor the top of the ladder is nearly empty, so one more rung is named explicitly and its tier stated honestly: 4. **documentation-derived, independently implemented** — a third party read the same manual and built something executable from it. A disagreement proves that one of the two readings is wrong, which is worth a great deal; it does not prove which. This sits *above* "another emulator's opinion" because the reading is independent and the artifact is a test rather than an implementation, and *below* anything measured. ## What exists ### 1. Two real-silicon measurements — hardware-captured, and that is all there is | | | | --- | --- | | Source | MAME 0.285, `src/devices/cpu/mcs48/mcs48.cpp`, the TODO block at lines 11-45 | | Licence | BSD-3-Clause | | Provenance | measured on a real 8048 by the MAME contributor known as *bataais*; quoted verbatim in the source | | Coverage | **two programs**, both about the interaction of `STRT T`, the timer, and interrupt entry | Reproduced in full in [undocumented-behavior.md](undocumented-behavior.md) §6. In summary: after an interrupt, a real 8048 has `A = 0x22` where MAME has `0x20`; and between `STRT T` and `MOV A,T`, the real chip's counter rolls one `NOP` later than MAME's. MAME's header adds that its interrupt timing is hacked outright for the benefit of one driver. Two data points is a strange oracle, but it is the only tier-1 evidence this repository could find anywhere, and it is genuinely decisive about two questions. Encode both as tests. Passing them is the only "verified against hardware" claim this project will ever be entitled to make unless somebody builds a capture rig. **Limit**: they say nothing about any other instruction, and they do not distinguish "STRT T has a one-cycle delay" from "MOV A,T reads the pre-increment value" — the header says so itself. ### 2. Intel's manuals — documentation, the spec of record | Document | Order number | URL | | --- | --- | --- | | *MCS-48 Family of Single Chip Microcomputers User's Manual*, July 1978 | 9800270D | | | *MCS-48 Microcomputer User's Manual*, 1980 edition | — | | | *MCS-48 and UPI-41 Assembly Language Manual*, December 1978 | 9800255D | | | *UPI-41A User's Manual*, 1980 | — | | | *8048 Family Applications Handbook*, 1980 | — | | | *8048/8035 HMOS Single Component 8-Bit Microcomputer* data sheet, 1980 | — | | Copyright Intel; cited, never redistributed. The directory is `https://www.bitsavers.org/components/intel/8048/` — note that there is **no** `/components/intel/MCS48/` path; the obvious guess 404s. The July 1978 scan has a usable OCR text layer, which is what made the page-accurate citations in [start-here.md](start-here.md) possible. Unit tests written from these cover what nothing else can: the reset list (UM §2.1.12, eleven items), the interrupt rules (UM §2.1.9), the stack wrap (UM §2.1.6), the bank-switch flip-flop (UM §3.1.2), the control-signal table (UM §3.6), and the bytes and cycles of all 230 defined opcodes (UM §4.1, p. 4-5). Every such test must name the section it encodes. ### 3. The T48 verification suite — documentation-derived, independently implemented **This is the most valuable thing found, and it did not previously exist in this project's plan.** | | | | --- | --- | | Project | `devsaurus/t48`, "A cycle-accurate VHDL model for MCS-48 and UPI devices", originally OpenCores | | URL | | | Revision seen | `837bd24f8a93275e0233c679b4f00e344bb4e912`, 2025-10-05 (the tip of `master`) | | **Licence** | **GPL-2.0** | | What matters here | `sw/verif/` — **102 self-checking `test.asm` programs**, 360 files in the subtree | Verified by reading the repository tree at that commit: 93 tests under `black_box/`, grouped by mnemonic and addressing mode (`add`, `addc`, `anl` with five sub-modes, `anld`, `call`, `clr`, `cnt`, `cpl`, `da`, `dec`, `djnz`, `expander`, `in`, `inc`, `ins`, `int` with `jni`/`simple_int_retr`/ `simple_jump_to`, `jbb`, `jc`, `jnc`, `jz`, `jnz`, `jmp`, `jmpp`, `mb`, `mcs2x`, `mov`, `movd`, `movp`, `movx`, `orl`, `orld`, `outl`, `psw`, `rb`, `rc`, `rl`, `swap`, `tim`, `tx`, `upi41`, `xch`, `xchd`, `xrl`); 8 under `white_box/` aimed at exactly the corners [undocumented-behavior.md](undocumented-behavior.md) is about — `int_on_call`, `int_on_jmp`, `int_on_mb1`, `p1_port_reg_conflict`, `p2_port_reg_conflict`, `p2_io_exp`, `pc_wrap_bit11`, `psen_rd_wr_timing`; and one under `gp_sw/`. **The pass/fail protocol** is a magic accumulator sequence, `sw/verif/include/pass_fail.inc`, quoted in full: ```asm FAIL MACRO mov a, #0AAH mov a, #055H mov a, #000H ENDM PASS MACRO mov a, #0AAH mov a, #055H mov a, #001H ENDM ``` So a software core needs no VHDL and no simulator: assemble a test, run it, and watch the accumulator for `AA, 55, 01` (pass) or `AA, 55, 00` (fail). That is a twenty-line runner. **How the tests are built.** `sw/verif/include/cpu.inc` is a single line, `CPU 8048`, so the assembler is **Alfred Arnold's AS (`asl`)** with `p2hex`. `Makefile.core` builds three ROM layouts from each source — `t48` (1 KB internal + external above), `t49` (2 KB internal), `t3x` (romless, 4 KB external) — which is also a ready-made matrix for testing the family members. **Neither `asl` nor `p2hex` is installed on this machine**; that is a prerequisite for this rung, not a blocker for the plan. **Its provenance, stated plainly.** The expected values are read out of Intel's documentation -- the `da` test's own comment says `;; testcase from "Single Component MCS-48 System"`. The project's second check, `run_regression.pl -d`, is a signal-level dump comparison (`sw/dump_compare.signals`: PC, A, SP, PSW, the DB bus, F1, P1, P2, MB, and RAM address/data/we) against `sw/i8039emu/`, which is **MAME's own i8039 core** vendored into the repository. So T48 is documentation-derived and emulator-cross-checked. It is **not** hardware-captured, and a T48 failure is a disagreement to investigate, not a verdict. Corrections have flowed the other way too: MAME's history contains "mcs48: correct opcode cycles for IN A,DBB and OUT DBB,A [devsaurus]", i.e. MAME taking a fix *from* T48. **The licence matters.** T48 is GPL-2.0 and this repository is MIT. The suite is **fetched and run, never vendored**; no `test.asm`, no assembled image, and no derived table may be committed here. A test *runner* written from scratch against the documented `AA/55/01` protocol is this project's own work; a translation of the test sources is not. **Coverage limits**: the suite is per-mnemonic and per-corner, not exhaustive-per-opcode. It does not enumerate operand values the way a SingleStepTests corpus does, so it will not catch, say, a wrong `AC` for one particular addend pair. It is a conformance suite, not a fuzz corpus. ### 4. MAME 0.285 — emulator-derived, a detector | | | | --- | --- | | Binary | `/usr/games/mame`, reports `0.285 (unknown)` | | Source | `src/devices/cpu/mcs48/{mcs48.cpp,mcs48.h,mcs48dsm.cpp}` at tag `mame0285`, commit `f379cd060ac3b2bd567ebbd0957aed059d6895ff`; BSD-3-Clause | | Pinned and hash-verified by | [`scripts/fetch_sources.py`](../scripts/fetch_sources.py) | | Used for | the opcode table, cycle counts and undefined-opcode behaviour in [start-here.md](start-here.md), re-derived and diffed by [`scripts/check_instruction_table.py`](../scripts/check_instruction_table.py); and per-instruction traces of Donkey Kong's 8035 ([mame-oracle.md](mame-oracle.md)) | **MAME has no CPU unit tests.** Its `tests/` directory covers `attotime` and video; its `regtests/` cover `chdman` and `jedutil`. Its MCS-48 device is validated by running real driver software and by ad-hoc bug reports. That is worth something — it means the behaviour of every instruction that appears in a MAME-supported game has been exercised against a working game — and it is not a test suite. **Its known-bad regions**, from its own header: timer increment timing, interrupt entry timing, and a deliberate hack in the `JNI`/interrupt interaction. Do not "fix" a core to agree with MAME in those three places. Also unimplemented: `IDL` (opcode 01) on CMOS parts, and the 8021/8022-only opcodes `RAD`, `SEL AN0`, `SEL AN1`, `RETI`. ### 5. Real arcade programs — emulator-derived when run under MAME, but the workload that matters The judge of last resort for a core that exists to run arcade boards is whether an arcade board's own program does the right thing. Donkey Kong's sound 8035 is the reference: | | | | --- | --- | | ROM | the `soundcpu` region of the `dkong` set, 0x1800 bytes, read **in place** from the MAME collection with `-rompath`; never copied, never committed | | Observable | the byte stream written to P1 (the DAC), the P2 bank and decay bits, the `MOVX` addresses into the banked sample ROM, and the control flow | | Measured here | 2,406,109 instructions over 460 frames, 196 distinct addresses, 38 distinct mnemonics: `MOVX`, `MOVP`, `MOVP3`, both `RET` and `RETR`, `XCH`, `DJNZ`, `SWAP`, `RL`/`RR`/`RRC`, and the conditional jumps `JZ`, `JNZ`, `JNC`, `JTF`, `JNT0`, `JNT1`, `JF0`, `JF1`, `JB4`-`JB7`. verified **absent** from the whole run: `JC`, `JT0`, `JT1`, `JNI`, `JB0`-`JB3`, `JMPP @A`, `XCHD`, `DA A`, `DEC`, `XRL`, `INS A,BUS`, the four 8243 expander instructions, `ENT0 CLK`, and every interrupt entry | | Does **not** cover | **any interrupt.** Zero entries to location 3 or 7 in the whole run; Donkey Kong's sound-trigger line is labelled "dead" in MAME's own memory map comment | Other real MCS-48 firmware, found and recorded but **not used here**: - `Halicery/8042` (, MIT): fully commented disassemblies of the IBM PC/AT 8042 controller ROM, the PS/2 8042, and the 8048 ROMs from IBM XT and AT Model F keyboards. Documentation of real firmware, not runnable tests, but a good source of "what real code relies on". `[not independently verified here beyond the repository's existence and licence]` - The Philips/Magnavox **Service Test Cartridge** for the Videopac/Odyssey², whose main CPU *is* an Intel 8048 at 5.911 MHz (`philips/odyssey2.cpp`, confirmed in the `-listxml` sweep). MAME's `hash/videopac.xml` lists it as `testcart` (2 KB, crc `3fb92bf1`, sha1 `e5e24c7f…`) with the usage note "Test 1: press all joystick inputs. Test 4: type NAGEL137." A factory diagnostic that exercises an 8048 is close to the Intel self-test that does not exist. **The software-list ROMs are not present in the local collection**, so this was not run; it is a milestone-5 idea, not a measurement. - PROMPT-48 monitor firmware on bitsavers (), four 1 KB images. Not fetched, not verified here. ### 6. Reference documentation that is not an oracle "Grokking the MCS-48 System", Arnim Läuger, v3.5.2 (2021), . Its own preface says it is a compilation of five paper sources and disclaims correctness; it contains no original measurements. Convenient; not evidence. No licence is stated on the source repository. ## What does not exist These are confident negatives, established by looking rather than by assuming. Each one is a thing a later session should not spend a day re-searching. | Searched for | Result | | --- | --- | | A SingleStepTests 8048/MCS-48 corpus | **Does not exist.** The organisation's 22 repositories were enumerated through the GitHub API: `ProcessorTests` (archived), `8088`, `8086`, `80186`, `80286`, `80386`, `v20`, `65x02`, `65816`, `680x0`, `m68000`, `z80`, `sm83`, `spc700`, `GameboyCPUTests`, `huc6280`, `sh4`, `r3000`, `ares_r3000_ssts`, `tlcs900h`, `ares_tcls900h_ssts`, `ARM7TDMI`. No MCS-48, and issue searches for `8048`, `mcs48`, `mcs-48` in the org return nothing. Tom Harte's personal repositories have nothing either. | | The capture rig that would produce one | `dbalsom/arduinoX86` covers 8088, 8086, V20, V30, 80186, 80286 only. No MCS-48 variant exists. The gap nobody has filled is exactly an 8048 harness plus a JSON corpus. | | Any other JSON-per-opcode corpus for the 8048 | None. GitHub searches for `mcs48` / `mcs-48` / `8048 tests` turn up a Binary Ninja disassembler plugin, an assembler macro set, a programmer/reader, and one abandoned Rust toy with six partial instructions. `raddad772`'s test repositories have no 8048 set. | | An Intel-era self-test, exerciser or "instruction set verification" program | **Never published.** The OCR text of the 1978 User's Manual and the 1980 Applications Handbook contain no "self test", no "exerciser", no "verification program"; every occurrence of "verify" is about EPROM program/verify mode. Intel's answer was the **ICE-48 in-circuit emulator**, for which the manual says the diagnostic exercise is *written by the user*. UM §2.4 likewise suggests pulling EA low and running "a diagnostic routine to exercise the processor, the internal RAM, the timer, and the I/O lines" — your routine, not Intel's. | | Any published logic-analyser capture or bus trace of a real MCS-48 | None, beyond the two bataais experiments above. The only hardware tooling in this space (Matt Millman's HVEPROM MCS-48 programmer/reader, for instance) reads ROM contents, not behaviour. | **So there is no tier-1 oracle worth the name and no tier-2 oracle at all.** The README must say that in a plain sentence, and every claim this project makes must name which of the remaining sources it rests on. ## The gates, in order | Gate | Oracle | Tier | What passing lets you say | | --- | --- | --- | --- | | 0 | `scripts/check_instruction_table.py` | mechanical | The opcode table in the documents still matches MAME 0.285's dispatch table, cycle counts and byte counts. Currently: **0 disagreements**. | | 1 | Unit tests written from UM §2.1 and §3.1-3.6 | documentation | Reset, PSW, the stack and its wrap, the bank flip-flop, the interrupt sequence, the timer prescaler and the control-signal rules follow the manual. Every test names its section. | | 2 | The instruction set against UM §4.1 | documentation | All 230 defined opcodes decode, execute, and report the documented bytes and cycles; the 26 undefined ones behave as MAME's `illegal` and raise a host-visible hook. | | 3 | **T48 `sw/verif`, all 102 programs** | documentation-derived, independent | An independent reading of the same manual, executed, agrees: **102/102 PASS**, including the eight white-box corners (`pc_wrap_bit11`, `int_on_call`, `int_on_jmp`, `int_on_mb1`, the two port/register conflicts, `p2_io_exp`, `psen_rd_wr_timing`) and the UPI-41 group. Report the T48 commit and the per-test result. | | 4 | **The two bataais experiments** | **hardware-captured** | The only hardware-verified claim available: after the interrupt sequence `A = 0x22`, and the timer rolls over after 32 `NOP`s, not 31. This is the gate MAME itself fails. | | 5 | MAME lockstep on `dkong` | emulator-derived (detector) | N instructions of the real Donkey Kong sound program with no undecided divergence, N stated, and every divergence decided by the manual, by T48, or by gate 4 — never by MAME. Excludes the three known-bad regions of §4 above, named explicitly. | | 6 | UPI-41 milestone: T48's `upi41` group plus a DECO Cassette or `gsword` lockstep | mixed | The DBB/STS host interface and the fourteen changed opcodes work in a real protection MCU. | Do not reorder them. Gate 3's failures are cheapest to diagnose before gate 5 produces a million-line diff, and gate 4 is the one that tells you when to stop trusting gate 5. ## Reproducing what is recorded here ```text python scripts/fetch_sources.py # MAME 0.285 sources, sha256-verified python scripts/check_instruction_table.py # re-derive the opcode table, diff the docs scripts/mame/trace_dkong.sh # the Donkey Kong trace (see mame-oracle.md) ``` Record of the runs on 2026-09-12 (Python 3.14.4, MAME 0.285, Linux x86_64): ```text MAME mame0285 @ f379cd060ac3 ok mcs48.cpp 65,255 bytes sha256 29d5a053... ok mcs48.h 19,183 bytes sha256 a660900d... ok mcs48dsm.cpp 30,140 bytes sha256 54cf5795... ok dkong.h 12,151 bytes sha256 05b3f635... ok dkong_a.cpp 49,727 bytes sha256 a381457e... check_instruction_table.py: 0 disagreements 230 defined opcodes, 26 undefined; 159 one-cycle, 97 two-cycle; 190 one-byte, 66 two-byte; 14 UPI-41 opcode differences trace_dkong.sh (frames 400-460): 314,303 instructions, 95 distinct addresses trace_dkong.sh (frames 0-460): 2,406,109 instructions, 196 distinct addresses, 0 entries to the interrupt vectors ``` State the MAME version, the T48 commit, and the pass counts with every claim. A claim without those numbers is not reproducible.