# The video processor: TMS9928A (NTSC) and TMS9929A (PAL) Sources: **[TI]** the TMS9918A/TMS9928A/TMS9929A data manual, November 1982 (tier 2, the judge for what a register is for); **[TI-PG]** TI's Programmer's Guide SPPU004 (tier 2); **[Young]** Sean Young's `tms9918a.txt` v0.4.2, tested by its author on MSX machines (tier 3); **[TM]** Coleco's Technical Manual; emulators and FPGA cores as detectors (tiers 4-5, named where used). Section numbers are the sources' own. **No die-level work on the TMS9918 family was found**: no netlist, no transistor-level or "visual" simulation, no published decap study. (Searched 2026-11-11: four web searches and the references of every pinned repository; not exhaustive.) The closest things to hardware are TI's own manual, the designers' 1980 symposium draft, Karl Guttag's 2025 talk (a designer's account of the sprite processor and DRAM interface; history, not measurements), and Charles MacDonald's tests of the 4K/16K address wiring on a TMS9929A, quoted in [Young 2.1]. Everything about *when* things happen inside a line is tier 3 at best. ## What the ColecoVision has A TMS9928A (Y, R-Y, B-Y outputs) with 16K of VRAM in eight 16Kx1 DRAMs, clocked at 10.738635 MHz from the CPU clock's third harmonic, `/INT` wired to the Z80's `/NMI`, CPU side at ports `$BE` (data) and `$BF` (control/status) [TM, [memory-map.md](memory-map.md)]. PAL consoles carry the TMS9929A. The plain TMS9918 (no "A") lacks Graphics II and is not used here. ## CPU interface [TI 2.1; Young 2] - One 14-bit address register, one read-ahead byte, one "second byte" latch. The read-ahead is the designers' own description too: "When the CPU is reading data, the VDP always reads the next memory location after the CPU gets the current location's data" (1980 symposium draft, "CPU interface"; read here from an OCR pass, the PDF has no text layer). That draft describes the plain TMS9918: pattern, text and multicolor modes only, four sprites a line, the early clock shifting a sprite 32 pixels; no timing. - Control port, two writes: the low byte, then a byte whose top bits say what it was: `1xxxxRRR` writes the first byte to register RRR; `00AAAAAA` sets the address and **reads ahead** (fetch VRAM, then increment); `01AAAAAA` sets the address for writing. - Data read: return the buffer, refill it from the address, increment. Data write: store, increment; **the byte written also lands in the read-ahead buffer** [Young 2.1]. - **The second-byte latch is cleared by a status read and by any data-port access** [Young 2.3]. This is why an NMI between the two control writes corrupts a game's VDP traffic on the ColecoVision (the handler reads the status register), and why games mask the NMI with register 1 bit 5 instead. - Register bits [Young 1.2]: R0 `M2`, `EXTVID`; R1 `4/16K`, `BLANK`, `IE`, `M1`, `M3`, `SIZE`, `MAG`; R2 name table; R3 colour table; R4 pattern table; R5 sprite attributes; R6 sprite patterns; R7 text colour and backdrop. Register select is 3 bits; the other bits of the second byte are ignored on this chip. - **4K/16K (R1 bit 7)** does not limit memory: it changes how the 14 address bits are put on the DRAM's row and column pins, so the same address reaches a different cell [MacDonald in Young 2.1, measured on a TMS9929A]. The ColecoVision BIOS sets 16K. MAME lists this as not done (`tms9928a.cpp` to-do). Implement the table; it costs one lookup. ### Access windows: writes can be lost [TI 2.1.5, table 2-2] The chip serves the CPU only in **access windows** between its own memory cycles (a cycle is "about 372 nanoseconds", 4 VDP clocks; a line is 342 pixels of 2 VDP clocks, so 684 / 4 = 171 cycles a line: arithmetic on TI's figures, not a TI statement). TI's figures: 2 microseconds from the request, plus a wait for a window of up to 5.95 microseconds in Graphics I/II active display ("CPU windows occur once every 16 memory cycles"), 1.1 in Text, 1.5 in Multicolor, and none with the display blanked or during the 4.3 ms after the frame interrupt. Worst case 8 microseconds = 28.6 CPU clocks. `OTIR` on this console is 21 + 2 = 23 clocks per byte; `OUTI` in an unrolled loop is 16 + 2. So a fast copy during active display can outrun the chip. **What the chip does with a second access that arrives before the first was served is not in the manual** (U1). Clock Signal models windows (its 171-slot dispatcher follows "Grauw's timing diagrams"); MAME, Gearcoleco and sms-python serve every access at once. openMSX has access-slot tables, but its file says which chip each was measured on: check before citing one for the TMS9918A. ## Interrupt and the status register `F C 5S n n n n n` (bit 7 first). - **F** is "set to 1 at the end of the raster scan of the last line of the active display" and cleared by reading the status register or by reset [TI 2.3.1]. `/INT` is low while F and IE (R1 bit 5) are both 1 [TI 2.1.6]. Setting IE while F is already 1 pulls `/INT` low at once [Young 2.4, with the MSX games that need it]. On the ColecoVision that edge is an NMI. - **The race is in the manufacturer's manual**: "asynchronous reads will cause the frame flag (F) bit to be reset and therefore missed. Consequently, the status register should be read only when the VDP interrupt is pending" [TI 2.3]. A program that polls status near the end of line 191 can clear F in the same instant it sets, and that frame's NMI never happens. TI gives neither the width of the window nor what the read returns in it. **The best measurement is of the wrong chip**: openMSX's `doc/internal/vdp-status-race` (pinned) holds test programs and result files from real MSX2 machines (a V9938 and two V9958s): a read near the moment F sets "returns 0 for it, the flag stays 0, and there is no interrupt", inside a window of 13 VDP clocks before to 15 after on the V9938 (their 21.48 MHz clock: about 2.5 Z80 clocks each side). Their notes say the TMS99xx VDPs were not measured and are assumed to behave like the V9938 (read from an openMSX source comment before the 2026-11-14 rule; that source is no longer fetched). So for the TMS9928A the window is an assumption borrowed from its successor (U2). The board must at least order the two events on its one timeline; the exact dot at which F sets on the TI chip has no hardware source here either (MAME sets it when it starts line 192; Clock Signal's constants for it are quoted from a Sega VDP thread). - **C** (coincidence) sets when two sprites have a 1 bit on the same pixel, whatever their colours, cleared by a status read [TI 2.3.2]. TI says sprites "partially or completely off the screen are also considered"; Young says a sprite line dropped as a fifth sprite does not count (C2: not the same case, both may hold). - **5S** sets when a line has five or more sprites **and F is 0**; the low five bits then hold that sprite's number; cleared by a status read [TI 2.3.3]. **Young says a status read clears bits 7 and 5 only** (C1); TI, MAME (`m_StatusReg = m_FifthSprite` after a read) and sms-python clear 5S too. Follow TI. - With 5S clear, the low five bits follow the last sprite the chip looked at: 31, or the first with Y = 208 [Young 4.3: "isn't fully checked"]. MAME's bookkeeping is the family's current model (sms-python found Hyper Sports needs the number not to be held while 5S is set). AtariAge posters report the fifth-sprite number misbehaving on warm consoles; unverified, noted only (U9). ## Display modes [TI 2.4-2.7; Young 3] Mode bits M1 (R1 bit 4), M2 (R0 bit 1), M3 (R1 bit 3). | M1 M2 M3 | Mode | Notes | | --- | --- | --- | | 0 0 0 | Graphics I | 32x24 names, one colour byte per 8 patterns | | 0 1 0 | Graphics II | three 256-pattern thirds; **R3 and R4 become masks**: R4 bit 2 is the table address and bits 1-0 AND with the third number; R3 bit 7 is the address and bits 6-0 AND with the top of the pattern number [Young 3.3]. Games use the masks to share one third | | 0 0 1 | Multicolor | 4x4 blocks, two colour nibbles per byte, row & 3 picks the byte | | 1 0 0 | Text | 40x24, 6-pixel cells, R7's two colours, **no sprites**, 8-pixel borders (TI table 3-3: 240 active pixels) | | 1 1 0 | "Text + II" (undocumented) | text with the three-thirds pattern table of mode II [Young 3.5]. A web page claims TI's Programmer's Guide documents this; it does not: the Guide's mode table (section 5.1.1, read here) lists Graphics I, Graphics II, Multicolor and Text only | | 0 1 1 | "Multicolor + II" (undocumented) | multicolor with the thirds [Young 3.6] | | 1 0 1, 1 1 1 | (undocumented) | no table has any effect: 40 columns of 4 pixels text colour, 2 pixels backdrop, borders as in text, sprites off [Young 3.7] | MAME draws the last two as "MODE bogus" the same way. One known gap in every source: with masks in Graphics II, "sprites 8-31 are ghosted/cloned ... Exact behaviour is not known" (MAME's to-do; an AtariAge poster says blueMSX tried and withdrew it) (U10). Colour 0 is transparent: the backdrop (R7 low nibble) shows, and a backdrop of 0 is black. With BLANK (R1 bit 6) clear the whole picture is backdrop and sprites are not processed. ## Sprites [TI 2.5; Young 4] 32 entries of `Y X pattern colour|EC`. Y is the line above the sprite's first line (Y = 255 puts it on line 0); **Y = 208 ends the list**. EC (bit 7 of the fourth byte) shifts the sprite 32 pixels left. SIZE picks 8x8 or 16x16 (pattern number AND `$FC`, the right half 16 bytes on), MAG doubles each pixel. **Four per line**; the lowest numbers win and are in front; a transparent (colour 0) sprite still takes a slot, still collides, and still hides nothing [Young 4.3; sms-python's Ping Pong finding]. The chip evaluates the next line's sprites during the current line; exactly when it reads the attribute table matters only to programs that rewrite it mid-frame (U11). ## Frame and line [TI table 3-3] A line is 342 pixels: 256 active (240 in text), right border 15 (25), right blanking 8, sync 26, left blanking 2, burst 14, left blanking 8, left border 13 (19). A frame on the 9928A is 262 lines: 192 active, bottom border 24, bottom blanking 3, sync 3, top blanking 13, top border 27. The 9929A has 313 lines; TI's table gives only the NTSC column, and MAME uses a top border of 13 + 51 lines for PAL. (The manual's sentence naming the chips says "TMS9918A/9929A operates at 262 lines", a misprint for 9928A: C5.) Colours: the 9928A puts out luminance and two colour differences; TI's table of levels is the source and the RGB table is a replaceable choice (Young 1.1 derives one). **Compare pictures by colour index 0-15, never by RGB.** ## The decision: a `tms9918-python` core, or a second in-board VDP The chip rule says a non-CPU chip gets its own repository when another emulator in the family could use it. Users of the TMS9918 family: | Consumer | Chip | State | | --- | --- | --- | | sms-python, SG-1000 / SC-3000 | TMS9918A | built: `src/sms_python/vdp.py`, one class for the TMS9918A and Sega's Mode 4 VDPs | | colecovision-python | TMS9928A / TMS9929A | this board | | an ADAM board | TMS9928A | out of scope, same chip | | an MSX1 board | TMS9918A / 9928A / 9929A (and TMS91xx) | not started; a third consumer if it comes | | TI-99/4A, Sord M5, SVI, Memotech, CreatiVision | same family | not planned | **What sms-python has** (read, not copied): `VDP` renders a whole line at one point of it; `VDPVariant` is data, with a `TMS9918A` row whose only flag is `tms_status_low_bits`; modes 0-3 and Young's undocumented modes live in `_render_tms` and `_tms_sprites` (about 140 lines); the fifth-sprite bookkeeping follows MAME; the line timing constants (`SMS_TIMING`) were fitted to FluBBa's tests of Sega's 315-5124/5246, and the TMS9918A row inherits them; there are no access windows and no 4K address table. Its Sega VDPs are their own silicon that happens to implement the TMS modes: they will never be the TI chip. **Option A: extract `tms9918-python`** (package `tms9918_python`, class `TMS9918`, variants as data: `TMS9918A`, `TMS9928A`, `TMS9929A`, later `TMS9918` and the TMS91xx). Built fresh from the manuals, with this board as first consumer; steps by memory cycle (171 a line) so access windows, the status race and mid-line changes have a place to live; exposes colour indices, `/INT` as a level, and CPU port calls stamped with a time in VDP clocks. - For sms-python: the SG-1000 machine would construct the core instead of `VDP(TMS9918A)`; `board.py` and `system.py` would talk to a small shared surface (`run`, the four port calls, `irq`, the frame); the `TMS9918A` variant and `tms_status_low_bits` branches leave `vdp.py`; the Sega class keeps its own modes 0-3 (a Sega chip, with SMS1 masks, Sega overflow rules and CRAM colours), so about 140 lines of similar rendering remain there, legitimately. Its gate is its SG-1000 sweep (208 of 214) and the M2 Check Program; expect rows to move, because today's SG-1000 timing is Sega's and the core's would be TI's. That adoption is a separate, later change on an sms-python branch, as `adopt-sn76489-python` was. - Cost: one more repository and a Phase 0 of its own (most of it is this document and [validation.md](validation.md)); the board waits on the core for its first picture. **Option B: a second in-board implementation** here. Faster to a first picture, no cross-repo work. But it is the second copy of the same chip in the family, an ADAM or MSX board would make a third, and each fix (the status race, the windows) would have to be made twice by hand, which is the situation the rule exists to prevent. **Recommendation: A.** Two consumers exist today and the chip is the hard part of this machine. If Aubrey prefers to see a picture first, the fallback is to incubate the chip as `colecovision/tms9918/` behind an import-boundary test (it may import nothing from the board) and move it out, unchanged, before milestone M4; never to copy it.