68 lines
3.8 KiB
C++
68 lines
3.8 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Optional real-cartridge check; requires private system ROM and Scripsit II.
|
|
// Usage: probe SYSTEM_ROM SCRIPSIT_CCC OUTPUT_PREFIX
|
|
// No media writes or bundled copyrighted payloads. See CPU_CORE.md.
|
|
#include "../../src/core/MachineSession.h"
|
|
#include "../../src/devices/RomCartridge.h"
|
|
#include <algorithm>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace VCC::Mac;
|
|
static void require(bool ok, const char* message) {
|
|
if (!ok) throw std::runtime_error(message);
|
|
}
|
|
static std::vector<std::uint8_t> read(const char* path) {
|
|
std::ifstream in(path, std::ios::binary);
|
|
require(bool(in), "Cannot open ROM/cartridge");
|
|
return {std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()};
|
|
}
|
|
int main(int argc, char** argv) {
|
|
try {
|
|
require(argc == 4, "Supply system ROM, Scripsit II cartridge and output prefix");
|
|
const auto rom = read(argv[1]), cartridge = read(argv[2]);
|
|
for (auto processor : {Processor::MC6809, Processor::HD6309}) {
|
|
MachineSession m;
|
|
MachineConfiguration config; config.processor = processor;
|
|
m.configure(config);
|
|
m.cartridges().configure({nullptr, nullptr, nullptr, nullptr,
|
|
std::make_shared<VCC::Devices::RomCartridge>(cartridge)}, true, 4);
|
|
m.load(rom, processor); m.resume();
|
|
auto frames = [&](unsigned count) { while (count--) { m.advance(); m.takeAudio(); } };
|
|
auto press = [&](std::uint64_t keys) {
|
|
m.setKeyboard(keys); frames(6); m.setKeyboard(0); frames(6);
|
|
};
|
|
frames(180);
|
|
require(m.copyScreenText().find("COLOR SCRIPSIT II") != std::string::npos, "Scripsit menu did not boot");
|
|
// This known cartridge's sync-poll return, not a production special case.
|
|
m.debuggerSetBreakpoints({0x41f0});
|
|
press(1ull << 5); // E: enter the editor's command mode.
|
|
frames(180);
|
|
require(m.snapshot().state == RunState::Paused && m.snapshot().cpu.PC == 0x41f0,
|
|
"Editor is stuck polling VSYNC (TST/IRQ starvation)");
|
|
m.debuggerSetBreakpoints({}); m.resume(); frames(60);
|
|
press(1ull << 9); // I: insert mode (manual p. 11).
|
|
const std::string text = "hello from vcc plus";
|
|
for (char c : text) press(1ull << (c == ' ' ? 31 : c - 'a' + 1));
|
|
frames(120);
|
|
const auto memory = m.debuggerMemoryRange(0, 0x8000, false);
|
|
require(std::search(memory.bytes.begin(), memory.bytes.end(), text.begin(), text.end()) != memory.bytes.end(),
|
|
"Inserted text was not retained in guest memory");
|
|
const std::string cpu = processor == Processor::MC6809 ? "6809" : "6309";
|
|
const auto frame = m.snapshot().frame;
|
|
require(bool(frame), "No video frame");
|
|
std::ofstream out(std::string(argv[3]) + "-" + cpu + ".ppm", std::ios::binary);
|
|
out << "P6\n640 480\n255\n";
|
|
for (auto pixel : frame->pixels) { out.put(char(pixel >> 16)); out.put(char(pixel >> 8)); out.put(char(pixel)); }
|
|
require(bool(out), "Cannot write frame capture");
|
|
press(1ull << 50); // BREAK returns to command mode.
|
|
press((1ull << 52) | (1ull << 50)); // CTRL+BREAK returns to main menu.
|
|
frames(120);
|
|
require(m.copyScreenText().find("E-EDIT") != std::string::npos, "Did not return to the main menu");
|
|
press(1ull << 5); frames(120);
|
|
require(m.copyScreenText().find("E-EDIT") == std::string::npos, "Could not re-enter the editor");
|
|
std::cout << "PASS " << cpu << ": menu, sync-poll exit, insert text, return, re-enter\n";
|
|
}
|
|
} catch (const std::exception& e) { std::cerr << e.what() << '\n'; return 1; }
|
|
}
|