[Scummvm-cvs-logs] SF.net SVN: scummvm:[53821] scummvm/branches/branch-1-2-0/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Oct 25 13:32:23 CEST 2010


Revision: 53821
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53821&view=rev
Author:   thebluegr
Date:     2010-10-25 11:32:23 +0000 (Mon, 25 Oct 2010)

Log Message:
-----------
SCI: Backport of revisions 53646, 53649, 53673, 53743 (find_callk console command, enhancements to the class_table console command, silenced MSVC2010 warning during editing)

Modified Paths:
--------------
    scummvm/branches/branch-1-2-0/engines/sci/console.cpp
    scummvm/branches/branch-1-2-0/engines/sci/console.h
    scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.cpp
    scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.h
    scummvm/branches/branch-1-2-0/engines/sci/engine/kernel_tables.h
    scummvm/branches/branch-1-2-0/engines/sci/engine/segment.h

Modified: scummvm/branches/branch-1-2-0/engines/sci/console.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/console.cpp	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/console.cpp	2010-10-25 11:32:23 UTC (rev 53821)
@@ -166,6 +166,7 @@
 	DCmd_Register("snk",				WRAP_METHOD(Console, cmdStepCallk));	// alias
 	DCmd_Register("disasm",				WRAP_METHOD(Console, cmdDisassemble));
 	DCmd_Register("disasm_addr",		WRAP_METHOD(Console, cmdDisassembleAddress));
+	DCmd_Register("find_callk",			WRAP_METHOD(Console, cmdFindKernelFunctionCall));
 	DCmd_Register("send",				WRAP_METHOD(Console, cmdSend));
 	DCmd_Register("go",					WRAP_METHOD(Console, cmdGo));
 	DCmd_Register("logkernel",          WRAP_METHOD(Console, cmdLogKernel));
@@ -1140,14 +1141,18 @@
 }
 
 bool Console::cmdClassTable(int argc, const char **argv) {
-	DebugPrintf("Available classes:\n");
+	DebugPrintf("Available classes (parse a parameter to filter the table by a specific class):\n");
+
 	for (uint i = 0; i < _engine->_gamestate->_segMan->classTableSize(); i++) {
 		Class temp = _engine->_gamestate->_segMan->_classTable[i];
 		if (temp.reg.segment) {
-			DebugPrintf(" Class 0x%x (%s) at %04x:%04x (script 0x%x)\n", i,
-					_engine->_gamestate->_segMan->getObjectName(temp.reg),
-					PRINT_REG(temp.reg),
-					temp.script);
+			const char *className = _engine->_gamestate->_segMan->getObjectName(temp.reg);
+			if (argc == 1 || (argc == 2 && !strcmp(className, argv[1]))) {
+				DebugPrintf(" Class 0x%x (%s) at %04x:%04x (script %d)\n", i,
+						className,
+						PRINT_REG(temp.reg),
+						temp.script);
+			}
 		}
 	}
 
@@ -2624,11 +2629,88 @@
 	return true;
 }
 
+bool Console::cmdFindKernelFunctionCall(int argc, const char **argv) {
+	if (argc < 2) {
+		DebugPrintf("Finds the scripts and methods that call a specific kernel function.\n");
+		DebugPrintf("Usage: %s <kernel function>\n", argv[0]);
+		DebugPrintf("Example: %s Display\n", argv[0]);
+		return true;
+	}
+
+	// Find the number of the kernel function call
+	int kernelFuncNum = _engine->getKernel()->findKernelFuncPos(argv[1]);
+
+	if (kernelFuncNum < 0) {
+		DebugPrintf("Invalid kernel function requested");
+		return true;
+	}
+
+	Common::List<ResourceId> *resources = _engine->getResMan()->listResources(kResourceTypeScript);
+	Common::sort(resources->begin(), resources->end());
+	Common::List<ResourceId>::iterator itr = resources->begin();
+
+	DebugPrintf("%d scripts found, dissassembling...\n", resources->size());
+
+	int scriptSegment;
+	Script *script;
+	SegManager *segMan = _engine->getEngineState()->_segMan;
+
+	while (itr != resources->end()) {
+		// Load script
+		scriptSegment = segMan->instantiateScript(itr->getNumber());
+		script = segMan->getScript(scriptSegment);
+
+		// Iterate through all the script's objects
+		ObjMap::iterator it;
+		const ObjMap::iterator end = script->_objects.end();
+		for (it = script->_objects.begin(); it != end; ++it) {
+			const Object *obj = segMan->getObject(it->_value.getPos());
+			const char *objName = segMan->getObjectName(it->_value.getPos());
+
+			// Now dissassemble each method of the script object
+			for (uint16 i = 0; i < obj->getMethodCount(); i++) {
+				reg_t fptr = obj->getFunction(i);
+				uint16 offset = fptr.offset;
+				int16 opparams[4];
+				byte extOpcode;
+				byte opcode;
+
+				while (true) {
+					offset += readPMachineInstruction(script->getBuf(offset), extOpcode, opparams);
+					opcode = extOpcode >> 1;
+
+					if (opcode == op_callk) {
+						uint16 kFuncNum = opparams[0];
+						uint16 argc2 = opparams[1];
+
+						if (kFuncNum == kernelFuncNum) {
+							DebugPrintf("Called from script %d, object %s, method %s(%d) with %d parameters\n", 
+								itr->getNumber(), objName, 
+								_engine->getKernel()->getSelectorName(obj->getFuncSelector(i)).c_str(), i, argc2);
+						}
+					}
+
+					// Check for end of function/script
+					if (opcode == op_ret || offset >= script->getBufSize())
+						break;
+				}	// while (true)
+			}	// for (uint16 i = 0; i < obj->getMethodCount(); i++)
+		}	// for (it = script->_objects.begin(); it != end; ++it)
+
+		segMan->uninstantiateScript(itr->getNumber());
+		++itr;
+	}
+
+	delete resources;
+
+	return true;
+}
+
 bool Console::cmdSend(int argc, const char **argv) {
 	if (argc < 3) {
 		DebugPrintf("Sends a message to an object.\n");
 		DebugPrintf("Usage: %s <object> <selector name> <param1> <param2> ... <paramn>\n", argv[0]);
-		DebugPrintf("Example: send ?fooScript cue\n");
+		DebugPrintf("Example: %s ?fooScript cue\n", argv[0]);
 		return true;
 	}
 

Modified: scummvm/branches/branch-1-2-0/engines/sci/console.h
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/console.h	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/console.h	2010-10-25 11:32:23 UTC (rev 53821)
@@ -128,6 +128,7 @@
 	bool cmdStepCallk(int argc, const char **argv);
 	bool cmdDisassemble(int argc, const char **argv);
 	bool cmdDisassembleAddress(int argc, const char **argv);
+	bool cmdFindKernelFunctionCall(int argc, const char **argv);
 	bool cmdSend(int argc, const char **argv);
 	bool cmdGo(int argc, const char **argv);
 	bool cmdLogKernel(int argc, const char **argv);

Modified: scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.cpp	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.cpp	2010-10-25 11:32:23 UTC (rev 53821)
@@ -88,6 +88,14 @@
 	return _kernelNames[number];
 }
 
+int Kernel::findKernelFuncPos(Common::String kernelFuncName) {
+	for (uint32 i = 0; i < _kernelNames.size(); i++)
+		if (_kernelNames[i] == kernelFuncName)
+			return i;
+
+	return -1;
+}
+
 int Kernel::findSelector(const char *selectorName) const {
 	for (uint pos = 0; pos < _selectorNames.size(); ++pos) {
 		if (_selectorNames[pos] == selectorName)

Modified: scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.h
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.h	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/engine/kernel.h	2010-10-25 11:32:23 UTC (rev 53821)
@@ -151,6 +151,7 @@
 
 	uint getSelectorNamesSize() const;
 	const Common::String &getSelectorName(uint selector);
+	int findKernelFuncPos(Common::String kernelFuncName);
 
 	uint getKernelNamesSize() const;
 	const Common::String &getKernelName(uint number) const;

Modified: scummvm/branches/branch-1-2-0/engines/sci/engine/kernel_tables.h
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/engine/kernel_tables.h	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/engine/kernel_tables.h	2010-10-25 11:32:23 UTC (rev 53821)
@@ -27,6 +27,7 @@
 #define SCI_ENGINE_KERNEL_TABLES_H
 
 #include "sci/engine/workarounds.h"
+#include "sci/engine/vm.h"	// for opcode_formats
 
 namespace Sci {
 

Modified: scummvm/branches/branch-1-2-0/engines/sci/engine/segment.h
===================================================================
--- scummvm/branches/branch-1-2-0/engines/sci/engine/segment.h	2010-10-25 11:19:44 UTC (rev 53820)
+++ scummvm/branches/branch-1-2-0/engines/sci/engine/segment.h	2010-10-25 11:32:23 UTC (rev 53821)
@@ -246,7 +246,7 @@
 	reg_t getInfoSelector() const { return _variables[_offset + 2]; }
 	void setInfoSelector(reg_t value) { _variables[_offset + 2] = value; }
 
-	reg_t getNameSelector() const { return _variables[_offset + 3]; }
+	reg_t getNameSelector() const { return _offset + 3 < (uint16)_variables.size() ? _variables[_offset + 3] : NULL_REG; }
 	void setNameSelector(reg_t value) { _variables[_offset + 3] = value; }
 
 	reg_t getPropDictSelector() const { return _variables[2]; }


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