// 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 <fstream>
#include <iostream>
#include <stdexcept>
#include <vector>
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<std::uint8_t> rom{std::istreambuf_iterator<char>(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::uint16_t>(std::stoul(argv[3], nullptr, 0));
const auto stop = static_cast<std::uint16_t>(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;
}
}
Evidence record
experiments/xroar/vcc-fixture.cpp
From Windows Application to Portable Emulation Platform
3,336 bytes
SHA-256f735e0dbabd566f4288477680731ddcabb94679fff2fa1c1b0356f2b61a22b33