diff --git a/include/vm_debug.h b/include/vm_debug.h index 51a54b0..7ad1a42 100644 --- a/include/vm_debug.h +++ b/include/vm_debug.h @@ -15,16 +15,16 @@ typedef struct { char *name; char *abbrev; - /* - * The number of arguments we expect to see - */ - int nargs; - /* * The function that will do something with the command's input */ vm_debug_func handler; + /* + * The number of arguments we expect to see + */ + int nargs; + /* * What do our arguments look like? */ @@ -68,6 +68,8 @@ extern vm_debug_cmd *vm_debug_find_cmd(const char *); extern void vm_debug_execute(const char *); extern DEBUG_CMD(help); +extern DEBUG_CMD(printaddr); +extern DEBUG_CMD(printstate); extern DEBUG_CMD(resume); #endif diff --git a/src/vm_debug.c b/src/vm_debug.c index eaa37d9..238e3ee 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -7,14 +7,19 @@ #include #include +#include "mos6502.h" #include "vm_debug.h" #include "vm_di.h" #include "vm_reflect.h" vm_debug_cmd cmdtable[] = { - { "help", "h", 0, vm_debug_cmd_help, "", + { "help", "h", vm_debug_cmd_help, 0, "", "Print out this list of commands", }, - { "resume", "r", 0, vm_debug_cmd_resume, "", + { "printaddr", "pa", vm_debug_cmd_printaddr, 1, "", + "Print the value at memory address ", }, + { "printstate", "ps", vm_debug_cmd_printstate, 0, "", + "Print the machine and CPU state", }, + { "resume", "r", vm_debug_cmd_resume, 0, "", "Resume execution", }, }; @@ -37,8 +42,7 @@ vm_debug_next_arg(char **str) break; } - return tok; -} + return tok; } int vm_debug_addr(const char *str) @@ -161,3 +165,19 @@ DEBUG_CMD(resume) { vm_reflect_pause(NULL); } + +DEBUG_CMD(printstate) +{ + vm_reflect_cpu_info(NULL); + vm_reflect_machine_info(NULL); +} + +DEBUG_CMD(printaddr) +{ + // FIXME: This is... too machine-specific; we need to abstract this logic + + mos6502 *cpu = (mos6502 *)vm_di_get(VM_CPU); + FILE *stream = (FILE *)vm_di_get(VM_OUTPUT); + + fprintf(stream, "$%02X\n", mos6502_get(cpu, args->addr1)); +} diff --git a/tests/vm_debug.c b/tests/vm_debug.c index 83a7367..d8cfb11 100644 --- a/tests/vm_debug.c +++ b/tests/vm_debug.c @@ -94,3 +94,17 @@ Test(vm_debug, cmd_resume) cr_assert_eq(mach->paused, false); } + +Test(vm_debug, cmd_printstate) +{ + vm_debug_cmd_printstate(&args); + cr_assert_neq(strlen(buf), 0); +} + +Test(vm_debug, cmd_printaddr) +{ + args.addr1 = 123; + mos6502_set(mach->cpu, args.addr1, 127); + vm_debug_cmd_printaddr(&args); + cr_assert_str_eq(buf, "$7F\n"); +}