diff --git a/include/vm_debug.h b/include/apple2/debug.h similarity index 67% rename from include/vm_debug.h rename to include/apple2/debug.h index fba4d2f..43a51e8 100644 --- a/include/vm_debug.h +++ b/include/apple2/debug.h @@ -1,12 +1,12 @@ -#ifndef _VM_DEBUG_H_ -#define _VM_DEBUG_H_ +#ifndef _APPLE2_DEBUG_H_ +#define _APPLE2_DEBUG_H_ #include -struct vm_debug_args; -typedef struct vm_debug_args vm_debug_args; +struct apple2_debug_args; +typedef struct apple2_debug_args apple2_debug_args; -typedef void (*vm_debug_func)(vm_debug_args *); +typedef void (*apple2_debug_func)(apple2_debug_args *); typedef struct { /* @@ -20,7 +20,7 @@ typedef struct { /* * The function that will do something with the command's input */ - vm_debug_func handler; + apple2_debug_func handler; /* * The number of arguments we expect to see @@ -36,9 +36,9 @@ typedef struct { * What do we do? */ char *desc; -} vm_debug_cmd; +} apple2_debug_cmd; -struct vm_debug_args { +struct apple2_debug_args { /* * Most commands that need an argument will simply use addr1, but a * few have more than one address--hence addr2. @@ -60,22 +60,22 @@ struct vm_debug_args { * The command our arguments are attached to; from here we can call * the handler with ourselves. (Very meta.) */ - vm_debug_cmd *cmd; + apple2_debug_cmd *cmd; }; #define DEBUG_CMD(x) \ - void vm_debug_cmd_##x (vm_debug_args *args) + void apple2_debug_cmd_##x (apple2_debug_args *args) -extern int vm_debug_addr(const char *); -extern bool vm_debug_broke(int); -extern char *vm_debug_next_arg(char **); -extern char *vm_debug_prompt(); -extern vm_debug_cmd *vm_debug_find_cmd(const char *); -extern void vm_debug_break(int); -extern void vm_debug_execute(const char *); -extern void vm_debug_quit(); -extern void vm_debug_unbreak(int); -extern void vm_debug_unbreak_all(); +extern int apple2_debug_addr(const char *); +extern bool apple2_debug_broke(int); +extern char *apple2_debug_next_arg(char **); +extern char *apple2_debug_prompt(); +extern apple2_debug_cmd *apple2_debug_find_cmd(const char *); +extern void apple2_debug_break(int); +extern void apple2_debug_execute(const char *); +extern void apple2_debug_quit(); +extern void apple2_debug_unbreak(int); +extern void apple2_debug_unbreak_all(); extern DEBUG_CMD(break); extern DEBUG_CMD(dblock); diff --git a/sources.cmake b/sources.cmake index 072baef..176e24c 100644 --- a/sources.cmake +++ b/sources.cmake @@ -3,6 +3,7 @@ set(erc_sources apple2/bank.c apple2/dbuf.c apple2/dd.c + apple2/debug.c apple2/dec.c apple2/draw.c apple2/enc.c @@ -27,7 +28,6 @@ set(erc_sources option.c vm_area.c vm_bitfont.c - vm_debug.c vm_di.c vm_event.c vm_screen.c diff --git a/src/apple2/apple2.c b/src/apple2/apple2.c index 834eda8..087eefc 100644 --- a/src/apple2/apple2.c +++ b/src/apple2/apple2.c @@ -9,13 +9,13 @@ #include #include "apple2/apple2.h" +#include "apple2/debug.h" #include "apple2/draw.h" #include "apple2/mem.h" -#include "mos6502/enums.h" #include "mos6502/dis.h" +#include "mos6502/enums.h" #include "objstore.h" #include "option.h" -#include "vm_debug.h" #include "vm_di.h" #include "vm_event.h" #include "vm_segment.h" @@ -353,7 +353,7 @@ apple2_run_loop(apple2 *mach) i = 0; } - if (vm_debug_broke(mach->cpu->PC)) { + if (apple2_debug_broke(mach->cpu->PC)) { mach->paused = true; } @@ -369,10 +369,10 @@ apple2_run_loop(apple2 *mach) mach->selected_drive->locked = false; } - char *input = vm_debug_prompt(); + char *input = apple2_debug_prompt(); if (input != NULL) { - vm_debug_execute(input); + apple2_debug_execute(input); } free(input); @@ -391,7 +391,7 @@ apple2_run_loop(apple2 *mach) } } - if (!vm_debug_broke(mach->cpu->PC)) { + if (!apple2_debug_broke(mach->cpu->PC)) { mos6502_execute(mach->cpu); } diff --git a/src/vm_debug.c b/src/apple2/debug.c similarity index 80% rename from src/vm_debug.c rename to src/apple2/debug.c index a69b80e..d068905 100644 --- a/src/vm_debug.c +++ b/src/apple2/debug.c @@ -1,5 +1,5 @@ /* - * vm_debug.c + * apple2_debug.c */ #include @@ -10,10 +10,10 @@ #include #include "apple2/apple2.h" +#include "apple2/debug.h" #include "apple2/hires.h" -#include "mos6502/mos6502.h" #include "mos6502/dis.h" -#include "vm_debug.h" +#include "mos6502/mos6502.h" #include "vm_di.h" #include "vm_event.h" @@ -33,47 +33,47 @@ static bool breakpoints[BREAKPOINTS_MAX]; * A table of commands that we support in the debugger. This list is * printed out (in somewhat readable form) by the help/h command. */ -vm_debug_cmd cmdtable[] = { - { "break", "b", vm_debug_cmd_break, 1, "", +apple2_debug_cmd cmdtable[] = { + { "break", "b", apple2_debug_cmd_break, 1, "", "Add breakpoint at ", }, - { "dblock", "db", vm_debug_cmd_dblock, 2, " ", + { "dblock", "db", apple2_debug_cmd_dblock, 2, " ", "Disassemble a block of code", }, - { "disasm", "d", vm_debug_cmd_disasm, 0, "", + { "disasm", "d", apple2_debug_cmd_disasm, 0, "", "Toggle disassembly", }, - { "help", "h", vm_debug_cmd_help, 0, "", + { "help", "h", apple2_debug_cmd_help, 0, "", "Print out this list of commands", }, - { "hdump", "hd", vm_debug_cmd_hdump, 2, " ", + { "hdump", "hd", apple2_debug_cmd_hdump, 2, " ", "Hex dump memory in a given region", }, - { "hidump", "hid", vm_debug_cmd_hidump, 1, "", + { "hidump", "hid", apple2_debug_cmd_hidump, 1, "", "Dump hires graphics memory to file", }, - { "jump", "j", vm_debug_cmd_jump, 1, "", + { "jump", "j", apple2_debug_cmd_jump, 1, "", "Jump to for next execution", }, - { "printaddr", "pa", vm_debug_cmd_printaddr, 1, "", + { "printaddr", "pa", apple2_debug_cmd_printaddr, 1, "", "Print the value at memory address ", }, - { "printstate", "ps", vm_debug_cmd_printstate, 0, "", + { "printstate", "ps", apple2_debug_cmd_printstate, 0, "", "Print the machine and CPU state", }, - { "quit", "q", vm_debug_cmd_quit, 0, "", + { "quit", "q", apple2_debug_cmd_quit, 0, "", "Quit the emulator", }, - { "resume", "r", vm_debug_cmd_resume, 0, "", + { "resume", "r", apple2_debug_cmd_resume, 0, "", "Resume execution", }, - { "step", "s", vm_debug_cmd_step, 0, "", + { "step", "s", apple2_debug_cmd_step, 0, "", "Execute the current opcode and break at the next", }, - { "unbreak", "u", vm_debug_cmd_unbreak, 1, "", + { "unbreak", "u", apple2_debug_cmd_unbreak, 1, "", "Remove breakpoint at ", }, - { "writeaddr", "wa", vm_debug_cmd_writeaddr, 2, " ", + { "writeaddr", "wa", apple2_debug_cmd_writeaddr, 2, " ", "Write at ", }, - { "writestate", "ws", vm_debug_cmd_writestate, 2, " ", + { "writestate", "ws", apple2_debug_cmd_writestate, 2, " ", "Write into ", }, }; -#define CMDTABLE_SIZE (sizeof(cmdtable) / sizeof(vm_debug_cmd)) +#define CMDTABLE_SIZE (sizeof(cmdtable) / sizeof(apple2_debug_cmd)) /* * Return the next argument in a string passed in for input with the * debugger. All arguments are space-separated. */ char * -vm_debug_next_arg(char **str) +apple2_debug_next_arg(char **str) { char *tok; @@ -94,7 +94,7 @@ vm_debug_next_arg(char **str) * with. */ int -vm_debug_addr(const char *str) +apple2_debug_addr(const char *str) { int addr; @@ -120,7 +120,7 @@ vm_debug_addr(const char *str) * Add a breakpoint for addr */ void -vm_debug_break(int addr) +apple2_debug_break(int addr) { if (addr < 0 || addr >= BREAKPOINTS_MAX) { return; @@ -133,7 +133,7 @@ vm_debug_break(int addr) * Remove a breakpoint for addr, if one is set */ void -vm_debug_unbreak(int addr) +apple2_debug_unbreak(int addr) { if (addr < 0 || addr >= BREAKPOINTS_MAX) { return; @@ -146,7 +146,7 @@ vm_debug_unbreak(int addr) * Return true if there is a breakpoint set for addr */ bool -vm_debug_broke(int addr) +apple2_debug_broke(int addr) { if (addr < 0 || addr >= BREAKPOINTS_MAX) { return false; @@ -162,7 +162,7 @@ vm_debug_broke(int addr) * array when tearing down for a given test. */ void -vm_debug_unbreak_all() +apple2_debug_unbreak_all() { memset(breakpoints, false, BREAKPOINTS_MAX); } @@ -174,7 +174,7 @@ vm_debug_unbreak_all() * Unless you're ok with memory leaks!) */ char * -vm_debug_prompt() +apple2_debug_prompt() { char buf[256]; FILE *stream = (FILE *)vm_di_get(VM_OUTPUT); @@ -200,16 +200,16 @@ vm_debug_prompt() * it (assuming they are space-separated). */ void -vm_debug_execute(const char *str) +apple2_debug_execute(const char *str) { char *tok, *ebuf, *orig; - vm_debug_cmd *cmd; - vm_debug_args args; + apple2_debug_cmd *cmd; + apple2_debug_args args; orig = ebuf = strdup(str); cmd = NULL; - tok = vm_debug_next_arg(&ebuf); + tok = apple2_debug_next_arg(&ebuf); // No input if (tok == NULL) { @@ -217,7 +217,7 @@ vm_debug_execute(const char *str) return; } - cmd = vm_debug_find_cmd(tok); + cmd = apple2_debug_find_cmd(tok); // No command found if (cmd == NULL) { @@ -231,13 +231,13 @@ vm_debug_execute(const char *str) switch (cmd->nargs) { case 2: - args.target = vm_debug_next_arg(&ebuf); + args.target = apple2_debug_next_arg(&ebuf); // This _may_ be -1 if we have a string target for argument // 1, as in the writestate command - args.addr1 = vm_debug_addr(args.target); + args.addr1 = apple2_debug_addr(args.target); - args.addr2 = vm_debug_addr(vm_debug_next_arg(&ebuf)); + args.addr2 = apple2_debug_addr(apple2_debug_next_arg(&ebuf)); // But if this is -1, then something went wrong if (args.addr2 == -1) { @@ -248,8 +248,8 @@ vm_debug_execute(const char *str) break; case 1: - args.target = vm_debug_next_arg(&ebuf); - args.addr1 = vm_debug_addr(args.target); + args.target = apple2_debug_next_arg(&ebuf); + args.addr1 = apple2_debug_addr(args.target); break; @@ -264,15 +264,15 @@ vm_debug_execute(const char *str) } /* - * Compare a string key (k) with a vm_debug_cmd (elem) name or abbrev + * Compare a string key (k) with a apple2_debug_cmd (elem) name or abbrev * field. This is the function we use for bsearch() in - * vm_debug_find_cmd(). + * apple2_debug_find_cmd(). */ static int cmd_compar(const void *k, const void *elem) { const char *key = (const char *)k; - const vm_debug_cmd *cmd = (const vm_debug_cmd *)elem; + const apple2_debug_cmd *cmd = (const apple2_debug_cmd *)elem; if (strlen(key) < 3) { return strcmp(key, cmd->abbrev); @@ -286,11 +286,11 @@ cmd_compar(const void *k, const void *elem) * either be an abbreviation (if 1 or 2 characters) or a full name (if * otherwise). If no matching cmd can be found, return NULL. */ -vm_debug_cmd * -vm_debug_find_cmd(const char *str) +apple2_debug_cmd * +apple2_debug_find_cmd(const char *str) { - return (vm_debug_cmd *)bsearch(str, &cmdtable, CMDTABLE_SIZE, - sizeof(vm_debug_cmd), cmd_compar); + return (apple2_debug_cmd *)bsearch(str, &cmdtable, CMDTABLE_SIZE, + sizeof(apple2_debug_cmd), cmd_compar); } /* @@ -298,7 +298,7 @@ vm_debug_find_cmd(const char *str) */ DEBUG_CMD(break) { - vm_debug_break(args->addr1); + apple2_debug_break(args->addr1); } /* @@ -307,7 +307,7 @@ DEBUG_CMD(break) DEBUG_CMD(help) { FILE *stream = (FILE *)vm_di_get(VM_OUTPUT); - vm_debug_cmd *cmd; + apple2_debug_cmd *cmd; for (int i = 0; i < CMDTABLE_SIZE; i++) { cmd = &cmdtable[i]; @@ -325,7 +325,7 @@ DEBUG_CMD(resume) // If we paused because of a breakpoint, then we need to clear it // before we can really keep moving. - vm_debug_unbreak(mach->cpu->PC); + apple2_debug_unbreak(mach->cpu->PC); mach->paused = false; } @@ -411,7 +411,7 @@ DEBUG_CMD(quit) */ DEBUG_CMD(unbreak) { - vm_debug_unbreak(args->addr1); + apple2_debug_unbreak(args->addr1); } /* @@ -422,9 +422,9 @@ DEBUG_CMD(step) { mos6502 *cpu = (mos6502 *)vm_di_get(VM_CPU); - vm_debug_unbreak(cpu->PC); + apple2_debug_unbreak(cpu->PC); mos6502_execute(cpu); - vm_debug_break(cpu->PC); + apple2_debug_break(cpu->PC); } /* diff --git a/src/mos6502/mos6502.c b/src/mos6502/mos6502.c index d518456..d80aca1 100644 --- a/src/mos6502/mos6502.c +++ b/src/mos6502/mos6502.c @@ -14,7 +14,6 @@ #include "log.h" #include "mos6502/mos6502.h" #include "mos6502/dis.h" -#include "vm_debug.h" // All of our address modes, instructions, etc. are defined here. #include "mos6502/enums.h"