#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Write the opcode table of src/dispatch.rs from the reference's ``_dispatch.OPCODES``. gen_dispatch.py > table.rs.in (run with the reference's interpreter) Prints the 256 ``(Op, Option)`` rows, one per opcode with the reference's comment, to be pasted between the markers in src/dispatch.rs; rung 1's ``check_tables.py`` then holds the two equal on every run. """ from w65c816._dispatch import OPCODES def camel(name: str) -> str: return "".join(part.capitalize() for part in name.split("_")) def main() -> None: with open(__import__("w65c816._dispatch").__file__.replace("__init__.py", "_dispatch.py")) as f: comments = {} for line in f: line = line.strip() if line.startswith("0x") and "#" in line: comments[int(line[:4], 16)] = line.split("#", 1)[1].strip() for opcode in range(256): handler, mode = OPCODES[opcode] mode_text = "None" if mode is None else f"Some(Mode::{camel(mode)})" print(f" (Op::{camel(handler)}, {mode_text}), // {opcode:02X} {comments.get(opcode, '')}") if __name__ == "__main__": main()