# Video: the 315-5196 sprites, the 315-5197 tiles, text, priority, palette DOC from CM16B §3, §5-§8 for System 16B and CMP16 "Sprites" for Pre-System 16/16A, unless tagged. Chip rule: these chips stay in the board (users in the family: this board; System 18 uses successors 315-5361/5362, the X/Y boards others), behind pin-shaped classes. ## Layers Two tile layers, **foreground** and **background**, each a 128 x 64-cell virtual map made of four 64 x 32 pages chosen from sixteen in tile RAM; a **text** layer (64 x 28 cells, 40 x 28 shown: columns 24-63 map to screen columns 0-39); **sprites**; the backdrop (colour entry 0). Cells are 8 x 8, three bitplanes (three tile ROMs, CM16B ROM board tables). **Tile word**: bits 12-0 tile index (0-8191), bits 12-6 also the palette (0-127: the palette overlaps the index, so the same graphics stored twice give two palettes), bit 15 priority (against sprites only), bits 14-13 no visible effect. **Text word**: `p???cccnnnnnnnnn`: 9-bit index, 3-bit palette (8 palettes of 8 colours, entries 0-63), p = 1 puts text over every sprite, p = 0 lets priority-3 sprites over it. **Text RAM 0xE80-0xFFF** holds the layer controls: page selects (FG 0xE80, BG 0xE82, and alternates 0xE84/0xE86; four nibbles = the four pages), vertical scroll with bit 15 = column scroll enable (0xE90/0xE92, alternates 0xE94/0xE96, 9 bits), horizontal scroll with bit 15 = row scroll enable (0xE98/0xE9A, alternates 0xE9C/0xE9E, 10 bits), column tables (FG 0xF00, BG 0xF40; one entry per 16-pixel column pair, 20 used), row tables (FG 0xF80, BG 0xFC0; one entry per 8 lines, bit 15 switches that row to the alternate layer with its own page and scroll and no row/column scroll). In column scroll mode the horizontal scroll's low 3 bits shift each column right and its upper bits pick the map offset ("almost identical" to the Mega Drive VDP's column scroll, CM16B §7). ## Sprites (16B, the 315-5196) 128 entries of 16 bytes in 2 KB of sprite RAM; graphics are horizontal strips of 4-bit pixels read word by word from 128 KB banks, any height and any width, the width set per line by **end markers** (pixel 15). Entry: ``` 00 bbbbbbbb tttttttt bottom line, top line (top >= bottom: not drawn) 02 -------x xxxxxxxx X; the visible range is 0x0B6-0x1F5 04 eh-----f pppppppp e: hide this and all later sprites; h: hide this one; f: X flip; p: pitch (signed words a line) 06 aaaaaaaa aaaaaaaa start word address in the 128 KB bank 08 1111bbbb ppcccccc bank (ROM-board specific), priority 0-3, palette 0-63 (63: shadow/highlight) 0A 000000vv vvvhhhhh Y zoom, X zoom (0 normal, 31 = 50% smaller by skipping lines/pixels) 0C ---------------- 0E mmmmmmmm mmmmmmmm end address, written back by the sprite chip ``` - The pitch is added to the address **before** each line is drawn; pitch 0 repeats one line; a negative pitch with the address at the last line draws Y-flipped. - Normal sprites stop after the 4-pixel group whose **last** pixel is 15; X-flipped ones read backwards from address + pitch and stop at a group whose **first** pixel is 15. 0 and 15 are transparent. - The bank address wraps at 0xFFFF inside the same bank. - After the active display (probably in vblank) the chip **writes back** word 7 (the last address it read; the start address when the sprite is hidden, has pitch 0 or a bad height) and bits 15-10 of word 5 (some internal zoom state, meaning unknown: U7). Values written there read back until the chip next writes them. - Sprite priority affects only sprite-against-tile order; sprites among themselves: later entries draw over earlier ones (CMP16: "subsequent sprites overwriting the previously drawn ones"; CM16B: the last drawn has the highest inter-sprite priority). - Drawing goes into one of two 512 x 12-bit line buffers at 12.5874 MHz while the other is scanned out and erased at 6.2937 MHz (CMP16; CM16B infers the same from the RAM parts). A line has about 800 render ticks: how many sprites fit on a line, and what happens when they do not, is not documented (U8). **Pre-System 16/16A sprites differ** (CMP16): word 04 is a 16-bit pitch; word 06 carries the X-flip bit and a 15-bit offset; word 08 is `--cccccc-bbb--pp` (palette, 3 bank bits, 2 priority bits); word 0A is the "current offset" the chip copies the start into and then uses; a bottom line >= 0xF0 ends the list; X range 0x0BD-0x1FC; no zoom (Hang-On's zoom ROM is not on this board). ## Priority `T1 > S3 > T0 > F1 > S2 > F0 > B1 > S1 > B0 > S0 > G` (CM16B §8): text, foreground and background each have two levels (their priority bit), sprites four; tile priority bits only move tiles against sprites, never against each other (always T > F > B > G). ## Palette and output 4 KB colour RAM, 2048 words: tiles use 0-1023 (128 palettes of 8), sprites 1024-2047 (64 of 16), text 0-63. Word: D15 shade, D14/D13/D12 the low bits of B/G/R, D11-D8 B4-1, D7-D4 G4-1, D3-D0 R4-1: 5 bits per gun plus the shared shade bit, "up to 32768 colors". The backdrop is entry 0 inside the active area; the border, blanking and display-disabled lines are black. **Shadow/highlight**: a sprite with palette 63 hides its own pixels 1-14 and changes what lies below it (backdrop, text, both tile layers; never other sprites): colour RAM bit 15 clear = half intensity, set = double. Sprite priority still applies. The amount is not measured (JT16's PCB check list: "The core assumes 25% attenuation": U9). **Palette flicker**: the CPU and the video share one colour RAM bus; a CPU access during the active display wins, and the pixel being drawn shows the colour of the CPU's address/data. Exact reproduction needs the 68000's bus cycle times against the dot clock, which m68000-python provides (cycle-exact bus); the board decides the pixel. ## Out Run's road chip (not this board) The road generator (`segaic16road` in MAME, two road ROMs in the Out Run sets: census) is on the Out Run and X/Y boards. It belongs to an `outrun-python` board that would pin this one's video classes or extract them (open decision 7).