[Scummvm-cvs-logs] SF.net SVN: scummvm:[42062] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Jul 3 16:22:50 CEST 2009


Revision: 42062
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42062&view=rev
Author:   thebluegr
Date:     2009-07-03 14:22:50 +0000 (Fri, 03 Jul 2009)

Log Message:
-----------
- Pushed debugstate into debug.h
- When an error occurs, manipulate the execution stack before error() opens the console inside getDebugger(), like FreeSCI did. Added another method for obtaining the SCI console for use by the engine itself.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/console.h
    scummvm/trunk/engines/sci/debug.h
    scummvm/trunk/engines/sci/engine/grammar.cpp
    scummvm/trunk/engines/sci/engine/kevent.cpp
    scummvm/trunk/engines/sci/engine/kmisc.cpp
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/gfx/operations.cpp
    scummvm/trunk/engines/sci/sci.cpp
    scummvm/trunk/engines/sci/sci.h
    scummvm/trunk/engines/sci/tools.cpp
    scummvm/trunk/engines/sci/vocabulary.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/console.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -50,7 +50,6 @@
 int g_debug_simulated_key = 0;
 bool g_debug_track_mouse_clicks = false;
 bool g_debug_weak_validations = true;
-extern DebugState debugState;
 
 Console::Console(SciEngine *vm) : GUI::Debugger() {
 	_vm = vm;
@@ -1598,7 +1597,7 @@
 
 void _print_address(void * _, reg_t addr) {
 	if (addr.segment)
-		((SciEngine *)g_engine)->getDebugger()->DebugPrintf("  %04x:%04x\n", PRINT_REG(addr));
+		((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("  %04x:%04x\n", PRINT_REG(addr));
 }
 
 bool Console::cmdGCShowReachable(int argc, const char **argv) {

Modified: scummvm/trunk/engines/sci/console.h
===================================================================
--- scummvm/trunk/engines/sci/console.h	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/console.h	2009-07-03 14:22:50 UTC (rev 42062)
@@ -154,6 +154,7 @@
 
 private:
 	SciEngine *_vm;
+	bool _mouseVisible;
 };
 
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/debug.h
===================================================================
--- scummvm/trunk/engines/sci/debug.h	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/debug.h	2009-07-03 14:22:50 UTC (rev 42062)
@@ -28,12 +28,6 @@
 
 namespace Sci {
 
-// Various global variables used for debugging are declared here
-extern int g_debug_sleeptime_factor;
-extern int g_debug_simulated_key;
-extern bool g_debug_track_mouse_clicks;
-extern bool g_debug_weak_validations;
-
 enum DebugSeeking {
 	kDebugSeekNothing = 0,
 	kDebugSeekCallk = 1,        // Step forward until callk is found
@@ -50,6 +44,8 @@
 	int runningStep;			// Set to > 0 to allow multiple stepping
 	int seekLevel;				// Used for seekers that want to check their exec stack depth
 	int seekSpecial;			// Used for special seeks
+	int old_pc_offset;
+	StackPtr old_sp;
 	reg_t *p_pc;
 	StackPtr *p_sp;
 	StackPtr *p_pp;
@@ -61,6 +57,13 @@
 	int *p_var_max;				// May be NULL even in valid state!
 };
 
+// Various global variables used for debugging are declared here
+extern int g_debug_sleeptime_factor;
+extern int g_debug_simulated_key;
+extern bool g_debug_track_mouse_clicks;
+extern bool g_debug_weak_validations;
+extern DebugState debugState;
+
 } // End of namespace Sci
 
 #endif

Modified: scummvm/trunk/engines/sci/engine/grammar.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/grammar.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/engine/grammar.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -351,7 +351,7 @@
 	int ntrules_nr;
 	parse_rule_list_t *ntlist = NULL;
 	parse_rule_list_t *tlist, *new_tlist;
-	GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+	Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 
 	for (uint i = 1; i < _parserBranches.size(); i++) { // branch rule 0 is treated specially
 		parse_rule_t *rule = _vbuild_rule(&_parserBranches[i]);
@@ -477,7 +477,7 @@
 }
 
 int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words, bool verbose) {
-	GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+	Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 	// Get the start rules:
 	parse_rule_list_t *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]);
 	parse_rule_list_t *results = NULL;

Modified: scummvm/trunk/engines/sci/engine/kevent.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kevent.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/engine/kevent.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -33,8 +33,6 @@
 
 namespace Sci {
 
-extern DebugState debugState;
-
 #define SCI_VARIABLE_GAME_SPEED 3
 
 reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
@@ -112,7 +110,7 @@
 
 		// track left buttton clicks, if requested
 		if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && g_debug_track_mouse_clicks) {
-			((SciEngine *)g_engine)->getDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", 
+			((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", 
 						s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y);
 		}
 
@@ -143,7 +141,7 @@
 		debugState.stopOnEvent = false;
 
 		// A SCI event occured, and we have been asked to stop, so open the debug console
-		GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger();
+		Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
 		con->DebugPrintf("SCI event occured: ");
 		switch (e.type) {
 		case SCI_EVT_QUIT:

Modified: scummvm/trunk/engines/sci/engine/kmisc.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmisc.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/engine/kmisc.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -93,8 +93,6 @@
 	return s->r_acc;
 }
 
-extern DebugState debugState;
-
 reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
 	sciprintf("Debug mode activated\n");
 

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -49,7 +49,6 @@
 int script_abort_flag = 0; // Set to 1 to abort execution. Set to 2 to force a replay afterwards	// FIXME: Avoid non-const global vars
 int script_step_counter = 0; // Counts the number of steps executed	// FIXME: Avoid non-const global vars
 int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs	// FIXME: Avoid non-const global vars
-extern DebugState debugState;
 
 static bool breakpointFlag = false;	// FIXME: Avoid non-const global vars
 static reg_t _dummy_register;		// FIXME: Avoid non-const global vars
@@ -606,14 +605,12 @@
 
 	while (1) {
 		byte opcode;
-		int old_pc_offset;
-		StackPtr old_sp;
 		byte opnumber;
 		int var_type; // See description below
 		int var_number;
 
-		old_pc_offset = xs->addr.pc.offset;
-		old_sp = xs->sp;
+		debugState.old_pc_offset = xs->addr.pc.offset;
+		debugState.old_sp = xs->sp;
 
 		if (s->_executionStackPosChanged) {
 			Script *scr;
@@ -1424,16 +1421,7 @@
 					opnumber);
 		}
 //#endif
-
-#if 0
-		if (script_error_flag) {
-			debugState.runningStep = 0; // Stop multiple execution
-			debugState.seeking = 0; // Stop special seeks
-			xs->addr.pc.offset = old_pc_offset;
-			xs->sp = old_sp;
-		} else
-#endif
-			++script_step_counter;
+		++script_step_counter;
 	}
 }
 

Modified: scummvm/trunk/engines/sci/gfx/operations.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/operations.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/gfx/operations.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -1418,8 +1418,9 @@
 			// Debug console
 			if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {	
 				// Open debug console
-				((Sci::SciEngine*)g_engine)->getDebugger()->attach();
-				((Sci::SciEngine*)g_engine)->getDebugger()->onFrame();
+				Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
+				con->attach();
+				con->onFrame();
 
 				// Clear keyboard event
 				input.type = SCI_EVT_NONE;

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/sci.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -29,6 +29,7 @@
 
 #include "engines/advancedDetector.h"
 #include "sci/sci.h"
+#include "sci/debug.h"
 #include "sci/console.h"
 
 #include "sci/engine/state.h"
@@ -254,10 +255,22 @@
 	return Common::kNoError;
 }
 
+// Invoked by error() when a severe error occurs
 GUI::Debugger *SciEngine::getDebugger() {
+	ExecStack *xs = &(_gamestate->_executionStack.back());
+	debugState.runningStep = 0; // Stop multiple execution
+	debugState.seeking = kDebugSeekNothing; // Stop special seeks
+	xs->addr.pc.offset = debugState.old_pc_offset;
+	xs->sp = debugState.old_sp;
+
 	return _console;
 }
 
+// Used to obtain the engine's console in order to print messages to it
+Console *SciEngine::getSciDebugger() {
+	return _console;
+}
+
 const char* SciEngine::getGameID() const {
 	return _gameDescription->desc.gameid;
 }

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/sci.h	2009-07-03 14:22:50 UTC (rev 42062)
@@ -142,6 +142,7 @@
 	virtual Common::Error run();
 	void pauseEngineIntern(bool pause);
 	virtual GUI::Debugger *getDebugger();
+	Console *getSciDebugger();
 
 	const char* getGameID() const;
 	int getResourceVersion() const;

Modified: scummvm/trunk/engines/sci/tools.cpp
===================================================================
--- scummvm/trunk/engines/sci/tools.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/tools.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -70,7 +70,7 @@
 
 	// Display the result suitably
 	if (g_redirect_sciprintf_to_gui)
-		((SciEngine *)g_engine)->getDebugger()->DebugPrintf("%s", buf);
+		((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("%s", buf);
 	printf("%s", buf);
 
 	free(buf);

Modified: scummvm/trunk/engines/sci/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/vocabulary.cpp	2009-07-03 14:21:31 UTC (rev 42061)
+++ scummvm/trunk/engines/sci/vocabulary.cpp	2009-07-03 14:22:50 UTC (rev 42062)
@@ -438,7 +438,7 @@
 
 void Vocabulary::printSuffixes() const {
 	char word_buf[256], alt_buf[256];
-	GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+	Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 
 	int i = 0;
 	for (SuffixList::const_iterator suf = _parserSuffixes.begin(); suf != _parserSuffixes.end(); ++suf) {
@@ -453,7 +453,7 @@
 }
 
 void Vocabulary::printParserWords() const {
-	GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+	Console *con = ((SciEngine *)g_engine)->getSciDebugger();
 
 	int j = 0;
 	for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list