From e07cef142e85fe1986d8187ac862c96b0f4761c6 Mon Sep 17 00:00:00 2001 From: skidau Date: Sun, 19 Apr 2015 07:01:41 +0000 Subject: [PATCH] Re-enabled the debugger in the command line version (SDL) --- src/common/ConfigManager.cpp | 92 ++++++++++++++++++------------------ src/gba/GBA.cpp | 41 ++++++++-------- src/gba/remote.h | 6 +++ src/sdl/SDL.cpp | 13 ++--- src/win32/VBA.cpp | 3 -- 5 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 6bda4edd..9664fe22 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -20,6 +20,7 @@ extern "C" { #include "../gba/agbprint.h" #include "../gba/Flash.h" #include "../gba/Cheats.h" +#include "../gba/remote.h" #include "../gba/RTC.h" #include "../gba/Sound.h" #include "../gb/gb.h" @@ -252,7 +253,9 @@ int ifbType = kIFBNone; int patchNum = 0; char *(patchNames[PATCH_MAX_NUM]) = { NULL }; // and so on - +void(*dbgMain)() = remoteStubMain; +void(*dbgSignal)(int, int) = remoteStubSignal; +void(*dbgOutput)(const char *, u32) = remoteOutput; char* homeDir = NULL; char* arg0 = NULL; @@ -894,7 +897,7 @@ int ReadOpts(int argc, char ** argv) log("Missing BIOS file name\n"); break; } - strcpy(biosFileNameGBA, optarg + 1); + strcpy(biosFileNameGBA, optarg); break; case 'c': { @@ -902,13 +905,13 @@ int ReadOpts(int argc, char ** argv) log("Missing config file name\n"); break; } - FILE *f = fopen(optarg + 1, "r"); + FILE *f = fopen(optarg, "r"); if (f == NULL) { - log("File not found %s\n", optarg + 1); + log("File not found %s\n", optarg); break; } preferences = NULL; - OpenPreferences(optarg + 1); + OpenPreferences(optarg); fclose(f); } break; @@ -924,49 +927,48 @@ int ReadOpts(int argc, char ** argv) break; } if (patchNum >= PATCH_MAX_NUM) { - log("Too many patches given at %s (max is %d). Ignoring.\n", optarg + 1, PATCH_MAX_NUM); + log("Too many patches given at %s (max is %d). Ignoring.\n", optarg, PATCH_MAX_NUM); } else { - patchNames[patchNum] = (char *)malloc(1 + strlen(optarg + 1)); - strcpy(patchNames[patchNum], optarg + 1); + patchNames[patchNum] = (char *)malloc(1 + strlen(optarg)); + strcpy(patchNames[patchNum], optarg); patchNum++; } break; - //case 'G': - // dbgMain = remoteStubMain; - // dbgSignal = remoteStubSignal; - // dbgOutput = remoteOutput; - // debugger = true; - // debuggerStub = true; - // if (optarg) { - // char *s = optarg; - // if (strncmp(s, "tcp:", 4) == 0) { - // s += 4; - // int port = atoi(s); - // remoteSetProtocol(0); - // remoteSetPort(port); - // } - // else if (strcmp(s, "tcp") == 0) { - // remoteSetProtocol(0); - // } - // else if (strcmp(s, "pipe") == 0) { - // remoteSetProtocol(1); - // } - // else { - // log("Unknown protocol %s\n", s); - // break; - // } - // } - // else { - // remoteSetProtocol(0); - // } - // break; + case 'G': + dbgMain = remoteStubMain; + dbgSignal = remoteStubSignal; + dbgOutput = remoteOutput; + debugger = true; + if (optarg) { + char *s = optarg; + if (strncmp(s, "tcp:", 4) == 0) { + s += 4; + int port = atoi(s); + remoteSetProtocol(0); + remoteSetPort(port); + } + else if (strcmp(s, "tcp") == 0) { + remoteSetProtocol(0); + } + else if (strcmp(s, "pipe") == 0) { + remoteSetProtocol(1); + } + else { + log("Unknown protocol %s\n", s); + break; + } + } + else { + remoteSetProtocol(0); + } + break; case 'N': parseDebug = false; break; case 'D': if (optarg) { - systemDebug = atoi(optarg + 1); + systemDebug = atoi(optarg); } else { systemDebug = 1; @@ -978,7 +980,7 @@ int ReadOpts(int argc, char ** argv) break; case 'f': if (optarg) { - filter = (Filter)atoi(optarg + 1); + filter = (Filter)atoi(optarg); } else { filter = kStretch2x; @@ -986,7 +988,7 @@ int ReadOpts(int argc, char ** argv) break; case 'I': if (optarg) { - ifbType = (IFBFilter)atoi(optarg + 1); + ifbType = (IFBFilter)atoi(optarg); } else { ifbType = kIFBNone; @@ -1002,13 +1004,13 @@ int ReadOpts(int argc, char ** argv) #endif break; case 'S': - optFlashSize = atoi(optarg + 1); + optFlashSize = atoi(optarg); if (optFlashSize < 0 || optFlashSize > 1) optFlashSize = 0; break; case 's': if (optarg) { - int a = atoi(optarg + 1); + int a = atoi(optarg); if (a >= 0 && a <= 9) { gbFrameSkip = a; frameSkip = a; @@ -1021,7 +1023,7 @@ int ReadOpts(int argc, char ** argv) break; case 't': if (optarg) { - int a = atoi(optarg + 1); + int a = atoi(optarg); if (a < 0 || a > 5) a = 0; cpuSaveType = a; @@ -1029,7 +1031,7 @@ int ReadOpts(int argc, char ** argv) break; case 'v': if (optarg) { - systemVerbose = atoi(optarg + 1); + systemVerbose = atoi(optarg); } else systemVerbose = 0; @@ -1039,7 +1041,7 @@ int ReadOpts(int argc, char ** argv) break; case 'O': if (optarg) { - openGL = atoi(optarg + 1); + openGL = atoi(optarg); if (openGL < 0 || openGL > 2) openGL = 1; } diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index a6e18dcb..4ee6d76d 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -1510,6 +1510,26 @@ void SetMapMasks() map[10].mask = 0x1FFFFFF; map[12].mask = 0x1FFFFFF; map[14].mask = 0xFFFF; + + for (int i = 0; i < 16; i++) { + map[i].size = map[i].mask + 1; + if (map[i].size > 0) { + map[i].trace = (u8 *)calloc(map[i].size >> 3, sizeof(u8)); + + map[i].breakPoints = (u8 *)calloc(map[i].size >> 1, sizeof(u8)); //\\ + + if (map[i].trace == NULL || map[i].breakPoints == NULL) { + systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), + "TRACE"); + } + } + else { + map[i].trace = NULL; + map[i].breakPoints = NULL; //\\ + + } + } + clearBreakRegList(); } int CPULoadRom(const char *szFile) @@ -1737,27 +1757,6 @@ int CPULoadRomData(const char *data, int size) #ifdef BKPT_SUPPORT SetMapMasks(); - - for (int i = 0; i < 16; i++) { - map[i].size = map[i].mask + 1; - if (map[i].size > 0) { - map[i].trace = (u8 *)calloc(map[i].size >> 3, sizeof(u8)); - - map[i].breakPoints = (u8 *)calloc(map[i].size >> 1, sizeof(u8)); //\\ - - if (map[i].trace == NULL || map[i].breakPoints == NULL) { - systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), - "TRACE"); - } - } - else { - map[i].trace = NULL; - map[i].breakPoints = NULL; //\\ - - } - } - clearBreakRegList(); - #endif return romSize; diff --git a/src/gba/remote.h b/src/gba/remote.h index 951e42cb..7d210337 100644 --- a/src/gba/remote.h +++ b/src/gba/remote.h @@ -76,4 +76,10 @@ void deleteFromBreakRegList(u8 regnum, int location); void addBreakRegToList(u8 regnum, u8 flags, u32 value); void printBreakRegList(bool verbose); +void remoteStubMain(); +void remoteStubSignal(int sig, int number); +void remoteOutput(const char *s, u32 addr); +void remoteSetProtocol(int p); +void remoteSetPort(int port); + #endif // REMOTE_H diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index c776ef68..4df41b31 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -182,18 +182,13 @@ enum VIDEO_SIZE{ u32 throttleLastTime = 0; bool pauseNextFrame = false; -bool debuggerStub = false; int sdlMirroringEnable = 0; static int ignore_first_resize_event = 0; -void (*dbgMain)(); /* forward */ void systemConsoleMessage(const char*); -void (*dbgSignal)(int,int); -void (*dbgOutput)(const char *, u32); - char* home; char screenMessageBuffer[21]; @@ -1157,7 +1152,6 @@ void sdlPollEvents() } break; case SDLK_F11: - if(dbgMain == remoteStubMain) { if(armState) { armNextPC -= 4; reg[15].I -= 4; @@ -1165,7 +1159,6 @@ void sdlPollEvents() armNextPC -= 2; reg[15].I -= 2; } - } debugger = true; break; case SDLK_F1: @@ -1569,7 +1562,7 @@ int main(int argc, char **argv) exit(-1); } - if (!debuggerStub) { + if (!debugger) { if (optind >= argc) { systemMessage(0, "Missing image name"); usage(argv[0]); @@ -1701,7 +1694,7 @@ int main(int argc, char **argv) sdlReadBattery(); - if(debuggerStub) + if(debugger) remoteInit(); int flags = SDL_INIT_VIDEO|SDL_INIT_AUDIO| @@ -1810,7 +1803,7 @@ int main(int argc, char **argv) while(emulating) { if(!paused && active) { if(debugger && emulator.emuHasDebugger) - dbgMain(); + remoteStubMain(); else { emulator.emuMain(emulator.emuCount); if(rewindSaveNeeded && rewindMemory && emulator.emuWriteMemState) { diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 5bfde6eb..f74f92d3 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -151,9 +151,6 @@ bool soundBufferLow = 0; void winSignal(int,int); void winOutput(const char *, u32); -void (*dbgSignal)(int,int) = winSignal; -void (*dbgOutput)(const char *, u32) = winOutput; - #ifdef MMX extern "C" bool cpu_mmx; #endif