# Timers, ports, buttons, the touchscreen, the UART ## Timers (DS p. 30-32) - **Timer 0, Timer 1**: 8-bit up-counters against a compare value. TMxC bit 7 start/stop, bits 2-0 the clock: fCK/2, fCK/1,024, /2,048, /4,096, /8,192, /16,384, /32,768, /65,536 (000 ... 111). TMxD: writing sets the time constant, reading gives the count. On each match the output toggles and the interrupt is raised (Timer 0 vector 1002, priority 2; Timer 1 vector 1012, priority 6). Timer 1's output can go out on P37 (P3C). Timer 0's output / 32 is the UART's baud clock. - **Clock timer** CLKT (0054): from the 32.768 kHz sub-clock, an interrupt each second or each minute (bit 6), bit 7 run/reset, bits 5-0 the count (read only). Vector 1016, priority 7. - **Watchdog**: WDT (005E, read) counts from PRS2 (fc11-fc15 from the main clock, or fx5-fx8 from the sub-clock); WDTC (005F, reset value 38h) bit 7 start/stop, bit 6 overflow -> reset or NMI, bit 3 clear (write only), bits 2-0 the clock. DS's text calls WDTC "an 8-bit read only register" and then describes writable bits (**C4**). - Prescalers: PRS0 divides fCK/2 into fc1-fc10, PRS1 divides the sub-clock into fx1-fx8, PRS2 divides fc10 for the watchdog (DS Fig. 8). Their phase at reset and on enable is **U13**. The ratio of the two crystals is exact: 11,059,200 / 32,768 = 337.5. The specification can step the sub-clock from main-clock time without drift (a fixed order of record), although on a real unit the two oscillators drift apart (a known simplification: HYPOTHESIS that no software can tell within a session). ## Ports (DS p. 29-30) P0-P3 (0014-0017) with P0C-P3C (0020-0023): each pair of bits is input, input with pull-up, output, or open-drain output. Reading an input pin gives the pin; reading an output gives the register. The firmware writes P1, P2, P3 about 91-99 times in 300 frames and sets P0C-P3C once (OBSERVED). What each pin does on the Game.com (button matrix, touchscreen scanning, cartridge slot select, speaker, contrast, power) is **U14**: no document; MAME (closed) knows. ## Buttons and the touchscreen (OBSERVED only) MAME's input ports (Lua, 2026-11-26): `IN0` Up, Down, Left, Right, Button A, Menu, Pause, Sound; `IN1` Button B, Button C; `IN2` Button D, Reset, Stylus press. No analogue fields appeared in that listing, so how MAME feeds the stylus position was not seen (it may be a grid of switches read through the ports). The panel's resolution and how it is scanned are **U2** (start-here.md). The build should find it from the firmware: trace port writes and reads while MAME's stylus is moved, then describe the protocol as OBSERVED behaviour of real code. ## UART (DS p. 47-50) URTT (002B, write), URTR (002C, read), URTS (002D: RBSY, OR, FE, PE, TDRE, RDRF), URTC (002E: TE, RE, PEN, EOP, SBL). Baud = Timer 0 output / 32 (/16 per Fig. 25's divider: **C5**). Full duplex, double-buffered receive, 1 or 2 stop bits, parity. Interrupt vector 1008, priority 4. Used by the modem cartridges and cable ("Internet", "Tiger Web Link": census.md): a late milestone with a `SerialDevice` socket. ## Interrupt registers (DS p. 25-26) IE0 (0010): bit 7 DMA, 6 Timer 0, 4 external, 3 UART, 0 LCDC. IE1 (0011): bit 6 Timer 1, 4 clock, 2 PIO. IR0/IR1 (0012/0013): the same bits as requests. These are the board's; the core reads the result as request lines (sm8521-python decision 3). Whether a request bit clears by hardware on acceptance or only by software is **U15**. MAME's tap saw IR0 written 198,244 times and IR1 194,593 times in 300 frames, but it also saw SPH/SPL/PS0/PS1 written about 3.96 M times each, far more than the firmware's own stores could be: MAME evidently routes some of its CPU's internal updates through the same address space, so these counts are MAME's implementation, not evidence of software clearing (OBSERVED, and uninterpreted).