#!/usr/bin/env python3 """Evaluate a B-board graphics-mapper PAL from its fuse map and print its ranges. The 1A PAL on a B-board sees the top of the CPS-A's graphics-ROM address (ROMA22-20 = layer type, ROMA19 down = tile code) and pulls one chip-enable low per ROM bank, or none (pull-ups: pen 15, transparent). This script evaluates the fuse map (a GAL16V8 image, see decode_gal16v8.py) for every input value with ROMOEB low and prints, per layer type and per output pin, the code ranges in MAME's units, so they can be compared with MAME's ``mapper_*`` tables (scripts/mapper_table.py). MAME's range value is ROMA19..3 for every type (code << shift in ``gfxrom_bank_mapper``), which is why one table covers all. The pin wiring is board data. ``--wiring 89624B-3`` is read off Capcom's 89624B-3 B-board schematic (sheet 3, the EPL16P8 at 1A): pin 1 ROMOEB, pins 2-8 ROMA22-16, pin 9 ROMA14, pin 11 ROMA15 (as drawn), outputs 19, 16, 14, 12. Other boards are unknown until their schematics are read (docs/gfx-mapping.md). python -I scripts/check_pal_mapper.py SET.zip MEMBER [--wiring 89624B-3] """ from __future__ import annotations import argparse import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from decode_gal16v8 import COMPLEX, OUTPUTS, REGISTERED, SIMPLE, fuses, load # noqa: E402 WIRINGS = { # pin -> signal name; ROMOEB is held low (an active fetch). "89624B-3": {1: "ROMOEB", 2: "A22", 3: "A21", 4: "A20", 5: "A19", 6: "A18", 7: "A17", 8: "A16", 9: "A14", 11: "A15", 13: "A13", 15: "A12", 17: "A11", 18: "A10"}, "89624B-3-swapped": {1: "ROMOEB", 2: "A22", 3: "A21", 4: "A20", 5: "A19", 6: "A18", 7: "A17", 8: "A16", 9: "A15", 11: "A14", 13: "A13", 15: "A12", 17: "A11", 18: "A10"}, } TYPES = {0: "SPRITES", 1: "SCROLL1", 2: "SCROLL2", 3: "SCROLL3", 4: "STARS"} def build(f: list[int]): syn, ac0 = f[2192], f[2193] mode = {(1, 0): SIMPLE, (1, 1): COMPLEX, (0, 1): REGISTERED}[(syn, ac0)] outs = {} for k, pin in enumerate(OUTPUTS): rows = [] first = k * 8 + (1 if (syn, ac0) == (1, 1) else 0) for r in range(first, k * 8 + 8): if not f[2128 + r]: continue row = f[r * 32 : r * 32 + 32] rows.append([(mode[c], row[2 * c], row[2 * c + 1]) for c in range(16)]) outs[pin] = (f[2048 + k], f[2120 + k], rows) return outs def evaluate(outs, pins: dict[int, int]) -> dict[int, int]: result = {} for pin, (xor, ac1, rows) in outs.items(): if not rows: continue # an input pin, or an output with every term disabled value = 0 for row in rows: term = 1 for p, t, n in row: level = pins.get(p, 1) if (t == 0 and not level) or (n == 0 and level): term = 0 break if term: value = 1 break result[pin] = value if xor else 1 - value return result def main(argv: list[str]) -> int: ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) ap.add_argument("source", nargs="+") ap.add_argument("--wiring", default="89624B-3", choices=sorted(WIRINGS)) args = ap.parse_args(argv) outs = build(fuses(load(args.source))) wiring = WIRINGS[args.wiring] used = [p for p in OUTPUTS if outs[p][2]] for t, name in TYPES.items(): spans: dict[int, list[list[int]]] = {} for block in range(0x400): # ROMA19..A10 for this type: 0x80 in MAME's units roma = (t << 20) | (block << 10) pins = {p: (roma >> int(s[1:])) & 1 for p, s in wiring.items() if s != "ROMOEB"} pins[1] = 0 levels = evaluate(outs, pins) low = [p for p in used if levels[p] == 0] v = (roma >> 3) & 0x1FFFF for p in low: s = spans.setdefault(p, []) if s and s[-1][1] + 1 == v: s[-1][1] = v + 0x7F else: s.append([v, v + 0x7F]) for p, s in spans.items(): print(f"{name:<8} pin {p}: " + ", ".join(f"{a:#07x}-{b:#07x}" for a, b in s)) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))