# The CPS-B chip (C-board) and its variants The CPS-B turns graphics-ROM data into pixels: it shifts each layer's ROM bytes out, applies the fine X scroll, mixes the six layers with the priority masks, drives the palette-RAM address, generates the sync and blanking counters, and on the B-21 runs the raster counters and the security logic `[die: DL-0921/doc/*]`. It sits on the C-board (on the first two games' 2-board sets, on the B-board), and the 68000 sees it as 32 word registers in `800140-80017F` (on two SF2 revisions `8001C0-8001FF`: [memory-map.md](memory-map.md)). Tags as in [memory-map.md](memory-map.md). **What changes from game to game is the register map, not the logic.** Every variant has the same functions; which offset each function answers at, which layer-control bit enables which layer, and what the ID register returns differ per chip. The board therefore has **one CPS-B model and one row of data per variant**. ## Two chip families | Family | Marked | Configuration | Has | Lacks | | --- | --- | --- | --- | --- | | DL-0411 | CPS-B-01 to -05, -11 to -18 (13 variants, all used by MAME sets) | hard-wired per die `[die: versions.md]` | layer mixing, priority, palette paging, ID register (all but B-01), multiply (none in MAME's rows) | battery, key, CHECK lock-out, raster counters `[die: versions.md]` | | DL-0921 | CPS-B-21 | a 144-bit key held by a battery, or a built-in default when `SEC-MODE0/1` are high `[die: security-scheme.md]` | everything above, plus multiply, CHECK1/CHECK2 lock-out, three raster counters, ID read counter | | From Three Wonders (1991) on, C-boards carry the B-21; the exception is Varth World/USA (1992, CPS-B-04) `[die: versions.md]`, `[mame: table at the top of cps1_v.cpp]`. On a "suicide" board a dead battery wipes the key and the game shows nothing; MAME's table marks those sets with `*`. **CPS-2's A-board carries the same B-21 running in its default mode** `[die]` ([cps2-sharing.md](cps2-sharing.md)). ## Registers (functions, B-21 default offsets) The default offsets are the B-21's built-in key `[die: configuration-key.md]`; MAME's `CPS_B_21_DEF` row agrees on every field it has. | Default | Function | What | | --- | --- | --- | | `00` `02` | MULT-X, MULT-Y (write) | factors of a 16 x 16 multiply | | `04` `06` | MULT-LSB, MULT-MSB (read) | the 32-bit product, low and high word `[mame]` | | `08` | MULT-TC | named by the die key layout; its function is not described (U12). MAME lists it as "unknown1" | | `0A` | CHECK1 | security check value (below) | | `0C` | CHECK2 | security check value; **a write to CHECK2 triggers the comparison** | | `0E` | RASTER1 | column counter, reset every line; read returns the count (below) | | `10` `12` | RASTER2, RASTER3 | line counters, reset every frame | | `26` | LAYER-CTRL | layer order and enables (below) | | `28` `2A` `2C` `2E` | PRIORITY0-3 | pen masks for tiles over sprites (below) | | `30` | PAL-CTRL | which palette pages a copy writes (below) | | `32` | CPS-ID | read: the chip ID (below) | Only the register offsets are word addresses with bit 0 dropped: the key stores each as five bits `[die]`. `3E` is unused in every key and Cruz's keys point the disabled functions there. MAME returns `FFFF` for any unmodelled read. ## Layer control and priority **LAYER-CTRL** `[die: layer-assembly.md]`, `[mame: register notes]`: | Bits | What | | --- | --- | | 0 | not connected `[die]`. MAME: games set it with row scroll on, but row scroll works without it (Magic Sword board test `[pcb]`) | | 1-5 | enable lines for scroll 1, scroll 2, scroll 3, stars 1, stars 2 **in the default key**; each layer's enable is a 3-bit select (LAYER-D1..D5) of *one* of these bits in the key | | 6-7, 8-9, 10-11, 12-13 | the layer drawn 4th, 3rd, 2nd, 1st (front): 0 sprites, 1 scroll 1, 2 scroll 2, 3 scroll 3 | | 14-15 | not connected; Ghouls'n Ghosts and Quiz Tonosama 2 set them with no effect `[mame]` | Stars are always layers 5 and 6, behind the four selectable ones. The mixer outputs the first layer, front to back, whose pen is not 15 (transparent), with one exception: **a sprite pixel loses to the tile pixel under it when that tile's priority group (attribute bits 7-8) has the tile's pen set in the matching PRIORITY mask** (bit *n* of PRIORITY*k* = pen *n* of a group-*k* tile is in front of sprites) `[die: layer-assembly.md]`. MAME draws the same rule as a two-pass render of the layer directly below sprites. **Layer-enable masks: the die and MAME disagree in form (C2).** The key holds a 3-bit select per layer, so exactly one LAYER-CTRL bit enables each layer. MAME's table has multi-bit masks for several rows (`0x12`, `0x14`, `0x16`, `0x30`, `0x0A`) tested with "any bit set". Decoding Cruz's 13 keys with the die's layout (`scripts/decode_cpsb21_keys.py`) gives, for every multi-bit MAME mask, a single bit that is one of MAME's bits: e.g. Cadillacs (QS2) selects bit 4 for all three scroll layers where MAME has `0x16`; King of Dragons (BT2) bit 4 where MAME has `0x30`. Games set all the bits MAME lists, so the forms agree on what the games do; they differ for a program that sets only one. The board follows the die: one bit per layer. For the DL-0411 chips no key exists and no trace was made; their masks are MAME's (C2). ## Palette control (PAL-CTRL) Bits 0-5 enable the six palette pages (sprites, scroll 1, scroll 2, scroll 3, stars 1, stars 2, `0x200` entries each) `[die: palette-copy.md]`, `[mame]`. **The page quirk**: the CPS-A walks graphics RAM from the palette base without regard to the mask; the CPS-B starts writing at the lowest enabled page, so graphics-RAM page 0 lands in the first enabled palette page, and after that a clear bit skips both a palette page and a RAM page `[die]`. MAME implements exactly that and says bits 0-3 were verified on a Magic Sword board `[mame]` (bits 4-5 "only supposed"). The values games write: `3F` normally; `02`, `0F` during boot in some games `[mame]`. ## CPS-ID Read-only. On the DL-0411 chips a fixed value at a fixed offset per die; on the B-21 a 16-bit value from the key at the key's offset. **Bits 6-9 count how many times the ID has been read** `[die: security-scheme.md]` (3 Wonders masks them out with `FC3F` before comparing with `0800`). MAME returns a constant and has no read counter (C7). Games check it at boot; Final Fight reads `800160` and gets `0004` in the MAME trace run here ([mame-oracle.md](mame-oracle.md)). ## Multiply and the lock-out (B-21 only) `MULT-LSB/MSB` return `MULT-X * MULT-Y` `[mame]`. The CHECK mechanism `[die: security-scheme.md]`: a write to CHECK2 compares the values last written to CHECK1 and CHECK2 with `CHECK1-D` and `CHECK2-D` in the key. On a mismatch a **64-frame timer** starts; when it expires the palette address bus (`LUT`) is disabled for good: a solid colour until power-off, sound and game still running. 3 Wonders writes `CHECK1 = 0x17 * 0x12C + 0x49 = 0x1B3D` and `CHECK2 = 0x0E6B`. A game that never writes CHECK2 never arms it. Consequences for the board: - Cruz's published keys set **CHECK2's address to an unused offset** (`00` or `3E`) and the CHECK data to zero; they were synthesised, not read from chips (the chips cannot be read: "You can't read them from outside, only write"). So **no published key carries a genuine `CHECK*-D`**. - MAME's three "unknown" B-21 registers are MULT-TC, CHECK1 and CHECK2: for 3 Wonders MAME has `06 04 02`; the key gives MULT-TC `06`, CHECK1 `04` and a neutralised CHECK2, and the game code quoted by the die documentation writes CHECK2 at `02`. - The board implements the lock-out (tier 1 by origin) with the CHECK data taken from the game's own code where it is known (3 Wonders) and otherwise disabled, recorded per row (Q6, U13). ## Raster counters (B-21 only) From `[die: raster-effects.md]`, whose author writes "this is still unknown and more work must be done": three down-counters reloaded from their registers; RASTER1 counts columns and reloads every line (its bit 0 is ignored, a clock-speed bit), RASTER2 and RASTER3 count lines and reload every frame; "an unknown behaviour is performed by the MSB"; reading returns the current count; reaching zero pulses `/OBJUP` (pin 57). On CPS-2 `/OBJUP` is the 68000's IPL2. On CPS-1 the die documentation says it goes only to the CPS-A; MAME's notes say later B-boards pass IPL2 to the C-board (connector CNA pin 9) where jumper JP1 joins it to CPS-B-21 pin 57, and that Ganbare! Marine Kun needs it ("HARD ERROR" otherwise) (C8). MAME's model: RASTER2/3 9-bit, reloaded at line 0 or immediately when bit 15 of the write is set, an IPL2 interrupt when one reaches zero, delayed by RASTER1 x 2 pixels. Only Ganbare and Puchi Monster use it on CPS-1 (MAME machine `ganbare`). Detail is U14. ## The variants: MAME's table as a detector, with the independent evidence per row `cps1_config_table` in `cps1_v.cpp` gives each set a CPS-B row and a mapper. Census ([census.md](census.md)): 26 rows in use by the 168 Capcom and CPS Changer sets. The columns MAME has: ID offset and value; multiply X, Y, LSB, MSB; three unknowns; layer control; four priority masks; palette control; five layer-enable masks. **Evidence other than MAME**: - **K** a Cruz key (tier 3: shifted into real chips, games verified running on them) decoded with the die's layout (tier 1 document). Independent of MAME for every register offset and the layer selects; not for the CHECK data (synthesised). - **G** the game's own program (a manufacturer artefact, tier 2 in effect): any set that boots past its ID check confirms the ID offset and value; the offsets it writes its layer, palette and priority values to confirm those offsets. Seen here only in the two MAME runs (pnickj: layer `26`, palette `30`; ffight: ID `20` read `0004`, layer `2E`, palette `2A`, priority `26 30 28 32`); a systematic scan of all 37 parents' programs is milestone work (M2). - **D** the die's default key (tier 1 document): only `CPS_B_21_DEF`. - **P** a board test quoted by MAME `[pcb]`: named per row. | Row | Chip | Sets | ID offset = value | Layer ctrl | Priority masks | Pal ctrl | Enables (MAME) | Multiply / other | Evidence besides MAME | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | CPS_B_01 | DL-0411 | 18 | none | 26 | 28 2A 2C 2E | 30 | 02 04 08 30 30 | | G; same as the B-21 default, which makes it the template | | CPS_B_02 | DL-0411 | 4 | 20 = 0002 | 2C | 2A 28 26 24 | 22 | 02 04 08 00 00 | | G | | CPS_B_03 | DL-0411 | 6 | 24 = 0003 | 30 | 2E 2C 2A 28 | 26 | 20 10 08 00 00 | | G | | CPS_B_04 | DL-0411 | 8 | 20 = 0004 | 2E | 26 30 28 32 | 2A | 02 04 08 00 00 | | G (ffight, measured here) | | CPS_B_05 | DL-0411 | 9 | 20 = 0005 | 28 | 2A 2C 2E 30 | 32 | 02 08 20 14 14 | | G | | CPS_B_11 | DL-0411 | 4 | 32 = 0401 | 26 | 28 2A 2C 2E | 30 | 08 10 20 00 00 | | G | | CPS_B_12 | DL-0411 | 6 | 20 = 0402 | 2C | 2A 28 26 24 | 22 | 02 04 08 00 00 | | G; MAD has a build for it | | CPS_B_13 | DL-0411 | 7 | 2E = 0403 | 22 | 24 26 28 2A | 2C | 20 02 04 00 00 | | G; P (Magic Sword palette and video-control tests) | | CPS_B_14 | DL-0411 | 3 | 1E = 0404 | 12 | 14 16 18 1A | 1C | 08 20 10 00 00 | | G | | CPS_B_15 | DL-0411 | 7 | 0E = 0405 | 02 | 04 06 08 0A | 0C | 04 02 20 00 00 | | G | | CPS_B_16 | DL-0411 | 4 | 00 = 0406 | 0C | 0A 08 06 04 | 02 | 10 0A 0A 00 00 | | G | | CPS_B_17 | DL-0411 | 11 | 08 = 0407 | 14 | 12 10 0E 0C | 0A | 08 14 02 00 00 | | G; MAME's note: a Strider-on-SF2 conversion board shows the second enable needs `04` | | CPS_B_18 | DL-0411 | 2 | 10 = 0408 | 1C | 1A 18 16 14 | 12 | 10 08 02 00 00 | at `8001C0` (IOB2 PAL) | G | | CPS_B_21_DEF | DL-0921 | 39 | 32 = (counter only) | 26 | 28 2A 2C 2E | 30 | 02 04 08 30 30 | mult 00 02 04 06; unknown1 08 | **D**: every field; MAME's stars mask `30` is two bits where the die has one each (bit 4, bit 5) | | CPS_B_21_BT1 | DL-0921 | 4 | 32 = 0800 | 28 | 26 24 22 20 | 30 | 20 04 08 12 12 | mult 0E 0C 0A 08; 06 04 02 | **K**, and the die's 3 Wonders code example (ID `0800`, CHECK1/2) | | CPS_B_21_BT2 | DL-0921 | 6 | none | 20 | 2E 2C 2A 28 | 30 | 30 08 30 00 00 | mult 1E 1C 1A 18; – 0C 0A | **K** | | CPS_B_21_BT3 | DL-0921 | 5 | none | 20 | 2E 2C 2A 28 | 30 | 20 12 12 00 00 | mult 06 04 02 00; 0E 0C 0A | **K** | | CPS_B_21_BT4 | DL-0921 | 4 | none | 28 | 26 24 22 20 | 30 | 20 10 02 00 00 | mult 06 04 02 00; 1E 1C 1A | **K** | | CPS_B_21_BT5 | DL-0921 | 2 | 32 = – | 20 | 2E 2C 2A 28 | 30 | 20 04 02 00 00 | mult 0E 0C 0A 08; 1E 1C 1A | **K** (Varth Japan) | | CPS_B_21_BT6 | DL-0921 | 2 | none | 20 | 2E 2C 2A 28 | 30 | 20 14 14 00 00 | none | **K** except priority 2-3: the key has `00 00`, MAME `2A 28` (C9) | | CPS_B_21_BT7 | DL-0921 | 1 | none | 2C | – | 12 | 14 02 14 00 00 | none; MAME: "layer enable mask incomplete" | **K** (Quiz & Dragons) | | CPS_B_21_QS1 | DL-0921 | 4 | none | 22 | 24 26 28 2A | 2C | 10 08 04 00 00 | none | **K** (Warriors of Fate) | | CPS_B_21_QS2 | DL-0921 | 3 | none | 0A | 0C 0E 00 02 | 04 | 16 16 16 00 00 | – 2E 20 | **K** (Cadillacs) | | CPS_B_21_QS3 | DL-0921 | 4 | 0E = 0C00 | 12 | 14 16 08 0A | 0C | 04 02 20 00 00 | 2C – – | **K** (Punisher) | | CPS_B_21_QS4 | DL-0921 | 4 | 2E = 0C01 | 16 | 00 02 28 2A | 2C | 04 08 10 00 00 | 1C 1E 08 | **K** (two keys: Slam Masters, Muscle Bomber) | | CPS_B_21_QS5 | DL-0921 | 2 | 1E = 0C02 | 2A | 2C 2E 30 32 | 1C | 04 08 10 00 00 | 0C – – | **K** (Muscle Bomber Duo) | Reading the table: **every B-21 row has an independent witness** (12 battery rows: Cruz's 13 keys; the default: the die). **No DL-0411 row has one besides the games themselves**: no DL-0411 die has been traced, no keys exist for them, and jtcps1's per-game configuration is generated from MAME's table (not independent). The DL-0411 rows are therefore tier 5 data checked only by "the game runs and draws" (G), which the board's milestones make systematic. Per-set extras outside the CPS-B rows, also in `cps1_config_table`: extra inputs `IN2`/`IN3` and an output port `OUT2` read through the CPS-B window but decoded by the C-board's C628/C632 PALs (`36`, `38`, `34`; [inputs.md](inputs.md)); the set list is printed by `scripts/mapper_table.py`.