Sync VCC Plus 3.7.1 build 67 source
Refresh reviewed MCP output export, four-drive owned playtests, bounded BASIC readiness, and pinned CMOC 0.1.101 source/patches. Preserve independent source-edition identity, empty libraries, notices and privacy boundaries. Validated 74 export/privacy checks, pinned dependency sources, and an independent unsigned universal Release build. A subsequent documentation-only correction removes an excluded qualification link; all build inputs remain identical.
This commit is contained in:
1 parent
4abc194001
commit
5534005799
54 files changed
+2950
-435
No files matched your search
@@ -281,7 +281,10 @@ class Playtest {
|
||||
}
|
||||
void armStop() { armEvidence(stops, stopModule); }
|
||||
void armInspection() { armEvidence({}, {}); }
|
||||
uint64_t consumed = 0, fieldClock = 0, bootNumber = 0, mediaGeneration = 0;
|
||||
uint64_t consumed = 0, fieldClock = 0, bootNumber = 0;
|
||||
std::array<uint64_t, 4> mediaGenerations{}, mountReadBases{}, mountWriteBases{};
|
||||
bool multiDrive = false, frozenForRetention = false;
|
||||
unsigned drainedDrives = 0;
|
||||
VCCPlaytestVideoWriter *videoWriter = nil;
|
||||
NSMutableDictionary *videoInfo = nil;
|
||||
NSURL *videoDirectory = nil;
|
||||
@@ -332,54 +335,80 @@ class Playtest {
|
||||
else if (fieldClock - videoFirstField >= videoMaximumFields) finishVideo(@"field_limit");
|
||||
}
|
||||
Processor processor = Processor::MC6809;
|
||||
NSString *originalDiskHash = nil, *currentMediaID = nil;
|
||||
NSString *diskHash() const {
|
||||
const auto *image = floppy ? floppy->image(0) : nullptr;
|
||||
NSMutableArray *originalDiskHashes = [NSMutableArray arrayWithObjects:@"", @"", @"", @"", nil];
|
||||
NSMutableArray *currentMediaIDs = [NSMutableArray arrayWithObjects:NSNull.null, NSNull.null, NSNull.null, NSNull.null, nil];
|
||||
NSString *mediaID(unsigned drive) const {
|
||||
id value = currentMediaIDs[drive];
|
||||
return [value isKindOfClass:NSString.class] ? value : nil;
|
||||
}
|
||||
NSString *diskHash(unsigned drive = 0) const {
|
||||
const auto *image = floppy ? floppy->image(drive) : nullptr;
|
||||
return image ? sha256(image->bytes()) : @"";
|
||||
}
|
||||
NSDictionary *driveStatus(unsigned drive) const {
|
||||
const auto *image = floppy->image(drive);
|
||||
return @{@"drive": @(drive), @"label": [NSString stringWithFormat:@"FD%u", drive],
|
||||
@"inserted": @(image != nullptr), @"disk_present": @(image != nullptr),
|
||||
@"media_id": mediaID(drive) ?: (id)NSNull.null,
|
||||
@"disk_original_sha256": originalDiskHashes[drive], @"disk_sha256": diskHash(drive),
|
||||
@"media_generation": @(mediaGenerations[drive]), @"byte_count": @(image ? image->bytes().size() : 0),
|
||||
@"disk_dirty": @(image && image->dirty()), @"write_protected": @(image && image->writeProtected()),
|
||||
@"disk_reads": @(floppy->readEvents(drive)), @"disk_writes": @(floppy->writeEvents(drive)),
|
||||
@"mount_read_bytes": @(floppy->readEvents(drive) - mountReadBases[drive]),
|
||||
@"mount_write_bytes": @(floppy->writeEvents(drive) - mountWriteBases[drive])};
|
||||
}
|
||||
void requireMediaExchangeState() const {
|
||||
if (machine->snapshot().state != RunState::Paused) throw std::runtime_error("playtest_not_stopped");
|
||||
// Motor activity or previously written bytes do not mean a transfer is
|
||||
// pending. Only the actual FDC busy state prevents a disk exchange.
|
||||
// A pending command on ANY drive protects the shared controller.
|
||||
if (floppy->snapshot().busy) throw std::runtime_error("playtest_media_busy");
|
||||
}
|
||||
NSDictionary *exportMedia() const {
|
||||
requireMediaExchangeState();
|
||||
NSDictionary *exportMedia(unsigned drive = 0) {
|
||||
if (!frozenForRetention) requireMediaExchangeState();
|
||||
NSMutableDictionary *out = [status() mutableCopy];
|
||||
if (const auto *image = floppy->image(0)) {
|
||||
if (multiDrive) out[@"exported_drive"] = driveStatus(drive);
|
||||
if (const auto *image = floppy->image(drive)) {
|
||||
const auto& data = image->bytes();
|
||||
out[@"disk_base64"] = [[NSData dataWithBytes:data.data() length:data.size()] base64EncodedStringWithOptions:0];
|
||||
}
|
||||
if (frozenForRetention) drainedDrives |= 1u << drive;
|
||||
return out;
|
||||
}
|
||||
NSDictionary *exchangeMedia(NSDictionary *request) {
|
||||
const unsigned drive = request[@"drive"] ? number(request[@"drive"], 0, 3) : 0;
|
||||
for (NSString *key in request)
|
||||
if (![@[@"op", @"expected_media_generation", @"expected_disk_sha256", @"media_id", @"disk_base64"] containsObject:key])
|
||||
throw std::invalid_argument("invalid_arguments");
|
||||
if (![@[@"op", @"expected_media_generation", @"expected_disk_sha256", @"media_id", @"disk_base64",
|
||||
@"drive", @"write_protected"] containsObject:key]) throw std::invalid_argument("invalid_arguments");
|
||||
if (!multiDrive && request[@"drive"]) throw std::invalid_argument("invalid_arguments");
|
||||
const bool inserting = request[@"media_id"] != nil;
|
||||
if ((request[@"disk_base64"] != nil) != inserting || request.count != (inserting ? 5u : 3u))
|
||||
const NSUInteger optional = (request[@"drive"] ? 1 : 0) + (request[@"write_protected"] ? 1 : 0);
|
||||
if ((request[@"disk_base64"] != nil) != inserting || request.count != (inserting ? 5u : 3u) + optional ||
|
||||
(!inserting && request[@"write_protected"])) throw std::invalid_argument("invalid_arguments");
|
||||
if (request[@"write_protected"] && CFGetTypeID((__bridge CFTypeRef)request[@"write_protected"]) != CFBooleanGetTypeID())
|
||||
throw std::invalid_argument("invalid_arguments");
|
||||
const auto expected = number(request[@"expected_media_generation"], 0, INT32_MAX);
|
||||
if (![request[@"expected_disk_sha256"] isKindOfClass:NSString.class]) throw std::invalid_argument("invalid_arguments");
|
||||
NSString *nextID = nil;
|
||||
std::optional<VCC::Devices::DiskImage> replacement;
|
||||
// Complete container validation and allocation precede any change to
|
||||
// mounted media. Invalid images cannot eject or replace the old disk.
|
||||
// Validate container and effective protection before changing any drive.
|
||||
if (inserting) {
|
||||
nextID = mediaIdentifier(request[@"media_id"]);
|
||||
replacement.emplace(VCC::Devices::DiskImage::load(bytes(request[@"disk_base64"], maximumDiskBytes)));
|
||||
for (unsigned other = 0; other < 4; ++other)
|
||||
if (other != drive && [nextID isEqual:mediaID(other)]) throw std::invalid_argument("playtest_media_already_inserted");
|
||||
replacement.emplace(VCC::Devices::DiskImage::load(bytes(request[@"disk_base64"], maximumDiskBytes),
|
||||
[request[@"write_protected"] boolValue]));
|
||||
}
|
||||
requireMediaExchangeState();
|
||||
NSString *oldHash = diskHash(), *oldID = currentMediaID;
|
||||
if (uint64_t(expected) != mediaGeneration || ![request[@"expected_disk_sha256"] isEqual:oldHash])
|
||||
NSString *oldHash = diskHash(drive), *oldID = mediaID(drive);
|
||||
if (uint64_t(expected) != mediaGenerations[drive] || ![request[@"expected_disk_sha256"] isEqual:oldHash])
|
||||
throw std::runtime_error("stale_media_exchange");
|
||||
if (mediaGeneration == INT32_MAX) throw std::runtime_error("playtest_media_limit");
|
||||
// The parent exports and durably retains the old image first. Explicit
|
||||
// discard only releases this worker's already-retained mounted copy.
|
||||
if (replacement) floppy->mount(0, std::move(*replacement), true);
|
||||
else floppy->eject(0, true);
|
||||
currentMediaID = nextID; originalDiskHash = diskHash(); ++mediaGeneration;
|
||||
if (mediaGenerations[drive] == INT32_MAX) throw std::runtime_error("playtest_media_limit");
|
||||
if (replacement) floppy->mount(drive, std::move(*replacement), true);
|
||||
else floppy->eject(drive, true);
|
||||
currentMediaIDs[drive] = nextID ?: (id)NSNull.null;
|
||||
originalDiskHashes[drive] = diskHash(drive); ++mediaGenerations[drive];
|
||||
mountReadBases[drive] = floppy->readEvents(drive); mountWriteBases[drive] = floppy->writeEvents(drive);
|
||||
NSMutableDictionary *out = [status() mutableCopy];
|
||||
out[@"target_drive"] = @(drive);
|
||||
out[@"previous_media_id"] = oldID ?: (id)NSNull.null;
|
||||
out[@"previous_disk_sha256"] = oldHash;
|
||||
out[@"advances_execution"] = @NO;
|
||||
@@ -420,11 +449,18 @@ class Playtest {
|
||||
@"remaining_boots": @(bootNumber < 16 ? 16 - bootNumber : 0),
|
||||
@"cycles": @(s.cycles), @"generation": @(s.generation), @"pc": @(s.cpu.PC),
|
||||
@"state": s.state == RunState::Paused ? @"paused" : @"running",
|
||||
@"disk_original_sha256": originalDiskHash ?: @"", @"disk_sha256": diskHash(),
|
||||
@"disk_present": @(image != nullptr), @"media_id": currentMediaID ?: (id)NSNull.null,
|
||||
@"media_generation": @(mediaGeneration), @"floppy_busy": @(floppy->snapshot().busy),
|
||||
@"disk_dirty": @(image && image->dirty()), @"disk_reads": @(floppy->readEvents(0)),
|
||||
@"disk_original_sha256": originalDiskHashes[0], @"disk_sha256": diskHash(),
|
||||
@"disk_present": @(image != nullptr), @"media_id": mediaID(0) ?: (id)NSNull.null,
|
||||
@"media_generation": @(mediaGenerations[0]), @"floppy_busy": @(floppy->snapshot().busy),
|
||||
@"disk_dirty": @(image && image->dirty()), @"disk_write_protected": @(image && image->writeProtected()), @"disk_reads": @(floppy->readEvents(0)),
|
||||
@"disk_writes": @(floppy->writeEvents(0)), @"isolated": @YES, @"input":inputMetadata(s) } mutableCopy];
|
||||
if (multiDrive) {
|
||||
NSMutableArray *drives = [NSMutableArray array];
|
||||
for (unsigned drive = 0; drive < 4; ++drive) [drives addObject:driveStatus(drive)];
|
||||
out[@"drives"] = drives; out[@"media_contract_version"] = @2;
|
||||
out[@"drive_activity_units"] = @"transferred_data_bytes";
|
||||
out[@"drive_activity_lifetime"] = @"worker lifetime; mount_* fields reset on each media generation";
|
||||
}
|
||||
if (videoInfo) out[@"video_recording"] = [videoInfo copy];
|
||||
return out;
|
||||
}
|
||||
@@ -499,6 +535,11 @@ public:
|
||||
rom = bytes(r[@"system_rom"], 32768, 32768);
|
||||
auto diskROM = bytes(r[@"disk_rom"], 8192, 8192), disk = bytes(r[@"disk"], maximumDiskBytes);
|
||||
NSString *initialMediaID = mediaIdentifier(r[@"media_id"] ?: @"primary");
|
||||
if (r[@"multi_drive"] && CFGetTypeID((__bridge CFTypeRef)r[@"multi_drive"]) != CFBooleanGetTypeID())
|
||||
throw std::invalid_argument("invalid_arguments");
|
||||
multiDrive = [r[@"multi_drive"] boolValue];
|
||||
if (r[@"write_protected"] && CFGetTypeID((__bridge CFTypeRef)r[@"write_protected"]) != CFBooleanGetTypeID())
|
||||
throw std::invalid_argument("invalid_arguments");
|
||||
NSArray *keys = r[@"boot_keys"];
|
||||
if (![keys isKindOfClass:NSArray.class] || keys.count == 0 || keys.count > 256) throw std::invalid_argument("invalid_boot_keys");
|
||||
for (NSNumber *n in keys) {
|
||||
@@ -598,8 +639,8 @@ public:
|
||||
MachineConfiguration config; config.processor = processor; config.ram = 1; config.frameInterval = 1;
|
||||
machine->configure(config);
|
||||
floppy = std::make_shared<VCC::Devices::Fd502Device>(diskROM);
|
||||
floppy->mount(0,VCC::Devices::DiskImage::load(disk));
|
||||
originalDiskHash = diskHash(); currentMediaID = initialMediaID;
|
||||
floppy->mount(0,VCC::Devices::DiskImage::load(disk, [r[@"write_protected"] boolValue]));
|
||||
originalDiskHashes[0] = diskHash(); currentMediaIDs[0] = initialMediaID;
|
||||
machine->cartridges().configure({nullptr,nullptr,nullptr,nullptr,floppy},true,4);
|
||||
machine->load(rom,processor);
|
||||
for (const auto& buffer : graphicsBuffers)
|
||||
@@ -608,13 +649,21 @@ public:
|
||||
boot(); return status();
|
||||
}
|
||||
if (!machine || stopped) throw std::runtime_error("stale_run");
|
||||
if (frozenForRetention && ![@[@"media_status", @"export_media", @"finish_stop"] containsObject:op])
|
||||
throw std::runtime_error("playtest_retention_pending");
|
||||
if ([op isEqual:@"finish_stop"]) {
|
||||
if (!multiDrive || !frozenForRetention || r.count != 1 || drainedDrives != 15)
|
||||
throw std::runtime_error("playtest_disk_export_incomplete");
|
||||
stopped = true; return status();
|
||||
}
|
||||
if ([op isEqual:@"media_status"]) {
|
||||
if (r.count != 1) throw std::invalid_argument("invalid_arguments");
|
||||
return status();
|
||||
}
|
||||
if ([op isEqual:@"export_media"]) {
|
||||
if (r.count != 1) throw std::invalid_argument("invalid_arguments");
|
||||
return exportMedia();
|
||||
if (r.count != 1 + (r[@"drive"] ? 1u : 0u) || (!multiDrive && r[@"drive"])) throw std::invalid_argument("invalid_arguments");
|
||||
const unsigned drive = r[@"drive"] ? number(r[@"drive"], 0, 3) : 0;
|
||||
return exportMedia(drive);
|
||||
}
|
||||
if ([op isEqual:@"exchange_media"]) return exchangeMedia(r);
|
||||
if ([op isEqual:@"video_start"]) {
|
||||
@@ -791,6 +840,11 @@ public:
|
||||
finishVideo(@"run_stopped");
|
||||
NSMutableDictionary *out = [status() mutableCopy];
|
||||
if (videoInfo) out[@"video"] = [videoInfo copy];
|
||||
if (multiDrive) {
|
||||
frozenForRetention = true; drainedDrives = 0;
|
||||
out[@"media_frozen"] = @YES;
|
||||
return out; // Drain four bounded per-drive replies before finish_stop.
|
||||
}
|
||||
if (const auto *image = floppy->image(0)) {
|
||||
const auto& disk = image->bytes();
|
||||
out[@"disk_base64"] = [[NSData dataWithBytes:disk.data() length:disk.size()] base64EncodedStringWithOptions:0];
|
||||
|
||||
Reference in new issue
Block a user