#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Which PlayStation BIOS and CD-controller firmware images do we have? SHA-1s only. Looks in MAME's romsets ($MAME_ROMPATH: psj.zip, which holds the psu/pse/psa clones in sub-folders, and psx_cd.zip) and in a loose BIOS folder ($PSX_BIOS_DIR: files such as scph1001.bin), hashes every candidate in place (zip members are read, never extracted), and matches the hashes against the SHA-1 list below. Nothing is copied anywhere. MAME_ROMPATH=... PSX_BIOS_DIR=... python -I scripts/census_bios.py The SHA-1 list is fact data, not firmware: it was taken from `mame -listxml psj psu pse psa` (MAME 0.285; the rom tags of sony/psx.cpp and sony/psxcd.cpp), as recorded in docs/bios.md. MAME's driver labels the BIOS sets by version and model. """ from __future__ import annotations import hashlib import os import sys import zipfile from pathlib import Path # SHA-1 -> (MAME bios set, MAME description). OBSERVED: mame -listxml, MAME 0.285. KNOWN = { "343883a7b555646da8cee54aadd2795b6e7dd070": ("1.0j", "SCPH-1000/DTL-H1000"), "b06f4a861f74270be819aa2a07db8d0563a7cc4e": ("1.1j", "SCPH-3000/DTL-H1000H (v1.1 01/22/95)"), "e38466a4ba8005fba7e9e3c7b9efeba7205bee3f": ("2.1j", "SCPH-3500 (v2.1 07/17/95 J)"), "ffa7f9a7fb19d773a0c3985a541c8e5623d2c30d": ("2.2j", "SCPH-5000/DTL-H1200/DTL-H3000 (v2.2 12/04/95 J)"), "73107d468fc7cb1d2c5b18b269715dd889ecef06": ("2.2d", "DTL-H1100 (v2.2 03/06/96 D)"), "b05def971d8ec59f346f2d9ac21fb742e3eb6917": ("3.0j", "SCPH-5500 (v3.0 09/09/96 J)"), "77b10118d21ac7ffa9b35f9c4fd814da240eb3e9": ("4.0j", "SCPH-7000/7500/9000 (v4.0 08/18/97 J)"), "1b0dbdb23da9dc0776aac58d0755dc80fea20975": ("4.1a(w)", "SCPH-7000W (v4.1 11/14/97 A)"), "339a48f4fcf63e10b5b867b8c93cfd40945faf6c": ("4.3j", "SCPH-100 (v4.3 03/11/00 J)"), "649895efd79d14790eabb362e94eb0622093dfb9": ("2.0a", "DTL-H1001 (v2.0 05/07/95 A)"), "ca7af30b50d9756cbd764640126c454cff658479": ("2.1a", "DTL-H1101 (v2.1 07/17/95 A)"), "10155d8d6e6e832d6ea66db9bc098321fb5e8ebf": ("2.2a", "SCPH-1001/DTL-H1201/DTL-H3001 (v2.2 12/04/95 A)"), "0555c6fae8906f3f09baf5988f00e55f88e9f30b": ("3.0a", "SCPH-5501/5503/7003 (v3.0 11/18/96 A)"), "14df4f6c1e367ce097c11deae21566b4fe5647a9": ("4.1a", "SCPH-7001/7501/7503/9001/9003/9903 (v4.1 12/16/97 A)"), "dcffe16bd90a723499ad46c641424981338d8378": ("4.5a", "SCPH-101 (v4.5 05/25/00 A)"), "20b98f3d80f11cbf5a7bfd0779b0e63760ecc62c": ("2.0e", "DTL-H1002/SCPH-1002 (v2.0 05/10/95 E)"), "76cf6b1b2a7c571a6ad07f2bac0db6cd8f71e2cc": ("2.1e", "SCPH-1002/DTL-H1102 (v2.1 07/17/95 E)"), "b6a11579caef3875504fcf3831b8e3922746df2c": ("2.2e", "SCPH-1002/DTL-H1202/DTL-H3002 (v2.2 12/04/95 E)"), "f6bc2d1f5eb6593de7d089c425ac681d6fffd3f0": ("3.0e", "SCPH-5502/5552 (v3.0 01/06/97 E)"), "8d5de56a79954f29e9006929ba3fed9b6a418c1d": ("4.1e", "SCPH-7002/7502/9002 (v4.1 12/16/97 E)"), "beb0ac693c0dc26daf5665b3314db81480fa5c7c": ("4.4e", "SCPH-102 (v4.4 03/24/00 E)"), "dbc7339e5d85827c095764fc077b41f78fd2ecae": ("4.5e", "SCPH-102 (v4.5 05/25/00 E)"), # CD controller (HC05) firmware, MAME device psx_cd (region cdrom_mcu). "095434948d4c71cdfaa069e91053443887a6d139": ("cd 424660", "SCPH-1000 NTSC:J (later)"), "80674353daf95ffb4bd15cc4bb8cfa713370dd45": ("cd 424666", "SCPH-1000 NTSC:J (early)"), "9b06b1d407b784095ddbd45aeabafd689d2ee347": ("cd 424684", "SCPH-1002 PAL (early PU-8)"), "0ae8348fb43ab80845b0166494edc3e1565a3ef7": ("cd sc430916", "SCPH-5000 NTSC:J"), "b9ad66cc8ea4d6e2eb2709ffb77c9647f679097a": ("cd sc430925", "SCPH-5500 NTSC:J"), "556c3adc37e4eb64fd463c54f7a310c483e0e835": ("cd sc430930", "SCPH-5501 NTSC:U/C"), "f23458d13a518616a8592b8ddd668c052bc9be5a": ("cd sc430929", "SCPH-5502 PAL"), "ac72cb616b1449fe29e52faf6aad389118852d73": ("cd sc430924", "SCPH-5903 NTSC:J (Video CD)"), "d9734c7135c75dbe7733079a2d4244a28c9e966e": ("cd sc430934", "SCPH-7000 NTSC:J"), "f017d34a98a8a023f6752ba9ed749bb9e2b836d5": ("cd sc430938", "SCPH-7500 NTSC:J"), "e72b5093a3e25de1548be7668179ff3e001e3ec5": ("cd sc430940", "SCPH-7501 NTSC:U/C"), "25d98454e567e064c06f840d57f763fb7c8b7219": ("cd sc430939", "SCPH-7502 PAL"), "db72ba02466942d1a1a07c4d855edd18f84de92e": ("cd sc430944", "SCPH-9001 NTSC:U/C"), "62999e7f8429f381e19d44d2399b6017959f4f13": ("cd sc430943", "SCPH-9002 PAL"), "6fe45fd6fb96b12a25a45f39b5efd0be5e3f3e86": ("cd sc430920", "DTL-H1202 PAL"), } def candidates() -> list[tuple[str, bytes]]: found: list[tuple[str, bytes]] = [] mame = os.environ.get("MAME_ROMPATH") if mame: for folder in mame.split(os.pathsep): for name in ("psj.zip", "psx_cd.zip"): path = Path(folder) / name if path.is_file(): with zipfile.ZipFile(path) as archive: for member in archive.infolist(): found.append((f"$MAME_ROMPATH/{name}:{member.filename}", archive.read(member))) loose = os.environ.get("PSX_BIOS_DIR") if loose: for path in sorted(Path(loose).iterdir()): # A mixed emulator BIOS folder: only 512 KiB files named like a PlayStation BIOS. plausible = path.name.lower().startswith(("scph", "ps", "dtl")) if plausible and path.is_file() and path.stat().st_size == 512 * 1024: found.append((f"$PSX_BIOS_DIR/{path.name}", path.read_bytes())) return found def main() -> int: seen: dict[str, list[str]] = {} unknown = [] for label, data in candidates(): digest = hashlib.sha1(data).hexdigest() if digest in KNOWN: if label not in seen.setdefault(digest, []): seen[digest].append(label) else: unknown.append((label, len(data), digest)) print(f"{'set':12} {'have':4} sha1 description / where") for digest, (key, description) in KNOWN.items(): where = seen.get(digest, []) print(f"{key:12} {'yes' if where else 'NO':4} {digest} {description}") for label in where: print(f"{'':17}{'':41}{label}") if unknown: print("\nnot in the list (hash, size, where):") for label, size, digest in unknown: print(f" {digest} {size:8} {label}") return 0 if __name__ == "__main__": sys.exit(main())