[Scummvm-cvs-logs] SF.net SVN: scummvm: [32167] scummvm/trunk/engines/made

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun May 18 12:57:59 CEST 2008


Revision: 32167
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32167&view=rev
Author:   thebluegr
Date:     2008-05-18 03:57:58 -0700 (Sun, 18 May 2008)

Log Message:
-----------
Rewrote the MADE script dumper, hopefully in a more efficient way

Modified Paths:
--------------
    scummvm/trunk/engines/made/script.cpp
    scummvm/trunk/engines/made/script.h
    scummvm/trunk/engines/made/scriptfuncs.h

Modified: scummvm/trunk/engines/made/script.cpp
===================================================================
--- scummvm/trunk/engines/made/script.cpp	2008-05-18 08:04:12 UTC (rev 32166)
+++ scummvm/trunk/engines/made/script.cpp	2008-05-18 10:57:58 UTC (rev 32167)
@@ -175,6 +175,9 @@
 	_functions = new ScriptFunctions(_vm);
 	_functions->setupExternalsTable();
 	
+	// set to true to dump scripts instead of parsing them
+	_dumpScripts = false;
+
 #undef COMMAND
 }
 
@@ -194,7 +197,7 @@
 	while (!_vm->_quit) {
 		byte opcode = readByte();
 		if (opcode >= 1 && opcode <= _commandsMax) {
-			debug(4, "[%04X:%04X] opcode = %s", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc);
+			debug(4, "[%04X:%04X] %s", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc);
 			(this->*_commands[opcode - 1].proc)();
 		} else {
 			warning("ScriptInterpreter::runScript(%d) Unknown opcode %02X", _runningScriptObjectIndex, opcode);
@@ -202,61 +205,6 @@
 	}
 }
 
-void ScriptInterpreter::dumpScript(int16 scriptObjectIndex) {
-	_codeBase = _vm->_dat->getObject(scriptObjectIndex)->getData();
-	_codeIp = _codeBase;
-	int16 val = 0;
-
-	// TODO: script size
-	while (true) {
-		byte opcode = readByte();
-		if (opcode >= 1 && opcode <= _commandsMax) {
-			printf("[%04X:%04X] %s\n", _runningScriptObjectIndex, (uint) (_codeIp - _codeBase), _commands[opcode - 1].desc);
-			//(this->*_commands[opcode - 1].proc)();
-
-			// Handle command data
-			if (!strcmp(_commands[opcode - 1].desc, "cmd_branchTrue") ||
-				!strcmp(_commands[opcode - 1].desc, "cmd_branchFalse") ||
-				!strcmp(_commands[opcode - 1].desc, "cmd_branch")) {
-				val = readInt16();
-				printf("Offset = %04X\n", val);
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_loadConstant")) {
-				val = readInt16();
-				printf("Constant = %04X\n", val);
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_loadVariable")) {
-				val = readInt16();
-				printf("Variable = %04X\n", val);
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_set")) {
-				val = readInt16();
-				printf("Variable = %04X\n", val);
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_call")) {
-				/*byte argc = */readByte();
-				// TODO
-				printf("TODO\n");
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_arg") ||
-					   !strcmp(_commands[opcode - 1].desc, "cmd_aset") ||
-					   !strcmp(_commands[opcode - 1].desc, "cmd_tmp") ||
-					   !strcmp(_commands[opcode - 1].desc, "cmd_tset") ||
-					   !strcmp(_commands[opcode - 1].desc, "cmd_tspace")) {
-				val = readByte();
-				printf("argIndex = %d\n", val);
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_send")) {
-				/*byte argc = */readByte();
-				// TODO
-				printf("TODO\n");
-			} else if (!strcmp(_commands[opcode - 1].desc, "cmd_extend")) {
-				/*byte func = */readByte();
-
-				/*byte argc = */readByte();
-				// TODO
-				printf("TODO\n");
-			}
-		} else {
-			warning("ScriptInterpreter::runScript(%d) Unknown opcode %02X", _runningScriptObjectIndex, opcode);
-		}
-	}
-}
-
 byte ScriptInterpreter::readByte() {
 	return *_codeIp++;
 }
@@ -269,18 +217,27 @@
 }
 
 void ScriptInterpreter::cmd_branchTrue() {
+	if (_dumpScripts)
+		return;
+
 	int16 ofs = readInt16();
 	if (_stack.top() != 0)
 		_codeIp = _codeBase + ofs;
 }
 
 void ScriptInterpreter::cmd_branchFalse() {
+	if (_dumpScripts)
+		return;
+
 	int16 ofs = readInt16();
 	if (_stack.top() == 0)
 		_codeIp = _codeBase + ofs;
 }
 
 void ScriptInterpreter::cmd_branch() {
+	if (_dumpScripts)
+		return;
+
 	int16 ofs = readInt16();
 	_codeIp = _codeBase + ofs;
 }
@@ -474,6 +431,9 @@
 		return;
 	}
 
+	if (_dumpScripts)
+		return;
+
 	int16 funcResult = _stack.top();
 	_stack.setStackPos(_localStackPos);
 	_localStackPos = kScriptStackLimit - _stack.pop();
@@ -489,6 +449,10 @@
 void ScriptInterpreter::cmd_call() {
 	debug(4, "\nENTER: stackPtr = %d; _localStackPos = %d", _stack.getStackPos(), _localStackPos);
 	byte argc = readByte();
+
+	if (_dumpScripts)
+		return;
+
 	_stack.push(argc);
 	_stack.push(_codeIp - _codeBase);
 	_stack.push(_runningScriptObjectIndex);
@@ -521,6 +485,9 @@
 }
 
 void ScriptInterpreter::cmd_save() {
+	if (_dumpScripts)
+		return;
+
 	int16 result = 0;
 	int16 stringOfs = _stack.top();
 	const char *filename = _vm->_dat->getString(stringOfs);
@@ -529,6 +496,9 @@
 }
 
 void ScriptInterpreter::cmd_restore() {
+	if (_dumpScripts)
+		return;
+
 	int16 result = 0;
 	int16 stringOfs = _stack.top();
 	const char *filename = _vm->_dat->getString(stringOfs);
@@ -603,6 +573,9 @@
 	
 	debug(4, "argc = %d", argc);
 	
+	if (_dumpScripts)
+		return;
+
 	_stack.push(argc);
 	_stack.push(_codeIp - _codeBase);
 	_stack.push(_runningScriptObjectIndex);
@@ -645,11 +618,13 @@
 	byte argc = readByte();
 	int16 *argv = _stack.getStackPtr();
 
-	//debug(4, "func = %d (%s); argc = %d", func, extendFuncNames[func], argc);
-	debug(2, "func = %d; argc = %d", func, argc);
+	debug(4, "func = %d (%s); argc = %d", func, _functions->getFuncName(func), argc);
 	for (int i = 0; i < argc; i++)
 		debug(2, "argv[%02d] = %04X (%d)", i, argv[i], argv[i]);
 
+	if (_dumpScripts)
+		return;
+
 	int16 result = _functions->callFunction(func, argc, argv);
 	debug(2, "result = %04X (%d)", result, result);
 	

Modified: scummvm/trunk/engines/made/script.h
===================================================================
--- scummvm/trunk/engines/made/script.h	2008-05-18 08:04:12 UTC (rev 32166)
+++ scummvm/trunk/engines/made/script.h	2008-05-18 10:57:58 UTC (rev 32167)
@@ -63,7 +63,6 @@
 	ScriptInterpreter(MadeEngine *vm);
 	~ScriptInterpreter();
 	void runScript(int16 scriptObjectIndex);
-	void dumpScript(int16 scriptObjectIndex);
 protected:
 	MadeEngine *_vm;
 
@@ -72,6 +71,7 @@
 	int16 _runningScriptObjectIndex;
 	byte *_codeBase, *_codeIp;
 	bool _terminated;
+	bool _dumpScripts;
 
 	ScriptFunctions *_functions;
 

Modified: scummvm/trunk/engines/made/scriptfuncs.h
===================================================================
--- scummvm/trunk/engines/made/scriptfuncs.h	2008-05-18 08:04:12 UTC (rev 32166)
+++ scummvm/trunk/engines/made/scriptfuncs.h	2008-05-18 10:57:58 UTC (rev 32167)
@@ -53,6 +53,7 @@
 		return (*_externalFuncs[index])(argc, argv);
 	}
 	void setupExternalsTable();
+	const char* getFuncName(int index) { return _externalFuncNames[index]; }
 protected:
 	MadeEngine *_vm;
 	Audio::SoundHandle _audioStreamHandle;


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