Skip to content

Commit fd566bc

Browse files
autismuksmokku
authored andcommitted
Changes for opcode breakpoint
1 parent 210a454 commit fd566bc

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ Linux
6464
Windows
6565

6666
> build/emu.exe file=roms/SOTB.xex
67+
68+
### Opcode Breakpoints
69+
70+
The emulator supports opcode based breakpoints, if an specified opcode is executed, the emulator will stop. Possible breakpoint values are EA (NOP) 42 (WDM #xx) and B8 (CLV).
71+
72+
> build/emu.exe file=roms/SOTB.xex break=EA

src/ui/ui_dbg.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ typedef struct ui_dbg_state_t {
235235
int delete_breakpoint_index;
236236
int num_breakpoints;
237237
ui_dbg_breakpoint_t breakpoints[UI_DBG_MAX_BREAKPOINTS];
238+
bool opcodeDebugEnabled; // True when opcode debug is enabled.
239+
uint8_t opcodeDebugByte; // Opcode debug value.
238240
} ui_dbg_state_t;
239241

240242
/* a displayed line */
@@ -398,6 +400,8 @@ void ui_dbg_step_next(ui_dbg_t* win);
398400
void ui_dbg_step_into(ui_dbg_t* win);
399401
// request a disassembly at start address
400402
void ui_dbg_disassemble(ui_dbg_t* win, const ui_dbg_dasm_request_t* request);
403+
// enable opcode debugging
404+
void ui_dbg_control_opcode_break(ui_dbg_t* win,bool enable,uint8_t byteValue);
401405

402406
#ifdef __cplusplus
403407
} // extern "C"
@@ -720,6 +724,11 @@ static void _ui_dbg_dbgstate_reset(ui_dbg_t* win) {
720724
dbg->last_trap_id = 0;
721725
}
722726

727+
void ui_dbg_control_opcode_break(ui_dbg_t *dbg,bool enable,uint8_t byteValue) {
728+
dbg->dbg.opcodeDebugEnabled = enable;
729+
dbg->dbg.opcodeDebugByte = byteValue;
730+
}
731+
723732
static void _ui_dbg_dbgstate_reboot(ui_dbg_t* win) {
724733
_ui_dbg_dbgstate_reset(win);
725734
}
@@ -2151,6 +2160,13 @@ void ui_dbg_tick(ui_dbg_t* win, uint64_t pins) {
21512160
_ui_dbg_history_push(win, pc);
21522161
win->dbg.cur_op_ticks = 0;
21532162
win->dbg.cur_op_pc = pc;
2163+
2164+
if (win->dbg.opcodeDebugEnabled) {
2165+
if (_ui_dbg_read_byte(win, win->dbg.cur_op_pc) == win->dbg.opcodeDebugByte) {
2166+
win->dbg.stopped = true;
2167+
}
2168+
}
2169+
21542170
}
21552171
if (win->dbg.step_mode == UI_DBG_STEPMODE_NONE) {
21562172
trap_id = _ui_dbg_eval_tick_breakpoints(win, trap_id, pins);

src/x65.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ void app_init(void) {
279279
keybuf_put(sargs_value("input"));
280280
}
281281
}
282+
if (sargs_exists("break")) {
283+
int opcode;
284+
if (sscanf(sargs_value("break"),"%x",&opcode) == 1) {
285+
ui_dbg_control_opcode_break(&state.ui.dbg,true,opcode);
286+
} else {
287+
fprintf(stderr,"Bad breakpoint opcode %s\n",sargs_value("break"));
288+
}
289+
}
282290
}
283291

284292
static void handle_file_loading(void);

0 commit comments

Comments
 (0)