diff options
-rw-r--r-- | base/engine.cpp | 27 | ||||
-rw-r--r-- | common/util.h | 1 | ||||
-rw-r--r-- | scumm/debugger.cpp | 78 | ||||
-rw-r--r-- | scumm/debugger.h | 1 | ||||
-rw-r--r-- | scumm/script.cpp | 6 | ||||
-rw-r--r-- | scumm/scumm.h | 28 |
6 files changed, 141 insertions, 0 deletions
diff --git a/base/engine.cpp b/base/engine.cpp index 5bb7a33fe5..7660fbcfd4 100644 --- a/base/engine.cpp +++ b/base/engine.cpp @@ -192,6 +192,33 @@ void CDECL debug(int level, const char *s, ...) { fflush(stdout); } +void CDECL debug(const char *s, ...) { +#ifdef __PALM_OS__ + char buf[256]; // 1024 is too big overflow the stack +#else + char buf[1024]; +#endif + va_list va; + + va_start(va, s); + vsprintf(buf, s, va); + va_end(va); + printf("%s\n", buf); + +#if defined( USE_WINDBG ) + strcat(buf, "\n"); +#if defined( _WIN32_WCE ) + TCHAR buf_unicode[1024]; + MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode)); + OutputDebugString(buf_unicode); +#else + OutputDebugString(buf); +#endif +#endif + + fflush(stdout); +} + void checkHeap() { #if defined(_MSC_VER) if (_heapchk() != _HEAPOK) { diff --git a/common/util.h b/common/util.h index ffd77e3252..9e103f1229 100644 --- a/common/util.h +++ b/common/util.h @@ -164,6 +164,7 @@ void CDECL NORETURN error(const char *s, ...); void CDECL warning(const char *s, ...); void CDECL debug(int level, const char *s, ...); +void CDECL debug(const char *s, ...); void checkHeap(); diff --git a/scumm/debugger.cpp b/scumm/debugger.cpp index fe9e8eec7d..1f42b7bfeb 100644 --- a/scumm/debugger.cpp +++ b/scumm/debugger.cpp @@ -39,6 +39,24 @@ extern uint16 g_debugLevel; namespace Scumm { +void CDECL debugC(int channel, const char *s, ...) { +#ifdef __PALM_OS__ + char buf[256]; // 1024 is too big overflow the stack +#else + char buf[1024]; +#endif + va_list va; + + if (!(g_scumm->_debugFlags & channel)) + return; + + va_start(va, s); + vsprintf(buf, s, va); + va_end(va); + + debug(buf); +}; + ScummDebugger::ScummDebugger(ScummEngine *s) : Common::Debugger<ScummDebugger>() { _vm = s; @@ -80,6 +98,7 @@ ScummDebugger::ScummDebugger(ScummEngine *s) DCmd_Register("savegame", &ScummDebugger::Cmd_SaveGame); DCmd_Register("level", &ScummDebugger::Cmd_DebugLevel); + DCmd_Register("debug", &ScummDebugger::Cmd_Debug); DCmd_Register("help", &ScummDebugger::Cmd_Help); DCmd_Register("show", &ScummDebugger::Cmd_Show); @@ -519,6 +538,65 @@ bool ScummDebugger::Cmd_Help(int argc, const char **argv) { return true; } +bool ScummDebugger::Cmd_Debug(int argc, const char **argv) { + int numChannels = sizeof(debugChannels) / sizeof(dbgChannelDesc); + + bool setFlag = false; // Remove or add debug channel? + + if ((argc == 1) && (_vm->_debugFlags == 0)) { + DebugPrintf("No debug flags are enabled\n"); + DebugPrintf("Available Channels: "); + for (int i = 0; i < numChannels; i++) { + DebugPrintf("%s, ", debugChannels[i].channel); + } + DebugPrintf("\n"); + return true; + } + + if ((argc == 1) && (_vm->_debugFlags > 0)) { + for (int i = 0; i < numChannels; i++) { + if(_vm->_debugFlags & debugChannels[i].flag) + DebugPrintf("%s - %s\n", debugChannels[i].channel, + debugChannels[i].desc); + } + return true; + } + + // Enable or disable channel? + if (argv[1][0] == '+') { + setFlag = true; + } else if (argv[1][0] == '-') { + setFlag = false; + } else { + DebugPrintf("Syntax: Debug +CHANNEL, or Debug -CHANNEL\n"); + DebugPrintf("Available Channels: "); + for (int i = 0; i < numChannels; i++) { + DebugPrintf("%s, ", debugChannels[i].channel); + DebugPrintf("\n"); + } + } + + // Identify flag + const char *realFlag = argv[1] + 1; + for (int i = 0; i < numChannels; i++) { + if((scumm_stricmp(debugChannels[i].channel, realFlag)) == 0) { + if (setFlag) { + _vm->_debugFlags |= debugChannels[i].flag; + DebugPrintf("Enable "); + } else { + _vm->_debugFlags &= ~debugChannels[i].flag; + DebugPrintf("Disable "); + } + + DebugPrintf("%s\n", debugChannels[i].desc); + return true; + } + } + + DebugPrintf("Unknown flag. Type 'Debug ?' for syntax\n"); + return true; +}; + bool ScummDebugger::Cmd_DebugLevel(int argc, const char **argv) { if (argc == 1) { if (_vm->_debugMode == false) diff --git a/scumm/debugger.h b/scumm/debugger.h index 42fdcf002d..af9b10157f 100644 --- a/scumm/debugger.h +++ b/scumm/debugger.h @@ -57,6 +57,7 @@ protected: bool Cmd_PrintDraft(int argc, const char **argv); + bool Cmd_Debug(int argc, const char **argv); bool Cmd_DebugLevel(int argc, const char **argv); bool Cmd_Help(int argc, const char **argv); diff --git a/scumm/script.cpp b/scumm/script.cpp index 70bafab194..39becf1af1 100644 --- a/scumm/script.cpp +++ b/scumm/script.cpp @@ -50,11 +50,17 @@ void ScummEngine::runScript(int script, bool freezeResistant, bool recursive, in scriptPtr = getResourceAddress(rtScript, script); scriptOffs = _resourceHeaderSize; scriptType = WIO_GLOBAL; + + debugC(DEBUG_SCRIPTS, "runScript(Global-%d) from %d-%d", script, + vm.slot[_currentScript].number, _roomResource); } else { scriptOffs = _localScriptList[script - _numGlobalScripts]; if (scriptOffs == 0) error("Local script %d is not in room %d", script, _roomResource); scriptType = WIO_LOCAL; + + debugC(DEBUG_SCRIPTS, "runScript(%d) from %d-%d", script, + vm.slot[_currentScript].number, _roomResource); } slot = getScriptSlot(); diff --git a/scumm/scumm.h b/scumm/scumm.h index f9c58f4f19..3ba8d3fba5 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -38,6 +38,7 @@ namespace GUI { using GUI::Dialog; class GameDetector; + namespace Scumm { class Actor; @@ -111,6 +112,32 @@ enum ObjectClass { kObjectClassUntouchable = 32 }; +/* SCUMM Debug Channels */ +void CDECL debugC(int level, const char *s, ...); + +struct dbgChannelDesc { + const char *channel, *desc; + uint32 flag; +}; + +enum { + DEBUG_SCRIPTS = 1 << 0, // Track script execution (start/stop/pause) + DEBUG_OPCODES = 1 << 1, // Track opcode invocations + DEBUG_IMUSE = 1 << 2, // Track iMUSE events + DEBUG_RESOURCE = 1 << 3, // Track resource loading / allocation + DEBUG_VARS = 1 << 4 // Track variable changes +}; + + +// Debug channel lookup table for Debugger console +static const dbgChannelDesc debugChannels[] = { + {"SCRIPTS", "Track script execution", DEBUG_SCRIPTS}, + {"OPCODES", "Track opcode execution", DEBUG_OPCODES}, + {"IMUSE", "Track iMUSE events", DEBUG_IMUSE}, + {"RESOURCE", "Track resource loading/management", DEBUG_RESOURCE}, + {"VARS", "Track variable changes", DEBUG_VARS} +}; + struct MemBlkHeader { uint32 size; }; @@ -313,6 +340,7 @@ public: void clearClickedStatus(); // Misc utility functions + uint32 _debugFlags; const char *getGameName() const { return _gameName.c_str(); } const char *getGameDataPath() const; |