Sync source edition with VCC Plus 3.7.0 build 63

This commit is contained in:
Brian Holman committed 2026-11-14 01:43:46 -07:00
1 parent c652a5276d
commit b2ecec4d87
86 files changed
+10519 -472

No files matched your search

+48 -9
View File
@@ -352,10 +352,11 @@ final class MachineModel: ObservableObject {
private let automaticDiskWriter: @Sendable (Data, URL, Data) async throws -> Void
private let diskStore: DiskAssignmentStore
private let inputStore: InputSettingsStore
private let inputControllerReadings: (() -> [ControllerReading])?
lazy var printer = PrinterModel(controller: controller)
private var existingInputHub: InputHub?
lazy var input: InputHub = {
let hub = InputHub(controller: controller, store: inputStore)
let hub = InputHub(controller: controller, store: inputStore, controllerReadings: inputControllerReadings)
existingInputHub = hub
return hub
}()
@@ -386,10 +387,13 @@ final class MachineModel: ObservableObject {
private var mediaPromptOpen = false
let recentMedia: RecentMedia
let displayPreferences: DisplayPreferences
lazy var captures = CoCoCaptureCoordinator(machine: self, controller: controller, defaults: displayDefaults,
directory: diskStore.url.deletingLastPathComponent())
private var screenshotInProgress = false
private let controller: VCCMachineController
init(diskStore: DiskAssignmentStore = .standard, controller: VCCMachineController = VCCMachineController(),
displayDefaults: UserDefaults = .standard, inputStore: InputSettingsStore = .standard, startupStore: StartupStore? = nil,
inputControllerReadings: (() -> [ControllerReading])? = nil,
restoreMediaOnLaunch: Bool = true,
automaticHardDiskWriter: @escaping @Sendable (Data, Int, URL, String) async throws -> String = { patches, length, url, expected in
try await Task.detached(priority: .utility) { try HardDiskFiles.saveAutomatically(patches, length: length, to: url, expected: expected) }.value
@@ -403,6 +407,7 @@ final class MachineModel: ObservableObject {
self.starterShellDiskURL = startupStore?.directory.resolvingSymlinksInPath()
.appendingPathComponent("Starter Media/NitrOS-9 L2 V3.3.0.vhd").standardizedFileURL
self.inputStore = inputStore
self.inputControllerReadings = inputControllerReadings
self.displayDefaults = displayDefaults
videoOutput = DisplayOutput.remembered(in: displayDefaults)
let rememberedSettings = MachineSettings.remembered(in: displayDefaults)
@@ -522,7 +527,7 @@ final class MachineModel: ObservableObject {
// Shared by both presentations. The profile transaction already pauses the
// worker, drains automatic writes and rejects any unsaved media atomically.
@discardableResult func restoreAppDefaults() async -> Bool {
await loadSystemProfile(.diskBasic)
await loadSystemProfile(.diskBasic, resetInput: true)
}
func systemProfileUnavailableReason(_ kind: SystemProfile) -> String? {
guard let startupStore else { return StartupStore.Failure.unavailable.localizedDescription }
@@ -537,11 +542,15 @@ final class MachineModel: ObservableObject {
}.value
}
@discardableResult func loadSystemProfile(_ kind: SystemProfile) async -> Bool {
await loadSystemProfile(kind, resetInput: false)
}
@discardableResult private func loadSystemProfile(_ kind: SystemProfile, resetInput: Bool) async -> Bool {
guard !busy, !diskSaving, state != .closed else { return false }
await loadProfile(preparing: { [startupStore] in
guard let startupStore else { throw StartupStore.Failure.unavailable }
return try await Task.detached(priority: .userInitiated) { try startupStore.systemProfile(kind) }.value
}, startRunning: true, builtInNitros9: kind == .nitros9)
}, startRunning: true, builtInNitros9: kind == .nitros9,
preserveInput: !resetInput, resetInput: resetInput)
let succeeded = profileError == nil && fileError == nil
if succeeded { guideRequest = GuideRequest(profile: kind) }
return succeeded
@@ -1080,6 +1089,9 @@ final class MachineModel: ObservableObject {
// checks active disk writes and recordings again on its serial queue.
func applyMachineSettings(_ value: MachineSettings) {
guard !busy, !diskSaving, state != .closed, value.valid else { return }
if captures.active && (value.fastForward || value.use6309 != settings.use6309 || value.ram != settings.ram) {
Task { if await captures.stopBeforeReplacingMachine() { applyMachineSettings(value) } }; return
}
command({ controller.configureMachine(use6309: value.use6309, ram: value.ram,
overclock: value.overclock, frameInterval: value.frameInterval,
fastForward: value.fastForward, completion: $0) }, onSuccess: { [self] in
@@ -1111,6 +1123,10 @@ final class MachineModel: ObservableObject {
}
}
func installROM(_ data: Data, url: URL) {
if captures.active {
Task { if await captures.stopBeforeReplacingMachine() { installROM(data, url: url) } else { busy = false } }; return
}
captures.cancelCountdown()
busy = true; inputEpoch += 1
controller.loadROM(data, use6309: use6309) { [weak self] snapshot in
MainActor.assumeIsolated {
@@ -1761,6 +1777,9 @@ final class MachineModel: ObservableObject {
var definition: [String: Any] = ["id": module.id, "pages": module.pages.map {
["logicalPage": $0.logicalPage, "physicalPage": $0.physicalPage]
}, "addresses": code.map { NSNumber(value: $0.address) }, "bytes": code.map { Data($0.bytes) }]
if let overlay = module.overlay {
definition["overlay_group"] = overlay.group; definition["overlay_owner"] = overlay.owner
}
if let pointModules {
definition["breakpoints"] = addresses.filter { pointModules[$0]?.contains(module.id) == true }.map { NSNumber(value: $0) }
}
@@ -1846,6 +1865,7 @@ final class MachineModel: ObservableObject {
debuggerCommand({ controller.debuggerStepBankedSource(mode: mode, addresses: addresses, locations: locations,
bytes: bytes, moduleIdentifiers: moduleIdentifiers, generation: expected.generation,
programRevision: expected.debuggerProgramRevision, mappingFingerprint: expected.debuggerMappingFingerprint,
residencyFingerprint: expected.debuggerResidencyFingerprint,
programCounter: expected.programCounter, completion: $0) }, completion: completion)
return
}
@@ -1891,8 +1911,8 @@ final class MachineModel: ObservableObject {
func debuggerWriteMemory(address: UInt16, data: Data, completion: @escaping () -> Void) {
debuggerCommand({ controller.debuggerWriteMemory(address: address, data: data, completion: $0) }, completion: completion)
}
func softReset() { command(controller.softReset, onSuccess: { [self] in binaryName = nil; deniedShellGeneration = nil }) }
func reset() { command(controller.reset, onSuccess: { [self] in binaryName = nil; deniedShellGeneration = nil }) }
func softReset() { captures.cancelCountdown(); command(controller.softReset, onSuccess: { [self] in binaryName = nil; deniedShellGeneration = nil }) }
func reset() { captures.cancelCountdown(); command(controller.reset, onSuccess: { [self] in binaryName = nil; deniedShellGeneration = nil }) }
func poll() {
guard !polling, !busy, state != .closed else { return }
polling = true
@@ -2373,8 +2393,11 @@ extension MachineModel {
await loadProfile(preparing: { profile }, startRunning: false)
}
@discardableResult private func loadProfile(preparing: () async throws -> ConfigurationProfile, startRunning: Bool,
builtInNitros9: Bool = false, afterStart: (() async throws -> Void)? = nil) async -> Bool {
builtInNitros9: Bool = false, preserveInput: Bool = false, resetInput: Bool = false,
libraryInputs: Bool = false,
afterStart: (() async throws -> Void)? = nil) async -> Bool {
guard !busy, state != .closed else { return false }
guard await captures.stopBeforeReplacingMachine() else { return false }
var committed = false
guideRequest = nil
busy = true; inputEpoch += 1; profileError = nil; fileError = nil
@@ -2428,7 +2451,11 @@ extension MachineModel {
}
}
nextHardSave = .distantPast; savedHardFlushRequests = hardFlushRequests
volume = profile.volume; input.settings = profile.input
volume = profile.volume
if resetInput { input.restoreDefaultSettings() }
else if preserveInput { input.release() }
else if libraryInputs { input.applyLibrarySettings(profile.input) }
else { input.applyProfileSettings(profile.input) }
_ = await applyDriveWireDefault(builtInNitros9)
rememberStartup()
loadedProfileConfiguration = profileConfiguration
@@ -2609,6 +2636,7 @@ extension MachineModel {
let capture: ScreenCapture
do { capture = try ScreenCapture(pixels: pixels, area: activeVideoRect) }
catch { fileError = error.localizedDescription; return }
CoCoCaptureFeedback.play(.screenshot)
screenshotInProgress = true; fileError = nil
let panel = NSSavePanel()
panel.title = "Save CoCo Screen"
@@ -2685,6 +2713,15 @@ extension MachineModel {
case .diskBasic:
profile.media.rom = try firmware("disk11.rom", fallback: diskAssignments.rom)
layout.slots[plan.controllerSlot].kind = .floppy
case .hardDriveBasic:
// An arbitrary active disk ROM may be Disk BASIC rather than RGB-DOS.
// Only recognized starter firmware can supply a missing bundled ROM;
// editable profile names and the presence of a hard disk prove nothing.
let knownRGBDOS = usageProfile == .hardDriveBasic || usageProfile == .nitros9
profile.media.rom = try firmware(SystemProfile.hardDriveBasic.diskROMName,
fallback: knownRGBDOS ? diskAssignments.rom : nil)
layout.slots[plan.controllerSlot].kind = .floppy
layout.slots[plan.controllerSlot == 1 ? 2 : 1].kind = .hardDisk
case .cocoSDC:
let priorROM = cartridgeAssignments.slots.first { $0.kind == .sdc }?.url
layout.slots[plan.controllerSlot] = .init(kind: .sdc, url: try firmware("sdcdos.rom", fallback: priorROM),
@@ -2692,6 +2729,7 @@ extension MachineModel {
}
profile.media.cartridges = layout
profile.media.hardDisks = HardDiskAssignments()
for (drive, url) in plan.hardDiskURLs { profile.media.hardDisks?.drives[drive] = .init(url: url, writeProtected: false) }
for (drive, url) in plan.floppyURLs { profile.media.drives[drive] = .init(url: url, writeProtected: false) }
profile.cassette = plan.cassetteURL; profile.fastCassette = plan.cassetteURL != nil
profile.bootNitros9 = nil
@@ -2720,7 +2758,7 @@ extension MachineModel {
let applied = await loadProfile(preparing: {
try await Task.detached(priority: .userInitiated) { try prepared.plan.validateMedia() }.value
return prepared.profile
}, startRunning: true, afterStart: { [self] in
}, startRunning: true, libraryInputs: true, afterStart: { [self] in
do {
try Task.checkCancellation()
if prepared.plan.cassetteURL != nil && !prepared.plan.commands.isEmpty {
@@ -2769,7 +2807,8 @@ extension MachineModel {
guard canLaunchLibrarySoftware else { throw ProfileFailure.message("Wait for the current machine operation to finish.") }
_ = try await Task.detached(priority: .userInitiated) { try PreparedProfile.read(profile) }.value
try Task.checkCancellation()
let applied = await loadProfile(preparing: { profile }, startRunning: true, builtInNitros9: profile == libraryReturnToNitros9)
let applied = await loadProfile(preparing: { profile }, startRunning: true, builtInNitros9: profile == libraryReturnToNitros9,
libraryInputs: true)
guard applied, profileError == nil else { throw ProfileFailure.message(profileError ?? "The previous setup could not be restored.") }
libraryReturnToNitros9 = nil
}