Files
VCCPlusOSS/platforms/macos/App/MachineSettingsView.swift
T

120 lines
8.4 KiB
Swift
Raw 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
struct MachineSettingsView: View {
@ObservedObject var machine: MachineModel
@State private var draft = MachineSettings()
@State private var confirmRestart = false
private var restartRequired: Bool {
(machine.state == .running || machine.state == .paused) && draft.needsRestart(comparedTo: machine.settings)
}
var body: some View {
VStack(alignment: .leading, spacing: 0) {
SecondaryHeader(title: "Machine Settings", symbol: "cpu", subtitle: "Review changes, then apply them to the CoCo.")
.padding(20)
Divider()
ScrollView {
VStack(alignment: .leading, spacing: 16) {
SecondaryCard {
Label("Hardware", systemImage: "cpu").font(.headline)
Picker("Processor", selection: $draft.use6309) {
Text("Motorola 6809").tag(false)
Text("Hitachi 6309").tag(true)
}.accessibilityIdentifier("machine-processor")
Picker("Memory", selection: $draft.ram) {
ForEach(0..<4) { Text(MachineSettings.memoryLabels[$0]).tag($0) }
}.accessibilityIdentifier("machine-memory")
Label("Hardware changes restart the CoCo and clear RAM. Mounted media stays attached.", systemImage: "arrow.counterclockwise")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
SecondaryCard {
Label("Performance", systemImage: "speedometer").font(.headline)
Stepper("CPU overclock: \(draft.overclock)×", value: $draft.overclock, in: 1...16)
.monospacedDigit()
Toggle("Fast-forward", isOn: $draft.fastForward)
Text("Fast-forward temporarily silences playback. Disk and cassette operations continue.")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
Divider()
Picker("Present frames", selection: $draft.frameInterval) {
Text("Every frame").tag(1)
ForEach(2...6, id: \.self) { Text("Every \($0) frames").tag($0) }
}.accessibilityIdentifier("machine-frame-interval")
SecondaryHelp(title: "About speed and display timing") {
Text("1× is normal. Overclock increases CPU speed when software selects double-speed mode. Video and device timing stay unchanged.")
Text("Fast-forward runs faster than real time as this Mac allows. Presenting fewer frames reduces display updates only; CPU, video timing, sound and devices still run every frame.")
}
}
SecondaryCard {
Label("Networking", systemImage: "network").font(.headline)
Toggle("Enable DriveWire networking", isOn: Binding(
get: { machine.driveWireEnabled }, set: machine.setDriveWireNetworking))
.accessibilityIdentifier("machine-drivewire-networking")
Text("Lets compatible NitrOS-9 programs open outbound TCP connections through the FD-502 Becker port. Networking defaults on for the built-in NitrOS-9 profile. Your choice here applies across profiles. Turning it off closes connections immediately.")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
DriveWireNetworkingHelp()
Divider()
Label("Mac shell", systemImage: "terminal").font(.subheadline.bold())
Text("At the OS-9 prompt, enter telnet macshell 2323 to request access to your Mac command line. Programs in the guest can then run commands with your Mac account’s permissions. Type exit to return to OS-9.")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
if machine.macShellStatus == "idle" {
Button("Start Mac Shell Session", action: machine.startMacShellSession)
.disabled(!machine.driveWireEnabled || machine.busy)
} else {
Text(machine.macShellStatus == "ready" ? "Ready for one guest connection." :
machine.macShellStatus == "requested" ? "Waiting for your permission." : "Mac shell session connected.")
.font(.callout)
Button("Stop Mac Shell Session", action: machine.stopMacShellSession)
}
if machine.hasRememberedMacShellPermission {
Button("Forget Mac Shell Permission", action: machine.forgetMacShellPermission)
}
}
SecondaryCard {
Label("Recovery", systemImage: "arrow.counterclockwise").font(.headline)
Text(machine.hasBundledROMs ? "Restore the complete standard setup, including ROMs and media assignments. This is separate from editing the hardware above." : "Bundled defaults are unavailable in this source build. Choose your own ROMs, or add the private development ROMs.")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
Button { machine.confirmRestoreAppDefaults { draft = machine.settings } } label: {
Label("Restore App Defaults…", systemImage: "arrow.counterclockwise")
}.disabled(!machine.hasBundledROMs)
}
}.padding(20)
}
Divider()
VStack(alignment: .leading, spacing: 8) {
if let error = machine.profileError ?? machine.fileError ?? machine.error {
Text(error).foregroundStyle(.red).font(.callout).textSelection(.enabled)
.fixedSize(horizontal: false, vertical: true)
}
HStack {
Button { draft = MachineSettings() } label: {
Label("Hardware Defaults", systemImage: "arrow.counterclockwise")
}.help("Reset this form's draft only. Choose Apply to change the machine.")
Spacer()
Button { draft = machine.settings } label: { Label("Revert", systemImage: "arrow.uturn.backward") }
.disabled(draft == machine.settings)
Button {
if restartRequired { confirmRestart = true }
else { machine.applyMachineSettings(draft) }
} label: {
Label(restartRequired ? "Apply and Restart…" : "Apply",
systemImage: restartRequired ? "arrow.clockwise" : "checkmark")
}.keyboardShortcut(.defaultAction).disabled(draft == machine.settings || !draft.valid)
}
Text("Hardware Defaults edits this draft. Applied settings are remembered for the next launch.")
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}.padding(16)
}
.background(MacShellPermissionPresenter(machine: machine))
.frame(minWidth: 540, minHeight: 520)
.disabled(machine.busy || machine.diskSaving || machine.state == .closed)
.onAppear { draft = machine.settings }
.onChange(of: machine.settings) { old, new in if draft == old { draft = new } }
.alert("Cold-restart the machine?", isPresented: $confirmRestart) {
Button("Cancel", role: .cancel) { }
Button("Apply and Restart", role: .destructive) { machine.applyMachineSettings(draft) }
} message: {
Text("Programs and other contents of RAM will be cleared. Mounted disks, cartridges, and cassette contents are retained. The machine will keep its current running or paused state.")
}
}
}