# Video: what CPS-2 keeps from CPS-1, every difference, and how to share the code Tags as in [memory-map.md](memory-map.md): `[die]` Loïc Petit's traces (tier 1 by origin, read as documents), `[jt]` jtcps2 HDL (tier 4), `[mame]` MAME 0.285 (tier 5). The CPS-1 side is documented by the cps1-python Phase 0 (`../cps1-python/docs/cps-a.md`, `memory-map.md`, drafts when read on 2026-11-12); register meanings are not repeated here. ## What is the same chip doing the same job The A-board carries **the same CPS-A-01 (DL-0311) and CPS-B-21 (DL-0921)** as CPS-1 boards `[die]` `DLs/README.md`. On CPS-2 they do the tile layers, the palette and the timing: - **Scroll 1/2/3** (8x8, 16x16, 32x32 tiles), row scroll on scroll 2, the base and scroll registers at `804100+` (`800100+` mirror): the CPS-1 register set, unchanged `[die]` `DL-0311/doc/vram.md` ("they kept the same tilemap layers"). - **Palette copy** from graphics RAM to palette RAM on a write to the palette base, page bits in CPS-B `+30` (bit 0 objects `000-1FF`, 1-3 scroll 1-3, 4-5 stars) `[die]` `DL-0921/doc/palette-copy.md`; on CPS-2 the copy is also driven by the PAL BGSA5. Same 16-bit colour word format (`DL-0311/doc/wstlut.md`, "in the case of the CPS-1 and CPS-2"). - **Timing**: 16 MHz crystal, 8 MHz pixel clock, 512 x 262, 384 x 224 visible, sync from the CPS-B; MAME `set_raw(8 MHz, 512, 64, 448, 262, 16, 240)` for both. The frame-rate figures and their origins are tabled in cps1-python's `cps-a.md`; MAME's CPS-2 notes add "VSync 59.6388 Hz, HSync 15.4445 kHz" with no stated origin. - **CPS-B-21 in its default (battery-less) mode**: ID at `+32`, layer control `+26`, priority masks `+28-2E`, palette control `+30`, layer enables bits 1-3 (scrolls) and 4-5 (stars) `[die]` `DL-0921/doc/configuration-key.md`, `security-scheme.md` ("This is the mode that the CPS2 runs on"); MAME's `CPS_B_21_DEF`, **which two CPS-1 games also use** (`pang3`, `daimakair`). So the default-mode B-21 is not CPS-2-specific. ## Every difference from CPS-1 | # | Subject | CPS-1 | CPS-2 | Source | | --- | --- | --- | --- | --- | | D1 | **Object engine** | CPS-A fetches the object list from graphics RAM (WSTOBJ bus requests) into the VRAM frame buffer; CPS-B decodes and mixes it | **Not the CPS-A/CPS-B at all.** "On the CPS-2, the designers decided that they needed another sprite engine": the CPS-A/CPS-B VRAM ports are unplugged; objects are managed by DL-1525 on the B-board and drawn through a frame buffer (2 x HM514260, 512 x 512 x 16, top 4 bits unused) controlled by DL-1625 / DL-2227, which also add "an additional composition on top of the CPS-B". **DL-1525, DL-1625, DL-2227 are 0 % reversed** | `[die]` `DL-0311/doc/vram.md`, `DL-0921/doc/layer-assembly.md` ("NOT handled by the B-21 at all ... still unclear how it injects") | | D2 | Object list storage | in graphics RAM at the CPS-A `+00` base, 256 entries (`0x800` bytes), buffered one frame | **separate object RAM** on the B-board, 2 x 8 KiB banks (1,024 entries of 4 words each), `700000` / `708000`, swapped by `8040E0` bit 0; CPS-A `+00` unused | `[mame]` `video_start`, `cps2_objram*`; `[die]` DL-1827; `[mad]` | | D3 | When the list is taken | MAME copies the list at vblank and draws it next frame (`cps1_objram_latch`, "sprites have to be delayed one frame") | MAME copies the active bank and the priority register at vblank (`cps2_objram_latch`) and draws them in the next frame's render. jtcps2 latches the priority register on the vblank edge (`jtcps2_colmix.v`). Giga Wing's sprites are one frame out in MAME (known problem) | `[mame]`, `[jt]` | | D4 | Object word layout | x, y, code, attributes; end marker attribute `FF00`-`FFFF` | x bits 15-13 = **priority** (0-7), y bits 14-13 = **code bits 17-16**; attribute bit 7 = add the X/Y offset registers; end at y >= `8000` **or** attribute >= `FF00`; block (multi-tile) size in attribute bits 8-15 as on CPS-1; 5-bit colour | `[mame]` `cps2_render_sprites`, `find_last_sprite` | | D5 | Object output registers | none | `400000-40000B`: `+4` layer priorities (three 4-bit fields used against layer numbers), `+8`/`+A` X/Y offsets (`0040`, `0010`), `+0`, `+2`, `+6` unknown. Key word 7 (`0x4000`) is "bits 8 to 23 of CPS2 object output address" per MAME, so the address `$400000` itself comes from the key RAM | `[mame]` | | D6 | **Priority** | layer order from CPS-B layer control (objects one of the four layers) + CPS-B pen-priority masks (`+28-2E`) that let scroll pens pass over objects | **per-object priority** (3 bits) against a priority nibble per scroll layer (`400004`). MAME removes the object layer from the CPS-B order, draws scroll layers whole (never the split "high" layer: the B-21 masks are unused), then objects through computed masks. jtcps2 compares the object priority only with the nibble of the layer that owns the topmost scroll pixel (object wins if strictly greater; a transparent pixel counts as 0, so priority-0 objects never show). The two models differ when layers overlap (C4) | `[mame]` `render_layers`; `[jt]` `jtcps2_colmix.v` | | D7 | **Raster interrupts** | the B-21's raster counters exist but `/OBJUP` goes only to the CPS-A (unused; CPS-1 used vblank only, except Ganbare in MAME) | `/OBJUP` "transmitted to IPL2" (level 4); counters at B-21 `+0E` (column), `+10`, `+12` (lines), readable. Exact behaviour unknown in the die doc; MAME and jtcps2 disagree (C5) | `[die]` `DL-0921/doc/raster-effects.md`; `[mame]` `raster_scanline`; `[jt]` `jtcps2_raster.v` | | D8 | Graphics ROM addressing | a per-game PAL maps each layer's tile range to ROM (MAME `cps1_config_table`, cps1-python's mapper work) | the CPS-A drives only scroll and star addresses, `ROMA[20..22]` ignored; DL-1927 mangles the address ("adding `0b01` on top and shifting bit 17 to bit 0"); objects address the ROM linearly; MAME uses one fixed range (`mapper_cps2`: scroll tiles in the second `0x20000`) and **unshuffles** every `0x200000` bank at load (`cps2_gfx_decode`) | `[die]` `DL-0311/doc/graphics-rom-layout.md`; `[mame]` | | D9 | Background pen | MAME fills with pen `0xBFF` (3 Wonders, Mercs show it) | MAME fills with black: "CPS2 apparently always forces the background to black" (a guess in the comment) | `[mame]` `screen_update_cps1` | | D10 | Stars | some CPS-1 games (Forgotten Worlds, Strider) have a star ROM | **no CPS-2 set has a star ROM** (0 `region="stars"` entries in MAME 0.285 `-listxml` for the 323 sets; measured) though the B-21 still has the enables | measured; `[die]` | | D11 | Bus requests | CPS-A takes the 68000 bus for row scroll, scroll tiles, objects, palette | the same minus objects; and the CPS-A cannot take the bus while the Z80 has released its RAM to the 68000 side | `[die]` `DL-0311/doc/bus-requests.md` | | D12 | CPS-B configuration | about 30 B-chip variants with moved registers, IDs, protection multiplier (cps1-python's `cps-b` work) | only the default-mode B-21 | `[die]`, `[mame]` | | D13 | Wait states | CPS-1: per-board | one wait per access in `000000-4FFFFF` and `800000-FFFFFF` (DL-1827) | `[jt]` from `[die]` | | D14 | Palette entries | `0xC00` in MAME | `0xC00` in MAME (same) | `[mame]` | What this means for the code: **CPS-2 reuses the tile-layer, palette and timing half of the CPS-A/CPS-B, plus the B-21 raster counters that CPS-1 leaves unconnected; it replaces the object half and the final mix with hardware nobody has reversed.** The CPS-2 object engine and mixer are CPS-2's own code whatever is decided below; their judge is tier 4-5 only (jtcps2, MAME), and the games' own test screens. ## How CPS-1 and CPS-2 should share the video code The chip rule: non-CPU chips used by one machine stay in the board; a chip gets its own repository only when another emulator in the family could use it. The CPS-A-01 and CPS-B-21 are used by two family boards from day one, so they qualify. The choice: | Option | Shape | For | Against | | --- | --- | --- | --- | | **A. cps2-python pins cps1-python and imports its video** | cps1-python keeps CPS-A/CPS-B as an import-bounded subpackage; cps2 depends on the whole board at a commit | no new repository; the CPS-1 board exercises more of the chips (B-chip variants, keys, its object path, stars), so it is where they get right first; mirrors how the Sega add-on boards pin the Mega Drive | cps2 inherits cps1's dependency closure (`ym2151-python`, `msm6295-python`, Kabuki, PAL mapper data) for no use; the B-21 raster counters (wired to an IRQ on every CPS-2 game, only on two CPS-1 games, Ganbare and Puchi Monster per cps1-python) live where they are least exercised; every cps1 repin moves cps2's gate; "board pins board" is the add-on pattern, and CPS-2 is not an add-on to CPS-1 | | **B. One repository, two machines** (`cps-python`, packages `cps1`, `cps2`) | one tree, shared video module | trivially shared code; one CI | two boards with different CPUs-in-package, sound and security in one tree; certification and tags of one move the other; against the family's one-board-per-repo shape; would also want CPS-3? (no: different hardware) | | **C. A shared chip repository** (`cps-video-python`, package `cpsvideo`: `CPSA`, `CPSB`, `CPSBConfig`, the palette; the name cps1-python's brief proposes) | the CPS-A-01 and CPS-B-21 (all B-chip configurations, raster counters, palette copy, tile layers, timing) with injection points; cps1-python and cps2-python both pin it | exactly the chip rule; each board pulls only what it uses; the raster counters are tested in the chip repo by directed tests from the die doc; the CPS-1 object path is an option of the chip API that CPS-2 leaves unconnected, as the hardware does (VRAM ports unplugged) | one more repository and pin; needs the chip API settled before either board's video milestone | The injection points a chip package needs, whichever of A or C hosts it (from the differences above): (1) a graphics-ROM address mapper (CPS-1 PAL tables, CPS-2 fixed range + DL-1927 mangling); (2) an object source that may be absent (CPS-1: the CPS-A object fetch + frame buffer; CPS-2: none, objects come from the board); (3) a final mixer the board can replace (CPS-1: CPS-B layer order + pen masks; CPS-2: object priority against `400004`); (4) the B-chip configuration (CPS-2: default mode only); (5) the raster `/OBJUP` output as a line the board wires (CPS-1: to nothing; CPS-2: to IPL2); (6) bus-request accounting reported to the board (stolen 68000 cycles); (7) the background pen policy (D9). **Recommendation: C, staged, which is also cps1-python's recommendation** (its `docs/cps2-sharing.md` and handoff brief, open decision 1, landed 2026-11-12 and read here afterwards): build the CPS-A/CPS-B as `cps1/video/` inside cps1-python first, behind an import boundary enforced by a test that imports it alone; **the day cps2-python starts its first video milestone (M3 here), move it to `cps-video-python` with its history, and both boards pin it.** Until then cps2-python does not import cps1-python at all: its M0-M2 (loader, cipher, CPU, memory map, boot with video off) need no video. Reject B; keep A only as the fallback if Aubrey prefers fewer repositories (the interface is the same, so A to C later is mechanical). The two briefs agree on this; the interface lists match (cps1-python's six points: bus-master callbacks with stolen-time reporting, a `fetch(roma)` ROM callback, a pluggable object-pixel source, a CPS-B configuration row, host-stepped clocking with raster and vblank as wired lines, no board imports; this page adds the replaceable final mixer and the background-pen policy, which the cps1 brief folds into the object source and the CPS-B row). What cps2-python will pass: the default-mode B-21 row, no CPS-A object source, its own object engine and mixer, a `fetch(roma)` with the DL-1927 mangling, and the raster line wired to IPL2. **The CPS-2 object engine and mixer stay in cps2-python** (single machine). ## The CPS-2 object engine as the board must model it (provisional) From `[mame]` with `[jt]` as the second opinion; nothing tier 1-3 exists: - At vblank, latch the bank that is *not* the one mapped read/write at `708000` (MAME's `cps2_objbase`: bank bit 0 clear draws `objram1`, set draws `objram2`, and `708000` always maps the other) and `400004`. - Find the end marker scanning from entry 0, then draw from the last entry back to entry 0. In MAME's `prio_transpen` (`src/emu/drawgfx.cpp`, `drawgfxt.ipp`, read at `mame0285`) every opaque object pixel sets the priority-bitmap pixel to 31 and the mask always includes bit 31, so **the first object drawn at a pixel wins: the highest-numbered entry is on top**, and an object pixel hidden behind a scroll layer **still masks** every later (lower-numbered) object at that pixel, whatever its priority. Whether the hardware's frame buffer behaves this way (one object pixel per position, then the mix) is unknown (U6); jtcps2's object line buffer is the second opinion to read when M3 starts. - Each entry: position plus `400008`/`40000A` offsets when attribute bit 7 is set; MAME adds `64 - X offset`, `16 - Y offset` to every object (`xoffs`, `yoffs`); 10-bit wrap; flips (attribute bits 5, 6); blocks of `(nx+1) x (ny+1)` 16x16 tiles with MAME's "pgear fix" for the tile code wrap in the non-flipped case. - Priority: see D6; implement MAME's mask model first (it is the detector we lockstep against), record jtcps2's as the alternative (C4). - Per-line limits (how many objects or pixels a line can hold), the frame buffer's double buffering and the exact latch moment are **unknown** (U6).