From f40b9ec82edbb852f2ac0677fda01b5728a3bfba Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 30 May 2016 12:12:00 -0700 Subject: [PATCH] GB: Fix up debugger a bit --- src/gb/cli.c | 16 +++++++- src/gb/io.c | 58 +++++++++++++++++++++++++++++ src/gb/io.h | 5 ++- src/gba/io.c | 2 +- src/gba/io.h | 2 +- src/lr35902/debugger/cli-debugger.c | 2 +- 6 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/gb/cli.c b/src/gb/cli.c index 132e6747f..7a166855e 100644 --- a/src/gb/cli.c +++ b/src/gb/cli.c @@ -16,6 +16,7 @@ static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*); static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*); +static uint32_t _GBCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); static void _frame(struct CLIDebugger*, struct CLIDebugVector*); @@ -31,7 +32,7 @@ struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore* core) { debugger->d.init = _GBCLIDebuggerInit; debugger->d.deinit = NULL; debugger->d.custom = _GBCLIDebuggerCustom; - debugger->d.lookupIdentifier = NULL; + debugger->d.lookupIdentifier = _GBCLIDebuggerLookupIdentifier; debugger->d.name = "Game Boy"; debugger->d.commands = _GBCLIDebuggerCommands; @@ -62,6 +63,19 @@ static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem* debugger) { return false; } +static uint32_t _GBCLIDebuggerLookupIdentifier(struct CLIDebuggerSystem* debugger, const char* name, struct CLIDebugVector* dv) { + UNUSED(debugger); + int i; + for (i = 0; i < REG_MAX; ++i) { + const char* reg = GBIORegisterNames[i]; + if (reg && strcasecmp(reg, name) == 0) { + return GB_BASE_IO | i; + } + } + dv->type = CLIDV_ERROR_TYPE; + return 0; +} + static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { UNUSED(dv); debugger->d.state = DEBUGGER_CUSTOM; diff --git a/src/gb/io.c b/src/gb/io.c index 5eed35823..34107601f 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -9,6 +9,64 @@ mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O"); +const char* const GBIORegisterNames[] = { + [REG_JOYP] = "JOYP", + [REG_SB] = "SB", + [REG_SC] = "SC", + [REG_DIV] = "DIV", + [REG_TIMA] = "TIMA", + [REG_TMA] = "TMA", + [REG_TAC] = "TAC", + [REG_IF] = "IF", + [REG_NR10] = "NR10", + [REG_NR11] = "NR11", + [REG_NR12] = "NR12", + [REG_NR13] = "NR13", + [REG_NR14] = "NR14", + [REG_NR21] = "NR21", + [REG_NR22] = "NR22", + [REG_NR23] = "NR23", + [REG_NR24] = "NR24", + [REG_NR30] = "NR30", + [REG_NR31] = "NR31", + [REG_NR32] = "NR32", + [REG_NR33] = "NR33", + [REG_NR34] = "NR34", + [REG_NR41] = "NR41", + [REG_NR42] = "NR42", + [REG_NR43] = "NR43", + [REG_NR44] = "NR44", + [REG_NR50] = "NR50", + [REG_NR51] = "NR51", + [REG_NR52] = "NR52", + [REG_LCDC] = "LCDC", + [REG_STAT] = "STAT", + [REG_SCY] = "SCY", + [REG_SCX] = "SCX", + [REG_LY] = "LY", + [REG_LYC] = "LYC", + [REG_DMA] = "DMA", + [REG_BGP] = "BGP", + [REG_OBP0] = "OBP0", + [REG_OBP1] = "OBP1", + [REG_WY] = "WY", + [REG_WX] = "WX", + [REG_KEY1] = "KEY1", + [REG_VBK] = "VBK", + [REG_HDMA1] = "HDMA1", + [REG_HDMA2] = "HDMA2", + [REG_HDMA3] = "HDMA3", + [REG_HDMA4] = "HDMA4", + [REG_HDMA5] = "HDMA5", + [REG_RP] = "RP", + [REG_BCPS] = "BCPS", + [REG_BCPD] = "BCPD", + [REG_OCPS] = "OCPS", + [REG_OCPD] = "OCPD", + [REG_SVBK] = "SVBK", + [REG_IE] = "IE", +}; + static const uint8_t _registerMask[] = { [REG_SC] = 0x7E, // TODO: GBC differences [REG_IF] = 0xE0, diff --git a/src/gb/io.h b/src/gb/io.h index 7c5cec231..88e4543b1 100644 --- a/src/gb/io.h +++ b/src/gb/io.h @@ -101,9 +101,12 @@ enum GBIORegisters { REG_UNK74 = 0x74, REG_UNK75 = 0x75, REG_UNK76 = 0x76, - REG_UNK77 = 0x77 + REG_UNK77 = 0x77, + REG_MAX = 0x100 }; +extern const char* const GBIORegisterNames[]; + struct GB; void GBIOInit(struct GB* gb); void GBIOReset(struct GB* gb); diff --git a/src/gba/io.c b/src/gba/io.c index ec340bf90..84b7a0043 100644 --- a/src/gba/io.c +++ b/src/gba/io.c @@ -12,7 +12,7 @@ mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O"); -const char* GBAIORegisterNames[] = { +const char* const GBAIORegisterNames[] = { // Video "DISPCNT", 0, diff --git a/src/gba/io.h b/src/gba/io.h index b66cc2a39..a47662a64 100644 --- a/src/gba/io.h +++ b/src/gba/io.h @@ -155,7 +155,7 @@ enum GBAIORegisters { mLOG_DECLARE_CATEGORY(GBA_IO); -extern const char* GBAIORegisterNames[]; +extern const char* const GBAIORegisterNames[]; void GBAIOInit(struct GBA* gba); void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value); diff --git a/src/lr35902/debugger/cli-debugger.c b/src/lr35902/debugger/cli-debugger.c index d6badb25f..6773a7120 100644 --- a/src/lr35902/debugger/cli-debugger.c +++ b/src/lr35902/debugger/cli-debugger.c @@ -87,7 +87,7 @@ void LR35902CLIDebuggerCreate(struct CLIDebuggerSystem* debugger) { debugger->disassemble = NULL; debugger->lookupPlatformIdentifier = _lookupPlatformIdentifier; debugger->platformName = "GB-Z80"; - debugger->platformCommands = NULL; + debugger->platformCommands = _lr35902Commands; } #endif