rlm@1: #include rlm@1: #include rlm@1: rlm@1: #include "GBAGlobals.h" rlm@1: rlm@1: extern void (*dbgOutput)(char *, u32); rlm@1: extern int systemVerbose; rlm@1: rlm@1: static bool agbPrintEnabled = false; rlm@1: static bool agbPrintProtect = false; rlm@1: rlm@1: bool agbPrintWrite(u32 address, u16 value) rlm@1: { rlm@1: if (agbPrintEnabled) rlm@1: { rlm@1: if (address == 0x9fe2ffe) // protect rlm@1: { rlm@1: agbPrintProtect = (value != 0); rlm@1: debuggerWriteHalfWord(address, value); rlm@1: return true; rlm@1: } rlm@1: else rlm@1: { rlm@1: if (agbPrintProtect && rlm@1: ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure rlm@1: || (address >= 0x8fd0000 && address <= 0x8fdffff) rlm@1: || (address >= 0x9fd0000 && address <= 0x9fdffff))) rlm@1: { rlm@1: debuggerWriteHalfWord(address, value); rlm@1: return true; rlm@1: } rlm@1: } rlm@1: } rlm@1: return false; rlm@1: } rlm@1: rlm@1: void agbPrintReset() rlm@1: { rlm@1: agbPrintProtect = false; rlm@1: } rlm@1: rlm@1: void agbPrintEnable(bool enable) rlm@1: { rlm@1: agbPrintEnabled = enable; rlm@1: } rlm@1: rlm@1: bool agbPrintIsEnabled() rlm@1: { rlm@1: return agbPrintEnabled; rlm@1: } rlm@1: rlm@1: void agbPrintFlush() rlm@1: { rlm@1: u16 get = debuggerReadHalfWord(0x9fe20fc); rlm@1: u16 put = debuggerReadHalfWord(0x9fe20fe); rlm@1: rlm@1: u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16); rlm@1: if (address != 0xfd0000 && address != 0x1fd0000) rlm@1: { rlm@1: dbgOutput("Did you forget to call AGBPrintInit?\n", 0); rlm@1: // get rid of the text otherwise we will continue to be called rlm@1: debuggerWriteHalfWord(0x9fe20fc, put); rlm@1: return; rlm@1: } rlm@1: rlm@1: u8 *data = &rom[address]; rlm@1: rlm@1: while (get != put) rlm@1: { rlm@1: char c = data[get++]; rlm@1: char s[2]; rlm@1: s[0] = c; rlm@1: s[1] = 0; rlm@1: rlm@1: if (systemVerbose & VERBOSE_AGBPRINT) rlm@1: dbgOutput(s, 0); rlm@1: if (c == '\n') rlm@1: break; rlm@1: } rlm@1: debuggerWriteHalfWord(0x9fe20fc, get); rlm@1: } rlm@1: