# Handoff: build `ti99-python`, the Texas Instruments TI-99/4A board ## Context you are inheriting The family's shape: chips are cores, boards compose cores; CPUs always get their own core; a non-CPU chip used by one machine stays in its board and is extracted only when a second family project needs it; never copy a file between repositories, pin the sibling by commit; add-on hardware is a separate board that plugs into sockets. Read the charter first (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md). The TI-99/4A is era 1 in the charter's table: one CPU, cycle level everywhere, Python runs the tests, Rust plays. Boards to model this one on: **colecovision-python** (a TMS9918A board with a sound chip, its VDP from tms9918-python), **a2600-python** and **gameboy-python** (finished era-1 boards: the gate, sockets, save states), **pcengine-python** (its Phase 0 brief carried to milestones). Cores it embeds: **tms9900-python** (`../tms9900-python`, Phase 0 done today in parallel: its handoff brief is the CPU's contract; build the core's rungs 0-2 before this board's M1), **tms9918-python** (`de266ef`, rungs 0-7 met) and **sn76489-python** (needs a TMS9919 variant, open decision 3). Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [memory-and-bus.md](memory-and-bus.md). 2. [grom.md](grom.md), [video-and-sound.md](video-and-sound.md), [tms9901-keyboard.md](tms9901-keyboard.md), [cartridges.md](cartridges.md). 3. [domains-and-speed.md](domains-and-speed.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md). 4. Later rows: [speech.md](speech.md), [peb.md](peb.md). Then `python -I scripts/fetch_references.py` (11 files, about 37 MB; `--verify` to check) and `python -I scripts/ocr_scans.py` (the scans have no text layer: [CTD], [HCTD], [5220], [6100], [IOB], [DSR], the pin sheet). Cite page images, not OCR, for figures and numbers. ## Decided by Aubrey (standing rules that apply here) - Name `ti99-python`, package `ti99_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own ROMs; nothing of TI's in the repository: firmware by SHA-1 only (census.md). - Python floor = PyPy's (3.11), PyPy must work; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps. - Technical choices are made, marked provisional and reported; policy waits for him. - The no-JIT path first (accepted 2026-11-25): this board declares `recompile: none`. ## Scope In (milestones 1-6): the NTSC TI-99/4A console: TMS9900 (pinned core), console ROM and GROMs, scratchpad, the 16/8-bit multiplexer with its wait states and byte order, the memory- mapped device decode, the TMS9918A (pinned core), the TMS9919 (pinned core, new variant), the TMS9901 (interrupts, timer, keyboard, joysticks, cassette lines), the cartridge port (ROM, RAM, GROM, banking rows on evidence), the I/O-port socket with the 32K expansion as a chipless card, save states. The PAL console (TMS9929A) as a machine row from M1. Later: the Speech Synthesizer (its own add-on board, open decision 4), the disk controller (FD1771), RS232, p-code card, cassette audio, the TI-99/4 (1979: TMS9918 without Graphics II, different firmware) and the 99/4QI rows. ## Package and classes (proposed) ``` ti99_python/ machine.py # rows: ti99_4a, ti99_4ae (later ti99_4, ti99_4qi): VDP part, firmware SHA-1s, clocks console.py # build(machine, cartridge=None, io_cards=(), firmware_dir=...) -> TI99 timeline.py # the common tick (1/2,147,727,000,000 s): CPU 715,909, VDP 200,000, GROMCLK 4,800,000 bus.py # the TMS9900 Bus: decode, 16-bit side, the multiplexer (odd byte first, waits), READY grom.py # Grom (one chip), GromBus (address writes reach all; the slot's chip answers) tms9901.py # TMS9901: interrupt encoder, clock mode, timer, I/O pins keyboard.py # the 8 x 8 matrix (columns via P2-P4, rows on INT3-INT10), ALPHA LOCK, joysticks cartridge.py # Cartridge(rom, grom, ram, pcb) + PCB rows (standard, paged12k, paged16k, ...) cards.py # chipless I/O-port cards: Expansion32K sockets.py # Protocols: CartridgePort, IoPort, Joysticks, Cassette, AudioIn + test fakes savestate.py # whole-machine states naming firmware and cartridges by SHA-1 ``` ## What the board needs from its cores - **tms9900-python**: the bus contract in its brief (read/write with wait clocks and the clock stamp; CRU in/out; external-instruction reports; INTREQ level code, LOAD, RESET, HOLD; `run` to a stamp). Every read-before-write is a real read: the board's decode relies on it. - **tms9918-python**: as colecovision-python uses it (`run(master_clocks)`, port reads and writes with MODE, `int_line`, `take_frame`), driven on the common timeline; no change. - **sn76489-python**: a `TMS9919` variant (2 input clocks per tick, input = GROMCLK; U15-U17 provisional), raised upstream before M3. ## Sockets `CartridgePort` (GROM bus + 6000-7FFF select + write strobe), `IoPort` (every memory and CRU cycle, READY, EXT INT, LOAD, RESET, SBE, AUDIO IN; pass-through capable), `Joysticks`, `Cassette`, `AudioIn`. With nothing plugged in, the port reads as the console's open bus (U24) and the gate must not move when a card or add-on lands. ## The gate (defined at M1) The CPU's instruction stream from reset against MAME's (tms9900-python's `mame_trace.py`) for 180 frames, 0 unexplained; the VRAM at frame 180 equal to MAME's; the bus census counts per device block equal to MAME's or explained (the read-before-write reads included); unit tests of every documented fact (maps, decode, multiplexer order, 9901 bits, GROM protocol); seeded faults each caught. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | Reset to the title screen: CPU, ROM, scratchpad, multiplexer waits, decode, GROMs, TMS9918A, TMS9901 (interrupts, timer), sockets and fakes | [CTD], [9901], [GPL] (2); MAME (5) detector | the gate above | | M2 | Keyboard matrix from the schematic, ALPHA LOCK, joysticks; the menu; TI BASIC | [CTD] schematics (2) | BASIC answers typed lines; matrix unit tests | | M3 | Sound (TMS9919 variant), mixing | [GPL] C (2) | CALL SOUND frequencies by N = 111860 / f | | M4 | Cartridges: standard, Extended BASIC paging ([CTD] B.1.6.1), other PCB rows on evidence | (2), MAME (5) | a smoke list reaches titles or menus | | M5 | 32K expansion card on the I/O-port socket; the CPU's timing switches (C2-C5 in tms9900-python) exposed | (2) | an assembly program in the expansion runs | | M6 | Save states | - | a state loads into a fresh machine and continues identically | | M7+ | Speech add-on board; disk (FD1771); RS232; p-code; cassette; 99/4 and 99/4QI rows | (2) | each its own gate; the base gate rerun first | ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | TMS9900 | TI-99/4, 99/4A, TI 990 boards (MAME 0.285: 10 machines) | new core `tms9900-python` (CPU rule), Phase 0 done | | TMS9918A / 9929A | ColecoVision, SG-1000, MSX, ... (217 MAME machines) | existing core `tms9918-python` | | TMS9919 = SN94624 | TI only (MAME: 7 machines + 2 cards) | a variant row in the existing `sn76489-python` (decision 3) | | TMC0430 GROM | TI home computers only | stays in the board (`grom.py`) | | TMS9901 | TI only (13 MAME machines + 2 cards) | stays in the board | | TMS5220 / TMS5200 (CD2501E) | BBC/Electron speech, Atari arcade, pinball (MAME: 54 + 76 + 29 machines) | stays inside the speech add-on board; extract as `tms5220-python` when a second family board needs it (decision 4) | | SP0256 | Intellivoice and home-computer speech (intellivision-python) | a different chip: no shared code with the TMS5220 | | TMS6100 VSM | TI speech, BBC speech, Speak & Spell family | with the speech add-on | | FD1771 | the TI disk controller | in a later disk row; check the family for WD177x/179x users then | Existing family cores checked and not needed: z80, m68000, mcs48, ay8910, ym2151, ym2413, arm7tdmi, sh2, i8086, huc6280, tms34010 (a TI graphics CPU, unrelated to the 9900). ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Default (provisional) | | --- | --- | --- | --- | | U1 | which address bits each 8000-9FFF device decodes inside its 1 KiB block | [CTD] schematics (scan) | decode as [CTD] A.3's table (A0-A5 and A14) | | U2 | how the multiplexer's 4 read waits split between the two byte cycles | [CTD] fig. B (scan) | 4 waits on the CPU's cycle, bytes at fixed offsets | | U3 | the write's wait count | [CTD] fig. C (scan) | 4 | | U4 | whether VDP accesses get the multiplexer's waits | schematic | yes (decode by address) | | U5 | the 9901's select decode and its mirrors in CRU 0000-07FE | [9901] §2.5, schematic | A10-A14 to S0-S4, mirrored through 0000-07FE | | U6 | what an external instruction (CRUCLK with A0-A2 set) does to the console's CRU devices | schematic | a CRU write at the address left on A3-A14 | | U7 | GROM READY durations (address write, address read, data read) | none documented | FITTED, one table, from MAME's observable timing only as a detector | | U8 | GROM address read-back: order and value | none documented | high byte first, address + 1 (HYPOTHESIS) | | U9 | GROM counter wrap and the 6-8 KiB hole | none | wrap in 13 bits within the slot; hole reads 0 (HYPOTHESIS) | | U10 | every GROM holds its own copy of the address | implied by the protocol | yes | | U11 | other GROM bases (port mirrors in 9800-9BFF) | [PES] ch. 12 | console GROMs answer at all bases (HYPOTHESIS) | | U12 | the V2.2 (QI) GROM 0 and other versions | MAME `ti99_4qi` image; Classic99 prose | machine row with MAME's image | | U13 | the European board beyond its VDP | none read | same as NTSC but TMS9929A | | U14 | the value read from an address nobody drives on the 8-bit bus | none | FITTED later; 0 meanwhile | | U15 | TMS9919 noise LFSR length and taps | none | the SN76489AN's | | U16 | TMS9919 tone N = 0, output level, READY | none | the SN76489AN's | | U17 | the 99/4's sound chip | MAME (SN94624) | same as the 4A | | U18 | the keyboard matrix | [CTD] schematics (scan) | transcribe in M2 | | U19 | ALPHA LOCK's row and polarity | schematic | from the schematic | | U20 | which phase clocks the 9901 (timer = φ/64 at 3 MHz) | schematic | 3 MHz → 46,875 Hz | | U21 | Extended BASIC's bank-select bit (address or data) | none in hand | address bit (A14: 6000/6002), HYPOTHESIS | | U22 | the No-Intro set's file layout | the set (absent) | readers for RPK and suffix files first | | U23 | speech READY duration on the PHP1500 | [5220] timing figures | from [5220] | | U24 | open-bus value of an empty I/O port and an empty DSR space | none | 0 (HYPOTHESIS) | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | the sound chip's name | TI's diagram: TMS9919; MAME: SN94624 | one variant, both names | | C2 | I/O pins 12 and 44 | [CTD]: READY, IAQ; [HCTD]: READY/HOLD, HOLD/IAQ (HOLDA when MEMEN is inactive) | [HCTD]'s fuller wording; HOLD on the port is a later (DMA card) row | | C3 | peripheral CRU allocation | [CTD] vs [HCTD] in four rows (memory-and-bus.md) | irrelevant to emulation; note only | | C4 | the speech chip | the brief's TMS5220 vs MAME's CD2501E (TMS5200 class) and whtech's "like 5200 in 99-4 speech" | settle before the speech row: a board photograph or TI document | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains**: C (CPU, 3.000 MHz from 48 MHz: CPU, ROM, scratchpad, multiplexer, 9901, cartridge ROM/RAM, 32K), V (TMS9918A, 10.738635 MHz), G (GROMs and sound on V's 447 kHz GROMCLK, scheduled apart from V; the GROMs stepped inside C's order of record because only the CPU reaches them, synchronously), S (speech, its own 640 kHz), D (disk, later). A common tick of 1/2,147,727,000,000 s makes the CPU (715,909 ticks) and the VDP (200,000) exact. - **Channels**: the VDP ports and /INT (→ 9901 INT2 → level 1), the GROM ports with READY, the sound write log, the speech ports with READY, the I/O and cartridge sockets. MAME's census: 10-30 thousand crossings a second, one in 30-100 CPU machine cycles. - **Need, with the arithmetic**: CPU ≤ 3,000,000 / 8 = 375,000 instructions/s (MAME at the title screen: 161,014/s); VDP 342 × 262 × 59.92 = 5.37 M dots/s (10.74 M master clocks/s); sound 447,443 / 2 = 223,722 ticks/s; speech 8,000 × 10 = 80,000 lattice steps/s. - **No-JIT path**: Python (PyPy) about 0.3-0.5 × real time (tms9918-python alone 0.95 × on PyPy), enough for the rungs; Rust desktop many times real time; Rust -fast reaches real time with margin on phone and in the browser without recompilation; threads optional (the VDP as a pure producer from a write log if a weak target needs it). `recompile: none`; no cached interpreter for the TMS9900 (prune what does not pay). ## Open decisions for Aubrey 1. **The No-Intro TI-99/4A set is not on this machine.** `$NO_INTRO_DIR` has 153 sets but no "Texas Instruments - TI-99-4A"; retool's metadata shows the DAT exists. Recommended: fetch it (your call) before M4; M1-M3 need only the console firmware, which is present (19 of 19 images by SHA-1), and MAME's CC0 cartridge list stands in as the catalogue meanwhile. 2. **Nouspikel's TI-99/4A Tech Pages: set aside (site's wishes).** www.unige.ch answers automated clients with a JavaScript challenge (even for robots.txt), and today's rule says not to work around it, so not even the Wayback copies were used. The pages are the best hardware-checked community source for the GROM, the multiplexer, the TMS9919 and the keyboard (U2-U11, U15-U19), and the author offers his whole site as a zip. Recommended: write to the author for permission to use a copy of the zip (or ask whether you are content with the archived zip), and until then work from TI's documents with the unknowns marked. 3. **The TMS9919 as a variant row in sn76489-python, not an in-board chip.** Recommended: TI's own programmer's summary matches the SN76489A's register protocol and formula exactly once the 447 kHz input is accounted for; a variant with a `clocks_per_tick` field and provisional noise rows is the smallest change, and fixes start upstream. 4. **The Speech Synthesizer as its own add-on board** (`ti99-speech-python`, package `ti99_speech_python`, pinning ti99-python and plugging into the I/O-port socket), with the TMS5220/5200 model inside it until a second family board needs that chip. Recommended: the family's add-on shape, and the chip rule (no family consumer beyond this today; the SP0256 is a different chip with nothing to share). Settle C4 (which part is fitted) first. 5. **Chipless I/O-port cards (the 32K expansion) inside the base board; cards with their own chips (disk FD1771, RS232 TMS9902) as later add-on boards.** Recommended: almost all assembly and Extended BASIC software needs the 32K card, which is only RAM on the 8-bit bus; the disk card brings a controller chip, firmware and drive timing of its own. 6. **First machine NTSC TI-99/4A, with the PAL console as a row from M1.** Recommended; the 99/4 (different VDP and firmware) and the 99/4QI (V2.2 GROM, U12) later as rows. 7. **Default provisional choices** (U1-U24 "Default" column above), each marked HYPOTHESIS or FITTED in code; the multiplexer's 4 waits on read and write are the most consequential and the first to check against the page images of [CTD] figures B and C. 8. **Rows for emulator-lineage sources.md** (validation.md, end): TI's documents (facts only), whtech as an archive, Nouspikel set aside (site's wishes), MAME's TI-99 files LGPL-2.1+ (closed), Classic99 all rights reserved, js99er no licence file, EP994A LGPL-3.0, retool metadata BSD-3-Clause. Recommended: add them as written. 9. **A probe queue entry**: no TI-99/4A hardware is on hand (no probes). Recommended: list the multiplexer waits (U2-U4), the GROM timing and read-back (U7-U9), the TMS9919 noise (U15) and tms9900-python's C2-C5 in the family's `PROBE-QUEUE.md` in case a console or a willing owner turns up.