"""Disassemble a stretch of a Galaga CPU's ROM (main, sub or sound) with the z80-python disassembler. Usage: python3 tools/z80dis.py main 0x0030 20""" import os import sys # z80-python: Z80_PYTHON_SRC, else a checkout beside this repository. _repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.environ.get("Z80_PYTHON_SRC", os.path.join(os.path.dirname(_repo), "z80-python", "src"))) import z80_python.disasm as d FILES = {"main": ("gg1_1b.3p", "gg1_2b.3m", "gg1_3.2m", "gg1_4b.2l"), "sub": ("gg1_5b.3f",), "sound": ("gg1_7b.2c",)} cpu, start, count = sys.argv[1], int(sys.argv[2], 16), int(sys.argv[3]) rom = b"".join(open(os.path.join("rom/galaga", f), "rb").read() for f in FILES[cpu]) pc = start for _ in range(count): ins = d.disassemble(lambda a: rom[a] if a < len(rom) else 0, pc) n = getattr(ins, "size", None) or len(getattr(ins, "bytes", b"")) or 1 text = getattr(ins, "text", None) or str(ins) print(f"{pc:04x}: {rom[pc:pc + n].hex(' '):14s} {text}") pc += n