# segacd-python **Lineage:** **segacd-python** (the specification; no Rust tiers yet) · plugs into megadrive-python's expansion port · fixes start here and flow down by merges · [family charter](https://github.com/alewman/emulator-lineage/blob/main/docs/charter.md) A readable, pure-Python **Sega CD / Mega-CD** board that will plug into [megadrive-python](https://github.com/alewman/megadrive-python)'s expansion port. Its sub CPU is a second instance of [m68000-python](https://github.com/alewman/m68000-python). **Status (2026-11-24, measured at 9f16fe2): rebuilt through milestone 4 (in part), with save states, a referee and a drive fitted to real-drive logs.** This repository restarts from the end of Phase 0 under the family's source rules ([docs/restart.md](docs/restart.md)). Built: the memories, the gate array, the sub CPU and its scheduler, the graphics unit, the CD-ROM decoder, the drive's protocol (high level; seek times and the seek's visible statuses fitted to KRIKzz's real-drive logs, 3,004 of their 11,256 exchanges replayed identically), PCM (checked against Sega's PCM manual) and CD-DA. On megadrive-python efd80fc: your own BIOS plays Sonic CD (USA) into its first zone (after `scripts/format_backup_ram.py` has your BIOS format the backup RAM); mcd-verificator passes 17 of its 18 rows as BIOS, the last (CDC FLAGS 40) failing as it does on LC8951 units (16 of 18 as a mode-1 cartridge, 2026-11-19); save states on megadrive-python's state version 2 ([docs/save-states.md](docs/save-states.md)) load into a fresh console and continue identically; `scripts/referee.py` puts the board beside Genesis Plus GX (a closed box), picture by picture and, with `scripts/compare_audio.py`, by sound: 12 of 12 Sonic CD boot frames agree, CD-DA correlation 0.97. Numbers and what is open: [docs/status.md](docs/status.md); sources: [docs/provenance.md](docs/provenance.md); sessions: [docs/worklog.md](docs/worklog.md). Local repository; nothing is pushed. The Sega CD is its own board, not a variant of the Mega Drive: a second 68000 on its own 50 MHz crystal, 512 KB of PRG RAM, 256 KB of word RAM shared by a hand-over protocol, a rotation and scaling unit, a CD-ROM decoder, a drive behind a 10-nibble protocol, PCM and CD-DA. It pins megadrive-python by git revision and copies nothing from it; the sockets it needs are designed in megadrive-python's `docs/expansion-sockets.md`, and [docs/sockets.md](docs/sockets.md) says what the CD needs from each and where that design is wrong or incomplete. ## Read - [docs/restart.md](docs/restart.md): the rules, what was carried over, the scrub record. - [docs/manual-registers.md](docs/manual-registers.md): the machine's registers, from Sega's hardware manual. - [docs/sockets.md](docs/sockets.md): the contract with the Mega Drive board. - [docs/validation.md](docs/validation.md): every oracle, its tier, and what ran here. - [docs/mame-oracle.md](docs/mame-oracle.md): MAME as a detector. - [docs/handoff-brief.md](docs/handoff-brief.md): the milestones, and the open decisions. The machine overview, the timing document and the quirks list of Phase 0 are to be rewritten from permitted sources during the rebuild. ## BIOS and discs: bring your own Sega's BIOS is **never fetched, committed or vendored**, and neither is any commercial disc. `.gitignore` refuses `bios/`, `*.bin`, `*.cue`, `*.chd` and the rest. KRIKzz's mcd-verificator can stand in for the BIOS (it was written to), so the first milestones need no Sega code at all. Disc images come from your own Redump set, named by the environment variable `REDUMP_DIR` (the family's name for it, as `NO_INTRO_DIR` names the cartridge set; Aubrey, 2026-11-25); never write a machine path into this repository. ## What is fetched Nothing third-party is committed. `scripts/fetch_references.py` rebuilds `reference/` from `scripts/pinned_files.json` (33 files pinned by SHA-256: Sega's hardware, software, PCM and BIOS manuals, the Model 1 and Model 2 service manuals, the LC8951 and LC7883 datasheets, the CUE specification, forum threads) and `scripts/pinned_repos.json` (21 repositories at full commit SHAs, sparse: mcd-verificator and its real-hardware CDD logs, the MiSTer core's SignalTap captures of a real Mega-CD, Genesis Plus GX, BlastEm, ares, jgenesis, clownmdemu, MAME, PicoDrive, KRIKzz's FPGA core, test programs, a BIOS disassembly with the BIOS image itself left out). Several of these are fetched only so the runners can build and run them as closed boxes; which may be read is in [docs/restart.md](docs/restart.md). ```sh python scripts/fetch_references.py # everything missing (~140 MB) python scripts/fetch_references.py --verify # check what is present python scripts/build_referees.py # Genesis Plus GX and BlastEm libretro cores python scripts/libretro_run.py gpgx DISC.chd --bios-is-verificator --frames 600,7200 python scripts/referee.py --bios $SEGACD_BIOS --disc DISC.cue --backup-ram BRM \ --frames 300-3600:300 --wav --out runs/referee/NAME # board beside Genesis Plus GX python3 scripts/compare_audio.py runs/referee/NAME/board.wav runs/referee/NAME/gpgx.wav python scripts/mame_cd.py DISC.chd --rompath ROMS --frames 300 --trace ``` They need `git`, `make`, a C compiler and, for MAME runs, MAME 0.285. No sudo. ## Licence MIT (see `LICENSE`). The fetched references keep their own licences. The GPL, AGPL and non-commercial ones (Genesis Plus GX, PicoDrive, BlastEm, jgenesis, clownmdemu-core, the FPGA cores' HDL, mcd-verificator's source, MAME's GPL files) are built and run as closed boxes only, never read; permissive ones (MAME's BSD-3 Sega CD files, ares, the 0BSD and MIT test programs) may be read and keep their notices where anything is taken from them.