// SPDX-License-Identifier: GPL-3.0-or-later // Optional integration check; all ROMs and generated media stay outside Git. #include "../../src/core/MachineSession.h" #include "../../src/devices/FD502/Fd502Device.h" #include #include #include #include using namespace VCC::Mac; using namespace VCC::Devices; namespace fs = std::filesystem; static std::vector read(const fs::path& path) { std::ifstream in(path, std::ios::binary); if (!in) throw std::runtime_error("Cannot read " + path.string()); return {std::istreambuf_iterator(in), std::istreambuf_iterator()}; } static void picture(const MachineSession& machine, const fs::path& path) { const auto frame = machine.snapshot().frame; if (!frame) throw std::runtime_error("Missing frame"); std::ofstream out(path, std::ios::binary); out << "P6\n" << Frame::width << ' ' << Frame::height << "\n255\n"; for (auto pixel : frame->pixels) { out.put(char(pixel >> 16)); out.put(char(pixel >> 8)); out.put(char(pixel)); } if (!out) throw std::runtime_error("Cannot save capture"); } int main(int argc, char** argv) { try { if (argc != 5) throw std::runtime_error("Usage: run-coco-letters COCO3_ROM DISK_ROM GAME_DSK OUTPUT_DIR"); const auto system = read(argv[1]), diskROM = read(argv[2]), disk = read(argv[3]); fs::create_directories(argv[4]); for (auto cpu : {Processor::MC6809, Processor::HD6309}) { const std::string name = cpu == Processor::MC6809 ? "6809" : "6309"; MachineSession machine; auto floppy = std::make_shared(diskROM); floppy->mount(0, DiskImage::load(disk, true)); machine.cartridges().configure({nullptr, nullptr, nullptr, nullptr, floppy}, true, 4); MachineConfiguration config; config.processor = cpu; config.ram = 0; machine.configure(config); machine.setVideoOutput(VideoOutput::RGB); machine.load(system, cpu); machine.resume(); std::uint64_t audio = 0; auto advance = [&](unsigned count) { while (count--) { machine.advance(); for (const auto sample : machine.takeAudio()) if (sample.left || sample.right) ++audio; } }; auto press = [&](unsigned bit) { machine.setKeyboard(std::uint64_t{1} << bit); advance(8); machine.setKeyboard(0); advance(8); }; advance(240); for (auto bit : {4u, 15u, 19u, 48u}) press(bit); // DOS + Return advance(1200); auto text = machine.copyScreenText(); std::cout << name << " title:\n" << text << std::endl; if (text.find("CoCo Letters") == std::string::npos) throw std::runtime_error("DOS did not reach the game title"); picture(machine, fs::path(argv[4]) / (name + "-title.ppm")); press(18); advance(120); // RGB press(5); advance(120); // Easy press(21); advance(600); // User plays first picture(machine, fs::path(argv[4]) / (name + "-board.ppm")); const auto before = machine.snapshot().frame->pixels; press(30); advance(60); // Right arrow moves the board cursor. picture(machine, fs::path(argv[4]) / (name + "-input.ppm")); if (before == machine.snapshot().frame->pixels) throw std::runtime_error("Game did not respond to cursor input"); if (!floppy->readEvents(0) || floppy->writeEvents(0) || floppy->image(0)->bytes() != disk) throw std::runtime_error("Unexpected disk activity or modification"); if (!audio) throw std::runtime_error("No game audio"); std::cout << "PASS " << name << ": 128 KB, DOS title, RGB/Easy/User selection, cursor response; " << floppy->readEvents(0) << " reads, no writes, " << audio << " audible samples.\n"; } } catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; } }