# The TMS9901: interrupts, keyboard, joysticks, cassette, timer Sources: **[9901]** TMS 9901 Programmable Systems Interface data manual, July 1978 (tier 2); **[CTD]** A.4-A.5 "9901 bit organization" and "9901 I/O mapping" (tier 2). Tags as in memory-and-bus.md; all DOC unless tagged. ## The chip [9901] - A CRU device with 32 bits (5 select lines S0-S4), an interrupt section (15 maskable inputs INT1-INT15 encoded to a 4-bit priority code IC0-IC3 plus INTREQ for the TMS9900), 16 I/O pins P0-P15 (seven of them shared with INT15-INT7), and a 14-bit interval timer [9901 §1-2]. - **Control bit 0** selects interrupt mode (0) or clock mode (1). In clock mode, CRU bits 1-14 read the timer's read register and write the clock register; writing the clock register reinitialises and starts the decrementer; writing 0 to bit 15 in clock mode resets the I/O pins (software reset) [9901 §2, table 1 notes]. - **Timer**: a 14-bit counter decrementing at f(φ)/64; "at 3 MHz this results in a maximum interval of 349 milliseconds with a resolution of 21.3 microseconds"; at zero it raises the level-3 interrupt and reloads from the clock register; the decrementer always runs; the read register is updated every decrement while the chip is not in clock mode, so a value is latched by entering clock mode [9901 §2.5]. On the 99/4A f(φ) is the CPU's 3 MHz (the console uses φ3 for its devices, [CTD A.2]): **46,875 Hz** (DOC by the manual's own 3 MHz example; which phase drives the 9901's φ pin is to be read from the schematic, U20). - The manual's own warning: with A10-A14 on the select lines, a CRU access outside the 9901's 32 bits can make the timer "think" it is out of clock mode and update the read register [9901 §2.5, lines 619-625 of the text]. The console decodes exactly that way (U5 in memory-and-bus.md); the board must model the select logic, not just bits 0-31. - **Interrupt code**: the highest-priority enabled active input wins; with RST1 low (the reset input) the code is forced to 0 and INTREQ held high [9901 §2.3, table 2]. On the 99/4A only INTREQ matters: the code lines are wired so the CPU always takes level 1 [CTD A.5], and software reads the 9901's input bits to find the source. ## The 99/4A's wiring [CTD A.4 "9901 bit organization", "9901 I/O mapping"] | CRU addr | Bit | 9901 | Use | | --- | --- | --- | --- | | 0000 | 0 | control | interrupt / clock mode | | 0002 | 1 | INT1 | external interrupt (I/O port EXT INT) | | 0004 | 2 | INT2 | VDP vertical sync interrupt | | 0006 | 3 | INT3 | 9901 timer interrupt; keyboard "=" line; joystick FIRE | | 0008 | 4 | INT4 | keyboard "space" line; joystick left | | 000A | 5 | INT5 | keyboard "enter" line; joystick right | | 000C | 6 | INT6 | keyboard "0" line; joystick down | | 000E | 7 | INT7 (P15) | keyboard "fctn" line; joystick up | | 0010 | 8 | INT8 (P14) | keyboard "shift" line | | 0012 | 9 | INT9 (P13) | keyboard "ctrl" line | | 0014 | 10 | INT10 (P12) | keyboard "z" line | | 0016 | 11 | INT11 (P11) | not used as interrupt | | 0018 | 12 | INT12 (P10) | reserved, high level | | 001A-001E | 13-15 | INT13-INT15 | not used as interrupt | | 0020, 0022 | 16, 17 | P0, P1 | reserved | | 0024 | 18 | P2 | keyboard select bit 2 | | 0026 | 19 | P3 | keyboard select bit 1 | | 0028 | 20 | P4 | keyboard select bit 0 (MSB) | | 002A | 21 | P5 | keyboard ALPHA LOCK | | 002C | 22 | P6 | cassette control 1 (motor) | | 002E | 23 | P7 (INT15) | cassette control 2 (motor) | | 0030 | 24 | P8 (INT14) | audio gate | | 0032 | 25 | P9 (INT13) | mag tape out | | 0034 | 26 | P10 (INT12) | reserved | | 0036 | 27 | P11 (INT11) | mag tape input | | 0038-003E | 28-31 | P12-P15 | not used in I/O mapping | The row names above are one column's keys (the key that drives each row line in the column [CTD] names); the **full 8-column × 8-row matrix** (columns 0-5 keys, 6-7 the two joysticks, selected by P2-P4; rows read on INT3-INT10) is in the schematic pages of [CTD] (scans, pp. 59-63): to be transcribed from the page images in milestone 3 (U18). ALPHA LOCK is an output that gates the alpha-lock key's row (U19: which row and with which polarity). Wired joysticks (TI's twin joysticks) share the row lines through the column select [CTD table]. ## Cassette and audio Two cassette motor controls (P6, P7), the audio gate (P8, which lets the cassette input reach the speaker), tape out (P9) and tape in (P11) [CTD]. The cassette is a later row (its own socket; no tape images in the No-Intro set as far as its absence lets us know). ## The chip rule The TMS9901 appears only in TI machines in MAME 0.285 (13 in `ti/`, one skeleton, and two PEB disk-controller cards; `listxml` device count, 2026-11-26, OBSERVED). It stays in the board: `ti99_python.tms9901.TMS9901`.