# Video timing, the line buffers and colour Sources as in [memory-map.md](memory-map.md): **[TRM]** p.6, 11-16, 21-28 (tier 2), **[TR10]** p.6-8 (tier 2, community-amended), **[NET]** `tom/VID.NET` (449 lines), `tom/PIX.NET` (266), `tom/LBUF.NET` (287) (tier 2 as text; only the lines cited were read), **[MAME run]** (tier 5). ## Two clock domains The video side of Tom runs from the **video clock**, the processors and memory from the **system clock**; the line buffers are the bridge [TRM p.21, 23]. In the console the two are the same 26.59 MHz oscillator [TR10 p.6], so the model may use one timeline in system clocks; keep the two names, because CoJag boards use other crystals (52 MHz and 14.318 MHz are on the board, [sockets.md](sockets.md)). ## Counters and the time base [TRM p.11-16] - **HC** (`F00004`): a 10-bit counter that runs from 0 to `HP` **twice per line**; an 11th bit says which half of the line. One count is one video clock, *not* one pixel: the manual says "incremented by the pixel clock", but with the boot ROM's `HP` = `$34C` only a count per 26.59 MHz clock gives a 15.73 kHz line (below). The manual calls reading HC "only for ASIC test purposes". - **VC** (`F00006`): an 11-bit counter of **half-lines**, 0 to `VP`, once per field; a 12th bit is the field. Software reads it for beam-synchronous work. The Object Processor latches it when it starts, so a whole line sees one value [TRM p.18]. - `HP` (`F0002E`): half-line period minus one. `VP` (`F0003E`): half-lines per field minus one; an **odd number of half-lines makes the display interlaced**. - `HBB`, `HBE`, `HS`, `HVS`, `HEQ`, `VBB`, `VBE`, `VS`, `VEB`, `VEE`: blanking, sync and equalisation: needed only to draw the border and blanking and to place a picture in a frame. - `HDB1`, `HDB2` (`F00038/3A`): when HC equals either, **the Object Processor starts at `OLP`, the line buffers swap, and the other buffer starts shifting out**. Two starts per line exist for 720-wide 24-bit modes; with one start both hold the same value. `HDE`: display end. - `VDB`, `VDE` (`F00046/48`): half-lines between which object processing restarts every line. The *Software Reference Manual* v2.4 (June 1995, image-only, page 13 viewed as an image here) says: "Due to a bug in the Jaguar Console, this register should be set at `$FFFF` to cause the Object Processor to process every line", yet the boot ROM writes `$1F0` and later `$206` (measured). What the bug is, and so what a game that leaves the boot ROM's value sees, is **U5**: `VID.NET`'s VDE comparator decides it. The same manual marks `VP`, `VBB`, `VBE`, `VS`, `VEB`, `VEE` "Do NOT Modify", says `GENLOCK` is "Not supported in Jaguar Console", and tells developers never to set `DMAEN` ("must not be set due to a bug in the Jaguar Console"), `BUS_HOG` and `BUSHI` (OCR text, about pages 45-46, 60 and 81-82). - `VI` (`F0004E`): the half-line of the video interrupt; "must be odd for non-interlaced setups". **The console's NTSC values** [MAME run, boot ROM Series K]: `HP` = `$34C` (845 clocks per half-line, 1,690 per line: 26,590,906 / 1,690 = 15,734.3 Hz), `VP` = `$20B` (524 half-lines = 262 lines, non-interlaced, 60.05 Hz), `HDB1` = `HDB2` = `$A6`, `HDE` = `$6A0`, `VDB` = `$2E`, `VDE` = `$1F0`, `VBB` = `$1F4`, `VBE` = `$18`. Later, from RAM, the ROM narrows the window (`HDB` = `$CB`, `HDE` = `$681`, `VDB` = `$26`, `VDE` = `$206`). The PAL set was not traced (MAME has only the NTSC machine): [TR10 p.8] gives 64.0 us lines and "624" lines non-interlaced against 625 interlaced (so 312 per field), 524 and 525 for NTSC; take the PAL register constants from the boot ROM by running it with the PAL strap (**U6**). ## VMODE (`F00028`) [TRM p.12-13] Bit 0 `VIDEN`; bits 1-2 `MODE`: 0 = CRY16, 1 = RGB24, 2 = DIRECT16, 3 = RGB16; bit 3 `GENLOCK`; bit 4 `INCEN` and bit 5 `BINC` (encrustation: an external video switch on the low bit); bit 6 `CSYNC`; bit 7 `BGEN` (after a line is displayed its buffer is cleared to `BG`, CRY and RGB16 only); bit 8 **`VARMOD`** (the low bit of each 16-bit pixel chooses per pixel: 0 = CRY, 1 = RGB with green in bits 1-5, blue 6-10, red 11-15); bits 9-11 **`PWIDTH`** (pixel width in video clocks, minus one). The boot ROM writes `$6C1`: CRY, composite sync, BGEN, 4 clocks per pixel. Pixels per line follow from `PWIDTH`: the manual's table gives, for divisors 1 to 8, 1330/665/443/332/266/222/190/166 overscanned pixels [TR10 p.6; its "655" for divisor 2 is a slip, 1330/2 = 665: **C4**]. Games change `PWIDTH` freely, so **the picture width is not a constant**: MAME's snapshots here were 642 wide for the boot screen and 713 for Tempest 2000. Compare pictures as line-buffer contents (16-bit values per pixel) before colour conversion wherever a referee allows it. ## The line buffers [TRM p.6, 17, 21-23] Two RAMs of **360 x 32 bits**. One is written by the Object Processor (and readable and writable by every bus master at `F00800`, `F01000`, `F01800`, and at `+$8000` as 32-bit) while the other is read by the pixel path; they swap at `HDB1`/`HDB2`. Each entry is two 16-bit pixels or one 24-bit pixel, so a line is at most 720 16-bit pixels. Writes land at an X the object supplies; objects wider than the display are clipped at the end of the buffer, not of the screen [TRM p.134, bug 5]. The Object Processor writes one entry per system clock: two pixels per clock for unscaled 1-16 bit objects, one for scaled or 24-bit ones, half that with RMW [TRM p.7]. Because the buffer being drawn is filled during the line *before* it is shown, **what software does during line N shows on line N+1**; and an object list too long for one line leaves the buffer incomplete when the swap comes (the state machine's `start or overrun` restart, [object-processor.md](object-processor.md)). ## Colour - **CRY16**: high byte = colour (two 4-bit coordinates on a square mapped from the RGB cube's hexagon), low byte = intensity. The colour byte indexes three ROMs giving red, green and blue at full intensity; each is multiplied by the intensity [TRM p.23, 25-28]. **The three 256-entry tables are printed in the manual** [TRM p.28] (tier 2); the netlist text has only the ROM cells (`PIX.NET` instantiates `CRYRGB`), no contents. Compared here entry by entry (2026-11-12): - Virtual Jaguar (`Virtual-Jaguar-Rx/src/cry2rgb.h`, the same table in the libretro fork's `src/tom/tom.c`) differs from the manual in **2** red entries: row 8, columns C and F hold 15 and 7 where the manual has 115 and 17 (the blue table's mirrored row has 115 and 17 in both). - `JagNetlists/soft/cry/cry2rgb.h` is Virtual Jaguar's file; its `cry_[rgb].mem`/`.mif` and the `verilog/cry_[rgb].ver` ROM images are generated from it (0 of 768 entries differ) and so carry the same 2 errors. The MiSTer core's `ra8008a-c.v` load `cry_[rgb].mem`/`.mif`, which are not in its tree: presumably the same files (not checked). - MAME (`jaguar_v.cpp` `red_lookup`/`grn_lookup`/`blu_lookup`) matches the manual in red but differs in **4** green entries: 182 for 192 at row 1 and row E column A, 96 for 95 at row 3 and row C column 4. So both emulators carry transcription errors and the manual is the judge (it is still a printed copy, not a ROM dump: **U7** now asks only whether silicon matches the printed table). How the intensity multiplication rounds (`PIX.NET`/`cryrgb.v` `r3` is a 20-bit product) is read from the netlist at the video milestone. - **RGB16**: bits 0-5 green, 6-10 blue, 11-15 red, each the top bits of an 8-bit value, low bits 0. - **RGB24**: one pixel per 32-bit entry; red is the low byte of the low-address word, green its high byte, blue the low byte of the high-address word [TRM p.17]. - **Border** (`BORD1` red low byte and green, `BORD2` blue) between active display and blanking; **BG** (`F00058`) the CRY colour the buffer is cleared to. - The CLUT (256 x 16 bits, duplicated so two pixels can be looked up per clock) translates 1/2/4/8-bit object pixels; for 1-4 bit objects the object's `INDEX` field supplies the high bits. ## What the model has to produce A frame as rows of line-buffer snapshots (pixel values and the mode/`VARMOD` state that decodes them) plus the time-base registers, so that a front end can place the picture; RGB conversion is a replaceable table. Decision proposed in the brief: step video by **scanline events on the system-clock timeline** (HC equals `HDB1`, `HDB2`, `HDE`, the half-line wrap, `VI`), with the Object Processor running inside the line as a bus master ([bus-arbitration.md](bus-arbitration.md)). ## Not established Interlace (odd `VP`) behaviour of the field bit and of object `YPOS`/`HEIGHT` stepping by two; the exact clock at which `VI` is raised within its half-line; the light-pen latch (`LPH` is said by the libretro errata to latch HC, not a pixel number: reported, unverified); genlock, encrustation and DIRECT16 (no console software is known to use them: an assertion, not a model).