diff --git a/A2Mac/Base.lproj/Main.storyboard b/A2Mac/Base.lproj/Main.storyboard index 7a8d55f..50512f7 100644 --- a/A2Mac/Base.lproj/Main.storyboard +++ b/A2Mac/Base.lproj/Main.storyboard @@ -1525,7 +1525,7 @@ Gw - + @@ -1811,8 +1811,8 @@ Gw - - + + @@ -1948,7 +1948,7 @@ Gw - + @@ -2000,7 +2000,7 @@ Gw - + @@ -2052,8 +2052,7 @@ Gw - - + @@ -2105,10 +2104,10 @@ Gw - + - - + - - + - - + - - + - - + - + @@ -2236,8 +2235,8 @@ Gw - - + @@ -2305,6 +2304,7 @@ Gw + @@ -2356,7 +2356,6 @@ Gw - @@ -139131,7 +139130,7 @@ BQB9EQcAfREJAH0RCwB9ERQAfREZAH0RHwB9EScAfREpAH0RKwB9ES0AfREvAH0imwB9IqAAfSKtAH0i sAB9Ir0AfSLCAH0iygB9Is0AfSLSAH0i2gAAAAAAAAQBAAAAAAAAAFAAAAAAAAAAAAAAAAAAfSLdA - + YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05T S2V5ZWRBcmNoaXZlctEICVRyb290gAGvEBcLDBkaIRQmKisyNTo9PkNGR0pUXF1hZFUkbnVsbNYNDg8Q diff --git a/A2Mac/DebuggerViewController.swift b/A2Mac/DebuggerViewController.swift index 26a5866..71f0cf9 100644 --- a/A2Mac/DebuggerViewController.swift +++ b/A2Mac/DebuggerViewController.swift @@ -294,15 +294,28 @@ N V - B D I Z C NSAttributedString.Key.foregroundColor: NSColor.cyan, ] - func highlight(view: DisplayView, line: Int, attr: [NSAttributedString.Key : Any]) { - if let lineRange = getLineRange(inView: view, forLine: line) { -// view.selectedRange = lineRange -// view.scrollRangeToVisible(lineRange) - if let oldLineRange = getLineRange(inView: view, forLine: line_number_cursor) { - view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: oldLineRange) - view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.foregroundColor, forCharacterRange: oldLineRange) + + func remove_highlight(view: DisplayView, line: Int) { + if line > 0 { + if let lineRange = getLineRange(inView: view, forLine: line) { + view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: lineRange) + view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.foregroundColor, forCharacterRange: lineRange) + } + } + } + + + func highlight(view: DisplayView, line: Int, attr: [NSAttributedString.Key : Any]) { + if line > 0 { + // remove old highlighted line + remove_highlight(view: view, line: line) + if let lineRange = getLineRange(inView: view, forLine: line) { + // view.selectedRange = lineRange + // view.scrollRangeToVisible(lineRange) +// remove_highlight(view: view, line: line_number_cursor) +// line_number_cursor = 0 + view.layoutManager?.addTemporaryAttributes(attr, forCharacterRange: lineRange) } - view.layoutManager?.addTemporaryAttributes(attr, forCharacterRange: lineRange) } } @@ -334,6 +347,7 @@ N V - B D I Z C let line = getLine(inView: Disass_Display, forY: location.y) highlight(view: Disass_Display, line: line_number_at_PC, attr: lineAttrAtPC) + remove_highlight(view: Disass_Display, line: line_number_cursor) highlight(view: Disass_Display, line: line, attr: lineAttrAtSelected) line_number_cursor = line } @@ -345,12 +359,21 @@ N V - B D I Z C var disass = "" line_number = 0 + + let highlighted = self.line_number_at_PC + DispatchQueue.main.async { + self.remove_highlight(view: self.Disass_Display, line: highlighted) + } line_number_at_PC = 0 + var need_disass = false + if m6502.PC > disass_addr && m6502.PC < disass_addr + disass_addr_max { m6502.PC = disass_addr } else { + need_disass = true + disass_addr = m6502.PC if m6502.PC >= disass_addr_min_pre { m6502.PC -= disass_addr_min_pre @@ -387,7 +410,10 @@ N V - B D I Z C DispatchQueue.main.async { // let isEmpty = self.Disass_Display.string.isEmpty - self.Disass_Display.string = disass + if need_disass { + self.Disass_Display.string = disass + } + let currentScrollLine = self.get_scroll_line(view: self.Disass_Display) + 1 if self.line_number_at_PC <= currentScrollLine || self.line_number_at_PC > currentScrollLine + 35 { self.scroll_to(view: self.Disass_Display, line: self.line_number_at_PC - 5) @@ -395,30 +421,32 @@ N V - B D I Z C // at the beginning it takes a while to fill up the buffer -- maybe allocation issue? if currentScrollLine == 1 { // so we need to scroll a bit later when the string is already populated - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { +// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { self.scroll_to(view: self.Disass_Display, line: self.line_number_at_PC - 5) - } +// } } } self.highlight(view: self.Disass_Display, line: self.line_number_at_PC, attr: self.lineAttrAtPC) } - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { +// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // your code here - } +// } m6502 = m6502_saved } let UpdateSemaphore = DispatchSemaphore(value: 1) func Update() { - UpdateSemaphore.wait() + DispatchQueue.global().async { + self.UpdateSemaphore.wait() - DisplayRegisters() - DisplayStack() - DisplayMemory() - DisplayDisassembly() + self.DisplayRegisters() + self.DisplayStack() + self.DisplayMemory() + self.DisplayDisassembly() - UpdateSemaphore.signal() + self.UpdateSemaphore.signal() + } } } diff --git a/A2Mac/Info.plist b/A2Mac/Info.plist index e5667be..4de6ec2 100644 --- a/A2Mac/Info.plist +++ b/A2Mac/Info.plist @@ -32,5 +32,10 @@ Main NSPrincipalClass NSApplication + UIAppFonts + + PrintChar21.ttf + PRNumber3.ttf + diff --git a/A2Mac/ViewController.swift b/A2Mac/ViewController.swift index e2ec58e..d3c36d1 100644 --- a/A2Mac/ViewController.swift +++ b/A2Mac/ViewController.swift @@ -1265,6 +1265,16 @@ class ViewController: NSViewController { } + func debugBreak() { + Pause() + + // TODO: This should be in Debugger! + if let debugger = DebuggerViewController.shared { + debugger.Update() + } + } + + let UpdateSemaphore = DispatchSemaphore(value: 1) func Update() { if UpdateSemaphore.wait(timeout: .now() + 0.001) == .timedOut { @@ -1305,21 +1315,21 @@ class ViewController: NSViewController { switch m6502.interrupt { case HALT: - Pause() + debugBreak() case BREAK: - Pause() + debugBreak() case RET: if m6502.debugger.mask.ret == 1 { // Step_Out / Step_Over if m6502.PC >= m6502.debugger.SP { - Pause() + debugBreak() } } case INV: - Pause() + debugBreak() default: break @@ -1340,7 +1350,7 @@ class ViewController: NSViewController { if let debugger = DebuggerViewController.shared { debugger.Update() } - + #endif break @@ -1354,7 +1364,7 @@ class ViewController: NSViewController { cpuState = cpuState_halted // last video rendering before halt Render() - + break case cpuState_halted: diff --git a/src/cpu/6502.c b/src/cpu/6502.c index bb53cbb..ab90a8f 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -439,6 +439,7 @@ void m6502_Debug(void) { if ( m6502_dbg_bp_is_exists(m6502.PC) ) { cpuState = cpuState_halted; m6502.debugger.wMask = 0; + m6502.debugger.on = 0; return; }