From 3223fe61101a99896453f194f7a9aa30790549fb Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 7 Feb 2018 15:24:02 -0600 Subject: [PATCH] Enable disassembly toggle (ALT+D) --- include/apple2.h | 5 +++++ include/apple2.reflect.h | 1 + src/apple2.c | 26 +++++++++++++++++++------- src/apple2.reflect.c | 7 +++++++ src/vm_event.c | 4 ++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/apple2.h b/include/apple2.h index e5df378..1ebd61d 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -338,6 +338,11 @@ struct apple2 { * If paused is true, then execution of opcodes is suspended. */ bool paused; + + /* + * If this is true, then we will disassemble opcodes as we execute. + */ + bool disasm; }; extern apple2 *apple2_create(int, int); diff --git a/include/apple2.reflect.h b/include/apple2.reflect.h index dad4e4f..a0d535b 100644 --- a/include/apple2.reflect.h +++ b/include/apple2.reflect.h @@ -6,6 +6,7 @@ extern void apple2_reflect_init(); extern REFLECT(apple2_reflect_cpu_info); +extern REFLECT(apple2_reflect_disasm); extern REFLECT(apple2_reflect_machine_info); extern REFLECT(apple2_reflect_pause); diff --git a/src/apple2.c b/src/apple2.c index 2414eaf..0cdcb82 100644 --- a/src/apple2.c +++ b/src/apple2.c @@ -14,6 +14,7 @@ #include "mos6502.dis.h" #include "objstore.h" #include "option.h" +#include "vm_di.h" #include "vm_segment.h" /* @@ -51,6 +52,9 @@ apple2_create(int width, int height) // Yes, please do execute opcodes to begin with mach->paused = false; + // Don't print opcodes by default + mach->disasm = false; + // Forward set these to NULL in case we fail to build the machine // properly; that way, we won't try to free garbage data mach->rom = NULL; @@ -334,10 +338,14 @@ apple2_free(apple2 *mach) void apple2_run_loop(apple2 *mach) { + FILE *out; + if (option_flag(OPTION_DISASSEMBLE)) { return; } + out = (FILE *)vm_di_get(VM_OUTPUT); + while (vm_screen_active(mach->screen)) { // If we're paused, then just re-loop until we're not if (mach->paused) { @@ -345,13 +353,17 @@ apple2_run_loop(apple2 *mach) continue; } -#if 0 - mach->drive1->locked = true; - mach->drive2->locked = true; - mos6502_dis_opcode(mach->cpu, stdout, mach->cpu->PC); - mach->drive1->locked = false; - mach->drive2->locked = false; -#endif + if (mach->disasm) { + if (mach->selected_drive) { + mach->selected_drive->locked = true; + } + + mos6502_dis_opcode(mach->cpu, out, mach->cpu->PC); + + if (mach->selected_drive) { + mach->selected_drive->locked = false; + } + } mos6502_execute(mach->cpu); diff --git a/src/apple2.reflect.c b/src/apple2.reflect.c index 0726716..e800f52 100644 --- a/src/apple2.reflect.c +++ b/src/apple2.reflect.c @@ -15,6 +15,7 @@ apple2_reflect_init() ref->cpu_info = apple2_reflect_cpu_info; ref->machine_info = apple2_reflect_machine_info; ref->pause = apple2_reflect_pause; + ref->disasm = apple2_reflect_disasm; } REFLECT(apple2_reflect_cpu_info) @@ -49,3 +50,9 @@ REFLECT(apple2_reflect_pause) apple2 *mach = (apple2 *)vm_di_get(VM_MACHINE); mach->paused = !mach->paused; } + +REFLECT(apple2_reflect_disasm) +{ + apple2 *mach = (apple2 *)vm_di_get(VM_MACHINE); + mach->disasm = !mach->disasm; +} diff --git a/src/vm_event.c b/src/vm_event.c index 92f28aa..f65c8aa 100644 --- a/src/vm_event.c +++ b/src/vm_event.c @@ -110,6 +110,10 @@ vm_event_keyboard_special(vm_event *ev, char ch) case 'p': vm_reflect_pause(NULL); break; + + case 'd': + vm_reflect_disasm(NULL); + break; } } }