# The CPS-A-01 and the video pipeline The graphics hardware is two chips with a clean division `[die]`: **the CPS-A-01 (DL-0311) handles addresses, the CPS-B (DL-0411 / DL-0921) handles data.** The CPS-A reads graphics RAM by taking the 68000's bus, drives the graphics ROM address bus, and owns the object frame buffer's write side. The CPS-B turns ROM data into pixels, mixes the layers, addresses the palette RAM and makes the sync signals ([cps-b.md](cps-b.md)). Tags are those of [memory-map.md](memory-map.md). Everything marked `[die]` is read from Loïc Petit's documentation of his trace (pin `cbd37b38`), not from a simulation, and his README warns that "traces were followed by hand and there may be issues". Where `[die]` and `[mame]` differ the difference is listed as a conflict in the brief; neither is silently preferred. ## Registers (`800100 + offset`, write only) | Offset | Name | What | Sources | | --- | --- | --- | --- | | `00` | OBJ base | object list base: value & `FFC0`, times 256. **Bit 0** selects 64-byte instead of 8-byte entries (no known game) | `[die: sprites.md]`; MAME uses the base only | | `02` `04` `06` | scroll 1/2/3 base | value & `FFC0`, times 256 (a 16 KiB boundary) | `[die: scroll.md]`, `[mame]` (which names Captain Commando and the Muscle Bomber games as writing unaligned bases) | | `08` | row scroll base | value & `FFF8`, times 256 | `[die]` | | `0A` | palette base | value & `FFFC`, times 256. **Writing it is what requests a palette copy.** **Bit 0 = one section only** (copy `0x400` words instead of `0x1800`) | `[die: wstlut.md]`. MAME: "minimum alignment 0x400 bytes ... when bit 0 is set the palette doesn't seem to be copied" (a Magic Sword board test): C3 | | `0C` `0E` | scroll 1 X, Y | 10 bits | `[die]` | | `10` `12` | scroll 2 X, Y | 10 bits | | | `14` `16` | scroll 3 X, Y | 10 bits | | | `18` `1A` | star field 1 X, Y | 9 bits | `[die: stars.md]` | | `1C` `1E` | star field 2 X, Y | 9 bits | | | `20` | row scroll offset | first index into the row scroll table, 10 bits | `[die]` | | `22` | video control | bit 15 flip screen; bit 3, 2, 1 enable the **bus requests** for scroll 3, 2, 1; bit 0 enables row scroll | `[die: scroll.md]`; `[pcb]` Corrado Tomaselli's tests on Magic Sword quoted in `cps1_v.cpp` (clearing bit 1 repeats the last two rows of scroll 1 over the screen: consistent with "the RAM is no longer read") | | `24` | WSTROM copy | development feature: copies RAM into graphics "ROM"; on a retail board it holds the bus for about four frames | `[die: wstrom.md]`; MAME: "pzloop2 writes to register 24 on startup. This is probably just a bug" | MAME's notes on the two unexplained bits: Ghouls'n Ghosts sets bit 14 of video control; Magic Sword writes `3E` where most games write `0E`, and bits 4-5 showed "no visible differences" on the board `[pcb]`. ## Raster All from `[die: video-signals.md]` unless marked; the counters live in the CPS-B and are clocked by `LI`/`FI` pulses from the CPS-A. - One 16 MHz oscillator; the pixel clock is 8 MHz. **512 pixel clocks per line, 262 lines per frame**: 15,625 Hz and **59.6374 Hz** by arithmetic. - `/HBLANK` is low for columns `0..64` and `449..511`: 384 active columns. `HSYNC` is high for `0..3` and `480..511`. - `/VBLANK` is low for lines `0..16` and `241..261`: 224 active lines. `VSYNC` is high for `252..254`. The line counter resets to 509 (-3), so the chip counts lines -3 to 258. - MAME: `set_raw(8 MHz, 512, 64, 448, 262, 16, 240)`. The one-count differences from `[die]` are a matter of which edge is counted, not yet reconciled (C5). **Which frame-rate figure comes from what:** | Figure | Where it comes from | | --- | --- | | 59.6374 Hz | arithmetic: 8,000,000 / (512 x 262); MAME (59.637405), Sanglard's book, jtcps1 (59.64) | | 59.61 Hz | **measured**, the only measurement found: Kold666, 2008, "one of the input gates of the 74ls08@4J on a gng romboard" (MAME Testers 02044; instrument not stated). 0.05% under the arithmetic figure, inside a crystal's tolerance | | 59.63 Hz | FinalBurn Neo's constant for CPS-1 and CPS-2; no measurement is cited | | 59.6333 Hz | the reporter's expectation in MAME Testers 02044 ("but I can't prove it in a digital way"); once MAME's CPS-2 value | | 59.6388 Hz | a figure in MAME's `cps2.cpp` board notes; origin not stated | | 60 Hz | MAME's CPS-1 value before 2008: never measured | The board decision: time is counted in 16 MHz master clocks and the frame is 512 x 262 pixel clocks; no frame-rate constant appears anywhere. ## Graphics ROM addressing The CPS-A drives a 23-bit address `ROMA[22..0]`; bits 22-20 name the layer (0 sprites, 1 scroll 1, 2 scroll 2, 3 scroll 3, 4 stars) `[die: graphics-rom-layout.md]`, `[mame]`. The B-board's PAL decides from the top bits which ROM bank answers, or none ([gfx-mapping.md](gfx-mapping.md)). The ROMs return 64 bits: sixteen 4-bit pixels, half of them selected by the C-board. **Pen 15 is transparent on every layer** `[die: layer-assembly.md]`. | | scroll 1 | scroll 2 | scroll 3 | sprites | | --- | --- | --- | --- | --- | | tile | 8x8 | 16x16 | 32x32 | 16x16 | | map | 64 x 64 | 64 x 64 | 64 x 64 | list | | tile code bits used | 16 | 16 | 14 | 16 | | ROM address | `0, code[15..3]` at bits 19..6, `code[2..0]` at 5..3, row at 2..0 | `code[15..2]` at 19..6, `code[1..0]` at 5..4, row at 3..0 | `code[13..0]` at 19..6, row at 5..1, half at 0 | `code[15..8]` at 19..12, tile Y nibble at 11..8, tile X nibble at 7..4, row at 3..0 | The row bits are inverted by the tile's Y flip (XNOR with the screen flip). The bit tables are in `[die: scroll.md, sprites.md]`; MAME's diagram (`cps1_v.cpp` l.389-395: `sprite 000ccccccccccccccccyyyy`, `scroll1 001?ccccccccccccccccyyy`, ...) agrees on the widths. The sprite tile nibbles are the block arithmetic of "Objects" below: bits 19..4 are the 16-bit code after the nibble-wise add. ## Scroll layers **Tile entry**: two words, tile code then attributes `[die]`, `[mame]`: | Bits | What | | --- | --- | | 4-0 | palette (32 palettes of 16 colours per layer) | | 5 | X flip | | 6 | Y flip | | 8-7 | priority group (which of the four CPS-B priority masks applies: [cps-b.md](cps-b.md)) | | 9 | `CDEN`, passed to the CPS-B, unused | | 15-10 | not connected; games store their own flags here `[mame]` | **Map addressing** (which entry is tile (X, Y)), from `[die: scroll.md]`: scroll 1 is column-major in a peculiar split (`Y5` at bit 13, `X5..X0` at 12..7, `Y4..Y0` at 6..2); scroll 2 has `Y5 Y4` at 13..12, `X5..X0` at 11..6, `Y3..Y0` at 5..2; scroll 3 has `Y5 Y4 Y3` at 13..11, `X5..X0` at 10..5, `Y2..Y0` at 4..2. MAME's three `tilemap_scan` functions encode the same. **How the chip draws** `[die: sram.md, scroll.md]`: the CPS-A cannot read RAM during the line. It holds a 256-entry internal SRAM (10 attribute bits and 16 code bits per entry) with the tile rows currently on screen, refilled by bus requests on fixed lines (below). Tiles are streamed on a fixed 16-pixel grid; the fine X shift is applied by the CPS-B (`XS` bus), the Y shift by the CPS-A choosing the ROM row. Scroll 1 holds 49 entries per row, scroll 3 uses the top quarter of the SRAM. **Row scroll** (scroll 2 only): per line, `X = scroll2_x + RAM[rowscroll_base + ((offset + line) & 0x3FF)]`, the table value taken as 9 bits `[die]`. To cope with any row offset the SRAM holds 48 scroll 2 tiles per row. **A row offset above 383 makes scroll 2 read scroll 3's SRAM entries** `[die: sram.md]`: a real glitch no emulator models (Q7). Games known to use row scroll `[mame]`: SF2, Mega Twins, Carrier Air Wing, Magic Sword, Varth, Captain Commando. ## Objects (sprites) **Entry**: four words `X, Y, code, attributes` `[die: sprites.md]`, `[mame]`: | Attribute bits | What | | --- | --- | | 4-0 | palette | | 5 | X flip | | 6 | Y flip | | 7 | `LOOKUP`: per-tile palette fetched from RAM at `((base ^ 0x40) << 8) + (palette << 9) + (y << 5) + (x << 1)` (no known game); MAME's comment for this bit describes CPS-2 | | 11-8 | width in tiles, minus one | | 15-12 | height in tiles, minus one | - A block's tile at (x, y) has code `code + x + (y << 4)` **with no carry between the two nibbles**: from `0x4E`, tile (0, 3) is `0x41`, not `0x51` `[die]`. MAME does the same arithmetic in its sprite loop. - The list ends at the first entry whose attribute high byte is `FF` `[mame]`; the list is 256 entries (`0x800` bytes) `[mame]`. Entry 0 is in front `[mame: drawn last]`. - **256 tiles per frame, not 256 entries.** The CPS-A makes one object bus request per scanline (every line except 239-244: 256 of them) and each request serves **one 16x16 tile**; a multi-tile block uses one line per tile `[die: sprites.md, bus-requests.md]`, `[book]` ("hard limit of 256 tiles per frame"). MAME draws every tile of every entry (Q3). - **The frame buffer and the one-frame lag.** The A-board carries twelve HM53461 video RAMs in two banks; each frame one bank is read out to the CPS-B while the other is written with the next frame's objects `[die: vram.md]`, `[sch]`. Objects therefore appear **one frame after** the scroll layers written in the same frame. MAME copies the list at vblank and draws it the next frame; FBNeo does the same (HYPOTHESIS: read from its non-commercial source in Phase 0; that source is not fetched since 2026-11-24). On hardware the list is not copied at one instant: it is read one entry per line across the frame (Q4, U8). - The sprite pixel stored in the frame buffer is 9 bits (4 colour, 5 palette) `[die: vram.md]`; the author marks the buffer's timing "VERY work-in-progress". - X and Y: 9 significant bits; MAME draws at `X - 64, Y - 16` with wrap at 512 `[mame]`. ## Star fields Two fields, each one star slot per 32 pixels, in a 512 x 512 space; no RAM, only the four position registers `[die: stars.md]`. The ROM address is `0000 000y xxxx yyyy yyyy`; only one of the four ROM byte lanes is read. A star byte holds a 5-bit position within the 32 pixels (value `0x0F` means no star) and a 3-bit palette `[die: star-raster.md]`. The palette address is `0x800` (field 1) or `0xA00` (field 2), plus `palette << 4`, plus a counter that advances every 16 frames and wraps at 16, or at 15 when the palette's top bit is set (the twinkle). MAME's code agrees on the arithmetic and on which registers go with which palette (`STAR1-X/Y` with `0x800`), but its enable index 0 (the layer-enable mask the die calls stars 1) draws the field the die calls stars 2 (C6). Only Forgotten Worlds and Strider enable them `[mame]`. ## Palette - Palette RAM is separate from graphics RAM and cannot be written by the 68000. It holds `0xC00` entries: six pages of 512 (sprites, scroll 1, scroll 2, scroll 3, stars 1, stars 2), each page 32 palettes of 16 `[die: palette-copy.md]`. - **Word format**: bits 15-12 brightness, 11-8 red, 7-4 green, 3-0 blue. - **Brightness** is analogue: the DAC is a resistor array per channel, the colour nibble on 2.2k/1k/470/220 ohm and the brightness nibble on 1k/470/220/100 ohm `[jt: colour_dac.md]`. `[die: wstlut.md]`: "roughly `C * (1 + 2.2 * F/15)`", normalised by 255/48, "not 100% accurate as it is in practice not 100% linear". MAME: `C * 17 * (15 + 2F) / 45`, with the comment "from my understanding of the schematics, when the 'brightness' component is set to 0 it should reduce brightness to 1/3". The two formulas differ by under 3% of full scale at every input (computed: at F=0 they give 31.2% and 33.3%). No measured transfer curve was found (U9). The board compares pictures at the **16-bit palette word**, never at RGB. - **The copy.** A write to the palette base register raises a request; at the next vertical blank the CPS-A takes the bus and walks `0x1800` words of graphics RAM (or `0x400` with bit 0 set), while the CPS-B walks the palette RAM and writes the pages its palette control register enables `[die: wstlut.md, palette-copy.md]`. If no write happens, changing graphics RAM changes nothing on screen. - **The page quirk** (which RAM page lands in which palette page when low bits are clear): [cps-b.md](cps-b.md), "Palette control". - **Cost**: the die documentation says the copy takes "`0x1800` 4 MHz strobes" (1,536 us, its 9.2% of a frame); jtcps measured **780.4 us** on a board, constant whatever the page mask `[jt: DMA.md]`. The palette holds `0xC00` words (six pages of `0x200`; MAME copies `0x200` words per enabled page), and `0xC00` words at 4 MHz is 768 us, within 2% of the measurement: the likely reading is that the die text's `0x1800` counts **byte** addresses. This is an inference from two numbers, not a trace (U10, C4). It is interrupted and resumed around the per-line requests. - The background, where every layer is transparent: MAME fills with palette entry `0xBFF` for CPS-1 and names 3 Wonders, Mega Twins and Mercs as depending on it `[mame]`. The die documentation does not say what the mixer outputs then (U11). ## Bus requests The part no emulator models. The CPS-A requests the 68000's bus (`/BR`, `/BG`, `/BGACK`) at the start of scanlines and runs its pending jobs in a fixed priority order `[die: bus-requests.md]`: | Job | When | Share of a frame | | --- | --- | --- | | WSTROM | after a write to register `24` | 391% | | objects | every line except 239-244 | 1.9% | | row scroll | every line in 15..239 when enabled | 0.3% | | scroll 1 | lines `1 mod 8` in 8..247 | 4.2% | | scroll 2 | lines `0 mod 16` below 240 | 2.1% | | scroll 3 | lines `0 mod 32` below 240, and line -2 | 0.3% | | palette | during vertical blank after a palette base write | 9.2% (1.5% for one section) | The percentages are the author's "rough approximation". jtcps's board measurements `[jt: DMA.md]`: the per-line header lasts 0.60 us with nothing to do, 1.64 us with objects, 2.06 us with objects and row scroll; a scroll 1 refill is 98 transfers (24.5 us at 4 MHz), scroll 2 96 (24 us), scroll 3 24 (6 us). Combining those durations with the die's schedule (computed here, arbitration overhead excluded): objects 256 x 1.64 = 420 us, row scroll 225 x 0.42 = 94 us, scroll 1 30 x 24.5 = 735 us, scroll 2 15 x 24 = 360 us, scroll 3 9 x 6 = 54 us: about **1,660 us, 9.9% of a 16,768 us frame** with everything on, and about **14.6%** in a frame that also copies the palette (780 us). That is before the wait states of [memory-map.md](memory-map.md). Clearing a layer's bit in video control gives the time back, which is the only visible effect of those bits on a board. jtcps's loop counter (a count kept by a test program between vblanks) moved by about 8% between its fastest and slowest register settings (`1A67` versus `1833`). A scanline's pulse ends any job still running (the palette copy resumes later).