# tms9918-python A readable, pure-Python reference core of Texas Instruments' **TMS9918A** video display processor family: the TMS9918A (composite video, 60 Hz), the TMS9928A (Y, R-Y, B-Y, 60 Hz) and the TMS9929A (Y, R-Y, B-Y, 50 Hz), one engine with the parts as data. 16K of VRAM behind a two-port CPU interface, four display modes and four undocumented ones, 32 sprites with four per line, and the memory schedule from TI's 1978 timing drawing, which gives the CPU its access windows between the chip's own fetches. It is a chip in the family's shape (chips are cores, boards compose cores), beside `sn76489-python`, `ym2413-python` and `z80-python`. Its first consumer is `colecovision-python` (TMS9928A/TMS9929A); `sms-python` (SG-1000 and SC-3000, TMS9918A) keeps its own in-board VDP for now and adopts this core later. ```python from tms9918_python import TMS9918, TMS9928A vdp = TMS9918(TMS9928A, vram_size=16384) vdp.run(cpu_cycles * 3) # master clocks (XTAL); the Z80 runs at XTAL/3 vdp.write(1, 0xE2); vdp.write(1, 0x81) # register 1 vdp.int_line # /INT as a level frame = vdp.take_frame() # 192 rows of 256 colour indices, plus the border per line ``` The contract is [docs/api.md](docs/api.md); every default no source settles is in [docs/claims.md](docs/claims.md). ## Status (2026-11-12) | Rung | What | Result | | | --- | --- | --- | --- | | 0 | Manual to tables | 30 tests; the schedule derived from TI's 1978 drawing alone (provenance wave 2, 2026-11-19) | verified | | 1 | Registers and ports | 45 tests from TI 2.1-2.3, Young 2, MacDonald | verified | | 2 | Pictures on register streams | 4 MAME game logs: 0 VRAM bytes, 0 pixels differ; 13 synthetic streams: 0 pixels except 2 cases, both attributed by switching | verified (detector) | | 3 | Sprite rules | 18 tests; Flicky's status 1,107 of 1,108 equal to MAME (U4) | verified | | 4 | Access windows | emulated VATT inside the hardware spread at the periods measured on 14-18 machines; outside by up to 4.4 points at periods measured on 1-3 | partly met | | 5 | Whole-frame replays, 6 + 6 + 1 PAL | 0 VRAM bytes everywhere; 0 pixels on 12 of 13, 2 on DokiDoki (a mid-line write); windows on: same, Flicky loses 7 writes | verified (detector), with named differences | | 6 | Seeded faults | 28 of 28 caught | verified | | 7 | Speed | Graphics II with sprites, windows on: CPython 16.7 frames/s (0.28 x real time), PyPy 56.9 (0.95 x) | measured | Details, commands and every number: [docs/results.md](docs/results.md). ## Running ```sh python3 -m venv .venv && .venv/bin/pip install pytest # CPython pypy3.11 -m venv .venv-pypy && .venv-pypy/bin/pip install pytest # PyPy (the floor: 3.11) .venv/bin/python -m pytest -q PYPY_GC_NURSERY=1M .venv-pypy/bin/python -m pytest -q ``` The MAME replays in the tests need the git-ignored traces (they are skipped otherwise): regenerate them with the commands in [docs/mame-oracle.md](docs/mame-oracle.md) and `python -I validation/synthetic.py record`. The references are fetched with `python -I scripts/fetch_references.py` (`--verify` to check). | Script | What | | --- | --- | | `validation/mame_replay.py RUN...` | replay MAME VDP logs, compare VRAM, reads and the snapshot | | `validation/synthetic.py record\|compare` | synthetic SG-1000 streams through MAME and sms-python | | `validation/vatt.py fit\|check` | the emulated VATT against VATT's hardware results | | `validation/faults.py` | seeded faults | | `validation/speed.py` | frames per second | The package is `tms9918_python`; standard library only; Python floor = PyPy's (3.11). Licence: MIT ([LICENSE](LICENSE)). Fetched references keep their own licences and are never committed. Start reading at [docs/start-here.md](docs/start-here.md).