# SPDX-License-Identifier: MIT """``python -m a7800_python ROM --frames N --png out.png``: run a cartridge headless. Loads ROM through the one loader (prints its description and provenance), starts it through the BIOS found by hash (or ``--direct``, labelled "BIOS skipped"), runs N frames and writes the last frame as a PNG (placeholder palette, television.py). ``--wav`` writes the mixed sound of the whole run (sound.py: the TIA and any cartridge POKEY; the mix is a fit, U15). """ from __future__ import annotations import argparse import sys import time from pathlib import Path from .cartridge import formats from .machine import MACHINES, NTSC from .sound import SoundTap, tia_rate, wav_bytes from .system import System from .television import Television, frame_png def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(prog="a7800-python", description=__doc__.split("\n\n")[0]) parser.add_argument("rom", type=Path) parser.add_argument("--frames", type=int, default=300) parser.add_argument("--png", type=Path) parser.add_argument("--wav", type=Path, help="the mixed sound, 16-bit mono (sound.py)") parser.add_argument("--direct", action="store_true", help="start without a BIOS (labelled)") parser.add_argument("--machine", choices=sorted(MACHINES), default=NTSC.name) parser.add_argument("--as", dest="override", help="hardware words, e.g. supergame,ram@4000") parser.add_argument("--trust", choices=("header", "table")) args = parser.parse_args(argv) overrides = formats.parse_as(args.override) if args.override else None desc = formats.load(args.rom, overrides=overrides, trust=args.trust) print(f"{args.rom.name}: {desc.summary()} sha256 {desc.sha256}") for note in desc.notes: print(f" note: {note}") if desc.console != "7800": print("a 2600 dump: 2600 mode is milestone 6", file=sys.stderr) return 2 system = System(formats.build(desc), MACHINES[args.machine], start="direct" if args.direct else "bios", description=desc) # fmt: skip tv = Television(system.board.maria, keep=1) tap = SoundTap(system.board, keep_streams=False).attach() if args.wav else None began = time.monotonic() system.run_frames(args.frames) wall = time.monotonic() - began print(f"{args.frames} frames in {wall:.1f} s ({args.frames / wall:.2f} frames/s); " f"{system.bios_name}; mode {system.mode}") # fmt: skip if args.png and tv.frames: args.png.write_bytes(frame_png(tv.frames[-1])) print(f"wrote {args.png}") if tap is not None: samples = tap.take() args.wav.write_bytes(wav_bytes(samples, tia_rate(system.machine))) print(f"wrote {args.wav}: {len(samples):,} samples, TIA + {len(tap.pokeys)} POKEY " f"(mix: a fit, U15)") # fmt: skip return 0 if __name__ == "__main__": sys.exit(main())