From 6e77e998132ac4ab05eb37d59852df54f70757c7 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 7 Apr 2018 11:14:12 -0500 Subject: [PATCH] Add ability to debug separate from pausing Also, pausing just pauses now; no debugger prompt is shown. ALT+P toggles pausing, so just hit it again to unpause. Also, when things are paused, you can perform other keyboard events (like quitting). --- include/apple2/apple2.h | 7 +++++++ include/apple2/event.h | 3 ++- src/apple2/apple2.c | 14 ++++++-------- src/apple2/debug.c | 1 + src/apple2/event.c | 4 +++- src/vm_event.c | 4 ++++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/apple2/apple2.h b/include/apple2/apple2.h index a5c6e79..cd37150 100644 --- a/include/apple2/apple2.h +++ b/include/apple2/apple2.h @@ -339,6 +339,13 @@ struct apple2 { */ bool paused; + /* + * When this and the paused fields are true, then we will print a + * debug prompt and allow the user to work with the machine through + * that. + */ + bool debug; + /* * If this is true, then we will disassemble opcodes as we execute. */ diff --git a/include/apple2/event.h b/include/apple2/event.h index d9e9cf9..86967c4 100644 --- a/include/apple2/event.h +++ b/include/apple2/event.h @@ -3,7 +3,8 @@ #include "vm_event.h" -extern void apple2_event_init(); +extern EVENT_DO(apple2_event_debug); extern EVENT_DO(apple2_event_pause); +extern void apple2_event_init(); #endif diff --git a/src/apple2/apple2.c b/src/apple2/apple2.c index 087eefc..ce68c0c 100644 --- a/src/apple2/apple2.c +++ b/src/apple2/apple2.c @@ -48,14 +48,9 @@ apple2_create(int width, int height) return NULL; } - // By default, we have no strobe set; it should only be set when a - // key is pressed mach->strobe = false; - - // Yes, please do execute opcodes to begin with mach->paused = false; - - // Don't print opcodes by default + mach->debug = false; mach->disasm = false; // Forward set these to NULL in case we fail to build the machine @@ -357,8 +352,7 @@ apple2_run_loop(apple2 *mach) mach->paused = true; } - // If we're paused, then just re-loop until we're not - if (mach->paused) { + if (mach->debug) { if (mach->selected_drive) { mach->selected_drive->locked = true; } @@ -376,6 +370,10 @@ apple2_run_loop(apple2 *mach) } free(input); + } + + if (mach->paused) { + vm_event_poll(mach->screen); continue; } diff --git a/src/apple2/debug.c b/src/apple2/debug.c index d068905..14d2644 100644 --- a/src/apple2/debug.c +++ b/src/apple2/debug.c @@ -328,6 +328,7 @@ DEBUG_CMD(resume) apple2_debug_unbreak(mach->cpu->PC); mach->paused = false; + mach->debug = false; } /* diff --git a/src/apple2/event.c b/src/apple2/event.c index 59e69a0..6db82c1 100644 --- a/src/apple2/event.c +++ b/src/apple2/event.c @@ -17,16 +17,18 @@ void apple2_event_init() { vm_di_set(VM_PAUSE_FUNC, apple2_event_pause); + vm_di_set(VM_DEBUG_FUNC, apple2_event_debug); } EVENT_DO(apple2_event_pause) { apple2 *mach = (apple2 *)_mach; - mach->paused = true; + mach->paused = !mach->paused; } EVENT_DO(apple2_event_debug) { apple2 *mach = (apple2 *)_mach; + mach->debug = true; mach->paused = true; } diff --git a/src/vm_event.c b/src/vm_event.c index a30ccb8..954f706 100644 --- a/src/vm_event.c +++ b/src/vm_event.c @@ -108,6 +108,10 @@ vm_event_keyboard_special(vm_event *ev, char ch) ev->screen->should_exit = true; break; + case 'd': + vm_event_do(VM_DEBUG_FUNC); + break; + case 'p': vm_event_do(VM_PAUSE_FUNC); break;