# mb88xx-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: the complete programming model of the processor, its timing, the Namco custom chips that are the reason to want it, a validation plan with every oracle ranked by provenance, a *verified* recipe for tracing one of those MCUs instruction by instruction out of MAME, and a handoff brief with milestones and acceptance tests. Read [docs/README.md](docs/README.md) for the index. ## What the project is `mb88xx-python` will be a readable, dependency-free Python 3.12+ Fujitsu **MB88xx 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**: 69 mnemonics across 256 opcodes as ordinary Python with explicit dispatch, every handler named by its Fujitsu 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 — and for this processor the honest answer is that the only judge is the real mask-ROM programs (see [docs/validation.md](docs/validation.md)); - **embeddable**: the host owns everything outside the chip and supplies the ports — | Host supplies | Direction | Width | | --- | --- | --- | | `read_k()` | in | 4 bits (K3-K0) | | `write_o(value)` | out | 8 bits (O7-O0), through the output PLA | | `write_p(value)` | out | 4 bits (P3-P0) | | `read_r[n]()` / `write_r[n](value)` | in/out | 4 bits each, n = 0..3 (R15-R0) | | `read_si()` / `write_so(bit)` | in/out | 1 bit (serial, MB8841/8843 only) | | `set_irq(level)` | in | /IRQ pin | | `set_tc(level)` | in | /TC pin (external timer clock) | | `set_reset(level)` | in | /RESET pin | the core owns A/X/Y, the RAM nibble array, PC/PA, the four-deep stack, the ST/Z/C/V/S/I flags, the timer, the serial shift register, the interrupt sequence, and instruction cycle counts; `step()` advances one instruction or one accepted interrupt and returns its cycle count. - **inspectable**: processor state, disassembly, and traces without contaminating the hot path. ## Why this processor The MB88xx is a 4-bit NMOS single-chip microcomputer family Fujitsu introduced in 1977. It is interesting here for one reason: **Namco built its custom I/O and sound chips out of it.** A 50xx, 51xx, 52xx, 53xx or 54xx on a Namco board is an MB88xx with a mask ROM and a package label. | Part | MCU | Program | Job | Games | | --- | --- | --- | --- | --- | | 50xx | MB8842 | `50xx.bin`, 2 KB | score / bonus-life protection | Bosconian (two of them), Xevious | | 51xx | MB8843 | `51xx.bin`, 1 KB | coin, credit, start, joystick I/O | Galaga, Bosconian, Xevious, Dig Dug, Pole Position | | 52xx | MB8843 | `52xx.bin`, 1 KB | sample player (addresses an external sample ROM) | Bosconian, Pole Position | | 53xx | MB8843 | `53xx.bin`, 1 KB | input multiplexer, eight modes | Dig Dug, Pole Position | | 54xx | MB8844 | `54xx.bin`, 1 KB | noise generator (explosions, tyre screech) | Galaga, Bosconian, Xevious, Pole Position | All five hang off the **06xx** bus controller, which is not an MCU. Sizes, hashes, pin wiring and protocols are in [docs/namco-customs.md](docs/namco-customs.md). ## The payoff, concretely `../emu-galaga` is a finished, deployed Galaga emulator — three Z80s, video, inputs and sound, reproducing MAME's per-frame RAM and device traces byte for byte. It has one weak point, and it is exactly this processor. Its 51xx is a hand-written model of the coin/credit protocol fitted to MAME's replies, and its **54xx is a hand-written noise model fitted to MAME's recording** rather than the real MCU program. That project's `docs/build-record.md` calls the 54xx "the day's longest detour", and its `docs/sound-hardware.md` leaves an open question in writing: > Simulating exactly that chain (MAME's `dst_op_amp_filt` coefficients, > rails, mixer, coupling capacitor) on the MCU's recorded output reproduces > neither MAME's level nor its spectrum: the recording peaks at 0.80 of > full scale where that chain cannot exceed 0.23, and two thirds of its > energy lies at 100-300 Hz with no linear relation to the noise bits > (waveform correlation 0.41 for the 450 Hz band, 0.0 for a 167 Hz band, > in both recordings). The cause was not found `[unverified]`. An MB88xx core would let that project run the real `51xx.bin` and `54xx.bin` instead of two fitted models: the credit logic, the coin debounce, the lamp blink rate, the noise generator's LFSR and its envelope would all come from Namco's own programs. It would also let the open question be settled from both ends — with the MCU's output bits generated rather than replayed, the analog chain is the only remaining variable, and a mismatch is then MAME's discrete network and nothing else. That is milestone (d) of [docs/handoff-brief.md](docs/handoff-brief.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 settles | | --- | --- | --- | | Fujitsu *MB8840/40H series* datasheet, TM336-A871 (January 1987) | documentation | The instruction table, per-instruction flag effects, cycle counts, the EN/DIS operand bit map, 6 clocks per instruction cycle, reset entry, stack depth, per-variant ROM/RAM sizes | | The real programs `51xx.bin` / `54xx.bin` inside their games | **behavioural, hardware-defined** | Whether a core is right where it matters: a wrong core makes Galaga miscount credits or produces the wrong noise | | MAME 0.285 `mb88xx` core, traced per instruction | emulator-derived | A detector: divergence from it is a bug in one of the two, decided by the datasheet | | `../emu-galaga` `oracle/reference/game-2400` | emulator-derived (second hand) | The 51xx reply stream a working Galaga needs | **There is no hardware-captured MB88xx test corpus.** SingleStepTests has 22 repositories and none of them is a 4-bit Fujitsu part; nothing equivalent was found anywhere. MAME's core is the only public model, and it carries four acknowledged guesses — the timer prescale, the serial prescale, the 3-cycle interrupt entry, and the interrupt vector addresses, which MAME's source says were inferred from what another game's MCU program expected (Sun Electronics' *Arabian*, 1983, an MB8841). Those four are named in [docs/validation.md](docs/validation.md) as the places a core cannot be proven right. ## Repository layout ```text README.md this file LICENSE MIT docs/ see docs/README.md scripts/mame/trace_mcu.lua the verified MAME MCU trace recipe, runnable scripts/mame/trace_mcu.sh its wrapper: paths, flags, output location ``` ## License MIT. External sources retain their own licenses and are never bundled: MAME's `src/devices/cpu/mb88xx/` and `src/mame/namco/` are BSD-3-Clause (transcribed with attribution, see [docs/start-here.md](docs/start-here.md)); the Fujitsu datasheet is cited, not redistributed; the MCU mask-ROM programs are read in place from a MAME ROM set and never copied here.