Merge pull request #462 from digitall/debugConsoleChangeLevel

Add command to change debug level to the Debugger base class.
This commit is contained in:
Johannes Schickel 2014-05-17 04:42:58 +02:00
commit e0b82f0ced
16 changed files with 69 additions and 86 deletions

View File

@ -21,6 +21,7 @@
*/
#include "common/config-manager.h"
#include "common/debug-channels.h"
#include "common/file.h"
#include "common/fs.h"
#include "common/textconsole.h"
@ -144,6 +145,14 @@ AGOSEngine_Elvira1::AGOSEngine_Elvira1(OSystem *system, const AGOSGameDescriptio
AGOSEngine::AGOSEngine(OSystem *system, const AGOSGameDescription *gd)
: Engine(system), _rnd("agos"), _gameDescription(gd) {
DebugMan.addDebugChannel(kDebugOpcode, "opcode", "Opcode debug level");
DebugMan.addDebugChannel(kDebugVGAOpcode, "vga_opcode", "VGA Opcode debug level");
DebugMan.addDebugChannel(kDebugSubroutine, "subroutine", "Subroutine debug level");
DebugMan.addDebugChannel(kDebugVGAScript, "vga_script", "VGA Script debug level");
//Image dumping command disabled as it doesn't work well
#if 0
DebugMan.addDebugChannel(kDebugImageDump, "image_dump", "Enable dumping of images to files");
#endif
_vcPtr = 0;
_vcGetOutOfCode = 0;
_gameOffsetsPtr = 0;
@ -243,13 +252,6 @@ AGOSEngine::AGOSEngine(OSystem *system, const AGOSGameDescription *gd)
_backFlag = false;
_debugMode = 0;
_dumpScripts = false;
_dumpOpcodes = false;
_dumpVgaScripts = false;
_dumpVgaOpcodes = false;
_dumpImages = false;
_copyProtection = false;
_pause = false;
_speech = false;
@ -675,15 +677,6 @@ Common::Error AGOSEngine::init() {
_subtitles = true;
}
// TODO: Use special debug levels instead of the following hack.
_debugMode = (gDebugLevel >= 0);
switch (gDebugLevel) {
case 2: _dumpOpcodes = true; break;
case 3: _dumpVgaOpcodes = true; break;
case 4: _dumpScripts = true; break;
case 5: _dumpVgaScripts = true; break;
}
return Common::kNoError;
}

View File

@ -61,6 +61,14 @@ struct Surface;
namespace AGOS {
enum {
kDebugOpcode = 1 << 0,
kDebugVGAOpcode = 1 << 1,
kDebugSubroutine = 1 << 2,
kDebugVGAScript = 1 << 3,
kDebugImageDump = 1 << 4
};
uint fileReadItemID(Common::SeekableReadStream *in);
#define CHECK_BOUNDS(x, y) assert((uint)(x) < ARRAYSIZE(y))
@ -324,15 +332,9 @@ protected:
bool _fastMode;
bool _backFlag;
uint16 _debugMode;
Common::Language _language;
bool _copyProtection;
bool _pause;
bool _dumpScripts;
bool _dumpOpcodes;
bool _dumpVgaScripts;
bool _dumpVgaOpcodes;
bool _dumpImages;
bool _speech;
bool _subtitles;
bool _vgaVar9;

View File

@ -33,7 +33,6 @@ Debugger::Debugger(AGOSEngine *vm)
_vm = vm;
DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit));
DCmd_Register("level", WRAP_METHOD(Debugger, Cmd_DebugLevel));
DCmd_Register("music", WRAP_METHOD(Debugger, Cmd_PlayMusic));
DCmd_Register("sound", WRAP_METHOD(Debugger, Cmd_PlaySound));
DCmd_Register("voice", WRAP_METHOD(Debugger, Cmd_PlayVoice));
@ -48,28 +47,6 @@ Debugger::Debugger(AGOSEngine *vm)
}
bool Debugger::Cmd_DebugLevel(int argc, const char **argv) {
if (argc == 1) {
if (_vm->_debugMode == false)
DebugPrintf("Debugging is not enabled at this time\n");
else
DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel);
} else { // set level
gDebugLevel = atoi(argv[1]);
if (0 <= gDebugLevel && gDebugLevel < 11) {
_vm->_debugMode = true;
DebugPrintf("Debug level set to level %d\n", gDebugLevel);
} else if (gDebugLevel < 0) {
_vm->_debugMode = false;
DebugPrintf("Debugging is now disabled\n");
} else
DebugPrintf("Not a valid debug level (0 - 10)\n");
}
return true;
}
bool Debugger::Cmd_PlayMusic(int argc, const char **argv) {
if (argc > 1) {
uint music = atoi(argv[1]);

View File

@ -37,7 +37,6 @@ public:
private:
AGOSEngine *_vm;
bool Cmd_DebugLevel(int argc, const char **argv);
bool Cmd_PlayMusic(int argc, const char **argv);
bool Cmd_PlaySound(int argc, const char **argv);
bool Cmd_PlayVoice(int argc, const char **argv);

View File

@ -20,6 +20,7 @@
*
*/
#include "common/debug-channels.h"
#include "common/endian.h"
#include "common/system.h"
#include "common/textconsole.h"
@ -1129,7 +1130,7 @@ void AGOSEngine::animate(uint16 windowNum, uint16 zoneNum, uint16 vgaSpriteId, i
assert(READ_BE_UINT16(&((AnimationHeader_WW *) p)->id) == vgaSpriteId);
}
if (_dumpVgaScripts) {
if (DebugMan.isDebugChannelEnabled(kDebugVGAScript)) {
if (getGameType() == GType_FF || getGameType() == GType_PP) {
dumpVgaScript(_curVgaFile1 + READ_LE_UINT16(&((AnimationHeader_Feeble*)p)->scriptOffs), zoneNum, vgaSpriteId);
} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
@ -1235,7 +1236,7 @@ void AGOSEngine::setImage(uint16 vgaSpriteId, bool vgaScript) {
}
}
if (_dumpVgaScripts) {
if (DebugMan.isDebugChannelEnabled(kDebugVGAScript)) {
if (getGameType() == GType_FF || getGameType() == GType_PP) {
dumpVgaScript(_curVgaFile1 + READ_LE_UINT16(&((ImageHeader_Feeble*)b)->scriptOffs), zoneNum, vgaSpriteId);
} else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {

View File

@ -22,6 +22,7 @@
// Item script opcodes for Simon1/Simon2
#include "common/debug-channels.h"
#include "common/endian.h"
#include "common/system.h"
#include "common/textconsole.h"
@ -987,7 +988,7 @@ int AGOSEngine::runScript() {
return 1;
do {
if (_dumpOpcodes)
if (DebugMan.isDebugChannelEnabled(kDebugOpcode))
dumpOpcode(_codePtr);
if (getGameType() == GType_ELVIRA1) {

View File

@ -20,8 +20,7 @@
*
*/
#include "common/debug-channels.h"
#include "common/file.h"
#include "common/textconsole.h"
@ -531,7 +530,7 @@ int AGOSEngine::startSubroutine(Subroutine *sub) {
_classMode1 = 0;
_classMode2 = 0;
if (_dumpScripts)
if (DebugMan.isDebugChannelEnabled(kDebugSubroutine))
dumpSubroutine(sub);
if (++_recursionDepth > 40)
@ -564,8 +563,7 @@ restart:
else
_codePtr += 8;
if (_dumpOpcodes)
debug("; %d", sub->id);
debugC(kDebugOpcode, "; %d", sub->id);
result = runScript();
if (result != 0) {
break;

View File

@ -27,6 +27,7 @@
#include "agos/intern.h"
#include "agos/vga.h"
#include "common/debug-channels.h"
#include "common/endian.h"
#include "common/system.h"
#include "common/textconsole.h"
@ -152,7 +153,7 @@ void AGOSEngine::runVgaScript() {
for (;;) {
uint opcode;
if (_dumpVgaOpcodes) {
if (DebugMan.isDebugChannelEnabled(kDebugVGAOpcode)) {
if (_vcPtr != (const byte *)&_vcGetOutOfCode) {
debugN("%.5d %.5X: %5d %4d ", _vgaTickCounter, (unsigned int)(_vcPtr - _curVgaFile1), _vgaCurSpriteId, _vgaCurZoneNum);
dumpVideoScript(_vcPtr, true);
@ -381,8 +382,7 @@ void AGOSEngine::vcSkipNextInstruction() {
_vcPtr += opcodeParamLenPN[opcode];
}
if (_dumpVgaOpcodes)
debugN("; skipped\n");
debugCN(kDebugVGAOpcode, "; skipped\n");
}
// VGA Script commands
@ -648,7 +648,7 @@ void AGOSEngine::drawImage_init(int16 image, uint16 palette, int16 x, int16 y, u
if (height == 0 || width == 0)
return;
if (_dumpImages)
if (DebugMan.isDebugChannelEnabled(kDebugImageDump))
dumpSingleBitmap(_vgaCurZoneNum, state.image, state.srcPtr, width, height,
state.palette);
state.width = state.draw_width = width; /* cl */

View File

@ -22,7 +22,6 @@ private:
Parallaction *_vm;
MouseTriState _mouseState;
bool Cmd_DebugLevel(int argc, const char **argv);
bool Cmd_Location(int argc, const char **argv);
bool Cmd_Give(int argc, const char **argv);
bool Cmd_Zones(int argc, const char **argv);

View File

@ -89,7 +89,6 @@ ScummDebugger::ScummDebugger(ScummEngine *s)
DCmd_Register("loadgame", WRAP_METHOD(ScummDebugger, Cmd_LoadGame));
DCmd_Register("savegame", WRAP_METHOD(ScummDebugger, Cmd_SaveGame));
DCmd_Register("level", WRAP_METHOD(ScummDebugger, Cmd_DebugLevel));
DCmd_Register("debug", WRAP_METHOD(ScummDebugger, Cmd_Debug));
DCmd_Register("show", WRAP_METHOD(ScummDebugger, Cmd_Show));
@ -104,6 +103,18 @@ ScummDebugger::~ScummDebugger() {
// we need this destructor, even if it is empty, for __SYMBIAN32__
}
void ScummDebugger::preEnter() {
}
void ScummDebugger::postEnter() {
// Runtime debug level change is dealt with by the base class "debuglevel" command
// but need to ensure that the _debugMode parameter is updated in sync.
_vm->_debugMode = (gDebugLevel >= 0);
// Boot params often need debugging switched on to work
if (_vm->_bootParam)
_vm->_debugMode = true;
}
///////////////////////////////////////////////////
// Now the fun stuff:
@ -523,27 +534,6 @@ bool ScummDebugger::Cmd_Debug(int argc, const char **argv) {
return true;
}
bool ScummDebugger::Cmd_DebugLevel(int argc, const char **argv) {
if (argc == 1) {
if (_vm->_debugMode == false)
DebugPrintf("Debugging is not enabled at this time\n");
else
DebugPrintf("Debugging is currently set at level %d\n", gDebugLevel);
} else { // set level
gDebugLevel = atoi(argv[1]);
if (gDebugLevel >= 0) {
_vm->_debugMode = true;
DebugPrintf("Debug level set to level %d\n", gDebugLevel);
} else if (gDebugLevel < 0) {
_vm->_debugMode = false;
DebugPrintf("Debugging is now disabled\n");
} else
DebugPrintf("Not a valid debug level\n");
}
return true;
}
bool ScummDebugger::Cmd_Camera(int argc, const char **argv) {
DebugPrintf("Camera: cur (%d,%d) - dest (%d,%d) - accel (%d,%d) -- last (%d,%d)\n",
_vm->camera._cur.x, _vm->camera._cur.y, _vm->camera._dest.x, _vm->camera._dest.y,

View File

@ -37,6 +37,9 @@ public:
private:
ScummEngine *_vm;
virtual void preEnter();
virtual void postEnter();
// Commands
bool Cmd_Room(int argc, const char **argv);
bool Cmd_LoadGame(int argc, const char **argv);
@ -58,7 +61,6 @@ private:
bool Cmd_Passcode(int argc, const char **argv);
bool Cmd_Debug(int argc, const char **argv);
bool Cmd_DebugLevel(int argc, const char **argv);
bool Cmd_Show(int argc, const char **argv);
bool Cmd_Hide(int argc, const char **argv);

View File

@ -205,7 +205,7 @@ ScummEngine::ScummEngine(OSystem *syst, const DetectorResult &dr)
_lastInputScriptTime = 0;
_bootParam = 0;
_dumpScripts = false;
_debugMode = 0;
_debugMode = false;
_objectOwnerTable = NULL;
_objectRoomTable = NULL;
_objectStateTable = NULL;
@ -2281,7 +2281,7 @@ void ScummEngine::scummLoop_updateScummVars() {
VAR(VAR_MOUSE_Y) = _mouse.y;
if (VAR_DEBUGMODE != 0xFF) {
// This is NOT for the Mac version of Indy3/Loom
VAR(VAR_DEBUGMODE) = _debugMode;
VAR(VAR_DEBUGMODE) = (_debugMode ? 1 : 0);
}
} else if (_game.version >= 1) {
// We use shifts below instead of dividing by V12_X_MULTIPLIER resp.

View File

@ -586,7 +586,7 @@ protected:
bool _dumpScripts;
bool _hexdumpScripts;
bool _showStack;
uint16 _debugMode;
bool _debugMode;
// Save/Load class - some of this may be GUI
byte _saveLoadFlag, _saveLoadSlot;

View File

@ -805,7 +805,7 @@ void ScummEngine::resetScummVars() {
}
if (VAR_DEBUGMODE != 0xFF) {
VAR(VAR_DEBUGMODE) = _debugMode;
VAR(VAR_DEBUGMODE) = (_debugMode ? 1 : 0);
if (_game.heversion >= 80 && _debugMode)
VAR(85) = 1;
}

View File

@ -61,6 +61,7 @@ Debugger::Debugger() {
DCmd_Register("help", WRAP_METHOD(Debugger, Cmd_Help));
DCmd_Register("openlog", WRAP_METHOD(Debugger, Cmd_OpenLog));
DCmd_Register("debuglevel", WRAP_METHOD(Debugger, Cmd_DebugLevel));
DCmd_Register("debugflag_list", WRAP_METHOD(Debugger, Cmd_DebugFlagsList));
DCmd_Register("debugflag_enable", WRAP_METHOD(Debugger, Cmd_DebugFlagEnable));
DCmd_Register("debugflag_disable", WRAP_METHOD(Debugger, Cmd_DebugFlagDisable));
@ -501,6 +502,25 @@ bool Debugger::Cmd_OpenLog(int argc, const char **argv) {
}
bool Debugger::Cmd_DebugLevel(int argc, const char **argv) {
if (argc == 1) { // print level
DebugPrintf("Debugging is currently %s (set at level %d)\n", (gDebugLevel >= 0) ? "enabled" : "disabled", gDebugLevel);
DebugPrintf("Usage: %s <n> where n is 0 to 10 or -1 to disable debugging\n", argv[0]);
} else { // set level
gDebugLevel = atoi(argv[1]);
if (gDebugLevel >= 0 && gDebugLevel < 11) {
DebugPrintf("Debug level set to level %d\n", gDebugLevel);
} else if (gDebugLevel < 0) {
DebugPrintf("Debugging is now disabled\n");
} else {
DebugPrintf("Invalid debug level value\n");
DebugPrintf("Usage: %s <n> where n is 0 to 10 or -1 to disable debugging\n", argv[0]);
}
}
return true;
}
bool Debugger::Cmd_DebugFlagsList(int argc, const char **argv) {
const Common::DebugManager::DebugChannelList &debugLevels = DebugMan.listDebugChannels();

View File

@ -193,6 +193,7 @@ protected:
bool Cmd_Exit(int argc, const char **argv);
bool Cmd_Help(int argc, const char **argv);
bool Cmd_OpenLog(int argc, const char **argv);
bool Cmd_DebugLevel(int argc, const char **argv);
bool Cmd_DebugFlagsList(int argc, const char **argv);
bool Cmd_DebugFlagEnable(int argc, const char **argv);
bool Cmd_DebugFlagDisable(int argc, const char **argv);