// SPDX-License-Identifier: GPL-3.0-or-later #include "../guest-captures.h" using namespace BasicDiskTests; static void visit(const fs::path& roms, const fs::path& binary, Processor cpu, Profile profile, bool capture) { Session guest(roms, "card/VOL.DSK", cpu, profile); guest.launch(binary); guest.until("AT BYTE ZERO\nFILING EARTH\nREOPENED TRIP.LOG\nVISIT 1: EARTH"); guest.verifyReturn(); saveVolume(guest, "earth.dsk"); setVolumeProtected(guest, true); const auto earth = volume(guest); const std::string prompt = "R: RETRY Q: QUIT"; guest.launch(binary); guest.until(prompt); guest.type("Q"); guest.until("CHECK DISK AND LOG"); guest.verifyReturn(); require(volume(guest) == earth, "Protected trip changed the disk"); // Run the disk copy and leave this Mars flight waiting in the guest. guest.type("CLS\r"); require(guest.machine.copyScreenText().find(prompt) == std::string::npos, "Old retry prompt is still visible"); guest.type("LOADM\"TRIP\":EXEC\r"); guest.until(prompt); if (capture) { guest.frames(3); saveActiveFrame(*guest.machine.snapshot().frame, "trip-retry.ppm"); } guest.type("R"); guest.until("RETRYING SAVE\nSAVE FAILED\nKEEP THE SAME DISK IN DRIVE 0\nIF PROTECTED, TURN PROTECT OFF\n" + prompt); require(volume(guest) == earth, "Retry while protected changed the disk"); setVolumeProtected(guest, false); // The learner returns from changing protection in the host. Let the // ROM observe the released key before the learner presses R again. guest.frames(30); guest.type("R"); guest.until("REOPENED TRIP.LOG\nVISIT 1: EARTH\nVISIT 2: MARS"); guest.until("OK"); if (capture) { guest.frames(3); saveActiveFrame(*guest.machine.snapshot().frame, "trip.ppm"); } guest.verifyReturn(); saveVolume(guest, "mars.dsk"); const auto mars = volume(guest); guest.launch(binary); guest.until("BOTH VISITS ALREADY FILED\nREOPENED TRIP.LOG\nVISIT 1: EARTH\nVISIT 2: MARS"); guest.verifyReturn(); require(volume(guest) == mars, "Third trip changed a completed log"); } int main(int argc, char** argv) { try { require(argc == 6, "Usage: returntrip ROMDIR BIN CPU PROFILE CAPTURE"); const auto cpu = std::string(argv[3]) == "6809" ? Processor::MC6809 : Processor::HD6309; const std::string mode = argv[4]; const auto profile = mode == "disk" ? Profile::fd : mode == "rgb-hd" ? Profile::rgbHD : Profile::sdc; visit(argv[1], argv[2], cpu, profile, std::string(argv[5]) == "capture"); Session other(argv[1], "other/VOL.DSK", cpu, profile); other.launch(argv[2]); other.until("UNRECOGNIZED TRIP.LOG\nCHECK DISK AND LOG"); other.verifyReturn(); require(volume(other) == other.original, "Trip changed an unrelated file"); } catch (const std::exception& error) { std::cerr << error.what() << std::endl; return 1; } }