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

511 lines
31 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
import AppKit
struct DebuggerView: View {
// The machine publishes at display cadence. Rendering this inspector is
// driven by its own bounded snapshot stream and local editing state.
private let machine: MachineModel
@StateObject private var debugger: DebuggerModel
@StateObject private var memoryTools: MemoryToolsModel
@StateObject private var graphics = GraphicsPreviewModel()
@StateObject private var trace: TraceModel
private enum Workspace: String, CaseIterable { case inspector = "Inspector", memory = "Memory Tools", graphics = "Graphics Preview", trace = "Trace" }
@State private var workspace = Workspace.inspector
init(machine: MachineModel) {
self.machine = machine
_debugger = StateObject(wrappedValue: DebuggerModel(machine: machine))
_memoryTools = StateObject(wrappedValue: MemoryToolsModel(machine: machine))
_trace = StateObject(wrappedValue: TraceModel(machine: machine))
}
var body: some View {
VStack(spacing: 0) {
executionToolbar
Divider()
if debugger.loaded {
HStack {
Picker("Debugger workspace", selection: $workspace) {
ForEach(Workspace.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}.pickerStyle(.segmented).labelsHidden().frame(width: 460)
.accessibilityIdentifier("debugger-workspace")
Spacer()
}.padding(.horizontal, 12).padding(.vertical, 6)
Divider()
if workspace == .memory { MemoryToolsView(model: memoryTools) }
else if workspace == .graphics {
GraphicsPreviewView(model: graphics, machine: machine) { address, physical in
debugger.revealGraphicsByte(address, physical: physical)
workspace = .inspector
}
}
else if workspace == .trace { TraceView(model: trace) }
else {
HSplitView {
VSplitView {
codeInspector.frame(minHeight: debugger.codePane == .source ? 340 : 220)
// Keep the combined minimum stable when Source needs
// more room, rather than overflowing a restored window.
memoryInspector.frame(minHeight: debugger.codePane == .source ? 145 : 265,
idealHeight: debugger.codePane == .source ? 180 : 310)
}.frame(minWidth: 590, idealWidth: 740)
inspector.frame(minWidth: 265, idealWidth: 285, maxWidth: 360)
}
}
} else {
VStack(spacing: 12) {
Image(systemName: "ladybug").font(.system(size: 36)).foregroundStyle(.secondary)
Text("Load a machine to begin debugging").font(.title2)
Text("Open a system ROM or choose a system profile in the main window.")
.foregroundStyle(.secondary)
}.frame(maxWidth: .infinity, maxHeight: .infinity)
}
Divider()
statusBar
}
.frame(minWidth: 920, minHeight: 640)
.task { await debugger.poll() }
.onChange(of: debugger.followPC) { _, _ in debugger.refresh() }
}
private var codeInspector: some View {
VStack(spacing: 0) {
HStack {
Picker("Code view", selection: $debugger.codePane) {
ForEach(DebuggerModel.CodePane.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}.pickerStyle(.segmented).labelsHidden().frame(width: 225)
.accessibilityIdentifier("debugger-code-pane")
Spacer(minLength: 8)
if debugger.codePane == .disassembly { disassemblyNavigation }
}.padding(.horizontal, 12).padding(.vertical, 6)
Divider()
if debugger.codePane == .source { DebugSourceView(debugger: debugger) }
else { disassembly }
}
}
private var executionToolbar: some View {
HStack(spacing: 14) {
Label(machine.state == .running ? "Running" : debugger.loaded ? "Paused" : "No machine",
systemImage: machine.state == .running ? "play.circle.fill" : "pause.circle")
.foregroundStyle(machine.state == .running ? Color.green : Color.secondary)
.frame(width: 100, alignment: .leading)
.accessibilityIdentifier("debugger-state")
Button(action: debugger.toggleExecution) {
Label(machine.state == .running ? "Pause" : "Continue",
systemImage: machine.state == .running ? "pause.fill" : "play.fill")
}.disabled(!debugger.commandsAvailable).accessibilityIdentifier("debugger-run")
Button(action: debugger.step) { Label("Step", systemImage: "arrow.right.to.line") }
.disabled(!debugger.canEdit || (workspace == .graphics && !graphics.readyToStep(machine: machine)))
.accessibilityIdentifier("debugger-step")
.help("Execute one instruction, then remain paused.")
Divider().frame(height: 22)
Text(machine.use6309 ? "HD6309" : "MC6809").font(.system(.body, design: .monospaced))
Spacer()
Text("PC").foregroundStyle(.secondary)
Text("$" + DebuggerModel.hex(debugger.programCounter))
.font(.system(.body, design: .monospaced)).textSelection(.enabled)
.accessibilityIdentifier("debugger-pc")
TextField("New PC", text: $debugger.pcText).frame(width: 80)
.font(.system(.body, design: .monospaced)).textFieldStyle(.roundedBorder)
.onSubmit { debugger.setPC() }.disabled(!debugger.canEdit)
.accessibilityLabel("New program counter in hexadecimal")
.accessibilityIdentifier("debugger-pc-entry")
Button("Set PC", action: debugger.setPC).disabled(!debugger.canEdit)
.accessibilityIdentifier("debugger-set-pc")
.help("Change the next instruction address without resetting the machine.")
}.padding(.horizontal, 16).padding(.vertical, 9)
}
private var disassemblyNavigation: some View {
HStack(spacing: 6) {
TextField("Address", text: $debugger.addressText).frame(width: 80)
.font(.system(.body, design: .monospaced)).textFieldStyle(.roundedBorder)
.onSubmit { debugger.goToAddress() }
.accessibilityLabel("Disassembly address in hexadecimal")
.accessibilityIdentifier("debugger-address")
Button("Go", action: debugger.goToAddress).accessibilityIdentifier("debugger-go")
Toggle("Follow PC", isOn: $debugger.followPC).toggleStyle(.checkbox)
.accessibilityIdentifier("debugger-follow-pc")
}
}
private var disassembly: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 10) {
Text("").frame(width: 22)
Text("Address").frame(width: 65, alignment: .leading)
Text("Bytes").frame(width: 132, alignment: .leading)
Text("Instruction").frame(maxWidth: .infinity, alignment: .leading)
}.font(.caption).foregroundStyle(.secondary).padding(.horizontal, 12).padding(.vertical, 5)
ScrollView {
LazyVStack(alignment: .leading, spacing: 0) {
if let snapshot = debugger.snapshot {
ForEach(Array(snapshot.instructions.enumerated()), id: \.offset) { _, instruction in
instructionRow(instruction)
}
}
}
}.accessibilityIdentifier("debugger-disassembly")
}.background(Color(nsColor: .textBackgroundColor))
}
private func instructionRow(_ instruction: VCCDebugInstruction) -> some View {
let isPC = instruction.address == debugger.programCounter
let breakpoint = debugger.allBreakpoints.contains(instruction.address)
let enabled = debugger.breakpoints.contains(instruction.address)
return HStack(spacing: 10) {
Button { debugger.toggleBreakpoint(at: instruction.address) } label: {
Image(systemName: enabled ? "circle.fill" : breakpoint ? "circle.dashed" : "circle")
.foregroundStyle(enabled ? Color.red : Color.secondary.opacity(0.6))
.frame(width: 22, height: 24).contentShape(Rectangle())
}.buttonStyle(.plain).disabled(!debugger.commandsAvailable)
.help("\(breakpoint ? "Remove" : "Add") breakpoint at \(DebuggerModel.hex(instruction.address))").accessibilityLabel("\(breakpoint ? "Remove" : "Add") breakpoint at \(DebuggerModel.hex(instruction.address))")
.accessibilityIdentifier("debugger-breakpoint-\(DebuggerModel.hex(instruction.address))")
Text(DebuggerModel.hex(instruction.address)).frame(width: 65, alignment: .leading)
Text(instruction.bytes.map { String(format: "%02X", $0) }.joined(separator: " "))
.foregroundStyle(.secondary).frame(width: 132, alignment: .leading)
Text(instruction.mnemonic).fontWeight(isPC ? .semibold : .regular)
.frame(width: 62, alignment: .leading)
Text(instruction.operand).frame(maxWidth: .infinity, alignment: .leading)
if isPC { Image(systemName: "arrow.left").foregroundStyle(Color.accentColor).accessibilityLabel("Current instruction") }
}
.font(.system(size: 12, design: .monospaced)).padding(.horizontal, 12)
.background(isPC ? Color.accentColor.opacity(0.12) : Color.clear)
.contentShape(Rectangle())
.contextMenu {
Button(breakpoint ? "Remove Breakpoint" : "Add Breakpoint") { debugger.toggleBreakpoint(at: instruction.address) }
.disabled(!debugger.commandsAvailable)
if breakpoint {
Button(enabled ? "Disable Breakpoint" : "Enable Breakpoint") { debugger.setBreakpoint(instruction.address, enabled: !enabled) }
.disabled(!debugger.commandsAvailable)
}
Button("Show in Memory") { debugger.showMemory(at: instruction.address) }
Button("Set PC Here") { debugger.setPC(to: instruction.address) }.disabled(!debugger.canEdit)
Button("Copy Instruction") {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString("\(DebuggerModel.hex(instruction.address)) \(instruction.mnemonic) \(instruction.operand)", forType: .string)
}
}
}
private var memoryInspector: some View {
VStack(spacing: 0) {
HStack {
Picker("Memory inspector", selection: $debugger.memoryPane) {
ForEach(DebuggerModel.MemoryPane.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}.pickerStyle(.segmented).labelsHidden().frame(width: 180)
.accessibilityIdentifier("debugger-memory-pane")
Spacer()
if debugger.memoryPane == .memory {
Button {
graphics.inspectAddress(debugger.highlightedByte ?? debugger.displayedMemoryAddress, physical: debugger.physical)
workspace = .graphics
} label: { Label("Preview as Graphics", systemImage: "rectangle.on.rectangle") }
.accessibilityIdentifier("debugger-preview-memory")
}
if debugger.installedRAM > 0 {
Text("\(debugger.installedRAM / 1024) KB installed").font(.caption).foregroundStyle(.secondary)
}
}.padding(.horizontal, 12).padding(.vertical, 6)
Divider()
if debugger.memoryPane == .memory { memory } else { mmu }
}
}
private var memory: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 8) {
Picker("Address space", selection: Binding(get: { debugger.memorySpace }, set: debugger.setMemorySpace)) {
ForEach(DebuggerModel.MemorySpace.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}.labelsHidden().frame(width: 150).accessibilityIdentifier("debugger-memory-space")
.help("Mapped CPU follows the current MMU and ROM overlays. Physical RAM shows installed RAM directly.")
Spacer()
Button { debugger.pageMemory(forward: false) } label: { Image(systemName: "chevron.left") }
.disabled(!debugger.canPreviousMemory).help("Show the previous block of memory").accessibilityLabel("Previous memory block")
.accessibilityIdentifier("debugger-memory-previous")
Button { debugger.pageMemory(forward: true) } label: { Image(systemName: "chevron.right") }
.disabled(!debugger.canNextMemory).help("Show the next block of memory").accessibilityLabel("Next memory block")
.accessibilityIdentifier("debugger-memory-next")
TextField("Address", text: Binding(get: {
debugger.physical ? debugger.physicalAddressText : debugger.memoryAddressText
}, set: {
if debugger.physical { debugger.physicalAddressText = $0 } else { debugger.memoryAddressText = $0 }
})).frame(width: 86)
.font(.system(.body, design: .monospaced)).textFieldStyle(.roundedBorder)
.onSubmit { debugger.goToMemory() }
.accessibilityLabel(debugger.physical ? "Physical RAM address in hexadecimal" : "Memory address in hexadecimal")
.accessibilityIdentifier("debugger-memory-address")
Button("Go", action: debugger.goToMemory).accessibilityIdentifier("debugger-memory-go")
}.padding(12)
Divider()
ScrollView([.vertical, .horizontal]) {
VStack(alignment: .leading, spacing: 2) {
HStack(spacing: 3) {
Text("Address").frame(width: 58, alignment: .leading)
ForEach(0..<16) { Text(String(format: "%02X", $0)).frame(width: 24) }
Text("ASCII").frame(width: 128, alignment: .leading)
}.foregroundStyle(.secondary).padding(.bottom, 4)
ForEach(0..<((debugger.memory.count + 15) / 16), id: \.self) { row in
memoryRow(row)
}
}.font(.system(size: 11, design: .monospaced)).padding(12)
}.accessibilityIdentifier("debugger-memory")
Divider()
if debugger.physical {
Text("Physical RAM is read-only here. ROM overlays and I/O are excluded; the bytes may differ from the CPU's view.")
.font(.caption).foregroundStyle(.secondary).padding(10)
.accessibilityIdentifier("debugger-physical-read-only")
} else {
HStack(spacing: 8) {
Text("Edit RAM").font(.caption).foregroundStyle(.secondary)
TextField("Address", text: $debugger.editAddressText).frame(width: 75)
.accessibilityLabel("RAM edit address in hexadecimal").accessibilityIdentifier("debugger-edit-address")
TextField("Byte", text: $debugger.editByteText).frame(width: 48)
.accessibilityLabel("RAM byte in hexadecimal").accessibilityIdentifier("debugger-edit-byte")
.onSubmit { debugger.writeByte() }
Button(action: debugger.writeByte) { Label("Write", systemImage: "pencil") }.accessibilityIdentifier("debugger-write-memory")
Spacer()
Text("I/O: — · RAM edits require Pause").font(.caption).foregroundStyle(.secondary)
}.textFieldStyle(.roundedBorder).disabled(!debugger.canEditMemory).padding(10)
}
}.background(Color(nsColor: .textBackgroundColor))
}
private var mmu: some View {
ScrollView {
if let state = debugger.snapshot?.mmu {
VStack(alignment: .leading, spacing: 10) {
HStack {
Label(state.enabled ? "MMU enabled" : "MMU disabled", systemImage: "memorychip")
.font(.headline).accessibilityIdentifier("debugger-mmu-enabled")
Spacer()
Text("Task \(state.activeTask) selected").font(.caption)
.accessibilityIdentifier("debugger-mmu-task")
DebuggerHelpButton(title: "MMU mapping", text: "Each row maps an 8 KB CPU window. Task columns show programmed banks. Effective read shows the current selection, including fixed banks while MMU is disabled. RAM backing buttons inspect physical bytes, including RAM hidden by ROM overlays.")
}
Text("All-RAM: \(state.allRAM ? "on" : "off") · ROM map: \(state.romMap) · Bank prefix: $\(DebuggerModel.hex(state.prefix, width: 3))")
.font(.system(.caption, design: .monospaced)).foregroundStyle(.secondary)
.help("The prefix supplies high bits for future bank-register writes; changing it does not rewrite existing bank selections.")
VStack(spacing: 0) {
HStack(spacing: 10) {
Text("CPU range").frame(width: 88, alignment: .leading)
Text("Task 0").frame(width: 58, alignment: .leading)
.fontWeight(state.enabled && state.activeTask == 0 ? .bold : .regular)
Text("Task 1").frame(width: 58, alignment: .leading)
.fontWeight(state.enabled && state.activeTask == 1 ? .bold : .regular)
Text("Effective read").frame(width: 175, alignment: .leading)
Text("RAM backing").frame(width: 90, alignment: .leading)
}.font(.caption).foregroundStyle(.secondary).padding(.bottom, 5)
ForEach(Array(state.effective.enumerated()), id: \.offset) { index, mapping in
mmuRow(index, mapping: mapping, state: state)
}
}
Divider()
Text(state.ramVectors
? "FE00–FEFF: fixed RAM at $\(DebuggerModel.hex(state.vectorRAMAddress, width: 6)) (RAM vectors on)."
: "FE00–FEFF follows the final bank's mapping (RAM vectors off).")
.accessibilityIdentifier("debugger-mmu-vectors")
Text("FF00–FFEF: device I/O. FFF0–FFFF: system ROM vectors at $7FF0–$7FFF.")
Text("Disassembly and breakpoints continue to use logical CPU addresses.")
.foregroundStyle(.secondary)
}.font(.caption).padding(12).frame(minWidth: 540, maxWidth: .infinity, alignment: .leading)
}
}.background(Color(nsColor: .textBackgroundColor))
}
private func mmuRow(_ index: Int, mapping: VCCMemoryMapping, state: VCCMMUSnapshot) -> some View {
let start = index * 8192
let source = mapping.source == 0 ? "RAM" : mapping.source == 1 ? "System ROM" : "Cartridge ROM"
let offset = mapping.source == 0 ? "" : " $" + DebuggerModel.hex(mapping.sourceAddress)
return HStack(spacing: 10) {
Text("\(DebuggerModel.hex(start))–\(DebuggerModel.hex(start + 8191))")
.frame(width: 88, alignment: .leading)
Text(state.task0.count > index ? DebuggerModel.hex(state.task0[index].uint16Value, width: 3) : "—")
.frame(width: 58, alignment: .leading)
.foregroundStyle(state.enabled && state.activeTask == 0 ? Color.accentColor : Color.secondary)
Text(state.task1.count > index ? DebuggerModel.hex(state.task1[index].uint16Value, width: 3) : "—")
.frame(width: 58, alignment: .leading)
.foregroundStyle(state.enabled && state.activeTask == 1 ? Color.accentColor : Color.secondary)
Text("[\(DebuggerModel.hex(mapping.page, width: 3))] \(source)\(offset)")
.frame(width: 175, alignment: .leading).fixedSize(horizontal: false, vertical: true)
.accessibilityIdentifier("debugger-mmu-source-\(index)")
Button("$" + DebuggerModel.hex(mapping.ramAddress, width: 6)) { debugger.showPhysicalMemory(at: mapping.ramAddress) }
.buttonStyle(.link).frame(width: 90, alignment: .leading)
.accessibilityLabel("Inspect RAM backing for CPU \(DebuggerModel.hex(start)) at \(DebuggerModel.hex(mapping.ramAddress, width: 6))")
.accessibilityIdentifier("debugger-mmu-ram-\(index)")
}.font(.system(size: 11, design: .monospaced)).padding(.vertical, 4)
}
private func memoryRow(_ row: Int) -> some View {
let bytes = debugger.memory
let available = debugger.memoryAvailable
let start = row * 16
let address = debugger.memoryLocation(offset: start)
let ascii = (start..<min(start + 16, bytes.count)).map { index -> String in
guard index < available.count, available[index] != 0 else { return "—" }
let byte = bytes[index]
return byte >= 32 && byte <= 126 ? String(UnicodeScalar(byte)) : "."
}.joined()
return HStack(spacing: 3) {
Text(DebuggerModel.hex(address, width: debugger.memoryAddressWidth)).foregroundStyle(.secondary).frame(width: 58, alignment: .leading)
ForEach(0..<16) { column in
let index = start + column
let readable = index < bytes.count && index < available.count && available[index] != 0
let value = readable ? String(format: "%02X", bytes[index]) : "—"
let location = DebuggerModel.hex(debugger.memoryLocation(offset: index), width: debugger.memoryAddressWidth)
Group {
if debugger.physical {
// A selectable Text with a custom accessibility label can
// recurse through NSTextView's value/label bridge on macOS.
// Static bytes remain readable by VoiceOver without that
// extra text-editor accessibility node.
Text(value).foregroundStyle(.primary).frame(width: 24, height: 18)
.accessibilityLabel("Physical RAM \(location), \(value)")
} else {
Button { debugger.selectByte(offset: index) } label: {
Text(value).frame(width: 24, height: 18).contentShape(Rectangle())
}.buttonStyle(.plain).disabled(!readable)
.accessibilityLabel("Memory \(location), \(readable ? value : "unavailable")")
}
}
.background(debugger.highlightedByte == debugger.memoryLocation(offset: index) && readable ? Color.accentColor.opacity(0.24) : Color.clear, in: RoundedRectangle(cornerRadius: 3))
}
Text(ascii).foregroundStyle(.secondary).frame(width: 128, alignment: .leading)
}
}
private var inspector: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
HStack {
Label("Registers", systemImage: "cpu").font(.headline)
Spacer()
DebuggerHelpButton(title: "Registers", text: "Changed registers are highlighted after execution. Addresses and register values are hexadecimal.")
}
Grid(alignment: .leading, horizontalSpacing: 18, verticalSpacing: 7) {
ForEach(registerNames, id: \.self) { name in
let value = debugger.snapshot?.registers[name]?.uint16Value ?? 0
let changed = debugger.changedRegisters.contains(name)
GridRow {
Text(name).foregroundStyle(.secondary).frame(width: 30, alignment: .leading)
Text("$" + DebuggerModel.hex(value, width: ["A", "B", "E", "F", "DP", "CC", "MD"].contains(name) ? 2 : 4))
.foregroundStyle(changed ? Color.accentColor : Color.primary)
.fontWeight(changed ? .semibold : .regular)
.textSelection(.enabled).accessibilityIdentifier("debugger-register-\(name)")
if changed { Image(systemName: "arrow.triangle.2.circlepath").font(.caption2).foregroundStyle(Color.accentColor).accessibilityLabel("Changed") }
}
}
}.font(.system(.body, design: .monospaced))
flags
Divider()
breakpointInspector
}.padding(16)
}.background(Color(nsColor: .controlBackgroundColor))
}
private var registerNames: [String] {
machine.use6309 ? ["A", "B", "E", "F", "X", "Y", "U", "S", "V", "PC", "DP", "CC", "MD"] : ["A", "B", "X", "Y", "U", "S", "PC", "DP", "CC"]
}
private var flags: some View {
let cc = debugger.snapshot?.registers["CC"]?.uint8Value ?? 0
let names = ["E", "F", "H", "I", "N", "Z", "V", "C"]
let descriptions = ["Entire state saved", "FIRQ masked", "Half carry", "IRQ masked", "Negative", "Zero", "Overflow", "Carry"]
return VStack(alignment: .leading, spacing: 5) {
Text("Condition Codes").font(.caption).foregroundStyle(.secondary)
HStack(spacing: 4) {
ForEach(0..<8) { index in
let active = cc & (1 << (7 - index)) != 0
Text(names[index]).font(.system(.caption, design: .monospaced)).fontWeight(active ? .bold : .regular)
.frame(width: 23, height: 23)
.background(active ? Color.accentColor.opacity(0.18) : Color.secondary.opacity(0.06), in: RoundedRectangle(cornerRadius: 4))
.foregroundStyle(active ? Color.accentColor : Color.secondary)
.help(descriptions[index] + (active ? ": set" : ": clear"))
.accessibilityLabel(descriptions[index] + (active ? ", set" : ", clear"))
}
}
}
}
private var breakpointInspector: some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Label("Breakpoints", systemImage: "circle.fill").font(.headline)
Spacer()
Text("\(debugger.allBreakpoints.count)").foregroundStyle(.secondary)
DebuggerHelpButton(title: "Breakpoints", text: "Click a circle beside an instruction, or enter an address. Execution pauses before that instruction. Uncheck to disable without removing. Breakpoints use logical CPU addresses and belong to this session.")
}
HStack {
TextField("Hex address", text: $debugger.breakpointText)
.textFieldStyle(.roundedBorder).font(.system(.body, design: .monospaced))
.onSubmit { debugger.addBreakpoint() }
.accessibilityLabel("New breakpoint address in hexadecimal")
.accessibilityIdentifier("debugger-breakpoint-address")
Button(action: debugger.addBreakpoint) { Label("Add", systemImage: "plus") }.accessibilityIdentifier("debugger-add-breakpoint")
}.disabled(!debugger.commandsAvailable)
if debugger.allBreakpoints.isEmpty {
Text("Click a circle beside an instruction, or enter an address. Execution pauses before that instruction.")
.font(.caption).foregroundStyle(.secondary)
}
ForEach(debugger.allBreakpoints, id: \.self) { address in
let action = "\(debugger.breakpoints.contains(address) ? "Disable" : "Enable") breakpoint at \(DebuggerModel.hex(address))"
HStack {
Toggle("Enabled", isOn: Binding(get: { debugger.breakpoints.contains(address) }, set: { debugger.setBreakpoint(address, enabled: $0) }))
.toggleStyle(.checkbox).labelsHidden().disabled(!debugger.commandsAvailable)
.help(action).accessibilityLabel(action)
.accessibilityIdentifier("debugger-breakpoint-enabled-\(DebuggerModel.hex(address))")
Button("$" + DebuggerModel.hex(address)) {
debugger.showDisassembly(at: address)
}.buttonStyle(.plain).font(.system(.body, design: .monospaced))
Spacer()
Button { debugger.toggleBreakpoint(at: address) } label: { Image(systemName: "minus.circle") }
.buttonStyle(.plain).disabled(!debugger.commandsAvailable)
.help("Remove breakpoint at \(DebuggerModel.hex(address))").accessibilityLabel("Remove breakpoint at \(DebuggerModel.hex(address))")
}
}
if !debugger.allBreakpoints.isEmpty {
Button(action: debugger.removeAllBreakpoints) { Label("Remove All", systemImage: "minus.circle") }.disabled(!debugger.commandsAvailable)
}
}
}
private var statusBar: some View {
HStack(alignment: .firstTextBaseline, spacing: 12) {
if let error = debugger.validationMessage ?? machine.error {
Image(systemName: "exclamationmark.triangle").foregroundStyle(.orange)
Text(error).foregroundStyle(.primary).textSelection(.enabled)
.accessibilityIdentifier("debugger-error")
} else {
Text(debugger.snapshot?.stopReason.isEmpty == false ? debugger.snapshot!.stopReason : "Inspection preserves the running machine. Pause to step or edit RAM.")
.foregroundStyle(.secondary).accessibilityIdentifier("debugger-status")
}
Spacer(minLength: 12)
if let snapshot = debugger.snapshot {
Text("\(snapshot.machine.cycles.formatted()) cycles").monospacedDigit().foregroundStyle(.secondary)
}
}.font(.caption).padding(.horizontal, 14).padding(.vertical, 10)
}
}
// A native, keyboard-accessible help popover keeps panel toolbars compact.
// Its local presentation state is independent of live machine snapshots.
struct DebuggerHelpButton: View {
let title: String
let text: String
@State private var presented = false
var body: some View {
Button { presented.toggle() } label: {
Image(systemName: "questionmark.circle").frame(width: 22, height: 22)
}.buttonStyle(.plain).foregroundStyle(.secondary)
.accessibilityLabel(title + " help").help(title + " help")
.popover(isPresented: $presented) {
VStack(alignment: .leading, spacing: 8) {
Text(title).font(.headline)
Text(text).fixedSize(horizontal: false, vertical: true)
}.padding(18).frame(width: 340)
}
}
}