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

+41
View File
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Run banked-memory transfers in the emulator on both CPUs at every RAM setting."""
import argparse
import os
import re
from pathlib import Path
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path, help="staged guest toolchain containing libbank.a")
parser.add_argument("core", type=Path, help="current libVCCCore.a")
parser.add_argument("rom", type=Path, help="local CoCo 3 ROM")
args = parser.parse_args()
runtime = args.runtime.resolve(strict=True)
fixture = Path(__file__).resolve().parent
env = dict(os.environ, PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"])
with tempfile.TemporaryDirectory(prefix="vcc-banked-memory-") as work:
subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
"-I", fixture.parents[2] / "src", fixture / "run.cpp",
args.core.resolve(strict=True), "-o", "check"], cwd=work, check=True)
for optimization in ("-O0", "-O2"):
print("Checking", optimization, flush=True)
layouts = (("QUAL.BIN", ("--org=2800",)),
("SPLIT.BIN", ("--org=3800", "--data=2800")))
for binary, flags in layouts:
subprocess.run([runtime / "bin/cmoc", "--coco", optimization, "--intermediate", "-Werror",
*flags, "-o", binary, fixture / "qualification.c", "-lbank"],
cwd=work, env=env, check=True)
listing = (Path(work) / "QUAL.map").read_text()
symbol = re.search(r"^Symbol: _bank_open \(.+?\) = ([0-9A-F]+)$", listing, re.MULTILINE)
if not symbol:
raise RuntimeError("Missing bank_open in the linker map")
subprocess.run(["./check", args.rom.resolve(strict=True), "QUAL.BIN", symbol[1], "SPLIT.BIN"],
cwd=work, check=True)
if __name__ == "__main__":
main()
+101
View File
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <cmoc.h>
#include <vcc/bank.h>
#define CHECK(test) do { if (!(test)) return __LINE__; } while (0)
#define REG(address) (*(unsigned char *)(address))
static unsigned char buffer[515];
static asm unsigned char interruptMasks(void)
{
asm {
tfr cc,b
andb #$50
}
}
static int exercise(void)
{
unsigned i, boundary;
unsigned char saved, opened, actual;
CHECK(!bank_read(0, buffer, 1) && !bank_write(0, buffer, 1));
if (!bank_open()) {
printf("BANK UNAVAILABLE\n");
return 0;
}
bank_close();
// An inactive task has as much right to an explicit reservation as the active one.
saved = REG(0xffa8);
REG(0xffa8) = BANK_FIRST_PAGE;
opened = bank_open();
actual = REG(0xffa8);
if (opened) bank_close();
REG(0xffa8) = saved;
CHECK(!opened && (actual & 63) == BANK_FIRST_PAGE);
CHECK(bank_open());
CHECK(!bank_open());
// A caller can mask both IRQ and FIRQ for a transfer. Restore the masks
// even if the test fails, before printf or BASIC attempts to use IRQs.
saved = interruptMasks();
asm("orcc", "#$50");
opened = bank_read(0, buffer, 1);
actual = interruptMasks();
asm {
tfr cc,b
andb #$af
orb :saved
tfr b,cc
}
CHECK(opened && actual == 0x50);
CHECK(bank_read(BANK_CAPACITY, NULL, 0) && bank_write(0, NULL, 0));
CHECK(!bank_read(BANK_CAPACITY + 1, NULL, 0));
CHECK(!bank_write(BANK_CAPACITY, buffer, 1));
CHECK(!bank_write(0xffffu, buffer, 2));
CHECK(!bank_write(1, buffer, 0xffffu));
CHECK(!bank_write(17, NULL, 1) && !bank_read(17, NULL, 1));
CHECK(!bank_read(17, (void *)0x21, 1)); // BASIC's stack top
CHECK(!bank_write(17, (void *)0x21, 1));
CHECK(!bank_read(17, (void *)0x2800, 1)); // this binary's entry page
CHECK(!bank_write(17, (const void *)0x7fff, 2));
CHECK(!bank_read(17, (void *)0x8000, 1));
CHECK(!bank_write(17, (const void *)0xfffe, 3));
for (boundary = BANK_PAGE_SIZE; boundary < BANK_CAPACITY; boundary += BANK_PAGE_SIZE) {
// Straddle each boundary with an odd count and protect the two buffer ends.
for (i = 1; i <= 513; ++i)
buffer[i] = (unsigned char)(boundary / BANK_PAGE_SIZE + i);
CHECK(bank_write(boundary - 3, buffer + 1, 513));
memset(buffer, 0xd7, sizeof(buffer));
CHECK(bank_read(boundary - 3, buffer + 1, 513));
CHECK(buffer[0] == 0xd7 && buffer[514] == 0xd7);
for (i = 1; i <= 513; ++i)
CHECK(buffer[i] == (unsigned char)(boundary / BANK_PAGE_SIZE + i));
}
buffer[0] = 0xbd;
CHECK(bank_write(BANK_CAPACITY - 1, buffer, 1));
buffer[0] = 0x44;
CHECK(!bank_write(BANK_CAPACITY - 1, buffer, 2));
memset(buffer, 0xbb, sizeof(buffer));
CHECK(!bank_read(BANK_CAPACITY - 1, buffer, 2));
CHECK(buffer[0] == 0xbb && buffer[1] == 0xbb);
bank_close();
bank_close();
CHECK(!bank_write(0, buffer, 1) && !bank_read(0, buffer, 1));
CHECK(bank_open());
CHECK(bank_read(BANK_CAPACITY - 1, buffer, 1) && buffer[0] == 0xbd);
bank_close();
printf("BANK PASSED\n");
return 0;
}
int main(void)
{
int line = exercise();
if (line) printf("FAIL LINE %d\n", line);
return 0;
}
+158
View File
@@ -0,0 +1,158 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "../basic-disk-session.h"
using namespace BasicDiskTests;
namespace {
constexpr unsigned bankBase = 0x50000;
constexpr unsigned bankSize = 8192;
constexpr unsigned capacity = 4 * bankSize;
bool sameMapping(const VCC::MMUState& before, const VCC::MMUState& after) {
return before.Enabled == after.Enabled && before.ActiveTask == after.ActiveTask &&
before.RamVectors == after.RamVectors && before.RomMap == after.RomMap &&
before.AllRAM == after.AllRAM && before.Prefix == after.Prefix &&
before.Task0 == after.Task0 && before.Task1 == after.Task1;
}
void until(MachineSession& machine, const std::string& message) {
for (unsigned n = 0; n < 1000; ++n) {
const auto screen = machine.copyScreenText();
if (screen.find(message) != screen.npos) return;
if (screen.find("FAIL LINE") != screen.npos) {
for (unsigned i = 0; i < 6; ++i) machine.advance();
throw std::runtime_error(machine.copyScreenText());
}
machine.advance();
machine.takeAudio();
}
throw std::runtime_error("Expected " + message + " on screen: " + machine.copyScreenText());
}
enum class Mapping { basic, taskOne, disabled, splitLayout };
void stopAt(MachineSession& machine, std::uint16_t address) {
machine.debuggerSetBreakpoints({address});
machine.resume();
for (unsigned i = 0; i < 300 && machine.snapshot().state == RunState::Running; ++i)
machine.advance();
require(machine.debuggerSnapshot().cpu.PC == address, "Did not reach bank API breakpoint");
machine.debuggerSetBreakpoints({});
}
// Inject unusual mappings only around bank_open(). BASIC's own screen/IRQ
// handling can program the GIME again after it regains control.
void checkRejectedMapping(MachineSession& machine, Mapping mapping, std::uint16_t open) {
stopAt(machine, open);
const auto before = machine.debuggerSnapshot();
const auto stack = machine.debuggerMemoryRange(before.cpu.S, 2, false).bytes;
const auto caller = std::uint16_t(stack[0] << 8 | stack[1]);
const auto init0 = SafeMemRead8(0xff90);
const auto init1 = SafeMemRead8(0xff91);
if (mapping == Mapping::taskOne) {
// Mirror task 0 to keep the running instructions and stack in place.
for (unsigned i = 0; i < 8; ++i)
MmuWrite8(std::uint8_t(before.mmu.Task0[i]), std::uint16_t(0xffa8 + i));
MmuWrite8(init1 | 1, 0xff91);
} else {
MmuWrite8(init0 & ~0x40, 0xff90);
}
const auto challenged = machine.debuggerSnapshot().mmu;
require(challenged.ActiveTask == (mapping == Mapping::taskOne) &&
challenged.Enabled == (mapping != Mapping::disabled), "Failed to establish test mapping");
stopAt(machine, caller);
const auto after = machine.debuggerSnapshot();
require(sameMapping(challenged, after.mmu), "Rejected open changed custom mapping");
require(after.cpu.B == 0, "Unexpected open with custom mapping");
MmuWrite8(init0, 0xff90);
MmuWrite8(init1, 0xff91);
if (mapping == Mapping::taskOne)
for (unsigned i = 0; i < 8; ++i)
MmuWrite8(std::uint8_t(before.mmu.Task1[i]), std::uint16_t(0xffa8 + i));
}
void qualify(const Bytes& rom, const Bytes& program, Processor cpu, unsigned ram, Mapping mapping, std::uint16_t open) {
MachineConfiguration configuration;
configuration.processor = cpu;
configuration.ram = ram;
MachineSession machine;
machine.configure(configuration);
machine.load(rom, cpu);
machine.resume();
until(machine, "OK");
auto physical = [&](unsigned address, unsigned length) {
return machine.debuggerMemoryRange(address, length, true).bytes;
};
const auto size = program.size();
require(size >= 5 && program[size - 5] == 0xff, "Invalid DECB fixture");
machine.debuggerLoadBinary(program, std::uint16_t(program[size - 2] << 8 | program.back()));
machine.debuggerClearDevelopmentBreakpoints();
const auto initial = machine.debuggerSnapshot().mmu;
const bool supported = ram != 0 && mapping == Mapping::basic;
Bytes expected;
Bytes freeRam, belowProgram;
if (ram != 0) {
// One real physical byte on either side catches off-by-one accesses.
expected = physical(bankBase - 1, capacity + 2);
} else {
// On 128 KiB the asset banks mirror BASIC's physical banks $08..$0B.
// Exclude live BASIC state and the loaded program, starting at $2800.
freeRam = physical(0, 65536);
belowProgram = physical(0x11000, 0x1800);
}
if (supported) {
for (unsigned boundary = bankSize; boundary < capacity; boundary += bankSize) {
for (unsigned i = 1; i <= 513; ++i)
expected[boundary - 3 + i] = std::uint8_t(boundary / bankSize + i);
}
expected[capacity] = 0xbd; // index zero is the lower guard byte
}
if (mapping == Mapping::taskOne || mapping == Mapping::disabled)
checkRejectedMapping(machine, mapping, open);
machine.resume();
until(machine, supported ? "BANK PASSED\nOK" : "BANK UNAVAILABLE\nOK");
require(sameMapping(initial, machine.debuggerSnapshot().mmu), "Guest changed the BASIC MMU map");
if (ram != 0) {
require(physical(bankBase - 1, capacity + 2) == expected,
"A reserved byte or a neighboring physical byte differs from the expected image");
} else {
require(physical(0, 65536) == freeRam && physical(0x11000, 0x1800) == belowProgram,
"RAM changed during a rejected 128 KiB reservation");
}
// Enter PRINT 7*9 through the keyboard matrix after returning from main.
constexpr auto key = [](unsigned bit) { return std::uint64_t(1) << bit; };
machine.paste({key(16), key(18), key(9), key(14), key(20), key(31),
key(39), key(55) | key(42), key(41), key(48)});
until(machine, " 63");
std::cout << "PASS " << (cpu == Processor::MC6809 ? "6809" : "6309") << ", "
<< initial.RAMBytes / 1024 << " KiB: ";
if (mapping == Mapping::taskOne) std::cout << "task 1, ";
if (mapping == Mapping::disabled) std::cout << "MMU disabled, ";
if (mapping == Mapping::splitLayout) std::cout << "writable data below code, ";
std::cout << (supported ? "physical bank contents" : "safe refusal")
<< ", restored MMU and BASIC input\n";
}
} // namespace
int main(int argc, char** argv) {
try {
require(argc == 5, "Usage: bank-check COCO3_ROM QUAL.BIN BANK_OPEN SPLIT.BIN");
const auto rom = readFile(argv[1]);
const auto program = readFile(argv[2]);
const auto split = readFile(argv[4]);
const auto open = std::uint16_t(std::stoul(argv[3], nullptr, 16));
for (auto cpu : {Processor::MC6809, Processor::HD6309}) {
for (unsigned ram = 0; ram < 4; ++ram)
qualify(rom, program, cpu, ram, Mapping::basic, open);
qualify(rom, program, cpu, 1, Mapping::taskOne, open);
qualify(rom, program, cpu, 1, Mapping::disabled, open);
qualify(rom, split, cpu, 1, Mapping::splitLayout, 0);
}
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}