Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,35 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Run the Speech/Sound C API fixture on both guest CPUs with private local ROMs."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("runtime", type=Path, help="staged Toolchain directory containing libssc.a")
|
||||
parser.add_argument("core", type=Path, help="current libVCCCore.a")
|
||||
parser.add_argument("roms", type=Path, help="directory with CoCo 3, Disk BASIC, PIC and speech ROMs")
|
||||
parser.add_argument("--lander", type=Path, help="also run LANDER.bin and LANDER.dsk from this directory")
|
||||
parser.add_argument("--captures", type=Path, help="directory for the Lander stereo WAVs (requires --lander)")
|
||||
args = parser.parse_args()
|
||||
if bool(args.lander) != bool(args.captures):
|
||||
parser.error("--lander and --captures must be supplied together")
|
||||
fixture = Path(__file__).resolve().parent
|
||||
roms = args.roms.resolve()
|
||||
with tempfile.TemporaryDirectory(prefix="vcc-ssc-") as work:
|
||||
subprocess.run([args.runtime.resolve() / "bin/cmoc", "--coco", "-O2", "-Werror", "-o", "QUAL.BIN",
|
||||
fixture / "qualification.c", "-lssc"], cwd=work, check=True)
|
||||
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
|
||||
fixture / "run.cpp", args.core.resolve(), "-o", "run-ssc"], cwd=work, check=True)
|
||||
command = ["./run-ssc", roms / "coco3.rom", roms / "disk11.rom", roms / "pic-7040-510.bin",
|
||||
roms / "sp0256-al2.bin", "QUAL.BIN"]
|
||||
if args.lander:
|
||||
project = args.lander.resolve()
|
||||
command.extend([project / "LANDER.bin", project / "LANDER.dsk", args.captures.resolve()])
|
||||
subprocess.run(command, cwd=work, check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,86 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Run with the accompanying host fixture, once with and once without firmware.
|
||||
#include <coco.h>
|
||||
#include <cmoc.h>
|
||||
#include <vcc/ssc.h>
|
||||
|
||||
static void wait_ticks(unsigned int count)
|
||||
{
|
||||
unsigned int start = getTimer();
|
||||
while ((unsigned int)(getTimer() - start) < count) {
|
||||
asm { nop }
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ssc_phrase phrase;
|
||||
unsigned int start, saved;
|
||||
unsigned char result, saw_input = 0;
|
||||
unsigned char low = *(unsigned char *)0xFF01 & 63;
|
||||
unsigned char high = *(unsigned char *)0xFF03 & 63;
|
||||
unsigned char sound = *(unsigned char *)0xFF23 & 63;
|
||||
|
||||
if (ssc_begin_phrase(&phrase, "") != SSC_INVALID ||
|
||||
ssc_begin_phrase(&phrase, "123456789012345678901234567890123456789012345678901234567890123") != SSC_INVALID ||
|
||||
ssc_begin_phrase(&phrase, "BAD\rDATA") != SSC_INVALID ||
|
||||
ssc_say("TEST", 0) != SSC_TIMEOUT ||
|
||||
ssc_play_effect(3, 1, 15, 2, 100) != SSC_INVALID ||
|
||||
ssc_play_noise(0, 32, 15, 2, 100) != SSC_INVALID)
|
||||
return 1;
|
||||
|
||||
saved = ssc_route_audio();
|
||||
if ((*(unsigned char *)0xFF01 & 63) != ((low & 7) | 0x30) ||
|
||||
(*(unsigned char *)0xFF03 & 63) != ((high & 7) | 0x38) ||
|
||||
(*(unsigned char *)0xFF23 & 63) != ((sound & 7) | 0x38))
|
||||
return 2;
|
||||
ssc_restore_audio(saved);
|
||||
if ((*(unsigned char *)0xFF01 & 63) != low || (*(unsigned char *)0xFF03 & 63) != high ||
|
||||
(*(unsigned char *)0xFF23 & 63) != sound)
|
||||
return 3;
|
||||
|
||||
saved = ssc_route_audio();
|
||||
result = ssc_say("blue planet earth", 8192);
|
||||
if (result == SSC_TIMEOUT) {
|
||||
printf("SSC UNAVAILABLE\n");
|
||||
ssc_restore_audio(saved);
|
||||
return 0;
|
||||
}
|
||||
if (result != SSC_OK)
|
||||
return 4;
|
||||
printf("FIRST SUBMITTED\n");
|
||||
start = getTimer();
|
||||
while ((unsigned int)(getTimer() - start) < 180) {
|
||||
if (!(ssc_status() & SSC_SPEECH_IDLE) && !(readJoystickButtons() & JOYSTK_BUTTON_1_RIGHT)) {
|
||||
if (readJoystickPositions()[JOYSTK_RIGHT_HORIZ] > 50)
|
||||
saw_input = 1;
|
||||
ssc_route_audio();
|
||||
}
|
||||
}
|
||||
if (!saw_input)
|
||||
return 5;
|
||||
printf("INPUT DURING SPEECH\n");
|
||||
if (ssc_begin_phrase(&phrase, "cold red mars") != SSC_OK)
|
||||
return 6;
|
||||
start = getTimer();
|
||||
while ((result = ssc_service(&phrase)) == SSC_PENDING) {
|
||||
if ((unsigned int)(getTimer() - start) >= 120)
|
||||
return 7;
|
||||
}
|
||||
if (result != SSC_OK || ssc_service(&phrase) != SSC_OK)
|
||||
return 8;
|
||||
printf("SECOND SUBMITTED\n");
|
||||
wait_ticks(180);
|
||||
|
||||
printf("TONE TEST\n");
|
||||
if (ssc_play_effect(0, 250, 12, 8, 8192) != SSC_OK)
|
||||
return 9;
|
||||
wait_ticks(60);
|
||||
printf("NOISE TEST\n");
|
||||
if (ssc_play_noise(2, 16, 12, 8, 8192) != SSC_OK)
|
||||
return 10;
|
||||
wait_ticks(60);
|
||||
ssc_restore_audio(saved);
|
||||
printf("SSC API PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// 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<SpeechSoundDevice>{}, std::make_shared<SpeechSoundDevice>(),
|
||||
std::make_shared<SpeechSoundDevice>(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<SpeechSoundDevice>(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<SpeechSoundDevice>(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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
// Real ROM boot, CMOC development launch, PIA input and guest audio.
|
||||
#include "../../../src/core/MachineSession.h"
|
||||
#include "../../../src/devices/FD502/Fd502Device.h"
|
||||
#include "../../../src/devices/SpeechSoundDevice.h"
|
||||
#include "../../../src/devices/Orchestra90Device.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace VCC::Mac;
|
||||
using namespace VCC::Devices;
|
||||
namespace fs = std::filesystem;
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
|
||||
static Bytes readFile(const fs::path& path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
if (!file) throw std::runtime_error("Cannot open " + path.string());
|
||||
return {std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
|
||||
}
|
||||
|
||||
static void require(bool condition, const std::string& message) {
|
||||
if (!condition) throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
struct Session {
|
||||
MachineSession machine;
|
||||
std::shared_ptr<Fd502Device> floppy;
|
||||
std::shared_ptr<SpeechSoundDevice> ssc;
|
||||
std::vector<StereoSample> audio;
|
||||
|
||||
Session(Processor cpu, const Bytes& system, const Bytes& diskRom,
|
||||
std::shared_ptr<SpeechSoundDevice> cartridge, bool useOrchestra = false,
|
||||
std::shared_ptr<CartridgeDevice> observer = nullptr)
|
||||
: floppy(std::make_shared<Fd502Device>(diskRom)), ssc(std::move(cartridge)) {
|
||||
auto orchestra = useOrchestra ? std::make_shared<Orchestra90Device>() : nullptr;
|
||||
machine.cartridges().configure({nullptr, ssc, orchestra, observer, floppy}, true, 4);
|
||||
machine.load(system, cpu);
|
||||
machine.resume();
|
||||
for (unsigned n = 0; n < 180; ++n) machine.advance();
|
||||
machine.takeAudio();
|
||||
require(contains("DISK EXTENDED"), "FD-502 in startup slot 4 did not boot Disk BASIC");
|
||||
}
|
||||
|
||||
bool contains(const std::string& text) { return machine.copyScreenText().find(text) != std::string::npos; }
|
||||
void tick() {
|
||||
machine.advance();
|
||||
auto samples = machine.takeAudio();
|
||||
audio.insert(audio.end(), samples.begin(), samples.end());
|
||||
}
|
||||
void until(const std::string& text, unsigned maxFrames = 360) {
|
||||
for (unsigned i = 0; i < maxFrames; ++i) {
|
||||
if (contains(text)) return;
|
||||
tick();
|
||||
}
|
||||
throw std::runtime_error("Timed out waiting for " + text + "\n" + machine.copyScreenText());
|
||||
}
|
||||
void launch(const Bytes& binary) {
|
||||
require(binary.size() >= 5, "Incomplete binary");
|
||||
auto entry = std::uint16_t(binary[binary.size() - 2] << 8 | binary.back());
|
||||
machine.debuggerLoadBinary(binary, entry);
|
||||
machine.debuggerClearDevelopmentBreakpoints();
|
||||
machine.resume();
|
||||
}
|
||||
void press(unsigned bit, bool shift = false) {
|
||||
machine.setKeyboard((std::uint64_t{1} << bit) | (std::uint64_t(shift) << 55));
|
||||
for (int i = 0; i < 6; ++i) tick();
|
||||
machine.setKeyboard(0);
|
||||
for (int i = 0; i < 6; ++i) tick();
|
||||
}
|
||||
void diskExec(const Bytes& disk, const std::string& basename) {
|
||||
floppy->mount(0, DiskImage::load(disk, true));
|
||||
for (char c : "LOADM\"" + basename + "\":EXEC\r") {
|
||||
if (c == '"') press(34, true);
|
||||
else if (c == ':') press(42);
|
||||
else if (c == '\r') press(48);
|
||||
else if (c >= 'A' && c <= 'Z') press(c - '@');
|
||||
else throw std::logic_error("Unsupported fixture key");
|
||||
}
|
||||
}
|
||||
void checkSignal(std::size_t from) const {
|
||||
require(from < audio.size(), "Missing PCM samples");
|
||||
auto range = std::minmax_element(audio.begin() + from, audio.end(),
|
||||
[](auto a, auto b) { return a.left < b.left; });
|
||||
require(range.second->left - range.first->left > 0.02f, "Expected audible output");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void saveWav(const fs::path& path, const std::vector<StereoSample>& pcm) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
auto little = [&](unsigned value, unsigned bytes) {
|
||||
while (bytes--) { file.put(char(value)); value >>= 8; }
|
||||
};
|
||||
const unsigned size = unsigned(pcm.size()) * 4;
|
||||
file.write("RIFF", 4); little(36 + size, 4); file.write("WAVEfmt ", 8);
|
||||
little(16, 4); little(1, 2); little(2, 2); little(44100, 4); little(176400, 4);
|
||||
little(4, 2); little(16, 2); file.write("data", 4); little(size, 4);
|
||||
for (auto sample : pcm) {
|
||||
for (float value : {sample.left, sample.right}) {
|
||||
const auto converted = std::lround(value * 32767.0f);
|
||||
little(static_cast<std::uint16_t>(std::clamp(converted, -32768l, 32767l)), 2);
|
||||
}
|
||||
}
|
||||
if (!file) throw std::runtime_error("Cannot save " + path.string());
|
||||
}
|
||||
Reference in new issue
Block a user