Files

103 lines
5.3 KiB
Python

# SPDX-License-Identifier: GPL-3.0-or-later
"""Exercise read-only guest streams through three real DOS ROMs on both CPUs."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
def qualification_disk(folder, disk_tool):
folder.mkdir()
disk = folder / "QUAL.DSK"
disk.write_bytes(bytes([255]) * (35 * 18 * 256))
files = {
"LARGE.DAT": b"".join(bytes((i + j) & 255 for j in range(256)) for i in range(257)),
"MIXED.TXT": b"A" * 255 + b"\r\nBETA\rRED\nLAST",
"SHORT.DAT": bytes([0, 255, 1, 2, 3, 4, 5, 6, 7]),
# Allocate distinct real directory entries before preparing boundary cases.
"EMPTY0.DAT": b".", "EMPTY1.DAT": b".", "CYCLE.DAT": b".", "INVALID.DAT": b".",
}
for name, data in files.items():
(folder / name).write_bytes(data)
subprocess.run([disk_tool, "--binary", disk, name], cwd=folder, check=True)
raw = bytearray(disk.read_bytes())
fat = (17 * 18 + 1) * 256
directory = fat + 256
for row in range(directory, directory + 256, 32):
name = raw[row:row + 8].rstrip()
granule = raw[row + 13]
if name in (b"EMPTY0", b"EMPTY1"):
raw[fat + granule] = 0xc0 if name == b"EMPTY0" else 0xc1
raw[row + 14:row + 16] = bytes(2)
elif name == b"INVALID":
raw[row + 14:row + 16] = (257).to_bytes(2, "big")
elif name == b"CYCLE":
raw[fat + granule] = granule
disk.write_bytes(raw)
second = folder / "SECOND.DSK"
second.write_bytes(bytes([255]) * (35 * 18 * 256))
(folder / "SIDE.TXT").write_bytes(b"1")
subprocess.run([disk_tool, second, "SIDE.TXT"], cwd=folder, check=True)
(folder / "startup.cfg").write_text("0=QUAL.DSK\n1=SECOND.DSK\n")
return disk
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path, help="staged Toolchain directory")
parser.add_argument("core", type=Path, help="current libVCCCore.a")
parser.add_argument("roms", type=Path, help="directory containing the privately supplied ROMs")
parser.add_argument("--profile", action="append", choices=("disk", "rgb-hd", "rgb-fd", "sdc"),
help="limit a diagnostic run to this route (repeatable)")
parser.add_argument("--capture", type=Path, help="save the Disk BASIC Mars report as a PNG")
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]
with tempfile.TemporaryDirectory(prefix="vcc-streams-") as tmp:
work = Path(tmp)
env = dict(os.environ, VCC_CMOC_COMPAT="1", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
subprocess.run([runtime / "bin/cmoc", "--coco", "-O2", "-Werror", "--org=2800",
"-o", "QUAL.BIN", fixture / "qualification.c", "-lvcccompat", "-ldecbfile"],
env=env, cwd=work, check=True)
disk = qualification_disk(work / "qualification", runtime / "bin/writecocofile")
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
"-I", root / "src", fixture / "run.cpp", core, "-o", work / "run"],
cwd=work, check=True)
for config in ("Debug", "Release"):
example = work / config
shutil.copytree(root / "examples/cmoc/PlanetSurvey", example)
make = [runtime / "bin/make", "disk", "VCC_CONFIGURATION=" + config]
subprocess.run(make, cwd=example, env=env, check=True)
data = (example / "generated/PLANETS.TXT").read_bytes()
if data[254:258] != b"MARS":
raise AssertionError("The published Mars record must straddle the sector boundary")
(example / "startup.cfg").write_text("0=SURVEY.dsk\n")
# Rebuild after editing just the data, as a reader would.
edited = work / (config + "-edited")
shutil.copytree(example, edited)
source = edited / "assets/planets.txt"
lines = source.read_text().splitlines()
lines[lines.index("MARS|RED,COLD|4")] = "MARS ORBIT|DUSTY,COLD|4"
source.write_text("\n".join(lines) + "\n")
subprocess.run(make, cwd=edited, env=env, check=True)
bad = example / "malformed"
bad.mkdir()
(bad / "BAD.DSK").write_bytes(bytes([255]) * (35 * 18 * 256))
(bad / "PLANETS.TXT").write_bytes(b"EARTH|BLUE|3\rMARS|RED,COLD|4X\r")
subprocess.run([runtime / "bin/writecocofile", "BAD.DSK", "PLANETS.TXT"], cwd=bad, check=True)
for mode in args.profile or ("disk", "rgb-hd", "rgb-fd", "sdc"):
capture = args.capture and mode == "disk" and config == "Debug"
subprocess.run([work / "run", roms, disk, work / "QUAL.BIN", mode, example, edited, config,
"capture" if capture else "check"],
cwd=work, check=True)
if capture:
subprocess.run(["sips", "-s", "format", "png", "survey.ppm", "--out", args.capture.resolve()],
cwd=work, check=True)
if __name__ == "__main__":
main()