// SPDX-License-Identifier: GPL-3.0-or-later #include "session.h" static void checkGuest(Session& run, const Bytes& guest, bool present) { run.launch(guest); if (!present) { run.until("SSC UNAVAILABLE"); return; } run.until("FIRST SUBMITTED"); run.machine.setJoystick(0, 16383, 8191, 1, 0); // move right and press fire during speech run.until("INPUT DURING SPEECH"); run.machine.setJoystick(0, 8191, 8191, 0, 0); auto& diagnostics = run.ssc->diagnostics(); auto first = diagnostics.AldSpeechCount(); require(first >= 4, "First phrase did not produce phonemes"); run.until("SECOND SUBMITTED"); run.until("TONE TEST"); require(diagnostics.AldSpeechCount() >= first + 4, "Second phrase did not produce phonemes"); const auto toneStart = run.audio.size(); run.until("NOISE TEST"); run.checkSignal(toneStart); const auto noiseStart = run.audio.size(); run.until("SSC API PASSED"); run.checkSignal(noiseStart); require(diagnostics.CpuIllegalCount() == 0, "Illegal speech firmware instruction"); // Each phrase includes a trailing space and CR, followed by the complete // 11-byte tone / 9-byte noise packets. Invalid calls must do no writes. const unsigned expected = 17 + 2 + 13 + 2 + 11 + 9; require(diagnostics.CommandCount() == expected, "Unexpected number of guest writes: " + std::to_string(diagnostics.CommandCount())); } static void checkLander(Session& run, const Bytes& bin, const Bytes& disk, bool bootDisk, const fs::path& wav) { if (bootDisk) run.diskExec(disk, "LANDER"); else run.launch(bin); run.until("2 MARS", 1200); run.audio.clear(); // Start the listening capture at the planet choice, after Disk BASIC setup. run.press(bootDisk ? 34 : 33); // Mars on disk, Earth on direct Run run.until(bootDisk ? "DESTINATION MARS" : "DESTINATION EARTH"); for (unsigned f = 0; f < 300 && run.ssc->diagnostics().AldSpeechCount() < 2; ++f) run.tick(); require(run.ssc->diagnostics().AldSpeechCount() >= 2, "First Lander phrase did not begin"); run.machine.setJoystick(0, 8191, 8191, 1, 0); run.until("THRUST", 60); run.machine.setJoystick(0, 8191, 8191, 0, 0); run.until("TOUCHDOWN", 1200); run.until("OK", 120); // Normal Direct Run and EXEC must both return to BASIC. for (unsigned i = 0; i < 90; ++i) run.tick(); run.checkSignal(0); require(std::count_if(run.audio.begin(), run.audio.end(), [](auto sample) { return std::fabs(sample.left - sample.right) > 0.01f; }) > 100, "No stereo beacon from Orchestra-90"); const auto& chip = run.ssc->diagnostics(); // Each string is followed by one space and one carriage return. const unsigned expected = std::string(bootDisk ? "DESTINATION MARS" : "DESTINATION EARTH").size() + std::string("LANDING COMPLETE").size() + 4; require(chip.CommandCount() == expected && chip.AldSpeechCount() >= 12 && chip.CpuIllegalCount() == 0, "Incomplete Lander speech"); if (bootDisk) require(run.floppy->readEvents(0) > 0 && run.floppy->writeEvents(0) == 0, "Unexpected disk I/O"); saveWav(wav, run.audio); std::cout << wav.filename() << ": " << chip.AldSpeechCount() << " phonemes, " << chip.CommandCount() << " submitted bytes, " << run.audio.size() << " frames\n"; } // A single sound cartridge or a disk-only machine still completes the mission. // Ask BASIC to compute a new result after the guest returns. static void checkOptionalCartridges(Session& run, const Bytes& binary, bool hasStereo) { run.launch(binary); run.until("2 MARS"); run.audio.clear(); run.press(33); run.until("DESTINATION EARTH"); run.until("TOUCHDOWN", 1200); run.until("OK"); run.press(47, true); // ? (PRINT) run.press(39); // 7 run.press(43, true); // + run.press(35); // 3 run.press(48); run.until("10"); const bool stereo = std::any_of(run.audio.begin(), run.audio.end(), [](auto frame) { return std::fabs(frame.left - frame.right) > 0.01f; }); require(stereo == hasStereo, "Unexpected channel activity with optional cartridges"); if (run.ssc) require(run.ssc->diagnostics().CommandCount() == 37, "Speech-only landing missed a phrase"); } int main(int argc, char** argv) { try { if (argc != 6 && argc != 9) throw std::runtime_error("Usage: run-ssc SYSTEM_ROM DISK_ROM PIC_ROM SPEECH_ROM QUAL.BIN [LANDER.BIN LANDER.DSK WAV_DIRECTORY]"); const auto system = readFile(argv[1]), diskRom = readFile(argv[2]), speech = readFile(argv[4]); auto chips = readFile(argv[3]); require(chips.size() == 4096 && speech.size() == 2048, "SSC needs both exact size chip images"); chips.insert(chips.end(), speech.begin(), speech.end()); const auto guest = readFile(argv[5]); for (auto cpu : {Processor::MC6809, Processor::HD6309}) { const std::string label = cpu == Processor::MC6809 ? "6809" : "6309"; for (auto device : {std::shared_ptr{}, std::make_shared(), std::make_shared(chips)}) { Session run(cpu, system, diskRom, device); checkGuest(run, guest, device && device->ready()); } std::cout << "PASS " << label << " absence, missing firmware, two phrases, joystick, tones and noise\n"; if (argc == 9) { const auto binary = readFile(argv[6]); for (int setup = 0; setup < 3; ++setup) { auto speechOnly = setup == 1 ? std::make_shared(chips) : nullptr; Session optional(cpu, system, diskRom, speechOnly, setup == 2); checkOptionalCartridges(optional, binary, setup == 2); } std::cout << "PASS " << label << " disk-only, speech-only and stereo-only landings and BASIC return\n"; fs::create_directories(argv[8]); for (bool bootDisk : {false, true}) { Session run(cpu, system, diskRom, std::make_shared(chips), true); const auto file = "talking-lander-" + label + (bootDisk ? "-disk.wav" : "-direct.wav"); checkLander(run, readFile(argv[6]), readFile(argv[7]), bootDisk, fs::path(argv[8]) / file); } } } } catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; } }