Turn debugging on and off based on debugger window active status

This commit is contained in:
tudnai 2022-11-13 11:49:34 -08:00
parent 82deef06aa
commit 4ae8bfe658
6 changed files with 45 additions and 31 deletions

View File

@ -31,6 +31,7 @@ class DebuggerWindowController: NSWindowController, NSWindowDelegate {
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
super.init(coder: coder) super.init(coder: coder)
DebuggerWindowController.shared = self DebuggerWindowController.shared = self
m6502_dbg_init()
} }
@ -39,8 +40,6 @@ class DebuggerWindowController: NSWindowController, NSWindowDelegate {
if isWindowFullscreen { if isWindowFullscreen {
window?.toggleFullScreen(self) window?.toggleFullScreen(self)
} }
m6502_dbg_init()
} }
@ -57,6 +56,7 @@ class DebuggerWindowController: NSWindowController, NSWindowDelegate {
} }
func windowWillClose(_ notification: Notification) { func windowWillClose(_ notification: Notification) {
m6502_dbg_off()
DebuggerWindowController.shared = nil DebuggerWindowController.shared = nil
} }

View File

@ -40,6 +40,7 @@
#include <time.h> #include <time.h>
#include "6502.h" #include "6502.h"
#include "6502_bp.h" #include "6502_bp.h"
#include "6502_debugger.h"
#include "speaker.h" #include "speaker.h"
@ -112,16 +113,11 @@ m6502_t m6502 = {
0, // lastIO 0, // lastIO
0, // ecoSpindown 0, // ecoSpindown
0, // trace 0, // debugger.on
0, // step 0xFF, // debugger.SP
0, // brk 0, // debugger.wMask
0, // rts
0, // bra
0, // bra_true
0, // bra_false
0, // compile
HALT, // IF HALT, // IF
}; };
@ -423,10 +419,7 @@ void m6502_Debug(void) {
m6502.lastIO = 0; m6502.lastIO = 0;
m6502.interrupt = NO_INT; // TODO: This should be taken care by the interrupt handler m6502.interrupt = NO_INT; // TODO: This should be taken care by the interrupt handler
m6502.debugger.on = 1; m6502_dbg_on();
m6502.debugger.mask.hlt = 1;
m6502.debugger.mask.brk = 1;
m6502.debugger.mask.inv = 1;
if( diskAccelerator_count ) { if( diskAccelerator_count ) {
if( --diskAccelerator_count <= 0 ) { if( --diskAccelerator_count <= 0 ) {
@ -443,7 +436,7 @@ void m6502_Debug(void) {
case HALT: case HALT:
if (m6502.debugger.mask.hlt) { if (m6502.debugger.mask.hlt) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
break; break;
@ -451,7 +444,7 @@ void m6502_Debug(void) {
case BREAK: case BREAK:
if (m6502.debugger.mask.brk) { if (m6502.debugger.mask.brk) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
break; break;
@ -459,7 +452,7 @@ void m6502_Debug(void) {
case IRQ: case IRQ:
if (m6502.debugger.mask.irq) { if (m6502.debugger.mask.irq) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
break; break;
@ -467,7 +460,7 @@ void m6502_Debug(void) {
case NMI: case NMI:
if (m6502.debugger.mask.nmi) { if (m6502.debugger.mask.nmi) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
break; break;
@ -475,7 +468,7 @@ void m6502_Debug(void) {
case INV: case INV:
if (m6502.debugger.mask.inv) { if (m6502.debugger.mask.inv) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
break; break;
@ -485,7 +478,7 @@ void m6502_Debug(void) {
if (m6502.debugger.mask.out) { if (m6502.debugger.mask.out) {
if ( m6502.SP >= m6502.debugger.SP ) { if ( m6502.SP >= m6502.debugger.SP ) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
return; return;
} }
} }
@ -512,8 +505,8 @@ void m6502_Debug(void) {
if ( m6502_dbg_bp_is_exists(m6502.PC) ) { if ( m6502_dbg_bp_is_exists(m6502.PC) ) {
cpuState = cpuState_halted; cpuState = cpuState_halted;
m6502.debugger.wMask = 0; // m6502.debugger.wMask = 0;
m6502.debugger.on = 0; // m6502.debugger.on = 0;
m6502.interrupt = BREAKPOINT; m6502.interrupt = BREAKPOINT;
return; return;
} }

View File

@ -30,6 +30,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "6502.h"
#include "6502_bp.h" #include "6502_bp.h"
/// Array of addresses of active breakpoints /// Array of addresses of active breakpoints
@ -239,9 +240,3 @@ void m6502_dbg_bp_del_all(void) {
} }
/// Initialize Breakpoints
void m6502_dbg_init(void) {
m6502_dbg_bp_del_all();
}

View File

@ -15,7 +15,6 @@
extern uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS]; extern uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS];
extern int bp_last_idx; extern int bp_last_idx;
extern void m6502_dbg_init(void);
extern int m6502_dbg_bp_add(uint16_t addr); extern int m6502_dbg_bp_add(uint16_t addr);
extern void m6502_dbg_bp_del(uint16_t addr); extern void m6502_dbg_bp_del(uint16_t addr);
extern void m6502_dbg_bp_del_all(void); extern void m6502_dbg_bp_del_all(void);

View File

@ -76,6 +76,7 @@ typedef struct {
#include "6502_debugger.h" #include "6502_debugger.h"
#include "6502_instructions.h" #include "6502_instructions.h"
#include "6502_bp.h"
INLINE int m6502_Disass_1_Instr(void) { INLINE int m6502_Disass_1_Instr(void) {
@ -94,4 +95,27 @@ INLINE int m6502_Disass_1_Instr(void) {
return 2; return 2;
} }
/// Turn On Debugger
void m6502_dbg_on(void) {
m6502.debugger.on = 1;
}
/// Turn Off Debugger
void m6502_dbg_off(void) {
m6502.debugger.on = 0;
}
/// Initialize Breakpoints
void m6502_dbg_init(void) {
m6502_dbg_on();
m6502.debugger.wMask = 0;
m6502.debugger.mask.hlt = 1;
m6502.debugger.mask.brk = 1;
m6502.debugger.mask.inv = 1;
m6502.debugger.SP = 0xFF;
m6502_dbg_bp_del_all();
}

View File

@ -12,6 +12,9 @@
extern uint16_t disass_addr; extern uint16_t disass_addr;
extern int m6502_Disass_1_Instr(void); extern int m6502_Disass_1_Instr(void);
extern void m6502_dbg_on(void);
extern void m6502_dbg_off(void);
extern void m6502_dbg_init(void);
#endif /* _6502_debugger_h */ #endif /* _6502_debugger_h */