# Protection: Sega's opcode decryption, the MC-8123 and the 8751 Three kinds, by the census ([census.md](census.md)): 53 machines with a Sega 315-xxxx or 317-xxxx encrypted Z80 (24 part numbers), 6 with an NEC MC-8123, 3 with an Intel 8751 MCU. ## What is documented, and what is not No document in hand describes any of the three algorithms. MAME's descriptions are its BSD-3-Clause files `src/devices/machine/segacrpt_device.cpp` and `segacrp2_device.cpp` (copyright Nicola Salmoria, David Haywood) and `src/devices/cpu/z80/mc8123.cpp` (Nicola Salmoria, David Widel), checked by their `license:` lines only and **not opened** (the brief: MAME is a closed box). Eduardo Cruz's FD1089/FD1094 guide (pinned in ../segasys24-python, "AHFD") says work on "the earlier MC 8 bit modules used in some System 1 / 2 boards" was in progress in 2018 and would be published later; nothing from it is in hand. ## What the closed box shows (OBSERVED, `scripts/mame_trace.py --views`) MAME gives an encrypted Z80 two address spaces: `opcodes` (what M1 fetches see) and `program` (what operand and data reads see). Over the first 32 KB of one set per part number, at frame 2: | Class | Parts | How the two views differ | | --- | --- | --- | | **A** (17 parts) | 315-5033, 5041, 5048, 5051, 5064, 5065, 5093, 5096, 5098, 5099, 5102, 5110, 5111, 5132, 5133, 5135, 5155 | in **bits 7, 5 and 3 only**: 0 of 16,402-28,643 differing bytes per set differ in any other bit | | **B** (7 parts) | 315-5162, 5176, 5177, 5178, 5179, 317-0006, 317-0007 | in every bit position: each differing byte differs outside bits 7, 5, 3 | | MC-8123 | `blockgal` | 32,485 of 32,768 bytes differ, 31,478 of them outside bits 7, 5, 3 | In class A the pattern of bit differences depends on address bits A12, A8, A4 and A0 (the key `(address & 0x1111)` sorts the differences into groups in `views.txt`), which is what a table-driven scheme selected by those four address bits would show (HYPOTHESIS: a 16-row table per part for opcodes and another for data). On `flicky` (class A), `wboy` (class B) and `wbml` (MC-8123) **both views differ from the raw ROM** (CRC-32 of each 16 KB or 32 KB ROM against the view over the same range): data reads are decrypted too, not only opcodes (OBSERVED in MAME's model). On the plain `wboyu` the program view's CRC-32 equals the ROM's, which checks the method. What the closed box cannot settle: whether the real parts decrypt by M1 alone or also look at other pins (refresh, the second byte of a prefixed opcode, the `DD CB d op` operand fetches that are ordinary reads on a Z80); whether MAME's tables for every part come from dumps of real parts or from analysis of the ROMs (MAME's files say, unopened); whether interrupt-acknowledge cycles pass through (U6). ## What the board needs from z80-python All three schemes key on whether a read is an opcode fetch: the Z80's /M1 pin. z80-python's `read_m1(address, kind)` hook does exactly that (`M1Cycle.FETCH` for opcode and prefix bytes, not for `d` and `op` of `DD CB d op`; `HALT`, `NMI`, `ACKNOWLEDGE` for M1 cycles whose data the CPU ignores). It lives on branch `m1-fetch-hook-rebased` (`5434349`, checked 2026-11-26 in ../z80-python-m1-hook), **not on `main`** (`cc2f794`). Every one of System 1's 59 protected machines needs it (system16-python needed it for six sound-CPU sets only). The board side is a `FetchFilter` with a key: a part's tables (class A, B) or an MC-8123 key ROM (`maincpu:key`, 8 KB, from the set). ## Decrypted sets against modelling the decryption | | Plain and decrypted sets first | Model the decryption | | --- | --- | --- | | Coverage | 16 of 28 titles (33 plain machines, among them MAME's decrypted bootlegs `wbmld`, `wbmljod`, `wbmlvcd`) | all 92 | | Evidence | none is needed beyond the board | MAME only (tier 5): its BSD-3 files, or measuring its two views (above) | | Cost | nothing | a fetch filter and per-part data; z80-python's `read_m1` on `main` | | Risk | 12 titles out of reach (`4dwarrio`, `bullfgt`, `dakkochn`, `gardia`, `hvymetal`, `imsorry`, `mrviking`, `shtngmst`, `spatter`, `swat`, `teddybb`, `wmatch`) | the tables are MAME's, judged by MAME | **Recommendation** (open decision 3): plain sets first (M1-M5), then the class-A filter as soon as `read_m1` is on z80-python's `main`; its data may come either from MAME's BSD-3 `segacrpt_device.cpp` read for facts with the notice kept (as pcenginecd-python did for `msm5205.cpp`), or from a closed-box measurement of MAME's two views per part, marked "closed-box measurement"; the second keeps MAME's source unopened but carries the same provenance (MAME's tables), so Aubrey's choice is about the rule, not the result. Class B and the MC-8123 follow by the same decision. ## The 8751 (three System 2 sets) **OBSERVED** (MAME, [mame-oracle.md](mame-oracle.md)): on `choplift` the 8751 runs from reset while the main Z80 executes nothing for at least 30 frames; MAME's log shows it reading 49,152 bytes through an external-bus window (the size of the main CPU's 48 KB program ROM: an "IC CHECK" checksum, HYPOTHESIS from the screen text) and then polling one location. So in MAME's model the 8751 holds the Z80 at power-on and reads the Z80's ROM: it is a second bus master on the main CPU's bus, as on System 16 (system16-python `protection.md`). What it does after the check, which signals it drives (BUSREQ, WAIT, RESET, an interrupt), and how its port 1 is wired are U7. All three MCU programs are dumped (census). Sega's 8751 programs are game parts: run from the player's set, never committed. The core is the new `mcs51-python` (MCS51 is its tier-2 judge; [cpu-cores.md](cpu-cores.md)).