From a57fcac59a47c406251e129e327487db90a14507 Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Mon, 13 Sep 2004 17:05:23 +0000 Subject: Add debugger for BASS. This should help in tracking down remaining bugs, such as the grid problems and walk deadlocks. svn-id: r15098 --- sky/debug.cpp | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- sky/debug.h | 31 +++++++++ sky/logic.cpp | 6 +- sky/logic.h | 1 + sky/mouse.cpp | 4 ++ sky/mouse.h | 3 +- sky/sky.cpp | 27 ++++---- sky/sky.h | 4 +- 8 files changed, 255 insertions(+), 20 deletions(-) (limited to 'sky') diff --git a/sky/debug.cpp b/sky/debug.cpp index e4973f4021..6354db77f3 100644 --- a/sky/debug.cpp +++ b/sky/debug.cpp @@ -22,6 +22,14 @@ #include "stdafx.h" #include "common/util.h" #include "sky/debug.h" +#include "sky/grid.h" +#include "sky/logic.h" +#include "sky/mouse.h" +#include "sky/screen.h" +#include "sky/sky.h" +#include "sky/struc.h" + +#include "common/debugger.cpp" namespace Sky { @@ -205,7 +213,7 @@ static const char *section_0_compacts[] = { "exit_seq", "forklift_cpt", "forklift1_cdt", - "forklift2_cdt", + "forklift2_cdt" }; static const char *logic_table_names[] = { @@ -225,7 +233,7 @@ static const char *logic_table_names[] = { "Logic::frames", "Logic::pause", "Logic::wait_sync", - "Logic::simple_anim", + "Logic::simple_anim" }; static const char opcode_par[] = { @@ -249,7 +257,7 @@ static const char opcode_par[] = { 0, 1, 0, - 0, + 0 }; static const char *opcodes[] = { @@ -273,7 +281,7 @@ static const char *opcodes[] = { "is_equal", "skip_nz", "script_exit", - "restart_script", + "restart_script" }; static const char *mcodes[] = { @@ -391,7 +399,7 @@ static const char *mcodes[] = { "fn_quit_to_dos", "fn_pause_fx", "fn_un_pause_fx", - "fn_printf", + "fn_printf" }; static const char *scriptVars[] = { @@ -1231,7 +1239,7 @@ static const char *scriptVars[] = { "man_talk", "man_loc1", "man_loc2", - "man_loc3", + "man_loc3" }; void Debug::fetchCompact(uint32 a) { @@ -1265,4 +1273,183 @@ void Debug::mcode(uint32 mcode, uint32 a, uint32 b, uint32 c) { debug(6, "MCODE: %s(%d, %d, %d)", mcodes[mcode], a, b, c); } + + + +Debugger::Debugger(Logic *logic, Mouse *mouse, Screen *screen) : _logic(logic), _mouse(mouse), _screen(screen), _showGrid(false) { + DCmd_Register("exit", &Debugger::Cmd_Exit); + DCmd_Register("help", &Debugger::Cmd_Help); + DCmd_Register("info", &Debugger::Cmd_Info); + DCmd_Register("showgrid", &Debugger::Cmd_ShowGrid); + DCmd_Register("reloadgrid", &Debugger::Cmd_ReloadGrid); + DCmd_Register("compact", &Debugger::Cmd_ShowCompact); + DCmd_Register("logiccmd", &Debugger::Cmd_LogicCommand); + DCmd_Register("scriptvar", &Debugger::Cmd_ScriptVar); +} + +void Debugger::preEnter() { + +} + +void Debugger::postEnter() { + _mouse->resetCursor(); +} + +bool Debugger::Cmd_Exit(int argc, const char **argv) { + _detach_now = true; + return false; +} + +bool Debugger::Cmd_Help(int argc, const char **argv) { + // console normally has 39 line width + // wrap around nicely + int width = 0, size; + + DebugPrintf("Commands are:\n"); + for (int i = 0; i < _dcmd_count; ++i) { + size = strlen(_dcmds[i].name) + 1; + + if ((width + size) >= 39) { + DebugPrintf("\n"); + width = size; + } else { + width += size; + } + + DebugPrintf("%s ", _dcmds[i].name); + } + DebugPrintf("\n"); + return true; +} + +bool Debugger::Cmd_ShowGrid(int argc, const char **argv) { + _showGrid = !_showGrid; + DebugPrintf("Show grid: %s\n", _showGrid ? "On" : "Off"); + if (!_showGrid) _screen->forceRefresh(); + return true; +} + +bool Debugger::Cmd_ReloadGrid(int argc, const char **argv) { + _logic->_skyGrid->loadGrids(); + DebugPrintf("Grid reloaded\n"); + return true; +} + +bool Debugger::Cmd_ShowCompact(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Example: %s foster\n", argv[0]); + return true; + } + + int i; + int numCompacts = sizeof(section_0_compacts) / sizeof(section_0_compacts[0]); + + if (0 == strcmp(argv[1], "list")) { + for (i = 0; i < numCompacts; ++i) { + DebugPrintf("%s\n", section_0_compacts[i]); + } + return true; + } + + Compact *cpt = 0; + + for (i = 0; i < numCompacts; ++i) { + if (0 == strcmp(section_0_compacts[i], argv[1])) { + cpt = SkyEngine::fetchCompact(i); + break; + } + } + + if (cpt) { + DebugPrintf("------Compact %d ('%s')------\n", i, section_0_compacts[i]); + DebugPrintf("logic : %d\n", cpt->logic); + DebugPrintf("status : %d\n", cpt->status); + DebugPrintf("sync : %d\n", cpt->sync); + DebugPrintf("screen : %d\n", cpt->screen); + DebugPrintf("x/y : %d/%d\n", cpt->xcood, cpt->ycood); + DebugPrintf("getToFlag : %d\n", cpt->getToFlag); + DebugPrintf("mode : %d\n", cpt->mode); + } else { + DebugPrintf("Unknown compact: '%s'\n", argv[1]); + } + + return true; +} + +bool Debugger::Cmd_LogicCommand(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Example: %s fn_printf 42\n", argv[0]); + return true; + } + + int numMCodes = sizeof(mcodes) / sizeof(mcodes[0]); + + if (0 == strcmp(argv[1], "list")) { + for (int i = 0; i < numMCodes; ++i) { + DebugPrintf("%s\n", mcodes[i]); + } + return true; + } + + uint32 arg1 = 0, arg2 = 0, arg3 = 0; + + switch (argc) { + case 5: + arg3 = atoi(argv[4]); + case 4: + arg2 = atoi(argv[3]); + case 3: + arg1 = atoi(argv[2]); + } + + for (int i = 0; i < numMCodes; ++i) { + if (0 == strcmp(mcodes[i], argv[1])) { + _logic->fnExec(i, arg1, arg2, arg3); + return true; + } + } + + DebugPrintf("Unknown function: '%s'\n", argv[1]); + + return true; +} + +bool Debugger::Cmd_Info(int argc, const char **argv) { + DebugPrintf("Beneath a Steel Sky version: 0.0%d\n", SkyEngine::_systemVars.gameVersion); + DebugPrintf("Speech: %s\n", (SkyEngine::_systemVars.systemFlags & SF_ALLOW_SPEECH) ? "on" : "off"); + DebugPrintf("Text : %s\n", (SkyEngine::_systemVars.systemFlags & SF_ALLOW_TEXT) ? "on" : "off"); + return true; +} + +bool Debugger::Cmd_ScriptVar(int argc, const char **argv) { + if (argc < 2) { + DebugPrintf("Example: %s lamb_friend \n", argv[0]); + return true; + } + + int numScriptVars = sizeof(scriptVars) / sizeof(scriptVars[0]); + + if (0 == strcmp(argv[1], "list")) { + for (int i = 0; i < numScriptVars; ++i) { + DebugPrintf("%s\n", scriptVars[i]); + } + return true; + } + + for (int i = 0; i < numScriptVars; ++i) { + if (0 == strcmp(scriptVars[i], argv[1])) { + if (argc == 3) { + Logic::_scriptVariables[i] = atoi(argv[2]); + } + DebugPrintf("%s = %d\n", argv[1], Logic::_scriptVariables[i]); + + return true; + } + } + + DebugPrintf("Unknown ScriptVar: '%s'\n", argv[1]); + + return true; +} + } // End of namespace Sky diff --git a/sky/debug.h b/sky/debug.h index 01a64a245d..a6de197756 100644 --- a/sky/debug.h +++ b/sky/debug.h @@ -24,9 +24,40 @@ #include "stdafx.h" #include "common/scummsys.h" +#include "common/debugger.h" namespace Sky { +class Logic; +class Mouse; +class Screen; + +class Debugger : public Common::Debugger { +public: + Debugger(Logic *logic, Mouse *mouse, Screen *screen); + bool showGrid() { return _showGrid; } + +protected: + virtual void preEnter(); + virtual void postEnter(); + + bool Cmd_Exit(int argc, const char **argv); + bool Cmd_Help(int argc, const char **argv); + bool Cmd_ShowGrid(int argc, const char **argv); + bool Cmd_ReloadGrid(int argc, const char **argv); + bool Cmd_ShowCompact(int argc, const char **argv); + bool Cmd_LogicCommand(int argc, const char **argv); + bool Cmd_Info(int argc, const char **argv); + bool Cmd_ScriptVar(int argc, const char **argv); + + Logic *_logic; + Mouse *_mouse; + Screen *_screen; + + bool _showGrid; +}; + + class Debug { public: static void fetchCompact(uint32 a); diff --git a/sky/logic.cpp b/sky/logic.cpp index d4bc08482b..a6cfcc2192 100644 --- a/sky/logic.cpp +++ b/sky/logic.cpp @@ -1115,6 +1115,10 @@ static const uint32 forwardList5b[] = { DISCONNECT_FOSTER }; +void Logic::fnExec(uint16 num, uint32 a, uint32 b, uint32 c) { + (this->*mcodeTable[num])(a, b, c); +} + void Logic::initScriptVariables() { for (int i = 0; i < ARRAYSIZE(_scriptVariables); i++) _scriptVariables[i] = 0; @@ -2449,7 +2453,7 @@ bool Logic::fnUnPauseFx(uint32 a, uint32 b, uint32 c) { } bool Logic::fnPrintf(uint32 a, uint32 b, uint32 c) { - printf("fnPrintf: %d", a); + printf("fnPrintf: %d\n", a); return true; } diff --git a/sky/logic.h b/sky/logic.h index 499f296c36..391e8ec931 100644 --- a/sky/logic.h +++ b/sky/logic.h @@ -240,6 +240,7 @@ public: bool fnPrintf(uint32 a, uint32 b, uint32 c); void stdSpeak(Compact *target, uint32 textNum, uint32 animNum, uint32 base); + void fnExec(uint16 num, uint32 a, uint32 b, uint32 c); static uint32 _scriptVariables[838]; Grid *_skyGrid; diff --git a/sky/mouse.cpp b/sky/mouse.cpp index 86ef028d01..2bb23dd759 100644 --- a/sky/mouse.cpp +++ b/sky/mouse.cpp @@ -265,6 +265,10 @@ void Mouse::buttonEngine1(void) { } } +void Mouse::resetCursor() { + spriteMouse(_currentCursor, 0, 0); +} + uint16 Mouse::findMouseCursor(uint32 itemNum) { uint8 cnt; diff --git a/sky/mouse.h b/sky/mouse.h index db9698ce31..80b034248d 100644 --- a/sky/mouse.h +++ b/sky/mouse.h @@ -58,7 +58,8 @@ public: uint16 giveCurrentMouseType(void) { return _currentCursor; }; bool wasClicked(void); void logicClick(void) { _logicClick = true; }; - + void resetCursor(); + protected: void pointerEngine(uint16 xPos, uint16 yPos); diff --git a/sky/sky.cpp b/sky/sky.cpp index 9912fccfce..d4f7ddfe5e 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -34,6 +34,7 @@ #include "sky/control.h" #include "sky/debug.h" #include "sky/disk.h" +#include "sky/grid.h" #include "sky/intro.h" #include "sky/logic.h" #include "sky/mouse.h" @@ -76,10 +77,6 @@ extern bool draw_keyboard; #undef WITH_DEBUG_CHEATS -#ifdef WITH_DEBUG_CHEATS -#include "sky/grid.h" -#endif - static const GameSettings skySetting = {"sky", "Beneath a Steel Sky", 0 }; @@ -140,6 +137,7 @@ SkyEngine::~SkyEngine() { delete _skyText; delete _skyMouse; delete _skyScreen; + delete _debugger; } void SkyEngine::errorString(const char *buf1, char *buf2) { @@ -178,6 +176,10 @@ void SkyEngine::doCheat(uint8 num) { void SkyEngine::handleKey(void) { + if (_key_pressed == '`') { + _debugger->attach(); + } + if (_key_pressed == 63) _skyControl->doControlPanel(); @@ -186,11 +188,6 @@ void SkyEngine::handleKey(void) { #ifdef WITH_DEBUG_CHEATS if ((_key_pressed >= '0') && (_key_pressed <= '9')) doCheat(_key_pressed - '0'); - - if (_key_pressed == 'r') { - warning("loading grid"); - _skyLogic->_skyGrid->loadGrids(); - } #endif if (_key_pressed == '.') _skyMouse->logicClick(); @@ -224,6 +221,10 @@ void SkyEngine::go() { _lastSaveTime = _system->get_msecs(); while (1) { + if (_debugger->isAttached()) { + _debugger->onFrame(); + } + if (_fastMode & 2) delay(0); else if (_fastMode & 1) @@ -246,6 +247,8 @@ void SkyEngine::go() { if (!_skyLogic->checkProtection()) { // don't let copy prot. screen flash up _skyScreen->recreate(); _skyScreen->spriteEngine(); + if (_debugger->showGrid()) + _skyScreen->showGrid(_skyLogic->_skyGrid->giveGrid(Logic::_scriptVariables[SCREEN])); _skyScreen->flip(); } } @@ -355,6 +358,8 @@ void SkyEngine::initialise(void) { _quickLaunch = false; _skyMusic->setVolume(ConfMan.getInt("music_volume") >> 1); + + _debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen); } void SkyEngine::initItemList() { @@ -433,7 +438,7 @@ Compact *SkyEngine::fetchCompact(uint32 a) { return (Compact *)(_itemList[119 + sectionNum][compactNum]); } -void SkyEngine::delay(uint amount) { //copied and mutilated from Simon.cpp +void SkyEngine::delay(uint amount) { OSystem::Event event; @@ -487,7 +492,7 @@ void SkyEngine::delay(uint amount) { //copied and mutilated from Simon.cpp break; { - uint this_delay = 20; // 1? + uint this_delay = 20; #ifdef _WIN32_WCE this_delay = 10; #endif diff --git a/sky/sky.h b/sky/sky.h index ed3a28a207..0eee981dea 100644 --- a/sky/sky.h +++ b/sky/sky.h @@ -51,6 +51,7 @@ class Screen; class Control; class MusicBase; class Intro; +class Debugger; class SkyEngine : public Engine { void errorString(const char *buf_input, char *buf_output); @@ -68,7 +69,8 @@ protected: Mouse *_skyMouse; Screen *_skyScreen; Control *_skyControl; - + Debugger *_debugger; + MusicBase *_skyMusic; Intro *_skyIntro; -- cgit v1.2.3