// SPDX-License-Identifier: GPL-3.0-or-later import Foundation /// Read-only observations of the shared development setup; host paths and guest contents stay private. enum MCPMachineStatus { enum Workspace { case basic, cmoc(needsFloppy: Bool), assembly(needs6309: Bool) } static let occupiedBASICGuidance = "A program is in CoCo BASIC memory. In BASIC Development, save any open draft, choose Read from CoCo, then Save As… to keep the guest listing. When you are ready to clear its program and variables, type NEW at the CoCo’s OK prompt and retry the C run." static func missingToolBlockers(in toolchain: URL, requiring names: [String]) async -> [String] { await Task.detached { let bin = toolchain.appendingPathComponent("bin") return names.filter { !FileManager.default.isExecutableFile(atPath: bin.appendingPathComponent($0).path) } .map { "Install the bundled development tool " + $0 + "." } }.value } static func result(_ machine: VCCMachineSnapshot, workspace: Workspace, buildBlockers: [String]?, runBlockers: [String], lastBuild: [String: Any]? = nil, profile: SystemProfile? = nil, input: [String: Any]? = nil) -> [String: Any] { var reasons = runBlockers + machine.assistantDeviceBlockers let state: String switch machine.state { case .running: state = "running" case .paused: state = "paused" case .empty: state = "empty" case .closed: state = "closed" @unknown default: state = "unknown" } if machine.state != .running && machine.state != .paused { reasons.append("Start the CoCo before running the shared program.") } switch workspace { case .assembly(let needs6309): if needs6309 && !machine.use6309 { reasons.append("Use an HD6309 guest or assemble for MC6809.") } case .cmoc(let needsFloppy): if needsFloppy && machine.disks.first?.mounted != false { reasons.append("Use an empty floppy drive 0 before starting Hello Disk.") } if machine.basicDebugAttached || (machine.debuggerDevelopmentAttached && !machine.assistantCompiledReturned) || machine.debuggerAssemblyAttached || machine.pasteRemaining > 0 { reasons.append("Finish the active debugging or paste session.") } if machine.assistantEmptyBASIC?.boolValue == false { reasons.append(occupiedBASICGuidance) } fallthrough case .basic: if machine.assistantDirectPrompt?.boolValue != true { reasons.append(machine.assistantDirectPrompt == nil ? "Use a supported BASIC system and memory map." : "Wait at the BASIC OK prompt.") } } func drives(_ disks: [VCCDiskSnapshot]) -> [[String: Any]] { disks.enumerated().map { index, disk in ["drive": index, "mounted": disk.mounted, "write_protected": disk.writeProtected] } } var build: [String: Any] = ["applicable": false] if let buildBlockers { build = ["applicable": true, "available": buildBlockers.isEmpty, "blockers": buildBlockers] if let lastBuild { build["last_build"] = lastBuild.filter { ["build_id", "revision", "status"].contains($0.key) } } } var result: [String: Any] = [ "processor": machine.use6309 ? "HD6309" : "MC6809", "state": state, "system_profile": (profile?.name as Any?) ?? NSNull(), "video_output": DisplayOutput(rawValue: machine.videoOutput)?.label ?? "unknown", "memory": MachineSettings.memoryLabels.indices.contains(Int(machine.ramConfiguration)) ? MachineSettings.memoryLabels[Int(machine.ramConfiguration)] : "unknown", "floppy_drives": drives(machine.disks), "hard_drives": drives(machine.hardDisks), "cassette_mounted": machine.tapeMounted, "cassette_recording": machine.tapeMode == 2, "drivewire_enabled": machine.driveWireEnabled, "basic_direct_prompt": (machine.assistantDirectPrompt as Any?) ?? NSNull(), "basic_program_loaded": (machine.assistantEmptyBASIC.map { !$0.boolValue } as Any?) ?? NSNull(), "build": build, "run": ["blockers": reasons, "ready_for_native_run": reasons.isEmpty] as [String: Any] ] if let input { result["input"] = input } return result } }