Debug window activates when breakpoint hits

This commit is contained in:
tudnai 2022-11-12 20:46:43 -08:00
parent d31c9ab22d
commit 57e10e65e6
8 changed files with 129 additions and 17 deletions

View File

@ -297,6 +297,9 @@
<ContextState
contextName = "m6502_dbg_bp_compact:6502_bp.c">
</ContextState>
<ContextState
contextName = "m6502_dbg_bp_get_last:6502_bp.c">
</ContextState>
<ContextState
contextName = "ViewController.Reset(_:):ViewController.swift">
<PersistentStrings>
@ -469,6 +472,20 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "DebuggerViewController.ASCII_to_Apple2(line:):DebuggerViewController.swift">
<PersistentStrings>
<PersistentString
value = "chr">
</PersistentString>
<PersistentString
value = "chr.utf8">
</PersistentString>
<PersistentString
value = "chr.asciiValue">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "LSRA:6502_instr_shift_rotate.h">
<PersistentStrings>

View File

@ -239,29 +239,95 @@
<stackView focusRingType="none" distribution="fill" orientation="vertical" alignment="leading" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="jY7-ZU-I4z" userLabel="Disassebler">
<rect key="frame" x="8" y="10" width="366" height="504"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="M3T-0I-hdp">
<rect key="frame" x="-2" y="488" width="81" height="16"/>
<stackView distribution="fill" orientation="horizontal" alignment="top" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lUp-Ww-thA">
<rect key="frame" x="0.0" y="484" width="233" height="20"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bwO-w1-hlg" userLabel="Memory Addr Field">
<rect key="frame" x="0.0" y="0.0" width="44" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" identifier="Memory Addr Field.Height" id="XCd-Q5-6sX"/>
<constraint firstAttribute="width" constant="44" id="t28-y8-Zr5"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Addr" drawsBackground="YES" usesSingleLineMode="YES" id="SCz-Q0-cv7" userLabel="Memory Addr Field Cell">
<font key="font" size="10" name="PrintChar21"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lht-UO-OM3" userLabel="Middle Space">
<rect key="frame" x="50" y="0.0" width="8" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" identifier="Memory Addr Field.Height" id="57Q-CT-Gpn"/>
<constraint firstAttribute="width" constant="4" id="lWh-zL-9R3"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" usesSingleLineMode="YES" id="Nrn-V7-Ftb" userLabel="Memory Addr Field Cell">
<font key="font" size="11" name="PrintChar21"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="zov-nz-fce">
<rect key="frame" x="62" y="2" width="40" height="18"/>
<buttonCell key="cell" type="check" title="PC" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Cu2-rY-Lii">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="jya-Sa-f8i" userLabel="Middle Space">
<rect key="frame" x="106" y="0.0" width="44" height="20"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="W3U-D5-7k9"/>
<constraint firstAttribute="height" constant="20" identifier="Memory Addr Field.Height" id="eb8-Te-a1X"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" usesSingleLineMode="YES" id="NLP-Iu-qf6" userLabel="Memory Addr Field Cell">
<font key="font" size="11" name="PrintChar21"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="hxo-9P-cZv">
<rect key="frame" x="154" y="4" width="81" height="16"/>
<constraints>
<constraint firstAttribute="height" constant="16" identifier="Disassembly.Height" id="jZh-9c-yY6"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="clipping" title="Disassembly" id="scD-F6-xz3">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="16" identifier="Disassembly.Height" id="Nho-aF-T9F"/>
<constraint firstAttribute="height" constant="20" id="IBp-m1-h7y"/>
<constraint firstItem="zov-nz-fce" firstAttribute="top" secondItem="lUp-Ww-thA" secondAttribute="top" constant="2" id="lFF-HX-eQV"/>
</constraints>
<textFieldCell key="cell" lineBreakMode="clipping" title="Disassembly" id="g1c-cQ-eDu">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<scrollView horizontalCompressionResistancePriority="250" verticalCompressionResistancePriority="250" borderType="line" horizontalLineScroll="0.0" horizontalPageScroll="0.0" verticalLineScroll="0.0" verticalPageScroll="0.0" hasHorizontalScroller="NO" minMagnification="1" translatesAutoresizingMaskIntoConstraints="NO" id="Pcn-4j-EEM" userLabel="Disass Scroll View" customClass="DisplayScrollView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="366" height="480"/>
<rect key="frame" x="0.0" y="0.0" width="366" height="476"/>
<clipView key="contentView" copiesOnScroll="NO" id="9iz-cs-4As" userLabel="Disass Clip View">
<rect key="frame" x="1" y="1" width="349" height="478"/>
<rect key="frame" x="1" y="1" width="349" height="474"/>
<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="DisassView" customModule="A2MacTests" customModuleProvider="target">
<rect key="frame" x="0.0" y="-196" width="349" height="1155"/>
<rect key="frame" x="0.0" y="-195" width="349" height="1156"/>
<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"/>
<size key="minSize" width="349" height="478"/>
<size key="minSize" width="349" height="474"/>
<size key="maxSize" width="3840" height="58101"/>
<attributedString key="textStorage">
<fragment>
@ -356,8 +422,8 @@ C20D: 4C C5 FE JMP $FEC5FEC5: 8D 06 C0 STA $C006</mutableString>
<rect key="frame" x="-100" y="-100" width="225" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="8wE-fn-MQK">
<rect key="frame" x="350" y="1" width="15" height="478"/>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="0.01466275659824047" horizontal="NO" id="8wE-fn-MQK">
<rect key="frame" x="350" y="1" width="15" height="474"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>

View File

@ -190,8 +190,23 @@ N V - B D I Z C
var converted = ""
for chr in line {
// make C character NORMAL Apple ][ character
let c = Int(chr.asciiValue!) & 0x3F | 0x80
converted.append(ViewController.charConvTbl[c])
// breakpoint marker
if c == 0xAA { // '*'
// converted.append("\u{E895}") // big dot (8x8)
// converted.append("\u{ED3C}") // big dot2 (8x8)
// converted.append("\u{E09B}") // right arrow
// converted.append("\u{E095}") // diamond
converted.append("\u{E080}") // closed apple
// converted.append("\u{E081}") // open apple
// converted.append("\u{E185}") // checkmark
}
// normal character
else {
converted.append(ViewController.charConvTbl[c])
}
}
return converted

View File

@ -1272,6 +1272,11 @@ class ViewController: NSViewController {
if let debugger = DebuggerViewController.shared {
debugger.Update()
}
if let debugger = DebuggerWindowController.current {
DispatchQueue.main.async {
debugger.showWindow(self)
}
}
}
@ -1319,6 +1324,9 @@ class ViewController: NSViewController {
case BREAK:
debugBreak()
case BREAKPOINT:
debugBreak()
case RET:
if m6502.debugger.mask.ret == 1 {
// Step_Out / Step_Over

View File

@ -514,6 +514,7 @@ void m6502_Debug(void) {
cpuState = cpuState_halted;
m6502.debugger.wMask = 0;
m6502.debugger.on = 0;
m6502.interrupt = BREAKPOINT;
return;
}

View File

@ -77,6 +77,9 @@ typedef enum : uint8_t {
RET, // RTS/RTI Used by Debugger Step_Over / Step_Out
HARDRESET,
SOFTRESET,
BREAKPOINT,
BREAKIO,
BREAKMEM,
} interrupt_t;

View File

@ -45,7 +45,7 @@ int bp_idx = 0;
/// Swap 2 items
/// @param a Pointer of first item
/// @param b Pointer to second item
static void swap(uint16_t * a, uint16_t * b) {
static inline void swap(uint16_t * a, uint16_t * b) {
uint16_t temp = *a;
*a = *b;
*b = temp;
@ -184,6 +184,7 @@ int m6502_dbg_bp_get_not_empty() {
/// Move array down to eliminate leading zeros
/// @note: Array must be sorted before this!
void m6502_dbg_bp_compact() {
int i = m6502_dbg_bp_get_not_empty();
memcpy(breakpoints, breakpoints + i, bp_last_idx * sizeof(uint16_t));

View File

@ -13,6 +13,7 @@
#define DEBUG_MAX_BREAKPOINTS 256
extern uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS];
extern int bp_last_idx;
extern void m6502_dbg_init(void);
extern int m6502_dbg_bp_add(uint16_t addr);