Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,51 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Compile and run the GIME qualification and joystick exercise against a real CoCo 3 ROM."""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("runtime", type=Path)
|
||||
parser.add_argument("core", type=Path, help="current libVCCCore.a")
|
||||
parser.add_argument("rom", type=Path, help="privately supplied CoCo 3 BASIC ROM")
|
||||
parser.add_argument("--capture", type=Path, help="save the lander display to this PNG")
|
||||
parser.add_argument("--disk-roms", type=Path, help="also test disk EXEC with the local profile ROMs")
|
||||
args = parser.parse_args()
|
||||
fixture = Path(__file__).resolve().parent
|
||||
root = fixture.parents[2]
|
||||
runtime = args.runtime.resolve(strict=True)
|
||||
env = dict(os.environ, VCC_CMOC_COMPAT="0", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
|
||||
with tempfile.TemporaryDirectory(prefix="vcc-gime-") as tmp:
|
||||
work = Path(tmp)
|
||||
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
||||
"-I", root / "src", fixture / "run.cpp", args.core.resolve(strict=True), "-o", "run"],
|
||||
cwd=work, check=True)
|
||||
for optimization in ("-O0", "-O2"):
|
||||
for source, output in ((fixture / "qualification.c", "QUAL"),
|
||||
(root / "examples/cmoc/manual/lander.c", "LANDER")):
|
||||
subprocess.run([runtime / "bin/cmoc", "--coco", "--intermediate", optimization, "-Werror",
|
||||
"--org=2800", "-o", output + ".bin", source, "-lgime", "-lbgraph", "-lbcontrol"],
|
||||
cwd=work, env=env, check=True)
|
||||
symbols = dict(re.findall(r"^Symbol: _(\w+) \(.+?\) = ([0-9A-F]+)$",
|
||||
(work / "QUAL.map").read_text(), re.MULTILINE))
|
||||
print("Checking", optimization, flush=True)
|
||||
subprocess.run(["./run", args.rom.resolve(strict=True), "QUAL.bin", "LANDER.bin",
|
||||
*(symbols[name] for name in ("stage", "advanceStage", "finishedFlips"))],
|
||||
cwd=work, check=True)
|
||||
if args.disk_roms:
|
||||
from disk import check_disk_launch
|
||||
check_disk_launch(runtime, args.core.resolve(strict=True), args.disk_roms.resolve(strict=True),
|
||||
work, work / "LANDER.bin")
|
||||
if args.capture:
|
||||
args.capture.parent.mkdir(parents=True, exist_ok=True)
|
||||
subprocess.run(["sips", "-s", "format", "png", work / "lander.bmp", "--out", args.capture],
|
||||
check=True, stdout=subprocess.DEVNULL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "../basic-disk-session.h"
|
||||
|
||||
using namespace BasicDiskTests;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
if (argc != 3) throw std::runtime_error("Usage: disk ROM_DIRECTORY LANDER.DSK");
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
for (auto profile : {Profile::fd, Profile::rgbHD, Profile::sdc}) {
|
||||
Session session(argv[1], argv[2], cpu, profile);
|
||||
const auto reads = session.reads(), otherReads = session.otherReads();
|
||||
session.type("LOADM\"LANDER\":EXEC\r");
|
||||
session.frames(1000); // Allow disk spin-up, loading and both landscape draws.
|
||||
const auto preview = session.machine.debuggerGraphicsPreview(true, true, 0, DebugGraphicsMode::HSCREEN2);
|
||||
require(!preview.text && preview.width == 320 && preview.height == 192 && preview.pixelsPerByte == 2,
|
||||
"Disk launch did not enter 320 x 192 x 16: " + preview.modeName);
|
||||
session.type("Q");
|
||||
session.until("FLIGHT ENDED");
|
||||
session.verifyReturn();
|
||||
require(session.reads() > reads && session.otherReads() == otherReads,
|
||||
"Unexpected route for LOADM");
|
||||
session.verifyMedia();
|
||||
const char* device = profile == Profile::fd ? "FD-502" : profile == Profile::sdc ? "SDC" : "RGB-DOS HD";
|
||||
std::cout << "PASS " << (cpu == Processor::MC6809 ? "MC6809 " : "HD6309 ") << device
|
||||
<< ": disk EXEC, graphics, Q, return to BASIC and intact media\n";
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Build the guest disk and exercise LOADM/EXEC on the three BASIC storage profiles."""
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
def check_disk_launch(runtime, core, roms, work, lander):
|
||||
fixture = Path(__file__).resolve().parent
|
||||
destination = Path(work) / "disk-launch"
|
||||
destination.mkdir()
|
||||
shutil.copyfile(lander, destination / "LANDER.BIN")
|
||||
disk = destination / "LANDER.DSK"
|
||||
disk.write_bytes(b"\xff" * (35 * 18 * 256))
|
||||
subprocess.run([runtime / "bin/writecocofile", "--binary", disk, "LANDER.BIN"],
|
||||
cwd=destination, check=True)
|
||||
(destination / "startup.cfg").write_text("0=LANDER.DSK\n")
|
||||
runner = destination / "disk"
|
||||
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
||||
"-I", fixture.parents[2] / "src", fixture / "disk.cpp", core, "-o", runner], check=True)
|
||||
subprocess.run([runner, roms, disk], check=True)
|
||||
@@ -0,0 +1,86 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Mailbox lets the host inspect the real guest's RAM/scanout at stable points.
|
||||
#include <cmoc.h>
|
||||
#include <vcc/gime.h>
|
||||
|
||||
unsigned char stage, advanceStage;
|
||||
|
||||
static void checkpoint(unsigned char n)
|
||||
{
|
||||
stage = n;
|
||||
asm {
|
||||
lda :n
|
||||
@wait cmpa :advanceStage
|
||||
bne @wait
|
||||
}
|
||||
}
|
||||
|
||||
// Keep this marker visible in the linker map for the instruction/VSYNC trace.
|
||||
void finishedFlips(void)
|
||||
{
|
||||
checkpoint(4);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char i, unexpected, savedBank;
|
||||
unsigned char *inactiveBank = (unsigned char *)0xffa8;
|
||||
if (gime_present()) { printf("FAIL IDLE PRESENT\n"); return 1; }
|
||||
gime_close();
|
||||
gime_set_palette(1, 5);
|
||||
gime_clear(7);
|
||||
// Refuse a screen bank owned by the inactive task, preserving its mapping.
|
||||
savedBank = *inactiveBank;
|
||||
*inactiveBank = 0x24;
|
||||
unexpected = gime_open();
|
||||
if (unexpected) gime_close();
|
||||
if ((*inactiveBank & 0x3f) != 0x24) unexpected = 1;
|
||||
*inactiveBank = savedBank;
|
||||
if (unexpected) { printf("FAIL RESERVED BANK\n"); return 1; }
|
||||
asm("orcc", "#$10");
|
||||
unexpected = gime_open();
|
||||
asm("andcc", "#$ef");
|
||||
if (unexpected) { gime_close(); printf("FAIL IRQ OPEN\n"); return 1; }
|
||||
if (!gime_open()) { printf("GRAPHICS UNAVAILABLE\n"); return 0; }
|
||||
if (gime_open()) { gime_close(); printf("FAIL SECOND OPEN\n"); return 1; }
|
||||
|
||||
gime_set_palette(0, 0);
|
||||
gime_set_palette(1, 9); // blue
|
||||
gime_set_palette(2, 36); // red
|
||||
gime_set_palette(3, 63); // white
|
||||
gime_clear(1);
|
||||
// Byte 8191 at (62,51) is adjacent to an 8 KiB bank boundary.
|
||||
gime_fill_rect(63, 51, 4, 2, 2);
|
||||
gime_fill_rect(318, 191, 14, 4, 2);
|
||||
gime_plot(319, 191, 3);
|
||||
gime_plot(320, 191, 2);
|
||||
gime_plot(319, 192, 2);
|
||||
gime_fill_rect(42, 18, 0, 9, 2);
|
||||
gime_plot(19, 30, 16);
|
||||
checkpoint(1); // first page remains visible
|
||||
if (!gime_present()) return 2;
|
||||
gime_clear(2); // immediately reuse the old front page
|
||||
checkpoint(2);
|
||||
if (!gime_present()) return 3;
|
||||
checkpoint(3);
|
||||
|
||||
// Consecutive swaps without drawing must still be frame-paced.
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (!gime_present()) return 4;
|
||||
finishedFlips();
|
||||
// A missing interrupt must time out and leave both page identities intact.
|
||||
asm("orcc", "#$10");
|
||||
unexpected = gime_present();
|
||||
gime_plot(319, 191, 1);
|
||||
checkpoint(6);
|
||||
gime_close(); // Even a stopped timer must allow cleanup.
|
||||
asm("andcc", "#$ef");
|
||||
if (unexpected) { printf("FAIL IRQ TIMEOUT\n"); return 1; }
|
||||
gime_close();
|
||||
if (gime_present()) { printf("FAIL CLOSED PRESENT\n"); return 1; }
|
||||
if (!gime_open()) { printf("FAIL REOPEN\n"); return 1; }
|
||||
gime_close();
|
||||
checkpoint(5);
|
||||
printf("GRAPHICS PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "core/MachineSession.h"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace VCC::Mac;
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
constexpr unsigned pageA = 0x40000, pageB = 0x48000, pageBytes = 160 * 192;
|
||||
|
||||
static void require(bool ok, const std::string& message) {
|
||||
if (!ok) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
static Bytes fileBytes(const char* path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
require(file.good(), std::string("Cannot read ") + path);
|
||||
return {std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
static void tick(MachineSession& machine, unsigned frames = 1) {
|
||||
for (unsigned i = 0; i < frames; ++i) {
|
||||
machine.advance();
|
||||
machine.takeAudio();
|
||||
}
|
||||
}
|
||||
|
||||
static std::string screen(MachineSession& machine) {
|
||||
try { return machine.copyScreenText(); }
|
||||
catch (const std::exception&) { return {}; } // Bitmap mode has no hardware text.
|
||||
}
|
||||
|
||||
static void waitText(MachineSession& machine, const std::string& expected) {
|
||||
for (unsigned n = 0; n < 600; ++n) {
|
||||
if (screen(machine).find(expected) != std::string::npos) return;
|
||||
tick(machine);
|
||||
}
|
||||
throw std::runtime_error("Expected " + expected + " on screen: " + screen(machine));
|
||||
}
|
||||
|
||||
static void type(MachineSession& machine, const std::string& text) {
|
||||
std::vector<std::uint64_t> keys;
|
||||
auto key = [](int bit) { return std::uint64_t{1} << bit; };
|
||||
for (char c : text) {
|
||||
if (c >= 'A' && c <= 'Z') keys.push_back(key(c - '@'));
|
||||
else if (c >= '0' && c <= '9') keys.push_back(key(c - '0' + 32));
|
||||
else if (c == ' ') keys.push_back(key(31));
|
||||
else if (c == '\r') keys.push_back(key(48));
|
||||
else if (c == ',') keys.push_back(key(44));
|
||||
else if (c == '*') keys.push_back(key(55) | key(42));
|
||||
else throw std::logic_error("Unhandled keyboard character");
|
||||
}
|
||||
machine.paste(keys);
|
||||
while (machine.pasteRemaining()) tick(machine);
|
||||
tick(machine, 6);
|
||||
}
|
||||
|
||||
static void boot(MachineSession& machine, const Bytes& rom, Processor cpu, unsigned ram) {
|
||||
MachineConfiguration config;
|
||||
config.ram = ram;
|
||||
config.processor = cpu;
|
||||
machine.configure(config);
|
||||
machine.load(rom, cpu);
|
||||
machine.resume();
|
||||
tick(machine, 180);
|
||||
waitText(machine, "OK");
|
||||
}
|
||||
|
||||
static void launch(MachineSession& machine, const Bytes& binary) {
|
||||
require(binary.size() >= 5 && binary[binary.size() - 5] == 0xff, "Missing DECB entry point");
|
||||
machine.debuggerLoadBinary(binary, (binary[binary.size() - 2] << 8) | binary.back());
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
machine.resume();
|
||||
}
|
||||
|
||||
static void checkBasic(MachineSession& machine) {
|
||||
type(machine, "PRINT 7*9\r");
|
||||
waitText(machine, " 63");
|
||||
}
|
||||
|
||||
static Bytes memory(MachineSession& machine, unsigned address, unsigned length, bool physical = false) {
|
||||
return machine.debuggerMemoryRange(address, length, physical).bytes;
|
||||
}
|
||||
|
||||
static DebugGraphicsPreview video(MachineSession& machine) {
|
||||
return machine.debuggerGraphicsPreview(true, true, 0, DebugGraphicsMode::HSCREEN1);
|
||||
}
|
||||
|
||||
static void waitStage(MachineSession& machine, unsigned mailbox, unsigned stage) {
|
||||
for (unsigned n = 0; n < 600; ++n) {
|
||||
if (memory(machine, mailbox, 1).front() == stage) {
|
||||
tick(machine, 2); // Observe two completed rasters at the stable checkpoint.
|
||||
return;
|
||||
}
|
||||
tick(machine);
|
||||
}
|
||||
throw std::runtime_error("Guest did not reach stage " + std::to_string(stage) + ": " + screen(machine));
|
||||
}
|
||||
|
||||
static void releaseStage(MachineSession& machine, unsigned mailbox, unsigned stage) {
|
||||
machine.pause();
|
||||
machine.debuggerWriteMemory(mailbox, {static_cast<std::uint8_t>(stage)});
|
||||
machine.resume();
|
||||
}
|
||||
|
||||
static void checkMmu(const VCC::MMUState& initial, const VCC::MMUState& current, const char* when) {
|
||||
for (unsigned i = 0; i < 8; ++i)
|
||||
if (initial.Task0[i] != current.Task0[i] || initial.Task1[i] != current.Task1[i])
|
||||
std::cerr << when << " MMU bank " << i << " tasks " << initial.Task0[i] << "/" << initial.Task1[i]
|
||||
<< " -> " << current.Task0[i] << "/" << current.Task1[i] << '\n';
|
||||
require(initial.Enabled == current.Enabled && initial.ActiveTask == current.ActiveTask &&
|
||||
initial.AllRAM == current.AllRAM && initial.Prefix == current.Prefix &&
|
||||
initial.RamVectors == current.RamVectors && initial.RomMap == current.RomMap &&
|
||||
initial.Task0 == current.Task0 && initial.Task1 == current.Task1, "MMU mapping changed: tasks " + std::to_string(initial.ActiveTask) + "/" + std::to_string(current.ActiveTask)
|
||||
+ ", control " + std::to_string(initial.RomMap) + "/" + std::to_string(current.RomMap));
|
||||
}
|
||||
|
||||
// Check actual RGB pixels presented for a complete frame, including untouched neighbors.
|
||||
static void checkRaster(MachineSession& machine, unsigned address, const Bytes& expected) {
|
||||
const auto image = video(machine);
|
||||
require(image.width == 320 && image.height == 192 && image.bytesPerRow == 160 &&
|
||||
image.address == address && !image.text, "Unexpected active graphics page or format");
|
||||
require(image.bytes == expected, "Wrong displayed page contents");
|
||||
const auto frame = machine.snapshot().frame;
|
||||
const auto area = frame->activeArea;
|
||||
require(area.width == 640 && area.height == 384, "Wrong active scanout dimensions");
|
||||
const std::uint32_t colors[] = {0x000000, 0x0000ff, 0xff0000, 0xffffff};
|
||||
for (unsigned y = 0; y < image.height; ++y) {
|
||||
for (unsigned x = 0; x < image.width; ++x) {
|
||||
const auto byte = expected[y * 160 + x / 2];
|
||||
const auto index = x % 2 ? byte & 0xf : byte >> 4;
|
||||
const auto offset = (area.y + 2 * y) * Frame::width + area.x + 2 * x;
|
||||
require(index < 4 && frame->pixels[offset] == colors[index], "Mixed or miscolored active raster at "
|
||||
+ std::to_string(x) + "," + std::to_string(y) + " actual " + std::to_string(frame->pixels[offset]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Four consecutive calls must write alternating page origins outside active scanout,
|
||||
// each separated by an actual active field. The trace timestamps are guest video events.
|
||||
static void checkTrace(MachineSession& machine) {
|
||||
const auto summary = machine.debuggerTrace();
|
||||
require(summary.status.find("Stop address") != std::string::npos, "Missing swap trace end");
|
||||
unsigned line = 0, field = 0, lastField = 0, count = 0, address = pageA;
|
||||
for (const auto& event : machine.debuggerTraceForExport(0, summary.total).records) {
|
||||
if (event.event == VCC::TraceEvent::ScreenHSYNCLow) {
|
||||
line = event.line;
|
||||
if (line == 128) ++field;
|
||||
} else if (event.event == VCC::TraceEvent::ScreenReg && event.detail.rfind("VOFF: ", 0) == 0) {
|
||||
const unsigned next = std::stoul(event.detail.substr(6), nullptr, 16);
|
||||
require(line < 43 || line >= 235, "Video origin changed during active scanout");
|
||||
if (next != address) {
|
||||
require(next == (address == pageA ? pageB : pageA), "Unexpected video origin");
|
||||
require(!count || field > lastField, "Two swaps in a single blanking interval");
|
||||
address = next;
|
||||
lastField = field;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
require(count == 4, "Expected four independently synchronized flips, saw " + std::to_string(count));
|
||||
}
|
||||
|
||||
static void qualify(const Bytes& rom, const Bytes& binary, Processor cpu, unsigned ram, unsigned stage,
|
||||
unsigned ack, unsigned finished) {
|
||||
MachineSession machine;
|
||||
boot(machine, rom, cpu, ram);
|
||||
const unsigned width = ram == 2 ? 40 : ram == 3 ? 80 : 32;
|
||||
if (width != 32) type(machine, "WIDTH " + std::to_string(width) + "\r");
|
||||
type(machine, "PALETTE 1,38\r");
|
||||
const auto text = video(machine);
|
||||
const auto mmu = machine.debuggerSnapshot().mmu;
|
||||
const auto palette = memory(machine, 0xffb0, 16);
|
||||
const auto display = memory(machine, 0xff98, 8);
|
||||
require(palette[1] == 38, "Could not install BASIC's custom palette");
|
||||
require(text.text && text.bytesPerRow / text.bytesPerCell == width, "Unexpected BASIC width before Run");
|
||||
const Bytes mirrored = ram == 0 ? memory(machine, 0, 65536, true) : Bytes{};
|
||||
launch(machine, binary);
|
||||
if (ram == 0) {
|
||||
waitText(machine, "GRAPHICS UNAVAILABLE\nOK");
|
||||
require(memory(machine, 0, 65536, true) == mirrored, "Graphics probe corrupted mirrored RAM");
|
||||
} else {
|
||||
waitStage(machine, stage, 1);
|
||||
checkMmu(mmu, machine.debuggerSnapshot().mmu, "open");
|
||||
Bytes drawn(pageBytes, 0x11);
|
||||
for (unsigned y : {51, 52}) {
|
||||
drawn[y * 160 + 31] = 0x12;
|
||||
drawn[y * 160 + 32] = 0x22;
|
||||
drawn[y * 160 + 33] = 0x21;
|
||||
}
|
||||
drawn.back() = 0x23;
|
||||
require(memory(machine, pageB, pageBytes, true) == drawn, "Incorrect hidden page after drawing");
|
||||
checkRaster(machine, pageA, Bytes(pageBytes, 0));
|
||||
releaseStage(machine, ack, 1);
|
||||
waitStage(machine, stage, 2);
|
||||
checkRaster(machine, pageB, drawn);
|
||||
require(memory(machine, pageA, pageBytes, true) == Bytes(pageBytes, 0x22), "Old front could not be reused");
|
||||
releaseStage(machine, ack, 2);
|
||||
waitStage(machine, stage, 3);
|
||||
checkRaster(machine, pageA, Bytes(pageBytes, 0x22));
|
||||
releaseStage(machine, ack, 3);
|
||||
machine.debuggerStartTrace(100000, {}, {static_cast<std::uint16_t>(finished)}, true, false);
|
||||
waitStage(machine, stage, 4);
|
||||
checkTrace(machine);
|
||||
checkRaster(machine, pageA, Bytes(pageBytes, 0x22));
|
||||
releaseStage(machine, ack, 4);
|
||||
waitStage(machine, stage, 6);
|
||||
checkRaster(machine, pageA, Bytes(pageBytes, 0x22));
|
||||
drawn.back() = 0x21; // Still wrote to the hidden page after a failed present.
|
||||
require(memory(machine, pageB, pageBytes, true) == drawn, "Failed swap changed the draw destination");
|
||||
releaseStage(machine, ack, 6);
|
||||
waitStage(machine, stage, 5);
|
||||
checkMmu(mmu, machine.debuggerSnapshot().mmu, "closed");
|
||||
releaseStage(machine, ack, 5);
|
||||
waitText(machine, "GRAPHICS PASSED\nOK");
|
||||
}
|
||||
|
||||
require(memory(machine, 0xffb0, 16) == palette, "Custom BASIC palette was not restored");
|
||||
require(memory(machine, 0xff98, 8) == display, "BASIC video registers were not restored");
|
||||
const auto restored = video(machine);
|
||||
require(restored.text && restored.address == text.address &&
|
||||
restored.bytesPerRow == text.bytesPerRow && restored.width == text.width, "BASIC text layout changed");
|
||||
checkBasic(machine);
|
||||
std::cout << " " << mmu.RAMBytes / 1024 << " KiB, WIDTH " << width << ": "
|
||||
<< (ram == 0 ? "safe refusal" : "page contents, raster, timing")
|
||||
<< ", restored BASIC keyboard, palette and mapping\n";
|
||||
}
|
||||
|
||||
// OS/2 24-bit BMP of the emulator's published active area, for the optional manual capture.
|
||||
static void saveFrame(const Frame& frame) {
|
||||
const auto area = frame.activeArea;
|
||||
const unsigned stride = (3 * area.width + 3u) & ~3u;
|
||||
std::ofstream out("lander.bmp", std::ios::binary);
|
||||
auto le = [&](unsigned value, unsigned bytes) {
|
||||
for (unsigned n = 0; n < bytes; ++n) out.put(static_cast<char>(value >> (8 * n)));
|
||||
};
|
||||
out.write("BM", 2);
|
||||
le(26 + stride * area.height, 4); le(0, 4); le(26, 4); le(12, 4);
|
||||
le(area.width, 2); le(area.height, 2); le(1, 2); le(24, 2);
|
||||
for (int y = area.height - 1; y >= 0; --y) {
|
||||
for (int x = 0; x < area.width; ++x)
|
||||
le(frame.pixels[(area.y + y) * Frame::width + area.x + x], 3);
|
||||
for (unsigned n = 3 * area.width; n < stride; ++n) out.put(0);
|
||||
}
|
||||
require(out.good(), "Unable to capture guest frame");
|
||||
}
|
||||
|
||||
static int craftLeft(MachineSession& machine) {
|
||||
if (!(memory(machine, 0xff98, 1)[0] & 0x80)) return -1;
|
||||
const auto image = video(machine);
|
||||
if (image.width != 320 || image.height != 192) return -1;
|
||||
const auto start = image.pixels.begin() + 89 * image.width;
|
||||
const auto x = std::find(start, start + image.width, 0xffffff);
|
||||
return x == start + image.width ? -1 : int(x - start) - 2;
|
||||
}
|
||||
|
||||
static void fly(const Bytes& rom, const Bytes& binary, Processor cpu) {
|
||||
MachineSession machine;
|
||||
boot(machine, rom, cpu, 1);
|
||||
machine.setJoystick(0, 8191, 8191, 0, 0);
|
||||
launch(machine, binary);
|
||||
for (unsigned n = 0; n < 600 && craftLeft(machine) != 144; ++n) tick(machine);
|
||||
require(craftLeft(machine) == 144, "Lander did not appear at its documented position");
|
||||
machine.setJoystick(0, 16383, 8191, 0, 0);
|
||||
int x = 144;
|
||||
unsigned firstMeasuredField = 0, measuredSteps = 0, elapsedFields = 0;
|
||||
for (unsigned n = 0; n < 360 && x < 226; ++n) {
|
||||
tick(machine);
|
||||
const int next = craftLeft(machine);
|
||||
// Skip the two one-time landscape draws when measuring steady flight.
|
||||
if (next > x && x >= 152) {
|
||||
if (firstMeasuredField) {
|
||||
++measuredSteps;
|
||||
elapsedFields = n - firstMeasuredField;
|
||||
} else {
|
||||
firstMeasuredField = n;
|
||||
}
|
||||
}
|
||||
x = next;
|
||||
}
|
||||
require(x >= 226 && x <= 246, "Right joystick did not steer across the display");
|
||||
machine.setJoystick(0, 8191, 8191, 0, 0);
|
||||
tick(machine, 12);
|
||||
const auto frame = machine.snapshot().frame;
|
||||
const auto area = frame->activeArea;
|
||||
const auto row = frame->pixels.begin() + (area.y + 2 * 89) * Frame::width + area.x;
|
||||
require(row[2 * (144 + 8)] == 0 && row[2 * (craftLeft(machine) + 8)] == 0xffffff,
|
||||
"Craft was absent or left a trail on the visible raster");
|
||||
const auto landscape = video(machine);
|
||||
require((landscape.bytes[168 * 160 + 315 / 2] & 0xf) == 6, "Right edge of the ridge is missing");
|
||||
if (cpu == Processor::MC6809) {
|
||||
saveFrame(*frame);
|
||||
machine.setJoystick(0, 8191, 16383, 0, 0);
|
||||
waitText(machine, "ON THE PAD!\nOK");
|
||||
} else {
|
||||
machine.setKeyboard(std::uint64_t{1} << 17); // Q on the real CoCo keyboard matrix
|
||||
tick(machine, 3);
|
||||
machine.setKeyboard(0);
|
||||
waitText(machine, "FLIGHT ENDED\nOK");
|
||||
}
|
||||
checkBasic(machine);
|
||||
std::cout << " Lander: " << measuredSteps << " moves in " << elapsedFields
|
||||
<< " steady-flight fields; old location erased; returned to BASIC\n";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
require(argc == 7, "Usage: run ROM QUAL.BIN LANDER.BIN STAGE ACK TRACE_STOP");
|
||||
const auto rom = fileBytes(argv[1]), probe = fileBytes(argv[2]), lander = fileBytes(argv[3]);
|
||||
const auto stage = std::stoul(argv[4], nullptr, 16), ack = std::stoul(argv[5], nullptr, 16);
|
||||
const auto end = std::stoul(argv[6], nullptr, 16);
|
||||
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
|
||||
std::cout << (cpu == Processor::MC6809 ? "6809" : "6309") << std::endl;
|
||||
for (unsigned ram = 0; ram < 4; ++ram) qualify(rom, probe, cpu, ram, stage, ack, end);
|
||||
fly(rom, lander, cpu);
|
||||
}
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user