// SPDX-License-Identifier: GPL-3.0-or-later // Executes the authored ROM through the actual VCC Plus MachineSession. // No native UI, audio device, private ROM, cartridge, media, or settings. #include "MachineSession.h" #include #include #include #include using namespace VCC::Mac; static void registers(const VCC::CPUState& s) { std::cout << "{\"pc\":" << s.PC << ",\"cc\":" << unsigned(s.CC) << ",\"a\":" << unsigned(s.A) << ",\"b\":" << unsigned(s.B) << ",\"dp\":" << unsigned(s.DP) << ",\"x\":" << s.X << ",\"y\":" << s.Y << ",\"u\":" << s.U << ",\"s\":" << s.S << ",\"e\":" << unsigned(s.E) << ",\"f\":" << unsigned(s.F) << ",\"v\":" << s.V << ",\"md\":" << unsigned(s.MD) << ",\"native\":" << (s.IsNative6309 ? "true" : "false") << "}"; } int main(int argc, char** argv) { try { if (argc != 5) throw std::runtime_error("Usage: vcc-fixture ROM 6809|6309 TRACE_START STOP_PC"); std::ifstream in(argv[1], std::ios::binary); if (!in) throw std::runtime_error("Cannot open authored ROM"); std::vector rom{std::istreambuf_iterator(in), {}}; if (rom.size() != 32768) throw std::runtime_error("Expected authored 32 KiB ROM"); const auto processor = std::string(argv[2]) == "6809" ? Processor::MC6809 : Processor::HD6309; const auto start = static_cast(std::stoul(argv[3], nullptr, 0)); const auto stop = static_cast(std::stoul(argv[4], nullptr, 0)); MachineSession machine; machine.load(rom, processor); machine.debuggerSetBreakpoints({stop}); machine.debuggerStartTrace(512, {start}, {stop}, false, false); machine.resume(); for (unsigned frame = 0; frame < 3 && machine.snapshot().state == RunState::Running; ++frame) { machine.advance(); machine.takeAudio(); } const auto snapshot = machine.snapshot(); if (snapshot.state != RunState::Paused || snapshot.cpu.PC != stop) throw std::runtime_error("Authored program did not reach final breakpoint"); const auto memory = machine.debuggerMemoryRange(0x4100, 16, false); const auto trace = machine.debuggerTrace(0, 256); std::cout << "{\"stopped_before_pc\":" << stop << ",\"cycles\":" << snapshot.cycles << ",\"registers\":"; registers(snapshot.cpu); std::cout << ",\"memory_4100\":["; for (unsigned i = 0; i < memory.bytes.size(); ++i) { if (i) std::cout << ','; if (!memory.available[i]) throw std::runtime_error("Authored result RAM unavailable"); std::cout << unsigned(memory.bytes[i]); } std::cout << "],\"trace\":["; bool first = true; for (const auto& record : trace.records) { if (record.event != VCC::TraceEvent::Instruction) continue; if (!first) std::cout << ','; first = false; std::cout << "{\"pc\":" << record.before.PC << ",\"after\":"; registers(record.after); std::cout << ",\"cycles\":" << record.cycles << "}"; } std::cout << "]}\n"; } catch (const std::exception& e) { std::cerr << e.what() << '\n'; return 1; } }