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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Jun 18 01:13:54 CEST 2010


Revision: 49967
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49967&view=rev
Author:   fingolfin
Date:     2010-06-17 23:13:54 +0000 (Thu, 17 Jun 2010)

Log Message:
-----------
SCI: Remove hack related to compiled kernel signatures.

Also change some things to comply to our code formatting conventions.

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kernel.h
    scummvm/trunk/engines/sci/engine/vm.cpp

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2010-06-17 23:13:30 UTC (rev 49966)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2010-06-17 23:13:54 UTC (rev 49967)
@@ -201,11 +201,11 @@
 
 struct SciKernelFunction {
 	const char *name;
-	KernelFunc *fun; /* The actual function */
+	KernelFunc *func; /* The actual function */
 	const char *signature;  /* kfunct signature */
 };
 
-SciKernelFunction kfunct_mappers[] = {
+static SciKernelFunction s_kernelFuncMap[] = {
 	/*00*/	{ "Load", kLoad, "iii*" },
 	/*01*/	{ "UnLoad", kUnLoad, "i.*" },	// Work around SQ1 bug, when exiting the Ulence flats bar
 	/*02*/	{ "ScriptID", kScriptID, "Ioi*" },
@@ -418,10 +418,7 @@
 
 Kernel::~Kernel() {
 	for (KernelFuncsContainer::iterator i = _kernelFuncs.begin(); i != _kernelFuncs.end(); ++i)
-		// TODO: Doing a const_cast is not that nice actually... But since KernelFuncWithSignature
-		// keeps the signature member as "const char *" there is no way around it.
-		// Think of a clever way to avoid this.
-		free(const_cast<char *>(i->signature));
+		free(i->signature);
 }
 
 uint Kernel::getSelectorNamesSize() const {
@@ -498,23 +495,23 @@
 	}
 }
 
-static void kernel_compile_signature(const char **s) {
-	const char *src = *s;
+static char *compileKernelSignature(const char *s) {
+	const char *src = s;
 	char *result;
 	bool ellipsis = false;
 	int index = 0;
 
 	if (!src)
-		return; // NULL signature: Nothing to do
+		return 0; // NULL signature: Nothing to do
 
-	result = (char *)malloc(strlen(*s) + 1);
+	result = (char *)malloc(strlen(s) + 1);
 
 	while (*src) {
 		char c;
 		char v = 0;
 
 		if (ellipsis) {
-			error("Failed compiling kernel function signature '%s': non-terminal ellipsis '%c'", *s, *src);
+			error("Failed compiling kernel function signature '%s': non-terminal ellipsis '%c'", s, *src);
 		}
 
 		do {
@@ -558,7 +555,7 @@
 				break;
 
 			default:
-				error("ERROR compiling kernel function signature '%s': (%02x / '%c') not understood", *s, c, c);
+				error("ERROR compiling kernel function signature '%s': (%02x / '%c') not understood", s, c, c);
 			}
 		} while (*src && (*src == KSIG_SPEC_ELLIPSIS || (c < 'a' && c != KSIG_SPEC_ANY)));
 
@@ -567,7 +564,8 @@
 	}
 
 	result[index] = 0;
-	*s = result; // Write back
+
+	return result;
 }
 
 void Kernel::mapFunctions() {
@@ -584,9 +582,9 @@
 		Common::String sought_name = _kernelNames[functnr];
 
 		// Reset the table entry
-		_kernelFuncs[functnr].fun = NULL;
+		_kernelFuncs[functnr].func = NULL;
 		_kernelFuncs[functnr].signature = NULL;
-		_kernelFuncs[functnr].orig_name = sought_name;
+		_kernelFuncs[functnr].origName = sought_name;
 
 		if (sought_name.empty()) {
 			// No name was given -> must be an unknown opcode
@@ -601,10 +599,10 @@
 			continue;
 		}
 
-		// If the name is known, look it up in kfunct_mappers. This table
+		// If the name is known, look it up in s_kernelFuncMap. This table
 		// maps kernel func names to actual function (pointers).
-		for (uint seeker = 0; (found == -1) && kfunct_mappers[seeker].name; seeker++)
-			if (sought_name == kfunct_mappers[seeker].name)
+		for (uint seeker = 0; (found == -1) && s_kernelFuncMap[seeker].name; seeker++)
+			if (sought_name == s_kernelFuncMap[seeker].name)
 				found = seeker; // Found a kernel function with the correct name!
 
 		if (found == -1) {
@@ -612,15 +610,14 @@
 			warning("Kernel function %s[%x] unmapped", sought_name.c_str(), functnr);
 			_kernelFuncs[functnr].isDummy = true;
 		} else {
-			// A match in kfunct_mappers was found
-			if (kfunct_mappers[found].fun) {
-				_kernelFuncs[functnr].fun = kfunct_mappers[found].fun;
-				_kernelFuncs[functnr].signature = kfunct_mappers[found].signature;
+			// A match in s_kernelFuncMap was found
+			if (s_kernelFuncMap[found].func) {
+				_kernelFuncs[functnr].func = s_kernelFuncMap[found].func;
+				_kernelFuncs[functnr].signature = compileKernelSignature(s_kernelFuncMap[found].signature);
 				_kernelFuncs[functnr].isDummy = false;
-				kernel_compile_signature(&(_kernelFuncs[functnr].signature));
 				++mapped;
 			} else {
-				//warning("Ignoring function %s\n", kfunct_mappers[found].name);
+				//warning("Ignoring function %s\n", s_kernelFuncMap[found].name);
 				++ignored;
 			}
 		}

Modified: scummvm/trunk/engines/sci/engine/kernel.h
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.h	2010-06-17 23:13:30 UTC (rev 49966)
+++ scummvm/trunk/engines/sci/engine/kernel.h	2010-06-17 23:13:54 UTC (rev 49967)
@@ -115,9 +115,9 @@
 typedef reg_t KernelFunc(EngineState *s, int argc, reg_t *argv);
 
 struct KernelFuncWithSignature {
-	KernelFunc *fun; /**< The actual function */
-	const char *signature;  /**< KernelFunc signature */
-	Common::String orig_name; /**< Original name, in case we couldn't map it */
+	KernelFunc *func; /**< The actual function */
+	char *signature;  /**< KernelFunc signature */
+	Common::String origName; /**< Original name, in case we couldn't map it */
 	bool isDummy;
 };
 

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-17 23:13:30 UTC (rev 49966)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-17 23:13:54 UTC (rev 49967)
@@ -590,7 +590,7 @@
 		xstack->selector = kernelFuncNum;
 		xstack->type = EXEC_STACK_TYPE_KERNEL;
 
-		//warning("callk %s", kernelFunc.orig_name.c_str());
+		//warning("callk %s", kernelFunc.origName.c_str());
 
 		// TODO: SCI2.1 equivalent
 		if (s->loadFromLauncher >= 0 && (
@@ -614,13 +614,13 @@
 				kRestoreGame(s, 2, restoreArgv);
 		} else {
 			// Call kernel function
-			s->r_acc = kernelFunc.fun(s, argc, argv);
+			s->r_acc = kernelFunc.func(s, argc, argv);
 		}
 
 		// Remove callk stack frame again
 		s->_executionStack.pop_back();
 	} else {
-		Common::String warningMsg = "Dummy function " + kernelFunc.orig_name +
+		Common::String warningMsg = "Dummy function " + kernelFunc.origName +
 									Common::String::printf("[0x%x]", kernelFuncNum) +
 									" invoked - ignoring. Params: " +
 									Common::String::printf("%d", argc) + " (";


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