// SPDX-License-Identifier: GPL-3.0-or-later // Exercise the same Direct Run entry point used by the C development workspace. #include "core/MachineSession.h" #include #include #include #include using namespace VCC::Mac; using Bytes = std::vector; static Bytes readFile(const char* path) { std::ifstream input(path, std::ios::binary); if (!input) throw std::runtime_error(std::string("Cannot open ") + path); return {std::istreambuf_iterator(input), std::istreambuf_iterator()}; } static void waitFor(MachineSession& machine, const std::string& expected) { for (unsigned frame = 0; frame < 900; ++frame) { const auto text = machine.copyScreenText(); if (text.find("FAIL LINE") != std::string::npos) break; if (text.find(expected) != std::string::npos) return; machine.advance(); } throw std::runtime_error("Expected " + expected + " on screen:\n" + machine.copyScreenText()); } static void run(const Bytes& rom, const Bytes& binary, Processor cpu, const std::string& expected) { MachineSession machine; machine.load(rom, cpu); machine.resume(); for (unsigned frame = 0; frame < 180; ++frame) machine.advance(); waitFor(machine, "OK"); if (binary.size() < 5 || binary[binary.size() - 5] != 0xFF) throw std::runtime_error("Expected a DECB executable with an entry point"); const auto n = binary.size(); machine.debuggerLoadBinary(binary, std::uint16_t((binary[n - 2] << 8) | binary[n - 1])); machine.debuggerClearDevelopmentBreakpoints(); machine.resume(); waitFor(machine, expected); // PRINT 7*9, followed by Enter, through the guest keyboard matrix. The // calculation confirms the interpreter accepted input after main returned. auto key = [](int bit) { return std::uint64_t(1) << bit; }; machine.paste({key(16), key(18), key(9), key(14), key(20), key(31), key(39), key(55) | key(42), key(41), key(48)}); waitFor(machine, " 63"); } int main(int argc, char** argv) { try { if (argc != 4) throw std::runtime_error("Usage: run COCO3_ROM QUAL_BIN CREW_BIN"); const auto rom = readFile(argv[1]), qual = readFile(argv[2]), crew = readFile(argv[3]); for (auto cpu : {Processor::MC6809, Processor::HD6309}) { run(rom, qual, cpu, "BOUNDED HEAP PASSED\nOK"); run(rom, crew, cpu, "CREW AT LAUNCH: 0\nCREW AFTER GROWTH: 3\nNO ROOM FOR 200\nCREW STILL ABOARD: 3\nCREW LOG CLOSED\nOK"); std::cout << "PASS " << (cpu == Processor::MC6809 ? "MC6809" : "HD6309") << ": heap boundaries, manual exercise and BASIC return\n"; } } catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; } }