aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2009-04-22 17:54:11 +0000
committerMax Horn2009-04-22 17:54:11 +0000
commit3af8918e1a0888d46df13eff088104dce4c88974 (patch)
treef82555b776ff10f38e5de6cd65ad3538137f79a0 /engines/sci
parent7a71fd35aeede3bd1f262e5d0b229235a36a2aeb (diff)
downloadscummvm-rg350-3af8918e1a0888d46df13eff088104dce4c88974.tar.gz
scummvm-rg350-3af8918e1a0888d46df13eff088104dce4c88974.tar.bz2
scummvm-rg350-3af8918e1a0888d46df13eff088104dce4c88974.zip
SCI: Changed kfunct_table to a Common::Array
svn-id: r40080
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/game.cpp31
-rw-r--r--engines/sci/engine/kernel.cpp30
-rw-r--r--engines/sci/engine/kernel.h3
-rw-r--r--engines/sci/engine/savegame.cpp3
-rw-r--r--engines/sci/engine/scriptdebug.cpp2
-rw-r--r--engines/sci/engine/state.cpp3
-rw-r--r--engines/sci/engine/state.h7
-rw-r--r--engines/sci/engine/vm.cpp8
8 files changed, 31 insertions, 56 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 39f1b2135b..a955b0058b 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -68,22 +68,6 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
extern int _allocd_rules;
-static void _free_vocabulary(EngineState *s) {
- sciprintf("Freeing vocabulary\n");
-
- s->_parserWords.clear();
- vocab_free_suffixes(s->resmgr, s->_parserSuffixes);
- vocab_free_branches(s->parser_branches);
- vocab_free_rule_list(s->parser_rules);
-
- s->_selectorNames.clear();
- s->_kernelNames.clear();
- vocabulary_free_opcodes(s->opcodes);
- s->opcodes = NULL;
-
- s->opcodes = NULL;
-}
-
static void _sci1_alloc_system_colors(EngineState *s) {
gfx_color_t black = { PaletteEntry(0, 0, 0), 0, 0, 0, GFX_MASK_VISUAL };
gfxop_set_system_color(s->gfx_state, 0, &black);
@@ -537,17 +521,22 @@ void script_free_vm_memory(EngineState *s) {
s->_fileHandles.resize(5);
}
-extern void free_kfunct_tables(EngineState *s);
-// From kernel.c
-
void script_free_engine(EngineState *s) {
script_free_vm_memory(s);
sciprintf("Freeing state-dependant data\n");
- free_kfunct_tables(s);
+ s->_kfuncTable.clear();
+
+ s->_parserWords.clear();
+ vocab_free_suffixes(s->resmgr, s->_parserSuffixes);
+ vocab_free_branches(s->parser_branches);
+ vocab_free_rule_list(s->parser_rules);
- _free_vocabulary(s);
+ s->_selectorNames.clear();
+ s->_kernelNames.clear();
+ vocabulary_free_opcodes(s->opcodes);
+ s->opcodes = NULL;
}
void script_free_breakpoints(EngineState *s) {
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 945fdab3a4..c5fca9deac 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -505,11 +505,9 @@ 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) {
warning("Kernel function 0x%02x invoked: unmapped", funct_nr);
-/* 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());
+ if (s->_kfuncTable[funct_nr].orig_name != SCRIPT_UNKNOWN_FUNCTION_STRING) {
+ warning(" (but its name is known to be %s)", s->_kfuncTable[funct_nr].orig_name.c_str());
}
-*/
return NULL_REG;
}
@@ -607,8 +605,7 @@ int script_map_kernel(EngineState *s) {
functions_nr = max_functions_nr;
}
- s->kfunct_table = (kfunct_sig_pair_t*)sci_malloc(sizeof(kfunct_sig_pair_t) * functions_nr);
- s->kfunct_nr = functions_nr;
+ s->_kfuncTable.resize(functions_nr);
for (uint functnr = 0; functnr < functions_nr; functnr++) {
int seeker, found = -1;
@@ -625,16 +622,14 @@ int script_map_kernel(EngineState *s) {
if (found == -1) {
if (!sought_name.empty()) {
warning("Kernel function %s[%x] unmapped", s->_kernelNames[functnr].c_str(), functnr);
- s->kfunct_table[functnr].fun = kNOP;
+ s->_kfuncTable[functnr].fun = kNOP;
} else {
warning("Flagging kernel function %x as unknown", functnr);
- s->kfunct_table[functnr].fun = k_Unknown;
+ s->_kfuncTable[functnr].fun = k_Unknown;
}
- s->kfunct_table[functnr].signature = NULL;
-/* TODO: re-enable this
- s->kfunct_table[functnr].orig_name = sought_name;
-*/
+ s->_kfuncTable[functnr].signature = NULL;
+ s->_kfuncTable[functnr].orig_name = sought_name;
} else
switch (kfunct_mappers[found].type) {
case KF_OLD:
@@ -642,13 +637,13 @@ int script_map_kernel(EngineState *s) {
return 1;
case KF_NONE:
- s->kfunct_table[functnr].signature = NULL;
+ s->_kfuncTable[functnr].signature = NULL;
++ignored;
break;
case KF_NEW:
- s->kfunct_table[functnr] = kfunct_mappers[found].sig_pair;
- kernel_compile_signature(&(s->kfunct_table[functnr].signature));
+ s->_kfuncTable[functnr] = kfunct_mappers[found].sig_pair;
+ kernel_compile_signature(&(s->_kfuncTable[functnr].signature));
++mapped;
break;
}
@@ -663,11 +658,6 @@ int script_map_kernel(EngineState *s) {
return 0;
}
-void free_kfunct_tables(EngineState *s) {
- free(s->kfunct_table);
- s->kfunct_table = NULL;
-}
-
int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) {
MemObject *mobj;
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 70561bc9c0..3a3b1f87db 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -28,6 +28,7 @@
#include "common/scummsys.h"
#include "common/debug.h"
+#include "common/rect.h"
#include "sci/engine/kdebug.h"
#include "sci/uinput.h"
@@ -306,7 +307,7 @@ typedef reg_t kfunct(EngineState *s, int funct_nr, int argc, reg_t *argv);
struct kfunct_sig_pair_t {
kfunct *fun; /* The actual function */
const char *signature; /* kfunct signature */
- const char *orig_name; /* Original name, in case we couldn't map it */
+ Common::String orig_name; /* Original name, in case we couldn't map it */
};
#define KF_OLD 0
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 77d36d8a3e..e8bd7a2020 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -904,8 +904,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// static VM/Kernel information:
retval->_selectorNames = s->_selectorNames;
retval->_kernelNames = s->_kernelNames;
- retval->kfunct_table = s->kfunct_table;
- retval->kfunct_nr = s->kfunct_nr;
+ retval->_kfuncTable = s->_kfuncTable;
retval->opcodes = s->opcodes;
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 77285f9aca..41fe16909b 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -1343,7 +1343,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) ?
+ sciprintf(" %s[%x]", (param_value < s->_kfuncTable.size()) ?
((param_value < s->_kernelNames.size()) ? s->_kernelNames[param_value].c_str() : "[Unknown(postulated)]")
: "<invalid>", param_value);
else
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index e87212ac3a..60fed060ff 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;
- kfunct_table = 0;
- kfunct_nr = 0;
-
opcodes = 0;
memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 87ed8cf2d4..037a99883b 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -37,9 +37,10 @@ namespace Common {
#include "sci/scicore/vocabulary.h"
#include "sci/scicore/resource.h"
-#include "sci/engine/script.h"
#include "sci/scicore/sciconsole.h"
#include "sci/scicore/versions.h"
+#include "sci/engine/kernel.h" // for kfunct_sig_pair_t
+#include "sci/engine/script.h"
#include "sci/engine/seg_manager.h"
#include "sci/gfx/gfx_system.h"
#include "sci/sfx/core.h"
@@ -271,9 +272,7 @@ public:
Common::StringList _selectorNames;
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
- ** kernel_names_nr */
+ Common::Array<kfunct_sig_pair_t> _kfuncTable; /* Table of kernel functions */
opcode *opcodes;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 8f596f16e7..358a35613a 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -1016,7 +1016,7 @@ void run_vm(EngineState *s, int restoring) {
s->r_amp_rest = 0; // We just used up the restadjust, remember?
}
- if (opparams[0] >= s->kfunct_nr) {
+ if (opparams[0] >= (int)s->_kfuncTable.size()) {
sciprintf("Invalid kernel function 0x%x requested\n", opparams[0]);
script_debug_flag = script_error_flag = 1;
} else {
@@ -1025,12 +1025,12 @@ void run_vm(EngineState *s, int restoring) {
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
argc += restadjust;
- if (s->kfunct_table[opparams[0]].signature
- && !kernel_matches_signature(s, s->kfunct_table[opparams[0]].signature, argc, xs->sp + 1)) {
+ if (s->_kfuncTable[opparams[0]].signature
+ && !kernel_matches_signature(s, s->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
sciprintf("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
script_debug_flag = script_error_flag = 1;
} else {
- s->r_acc = s->kfunct_table[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
+ s->r_acc = s->_kfuncTable[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
}
// Call kernel function