#!/usr/bin/env python3 """src/boards.tsv: MAME's software list, cut down to what a browser needs. The board finds a cartridge's mapper, EEPROM or battery by the image's SHA-1 in MAME's megadriv.xml, which a page has no file of. A plain ROM needs no entry (the board then reads the header, as it does for anything unlisted), so this keeps the entries that are something else: SHA-1, slot, sram bytes, name. The rule for which entries count is parse_software_list's in the board. Stdlib only. """ import sys import xml.etree.ElementTree as ET table = {} for software in ET.parse("/usr/share/games/mame/hash/megadriv.xml").getroot().findall("software"): for part in software.findall("part"): slot, sram = "rom", 0 for feature in part.findall("feature"): if feature.get("name") == "slot": slot = feature.get("value", "rom") for area in part.findall("dataarea"): if area.get("name") == "sram": sram = int(area.get("size", "0"), 0) roms = [r.get("sha1") for r in part.iter("rom") if r.get("sha1")] if not (len(roms) == 1 or (roms and slot != "rom")) or (slot == "rom" and not sram): continue entry = (slot, sram, software.get("name", "")) if len(roms) == 1: table[roms[0]] = entry else: table.setdefault(roms[0], entry) for sha1, (slot, sram, name) in sorted(table.items()): sys.stdout.write(f"{sha1}\t{slot}\t{sram}\t{name}\n")