# The chip as a stand-alone device Sources: **[TI]** the TMS9918A/TMS9928A/TMS9929A data manual, Nov 1982 (tier 2; section numbers are its own); **[PG]** TI's Programmer's Guide SPPU004 (tier 2); **[Young]** Sean Young's `tms9918a.txt` v0.4.2 (tier 3, MSX1 only, "I only know the VDP in the MSX system"); detectors (MAME 0.285 `tms9928a.cpp`, sms-python `vdp.py` at `3f26bc3`, others) named where used. Everything below was read in the pinned files on 2026-11-12; [colecovision-python's `docs/vdp.md`](../../colecovision-python/docs/vdp.md) covers the same ground for one board and is not repeated where it is right. **TI numbers bits MSB first.** In [TI] and [PG], bit 0 of a register is its most significant bit and CD0 is the data bus MSB ("Bit 0 is the MSB, and Bit 7 is the LSB", [PG 5.1]). Young, MAME and this core use LSB-first numbering. Every table here is LSB-first: "R1 bit 6" is `0x40`. ## Pins [TI 3.7] 40 pins. The parts differ only on pins 35, 36 and 38: | Pin | TMS9918A | TMS9928A / TMS9929A | Core's view | | --- | --- | --- | --- | | 39, 40 | XTAL1, XTAL2: 10.738635 MHz +- 0.005 [TI 3.6] | same | the master clock; the core counts it (or a multiple of it) | | 38 | CPUCLK: XTAL/3 = 3.58 MHz | R-Y colour difference | output only; the board decides whether its CPU runs from it | | 37 | GROMCLK: XTAL/24 (TI-99 GROMs) | same | output; ignored by the core (MAME drives it only on the 99xx) | | 36 | COMVID: composite video | Y: luminance and sync | frames as colour indices replace all analogue pins | | 35 | EXTVDP: external video input | B-Y colour difference | the 9918A mixes an external picture; the 92x9A only signal it (below) | | 34 | /RESET and SYNC, trilevel: below 0.8 V reset, above 9 V external sync | same | `reset()`; external sync is out of scope (U9) | | 16 | /INT | same | `int_line`: a level, low while F and IE are both 1 | | 15, 14, 13 | /CSR, /CSW, MODE | same | `read(mode)`, `write(mode, value)` | | 17-24 | CD7-CD0, CPU data | same | the byte | | 1, 2, 11 | /RAS, /CAS, R/W | same | VRAM cycles: inside the core | | 3-10, 25-32 | AD7-AD0 (address/data out), RD7-RD0 (data in) | same | inside the core; only the 4K/16K address mapping is visible to software | "CSW and CSR should never be simultaneously low ... If both are low, the VDP outputs data on CD0-CD7 and latches in invalid data" [TI 2.1.1]: not modelled; the board never does it. ## CPU interface [TI 2.1, table 2-1; Young 2.1-2.3] MODE (usually the CPU's address line 0) picks the port: **0 = data (VRAM), 1 = control (writes) and status (reads).** Internally: one 14-bit address register, one read-ahead byte, one first-byte latch and a flip-flop that says whether the next control write is a second byte. Young: "there is only one read/write address", contrary to "many (official!) docs"; [TI] never says otherwise, its table just describes setting it for reading or for writing. | Operation | Bytes | Effect | | --- | --- | --- | | control write, flip-flop clear | `d` | set the flip-flop. **Whether `d` goes into the address register's low byte now or waits for the second byte** is not in [TI] or [Young]: MAME (`register_write`) and sms-python's TMS row both write it at once, so a lone first byte followed by a data access moves the address; no hardware source either way (U1) | | control write, flip-flop set, `10xxxRRR` | `d`, then `0x80 \| r` | register `r & 7` = `d`; [TI] wants bits 6-3 zero, [Young] "don't care". "The CPU address is destroyed by writing to the VDP register" [TI 2.1.2 note]: the address register takes `d` and the second byte's low six bits, as with an address write | | control write, flip-flop set, `00AAAAAA` | low, then `0x00 \| high` | address = `high << 8 \| low`; **a VRAM read is started** and its byte lands in the read-ahead buffer; the address then increments [TI 2.1.5; Young 2.1] | | control write, flip-flop set, `01AAAAAA` | low, then `0x40 \| high` | address = `high << 8 \| low`; no memory cycle | | data write | `d` | VRAM[address] = `d`, address + 1 (wrapping at `$3FFF`); **the byte also replaces the read-ahead buffer** [Young 2.1] | | data read | | return the buffer; refill it from VRAM[address]; address + 1 | | status read | | return the status register; clear F, 5S, C (C1); the low five bits as below | **The flip-flop is cleared by a status read** [TI 2.1.2: "the status register must be read so that internal CPU interface logic is reinitialized"] **and by any data-port access** [Young 2.3, MSX-tested; not in TI]. Reset clears it (TI 2.1.7 says reset "synchronizes all clocks" and clears R0 and R1; the latch is assumed, U2). **The read-ahead is the designers' 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, as OCR'd by colecovision-python). A data write followed by a read returns the written byte, not memory: a test-visible rule. **Data transfers are not instantaneous.** "The VDP requires approximately 8 microseconds to fetch the VRAM byte following the last data transfer and 2 microseconds following address setup" [TI 2.1.5]. The CPU-side byte is taken at once; the memory cycle happens later, in an access window ([timing.md](timing.md)). What a second access does while the first is still waiting is the core's biggest timing unknown (U3). ## Registers [TI 2.2, figure 2-3; Young 1.2] | Reg | Bits (LSB first) | Meaning | MAME's write mask | | --- | --- | --- | --- | | R0 | 1: **M3** (TI's name; Young calls it M2), 0: EXTVID | Graphics II; external video | `$03` | | R1 | 7: 4/16K, 6: BLANK (0 = blank), 5: IE, 4: **M1**, 3: **M2** (TI; Young: M3), 1: SIZE, 0: MAG | | `$FB` | | R2 | 3-0: name table base / `$400` | | `$0F` | | R3 | 7-0: colour table base / `$40` | Graphics II: bit 7 base, bits 6-0 a mask (below) | `$FF` | | R4 | 2-0: pattern generator base / `$800` | Graphics II: bit 2 base, bits 1-0 a mask | `$07` | | R5 | 6-0: sprite attribute table base / `$80` | | `$7F` | | R6 | 2-0: sprite pattern base / `$800` | | `$07` | | R7 | 7-4: text colour 1; 3-0: text colour 0 and backdrop | | `$FF` | Write-only; there is no way to read a register back. Reset clears R0 and R1 only [TI 2.1.7] (so BLANK = 0 and IE = 0 after reset); R2-R7 power up unknown (U4). **The mode-bit names differ between TI and Young** (C2): this core uses TI's (M1 = Text, M2 = Multicolor, M3 = Graphics II) and says so in every docstring that names one. ## VRAM [TI 3.1; Young 2.1] - The chip addresses 16K with 14 bits and refreshes its own DRAM. It was designed for 4027 (4Kx1), 4108 (8Kx1) and 4116 (16Kx1) parts; R1 bit 7 selects 4027 (0) or 4108/4116 (1) operation [TI 3.1.2]. - **4K/16K does not shrink memory.** It changes which address bits go out on the row and column strobes. Charles MacDonald's table, "tested ... from a TMS9929A in an old Sega personal computer, which used eight 16Kx1 chips" and quoted in [Young 2.1], gives the mapping: in 4K mode, column bits AD0-AD5 = VA0-VA5 and AD6 = VA12; row bits AD0-AD5 = VA6-VA11 and AD6 = VA13. So with 16K of DRAM fitted, a program that writes in one mode and reads in the other sees scrambled addresses. MAME lists it as not done; sms-python does not model it. **Variant data**: the TMS91x8 family treats the bit as "don't care" and assumes 16K [PG 5.1.2 note]. - **The address counter also wraps at 4K in 4K mode.** Karl Guttag's TI message of 1982-06-29: "when in the 4K 'mode' the address counter register will 'roll over' the LS bits at 4K and will roll over at 16K in the 16K mode (which is what the part currently does in the respective modes)". Neither Young/MacDonald nor any detector models this; it and the mux table are two separate effects of the same bit (C11). Which parts of the 1982 plan shipped is not stated; the roll-over is described as existing behaviour. - The 4K/16K mapping is a board-visible fact only when the memory fitted is 16Kx1: on a real 4K board (4027s) the high bits do not exist. The core needs `vram_size` (4K, 8K or 16K) as a construction parameter, from the board, in addition to the register bit (U5). - Every console in scope fits 16K (ColecoVision, SG-1000, SC-3000, MSX1 [Young 1.2: "No effect in MSX1 system"]). ## Display modes [TI 2.4, table 3-2; Young 3] M1 M2 M3 in TI's names (R1 `0x10`, R1 `0x08`, R0 `0x02`). | M1 M2 M3 | Mode | Tables used | Notes | | --- | --- | --- | --- | | 0 0 0 | Graphics I | names (R2, 768 bytes), patterns (R4, 2K), colours (R3, 32 bytes: one per 8 names) | | | 0 0 1 | Graphics II | names; patterns and colours in three 2K thirds by screen third | **R3 and R4 become masks**: TI's table 3-2 uses only R3 bit 7 and R4 bit 2 as bases ("PATTERN COLOR TABLE BASE MSB"), [Young 3.3] gives the masks: R4 bits 1-0 AND with the third number, R3 bits 6-0 AND with the top seven bits of the 10-bit character number. **MAME also ANDs the pattern index with R3's low mask bits on the 99xx parts** (`m_patternmask`, "on 91xx family, the colour table mask doesn't affect the pattern table mask"); Young and sms-python do not. **TI's own 1982 memo sides with MAME**: Graphics II "does not allow for color tables of less than 2K bytes (due to a logic error, the color table cannot be reduced to only 64 bytes without adverse effects to the pattern addressing)" (C3) | | 0 1 0 | Multicolor | names, patterns (2 of every 8 bytes) | 4x4 blocks; byte = pattern base + name x 8 + (row & 3) x 2 + (line >> 2 & 1); **high nibble = left block** [TI 2.4.3: "The 4 MSBs of the first byte define the color of the upper left quarter"]; Young 3.4 says the low nibble is left (C4); MAME and sms-python follow TI | | 1 0 0 | Text | names (960), patterns | 40 x 6-pixel columns, R7's two colours, **no sprites**; the two low bits of each pattern byte are unused; 240 pixels with left border 19 and right 25 pixel clocks against 13 and 15 in the other modes [TI table 3-3], so the text area starts 6 pixels to the right of where the 256-pixel modes start | | 1 0 1 | "Text + Graphics II" (undocumented) | as Text, patterns in thirds with R4's mask | [Young 3.5]; MAME "TEXT 1 variation" | | 0 1 1 | "Multicolor + Graphics II" (undocumented) | as Multicolor, in thirds | [Young 3.6] | | 1 1 0, 1 1 1 | (undocumented) | none | "40 vertical lines of text colour ... 4 pixels TC, 2 pixels BD", borders as Text, sprites off; Tursi found VRAM still refreshed [Young 3.7]; MAME "BOGUS" | The rows above use TI's names; in Young's names the undocumented ones are "1+2", "2+3", "1+3" and "1+2+3". **The plain TMS9918 (no A) has no Graphics II**: MAME ignores R0 bit 1 on it (`m_reva`), and the 1980 draft describes three modes only. Whether the plain part also lacks the undocumented combinations, or treats M3 as zero, is not documented (U6). **Planes, backdrop and border** [TI 2.4]: front to back, sprites 0-31, the pattern plane, the backdrop (R7 low nibble, larger than the others so it forms the border), and the external video plane. Colour 0 is transparent at every plane; "Whenever all planes are of the transparent color at a given point, and external video is not selected, the color shown at that point will be black" [TI 2.4 note]. With BLANK = 0 "the entire screen will show only border color" [TI 2.1.5] and sprites are not processed [Young 1.2: "Sprite system inactive"]. **External video** [TI 2.4, 3.5; Young 1.3]: with R0 bit 0 set the 9918A mixes an external composite picture behind all planes, synced through pin 34; the 9928A/9929A instead drive R-Y and B-Y to a special level (-0.46 in table 2-3) wherever every plane is transparent, so outside circuitry can switch sources. Tursi confirmed the bit on a TI-99/4A [Young 1.3]. No console in scope uses it; Stern's *Cliff Hanger* (a TMS9128 over a laserdisc) does, so the core exposes "transparent everywhere" as colour index 0 in the frame and leaves mixing to the board. ## Sprites [TI 2.4.5, 2.3; Young 4] - 32 entries of four bytes at R5: Y, X, name, `EC 0 0 0 colour`. "A value of -1 puts the sprite butted up at the top of the screen"; "values for vertical displacement between -31 and 0 (E1 to 0) allow a sprite to bleed-in from the top" [TI]. So line = Y + 1, with Y above `$E0` read as negative (MAME: `if spr_y > 0xE0: spr_y -= 256`). - **Y = 208 (`$D0`) ends the table** for that line and every later entry [TI 2.3.2: "Sprites beyond the Sprite Attribute Table terminator (D0₁₆) are not considered"]. - **EC** (byte 3 bit 7) shifts the sprite 32 pixels left. SIZE: 8x8 or 16x16 (name AND `$FC`; four 8x8 quarters, the right half 16 bytes on). MAG doubles each pixel; 32x32 is the largest [TI table 2-5]. - **Four per line.** "The sprites are not active in the Text mode." Lower number = higher priority. A transparent (colour 0) sprite still takes a slot and still collides [TI 2.3.2: "Transparent colored sprites ... are also considered"; Young 4.3]. - **5S and the number** [TI 2.3.3]: 5S sets "whenever there are five or more sprites on a horizontal line (lines 0 to 192) and the frame flag is equal to a 0"; the fifth sprite's number goes into the low five bits. ([TI] writes "lines 0 to 192", one more than the 192 active lines 0-191: C5.) [PG 5.2.3] says instead "the number of the lowest priority sprite on the horizontal line" and omits the F condition (C6). With 5S clear the low bits hold the last entry examined: 31, or the first with Y = 208 [Young 4.3, "isn't fully checked"]; MAME keeps this number current only while 5S is clear, and sms-python found *Hyper Sports* depends on that detail. - **C** sets when two sprites have a 1 pixel at the same place "regardless of where it is located on the screen", including sprites "partially or completely off the screen" [TI 2.3.2]. **MAME and sms-python test only the 256 visible columns** (C7). Young adds that a sprite line dropped as a fifth sprite does not collide. - When the chip reads the attribute table, and so what a mid-frame or mid-line rewrite of it does, is in [timing.md](timing.md). ## Status register [TI 2.3] `F 5S C n4 n3 n2 n1 n0` (bit 7 first). - **F** "is set to 1 at the end of the raster scan of the last line of the active display. It is reset to a 0 after the status register is read or when the VDP is externally reset." - **/INT** "will be active (low) whenever the F status flag is a 1" and IE is 1 [TI 2.3.1, 2.1.6]. It is a level: setting IE while F is already 1 pulls /INT low at once [Young 2.4, with the MSX games that slow down otherwise]; reading status releases it. - **The race is TI's own**: "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]. Width and outcome: [timing.md](timing.md). - **What a status read clears** (C1): TI clears F, C and 5S; Young says bits 7 and 5 only. MAME (`m_StatusReg = m_FifthSprite` after a read) and sms-python clear all three. Follow TI. - Power-up: "The status register should be read immediately upon powerup to ensure that the coincidence flag is reset" [TI 2.3.2], so C is not cleared by power-on; MAME starts at 0 with the number 31 (U4). ## Video output and the three parts [TI 2.4 table 2-3, 3.4, 3.6] | | TMS9918A | TMS9928A | TMS9929A | | --- | --- | --- | --- | | output | composite (luminance + 3.58 MHz chroma) | Y, R-Y, B-Y | Y, R-Y, B-Y | | frame | 262 lines, ~60 Hz | 262 lines, ~60 Hz | 313 lines, ~50 Hz | | pin 38 | CPUCLK (XTAL/3) | R-Y | R-Y | | pin 35 | EXTVDP input | B-Y | B-Y | | colour burst | internal six-phase 3.579545 MHz [TI 3.6.1] | external encoder (3.58 MHz) | external encoder (4.43 MHz) [TI fig. 3-4] | | burst levels in table 2-3 | | R-Y .47, B-Y .1 | R-Y .73, B-Y .2 | Line layout [TI table 3-3, pixel clocks of XTAL/2]: 342 per line; 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). Frame (NTSC): 192 active, bottom border 24, bottom blanking 3, sync 3, top blanking 13, top border 27 = 262. **TI gives no PAL column**; MAME uses 313 lines with a top border of 13 + 51 (U7). [TI 3.6.2] says "TMS9918A/9929A operates at 262 lines", a misprint for 9928A: the manual prints the same sentence a second time, after table 3-2 (page 3-4), as "TMS9918A/9928A" (C8). ## Palette: TI's levels and the RGB everyone uses [TI table 2-3] is the only manufacturer source: for each colour a luminance level (0 = black, 1 = white) and the 9918A's chroma amplitude, and for the 9928A/9929A the Y, R-Y, B-Y levels in volts-like units with 0.47 as zero colour difference. The note "The gray levels differ slightly for the TMS9918A when compared to the TMS9928A/9929A" makes it two tables, not one. | Palette | What it is | Tier | | --- | --- | --- | | TI table 2-3 Y/R-Y/B-Y | the chip's specified output levels | 2 (the judge for levels) | | Young 1.1 RGB (from MESS, Raphael Nabet) | TI's 9928A levels through `Y = .299R + .587G + .114B` with 0.47 as zero; light red clips (R = 1.13); "The coefficients are likely to be slightly different with PAL" | derived from tier 2 by a stated formula: reproducible, not measured | | sms-python `TMS9918A_RGB` | SMS Power's SG-1000 palette page, values from Young | derived | | Measured palettes (captures of real 9918A/9928A video that various emulators and wikis ship) | through an encoder, a TV or a capture card, each a different analogue chain | not surveyed in Phase 0; none pinned, none needed, since the core outputs indices | **The core does not own RGB.** Pictures are compared as colour indices 0-15; converting indices to RGB (and which table to use) belongs to the board or the frontend. The core may ship TI's table 2-3 as data, with no RGB matrix.