Metadata-Version: 2.5 Name: sms-python Version: 0.1.0.dev0 Summary: Readable, pure-Python SG-1000, Master System and Game Gear emulator built on z80-python Author: alewman License: MIT License Copyright (c) 2026 alewman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License-File: LICENSE Requires-Python: >=3.11 Requires-Dist: z80-python>=0.4.0 Provides-Extra: dev Requires-Dist: pytest>=8; extra == 'dev' Requires-Dist: ruff==0.16.8; extra == 'dev' Description-Content-Type: text/markdown # sms-python A readable, dependency-free, pure-Python emulator of **Sega's 8-bit Z80 consoles**: the SG-1000 (and SC-3000), the Mark III and Master System (SMS1 and SMS2 video chips), and the Game Gear. It is a board built on [z80-python](https://github.com/alewman/z80-python): z80-python owns the instruction set, this repository owns everything around it. That means the memory map and cartridge mappers, the I/O ports, the video chip (TMS9918A modes and the Sega Mode 4), the SN76489 sound chip, the joypads, pause and reset, and the clock that ties them together. **Status (2026-09-21): the SG-1000, Master System and Game Gear run on z80-python 0.4.0.** Milestone 1 passes: ZEXDOC and ZEXALL (ZEXALL-SMS v0.21) report 79 of 79 tests OK on the SMS2 board. The whole system runs in lockstep with MAME 0.285, instruction for instruction: | MAME 0.285 run | Instructions identical | Port reads differing | Exit frame pixels | | --- | ---: | ---: | ---: | | Flicky, `sg1000`, 20 s | 7,703,804 | 0 | 49,152 / 49,152 | | Sonic the Hedgehog, `sms` (through the BIOS), 20 s | 7,904,561 | 0 | 49,152 / 49,152 | | SMS VDP Test v1.31, `sms`, 12 s | 3,556,264 | 0 | 49,152 / 49,152 | | Sonic the Hedgehog, `gamegear`, 20 s | 5,903,153 | 1 (power-on, open item 7) | 23,040 / 23,040 | MAME is a detector, not a judge (docs/validation.md has the tiers and the full certification record). Sega's SG-1000 M2 Check Program passes its RAM test and reaches its I/O screen. 74 unit tests run on CPython and PyPy; `pytest -m slow` reruns the MAME replays and locksteps when their logs are recorded locally. ```python from pathlib import Path from sms_python.board import SMS2 from sms_python.cartridge import Cartridge from sms_python.system import System system = System(SMS2, Cartridge.from_file(Path("game.sms"))) frame = system.run_frame() # rows of RGB888 ints audio = system.board.psg.take_samples() # (left, right) pairs ``` | Module | What | | --- | --- | | `system.py` | z80-python's `Z80CPU` on a board: INT from the VDP, pause as NMI | | `board.py` | eight machines as data; memory map, $3E slot switching, port decode | | `vdp.py` | TMS9918A modes 0-3 and Mode 4; SMS1/SMS2/GG/TMS variants as data | | `psg.py` | SN76489, discrete and Sega variants, Game Gear stereo | | `cartridge.py` | Sega and Codemasters boards; board detection from MAME's software lists | | `io.py` | ports $3F/$DC/$DD, region, TH latch; Game Gear ports $00-$05 | | `png.py`, `wav.py` | frames and audio out, stdlib only | What is here: - a primer on the three machines; - the display and interrupt timing, with where each number came from; - the hardware quirks that separate the chip revisions; - every oracle found, ranked by tier and pinned; - a fetch script that rebuilds the reference library from those pins; - a working, verified recipe for MAME traces of the Z80 and the I/O bus; - a handoff brief with milestones. See [docs/README.md](docs/README.md). ## Why one repository for three consoles The SG-1000 is not a prerequisite project: it is the first milestone. Its video chip, the TI TMS9918A, lives on inside the Master System's 315-5124 as modes 0 to 3, next to Sega's new Mode 4. That is how a Mark III or an SMS1 runs SG-1000 cartridges. The Game Gear keeps the same chip with a 12-bit palette and a smaller window. So the machines share a VDP, a PSG and a Z80, and differ in tables: | | SG-1000 | Mark III / SMS1 | SMS2 | Game Gear | | --- | --- | --- | --- | --- | | Video | TMS9918A (modes 0-3) | 315-5124 (modes 0-3 + Mode 4) | 315-5246 (adds 224/240 lines, loses the SMS1 mask quirks) | inside the 315-5378 ASIC (Mode 4, 160x144 window, 12-bit CRAM) | | Sound | SN76489AN, discrete, 15-bit noise LFSR | SN76489 inside the VDP, 16-bit LFSR | same, with volume clipping | same, stereo (port $06) | | Z80 | NMOS | NMOS | NMOS | CMOS (inside the ASIC) | | RAM | 1 KB at $C000, mirrored | 8 KB at $C000, mirrored | 8 KB | 8 KB | | Cartridge | up to 48 KB, no mapper (a few boards bank-switch) | Sega mapper; Codemasters and Korean boards | same | Sega mapper; Codemasters; EEPROM carts | ## What is here | Path | What it is | Committed | | --- | --- | --- | | `docs/` | The documents listed in `docs/README.md` | yes | | `scripts/fetch_references.py` | Rebuilds `reference/` and `tests/test_roms/` from the pins | yes | | `scripts/pinned_files.json` | 175 files: URL, SHA-256, size, kind, licence | yes | | `scripts/pinned_repos.json` | 11 git repositories at pinned revisions | yes | | `scripts/mame_trace.py` | The MAME 0.285 trace and I/O-log recipe, verified | yes | | `reference/` | Fetched manuals, SMS Power documents and wiki, forum threads, source trees (478 MB) | no | | `tests/test_roms/` | Fetched test and diagnostic cartridges from SMS Power | no | | `tests/mame_traces/` | MAME runs | no | python scripts/fetch_references.py # fetch everything missing python scripts/fetch_references.py --verify # check the pins, fetch nothing ## Licence MIT for what this repository contains. The fetched material keeps its own terms (recorded per file in `scripts/pinned_files.json` and per repository in `docs/validation.md`) and is never committed. Genesis Plus GX's licence forbids commercial use: read it, cite it, do not copy from it.