# Handoff, 2026-11-12: where sms-python stands The original brief ([handoff-brief.md](handoff-brief.md)) asked for a board in nine milestones. All nine are done, and the board has since grown past the brief. This is the state to pick up from. The detail lives in the documents it points to; nothing here is the only copy of a fact. ## What is built Sixteen machines, each a row of data in `board.py`: | Family | Machines | Checked against | | --- | --- | --- | | SG-1000 | `sg1000` | MAME lockstep (Flicky), Sega's M2 Check Program | | SC-3000 | `sc3000`, `sc3000pal` | Charles MacDonald's SC-3000H notes; BASIC Level III typed on, frame against MAME | | SF-7000 | `sf7000` | the IPL ROM's own behaviour; all seven disks and a Disk BASIC save and load against MAME | | Mark III, Master System | `mark3`, `mark3fm`, `smsj`, `sms1`, `sms1pal`, `sms2`, `sms2pal` | ZEXALL 79 of 79; FluBBa's VDP test 55 of 55 on SMS1 and SMS2; MAME lockstep (Sonic through the BIOS) | | Game Gear | `gamegear`, `ggsms`, `ggsms1asic` | MAME lockstep; enik2's `VDPTEST_GG` 55 of 55 (2-ASIC), 53 of 55 (1-ASIC) | | Mega Drive + Power Base Converter | `megadrive-pbc`, `megadrive-pbc-pal` | FluBBa's Mega Drive entry 55 of 55; Nuked-MD agrees on 50 | Every board a cartridge of the local romsets needs is modelled (`cartridge.py`), and the FM unit is ym2413-python. The certification record, row by row, is in [validation.md](validation.md). Compatibility sweep, frames against MAME 0.285 after 10 s (30 s for disks): | Romset | Identical | Differ | | --- | ---: | ---: | | Master System | 1,157 of 1,170 | 13 | | Game Gear | 823 of 874 | 51 | | SG-1000, SC-3000, SF-7000 | 237 of 243 | 6 | The differing cartridges were each run in lockstep and sorted by cause (validation.md, the triage table). That triage dates from 2026-11-11; the counts of differing cartridges have not changed since, but the rows were not triaged again after the later re-sweeps. Save states (`state.py`, after famicom-python's): the whole machine as bytes between two instructions, and back. They are what a libretro core's serialize calls need, so RetroArch's rewind and run-ahead; the window uses them itself (F6 save, F7 load, F8 held rewinds through about a minute). A new attribute on any device is saved without being listed. What to remember when adding one: a frozen dataclass is taken for configuration and skipped unless its class is in `state.VALUES`; `bytes` are taken for ROM and not saved; and `scripts/state_roundtrip.py` is the check. ## What is open, and why The open items are numbered in [undocumented-behavior.md](undocumented-behavior.md). None can be closed from what is in the reference library; each names the measurement that would settle it. The ones most likely to matter: - **Item 8, the 1-ASIC Game Gear's interrupt timing**: two of 55 tests fail. - **Item 17, the Mega Drive's H counter phase**: the fitted positions rest on one real console; Nuked-MD samples at another phase. - **Items 10 and 12**, the frame when the height changes and mid-line CRAM writes: most of the Game Gear and Master System render differences. - **Items 9 and 16**, the Game Gear's EXT port and serial status: MAME's model, no hardware reading. Known only from MAME or a data sheet, never checked against hardware: the SF-7000's ports and pins, its uPD765A (written from NEC's uPD765 data sheet, pinned), and several Korean, Taiwanese and cheat-device cartridge boards. Their docstrings say so. For these an identical frame shows that the board follows MAME, not that MAME is right. Not built, for want of anything to check against: the SC-3000's cassette and printer lines, the SF-7000's 8251 serial port and printer port, the X-Terminator's ACTION switch position, 8255 modes 1 and 2. Not tried at a screen: the desktop window on the SC-3000 (the PC keyboard as the computer's) and with a disk (`.sf`, with the IPL ROM as `--bios`). Both run on SDL's dummy drivers (a test does it, and Disk BASIC and BASIC Level III reach their prompts that way), but nobody has typed on them. ## Seams in the code - `Board.read_port` and `write_port`: the SC-3000's decode and the controller ports are methods of their own now, but the remaining machines still share one function with a branch per decode. A decode table per machine would be the next shape; any change there wants a full re-sweep (the split itself changed no row of 2,333). - `sf7000.py` holds the uPD765A. It is a board chip for now; if a second machine in the family wants one, it becomes a core of its own. - The scripts put `src/` and `scripts/` on `sys.path` by hand. ## Tools | Script | Use | | --- | --- | | `scripts/compat_sweep.py ` | the sweep; `--rerun `, `--match` and `--limit` update the record in place | | `scripts/triage_diffs.py` | a differing cartridge in lockstep with MAME, sorted by cause | | `scripts/lockstep_mame.py`, `replay_mame_io.py`, `mame_trace.py` | instruction-for-instruction comparison against a MAME trace | | `scripts/run_vdptest.py`, `run_zex.py` | FluBBa's and enik2's VDP tests; ZEXDOC and ZEXALL | | `scripts/fit_phase.py` | the power-on VDP phase of a MAME driver | | `scripts/romsets.py` | where the local romsets are | | `scripts/state_roundtrip.py` | save states on one real cartridge of every board: saved, loaded into a fresh system, compared | Traps worth knowing before using them ([mame-oracle.md](mame-oracle.md) has twelve for MAME alone): - Run on PyPy, and set `PYPY_GC_NURSERY=1M` for parallel runs: about five times the sweep's throughput on this machine. - The romsets are a local copy of No-Intro's folders, found through `NO_INTRO_DIR` (and MAME's BIOS sets through `MAME_ROMPATH`). No-Intro renames folders and files; when a count changes, look for an old folder beside the new one before looking for a bug. - MAME's keyboard posting (`natkeyboard:post`) has no type-ahead: post a line at a time with pauses, and not before the program is reading keys. - A disk takes about 15 s to boot; the sweep gives disks 30 s. ## Rules this repository keeps - An oracle has a tier (hardware-captured, hardware-corrected, die-derived, emulator-derived). MAME is a detector: a difference from it is a question, not an answer. - Every rule in the code names its source, or says that it is a choice. - GPL, LGPL and non-commercial emulators (Genesis Plus GX, Nuked-MD, Gearsystem, openMSX) are not read while writing code; they may be run as closed boxes to find differences. MAME's files used here are BSD-3-Clause and are credited in `NOTICE`. - Nothing fetched is committed: references, test ROMs, romsets, MAME traces.