diff options
-rw-r--r-- | engines/sci/engine/kernel.cpp | 45 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 6 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 6 |
3 files changed, 27 insertions, 30 deletions
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 8ebe78637c..7367e3f34a 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -201,11 +201,11 @@ static const char *s_defaultKernelNames[] = { 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(ResourceManager *resMan, SegManager *segMan) 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 @@ void Kernel::loadSelectorNames() { } } -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 @@ static void kernel_compile_signature(const char **s) { 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 @@ static void kernel_compile_signature(const char **s) { } result[index] = 0; - *s = result; // Write back + + return result; } void Kernel::mapFunctions() { @@ -584,9 +582,9 @@ void Kernel::mapFunctions() { 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 @@ void Kernel::mapFunctions() { 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 @@ void Kernel::mapFunctions() { 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; } } diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index f17e751709..11bc76348d 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -115,9 +115,9 @@ enum { 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; }; diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index f38ce5e3ab..3fbfba1c92 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -590,7 +590,7 @@ static void callKernelFunc(EngineState *s, int kernelFuncNum, int argc) { 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 @@ static void callKernelFunc(EngineState *s, int kernelFuncNum, int argc) { 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) + " ("; |