# tms34010-python **Status: documents and oracles only.** There is no core code in this repository yet. What is here is the groundwork a later session builds from: a primer on the processor, its timing, its undocumented corners, a validation plan with every oracle ranked by provenance, a verified recipe for producing emulator-derived traces from MAME 0.285, and a handoff brief with milestones and acceptance tests. Read [docs/README.md](docs/README.md) for the index. ## What the project is `tms34010-python` will be a readable, dependency-free Python 3.12+ Texas Instruments **TMS34010 Graphics System Processor** core, in the shape of the author's existing [z80-python](https://github.com/alewman/z80-python) and [6502-python](https://github.com/alewman/6502-python) cores: - **readable**: instruction families as ordinary Python with explicit dispatch, every handler named by its TI mnemonic, hardware reasons as comments on the lines that encode them; - **pure Python**: no runtime dependencies, CPython and PyPy; - **independently validated**: correctness claims come from external oracles ranked by where their expected values came from, never from confidence; - **embeddable**: the host owns the memory and supplies bit-addressable field access; the core owns the register file, the status register, the instruction semantics including the graphics operations, and the interrupt acceptance model; - **inspectable**: processor state, disassembly and traces without contaminating the hot path. ## Read this part first: it is not a conventional CPU Everything that makes a CPU core easy to write is different here. - **Memory is bit-addressed.** A 32-bit address selects a *bit*, not a byte. The address space is 2^32 bits = 512 MB. Byte address = bit address >> 3; 16-bit word index = bit address >> 4. Every address in a disassembly, in a MAME trace, in the reset vector, is a bit address. This is verified here, not assumed: see [docs/mame-oracle.md](docs/mame-oracle.md). - **Operands are variable-width fields.** A `MOVE *A0,A1,0` moves a field whose width is whatever the status register's FS0 field says (1 to 32 bits), sign- or zero-extended according to FE0, from an address that need not be aligned to anything. Two field descriptors, 0 and 1, are live at once and the instruction picks one. The field is the fundamental memory operation; bytes and words are special cases of it. - **The register file is two banks.** A0-A14 and B0-B14, plus one stack pointer shared by both banks, plus PC and ST. Which bank an instruction sees is a bit in the opcode, not a mode. - **Fifteen of those registers have hardware meanings.** The B file doubles as the parameter block for the graphics instructions: B0 SADDR, B1 SPTCH, B2 DADDR, B3 DPTCH, B4 OFFSET, B5 WSTART, B6 WEND, B7 DYDX, B8 COLOR0, B9 COLOR1. The blitter is not a peripheral; it reads its arguments out of the register file. - **A large part of the instruction set is graphics.** PIXT, PIXBLT, FILL, LINE and DRAV read and write the same memory the CPU executes from, through the same field machinery, with window clipping, transparency, plane masking and one of sixteen pixel-processing operations applied by hardware on every pixel. - **The chip is also the CRTC and a host port.** The video timing generator (HESYNC through VTOTAL, DPYCTL, DPYADR) and the host interface (HSTDATA, HSTADRL/H, HSTCTLL/H) live in the same memory-mapped I/O file at 0xC0000000 as the registers the graphics instructions read. Which of that belongs in a CPU core and which belongs in the host is a real design decision, and the recommendation is in [docs/start-here.md](docs/start-here.md#what-belongs-in-the-core-and-what-belongs-in-the-host). Short version: **the core owns the field machinery, the register file, the whole instruction set including the graphics operations, and the I/O registers the graphics operations read (CONTROL, PSIZE, PMASK, CONVSP, CONVDP, INTENB, INTPEND); the host owns the video timing generator, the shift-register transfer, and the host interface.** ## Scope **TMS34010 first.** The TMS34020 is a superset: wider data bus, more addressing, extra instructions (including `PIXBLT` variants and a floating-point coprocessor interface for the TMS34082), and a different cycle table. [docs/start-here.md](docs/start-here.md) notes the differences where they matter; a TMS34020 mode is a later milestone, not a first-core goal, and MAME's own TMS34020 support is thin ([docs/undocumented-behavior.md](docs/undocumented-behavior.md)). **The graphics operations are in scope for the core, late.** They are instructions, they take their arguments from the register file, and they go through the same bit-field access path as `MOVE`. Putting them in the host would mean implementing the field machinery twice. But they are the second half of the work, not the first: see the milestone order in [docs/handoff-brief.md](docs/handoff-brief.md). **Out of scope for a first core**: cycle-exact bus timing, DRAM refresh, the shift-register transfer's effect on timing, the TMS34082 floating-point coprocessor, and the emulation of any particular board. ## The hardware From MAME 0.285's own machine list (`mame -listxml`, filtered on machines whose CPU chip name contains TMS34010 or TMS34020; 306 machine entries across 25 driver source files; parent sets only below): | Board / family | Games | CPU and clock | | --- | --- | --- | | **Midway Y-unit** (`midway/midyunit.cpp`) | Narc (48 MHz), Trog (40), Smash T.V. (40), Strike Force (48), High Impact Football (40), Super High Impact (40), Total Carnage (48), Terminator 2 (50), **Y-Unit Test ROM v1.40** (40) | TMS34010 | | **Midway T-unit** (`midway/midtunit.cpp`) | Mortal Kombat, Mortal Kombat II, NBA Jam, NBA Jam Tournament Edition, Judge Dredd (location test) | TMS34010 @ 50 MHz | | **Midway Wolf-unit** (`midway/midwunit.cpp`) | Mortal Kombat 3, Ultimate MK3, NBA Hangtime, NHL Open Ice, Rampage: World Tour, WWF: Wrestlemania | TMS34010 @ 50 MHz | | **Midway X-unit** (`midway/midxunit.cpp`) | Revolution X | **TMS34020** @ 40 MHz | | **Atari Games** (`atari/harddriv.cpp`) | Hard Drivin', Race Drivin', Steel Talons, S.T.U.N. Runner, Street Drivin', Hard Drivin's Airborne (20 parent entries incl. board devices) | TMS34010 as `gsp` @ 48 MHz beside a 68010; some boards add a second TMS34010 as `msp` @ 50 MHz | | **Atari Games** (`atari/metalmx.cpp`) | Metal Maniax (prototype) | TMS34020 @ 40 MHz as `gsp` | | **Rare** (`rare/btoads.cpp`, `rare/xtheball.cpp`) | Battletoads (TMS34020 @ 32 MHz **as the main CPU**), X the Ball | TMS34010/34020 | | **Gottlieb** (`gottlieb/exterm.cpp`) | Exterminator | two TMS34010 @ 40 MHz | | **ICE** (`ice/lethalj.cpp`) | Lethal Justice, Egg Venture, Ripper Ribbit, Chicken Farm, Crazzy Clownz, Frantic Fred | TMS34010 | | **JPM Impact** (`jpm/jpmimpct.cpp`) | Cluedo, Scrabble, Trivial Pursuit, Hangman, Coronation Street Quiz, Treasure Quest, Snakes & Ladders, Buzzundrum, Money Spider | TMS34010 | | **Atronic** (`misc/atronic.cpp`) | 32 gambling machines | TMS34020 @ 40 MHz as a video coprocessor to a Z80180 | | Others | `misc/tickee.cpp` (6), `misc/artmagic.cpp` (4: Ultimate Tennis, Stone Ball, Cheese Chase, Shooting Star), `misc/micro3d.cpp` (4: F-15 Strike Eagle, Battle of the Solar System, Tank Battle, Super Tank Attack), `misc/coolpool.cpp` (3), `misc/megaphx.cpp` (2), `misc/vlc34010.cpp` (2), `misc/skeetsht.cpp` (2), `misc/skimaxx.cpp`, `misc/potgoldu.cpp`, `tch/littlerb.cpp`, `shared/inder_vid.cpp`, `tektronix/tekxp33x.cpp` (TekXpress XP330 X terminal), `devices/bus/isa/ex1280.cpp` (Vectrix EX1280 ISA card) | TMS34010 | Two corrections to the commission's working assumptions, from the same listing: **Revolution X is a TMS34020, not a TMS34010** (it is the sole Midway X-unit game), and the TMS34010's largest single deployment by machine count is not arcade at all — it is 32 Atronic gambling machines using a TMS34020 as a coprocessor. The four Midway families together account for 21 parent sets. ## Oracles at a glance Ranked by where their expected values came from (hardware-captured > hardware-corrected > emulator-derived; a low-tier oracle is a **detector**, never a **judge**). Details, licences and limits are in [docs/validation.md](docs/validation.md). | Oracle | Tier | Status | | --- | --- | --- | | A hardware-captured single-step corpus | hardware-captured | **None exists.** Confirmed against the SingleStepTests org (22 repos enumerated), GitHub at large, and TI's own literature. TI never shipped a CPU exerciser, and the TMS34010 has no on-chip self-test. | | *TMS34010 User's Guide*, SPVU001A, August 1988 (sections 12, 13, appendix C) | documentation | The judge, by default, because nothing higher exists | | **Midway Y-Unit Test ROM v1.40** (`yunittst`) — a standalone Midway factory diagnostic | hardware-corrected, end-to-end | Verified here: booted, ran its RAM test, reached `-- DONE --` with every chip green | | The games' own power-on self test | hardware-corrected, end-to-end | Verified here: `smashtv` reaches **`CPU BOARD OK`**; `mk`'s `CPU BOARD TEST` reaches its board diagram | | `birdybro/TMS34010_sv` `sim/vectors/` (MIT) — 137 graphics cases | emulator-derived | The only machine-readable corpus that exists. **Its expected values were generated by running MAME**, so it is a detector. Fetched and verified here by `scripts/fetch_test_vectors.py`. | | MAME 0.285 `tms34010`, traced on `mk` | emulator-derived | Working recipe and a verified sample in [docs/mame-oracle.md](docs/mame-oracle.md) | | FBNeo's `tms34010` core (BSD-3, Marcos Medeiros 2015) | emulator-derived | Genuinely independent of MAME; the tiebreaker when MAME and the manual disagree | Two corrections to this project's commission, both checked rather than assumed: there is **no "TMS340 Family Data Manual"** on bitsavers under that or any name, and no standalone TMS34010 data sheet there either — appendix A of the User's Guide *is* the data sheet. And **Midway's boards do not use the TMS34010's graphics instructions for sprites**; they have a custom DMA blitter, so passing a Midway self test proves the general instruction set and says almost nothing about PIXBLT. `xtheball` is the game that exercises the blitter — measured, in [docs/validation.md](docs/validation.md#which-games-actually-exercise-the-graphics-instructions). ## An honest note on size This is the **largest and least conventional** core of the set. The z80, 6502, 8080, 6809, 68000 and 8086 cores all model a byte-addressed machine with a fixed-width register file and an instruction set that a person can hold in their head. This one does not. The realistic comparison, with z80-python's 4,884 lines of `src/` as the unit, is in [docs/handoff-brief.md](docs/handoff-brief.md#how-big-is-this); the short answer is **two to three times z80-python**, most of it in the field-access machinery and the graphics operations, and there is **no hardware oracle** to certify any of it against. ## Repository layout ```text README.md this file LICENSE MIT .gitignore traces, ROMs, corpora, manuals: never committed docs/ see docs/README.md scripts/fetch_test_vectors.py fetch the pinned graphics corpus into tests/ (ignored) scripts/mame/ the MAME trace recipe as runnable files tests/ corpora land here; nothing is committed ``` ## License MIT. External sources retain their own licences (MAME: BSD-3-Clause for the files cited, and its licence permits transcription with attribution; the TI manuals are cited, not redistributed) and are never bundled. No ROM, no corpus and no third-party program is committed to this repository.