73 lines
4.1 KiB
Python
73 lines
4.1 KiB
Python
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Qualify the editable Planet Atlas on three Disk BASIC storage setups."""
|
|
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 Mars trip as a PNG and the input example alongside it with an -input suffix")
|
|
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]
|
|
blank = root / "docs/manuals/software-storage-and-peripherals/media/BLANK.DSK"
|
|
source = root / "examples/cmoc/manual/atlas.c"
|
|
env = dict(os.environ, VCC_CMOC_COMPAT="1", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
|
|
cards = [b"MERCURY: CRATERS", b"VENUS: CLOUDS", b"EARTH: BLUE SEA", b"MARS: RED RIDGE"]
|
|
original = b"".join(card.ljust(24, b"\x00") for card in cards)
|
|
with tempfile.TemporaryDirectory(prefix="vcc-planet-atlas-") as tmp:
|
|
work = Path(tmp)
|
|
|
|
def run(*cmd, **kwargs):
|
|
return subprocess.run(cmd, cwd=work, env=env, check=True, **kwargs)
|
|
|
|
# Earth and an extra Jupiter card surround the edited Mars record.
|
|
edited = original[:72] + b"MARS: DUST STORM".ljust(24, b"\x00") + b"JUPITER: STORM".ljust(24, b"\x00")
|
|
full = original[:72] + b"X" * 24
|
|
for disk, atlas in (("seed.dsk", edited), ("short.dsk", original[:80]), ("full.dsk", full)):
|
|
shutil.copyfile(blank, work / disk)
|
|
(work / "ATLAS.DAT").write_bytes(atlas)
|
|
run(runtime / "bin/writecocofile", "--binary", disk, "ATLAS.DAT")
|
|
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
|
"-I", root / "src", fixture / "run.cpp", core, "-o", "run")
|
|
for opt in ("-O0", "-O2"):
|
|
run(runtime / "bin/cmoc", "--coco", opt, "-Werror", "--org=2800",
|
|
"-o", "ATLAS.BIN", source, "-lvcccompat", "-ldecbfile")
|
|
shutil.copyfile(work / "seed.dsk", work / "launch.dsk")
|
|
run(runtime / "bin/writecocofile", "launch.dsk", "ATLAS.BIN")
|
|
for cpu in ("6809", "6309"):
|
|
for profile in ("disk", "rgb-hd", "sdc"):
|
|
for folder, disk in (("blank", blank), ("edited", work / "launch.dsk"),
|
|
("short", work / "short.dsk"), ("full", work / "full.dsk")):
|
|
(work / folder).mkdir(exist_ok=True)
|
|
shutil.copyfile(disk, work / folder / "VOL.DSK")
|
|
(work / folder / "startup.cfg").write_text("0=VOL.DSK\n")
|
|
capture = args.capture and (cpu, opt, profile) == ("6809", "-O2", "disk")
|
|
run("./run", roms, "ATLAS.BIN", cpu, profile, "capture" if capture else "check")
|
|
for name, before in (("saved", original), ("edited", edited)):
|
|
actual = run(runtime / "bin/writecocofile", "--stdout", name + "-atlas.dsk", "ATLAS.DAT",
|
|
stdout=subprocess.PIPE).stdout
|
|
expected = bytearray(before)
|
|
expected[95] = ord("V")
|
|
if actual != expected:
|
|
raise AssertionError(f"{cpu} {opt} {profile}: unexpected {name} atlas contents")
|
|
if capture:
|
|
destination = args.capture.resolve()
|
|
for suffix in ("", "-input"):
|
|
run("sips", "-s", "format", "png", f"atlas{suffix}.ppm", "--out",
|
|
destination.with_stem(destination.stem + suffix))
|
|
print(f"PASS {cpu} {opt} {profile}: persisted visit, protected refusal, preserved records, "
|
|
"numeric choices, disk launch and BASIC return", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|