# Timing: memory cycles, access windows, flags This is the heart of a cycle-stepped core and the least documented part of the chip. Every statement carries its tier (1 hardware, 2 manufacturer, 3 hardware-checked community, 4 FPGA, 5 emulator). **No die-level model of any TMS99x8 exists** (see [validation.md](validation.md)), so nothing here is above tier 2 except two captures of narrow facts. ## Clocks [TI 3.6, table 3-3] (tier 2) - Master clock XTAL = 10.738635 MHz. Pixel clock = XTAL / 2 = 5.369 MHz. A line is 342 pixel clocks = 684 master clocks. - **A memory cycle "takes about 372 nanoseconds"** [TI 2.1.5] = 4 master clocks = 2 pixel clocks, so **171 memory cycles a line** (arithmetic on TI's figures). "The TMS9918 never uses burst memory reads" (Vermaelen, tier 3 reading of the 1978 drawing). - CPU clock on the ColecoVision, SG-1000 and MSX1 = XTAL / 3 = 3.579545 MHz, so **one CPU clock = 3 master clocks**, a line = 228 CPU clocks, and a memory cycle = 4/3 CPU clock. This is why the core should count master clocks (or memory cycles with a remainder): the CPU and memory cycles do not divide each other. - Frame: 262 lines (342 x 262 = 89,604 pixel clocks, 59.92 Hz) on the 9918A/9928A; 313 lines (50.16 Hz) on the 9929A. The 1982 TI memo mentions a "rainbowless" plain 9918 at 340 dots a line, sampled and not released as far as anything here says: not in scope. ## The memory schedule What the chip fetches in each of the 171 cycles of a line, per mode, decides where the CPU's access windows fall. | Source | Tier | What it gives | | --- | --- | --- | | [TI 2.1.5, table 2-2] | 2 | the bounds: 2 us of "VDP delay" plus a wait for a window of 0-5.95 us in Graphics I/II active display ("CPU windows occur once every 16 memory cycles"), 0-1.1 us in Text ("at least once out of every three"), 0-1.5 us in Multicolor ("at least once out of every four"), 0 with BLANK = 0 or in the 4,300 us after the frame interrupt | | **TI's 1978 "9918 Address Select / RAM Data Load Timing" drawing** (Guttag archive) | 2 | the slot-level schedule of the *plain* 9918 by horizontal count: in each 8-pixel group the name, colour and pattern fetches; sprite Y checks interleaved with them; one CPU slot every 32 pixel clocks in the pattern modes; the four sprites' attribute (V, H, N, T) and pattern (P1, P2) fetches in the horizontal blank; text mode's name/pattern/CPU rhythm; "refresh mode" (the vertical border) with CPU slots between refresh cycles; blanking, sync and burst. The horizontal counter it uses runs 0-295 then 466-511 (342 states). Vermaelen: it "does contain some (confusing) mistakes"; it predates the 9918A | | Wouter Vermaelen, openMSX "VDP VRAM timing, part II", TMS9918 section (2014) | 3 (a reading, not a measurement) | a cleaned-up per-mode diagram built from that drawing and TI's manual; refresh only in the vertical border (32 refresh reads per border line, none on display lines); Graphics I assumed equal to Graphics II; the Multicolor claim of [TI] contradicted by the drawing in the horizontal border (15 memory cycles without a CPU slot) | | openMSX's MSX1 slot tables | 5 (GPL-2.0) | its author's reading of the same drawing, as numbers in its source: 19 CPU slots a line in Graphics I/II, 51 in Multicolor, 91 in Text, 107 with the screen off. Read under the old rule (detector, before 2026-11-19); **run, never read, from 2026-11-19**. The core's schedule is now derived from TI's drawing alone ([schedule.md](schedule.md)) | | Clock Signal `Components/9918/Implementation/Fetch.hpp`, `Storage.hpp` | 5 | a working implementation of a slot dispatcher "numbered as per Grauw's timing diagrams" | | **VATT results on real MSX1 machines** (msxgl wiki and its raw-data sheet, aoineko and the machines' owners; "17 different MSX1" with TMS9918A, 9928A, 9929, 9118, 9128 and one Toshiba T6950) | **3, hardware-run** | the fastest `OUT` loop with no lost write: display on, Graphics I, II and Multicolor 26-27 T-states depending on the machine (the wiki keeps 29 "to be conservative"), Text "<= 12"; display off, all four "<= 12". **The raw sheet gives the fraction that lands at each loop period**: e.g. a Toshiba HX-10DP (TMS9918A), Graphics II: 67 % at 12 T, 95 % at 22-23 T, 94 % at 24, 97 % at 25, 99 % at 26, all at 27. The protocol (write 256 reference bytes slowly, overwrite them fast, read back slowly, count) shows a lost write leaves the old byte in VRAM | | MAME 0.285, sms-python | 5 | no access windows at all: every access is served at once | **What the hardware run settles**: on real TMS99x8 parts, (a) with the display on, a VRAM write loop faster than about 27-29 Z80 clocks (MSX clocks include one M1 wait per opcode fetch) loses writes in the three pattern modes, (b) Text mode keeps up with the fastest loop, (c) a blanked display keeps up with the fastest loop, and (d) **Multicolor is no faster than Graphics II** (C9: TI's table 2-2 says 0-1.5 us of window wait; the drawing and VATT say the horizontal border's long gap rules). What it does not settle: where in the line the slots are, how many cycles the "2 us" is, and what a lost access looks like. **The "2 us VDP delay"** is unexplained in every source. Vermaelen's guess: 11 VDP (pixel) clocks = 2.05 us. It is the time from the CPU's port write to the chip being ready to use a window; it matters for back-to-back accesses (U3). ## What a too-early access does (U3: the main open timing question) [TI] says how long to wait, not what happens if you do not. The chip has one address register, one read-ahead byte and (per the CPU interface figure) a write-data register. The natural reading is: a data write latches its byte into the write-data register and requests a memory cycle; if a second write arrives before a window served the first, the first byte is overwritten in the register and is never stored, while the address increments once or twice depending on where the increment happens. VATT's protocol counts how many of 256 positions hold the fast-written byte afterwards, so a miss leaves the slow-written reference byte in place; whether the address skipped or the byte went to a neighbour it does not separate, since every fast byte is the same. **No source says which byte is lost or what happens to the address.** The core must make this a modelled choice behind a named switch, with the default stated in the claims and the alternative tested. ## Flags and the interrupt - **F** sets "at the end of the raster scan of the last line of the active display" [TI 2.3.1], tier 2. Young: "after vertical line 192 ... at the beginning of the bottom part of the backdrop". MAME 0.285 sets it when it draws line 193 (`y == 193`, at `HORZ_DISPLAY_START`, commented "vblank is set at the last cycle of the first inactive line"), about 1.25 lines (428 pixel clocks) after the end of line 191's active pixels. sms-python's TMS9918A row uses Sega's measured timing (the frame IRQ at the end of line 192 in mclocks fitted to FluBBa's SMS tests), not TI's. (C10.) The 1978 drawing does not mark it. - **The status-read race** (TI 2.3: an asynchronous read can clear F as it sets, so the frame's interrupt is lost). Window width: measured only on Yamaha's V9938/V9958 (openMSX `doc/internal/vdp-status-race`: a read inside a window of about 13 VDP clocks before to 15 after returns F = 0, F stays 0 and no interrupt occurs); openMSX's source says the TMS99xx parts were not measured (read under the old rule; openMSX is run, never read, from 2026-11-19). A forum report relays Karl Guttag saying a read at that moment clears the flag and that the F18A now models it; secondhand. U8. - **5S and C timing**: 5S is found during sprite pre-processing for the *next* line (the drawing's Y checks run during the current line), so its flag and number change during the line before the one with the fifth sprite; C is set "during the generation of the pixel" [TI 2.3.2], so at the pixel's dot. No measurement of either for the TI chip (sms-python's collision timing constant is Sega's, from FluBBa). U10. - **Register writes take effect** at the next memory cycle that uses them, if the chip reads registers live (likely for a 1978 NMOS design; MAME and sms-python latch per line). No source; mid-line register changes are demo territory (U11). ## Reset [TI 2.1.7] /RESET low for at least 3 us "synchronizes all clocks with its falling edge, sets the horizontal and vertical counters to known states, and clears VDP registers 0 and 1"; "While the RESET line is active, the VDP does not refresh the VRAM". Which known states: not given (U4). MAME starts the frame at the top of its screen; its ColecoVision trace shows `beamy` 244 at reset. ## What this means for the core 1. Count time in **master clocks** (exact for both the 3.58 MHz CPUs and the 5.37 MHz pixel clock); the memory cycle (4 master clocks) is the unit the schedule is written in. 2. Keep the schedule as **data per mode**: for each of the 171 cycles, what it fetches (name, colour, pattern, sprite Y, sprite attribute, sprite pattern, refresh, CPU). Build it from the 1978 drawing and TI table 2-2 alone (since 2026-11-19, provenance wave 2; other emulators' tables are not consulted), and judge the CPU-window part against VATT's thresholds (tier 3: the only hardware-run evidence). 3. Fetch-driven rendering falls out of the schedule (a pixel's colour comes from bytes fetched at known cycles), which is what makes mid-line VRAM and register changes and the timing of 5S and C answerable when hardware evidence appears. 4. Make the uncertain choices switches with stated defaults: the lost-access rule (U3), the status race window (U8, off by default as colecovision-python decided), the dot at which F sets (C10, TI's wording). ## Measured here: how close real game streams come From the MAME logs of [mame-oracle.md](mame-oracle.md) (MAME serves every access at once, so these are what the games *ask* for): | Log | VRAM accesses during active display (lines 0-191, BLANK = 1) | closer than 29 CPU clocks to the previous one | | --- | ---: | ---: | | ColecoVision *Zaxxon*, 20 s, title to gameplay | 16,642 | 0 | | SG-1000 *Flicky*, 20 s, attract mode | 186,031 | **93**, all at 21 clocks, all writes (one burst pattern, e.g. line 58) | So *Flicky* writes VRAM during active display at 21-clock spacing (5.9 us), inside TI's worst case of 8 us. Whether a real SG-1000 loses some of those bytes depends on where the slots fall; it is a ready-made test for the access-window rung (and for sms-python, whose SG-1000 row serves them all).