1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-27 20:51:17 +00:00

Add printaddr, printstate

This commit is contained in:
Peter Evans 2018-02-24 18:57:00 -06:00
parent ec253905ad
commit 1be1abc0af
3 changed files with 45 additions and 9 deletions

View File

@ -15,16 +15,16 @@ typedef struct {
char *name; char *name;
char *abbrev; char *abbrev;
/*
* The number of arguments we expect to see
*/
int nargs;
/* /*
* The function that will do something with the command's input * The function that will do something with the command's input
*/ */
vm_debug_func handler; vm_debug_func handler;
/*
* The number of arguments we expect to see
*/
int nargs;
/* /*
* What do our arguments look like? * 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 void vm_debug_execute(const char *);
extern DEBUG_CMD(help); extern DEBUG_CMD(help);
extern DEBUG_CMD(printaddr);
extern DEBUG_CMD(printstate);
extern DEBUG_CMD(resume); extern DEBUG_CMD(resume);
#endif #endif

View File

@ -7,14 +7,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
#include "mos6502.h"
#include "vm_debug.h" #include "vm_debug.h"
#include "vm_di.h" #include "vm_di.h"
#include "vm_reflect.h" #include "vm_reflect.h"
vm_debug_cmd cmdtable[] = { vm_debug_cmd cmdtable[] = {
{ "help", "h", 0, vm_debug_cmd_help, "", { "help", "h", vm_debug_cmd_help, 0, "",
"Print out this list of commands", }, "Print out this list of commands", },
{ "resume", "r", 0, vm_debug_cmd_resume, "", { "printaddr", "pa", vm_debug_cmd_printaddr, 1, "<addr>",
"Print the value at memory address <addr>", },
{ "printstate", "ps", vm_debug_cmd_printstate, 0, "",
"Print the machine and CPU state", },
{ "resume", "r", vm_debug_cmd_resume, 0, "",
"Resume execution", }, "Resume execution", },
}; };
@ -37,8 +42,7 @@ vm_debug_next_arg(char **str)
break; break;
} }
return tok; return tok; }
}
int int
vm_debug_addr(const char *str) vm_debug_addr(const char *str)
@ -161,3 +165,19 @@ DEBUG_CMD(resume)
{ {
vm_reflect_pause(NULL); 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));
}

View File

@ -94,3 +94,17 @@ Test(vm_debug, cmd_resume)
cr_assert_eq(mach->paused, false); 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");
}