diff options
author | Max Horn | 2009-04-22 17:53:29 +0000 |
---|---|---|
committer | Max Horn | 2009-04-22 17:53:29 +0000 |
commit | b1e43f3ca0d4830bd87a99334dc127e9d20555b1 (patch) | |
tree | 4a5e89e08c44fd5294dd377741ed349bfa5eb048 /engines/sci/engine | |
parent | b98f79fe120f3859cace579d21731f137376d5fb (diff) | |
download | scummvm-rg350-b1e43f3ca0d4830bd87a99334dc127e9d20555b1.tar.gz scummvm-rg350-b1e43f3ca0d4830bd87a99334dc127e9d20555b1.tar.bz2 scummvm-rg350-b1e43f3ca0d4830bd87a99334dc127e9d20555b1.zip |
SCI: Changed knames (kernel function name table) to Common::StringList
svn-id: r40078
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/kernel.cpp | 50 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/scriptconsole.cpp | 14 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 3 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 6 |
9 files changed, 42 insertions, 56 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 9d79d8e65c..39f1b2135b 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -77,11 +77,10 @@ static void _free_vocabulary(EngineState *s) { vocab_free_rule_list(s->parser_rules); s->_selectorNames.clear(); - vocabulary_free_knames(s->kernel_names); + s->_kernelNames.clear(); vocabulary_free_opcodes(s->opcodes); s->opcodes = NULL; - s->kernel_names = NULL; s->opcodes = NULL; } @@ -477,7 +476,7 @@ int script_init_engine(EngineState *s, sci_version_t version) { s->execution_stack_base = -1; // No vm is running yet s->execution_stack_pos = -1; // Start at execution stack position 0 - s->kernel_names = vocabulary_get_knames(s->resmgr, &s->kernel_names_nr); + vocabulary_get_knames(s->resmgr, s->_kernelNames); script_map_kernel(s); // Maps the kernel functions diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index ca940625b3..945fdab3a4 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -232,16 +232,11 @@ reg_t kalloc(EngineState *s, const char *type, int space) { return reg; } -int has_kernel_function(EngineState *s, const char *kname) { - int i = 0; +bool has_kernel_function(EngineState *s, const char *kname) { + Common::StringList::const_iterator it + = Common::find(s->_kernelNames.begin(), s->_kernelNames.end(), kname); - while (s->kernel_names[i]) { - if (!strcmp(s->kernel_names[i], kname)) - return 1; - i++; - } - - return 0; + return (it != s->_kernelNames.end()); } // Returns a pointer to the memory indicated by the specified handle @@ -496,7 +491,7 @@ reg_t kMemory(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kstub(EngineState *s, int funct_nr, int argc, reg_t *argv) { int i; - sciprintf("Unimplemented syscall: %s[%x](", s->kernel_names[funct_nr], funct_nr); + sciprintf("Unimplemented syscall: %s[%x](", s->_kernelNames[funct_nr].c_str(), funct_nr); for (i = 0; i < argc; i++) { sciprintf(PREG, PRINT_REG(argv[i])); @@ -508,13 +503,13 @@ reg_t kstub(EngineState *s, int funct_nr, int argc, reg_t *argv) { } reg_t kNOP(EngineState *s, int funct_nr, int argc, reg_t *argv) { - const char *problem = (const char*)(s->kfunct_table[funct_nr].orig_name ? "unmapped" : "NOP"); + warning("Kernel function 0x%02x invoked: unmapped", funct_nr); - warning("Kernel function 0x%02x invoked: %s", funct_nr, problem); - - if (s->kfunct_table[funct_nr].orig_name && strcmp(s->kfunct_table[funct_nr].orig_name, SCRIPT_UNKNOWN_FUNCTION_STRING)) { - warning(" (but its name is known to be %s)", s->kfunct_table[funct_nr].orig_name); +/* TODO: re-enable this + if (s->kfunct_table[funct_nr].orig_name != SCRIPT_UNKNOWN_FUNCTION_STRING) { + warning(" (but its name is known to be %s)", s->kfunct_table[funct_nr].orig_name.c_str()); } +*/ return NULL_REG; } @@ -599,11 +594,10 @@ void kernel_compile_signature(const char **s) { } int script_map_kernel(EngineState *s) { - int functnr; int mapped = 0; int ignored = 0; - int functions_nr = s->kernel_names_nr; - int max_functions_nr = sci_max_allowed_unknown_kernel_functions[s->resmgr->_sciVersion]; + uint functions_nr = s->_kernelNames.size(); + uint max_functions_nr = sci_max_allowed_unknown_kernel_functions[s->resmgr->_sciVersion]; if (functions_nr < max_functions_nr) { warning("SCI version believed to have %d kernel" @@ -616,21 +610,21 @@ int script_map_kernel(EngineState *s) { s->kfunct_table = (kfunct_sig_pair_t*)sci_malloc(sizeof(kfunct_sig_pair_t) * functions_nr); s->kfunct_nr = functions_nr; - for (functnr = 0; functnr < functions_nr; functnr++) { + for (uint functnr = 0; functnr < functions_nr; functnr++) { int seeker, found = -1; - char *sought_name = NULL; + Common::String sought_name; - if (functnr < s->kernel_names_nr) - sought_name = s->kernel_names[functnr]; + if (functnr < s->_kernelNames.size()) + sought_name = s->_kernelNames[functnr]; - if (sought_name) + if (!sought_name.empty()) for (seeker = 0; (found == -1) && kfunct_mappers[seeker].type != KF_TERMINATOR; seeker++) - if (kfunct_mappers[seeker].name && strcmp(kfunct_mappers[seeker].name, sought_name) == 0) + if (kfunct_mappers[seeker].name && sought_name == kfunct_mappers[seeker].name) found = seeker; // Found a kernel function with the same name! if (found == -1) { - if (sought_name) { - warning("Kernel function %s[%x] unmapped", s->kernel_names[functnr], functnr); + if (!sought_name.empty()) { + warning("Kernel function %s[%x] unmapped", s->_kernelNames[functnr].c_str(), functnr); s->kfunct_table[functnr].fun = kNOP; } else { warning("Flagging kernel function %x as unknown", functnr); @@ -638,7 +632,9 @@ int script_map_kernel(EngineState *s) { } s->kfunct_table[functnr].signature = NULL; +/* TODO: re-enable this s->kfunct_table[functnr].orig_name = sought_name; +*/ } else switch (kfunct_mappers[found].type) { case KF_OLD: @@ -659,7 +655,7 @@ int script_map_kernel(EngineState *s) { } // for all functions requesting to be mapped - sciprintf("Handled %d/%d kernel functions, mapping %d", mapped + ignored, s->kernel_names_nr, mapped); + sciprintf("Handled %d/%d kernel functions, mapping %d", mapped + ignored, s->_kernelNames.size(), mapped); if (ignored) sciprintf(" and ignoring %d", ignored); sciprintf(".\n"); diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 68ebbcc10f..70561bc9c0 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -109,7 +109,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index); #define CHECK_THIS_KERNEL_FUNCTION if (s->debug_mode & (1 << SCIkFUNCCHK_NR)) {\ int i;\ - sciprintf("Kernel CHECK: %s[%x](", s->kernel_names[funct_nr], funct_nr); \ + sciprintf("Kernel CHECK: %s[%x](", s->_kernelNames[funct_nr].c_str(), funct_nr); \ for (i = 0; i < argc; i++) { \ sciprintf("%04x", 0xffff & UKPV(i)); \ if (i+1 < argc) sciprintf(", "); \ diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 40be8bd4a2..77d36d8a3e 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -903,8 +903,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { // static VM/Kernel information: retval->_selectorNames = s->_selectorNames; - retval->kernel_names_nr = s->kernel_names_nr; - retval->kernel_names = s->kernel_names; + retval->_kernelNames = s->_kernelNames; retval->kfunct_table = s->kfunct_table; retval->kfunct_nr = s->kfunct_nr; retval->opcodes = s->opcodes; diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index 38acb8458f..b6f09ce8bc 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -1029,25 +1029,23 @@ static int c_selectornames(EngineState * s) { } static int c_kernelnames(EngineState * s) { - int knamectr; - char **knames = vocabulary_get_knames(s->resmgr, &knamectr); - int seeker = 0; + Common::StringList knames; if (NULL == s) { sciprintf("console.c: c_kernelnames NULL passed for parameter s\n"); return -1; } - if (!knames) { + vocabulary_get_knames(s->resmgr, knames); + + if (knames.empty()) { sciprintf("No kernel name table found!\n"); return 1; } sciprintf("Syscalls in numeric order:\n"); - for (seeker = 0; seeker < knamectr; seeker++) - sciprintf("%03x: %s\n", seeker, knames[seeker]); - - vocabulary_free_knames(knames); + for (uint seeker = 0; seeker < knames.size(); seeker++) + sciprintf("%03x: %s\n", seeker, knames[seeker].c_str()); return 0; } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 8769945b8c..77285f9aca 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -1344,7 +1344,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod if (opcode == op_callk) sciprintf(" %s[%x]", (param_value < s->kfunct_nr) ? - ((param_value < s->kernel_names_nr) ? s->kernel_names[param_value] : "[Unknown(postulated)]") + ((param_value < s->_kernelNames.size()) ? s->_kernelNames[param_value].c_str() : "[Unknown(postulated)]") : "<invalid>", param_value); else sciprintf(opsize ? " %02x" : " %04x", param_value); @@ -1564,7 +1564,7 @@ static int c_backtrace(EngineState *s) { break; case EXEC_STACK_TYPE_KERNEL: // Kernel function - sciprintf(" %x:[%x] k%s(", i, call->origin, s->kernel_names[-(call->selector)-42]); + sciprintf(" %x:[%x] k%s(", i, call->origin, s->_kernelNames[-(call->selector)-42].c_str()); break; case EXEC_STACK_TYPE_VARSELECTOR: @@ -2111,17 +2111,15 @@ static int c_snk(EngineState *s) { and scan the function table to find out the index. */ callk_index = strtoul(cmd_params [0].str, &endptr, 0); if (*endptr != '\0') { - int i; - callk_index = -1; - for (i = 0; i < s->kernel_names_nr; i++) - if (!strcmp(cmd_params [0].str, s->kernel_names [i])) { + for (uint i = 0; i < s->_kernelNames.size(); i++) + if (cmd_params [0].str == s->_kernelNames[i]) { callk_index = i; break; } if (callk_index == -1) { - sciprintf("Unknown kernel function '%s'\n", cmd_params [0].str); + sciprintf("Unknown kernel function '%s'\n", cmd_params[0].str); return 1; } } diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index 5fbfd44899..e87212ac3a 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -157,9 +157,6 @@ EngineState::EngineState() : _dirseeker(this) { seg_manager = 0; gc_countdown = 0; - kernel_names_nr = 0; - kernel_names = 0; - kfunct_table = 0; kfunct_nr = 0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 2a3a6a150c..87ed8cf2d4 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -269,8 +269,7 @@ public: int gc_countdown; /* Number of kernel calls until next gc */ Common::StringList _selectorNames; - int kernel_names_nr; /* Number of kernel function names */ - char **kernel_names; /* List of kernel names */ + Common::StringList _kernelNames; /* List of kernel names */ kfunct_sig_pair_t *kfunct_table; /* Table of kernel functions */ int kfunct_nr; /* Number of mapped kernel functions; may be more than diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 78b62b7524..9354ac4676 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -756,7 +756,7 @@ void script_map_selectors(EngineState *s, selector_map_t *map); int script_map_kernel(EngineState *s); /* Maps kernel functions -** Parameters: (EngineState *) s: The state which the kernel_names are retrieved from +** Parameters: (EngineState *) s: The state which the _kernelNames are retrieved from ** Returns : (void) ** This function reads from and writes to s. It is called by script_run(). */ @@ -776,11 +776,11 @@ reg_t kalloc(EngineState *s, const char *type, int space); ** Returns : (reg_t) The handle */ -int has_kernel_function(EngineState *s, const char *kname); +bool has_kernel_function(EngineState *s, const char *kname); /* Detects whether a particular kernel function is required in the game ** Parameters: (EngineState *) s: Pointer to the EngineState to operate on ** (const char *) kname: The name of the desired kernel function -** Returns : (int) 1 if the kernel function is listed in the kernel table, +** Returns : (bool) 1 if the kernel function is listed in the kernel table, ** 0 otherwise */ |