SCI: Changed kfunct_table to a Common::Array
svn-id: r40080
This commit is contained in:
parent
7a71fd35ae
commit
3af8918e1a
8 changed files with 31 additions and 56 deletions
|
@ -68,22 +68,6 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
|
||||||
|
|
||||||
extern int _allocd_rules;
|
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) {
|
static void _sci1_alloc_system_colors(EngineState *s) {
|
||||||
gfx_color_t black = { PaletteEntry(0, 0, 0), 0, 0, 0, GFX_MASK_VISUAL };
|
gfx_color_t black = { PaletteEntry(0, 0, 0), 0, 0, 0, GFX_MASK_VISUAL };
|
||||||
gfxop_set_system_color(s->gfx_state, 0, &black);
|
gfxop_set_system_color(s->gfx_state, 0, &black);
|
||||||
|
@ -537,17 +521,22 @@ void script_free_vm_memory(EngineState *s) {
|
||||||
s->_fileHandles.resize(5);
|
s->_fileHandles.resize(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void free_kfunct_tables(EngineState *s);
|
|
||||||
// From kernel.c
|
|
||||||
|
|
||||||
void script_free_engine(EngineState *s) {
|
void script_free_engine(EngineState *s) {
|
||||||
script_free_vm_memory(s);
|
script_free_vm_memory(s);
|
||||||
|
|
||||||
sciprintf("Freeing state-dependant data\n");
|
sciprintf("Freeing state-dependant data\n");
|
||||||
|
|
||||||
free_kfunct_tables(s);
|
s->_kfuncTable.clear();
|
||||||
|
|
||||||
_free_vocabulary(s);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void script_free_breakpoints(EngineState *s) {
|
void script_free_breakpoints(EngineState *s) {
|
||||||
|
|
|
@ -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) {
|
reg_t kNOP(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||||
warning("Kernel function 0x%02x invoked: unmapped", funct_nr);
|
warning("Kernel function 0x%02x invoked: unmapped", funct_nr);
|
||||||
|
|
||||||
/* TODO: re-enable this
|
if (s->_kfuncTable[funct_nr].orig_name != SCRIPT_UNKNOWN_FUNCTION_STRING) {
|
||||||
if (s->kfunct_table[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());
|
||||||
warning(" (but its name is known to be %s)", s->kfunct_table[funct_nr].orig_name.c_str());
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return NULL_REG;
|
return NULL_REG;
|
||||||
}
|
}
|
||||||
|
@ -607,8 +605,7 @@ int script_map_kernel(EngineState *s) {
|
||||||
functions_nr = max_functions_nr;
|
functions_nr = max_functions_nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->kfunct_table = (kfunct_sig_pair_t*)sci_malloc(sizeof(kfunct_sig_pair_t) * functions_nr);
|
s->_kfuncTable.resize(functions_nr);
|
||||||
s->kfunct_nr = functions_nr;
|
|
||||||
|
|
||||||
for (uint functnr = 0; functnr < functions_nr; functnr++) {
|
for (uint functnr = 0; functnr < functions_nr; functnr++) {
|
||||||
int seeker, found = -1;
|
int seeker, found = -1;
|
||||||
|
@ -625,16 +622,14 @@ int script_map_kernel(EngineState *s) {
|
||||||
if (found == -1) {
|
if (found == -1) {
|
||||||
if (!sought_name.empty()) {
|
if (!sought_name.empty()) {
|
||||||
warning("Kernel function %s[%x] unmapped", s->_kernelNames[functnr].c_str(), functnr);
|
warning("Kernel function %s[%x] unmapped", s->_kernelNames[functnr].c_str(), functnr);
|
||||||
s->kfunct_table[functnr].fun = kNOP;
|
s->_kfuncTable[functnr].fun = kNOP;
|
||||||
} else {
|
} else {
|
||||||
warning("Flagging kernel function %x as unknown", functnr);
|
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;
|
s->_kfuncTable[functnr].signature = NULL;
|
||||||
/* TODO: re-enable this
|
s->_kfuncTable[functnr].orig_name = sought_name;
|
||||||
s->kfunct_table[functnr].orig_name = sought_name;
|
|
||||||
*/
|
|
||||||
} else
|
} else
|
||||||
switch (kfunct_mappers[found].type) {
|
switch (kfunct_mappers[found].type) {
|
||||||
case KF_OLD:
|
case KF_OLD:
|
||||||
|
@ -642,13 +637,13 @@ int script_map_kernel(EngineState *s) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KF_NONE:
|
case KF_NONE:
|
||||||
s->kfunct_table[functnr].signature = NULL;
|
s->_kfuncTable[functnr].signature = NULL;
|
||||||
++ignored;
|
++ignored;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KF_NEW:
|
case KF_NEW:
|
||||||
s->kfunct_table[functnr] = kfunct_mappers[found].sig_pair;
|
s->_kfuncTable[functnr] = kfunct_mappers[found].sig_pair;
|
||||||
kernel_compile_signature(&(s->kfunct_table[functnr].signature));
|
kernel_compile_signature(&(s->_kfuncTable[functnr].signature));
|
||||||
++mapped;
|
++mapped;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -663,11 +658,6 @@ int script_map_kernel(EngineState *s) {
|
||||||
return 0;
|
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) {
|
int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) {
|
||||||
MemObject *mobj;
|
MemObject *mobj;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
#include "common/rect.h"
|
||||||
|
|
||||||
#include "sci/engine/kdebug.h"
|
#include "sci/engine/kdebug.h"
|
||||||
#include "sci/uinput.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 {
|
struct kfunct_sig_pair_t {
|
||||||
kfunct *fun; /* The actual function */
|
kfunct *fun; /* The actual function */
|
||||||
const char *signature; /* kfunct signature */
|
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
|
#define KF_OLD 0
|
||||||
|
|
|
@ -904,8 +904,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
||||||
// static VM/Kernel information:
|
// static VM/Kernel information:
|
||||||
retval->_selectorNames = s->_selectorNames;
|
retval->_selectorNames = s->_selectorNames;
|
||||||
retval->_kernelNames = s->_kernelNames;
|
retval->_kernelNames = s->_kernelNames;
|
||||||
retval->kfunct_table = s->kfunct_table;
|
retval->_kfuncTable = s->_kfuncTable;
|
||||||
retval->kfunct_nr = s->kfunct_nr;
|
|
||||||
retval->opcodes = s->opcodes;
|
retval->opcodes = s->opcodes;
|
||||||
|
|
||||||
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
|
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
|
||||||
|
|
|
@ -1343,7 +1343,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opcode == op_callk)
|
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)]")
|
((param_value < s->_kernelNames.size()) ? s->_kernelNames[param_value].c_str() : "[Unknown(postulated)]")
|
||||||
: "<invalid>", param_value);
|
: "<invalid>", param_value);
|
||||||
else
|
else
|
||||||
|
|
|
@ -157,9 +157,6 @@ EngineState::EngineState() : _dirseeker(this) {
|
||||||
seg_manager = 0;
|
seg_manager = 0;
|
||||||
gc_countdown = 0;
|
gc_countdown = 0;
|
||||||
|
|
||||||
kfunct_table = 0;
|
|
||||||
kfunct_nr = 0;
|
|
||||||
|
|
||||||
opcodes = 0;
|
opcodes = 0;
|
||||||
|
|
||||||
memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
|
memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
|
||||||
|
|
|
@ -37,9 +37,10 @@ namespace Common {
|
||||||
|
|
||||||
#include "sci/scicore/vocabulary.h"
|
#include "sci/scicore/vocabulary.h"
|
||||||
#include "sci/scicore/resource.h"
|
#include "sci/scicore/resource.h"
|
||||||
#include "sci/engine/script.h"
|
|
||||||
#include "sci/scicore/sciconsole.h"
|
#include "sci/scicore/sciconsole.h"
|
||||||
#include "sci/scicore/versions.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/engine/seg_manager.h"
|
||||||
#include "sci/gfx/gfx_system.h"
|
#include "sci/gfx/gfx_system.h"
|
||||||
#include "sci/sfx/core.h"
|
#include "sci/sfx/core.h"
|
||||||
|
@ -271,9 +272,7 @@ public:
|
||||||
Common::StringList _selectorNames;
|
Common::StringList _selectorNames;
|
||||||
Common::StringList _kernelNames; /* List of kernel names */
|
Common::StringList _kernelNames; /* List of kernel names */
|
||||||
|
|
||||||
kfunct_sig_pair_t *kfunct_table; /* Table of kernel functions */
|
Common::Array<kfunct_sig_pair_t> _kfuncTable; /* Table of kernel functions */
|
||||||
int kfunct_nr; /* Number of mapped kernel functions; may be more than
|
|
||||||
** kernel_names_nr */
|
|
||||||
|
|
||||||
opcode *opcodes;
|
opcode *opcodes;
|
||||||
|
|
||||||
|
|
|
@ -1016,7 +1016,7 @@ void run_vm(EngineState *s, int restoring) {
|
||||||
s->r_amp_rest = 0; // We just used up the restadjust, remember?
|
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]);
|
sciprintf("Invalid kernel function 0x%x requested\n", opparams[0]);
|
||||||
script_debug_flag = script_error_flag = 1;
|
script_debug_flag = script_error_flag = 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1025,12 +1025,12 @@ void run_vm(EngineState *s, int restoring) {
|
||||||
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
|
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
|
||||||
argc += restadjust;
|
argc += restadjust;
|
||||||
|
|
||||||
if (s->kfunct_table[opparams[0]].signature
|
if (s->_kfuncTable[opparams[0]].signature
|
||||||
&& !kernel_matches_signature(s, s->kfunct_table[opparams[0]].signature, argc, xs->sp + 1)) {
|
&& !kernel_matches_signature(s, s->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
|
||||||
sciprintf("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
|
sciprintf("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
|
||||||
script_debug_flag = script_error_flag = 1;
|
script_debug_flag = script_error_flag = 1;
|
||||||
} else {
|
} 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
|
// Call kernel function
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue