diff options
author | James Brown | 2004-01-10 05:20:15 +0000 |
---|---|---|
committer | James Brown | 2004-01-10 05:20:15 +0000 |
commit | 1778b01d765b8290c47324d6befebb9130353973 (patch) | |
tree | 0dfb0c136410c075a4f86a8f51db5c6a9a14499c /scumm | |
parent | ab7db8fb045d36dfcd1d5eb709c0ccc64298512d (diff) | |
download | scummvm-rg350-1778b01d765b8290c47324d6befebb9130353973.tar.gz scummvm-rg350-1778b01d765b8290c47324d6befebb9130353973.tar.bz2 scummvm-rg350-1778b01d765b8290c47324d6befebb9130353973.zip |
Start of debug channel support. TODO: Move this to the common Debugger system?
svn-id: r12289
Diffstat (limited to 'scumm')
-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 |
4 files changed, 113 insertions, 0 deletions
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; |