[Scummvm-cvs-logs] CVS: scummvm/sky debug.cpp,1.10,1.11 debug.h,1.5,1.6 logic.cpp,1.143,1.144 logic.h,1.37,1.38 mouse.cpp,1.33,1.34 mouse.h,1.25,1.26 sky.cpp,1.147,1.148 sky.h,1.59,1.60

Joost Peters joostp at users.sourceforge.net
Mon Sep 13 10:06:31 CEST 2004


Update of /cvsroot/scummvm/scummvm/sky
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30932/sky

Modified Files:
	debug.cpp debug.h logic.cpp logic.h mouse.cpp mouse.h sky.cpp 
	sky.h 
Log Message:
Add debugger for BASS.
This should help in tracking down remaining bugs, such as the grid problems and walk deadlocks.


Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/debug.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- debug.cpp	6 Jan 2004 12:45:32 -0000	1.10
+++ debug.cpp	13 Sep 2004 17:05:22 -0000	1.11
@@ -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 @@
 	"exit_seq",
 	"forklift_cpt",
 	"forklift1_cdt",
-	"forklift2_cdt",
+	"forklift2_cdt"
 };
 
 static const char *logic_table_names[] = {
@@ -225,7 +233,7 @@
 	"Logic::frames",
 	"Logic::pause",
 	"Logic::wait_sync",
-	"Logic::simple_anim",
+	"Logic::simple_anim"
 };
 
 static const char opcode_par[] = {
@@ -249,7 +257,7 @@
 	0,
 	1,
 	0,
-	0,
+	0
 };
 
 static const char *opcodes[] = {
@@ -273,7 +281,7 @@
 	"is_equal",
 	"skip_nz",
 	"script_exit",
-	"restart_script",
+	"restart_script"
 };
 
 static const char *mcodes[] = {
@@ -391,7 +399,7 @@
 	"fn_quit_to_dos",
 	"fn_pause_fx",
 	"fn_un_pause_fx",
-	"fn_printf",
+	"fn_printf"
 };
 
 static const char *scriptVars[] = {
@@ -1231,7 +1239,7 @@
 	"man_talk",
 	"man_loc1",
 	"man_loc2",
-	"man_loc3",
+	"man_loc3"
 };
 
 void Debug::fetchCompact(uint32 a) {
@@ -1265,4 +1273,183 @@
 	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 <value>\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

Index: debug.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/debug.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- debug.h	6 Jan 2004 12:45:32 -0000	1.5
+++ debug.h	13 Sep 2004 17:05:23 -0000	1.6
@@ -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<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);

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/logic.cpp,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- logic.cpp	14 Aug 2004 09:10:14 -0000	1.143
+++ logic.cpp	13 Sep 2004 17:05:23 -0000	1.144
@@ -1115,6 +1115,10 @@
 	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::fnPrintf(uint32 a, uint32 b, uint32 c) {
-	printf("fnPrintf: %d", a);
+	printf("fnPrintf: %d\n", a);
 	return true;
 }
 

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/logic.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- logic.h	6 Jan 2004 12:45:32 -0000	1.37
+++ logic.h	13 Sep 2004 17:05:23 -0000	1.38
@@ -240,6 +240,7 @@
 	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;

Index: mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/mouse.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- mouse.cpp	20 Aug 2004 13:37:49 -0000	1.33
+++ mouse.cpp	13 Sep 2004 17:05:23 -0000	1.34
@@ -265,6 +265,10 @@
 	}
 }
 
+void Mouse::resetCursor() {
+	spriteMouse(_currentCursor, 0, 0);
+}
+
 uint16 Mouse::findMouseCursor(uint32 itemNum) {
 
 	uint8 cnt;

Index: mouse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/mouse.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mouse.h	6 May 2004 00:25:18 -0000	1.25
+++ mouse.h	13 Sep 2004 17:05:23 -0000	1.26
@@ -58,7 +58,8 @@
 	uint16 giveCurrentMouseType(void) { return _currentCursor; };
 	bool wasClicked(void);
 	void logicClick(void) { _logicClick = true; };
-
+	void resetCursor();
+	
 protected:
 
 	void pointerEngine(uint16 xPos, uint16 yPos);

Index: sky.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.cpp,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- sky.cpp	28 Aug 2004 14:45:52 -0000	1.147
+++ sky.cpp	13 Sep 2004 17:05:23 -0000	1.148
@@ -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 @@
 
 #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 @@
 	delete _skyText;
 	delete _skyMouse;
 	delete _skyScreen;
+	delete _debugger;
 }
 
 void SkyEngine::errorString(const char *buf1, char *buf2) {
@@ -178,6 +176,10 @@
 
 void SkyEngine::handleKey(void) {
 
+	if (_key_pressed == '`') {
+		_debugger->attach();
+	}
+	
 	if (_key_pressed == 63)
 		_skyControl->doControlPanel();
 
@@ -186,11 +188,6 @@
 #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 @@
 	_lastSaveTime = _system->get_msecs();
 
 	while (1) {
+		if (_debugger->isAttached()) {
+			_debugger->onFrame();
+		}
+			
 		if (_fastMode & 2)
 			delay(0);
 		else if (_fastMode & 1)
@@ -246,6 +247,8 @@
 		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 @@
 		_quickLaunch = false;
 
 	_skyMusic->setVolume(ConfMan.getInt("music_volume") >> 1);
+
+	_debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen);
 }
 
 void SkyEngine::initItemList() {
@@ -433,7 +438,7 @@
 	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 @@
 			break;
 
 		{
-			uint this_delay = 20; // 1?
+			uint this_delay = 20;
 #ifdef _WIN32_WCE
 			this_delay = 10;
 #endif

Index: sky.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sky/sky.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- sky.h	20 Aug 2004 13:42:43 -0000	1.59
+++ sky.h	13 Sep 2004 17:05:23 -0000	1.60
@@ -51,6 +51,7 @@
 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 @@
 	Mouse *_skyMouse;
 	Screen *_skyScreen;
 	Control *_skyControl;
-
+	Debugger *_debugger;
+	
 	MusicBase *_skyMusic;
 	Intro *_skyIntro;
 	





More information about the Scummvm-git-logs mailing list