Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

@@ -0,0 +1,48 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Run the Orchestra-90 background player and Stereo Flyby on the emulated CoCo."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path)
parser.add_argument("core", type=Path)
parser.add_argument("roms", type=Path)
parser.add_argument("--capture", type=Path, help="write the optimized 6809 live display to a PNG")
parser.add_argument("--audio", type=Path, help="write the corresponding 44.1 kHz stereo recording")
args = parser.parse_args()
runtime, core, roms = (p.resolve(strict=True) for p in (args.runtime, args.core, args.roms))
fixture = Path(__file__).resolve().parent
repo = fixture.parents[2]
env = dict(os.environ, PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"], VCC_CMOC_COMPAT="0")
with tempfile.TemporaryDirectory(prefix="vcc-stereo-flyby-") as temp:
work = Path(temp)
def run(*cmd):
subprocess.run(cmd, cwd=work, env=env, check=True)
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
"-I", repo / "src", fixture / "run.cpp", core, "-o", "run")
for opt in ("-O0", "-O2"):
run(runtime / "bin/cmoc", "--coco", "--org=2800", opt, "-Werror", "-o", "QUAL.BIN",
fixture / "qualification.c", "-lorch90")
run(runtime / "bin/cmoc", "--coco", "--org=2800", opt, "-Werror", "-o", "FLYBY.BIN",
repo / "examples/cmoc/manual/flyby.c", "-lorch90", "-linput", "-lbcontrol")
shutil.copyfile(repo / "docs/manuals/software-storage-and-peripherals/media/BLANK.DSK", work / "VOL.DSK")
run(runtime / "bin/writecocofile", "VOL.DSK", "FLYBY.BIN")
capture = opt == "-O2" and (args.capture or args.audio)
print(f"Checking {opt}", flush=True)
run("./run", roms, *(["capture"] if capture else []))
if capture and args.capture:
run("sips", "-s", "format", "png", "flyby.ppm", "--out", args.capture.resolve())
if capture and args.audio:
shutil.copyfile(work / "flyby.wav", args.audio.resolve())
if __name__ == "__main__":
main()
@@ -0,0 +1,183 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <cmoc.h>
#include <coco.h>
#include <vcc/orch90.h>
#define COUNT 512
#define CHECK(test) do { if (!(test)) { printf("FAIL LINE %u\n", (unsigned)__LINE__); return 1; } } while (0)
static struct orch90_frame source[COUNT];
static byte savedVector[3];
asm byte interruptMasks(void)
{
asm {
tfr cc,b
andb #$50
}
}
// Same timed instruction loop before and after playback, starting at a
// vertical sync. This detects returning to BASIC at twice/half its old speed.
asm unsigned int speedProbe(void)
{
asm {
sync
ldd >$0112
addd #3
ldx #0
@count leax 1,x
cmpd >$0112
bne @count
tfr x,d
}
}
static byte refusedForeignVector(byte clock)
{
// JMP $010C reaches the same handler as BASIC's stock LBRA $010C.
// It is safe to execute yet a visibly different owner's vector.
byte result;
asm("orcc", "#$10");
*(byte *)0xfef7 = 0x7e;
*(unsigned *)0xfef8 = 0x010c;
asm("andcc", "#$ef");
result = !orch90_start(source, COUNT, 0, clock);
asm("orcc", "#$10");
memcpy((void *)0xfef7, savedVector, sizeof(savedVector));
asm("andcc", "#$ef");
return result;
}
asm byte control(void)
{
asm {
ldb >$ff01
andb #$3f
}
}
// Keep the stock IRQ entry, but give the already enabled HSYNC source a
// temporary consumer. A refused start must leave this user's PIA bit alone.
static asm __norts__ void occupiedHS(void)
{
asm {
tst >$ff00
tst >$ff02
rti
}
}
static byte refusedBusyHS(byte clock)
{
byte normalControl = control(), jump[3], result;
setHighSpeed(TRUE);
asm { sync }
asm { sync }
asm("orcc", "#$10");
memcpy(jump, (const void *)0x010c, 3);
*(byte *)0x010c = 0x7e;
*(unsigned *)0x010d = (unsigned)occupiedHS;
*(byte *)0xff01 = normalControl | 1;
asm("andcc", "#$ef");
result = !orch90_start(source, COUNT, 0, ORCH90_CLOCK_FAST);
asm("orcc", "#$10");
if (!(control() & 1)) result = 0;
*(byte *)0xff01 = normalControl;
memcpy((void *)0x010c, jump, 3);
asm("andcc", "#$ef");
setHighSpeed(clock == ORCH90_CLOCK_FAST);
return result;
}
int main(void)
{
byte clock, masks, initial, vertical, changed, status;
unsigned i, before, after, ticks, work = 0;
printf("SELECT CLOCK\n");
clock = waitkey(FALSE) == '2' ? ORCH90_CLOCK_FAST : ORCH90_CLOCK_NORMAL;
setHighSpeed(clock == ORCH90_CLOCK_FAST);
before = speedProbe();
initial = control();
masks = interruptMasks();
memcpy(savedVector, (const void *)0xfef7, sizeof(savedVector));
for (i = 0; i < COUNT; ++i) {
byte level = (i & 8) ? 64 : 192;
source[i].left = i < COUNT / 2 ? level : 128;
source[i].right = i >= COUNT / 2 ? level : 128;
}
orch90_write(19, 235);
CHECK(!orch90_active());
orch90_stop(); // Idle stop must leave another producer's DACs alone.
CHECK(!orch90_start(0, 1, 0, clock));
CHECK(!orch90_start(source, 0, 0, clock));
CHECK(!orch90_start((const struct orch90_frame *)0xffff, 1, 0, clock));
CHECK(!orch90_start(source, 1, 2, clock));
CHECK(!orch90_start(source, 1, 0, 2));
asm("orcc", "#$10");
status = orch90_start(source, COUNT, 0, clock);
asm("andcc", "#$ef");
CHECK(!status);
CHECK(refusedForeignVector(clock));
CHECK(refusedBusyHS(clock));
*(byte *)0xff01 = initial & 0x3b; // The data address now selects a DDR.
status = orch90_start(source, COUNT, 0, clock);
*(byte *)0xff01 = initial;
CHECK(!status);
vertical = *(byte *)0xff03 & 63;
*(byte *)0xff03 = vertical & 0x3e; // VSYNC disabled: arming would hang.
status = orch90_start(source, COUNT, 0, clock);
*(byte *)0xff03 = vertical;
CHECK(!status);
CHECK(!orch90_active());
CHECK(control() == initial && interruptMasks() == masks);
CHECK(!memcmp(savedVector, (const void *)0xfef7, sizeof(savedVector)));
// Before the second VSYNC arms HSYNC, cancellation releases the vector
// without reading any sample or leaving the clock at the borrowed speed.
CHECK(orch90_start(source, COUNT, 1, clock));
CHECK(orch90_active());
orch90_stop();
CHECK(!orch90_active() && control() == initial);
CHECK(!memcmp(savedVector, (const void *)0xfef7, sizeof(savedVector)));
after = speedProbe();
CHECK(after > before - before / 8 && after < before + before / 8);
ticks = getTimer();
CHECK(orch90_start(source, COUNT, 0, clock));
CHECK(!orch90_start(source, 1, 1, clock));
while (orch90_active()) ++work;
CHECK(work > 16 && (unsigned)(getTimer() - ticks) >= 4);
CHECK(!memcmp(savedVector, (const void *)0xfef7, sizeof(savedVector)));
CHECK(control() == initial && interruptMasks() == masks);
after = speedProbe();
CHECK(after > before - before / 8 && after < before + before / 8);
// A one-frame clip completes and a subsequent loop can be stopped at will.
CHECK(orch90_start(source, 1, 0, clock));
while (orch90_active()) {}
CHECK(orch90_start(source, 16, 1, clock));
ticks = getTimer();
while ((unsigned)(getTimer() - ticks) < 6) ++work;
CHECK(orch90_active());
asm("orcc", "#$50");
changed = initial ^ 8;
*(byte *)0xff01 = changed | 1; // Foreground changed a PIA field it still owns.
orch90_stop();
CHECK(interruptMasks() == 0x50 && control() == changed);
*(byte *)0xff01 = initial;
asm {
lda :masks
tfr a,cc
}
orch90_stop();
CHECK(!orch90_active());
CHECK(!memcmp(savedVector, (const void *)0xfef7, sizeof(savedVector)));
CHECK(control() == initial && interruptMasks() == masks);
after = speedProbe();
CHECK(after > before - before / 8 && after < before + before / 8);
orch90_write(21, 233);
setHighSpeed(FALSE);
printf("RESTORED\n");
return 0;
}
+196
View File
@@ -0,0 +1,196 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "../ssc/session.h"
#include "../guest-captures.h"
// Observe the actual guest writes in a spare MPI slot. The Orchestra-90 in a
// different slot supplies every host audio sample independently of this probe.
struct DacLog final : CartridgeDevice {
struct Write { unsigned audioTick; unsigned char port, value; };
std::vector<Write> writes;
unsigned audioTick = 0;
void reset() override { writes.clear(); audioTick = 0; }
void horizontalSync(DeviceHost&) override {}
void advanceAudio() override { ++audioTick; }
std::uint8_t readMemory(std::uint16_t) const override { return 0xff; }
std::uint8_t readPort(std::uint8_t, DeviceHost&) override { return 0; }
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost&) override {
if (port == 0x7a || port == 0x7b) writes.push_back({audioTick, port, value});
}
};
static void frames(Session& session, unsigned count) {
for (unsigned i = 0; i < count; ++i) session.tick();
}
static void verifyBasic(Session& session) {
session.until("OK", 180);
frames(session, 12);
session.press(47, true); session.press(39); session.press(43, true);
session.press(35); session.press(48); // ?7+3
session.until(" 10");
}
struct Pair { unsigned tick; unsigned char left, right; };
static std::vector<Pair> pairs(const DacLog& log) {
std::vector<Pair> result;
require(log.writes.size() % 2 == 0, "An incomplete stereo DAC pair");
for (std::size_t i = 0; i < log.writes.size(); i += 2) {
const auto& l = log.writes[i];
const auto& r = log.writes[i + 1];
require(l.port == 0x7a && r.port == 0x7b, "DAC writes out of stereo order");
result.push_back({l.audioTick, l.value, r.value});
}
return result;
}
static double measuredRate(std::size_t intervals, unsigned audioTicks) {
require(audioTicks != 0, "Elapsed audio ticks must be positive");
return 44100.0 * intervals / audioTicks;
}
static void qualify(Session& run, DacLog& log, bool fast) {
run.launch(readFile("QUAL.BIN"));
run.until("SELECT CLOCK");
log.writes.clear();
run.press(fast ? 34 : 33);
run.until("RESTORED", 240);
const auto writes = pairs(log);
require(writes.size() > 518, "One-shot or loop failed to write frames");
require(writes[0].left == 19 && writes[0].right == 235, "Missing fixture DAC marker");
require(writes[1].left == 128 && writes[1].right == 128, "Cancelled startup emitted a sample");
for (unsigned i = 0; i < 512; ++i) {
auto level = (i & 8) ? 64 : 192;
require(writes[i + 2].left == (i < 256 ? level : 128) &&
writes[i + 2].right == (i < 256 ? 128 : level), "One-shot frames dropped, reordered or distorted");
}
require(writes[514].left == 128 && writes[514].right == 128, "Natural end left a DAC on");
require(writes[515].left == 192 && writes[515].right == 128 &&
writes[516].left == 128 && writes[516].right == 128, "Single-frame replay failed");
const auto count = writes.size();
require(writes[count - 1].left == 21 && writes[count - 1].right == 233, "Missing final DAC marker");
require(writes[count - 2].left == 128 && writes[count - 2].right == 128, "Manual stop left a DAC on");
for (unsigned i = 517; i + 2 < count; ++i) {
auto level = ((i - 517) & 8) ? 64 : 192;
require(writes[i].left == level && writes[i].right == 128, "Loop boundary or frame mismatch");
}
const auto rate = measuredRate(511, writes[513].tick - writes[2].tick);
require(rate > 3600 && rate < 4050, "Quiet foreground sample rate: " + std::to_string(rate));
std::cout << " " << (fast ? "fast" : "normal") << " entry, " << rate
<< " frames/s, CPU speed and interrupts restored\n";
verifyBasic(run);
}
// Look at the real text scanout so a frozen picture can't pass as animation.
static int marker(Session& run, unsigned row, char symbol) {
const auto screen = run.machine.copyScreenText();
std::size_t start = 0;
for (unsigned i = 0; i < row; ++i) {
auto next = screen.find('\n', start);
if (next == std::string::npos) return -1;
start = next + 1;
}
const auto end = screen.find('\n', start);
auto column = screen.substr(start, end - start).find(symbol);
return column == std::string::npos ? -1 : int(column);
}
static void bookExercise(Session& run, DacLog& log, bool disk, bool capture, bool installed = true) {
if (disk) run.diskExec(readFile("VOL.DSK"), "FLYBY");
else run.launch(readFile("FLYBY.BIN"));
run.until("STEREO FLYBY", 1200);
for (unsigned i = 0; i < 180 && marker(run, 10, '^') != 15; ++i) run.tick();
require(marker(run, 10, '^') == 15, "Ship did not appear at its starting position");
run.press(33);
run.until("BEACON ON AIR", 240);
run.machine.setJoystick(0, 16383, 8191, 0, 0);
const auto logsBefore = log.writes.size();
const auto originalTick = log.audioTick;
run.audio.clear();
int firstStar = marker(run, 8, '*');
bool moved = false;
for (unsigned f = 0; f < 120; ++f) {
run.tick();
int star = marker(run, 8, '*');
if (star >= 2 && firstStar >= 2 && star != firstStar) moved = true;
}
require(moved && marker(run, 10, '^') >= 28, "Star or joystick-controlled ship stalled during sound");
run.machine.setJoystick(0, 8191, 8191, 0, 0);
const double rate = measuredRate((log.writes.size() - logsBefore) / 2, log.audioTick - originalTick);
require(rate > 3450 && rate < 4050, "Active foreground sample rate: " + std::to_string(rate));
std::size_t channelFrames[2] = {}, periods[2] = {}, elapsed[2] = {}, last[2] = {};
bool high[2] = {};
for (std::size_t i = 0; i < run.audio.size(); ++i) {
const auto sample = run.audio[i];
if (!installed) {
require(sample.left == sample.right, "Unexpected stereo with cartridge absent");
continue;
}
const float levels[] = {sample.left, sample.right};
require(sample.left == 0.5f || sample.right == 0.5f, "A stereo note crossed or dropped out");
for (unsigned side = 0; side < 2; ++side) {
channelFrames[side] += std::abs(levels[side] - 0.5f) > 0.04f;
bool nowHigh = levels[side] > 0.55f;
if (nowHigh && !high[side]) {
auto distance = i - last[side];
// The loop has silent gaps between its two notes. Count only
// adjacent waveform periods inside one note, ignoring gaps.
if (last[side] && distance < 300) {
++periods[side];
elapsed[side] += distance;
}
last[side] = i;
}
high[side] = nowHigh;
}
}
if (installed) {
for (unsigned side = 0; side < 2; ++side) {
require(channelFrames[side] > 2000 && periods[side] > 30, "Missing stereo cycles");
const double frequency = 44100.0 * periods[side] / elapsed[side];
const double expected = rate / (side ? 8 : 16);
require(std::abs(frequency - expected) < expected * 0.05, "Incorrect stereo note pitch");
std::cout << (side ? "right " : " left ") << frequency << " Hz ";
}
std::cout << '\n';
}
if (capture) {
BasicDiskTests::saveActiveFrame(*run.machine.snapshot().frame, "flyby.ppm");
saveWav("flyby.wav", run.audio);
}
run.press(17);
run.until("FLYBY COMPLETE");
const auto stopped = log.writes.size();
verifyBasic(run);
require(log.writes.size() == stopped, "Background writes continued after BASIC regained control");
if (disk) require(run.floppy->readEvents(0) > 0 && run.floppy->writeEvents(0) == 0, "Unexpected demo disk I/O");
std::cout << " " << (installed ? "stereo" : "absent") << " " << (disk ? "disk" : "direct")
<< ", steering/animation: " << rate << " frames/s\n";
}
int main(int argc, char** argv) {
try {
require(argc == 2 || argc == 3, "Usage: run ROM_DIRECTORY [capture]");
const fs::path rom(argv[1]);
const auto system = readFile(rom / "coco3.rom"), disk = readFile(rom / "disk11.rom");
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
std::cout << (cpu == Processor::MC6809 ? "6809" : "6309") << std::endl;
for (bool fast : {false, true}) {
auto log = std::make_shared<DacLog>();
Session guest(cpu, system, disk, nullptr, true, log);
qualify(guest, *log, fast);
}
for (bool fromDisk : {false, true}) {
auto log = std::make_shared<DacLog>();
Session guest(cpu, system, disk, nullptr, true, log);
bookExercise(guest, *log, fromDisk, argc == 3 && cpu == Processor::MC6809 && !fromDisk);
}
auto log = std::make_shared<DacLog>();
Session absent(cpu, system, disk, nullptr, false, log);
bookExercise(absent, *log, false, false, false);
}
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return 1;
}
}