diff --git a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist index ec5ebce..ce10f13 100644 --- a/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/A2Mac.xcodeproj/project.xcworkspace/xcuserdata/trudnai.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -1183,6 +1183,14 @@ + + + + + + diff --git a/A2Mac/DebuggerViewController.swift b/A2Mac/DebuggerViewController.swift index 9ee292d..61610b9 100644 --- a/A2Mac/DebuggerViewController.swift +++ b/A2Mac/DebuggerViewController.swift @@ -328,6 +328,22 @@ N V - B D I Z C } + func convertMouseCoordinates(scrollView : NSView, display : NSTextView, mouseLocation : NSPoint) -> NSPoint { + var location = mouseLocation + let parent_frame = scrollView.superview?.frame + +// let minX = parent_frame!.minX + scrollView.frame.minX + let minY = parent_frame!.minY + scrollView.frame.minY +// let maxX = minX + scrollView.frame.width + let maxY = minY + scrollView.frame.height + +// location.x = maxX - location.x + location.y = maxY - location.y + display.visibleRect.origin.y + + return location + } + + func highlightCursor(scrollView : NSView, display : NSTextView, mouseLocation : NSPoint) { var location = mouseLocation let parent_frame = scrollView.superview?.frame @@ -339,7 +355,7 @@ N V - B D I Z C if location.x > minX && location.x < maxX && location.y > minY && location.y < maxY { - location.x = maxX - location.x +// location.x = maxX - location.x location.y = maxY - location.y + display.visibleRect.origin.y let line = getLine(inView: display, forY: location.y) @@ -351,19 +367,50 @@ N V - B D I Z C } + // select disassembly line override func mouseDown(with event: NSEvent) { + let location = convertMouseCoordinates(scrollView: Disass_Scroll, display: Disass_Display, mouseLocation: event.locationInWindow) + + if location.x < 30 { + let line = getLine(inView: Disass_Display, forY: location.y) + let addr = getAddr(forLine: line) + + if m6502_dbg_bp_is_exists(addr) { + m6502_dbg_bp_del(addr) + } + else { + m6502_dbg_bp_add(addr) + } + + // force regenerate disassembly + disass_addr = 0xFFFF + DisplayDisassembly() +// scroll_to(view: Disass_Display, line: line) + } + else { + highlightCursor(scrollView: Disass_Scroll, display: Disass_Display, mouseLocation: location) + } + } + + + // context menu + override func rightMouseDown(with event: NSEvent) { let location = event.locationInWindow highlightCursor(scrollView: Disass_Scroll, display: Disass_Display, mouseLocation: location) } -// override func mouseMoved(with event: NSEvent) { -// let location = event.locationInWindow -// highlightCursor(scrollView: Disass_Scroll, display: Disass_Display, mouseLocation: location) -// } - var addr_line = [UInt16 : Int]() + func getLine(forAddr: UInt16) -> Int { + return addr_line[forAddr] ?? 0 + } + + func getAddr(forLine: Int) -> UInt16 { + return addr_line.first(where: { $1 == forLine })?.key ?? 0 + } + + func DisplayDisassembly() { let m6502_saved = m6502 var disass = "" @@ -378,7 +425,7 @@ N V - B D I Z C // TODO: Also check if memory area updated! var need_disass = m6502.PC < disass_addr || m6502.PC > disass_addr + disass_addr_max - line_number_at_PC = addr_line[m6502_saved.PC] ?? 0 + line_number_at_PC = getLine(forAddr: m6502_saved.PC) // if m6502.PC > disass_addr && m6502.PC < disass_addr + disass_addr_max { if line_number_at_PC != 0 && !need_disass { diff --git a/A2Mac/DisassView.swift b/A2Mac/DisassView.swift index 1034d73..7b0e140 100644 --- a/A2Mac/DisassView.swift +++ b/A2Mac/DisassView.swift @@ -58,30 +58,30 @@ class DisassView: NSTextView { // debugDisplayContraints() } - override func mouseUp(with event: NSEvent) { - // print(#function + "DisassView") - DebuggerViewController.shared?.mouseUp(with: event) - } +// override func mouseUp(with event: NSEvent) { +// // print(#function + "DisassView") +// DebuggerViewController.shared?.mouseUp(with: event) +// } override func rightMouseDown(with event: NSEvent) { // print(#function + "DisassView") DebuggerViewController.shared?.rightMouseDown(with: event) } - override func rightMouseUp(with event: NSEvent) { - // print(#function + "DisassView") - DebuggerViewController.shared?.rightMouseUp(with: event) - } +// override func rightMouseUp(with event: NSEvent) { +// // print(#function + "DisassView") +// DebuggerViewController.shared?.rightMouseUp(with: event) +// } - override func otherMouseDown(with event: NSEvent) { - // print(#function + "DisassView") - DebuggerViewController.shared?.otherMouseDown(with: event) - } - - override func otherMouseUp(with event: NSEvent) { - // print(#function + "DisassView") - DebuggerViewController.shared?.otherMouseUp(with: event) - } +// override func otherMouseDown(with event: NSEvent) { +// // print(#function + "DisassView") +// DebuggerViewController.shared?.otherMouseDown(with: event) +// } +// +// override func otherMouseUp(with event: NSEvent) { +// // print(#function + "DisassView") +// DebuggerViewController.shared?.otherMouseUp(with: event) +// } } diff --git a/src/cpu/6502.c b/src/cpu/6502.c index ab90a8f..31e359d 100644 --- a/src/cpu/6502.c +++ b/src/cpu/6502.c @@ -419,7 +419,7 @@ void m6502_Run() { void m6502_Debug(void) { m6502.clktime += m6502.clkfrm; - m6502.clkfrm = 0; +// m6502.clkfrm = 0; m6502.lastIO = 0; m6502.interrupt = NO_INT; // TODO: This should be taken care by the interrupt handler @@ -436,14 +436,9 @@ void m6502_Debug(void) { } } - if ( m6502_dbg_bp_is_exists(m6502.PC) ) { - cpuState = cpuState_halted; - m6502.debugger.wMask = 0; - m6502.debugger.on = 0; - return; - } + clk_6502_per_frm_max = clk_6502_per_frm; - for ( clk_6502_per_frm_max = clk_6502_per_frm; m6502.clkfrm < clk_6502_per_frm_max ; m6502.clkfrm += m6502_Step() ) { + for ( m6502.clkfrm = m6502_Step(); m6502.clkfrm < clk_6502_per_frm_max ; m6502.clkfrm += m6502_Step() ) { switch (m6502.interrupt) { case HALT: if (m6502.debugger.mask.hlt) { @@ -514,6 +509,14 @@ void m6502_Debug(void) { } m6502.interrupt = NO_INT; + + if ( m6502_dbg_bp_is_exists(m6502.PC) ) { + cpuState = cpuState_halted; + m6502.debugger.wMask = 0; + m6502.debugger.on = 0; + return; + } + } } diff --git a/src/cpu/6502_bp.c b/src/cpu/6502_bp.c index bff4aa8..ac9f557 100644 --- a/src/cpu/6502_bp.c +++ b/src/cpu/6502_bp.c @@ -77,11 +77,11 @@ uint16_t m6502_dbg_bp_get_first() { /// m6502_dbg_bp_get_first /// Get first valid BP /// @return addr of BP or 0 if non -uint16_t m6502_dbg_bp_is_exists(uint16_t addr) { +_Bool m6502_dbg_bp_is_exists(uint16_t addr) { for (uint16_t bp = m6502_dbg_bp_get_first(); bp; bp = m6502_dbg_bp_get_next()) { if ( bp == addr) { // found it! - return bp; + return 1; } } return 0; @@ -103,16 +103,26 @@ int m6502_dbg_bp_add(uint16_t addr) { } -void m6502_dbg_bp_init(void) { +/// m6502_dbg_bp_del +/// Remove a breakpoint +/// @param addr address to remove +void m6502_dbg_bp_del(uint16_t addr) { + for (uint16_t bp = m6502_dbg_bp_get_first(); bp; bp = m6502_dbg_bp_get_next()) { + if ( bp == addr ) { + breakpoints[bp_idx] = 0; + } + } +} + + +void m6502_dbg_bp_del_all(void) { bp_idx = 0; memset(breakpoints, 0, sizeof(breakpoints)); - - m6502_dbg_bp_add(0xC28B); // keyin DOS 3.3 } void m6502_dbg_init(void) { - m6502_dbg_bp_init(); + m6502_dbg_bp_del_all(); } diff --git a/src/cpu/6502_bp.h b/src/cpu/6502_bp.h index 5e6ba8f..e5f1dd0 100644 --- a/src/cpu/6502_bp.h +++ b/src/cpu/6502_bp.h @@ -16,7 +16,9 @@ extern uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS]; extern void m6502_dbg_init(void); extern int m6502_dbg_bp_add(uint16_t addr); -extern uint16_t m6502_dbg_bp_is_exists(uint16_t addr); +extern void m6502_dbg_bp_del(uint16_t addr); +extern void m6502_dbg_bp_del_all(void); +extern _Bool m6502_dbg_bp_is_exists(uint16_t addr); #endif /* _6502_bp_h */