Disassembly view: Click to Select

This commit is contained in:
tudnai 2022-11-10 22:07:32 -08:00
parent 3537ae0379
commit 8ae44a587f
5 changed files with 139 additions and 24 deletions

View File

@ -228,6 +228,8 @@
32C82360290888D10018438F /* CheatMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32100A8A2875387300D894EE /* CheatMenu.swift */; };
32D0897C291A44F200F2B486 /* 6502_bp.c in Sources */ = {isa = PBXBuildFile; fileRef = 32D0897B291A44F200F2B486 /* 6502_bp.c */; };
32D0897D291A44F200F2B486 /* 6502_bp.c in Sources */ = {isa = PBXBuildFile; fileRef = 32D0897B291A44F200F2B486 /* 6502_bp.c */; };
32D089D8291E1BF800F2B486 /* DisassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D089D7291E1BF800F2B486 /* DisassView.swift */; };
32D089D9291E1BF800F2B486 /* DisassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32D089D7291E1BF800F2B486 /* DisassView.swift */; };
32E3126624A7193700E61891 /* disk_ii_arm.sfx in Resources */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; };
32E3126724A7194900E61891 /* disk_ii_arm.sfx in Copy SFX Files */ = {isa = PBXBuildFile; fileRef = 32E3126424A7193700E61891 /* disk_ii_arm.sfx */; };
32E3126924A98B9300E61891 /* dsk2woz.c in Sources */ = {isa = PBXBuildFile; fileRef = 32E3126824A98B9300E61891 /* dsk2woz.c */; };
@ -747,6 +749,7 @@
32D0897B291A44F200F2B486 /* 6502_bp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = 6502_bp.c; sourceTree = "<group>"; };
32D08987291A450400F2B486 /* 6502_bp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = 6502_bp.h; sourceTree = "<group>"; };
32D08992291AF23500F2B486 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = A2Mac/Base.lproj/Debug.storyboard; sourceTree = "<group>"; };
32D089D7291E1BF800F2B486 /* DisassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisassView.swift; sourceTree = "<group>"; };
32DBF7632334657900DD50E7 /* HiRes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiRes.swift; sourceTree = "<group>"; };
32DBF76723373FB400DD50E7 /* disassembler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = disassembler.h; sourceTree = "<group>"; };
32E21BE62491BF8B006C0C72 /* apple-rainbow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "apple-rainbow.png"; sourceTree = "<group>"; };
@ -1179,6 +1182,7 @@
32E3126C24AC033A00E61891 /* ToolBarController.swift */,
32C6995127C5439300D0F25D /* Debugger.swift */,
323D042F24898AB70086A901 /* PreferencesViewController.swift */,
32D089D7291E1BF800F2B486 /* DisassView.swift */,
327B75D629064FDC00A86A71 /* DebuggerViewController.swift */,
32C823392908822E0018438F /* DebuggerWindowController.swift */,
323D04312489BFD80086A901 /* PreferencesWindowController.swift */,
@ -1661,6 +1665,7 @@
32A6AB10266AF5160023257A /* paddle.c in Sources */,
32799F83264B1A5700255669 /* speaker.c in Sources */,
32799F84264B1A5700255669 /* common.c in Sources */,
32D089D9291E1BF800F2B486 /* DisassView.swift in Sources */,
32799F85264B1A5700255669 /* ViewController.swift in Sources */,
32799F86264B1A5700255669 /* HiRes.swift in Sources */,
32799F87264B1A5700255669 /* LoRes.swift in Sources */,
@ -1693,6 +1698,7 @@
325EB63623F8F78300C6B4A4 /* disk.c in Sources */,
32100A8B2875387300D894EE /* CheatMenu.swift in Sources */,
3268B97A27DE7D6A003FBDCC /* disassembler.c in Sources */,
32D089D8291E1BF800F2B486 /* DisassView.swift in Sources */,
32C6995D27C548C800D0F25D /* Shaders.metal in Sources */,
325EB62F23F8856F00C6B4A4 /* woz.c in Sources */,
32100AB42877AB8600D894EE /* scsi.c in Sources */,

View File

@ -481,6 +481,9 @@
<ContextState
contextName = "_addr_zp_X_dbg:mmio.c">
</ContextState>
<ContextState
contextName = "main:AppDelegate.swift">
</ContextState>
<ContextState
contextName = "DebuggerViewController.mouseMoved(with:):DebuggerViewController.swift">
<PersistentStrings>
@ -1375,5 +1378,16 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "DebuggerViewController.highlightCursor(scrollView:mouseLocation:):DebuggerViewController.swift">
<PersistentStrings>
<PersistentString
value = "display">
</PersistentString>
<PersistentString
value = "scrollView.subviews">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>

View File

@ -256,8 +256,8 @@
<rect key="frame" x="1" y="1" width="349" height="478"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" verticallyResizable="YES" baseWritingDirection="leftToRight" findStyle="bar" allowsCharacterPickerTouchBarItem="NO" textCompletion="NO" id="Hwx-Gd-XW1" userLabel="Disass Display" customClass="DisplayView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-162" width="349" height="1155"/>
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" verticallyResizable="YES" baseWritingDirection="leftToRight" findStyle="bar" allowsCharacterPickerTouchBarItem="NO" textCompletion="NO" id="Hwx-Gd-XW1" userLabel="Disass Display" customClass="DisassView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-196" width="349" height="1155"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="0.12549019610000001" green="0.12549019610000001" blue="0.12549019610000001" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
@ -475,7 +475,7 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" verticallyResizable="YES" baseWritingDirection="leftToRight" findStyle="bar" allowsCharacterPickerTouchBarItem="NO" textCompletion="NO" id="BHr-Q4-rBI" userLabel="Stack Display" customClass="DisplayView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-225" width="334" height="165"/>
<rect key="frame" x="0.0" y="-232" width="334" height="165"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>

View File

@ -23,7 +23,7 @@
import Cocoa
class DebuggerViewController: NSViewController, NSTextFieldDelegate {
class DebuggerViewController: NSViewController {
static var shared : DebuggerViewController? = nil
@IBOutlet var CPU_Display: DisplayView!
@ -221,7 +221,7 @@ N V - B D I Z C
let lines_to_disass = 300
func get_scroll_line(view: DisplayView) -> Int {
func get_scroll_line(view: NSTextView) -> Int {
let scrollPos = view.visibleRect.origin.y
let lineSpacing = CGFloat(1.5)
let lineHeight = view.font!.pointSize * lineSpacing
@ -277,7 +277,7 @@ N V - B D I Z C
let lineFromTopToMiddle = 15
func scroll_to(view: DisplayView, line: Int) {
func scroll_to(view: NSTextView, line: Int) {
if let lineRange = getLineRange(inView: view, forLine: line + lineFromTopToMiddle) {
view.scrollRangeToVisible(lineRange)
}
@ -295,7 +295,7 @@ N V - B D I Z C
]
func remove_highlight(view: DisplayView, line: Int) {
func remove_highlight(view: NSTextView, line: Int) {
if line > 0 {
if let lineRange = getLineRange(inView: view, forLine: line) {
view.layoutManager?.removeTemporaryAttribute(NSAttributedString.Key.backgroundColor, forCharacterRange: lineRange)
@ -305,7 +305,7 @@ N V - B D I Z C
}
func highlight(view: DisplayView, line: Int, attr: [NSAttributedString.Key : Any]) {
func highlight(view: NSTextView, line: Int, attr: [NSAttributedString.Key : Any]) {
if line > 0 {
// remove old highlighted line
remove_highlight(view: view, line: line)
@ -328,32 +328,40 @@ N V - B D I Z C
}
override func mouseMoved(with event: NSEvent) {
var location = event.locationInWindow
let disass_frame = Disass_Scroll.superview?.frame
let minX = disass_frame!.minX + Disass_Scroll.frame.minX
let minY = disass_frame!.minY + Disass_Scroll.frame.minY
let maxX = minX + Disass_Scroll.frame.width
let maxY = minY + Disass_Scroll.frame.height
func highlightCursor(scrollView : NSView, display : NSTextView, mouseLocation : 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
// if isMouseInView(view: Disass_Scroll) {
if location.x > minX && location.x < maxX
&& location.y > minY && location.y < maxY {
// location.x -= Disass_Scroll.frame.origin.x
// location.y -= Disass_Scroll.frame.origin.y
location.x = maxX - location.x
location.y = maxY - location.y + Disass_Display.visibleRect.origin.y
// print(location)
location.y = maxY - location.y + display.visibleRect.origin.y
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)
let line = getLine(inView: display, forY: location.y)
highlight(view: display, line: line_number_at_PC, attr: lineAttrAtPC)
remove_highlight(view: display, line: line_number_cursor)
highlight(view: display, line: line, attr: lineAttrAtSelected)
line_number_cursor = line
}
}
override func mouseDown(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 DisplayDisassembly() {

87
A2Mac/DisassView.swift Normal file
View File

@ -0,0 +1,87 @@
//
// DisassView.swift
// Steve ][
//
// Created by Tamas Rudnai on 5/11/21.
// Copyright © 2021 GameAlloy. All rights reserved.
//
import Cocoa
class DisassView: NSTextView {
override var acceptsFirstResponder: Bool {
get {
return true
}
}
var trackingArea: NSTrackingArea?
func debugDisplayContraints() {
print( "debugDisplayContraints ----------------------------------" )
if let view = window?.contentView {
for constraint in view.constraints {
print( "debugDisplayContraints:", constraint.identifier ?? "{Constaint has no identifier}", constraint.constant )
}
}
}
/// Install tracking area if window is set, remove previous one if needed.
func installTrackingArea() {
guard let window = window else { return }
window.acceptsMouseMovedEvents = true
if trackingArea != nil { removeTrackingArea(trackingArea!) }
let trackingOptions : NSTrackingArea.Options = [.activeAlways, .mouseEnteredAndExited, .mouseMoved]
trackingArea = NSTrackingArea(rect: bounds,
options: trackingOptions,
owner: self, userInfo: nil)
self.addTrackingArea(trackingArea!)
}
// Called when layout is modified
override func updateTrackingAreas() {
super.updateTrackingAreas()
installTrackingArea()
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
return true
}
override func mouseDown(with event: NSEvent) {
// print(#function + "DisassView")
DebuggerViewController.shared?.mouseDown(with: event)
// debugDisplayContraints()
}
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 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)
}
}