mirror of
https://github.com/trudnai/Steve2.git
synced 2025-04-18 00:40:07 +00:00
Colorful debug lines + highlighted text lines in disassembly view
This commit is contained in:
parent
be0712990c
commit
58e0edc400
@ -178,6 +178,14 @@
|
||||
</PersistentString>
|
||||
</PersistentStrings>
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "DebuggerViewController.highlight(view:line:attr:):DebuggerViewController.swift">
|
||||
<PersistentStrings>
|
||||
<PersistentString
|
||||
value = "highlightedLine">
|
||||
</PersistentString>
|
||||
</PersistentStrings>
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "specialized closure #1 in ViewController.Update():ViewController.swift">
|
||||
<PersistentStrings>
|
||||
@ -473,6 +481,23 @@
|
||||
<ContextState
|
||||
contextName = "_addr_zp_X_dbg:mmio.c">
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "DebuggerViewController.mouseMoved(with:):DebuggerViewController.swift">
|
||||
<PersistentStrings>
|
||||
<PersistentString
|
||||
value = "highlightedLine">
|
||||
</PersistentString>
|
||||
<PersistentString
|
||||
value = "Disass_Display.frame.minX">
|
||||
</PersistentString>
|
||||
<PersistentString
|
||||
value = "Disass_Display.frame">
|
||||
</PersistentString>
|
||||
<PersistentString
|
||||
value = "Disass_Display.visibleRect">
|
||||
</PersistentString>
|
||||
</PersistentStrings>
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "BRA:6502_instr_branch.h">
|
||||
<PersistentStrings>
|
||||
|
@ -174,14 +174,14 @@
|
||||
<action selector="SetBreakPoint:" target="g5o-m8-tZm" id="xSR-v7-K7U"/>
|
||||
</connections>
|
||||
</toolbarItem>
|
||||
<toolbarItem implicitItemIdentifier="32E3CBD1-1CC4-4542-91D9-BFB4A092113B" label="BPs" paletteLabel="Breakpoints" image="NSTouchBarTextListTemplate" id="ULc-zd-2pO" userLabel="Breakpoints">
|
||||
<toolbarItem implicitItemIdentifier="32E3CBD1-1CC4-4542-91D9-BFB4A092113B" label="BPs" paletteLabel="Breakpoints" image="Debugger" id="ULc-zd-2pO" userLabel="Breakpoints">
|
||||
<nil key="toolTip"/>
|
||||
<size key="minSize" width="30" height="17"/>
|
||||
<size key="maxSize" width="30" height="43"/>
|
||||
<button key="view" verticalHuggingPriority="750" id="V6J-lV-2sp">
|
||||
<rect key="frame" x="20" y="14" width="30" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="bevel" bezelStyle="rounded" image="NSTouchBarTextListTemplate" imagePosition="only" alignment="center" refusesFirstResponder="YES" imageScaling="proportionallyUpOrDown" inset="2" id="tBj-Wd-GIS">
|
||||
<buttonCell key="cell" type="bevel" bezelStyle="rounded" image="Debugger" imagePosition="only" alignment="center" refusesFirstResponder="YES" imageScaling="proportionallyUpOrDown" inset="2" id="tBj-Wd-GIS">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
@ -339,21 +339,13 @@ CE11: 85 28 STA $28
|
||||
CE13: 60 RTS
|
||||
C20A: 28 PLP
|
||||
C20B: 30 03 BMI $C210
|
||||
C20D: 4C C5 FE JMP $FEC5
|
||||
</mutableString>
|
||||
C20D: 4C C5 FE JMP $FEC5
FEC5: 8D 06 C0 STA $C006</mutableString>
|
||||
<attributes>
|
||||
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<font key="NSFont" size="10" name="PrintChar21"/>
|
||||
<paragraphStyle key="NSParagraphStyle" alignment="natural" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" lineHeightMultiple="1.5" tighteningFactorForTruncation="0.0"/>
|
||||
</attributes>
|
||||
</fragment>
|
||||
<fragment content="FEC5: 8D 06 C0 STA $C006">
|
||||
<attributes>
|
||||
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<font key="NSFont" size="10" name="PrintChar21"/>
|
||||
<paragraphStyle key="NSParagraphStyle" alignment="natural" lineBreakMode="wordWrapping" baseWritingDirection="leftToRight" firstLineHeadIndent="8" headIndent="8" lineHeightMultiple="1.5" tighteningFactorForTruncation="0.0"/>
|
||||
</attributes>
|
||||
</fragment>
|
||||
</attributedString>
|
||||
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
</textView>
|
||||
@ -735,6 +727,7 @@ C20D: 4C C5 FE JMP $FEC5
|
||||
<connections>
|
||||
<outlet property="CPU_Display" destination="Wrs-Qt-Kmd" id="SUW-Lc-Zv4"/>
|
||||
<outlet property="Disass_Display" destination="Hwx-Gd-XW1" id="XHS-dZ-gCR"/>
|
||||
<outlet property="Disass_Scroll" destination="Pcn-4j-EEM" id="5w1-DZ-ypu"/>
|
||||
<outlet property="Mem1_Display" destination="qqp-t0-j4i" id="85A-sB-M0p"/>
|
||||
<outlet property="Stack_Display" destination="BHr-Q4-rBI" id="qlA-JC-xkW"/>
|
||||
</connections>
|
||||
@ -755,7 +748,6 @@ C20D: 4C C5 FE JMP $FEC5
|
||||
<image name="NSTouchBarGoUpTemplate" width="16" height="30"/>
|
||||
<image name="NSTouchBarPauseTemplate" width="11" height="30"/>
|
||||
<image name="NSTouchBarSkipToEndTemplate" width="12" height="30"/>
|
||||
<image name="NSTouchBarTextListTemplate" width="18" height="30"/>
|
||||
<image name="NSTrashEmpty" width="32" height="32"/>
|
||||
<image name="popUpButtonCell:0qv-E9-TgB:image" width="1" height="1">
|
||||
<mutableData key="keyedArchiveRepresentation">
|
||||
|
@ -29,6 +29,7 @@ class DebuggerViewController: NSViewController, NSTextFieldDelegate {
|
||||
@IBOutlet var CPU_Display: DisplayView!
|
||||
@IBOutlet var Stack_Display: DisplayView!
|
||||
@IBOutlet var Mem1_Display: DisplayView!
|
||||
@IBOutlet var Disass_Scroll: DisplayScrollView!
|
||||
@IBOutlet var Disass_Display: DisplayView!
|
||||
|
||||
// required init?(coder: NSCoder) {
|
||||
@ -185,11 +186,24 @@ N V - B D I Z C
|
||||
}
|
||||
|
||||
|
||||
func ASCII_to_Apple2(line : String) -> String {
|
||||
var converted = ""
|
||||
|
||||
for chr in line {
|
||||
let c = Int(chr.asciiValue!) & 0x3F | 0x80
|
||||
converted.append(ViewController.charConvTbl[c])
|
||||
}
|
||||
|
||||
return converted
|
||||
}
|
||||
|
||||
|
||||
func invertLine(line : String) -> String {
|
||||
var converted = ""
|
||||
|
||||
for chr in line {
|
||||
converted.append(ViewController.charConvTbl[Int(chr.asciiValue!)])
|
||||
let c = Int(chr.asciiValue!) & 0x3F
|
||||
converted.append(ViewController.charConvTbl[c])
|
||||
}
|
||||
|
||||
return converted
|
||||
@ -202,7 +216,8 @@ N V - B D I Z C
|
||||
let disass_addr_pre : UInt16 = 20
|
||||
let disass_addr_min_pre : UInt16 = 320 - 20
|
||||
var line_number = 0
|
||||
var current_line_number = 0
|
||||
var line_number_at_PC = 0
|
||||
var line_number_cursor = 0
|
||||
let lines_to_disass = 300
|
||||
|
||||
|
||||
@ -215,7 +230,7 @@ N V - B D I Z C
|
||||
}
|
||||
|
||||
|
||||
func scroll_to(view: DisplayView, line: Int) {
|
||||
func scroll_to_old(view: DisplayView, line: Int) {
|
||||
var scrollTo = view.visibleRect.origin
|
||||
let lineSpacing = CGFloat(1.5)
|
||||
let lineHeight = view.font!.pointSize * lineSpacing
|
||||
@ -226,12 +241,111 @@ N V - B D I Z C
|
||||
}
|
||||
|
||||
|
||||
func getLine(inView view: NSTextView, forY: CGFloat) -> Int {
|
||||
var scrollTo = view.visibleRect.origin
|
||||
let lineSpacing = CGFloat(1.5)
|
||||
let lineHeight = view.font!.pointSize * lineSpacing
|
||||
|
||||
let line = round(forY) / lineHeight
|
||||
|
||||
return Int(line) + 1
|
||||
}
|
||||
|
||||
|
||||
func getLineRange(inView view: NSTextView, forLine: Int) -> NSRange? {
|
||||
let layoutManager = view.layoutManager!
|
||||
var numberOfLines = 1
|
||||
let numberOfGlyphs = layoutManager.numberOfGlyphs
|
||||
var lineRange = NSRange()
|
||||
var indexOfGlyph = 0
|
||||
|
||||
while indexOfGlyph < numberOfGlyphs {
|
||||
layoutManager.lineFragmentRect(forGlyphAt: indexOfGlyph, effectiveRange: &lineRange, withoutAdditionalLayout: false)
|
||||
|
||||
// check if we've found our line number
|
||||
if numberOfLines == forLine {
|
||||
return lineRange
|
||||
}
|
||||
|
||||
indexOfGlyph = NSMaxRange(lineRange)
|
||||
numberOfLines += 1
|
||||
}
|
||||
|
||||
// could not find line number
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let lineFromTopToMiddle = 15
|
||||
func scroll_to(view: DisplayView, line: Int) {
|
||||
if let lineRange = getLineRange(inView: view, forLine: line + lineFromTopToMiddle) {
|
||||
view.scrollRangeToVisible(lineRange)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let lineAttrAtSelected = [
|
||||
NSAttributedString.Key.backgroundColor: NSColor.lightGray,
|
||||
NSAttributedString.Key.foregroundColor: NSColor.black,
|
||||
]
|
||||
|
||||
let lineAttrAtPC = [
|
||||
NSAttributedString.Key.backgroundColor: NSColor.blue,
|
||||
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)
|
||||
}
|
||||
view.layoutManager?.addTemporaryAttributes(attr, forCharacterRange: lineRange)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func isMouseInView(view: NSView) -> Bool {
|
||||
if let window = view.window {
|
||||
return view.isMousePoint(window.mouseLocationOutsideOfEventStream, in: view.frame)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
// 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)
|
||||
|
||||
let line = getLine(inView: Disass_Display, forY: location.y)
|
||||
highlight(view: Disass_Display, line: line_number_at_PC, attr: lineAttrAtPC)
|
||||
highlight(view: Disass_Display, line: line, attr: lineAttrAtSelected)
|
||||
line_number_cursor = line
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func DisplayDisassembly() {
|
||||
let m6502_saved = m6502
|
||||
var disass = ""
|
||||
|
||||
line_number = 0
|
||||
current_line_number = 0
|
||||
line_number_at_PC = 0
|
||||
|
||||
if m6502.PC > disass_addr && m6502.PC < disass_addr + disass_addr_max {
|
||||
m6502.PC = disass_addr
|
||||
@ -255,16 +369,17 @@ N V - B D I Z C
|
||||
|
||||
// normal disassembly
|
||||
for _ in 1...lines_to_disass {
|
||||
// check if this is the current line before disassembling it (that will change PC...)
|
||||
let isCurrentLine = m6502.PC == m6502_saved.PC
|
||||
|
||||
m6502_Disass_1_Instr()
|
||||
line_number += 1
|
||||
|
||||
var line = String(cString: disassemblyLine( isCurrentLine )!)
|
||||
let line = ASCII_to_Apple2( line: String(cString: disassemblyLine( isCurrentLine )!) )
|
||||
|
||||
if isCurrentLine {
|
||||
line = invertLine(line: line)
|
||||
current_line_number = line_number
|
||||
// line = invertLine(line: line)
|
||||
line_number_at_PC = line_number
|
||||
}
|
||||
|
||||
disass += line + "\n"
|
||||
@ -274,17 +389,18 @@ N V - B D I Z C
|
||||
// let isEmpty = self.Disass_Display.string.isEmpty
|
||||
self.Disass_Display.string = disass
|
||||
let currentScrollLine = self.get_scroll_line(view: self.Disass_Display) + 1
|
||||
if self.current_line_number <= currentScrollLine || self.current_line_number > currentScrollLine + 35 {
|
||||
self.scroll_to(view: self.Disass_Display, line: self.current_line_number - 5)
|
||||
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)
|
||||
|
||||
// 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) {
|
||||
self.scroll_to(view: self.Disass_Display, line: self.current_line_number - 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) {
|
||||
// your code here
|
||||
|
Loading…
x
Reference in New Issue
Block a user