aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/game.cpp17
-rw-r--r--engines/sci/engine/kernel.cpp40
-rw-r--r--engines/sci/engine/kernel.h28
-rw-r--r--engines/sci/engine/kgraphics.cpp12
-rw-r--r--engines/sci/engine/kmisc.cpp2
-rw-r--r--engines/sci/engine/savegame.cpp1
-rw-r--r--engines/sci/engine/scriptdebug.cpp2
-rw-r--r--engines/sci/engine/state.h2
-rw-r--r--engines/sci/engine/vm.cpp8
-rw-r--r--engines/sci/engine/vm.h7
10 files changed, 56 insertions, 63 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index d29feac3a8..6aba9b3f10 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -104,11 +104,11 @@ int _reset_graphics_input(EngineState *s) {
return 1;
}
- s->visual = gfxw_new_visual(s->gfx_state, font_nr);
+ s->visual = new GfxVisual(s->gfx_state, font_nr);
- s->wm_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
+ s->wm_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
- s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
+ s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
if (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) {
@@ -124,9 +124,9 @@ int _reset_graphics_input(EngineState *s) {
bgcolor.visual = s->gfx_state->resstate->static_palette[255];
bgcolor.mask = GFX_MASK_VISUAL;
#endif
- s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), fgcolor, bgcolor);
+ s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), fgcolor, bgcolor);
} else {
- s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[15]);
+ s->titlebar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 10), s->ega_colors[0], s->ega_colors[15]);
}
s->titlebar_port->_color.mask |= GFX_MASK_PRIORITY;
s->titlebar_port->_color.priority = 11;
@@ -135,7 +135,7 @@ int _reset_graphics_input(EngineState *s) {
s->titlebar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
// but this is correct
- s->picture_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
+ s->picture_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
s->_pics.clear();
@@ -373,9 +373,6 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->_kernel = new Kernel(s->resmgr, (s->flags & GF_SCI0_OLD));
s->_vocabulary = new Vocabulary(s->resmgr);
- script_map_kernel(s);
- // Maps the kernel functions
-
s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
s->bp_list = NULL; // No breakpoints defined
@@ -419,8 +416,6 @@ void script_free_engine(EngineState *s) {
debug(2, "Freeing state-dependant data");
- s->_kfuncTable.clear();
-
delete s->_vocabulary;
s->_vocabulary = 0;
delete s->_kernel;
diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp
index 740673afab..719ff16334 100644
--- a/engines/sci/engine/kernel.cpp
+++ b/engines/sci/engine/kernel.cpp
@@ -482,6 +482,9 @@ Kernel::Kernel(ResourceManager *resmgr, bool isOldSci0) : _resmgr(resmgr) {
error("Kernel: Could not retrieve selector names");
}
+ // Map the kernel functions
+ mapFunctions();
+
// Map a few special selectors for later use
mapSelectors();
}
@@ -490,6 +493,7 @@ Kernel::~Kernel() {
_selectorNames.clear();
_opcodes.clear();
_kernelNames.clear();
+ _kfuncTable.clear();
}
bool Kernel::loadSelectorNames(bool isOldSci0) {
@@ -652,11 +656,11 @@ void kernel_compile_signature(const char **s) {
*s = result; // Write back
}
-int script_map_kernel(EngineState *s) {
+void Kernel::mapFunctions() {
int mapped = 0;
int ignored = 0;
- uint functions_nr = s->_kernel->getKernelNamesSize();
- uint max_functions_nr = (s->resmgr->_sciVersion == SCI_VERSION_0) ? 0x72 : 0x7b;
+ uint functions_nr = getKernelNamesSize();
+ uint max_functions_nr = (_resmgr->_sciVersion == SCI_VERSION_0) ? 0x72 : 0x7b;
if (functions_nr < max_functions_nr) {
warning("SCI version believed to have %d kernel"
@@ -666,14 +670,14 @@ int script_map_kernel(EngineState *s) {
functions_nr = max_functions_nr;
}
- s->_kfuncTable.resize(functions_nr);
+ _kfuncTable.resize(functions_nr);
for (uint functnr = 0; functnr < functions_nr; functnr++) {
int seeker, found = -1;
Common::String sought_name;
- if (functnr < s->_kernel->getKernelNamesSize())
- sought_name = s->_kernel->getKernelName(functnr);
+ if (functnr < getKernelNamesSize())
+ sought_name = getKernelName(functnr);
if (!sought_name.empty())
for (seeker = 0; (found == -1) && kfunct_mappers[seeker].type != KF_TERMINATOR; seeker++)
@@ -682,27 +686,27 @@ int script_map_kernel(EngineState *s) {
if (found == -1) {
if (!sought_name.empty()) {
- warning("Kernel function %s[%x] unmapped", s->_kernel->getKernelName(functnr).c_str(), functnr);
- s->_kfuncTable[functnr].fun = kNOP;
+ warning("Kernel function %s[%x] unmapped", getKernelName(functnr).c_str(), functnr);
+ _kfuncTable[functnr].fun = kNOP;
} else {
warning("Flagging kernel function %x as unknown", functnr);
- s->_kfuncTable[functnr].fun = k_Unknown;
+ _kfuncTable[functnr].fun = k_Unknown;
}
- s->_kfuncTable[functnr].signature = NULL;
- s->_kfuncTable[functnr].orig_name = sought_name;
+ _kfuncTable[functnr].signature = NULL;
+ _kfuncTable[functnr].orig_name = sought_name;
} else
switch (kfunct_mappers[found].type) {
case KF_NONE:
- s->_kfuncTable[functnr].signature = NULL;
+ _kfuncTable[functnr].signature = NULL;
++ignored;
break;
case KF_NEW:
- s->_kfuncTable[functnr].fun = kfunct_mappers[found].fun;
- s->_kfuncTable[functnr].signature = kfunct_mappers[found].signature;
- s->_kfuncTable[functnr].orig_name.clear();
- kernel_compile_signature(&(s->_kfuncTable[functnr].signature));
+ _kfuncTable[functnr].fun = kfunct_mappers[found].fun;
+ _kfuncTable[functnr].signature = kfunct_mappers[found].signature;
+ _kfuncTable[functnr].orig_name.clear();
+ kernel_compile_signature(&(_kfuncTable[functnr].signature));
++mapped;
break;
case KF_TERMINATOR:
@@ -712,12 +716,12 @@ 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->getKernelNamesSize(), mapped);
+ sciprintf("Handled %d/%d kernel functions, mapping %d", mapped + ignored, getKernelNamesSize(), mapped);
if (ignored)
sciprintf(" and ignoring %d", ignored);
sciprintf(".\n");
- return 0;
+ return;
}
int determine_reg_type(EngineState *s, reg_t reg, int allow_invalid) {
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 1ef1e918d9..862ca2514e 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -51,6 +51,15 @@ struct opcode {
Common::String name;
};
+/* Generic description: */
+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 */
+ Common::String orig_name; /* Original name, in case we couldn't map it */
+};
+
class Kernel {
public:
Kernel(ResourceManager *resmgr, bool isOldSci0);
@@ -84,6 +93,8 @@ public:
void dumpScriptClass(char *data, int seeker, int objsize);
selector_map_t _selectorMap; /**< Shortcut list for important selectors */
+ Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
+
private:
/**
* Loads the kernel function names.
@@ -107,6 +118,11 @@ private:
*/
void mapSelectors();
+ /* Maps kernel functions
+ ** Returns : (void)
+ */
+ void mapFunctions();
+
/**
* Loads the opcode names (only used for debugging).
* @return true on success, false on failure
@@ -341,18 +357,6 @@ List *lookup_list(EngineState *s, reg_t addr);
/******************** Kernel functions ********************/
-/* Generic description: */
-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 */
- Common::String orig_name; /* Original name, in case we couldn't map it */
-};
-
-
-
-
// New kernel functions
reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv);
reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv);
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index ae0b2a6d6b..ab981e01f0 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -232,7 +232,7 @@ void graph_restore_box(EngineState *s, reg_t handle) {
while (port_nr > 2 && !(s->port->_flags & GFXW_FLAG_IMMUNE_TO_SNAPSHOTS) && (gfxw_widget_matches_snapshot(*ptr, s->port))) {
// This shouldn't ever happen, actually, since windows (ports w/ ID > 2) should all be immune
- GfxPort *newport = gfxw_find_port(s->visual, port_nr);
+ GfxPort *newport = s->visual->getPort(port_nr);
error("Port %d is not immune against snapshots", s->port->_ID);
port_nr--;
if (newport)
@@ -1031,10 +1031,10 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
delete s->picture_port;
delete s->iconbar_port;
- s->wm_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
- s->picture_port = gfxw_new_port(s->visual, NULL, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
+ s->wm_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
+ s->picture_port = new GfxPort(s->visual, s->gfx_state->pic_port_bounds, s->ega_colors[0], transparent);
- s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
+ s->iconbar_port = new GfxPort(s->visual, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent);
s->iconbar_port->_flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH;
s->visual->add((GfxContainer *)s->visual, s->picture_port);
@@ -2345,7 +2345,7 @@ reg_t kSetPort(EngineState *s, int funct_nr, int argc, reg_t *argv) {
iconbar_port that does not exist in SSCI. */
if (port_nr == (unsigned int) - 1) port_nr = s->iconbar_port->_ID;
- new_port = gfxw_find_port(s->visual, port_nr);
+ new_port = s->visual->getPort(port_nr);
if (!new_port) {
error("Invalid port %04x requested", port_nr);
@@ -2431,7 +2431,7 @@ reg_t kDisposeWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) {
GfxPort *goner;
GfxPort *pred;
- goner = gfxw_find_port(s->visual, goner_nr);
+ goner = s->visual->getPort(goner_nr);
if ((goner_nr < 3) || (goner == NULL)) {
error("Removal of invalid window %04x requested", goner_nr);
return s->r_acc;
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index df5b3ffba9..34d8b5397c 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -248,7 +248,7 @@ 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 (%s) invoked: unmapped", funct_nr, s->_kfuncTable[funct_nr].orig_name.c_str());
+ warning("Kernel function 0x%02x (%s) invoked: unmapped", funct_nr, s->_kernel->_kfuncTable[funct_nr].orig_name.c_str());
return NULL_REG;
}
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index aa93355e1a..bf099816e3 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -837,7 +837,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// s->_kernel = 0; // FIXME: We should set s->_kernel to 0 here,
// else it could be freed when the old EngineState is freed. Luckily, this freeing currently
// never happens, so we don't need to.
- retval->_kfuncTable = s->_kfuncTable;
// Copy breakpoint information from current game instance
retval->have_bp = s->have_bp;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 1f7fe73e51..1f57d666db 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -857,7 +857,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->_kfuncTable.size()) ?
+ sciprintf(" %s[%x]", (param_value < s->_kernel->_kfuncTable.size()) ?
((param_value < s->_kernel->getKernelNamesSize()) ? s->_kernel->getKernelName(param_value).c_str() : "[Unknown(postulated)]")
: "<invalid>", param_value);
else
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index b0cb5fb396..0623aa35fd 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -234,8 +234,6 @@ public:
SegManager *seg_manager;
int gc_countdown; /**< Number of kernel calls until next gc */
- Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
-
MessageState _msgState;
Vocabulary *_vocabulary;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index e796d0ae30..ef50039cf0 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -972,7 +972,7 @@ void run_vm(EngineState *s, int restoring) {
s->r_amp_rest = 0; // We just used up the restadjust, remember?
}
- if (opparams[0] >= (int)s->_kfuncTable.size()) {
+ if (opparams[0] >= (int)s->_kernel->_kfuncTable.size()) {
error("Invalid kernel function 0x%x requested\n", opparams[0]);
} else {
int argc = ASSERT_ARITHMETIC(xs->sp[0]);
@@ -980,11 +980,11 @@ void run_vm(EngineState *s, int restoring) {
if (!(s->flags & GF_SCI0_OLD))
argc += restadjust;
- if (s->_kfuncTable[opparams[0]].signature
- && !kernel_matches_signature(s, s->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
+ if (s->_kernel->_kfuncTable[opparams[0]].signature
+ && !kernel_matches_signature(s, s->_kernel->_kfuncTable[opparams[0]].signature, argc, xs->sp + 1)) {
error("[VM] Invalid arguments to kernel call %x\n", opparams[0]);
} else {
- s->r_acc = s->_kfuncTable[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
+ s->r_acc = s->_kernel->_kfuncTable[opparams[0]].fun(s, opparams[0], argc, xs->sp + 1);
}
// Call kernel function
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 103cb375c2..84e6cc4923 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -1069,13 +1069,6 @@ void quit_vm();
** Returns : (void)
*/
-int script_map_kernel(EngineState *s);
-/* Maps kernel functions
-** 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().
-*/
-
reg_t kalloc(EngineState *s, const char *type, int space);
/* Allocates "kernel" memory and returns a handle suitable to be passed on to SCI scripts
** Parameters: (EngineState *) s: Pointer to the EngineState to operate on