55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Cross-read tapes recorded by the real BASIC ROM and by the packaged CMOC SDK."""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("runtime", type=Path)
|
|
parser.add_argument("core", type=Path)
|
|
parser.add_argument("roms", type=Path)
|
|
parser.add_argument("--capture", type=Path, help="save the guest's flight replay screen")
|
|
args = parser.parse_args()
|
|
runtime, core, roms = (p.resolve(strict=True) for p in (args.runtime, args.core, args.roms))
|
|
fixture = Path(__file__).resolve().parent
|
|
root = fixture.parents[2]
|
|
lessons = root / "examples/cmoc/manual"
|
|
disk = root / "docs/manuals/software-storage-and-peripherals/media/BLANK.DSK"
|
|
env = dict(os.environ, PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"], VCC_CMOC_COMPAT="1")
|
|
with tempfile.TemporaryDirectory(prefix="vcc-cassette-demo-") as tmp:
|
|
def run(*command):
|
|
subprocess.run(command, cwd=tmp, env=env, check=True)
|
|
|
|
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
|
"-I", root / "src", fixture / "run.cpp", core, "-o", "run")
|
|
card = Path(tmp) / "card"
|
|
card.mkdir()
|
|
practice = card / "VOL.DSK"
|
|
shutil.copyfile(disk, practice)
|
|
(card / "startup.cfg").write_text("0=VOL.DSK\n")
|
|
for opt in ("-O0", "-O2"):
|
|
for source, binary in ((lessons / "flightrecorder.c", "FLIGHT.BIN"),
|
|
(fixture / "qualification.c", "QUAL.BIN")):
|
|
run(runtime / "bin/cmoc", "--coco", opt, "-Werror", "--org=2800",
|
|
"-o", binary, source, "-lvcccompat")
|
|
for cpu in ("6809", "6309"):
|
|
starter = root / "platforms/macos/Resources/StarterMedia/Hello World.cas"
|
|
run("./run", roms, practice, cpu, lessons, starter, "disk")
|
|
if opt == "-O2":
|
|
for setup in ("wav", "rgb-hd", "sdc"):
|
|
run("./run", roms, practice, cpu, lessons, starter, setup)
|
|
print(f"PASS {cpu} {opt} {setup}: recorded in C and read in BASIC, and vice versa", flush=True)
|
|
if args.capture and (cpu, opt) == ("6809", "-O2"):
|
|
run("sips", "-s", "format", "png", "flight.ppm", "--out", args.capture.resolve())
|
|
print(f"PASS {cpu} {opt}: BASIC/C cassette exchange, empty files, cross-block records and damaged tapes",
|
|
flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|