# Graphics ROMs and the B-board mapper PAL ## What the hardware does The CPS-A drives a 23-bit graphics-ROM address `ROMA22-0` ([cps-a.md](cps-a.md)): `ROMA22-20` name the layer (`000` sprites, `001` scroll 1, `010` scroll 2, `011` scroll 3, `100` stars), the rest is the tile code and row. The ROMs on the B-board are organised as four byte lanes read together (64 bits: 16 pixels of 4 bits), half of which the C-board selects per fetch `[mame: cps1_v.cpp notes]`, `[die: graphics-rom-layout.md]`. MAME loads them with `ROM_LOAD64_WORD`: four 16-bit-wide ROMs interleaved word by word into one 64-bit-wide region. **Which ROM bank answers is decided by one PAL on the B-board, at socket 1A**, from the top of `ROMA`. It pulls a chip-enable low for one bank group, or for none: then no ROM drives the bus, pull-ups read all ones, and every pixel is **pen 15, transparent** `[mame]`. Games do ask for tiles outside their ranges (MAME: "many games contain bugs which make them try to display out of range tiles"), so this masking is visible behaviour, not bookkeeping. The same PAL also makes one tile code mean different ROM data for different layers: e.g. Final Fight's sprite code `0x2000` and scroll 2 code `0x2000` (MAME's units, below) are different ROM addresses. Because the PAL differs per game (its name is the B-board's: `S224B`, `CA24B`, `S9263B`, ...), the mapper is per-set data. MAME 0.285 defines 58 mapper tables (`scripts/mapper_table.py`), 53 of them used by the Capcom and Changer sets (census). 53 tables say "verified from PAL dump" or "from JED"; `gulunpa` says "TODO: guesswork"; `PKB10B` (pnickj) and `pokonyan` state nothing; `varthb2` and `cps2` are bootleg and CPS-2 helpers. **MAME's unit**: `gfxrom_bank_mapper` shifts the tile code by 1 (sprites, scroll 2), 0 (scroll 1) or 3 (scroll 3) before comparing it with the table; in every case the compared value is `ROMA19-3` (checked against the address layouts in [cps-a.md](cps-a.md)). One table therefore covers all layers, and a range boundary of `0x80` in MAME's units is one step of `ROMA10`. ## The judge: the fuse map in the ROM set The MAME ROM sets carry the B-board PALs as 279-byte files: a 4-byte big-endian fuse count (`0x892` = 2,194, a GAL16V8) and the fuses, eight to a byte, fuse 0 in bit 0 (checked by decoding them). Census: **166 of the 168 Capcom and Changer sets carry at least one fuse map**; 8 sets list an undumped mapper PAL (`cworld2ja`, `cworld2jb`, `dynwarjr`, `mercsj`, `pnickj`, `sf2en`, `striderjr`, `striderua`), so those keep MAME's table (or a sibling set's PAL of the same name) until a dump appears. MAME says most dumps are "logically equivalent replacements" (GAL16V8 images of the original PAL16L8/EPL16P8 parts): logically, not electrically, equal; for a board that has only logic it is the same thing. Two scripts were written and run in this phase: - `scripts/decode_gal16v8.py` prints a fuse map's equations. Checked on the A-board: **PRG1 and IOA1 from `sf2ce` decode to exactly the equations MAME quotes** (`cps1.cpp` l.485-580), which fixes the fuse layout, the polarity bits and the simple-mode column order (pins 15 and 16 have no column in simple mode; `S9263B`'s pin 13 feeding its pins 14 and 15, as MAME's comment says, was the check on the column order). - `scripts/check_pal_mapper.py` evaluates a mapper PAL over every `ROMA22-10` with a **pin wiring read off Capcom's schematic**: on the 89624B-3 B-board (the schematic in `reference/`, sheet 3) the 1A part is an EPL16P8 with pin 1 `ROMOEB`, pins 2-8 `ROMA22-16`, pin 9 `ROMA14`, pin 11 `ROMA15`, pin 13 `ROMA13`, 15 `ROMA12`, 17 `ROMA11`, 18 `ROMA10`, outputs 19, 16, 14, 12 to `/CE1-4`. **Result** (run here, sets from the local non-merged tree): for **all ten 89624B-3 mappers tried** (`CA24B` cawing, `MS24B` msword, `WL24B` willow, `RT24B` 3wonders, `S224B` ffight, `NM24B` nemo, `VA24B` varth, `CK24B` mtwins, `YI24B` 1941, `O224B` mercs) **the set of codes that enable any ROM, per layer, is identical to MAME's table, boundary for boundary** (e.g. `S224B`: sprites `0000-43FF`, scroll 1 `4400-4BFF`, scroll 3 `4C00-5FFF`, scroll 2 `6000-7FFF`). Swapping pins 9 and 11 (the hand-drawn labels are hard to read) breaks the match, so the drawn order is right. For the single-bank boards the bank-0 enable is pin 16; pins 12 and 14 split it further (which ROM sockets each output reaches is on sheets 4-5, not yet read: U15). On `S9263B` (91635B-2 board) the 89624B-3 wiring gives nonsense, as expected: **the wiring is per B-board type** and each needs its schematic or a trace (U15). So the board can **compute its mapper from the dump** for every set whose B-board wiring is known, with MAME's table as the detector; that is the plan ([handoff-brief.md](handoff-brief.md) M3). B-board types in the census: 88618B-2, 88621B-2, 88620-B, 88622B-2/-3, 89624B-2/-3, 89625B-1, 90629B-2/-3, 91634B-2, 91635B-2, 94916-10 (Pang! 3), and the CPS Changer's. Only the 89624B-3 schematic is in hand. ## Other per-set graphics facts - **Star ROM**: stars read one byte lane at `ROMA` `100 0000 000y xxxx yyyy yyyy` `[die]`; MAME keeps a separate copy of the star data. Only Forgotten Worlds and Strider use stars. - **Kludges in MAME's table** (`bootleg_kludge`) are bootleg-only and out of scope. - **Graphics ROM sizes** per parent are in [census.md](census.md) (1-8 MiB). - **Pang! 3** has a different B-board (94916-10, Mitchell's design) with PALs `CP1B1F` (mapper), `CP1B8K` (Mach215 range), `CP1B9K` (encryption range) `[mame]`.