# mcs48-python **Status: documents and oracles only.** There is no core code in this repository yet. What is here is the groundwork a later session builds from: a primer on the processor, its timing, its undocumented behaviour, a validation plan with every oracle ranked by provenance, a pinned fetch script for the sources the documents rest on, a verified recipe for producing traces from MAME, and a handoff brief with milestones and acceptance tests. Read [docs/README.md](docs/README.md) for the index. ## What the project is `mcs48-python` will be a readable, dependency-free Python 3.12+ Intel MCS-48 **instruction core**, in the shape of the author's existing [z80-python](https://github.com/alewman/z80-python) and [6502-python](https://github.com/alewman/6502-python) cores: - **readable**: instruction families as ordinary Python with explicit dispatch, every handler named by its Intel mnemonic, hardware reasons as comments on the lines that encode them; - **pure Python**: no runtime dependencies, CPython and PyPy; - **independently validated**: correctness claims come from external oracles ranked by where their expected values came from, never from confidence; - **embeddable**: the MCS-48 is a microcontroller, so the host owns far more than it does for a Z80. The host supplies external program memory (`read_program(addr12)`), external data memory (`read_ext`/`write_ext` for `MOVX`), the three ports (`read_port`/`write_port` for P1, P2 and BUS), the two test inputs (`read_t0`/`read_t1`), the 8243 expander ports P4-P7, and the `INT` line; the core owns the accumulator, the two register banks, the PSW, internal RAM with its stack, the program counter and its bank bit, the timer/event counter with its prescaler, and the interrupt model. `step()` advances one instruction (or one accepted interrupt) and returns its machine cycle count; - **inspectable**: processor state, disassembly, and traces without contaminating the hot path. Internal ROM is a host-supplied byte string too: an 8048 is an 8035 with 1 KB of program memory wired inside, and the `EA` pin decides which one you have. Modelling it as a host decision keeps one core for the whole family. ## Scope decision: MCS-48, not MCS-51 These are two different architectures with confusingly adjacent names, and arcade hardware uses both. This repository is **MCS-48 only**. | | MCS-48 (this repository) | MCS-51 (out of scope) | | --- | --- | --- | | Parts | 8021, 8022, 8035, 8039, 8040, 8048, 8049, 8050, 8648, 8748, 8749, and the UPI-41/42 peripherals 8041, 8042, 8741, 8742 | 8031, 8051, 8751, 8052, 8752, and the Philips/Siemens second sources | | Program counter | 12 bits, addressing 4 KB in 2 KB banks selected by a `SEL MB` flip-flop | 16 bits, flat 64 KB | | Register file | A plus two banks of R0-R7 living in internal RAM, selected by PSW bit BS | four banks of R0-R7, plus bit-addressable SFRs and a DPTR | | Stack | 8 levels, fixed at internal RAM 8-23, pointer is PSW bits 0-2 | anywhere in internal RAM, an 8-bit SP SFR | | Arithmetic | 8-bit add with CY and AC; no subtract, no multiply, no divide | adds SUBB, MUL AB, DIV AB, a parity flag, bit operations | | Opcode map | the table in [docs/start-here.md](docs/start-here.md); 26 undefined opcodes | a different map entirely; `JMP` is not `04` | | MAME device | `src/devices/cpu/mcs48/` | `src/devices/cpu/mcs51/` | MCS-51 is what Sega's and Capcom's protection MCUs are (`i8751` in MAME's machine configurations: Sega System 16, Capcom's CPS-1 sound and various Taito boards). It deserves its own `mcs51-python` repository later, with its own oracles; it is not a mode of this one. Nothing in this repository should be written as if the two share a decoder. The MCS-48 family itself splits three ways, and one core covers all of it: | Part | Internal ROM | Internal RAM | Notes | | --- | --- | --- | --- | | 8035 | none | 64 | romless; runs entirely from external program memory (`EA` tied high) | | 8048 / 8648 / 8748 | 1 KB (mask / OTP / EPROM) | 64 | the baseline part | | 8039 | none | 128 | romless 8049 | | 8049 / 8749 | 2 KB | 128 | "bigger 8048": the extra RAM moves nothing in the ISA, but `SEL MB` matters sooner | | 8040 / 8050 | none / 4 KB | 256 | the largest of the family | | 8021 / 8022 | 1 KB / 2 KB | 64 | **reduced** instruction set; the 8022 adds an A/D converter. A different machine cycle too (30 clocks, not 15) | | 8041A / 8741A / 8042 / 8742 | 1 KB / 2 KB | 64-256 | **UPI-41/42**: an MCS-48 with a host data-bus interface (DBB, STS, IBF/OBF) instead of BUS, and fourteen opcodes changed | | MB8884 (Fujitsu), M58715 (Mitsubishi), µPD7751 (NEC) | second sources | | MAME treats MB8884 as a romless 64-byte-RAM part, i.e. an 8035 | Sizes from Intel's *MCS-48 Family User's Manual* chapter 6 and from the device table in MAME's `src/devices/cpu/mcs48/mcs48.cpp` (lines 50-107), which agree. The UPI opcode differences are the table at `mcs48.cpp` lines 74-91 and are reproduced in [docs/start-here.md](docs/start-here.md). ## What runs on one Not from memory: from MAME 0.285's own machine list. `mame -listxml` was dumped whole (314 MB) and every `` whose name is an MCS-48 family part was collected; 433 parent machines have one, of which these are the arcade boards. Clock values are MAME's, in the driver's own units. | Maker | Machines (MAME parent set) | Part, tag, clock | | --- | --- | --- | | Nintendo | `dkong` Donkey Kong, `dkongjr` Donkey Kong Junior, `radarscp` Radar Scope, plus the DK-conversion sets `8ballact`, `drakton`, `shootgal`, `strtheat` | **Fujitsu MB8884 (an 8035), `:soundcpu`, 6 MHz** | | Nintendo | `sheriff` Sheriff, `spacefev` Space Fever, `helifire` HeliFire, `highsplt`, `spacelnc` | Intel 8035, `:soundboard:cpu`, 6 MHz | | Nintendo | `spacefb` Space Firebird | Intel 8035, `:audiocpu`, 6 MHz | | Konami | `gyruss` Gyruss | Intel 8039, `:audio2`, 8 MHz | | Konami | `finalizr` Finalizer | Intel 8049, `:audiocpu`, 6.144 MHz | | Konami | `junofrst` Juno First | Intel 8039, `:mcu`, 8 MHz | | Konami | `megazone` Mega Zone | Intel 8039, `:daccpu`, 7.159 MHz | | Konami | `pandoras` Pandora's Palace | Intel 8039, `:mcu`, 7.159 MHz | | Data East | the whole DECO Cassette system: `decocass` and 39 game sets (`cbtime` Burger Time, `ctisland` Treasure Island, `cppicf`, ...) | **Intel 8041A, `:mcu`, 6 MHz** — the protection and cassette-control MCU | | Sega | `carnival` Carnival (VIC Dual) | Intel 8035, `:audiocpu`, 3.579545 MHz | | Sega | the Speech Board (`astrob` Astro Blaster, `spacfury` Space Fury, `zektor`, `startrek`) | Intel 8035, `:speech:cpu`, 3.12 MHz | | Sega | the Universal Sound Board (`startrek`, `tacscan`, `pignewt`, `razmataz`, `ixion`) | Intel 8035, `:usbsnd:ourcpu`, 6 MHz | | Taito | `gsword` Great Swordsman | **three** Intel 8041A, `:mcu1` `:mcu2` `:mcu3`, 6 MHz | | Tecmo | `wildfang` Tecmo Knight, `stratof` Raiga | Intel 8749, `:mcu`, 4 MHz — protection | | Irem | `wilytowr` Wily Tower, `fghtbskt` | Intel 8039, `:soundcpu`, 3 MHz | | Zaccaria | `quasar` Quasar | Intel 8035, `:audiocpu`, 6 MHz | | Alpha Denshi | `sstingry` Super Stingray | Intel 8748, `:alpha8511`, 9.264 MHz | | Stern / Gottlieb / Simutrek (laserdisc) | `cliffhgr` Cliff Hanger, `goaltogo`, `mach3`, `usvsthem`, `cubeqst` | Intel 8049 **inside the Pioneer PR-8210 player** (`:laserdisc:pr8210`, 4.41 MHz), not on the game board; `cubeqst` adds an 8748 at 6 MHz in its Simutrek controller | | Atari (laserdisc) | `firefox` Fire Fox | Intel 8049 inside the **Philips VP931** player (`:laserdisc:vp931`, 11 MHz) | | Various | `lckydraw`, `sshtlzac`/`locomotp`/`ewf` (Zaccaria pinball), `sleicpin`, `supstarf`, `drw80pkr`, `fortune1`, `interflip8035`, `sumt8035` gambling and pinball boards | 8035 / 8039 | Two corrections to the assumptions this repository was commissioned with, from the same listing: - **Popeye does not have one.** `mame -listxml popeye` gives a Z80 at 4 MHz, an AY-3-8910A and a netlist sound device — no MCS-48 part anywhere in the machine. Donkey Kong's and Donkey Kong Junior's `:soundcpu` is real and is the canonical target; Popeye is not. - **Gottlieb's own boards do not have one either.** The only MCS-48 in a Gottlieb machine in MAME 0.285 is the 8049 inside the Pioneer PR-8210 laserdisc player used by `mach3` and `usvsthem`. Gottlieb's System 1/80 sound boards are 6502-based. Konami's use (five parent sets above) is real and stays on the list. `dkong` is therefore the reference target throughout this repository: a real 8035 sound program, driven by a real Z80, whose only outputs are port writes. See [docs/mame-oracle.md](docs/mame-oracle.md). ## Oracles at a glance Ranked by where their expected values came from (hardware-captured > hardware-corrected > emulator-derived; a low-tier oracle is a detector, never a judge). Details, coverage and limits are in [docs/validation.md](docs/validation.md). | Oracle | Tier | What it can settle | | --- | --- | --- | | **(none found)** | hardware-captured | — | | Intel, *MCS-48 Family User's Manual* (9800270D, 1978) and *MCS-48 and UPI-41 Assembly Language Manual* (9800255D, 1978) | documentation | encodings, bytes, cycles, flag rules, reset state, interrupt and timer behaviour | | Donkey Kong's 8035 sound program under MAME 0.285 | emulator-derived (detector) | that a real arcade program's control flow and port writes are reproduced | | MAME 0.285 `mcs48` device source | emulator-derived (detector) | what a widely-exercised implementation does where the manual is silent | **There is no hardware-captured oracle for the MCS-48.** That is the single most important fact in this repository and it is stated plainly rather than worked around: no SingleStepTests corpus, no published logic-analyser capture, no Intel verification program that survives. The judge is therefore the manual, and the strongest evidence available is that real arcade sound programs produce the right port writes and that a long lockstep against MAME has no undecided divergence. Every claim this project makes must say which of those it rests on. ## Repository layout ```text README.md this file LICENSE MIT docs/ see docs/README.md scripts/fetch_sources.py fetch the pinned MAME sources, hash-verified scripts/check_instruction_table.py re-derive the opcode table and diff it scripts/mame/trace_dkong.sh the MAME trace recipe as runnable files scripts/mame/trace_dkong.lua ``` Nothing fetched or traced is committed: MAME's sources are BSD-3-Clause but belong upstream, arcade ROMs belong to their publishers and are read in place from the MAME collection with `-rompath`, and traces are large and reproducible. ## License MIT. External sources retain their own licenses: MAME is BSD-3-Clause (transcription with attribution is permitted and is used here for the instruction table and the undefined-opcode behaviour); the Intel manuals are copyright Intel and are cited, never redistributed.