Files

465 lines
31 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
enum SystemTarget: Hashable, Identifiable {
case computer, keyboard, joystick, cassette, printer, library, manuals, monitor, selector, slot(Int), sdc(Int), floppy(Int), hard(Int)
var id: String { String(describing: self) }
var title: String {
switch self {
case .manuals: return "Help — Manual Library"
case .library: return "Software Library"
case .monitor: return "Monitor video signal"
case .computer: return "Color Computer 3"
case .keyboard: return "Keyboard"
case .joystick: return "Joystick ports"
case .cassette: return "Cassette"
case .printer: return "Tandy TP-10 printer"
case .selector: return "Multi-Pak startup selector"
case .slot(let n): return "Multi-Pak slot \(n)"
case .sdc(let n): return "CoCo SDC in slot \(n)"
case .floppy(let n): return "Floppy FD\(n)"
case .hard(let n): return "Hard disk HD\(n)"
}
}
var action: String {
switch self {
case .manuals: return "Open the offline manual index"
case .library: return "Open the Software Library"
case .printer: return "Open Printer Output"
case .monitor: return "Choose the monitor video signal"
default: return "Show " + title + " controls"
}
}
var mediaDestination: MediaDestination? {
switch self {
case .computer: return .systemROM
case .cassette: return .cassette
case .slot(let n), .sdc(let n): return .cartridge(n)
case .floppy(let n): return .floppy(n)
case .hard(let n): return .hardDisk(n)
default: return nil
}
}
// Scene coordinates shared with runtime-system.svg. The slot targets follow
// the sockets and their numbered shelf, independent of cartridge occupancy.
var rect: CGRect {
switch self {
case .manuals: return CGRect(x: 453, y: 400, width: 58, height: 50.025)
case .library: return CGRect(x: 430, y: 19, width: 285, height: 115)
case .monitor: return CGRect(x: 54, y: 219, width: 272, height: 23)
case .computer: return CGRect(x: 52, y: 279, width: 284, height: 24)
case .keyboard: return CGRect(x: 49, y: 324, width: 284, height: 84)
case .joystick: return CGRect(x: -100, y: 354, width: 112, height: 94)
case .cassette: return CGRect(x: -111, y: 205, width: 150, height: 138)
case .printer: return CGRect(x: -113, y: 89, width: 159, height: 93)
case .selector: return CGRect(x: 367, y: 368, width: 195, height: 21)
case .sdc(let n): return SystemTarget.slot(n).rect
case .slot(let n):
return [CGRect(x: 366, y: 313, width: 173, height: 16),
CGRect(x: 358, y: 295, width: 170, height: 15),
CGRect(x: 352, y: 278, width: 166, height: 14),
CGRect(x: 349, y: 260, width: 158, height: 16)][n - 1]
case .floppy(let n):
return Self.driveFace(y: [339.966641, 308.442122, 268.911376, 237.386856][n])
case .hard(let n):
return Self.driveFace(y: n == 0 ? 411.021906 : 379.497387)
}
}
private static func driveFace(y: Double) -> CGRect {
// Exact outer black face bounds after the SVG's vertical bay transform.
// Equal insets plus strokeBorder keep every highlight inside the face.
CGRect(x: 649.35728, y: y, width: 174.13544, height: 31.79139 * 0.96012592)
.insetBy(dx: 1.25, dy: 1.25)
}
}
struct MachineStage: View {
@Environment(\.openWindow) private var openWindow
@ObservedObject var machine: MachineModel
@ObservedObject var presentation: PresentationSettings
let system: Bool
let openManualIndex: () -> Void
@State private var target: SystemTarget?
@State private var list = false
@State private var hovered: SystemTarget?
@FocusState private var focused: SystemTarget?
private var targets: [SystemTarget] {
var result: [SystemTarget] = [.computer, .keyboard, .printer, .cassette, .joystick, .monitor, .library, .manuals]
if machine.hardware.values["mpi"] == "on" { result += [.selector] + (1...4).map { .slot($0) } }
if machine.hardware.values["floppyCase"] == "on" { result += (0..<4).map { .floppy($0) } }
if machine.hardware.values["hardCase"] == "on" { result += (0..<2).map { .hard($0) } }
return result
}
var body: some View {
GeometryReader { proxy in
let geometry = SystemGeometry(size: proxy.size, system: system, expanded: presentation.expanded,
contentBounds: HardwareArtwork.shared.layoutBounds(machine.hardware.values))
ZStack(alignment: .topLeading) {
if system {
HardwareCanvas(values: machine.hardware.values, part: "scene")
.frame(width: geometry.scene.width, height: geometry.scene.height)
.position(x: geometry.scene.midX, y: geometry.scene.midY)
.opacity(presentation.expanded ? 0.20 : 1).accessibilityHidden(true).allowsHitTesting(false)
if let image = HardwareArtwork.shared.image("software-library-shelf.png") {
let shelf = geometry.rect(SystemGeometry.libraryArtwork)
Image(nsImage: image).resizable().scaledToFit()
.frame(width: shelf.width, height: shelf.height)
.position(x: shelf.midX, y: shelf.midY)
.opacity(presentation.expanded ? 0.20 : 1)
.accessibilityHidden(true).allowsHitTesting(false)
}
if let image = HardwareArtwork.shared.image("manual-help.pdf") {
let button = geometry.rect(SystemTarget.manuals.rect)
Image(nsImage: image).resizable().scaledToFit()
.frame(width: button.width, height: button.height)
.position(x: button.midX, y: button.midY)
.opacity(presentation.expanded ? 0.20 : 1)
.accessibilityHidden(true).allowsHitTesting(false)
}
if !presentation.expanded {
connectionOverlay(geometry)
ForEach(["floppy", "hard"], id: \.self) { kind in
if machine.hardware.values[kind + "Case"] == "on" && machine.hardware.values[kind] != "on" {
let r = geometry.rect(CGRect(x: 649, y: kind == "floppy" ? 300 : 400, width: 176, height: 20))
Text("\(kind == "floppy" ? "Floppy" : "Hard-disk") controller disconnected")
.font(.caption).foregroundStyle(.black).padding(4)
.background(.white.opacity(0.9), in: RoundedRectangle(cornerRadius: 4))
.position(x: r.midX, y: r.midY).allowsHitTesting(false)
}
}
ForEach(targets.filter { $0 != .monitor }) { item in
hotspot(item, frame: geometry.rect(item.rect))
}
ForEach(1...4, id: \.self) { n in
if machine.hardware.values["mpi"] == "on", machine.hardware.values["slot\(n)"] == "sdc",
let rect = HardwareArtwork.shared.cartridgeHitRect(slot: n, values: machine.hardware.values) {
hotspot(.sdc(n), frame: geometry.rect(rect))
}
}
}
HardwareCanvas(values: machine.hardware.values, part: "monitor")
.frame(width: geometry.monitor.width, height: geometry.monitor.height)
.position(x: geometry.monitor.midX, y: geometry.monitor.midY).accessibilityHidden(true).allowsHitTesting(false)
hotspot(.monitor, frame: geometry.monitorRect(SystemTarget.monitor.rect))
}
// This representable occupies the same structural position in
// every presentation: one MTKView, one input owner, one session.
EmulatorDisplay(machine: machine, presentationToken: "\(system)-\(presentation.expanded)")
.frame(width: geometry.screen.width, height: geometry.screen.height)
.position(x: geometry.screen.midX, y: geometry.screen.midY)
if machine.pixels == nil {
VStack(spacing: 8) {
Text("VCC").font(.headline)
Text(machine.state == .empty ? "Open a CoCo 3 ROM to begin" : "Press Run to generate a frame")
.font(.callout).multilineTextAlignment(.center)
}.foregroundStyle(.white.opacity(0.85))
.frame(width: geometry.screen.width, height: geometry.screen.height)
.position(x: geometry.screen.midX, y: geometry.screen.midY).allowsHitTesting(false)
}
if system {
HStack {
Button { list.toggle() } label: { Label("Devices", systemImage: "list.bullet") }
.popover(isPresented: $list) {
ScrollView {
VStack(alignment: .leading, spacing: 8) {
Text("System devices").font(.headline)
Text("All illustrated objects are available here, including obscured slots.").font(.caption).foregroundStyle(.secondary)
ForEach(targets) { item in
if item == .manuals {
Button { list = false; openManualIndex() } label: {
Label("Open Manual Library", systemImage: "books.vertical")
}
} else {
DisclosureGroup(item.title + " — " + description(item)) {
SystemDeviceControls(machine: machine, target: item).padding(.vertical, 8)
}
}
}
}.padding(16)
}.frame(width: 430, height: 520)
}
Toggle("Connections", isOn: $presentation.showConnections).toggleStyle(.button)
.help("Show which controller connects to each set of drives")
Spacer(minLength: 16)
Toggle("Show Clickable Areas", isOn: $presentation.showClickableAreas)
.toggleStyle(.checkbox).accessibilityIdentifier("show-clickable-areas")
.help("Outline available controls with dashed gray lines. Hover or focus highlights one in blue.")
}.controlSize(.small).environment(\.colorScheme, .light).padding(10)
}
}
.onChange(of: presentation.mode) { _, _ in target = nil; list = false; hovered = nil; focused = nil }
.onChange(of: presentation.expanded) { _, _ in target = nil; list = false; hovered = nil; focused = nil }
}
}
private func hotspot(_ item: SystemTarget, frame: CGRect) -> some View {
let active = focused == item || hovered == item
return Button {
if item == .manuals { target = nil; openManualIndex() }
else if item == .library { target = nil; openWindow(id: "software-library") }
else if item == .printer { target = nil; openWindow(id: "printer") }
else { target = item }
} label: {
RoundedRectangle(cornerRadius: 4).fill(Color.white.opacity(0.001))
.contentShape(Rectangle())
.overlay(alignment: .topTrailing) {
if unavailable(item) { Image(systemName: "exclamationmark.triangle.fill").foregroundStyle(.orange).font(.caption) }
}
.overlay {
RoundedRectangle(cornerRadius: 4)
.strokeBorder(active ? Color.accentColor : presentation.showClickableAreas ? Color.gray.opacity(0.7) : .clear,
style: StrokeStyle(lineWidth: active ? 2 : 1, dash: active ? [] : [4, 3]))
.allowsHitTesting(false)
}
}.buttonStyle(.plain)
// Do not grow narrow MPI rows into their neighbours at small sizes.
// Devices supplies a larger, accessible alternative for every target.
.frame(width: frame.width, height: frame.height)
.modifier(MediaDropTarget(machine: machine, destination: item.mediaDestination))
.focused($focused, equals: item)
.onHover { hovered = $0 ? item : nil }
.accessibilityIdentifier("system-\(item.id)")
.accessibilityLabel(item.title).accessibilityValue(description(item))
.help(item.action)
.popover(isPresented: Binding(get: { target == item }, set: { if !$0 && target == item { target = nil } })) {
SystemDeviceControls(machine: machine, target: item)
}
// Attach the popover to the device bounds, before scene positioning.
.position(x: frame.midX, y: frame.midY)
}
private func unavailable(_ item: SystemTarget) -> Bool {
switch item {
case .slot(let n), .sdc(let n): return machine.cartridgeAssignments.slots[n].kind != .empty && machine.cartridgeNames[n].isEmpty
case .floppy(let n): return machine.diskRestoreErrors[n] != nil
case .hard(let n): return machine.hardRestoreErrors[n] != nil
case .printer: return machine.printer.dropped > 0
default: return false
}
}
private func description(_ item: SystemTarget) -> String {
switch item {
case .manuals: return "Offline books for VCC Plus"
case .library: return "Browse, install and play Color Computer software"
case .monitor: return machine.videoOutput.label
case .printer: return "\(machine.printer.enabled ? "Capturing" : "Capture stopped") · \(machine.printer.byteCount.formatted()) bytes\(machine.printer.unsaved ? " · Not saved" : "")"
case .computer: return "\(MachineSettings.memoryLabels[machine.settings.ram]), \(machine.use6309 ? "Hitachi 6309" : "Motorola 6809")"
case .cassette: return machine.tapeMounted ? machine.tapeName + " · " + machine.tapeTransportDescription : "Empty"
case .slot(let n), .sdc(let n):
let slot = machine.cartridgeAssignments.slots[n]
if slot.kind == .sdc, !machine.cartridgeNames[n].isEmpty {
return "CoCo SDC · \(slot.sdcFolderURL?.lastPathComponent ?? "No SD card folder") · \(machine.hardware.values["sdcActivity"] ?? "empty") · \(machine.sdcReadOnly ? "Read-only" : "Writable")"
}
return slot.kind == .empty ? "Empty" : machine.cartridgeNames[n].isEmpty ? "Unavailable — open controls to repair" : machine.cartridgeNames[n]
case .selector: return "Startup \(machine.cartridgeAssignments.physicalSlot); live ROM \(machine.romSlot), I/O \(machine.ioSlot)"
case .floppy(let n): return diskDescription(machine.disks, n, activity: n)
case .hard(let n): return diskDescription(machine.hardDisks, n, activity: n+4)
case .joystick: return "Assignments for both CoCo ports"
case .keyboard: return "Host key mappings and input help"
}
}
private func diskDescription(_ disks: [VCCDiskSnapshot], _ n: Int, activity: Int) -> String {
guard disks.indices.contains(n), disks[n].mounted else {
let error = activity < 4 ? machine.diskRestoreErrors[n] : machine.hardRestoreErrors[n]
return error == nil ? "Empty" : "Unavailable — open controls to repair the file location"
}
let d = disks[n]
return "\(d.name) · \(machine.hardware.activities[activity].rawValue)\(d.dirty ? " · Unsaved" : "")\(d.writeProtected ? " · Write protected" : "")"
}
@ViewBuilder private func connectionOverlay(_ geometry: SystemGeometry) -> some View {
let selection = focused ?? hovered ?? target
ForEach(1...4, id: \.self) { n in
let kind = machine.hardware.values["slot\(n)"] ?? "empty"
if (kind == "floppy" || kind == "hard") && (presentation.showConnections || selection == .slot(n)) {
let from = geometry.rect(SystemTarget.slot(n).rect)
let to = geometry.rect((kind == "floppy" ? SystemTarget.floppy(2) : SystemTarget.hard(1)).rect)
Path { p in
p.move(to: CGPoint(x: from.midX, y: from.minY))
p.addCurve(to: CGPoint(x: to.minX, y: to.midY), control1: CGPoint(x: from.midX+30, y: from.minY-55), control2: CGPoint(x: to.minX-40, y: to.midY-50))
}.stroke(Color.accentColor.opacity(0.65), style: StrokeStyle(lineWidth: 2, dash: [5,4]))
.allowsHitTesting(false).accessibilityHidden(true)
Text("Slot \(n) → \(kind == "floppy" ? "FD0–FD3" : "HD0–HD1")")
.font(.caption).padding(4).background(.regularMaterial, in: RoundedRectangle(cornerRadius: 4))
.position(x: (from.midX+to.minX)/2, y: min(from.minY,to.minY)-22).allowsHitTesting(false)
}
}
}
}
struct SystemDeviceControls: View {
@ObservedObject var machine: MachineModel
let target: SystemTarget
@Environment(\.openWindow) private var openWindow
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text(target.title).font(.headline)
controls
if let error = machine.fileError ?? machine.error { Text(error).foregroundStyle(.red).textSelection(.enabled) }
}.padding(16).frame(width: 375)
}
@ViewBuilder private var controls: some View {
switch target {
case .manuals: EmptyView() // Opens the reader directly.
case .library:
Text("Explore the software collection, read manuals, and choose something to play.")
Button { openWindow(id: "software-library") } label: {
Label("Open Software Library", systemImage: "books.vertical")
}
.accessibilityIdentifier("system-library-open")
case .printer:
SystemPrinterControls(printer: machine.printer)
case .monitor:
SystemVideoControls(machine: machine).equatable()
case .computer:
Text("Memory holds your working program. CPU or memory changes restart the computer and clear RAM.")
Text("\(MachineSettings.memoryLabels[machine.settings.ram]) · \(machine.use6309 ? "Hitachi 6309" : "Motorola 6809")")
Button("Machine Settings…") { openWindow(id: "machine-settings") }
case .keyboard, .joystick:
Text("Your Mac controller, mouse or keyboard can operate either CoCo joystick port. The pictured joystick's position does not assign a port.")
Text("Click the monitor to type. Escape is Break; Home is Clear. Leaving the display releases held keys and buttons.")
Button("Keyboard and Joysticks…") { openWindow(id: "input") }
case .cassette:
Text(machine.tapeName).textSelection(.enabled)
Text(machine.tapeTransportDescription)
Text("Play prepares the tape; the computer controls movement. Record creates a new tape in memory. Export keeps a recording on your Mac.").font(.callout).foregroundStyle(.secondary)
HStack {
Button("Play") { machine.tapeAction(1) }.disabled(!machine.tapeMounted || machine.tapeMode == 2)
Button("Stop") { machine.tapeAction(0) }.disabled(!machine.tapeMounted)
Button("Rewind") { machine.tapeAction(2) }.disabled(!machine.tapeMounted)
}.disabled(machine.busy || machine.state == .closed)
if machine.tapeDirty || machine.tapeMode == 2 { Label("Unsaved recording — export to keep", systemImage: "exclamationmark.circle").foregroundStyle(.orange) }
Button("Cassette Controls…") { openWindow(id: "cassette") }
case .selector:
Text("Startup selection takes effect with a cold restart and clears RAM. Software can route ROM and disk I/O independently afterward.").font(.callout)
Picker("Startup slot", selection: Binding(get: { machine.cartridgeAssignments.physicalSlot }, set: machine.selectPhysicalSlot)) {
ForEach(1...4,id: \.self) { Text("\($0)").tag($0) }
}.pickerStyle(.segmented).disabled(machine.busy || machine.diskSaving || machine.diskBusy)
Text("Live ROM slot \(machine.romSlot) · Disk I/O slot \(machine.ioSlot)").foregroundStyle(.secondary)
case .slot(let n), .sdc(let n):
let slot = machine.cartridgeAssignments.slots[n]
if slot.kind == .sdc { SystemSDCControls(machine: machine, slot: n) } else {
Text(slot.url?.lastPathComponent ?? (slot.kind == .floppy ? "Floppy controller (FD-502)" : slot.kind == .hardDisk ? "Virtual hard-disk controller" : slot.kind == .orchestra90 ? "Orchestra-90" : slot.kind == .speechSound ? "Speech/Sound Cartridge" : "Empty"))
.textSelection(.enabled)
Text(slot.kind == .speechSound ? "Speech/Sound adds speech and music for supporting programs. Both internal chip ROMs are required. It has no boot ROM; keep the disk controller as your startup slot." : slot.kind == .orchestra90 ? "Orchestra-90 provides stereo sound to supporting software. Its optional 8 KiB ROM adds the music program; choose it in Cartridge Settings and select this startup slot to boot it. Sound ports work independently of the live ROM selection." : slot.kind == .floppy ? "One controller serves FD0–FD3 in two enclosures. The FD-502 badges identify the emulated floppy controller." : slot.kind == .hardDisk ? "This separate virtual controller serves HD0–HD1. It has no boot ROM; use a compatible floppy ROM or OS-9 boot disk." : "A ROM cartridge contains a program. A storage controller connects the computer to disks; it does not contain the disks' files.").font(.callout).foregroundStyle(.secondary)
Text("Changing this slot cold-restarts the computer and clears its working program.").font(.caption)
VStack(alignment: .leading, spacing: 8) {
Button("Choose ROM…") { machine.openCartridgeROM(n) }
Button("Use Floppy Controller…") { machine.requestCartridge(.floppy, slot: n) }.disabled(slot.kind == .floppy)
Button("Use Hard-Disk Controller…") { machine.requestCartridge(.hardDisk, slot: n) }.disabled(slot.kind == .hardDisk)
Button("Use Speech/Sound…") { machine.requestCartridge(.speechSound, slot: n) }.disabled(slot.kind == .speechSound)
Button("Use Orchestra-90…") { machine.requestCartridge(.orchestra90, slot: n) }.disabled(slot.kind == .orchestra90)
Button("Use CoCo SDC…") { machine.requestCartridge(.sdc, slot: n) }.disabled(slot.kind == .sdc)
Button("Use RAM Disk…") { machine.requestCartridge(.ramDisk, slot: n) }.disabled(slot.kind == .ramDisk)
Button("Remove Cartridge…") { machine.requestCartridge(.empty, slot: n) }.disabled(slot.kind == .empty)
}.disabled(machine.busy || machine.diskSaving || machine.diskBusy || machine.state == .closed)
}
if let error = machine.cartridgeRestoreErrors[n] { Text(error).foregroundStyle(.orange) }
Button("All Cartridge Settings…") { openWindow(id: "cartridges") }
case .floppy(let n):
diskControls(n, hard: false)
case .hard(let n):
diskControls(n, hard: true)
}
}
@ViewBuilder private func diskControls(_ n: Int, hard: Bool) -> some View {
let disks = hard ? machine.hardDisks : machine.disks
if !(hard ? machine.hardDiskConnected : machine.diskConnected) {
Text("Controller disconnected. Retained media remains available here; connect the controller in Cartridges to use it.").foregroundStyle(.orange)
Button("Cartridges…") { openWindow(id: "cartridges") }
}
if disks.indices.contains(n) {
let disk = disks[n]
let remembered = hard ? machine.hardSettings.drives[n]?.url : machine.diskAssignments.drives[n]?.url
Text(disk.mounted ? disk.name : remembered.map { "Unavailable — " + $0.lastPathComponent } ?? "Empty").textSelection(.enabled)
if let error = hard ? machine.hardRestoreErrors[n] ?? machine.hardSaveErrors[n] : machine.diskRestoreErrors[n] ?? machine.diskSaveErrors[n] {
Text(error).foregroundStyle(.orange).textSelection(.enabled)
}
Text("\(hard ? "HD" : "FD")\(n) · \(machine.hardware.activities[hard ? n+4 : n].rawValue.capitalized)").foregroundStyle(.secondary)
if disk.dirty { Label("Unsaved changes", systemImage: "exclamationmark.circle").foregroundStyle(.orange) }
let temporary = hard ? machine.hardTemporary[n] : machine.diskTemporary[n]
Text(disk.writeProtected ? "Write protected" : temporary ? "Temporary changes — Save As to keep" : "Writable backed images save automatically")
.font(.callout).foregroundStyle(.secondary)
HStack {
Button("Insert…") { if hard { machine.openHardDisk(n) } else { machine.openDisk(n) } }.disabled(disk.dirty)
Button("Eject") { if hard { machine.ejectHardDisk(n) } else { machine.ejectDisk(n) } }.disabled(disk.dirty || !disk.mounted)
Button("Save As…") { if hard { machine.exportHardDisk(n) } else { machine.exportDisk(n) } }.disabled(!disk.mounted)
}.disabled(machine.busy || machine.diskSaving || (!hard && machine.diskBusy) || machine.state == .closed)
Text("The pictured medium is a file on your Mac. Insertion does not run its software. Media changes pause emulation.").font(.callout).foregroundStyle(.secondary)
}
Button("\(hard ? "Hard Disk" : "Floppy") Controls…") { openWindow(id: hard ? "hard-disks" : "disks") }
}
}
// Keep a native signal picker stable while its surrounding popover refreshes.
private struct SystemVideoControls: View, Equatable {
@Environment(\.openWindow) private var openWindow
let machine: MachineModel
@ObservedObject private var menu: MachineMenuState
init(machine: MachineModel) { self.machine = machine; self.menu = machine.menuState }
static func == (lhs: Self, rhs: Self) -> Bool { lhs.machine === rhs.machine }
var body: some View {
VStack(alignment: .leading, spacing: 12) {
Picker("Video Signal", selection: Binding(get: { menu.values.videoOutput }, set: machine.setVideoOutput)) {
ForEach(DisplayOutput.allCases, id: \.rawValue) { Text($0.label).tag($0) }
}.accessibilityIdentifier("monitor-video-signal")
.disabled(menu.values.busy || menu.values.state == .closed)
Text("Composite TV reproduces the artifact colors used by many CoCo games. Alternate Colors swaps their color phase. RGB gives a direct monitor signal.")
.font(.callout).foregroundStyle(.secondary)
Button("Display Settings…") { openWindow(id: "display-settings") }
Text("Changing the signal preserves the running session.").font(.caption).foregroundStyle(.secondary)
}
}
}
// The accessible Devices alternative uses the same capture model and commands
// as the dedicated window. Paper feed on the illustration is not a second UI.
private struct SystemPrinterControls: View {
@ObservedObject var printer: PrinterModel
@Environment(\.openWindow) private var openWindow
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text("\(printer.byteCount.formatted()) captured bytes\(printer.unsaved ? " · Not saved" : "")")
Text("The power light shows capture is enabled. Marks on the paper show that output has been collected. Open Printer Output to read, save or print it.")
.font(.callout).foregroundStyle(.secondary)
HStack {
Button { printer.setCapture(!printer.enabled) } label: {
Label(printer.enabled ? "Stop Capture" : "Start Capture", systemImage: printer.enabled ? "stop.fill" : "record.circle")
}.disabled(printer.busy)
Button("Printer Output…") { openWindow(id: "printer") }
}
}
}
}
// Shares the same queued commands and restart/media protections as Cartridges.
private struct SystemSDCControls: View {
@ObservedObject var machine: MachineModel
let slot: Int
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Label("CoCo SDC", systemImage: "sdcard").font(.headline)
Text(machine.cartridgeAssignments.slots[slot].sdcFolderURL?.lastPathComponent ?? "No SD card folder")
.textSelection(.enabled)
if let folder = machine.cartridgeAssignments.slots[slot].sdcFolderURL {
Button { NSWorkspace.shared.activateFileViewerSelecting([folder]) } label: { Label("Show SD Card Folder in Finder", systemImage: "folder") }
}
Text(machine.sdcReadOnly ? "Read-only SD card" : "Writable SD card — changes save directly")
Text("Current folder: \(machine.sdcDirectory.isEmpty ? "/" : machine.sdcDirectory)").font(.callout)
ForEach(0..<2, id: \.self) { drive in
Text("SDC\(drive): \(machine.sdcDriveNames.indices.contains(drive) && !machine.sdcDriveNames[drive].isEmpty ? machine.sdcDriveNames[drive] : "No image mounted")")
.textSelection(.enabled)
}
Text("Transfers · Read \(machine.sdcReadCount) · Written \(machine.sdcWriteCount)")
.monospacedDigit().accessibilityIdentifier("system-sdc-transfers")
if let error = machine.sdcError { Text(error).foregroundStyle(.orange) }
Button { machine.openSDCFolder(slot) } label: { Label("Choose SD Card Folder…", systemImage: "folder") }
.disabled(machine.busy || machine.diskSaving || machine.diskBusy || machine.state == .closed)
Button { machine.openCartridgeROM(slot, kind: .sdc) } label: { Label("Choose SDC-DOS ROM…", systemImage: "memorychip") }
.disabled(machine.busy || machine.diskSaving || machine.diskBusy || machine.state == .closed)
Text("Changing the folder or ROM cold-restarts the CoCo. Use Cartridge Settings for write protection and slot changes.")
.font(.caption).foregroundStyle(.secondary)
Text("Green means an image is mounted; amber and red show actual reads and writes. Closing these controls keeps the session running.")
.font(.caption).foregroundStyle(.secondary)
}
}
}