#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Write src/colours.inc: every colour the game uses, NTSC value and PAL value. The NTSC values are chosen by eye. Each PAL value is the PAL register value whose colour is nearest (in RGB) to the NTSC colour, both read from the palettes of our board (a2600-python's palettes, MAME 0.285's BSD-3 tables), dumped by `tools/harness palettes` into tools/palettes.txt. Run by scripts/build.sh. """ import os HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.join(HERE, "..") NTSC = { "BLACK": 0x00, "SCORE1": 0x1E, "SCORE2": 0x9E, "PIPS": 0x0E, "FLOORMK": 0x3A, "BG0": 0x80, "BG1": 0x50, "BG2": 0x40, "WALL0": 0x0C, "WALL1": 0x0C, "WALL2": 0x0C, "ROW0": 0x46, "ROW1": 0x38, "ROW2": 0x1C, "ROW3": 0xC8, "ROW4": 0x8A, "ROW5": 0x5A, "DROP": 0x1E, "BUMP": 0x9C, "FLASH": 0x0E, "BAT": 0x0E, "BATK": 0x1E, "BAL0A": 0x46, "BAL0B": 0x1E, "BAL1A": 0x86, "BAL1B": 0xC8, "BAL2A": 0x5C, "BAL2B": 0x2A, # the ball's power (2026-11-23), as the ball and wall colour on the middle and top # floors: grey (WALL) when slow, yellow, orange, then blue-white when it punches # through balloons (a flame's order, hotter to the right; our own choice) "POW1": 0x1C, "POW2": 0x3C, "POW3": 0x9E, "ROOFA": 0x44, "ROOFB": 0x0E, "CL_RED": 0x44, "CL_YELLOW": 0x1C, "CL_SKIN": 0x3C, "CL_WHITE": 0x0E, "CL_BLUE": 0x86, "CL_GREEN": 0xC6, "TITLE1": 0x46, "TITLE2": 0x1E, "TITLE3": 0x9C, "TITLE4": 0x5C, "TBG": 0x00, "TEXT": 0x0E, } def load_palettes(): path = os.path.join(ROOT, "tools", "palettes.txt") pals = {} if not os.path.exists(path): return None for line in open(path): name, idx, r, g, b = line.split() pals.setdefault(name, {})[int(idx)] = (int(r), int(g), int(b)) return pals def nearest_pal(pals, v): # palette entries are indexed by register value >> 1 target = pals["ntsc"][v >> 1] best = None for i in range(128): c = pals["pal"][i] d = sum((a - b) ** 2 for a, b in zip(c, target)) if best is None or d < best[0]: best = (d, i * 2) return best[1] def main(): pals = load_palettes() if pals is None: raise SystemExit("tools/palettes.txt missing: run `bigtop-harness palettes` first") out = ["; SPDX-License-Identifier: MIT", "; Generated by scripts/colours.py: do not edit. NTSC by eye; PAL nearest in RGB", "; within the board's palettes (MAME 0.285 tables via a2600-python, BSD-3).", ".ifdef PALCOL"] for k, v in NTSC.items(): p = nearest_pal(pals, v) if pals else v out.append(f"C_{k} = ${p:02X}") out.append(".else") for k, v in NTSC.items(): out.append(f"C_{k} = ${v:02X}") out.append(".endif") open(os.path.join(ROOT, "src", "colours.inc"), "w").write("\n".join(out) + "\n") if __name__ == "__main__": main()