aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2009-06-04 21:44:39 +0000
committerMax Horn2009-06-04 21:44:39 +0000
commit10c54394bd2f97a6a59a4fc1aedfcad09c40f1dc (patch)
tree06064a5a492015e1f79f3a3b8d2129c39346aa1f /engines/sci
parent870db34cd1e435891e02f54c1c0dc013f257135d (diff)
downloadscummvm-rg350-10c54394bd2f97a6a59a4fc1aedfcad09c40f1dc.tar.gz
scummvm-rg350-10c54394bd2f97a6a59a4fc1aedfcad09c40f1dc.tar.bz2
scummvm-rg350-10c54394bd2f97a6a59a4fc1aedfcad09c40f1dc.zip
SCI: Renamed EngineState::flags and version to _flags and _version (following our conventions); also slightly changed the EngineState constructor to init _version & _flags, and used this to make them constant
svn-id: r41177
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/game.cpp19
-rw-r--r--engines/sci/engine/kevent.cpp2
-rw-r--r--engines/sci/engine/kgraphics.cpp22
-rw-r--r--engines/sci/engine/kmisc.cpp2
-rw-r--r--engines/sci/engine/kmovement.cpp6
-rw-r--r--engines/sci/engine/ksound.cpp8
-rw-r--r--engines/sci/engine/memobj.h6
-rw-r--r--engines/sci/engine/savegame.cpp12
-rw-r--r--engines/sci/engine/scriptdebug.cpp4
-rw-r--r--engines/sci/engine/seg_manager.cpp8
-rw-r--r--engines/sci/engine/state.cpp6
-rw-r--r--engines/sci/engine/state.h8
-rw-r--r--engines/sci/engine/vm.cpp34
-rw-r--r--engines/sci/engine/vm.h18
-rw-r--r--engines/sci/sci.cpp36
15 files changed, 90 insertions, 101 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 6aba9b3f10..bfd38f2c1b 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -43,7 +43,7 @@ int _reset_graphics_input(EngineState *s) {
gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 };
debug(2, "Initializing graphics");
- if (s->resmgr->_sciVersion <= SCI_VERSION_01 || (s->flags & GF_SCI1_EGA)) {
+ if (s->resmgr->_sciVersion <= SCI_VERSION_01 || (s->_flags & GF_SCI1_EGA)) {
int i;
for (i = 0; i < 16; i++) {
@@ -66,7 +66,7 @@ int _reset_graphics_input(EngineState *s) {
} else {
resource = s->resmgr->findResource(kResourceTypePalette, 999, 1);
if (resource) {
- if (s->version < SCI_VERSION_1_1)
+ if (s->_version < SCI_VERSION_1_1)
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal1(999, resource->data, resource->size));
else
s->gfx_state->gfxResMan->setStaticPalette(gfxr_read_pal11(999, resource->data, resource->size));
@@ -89,7 +89,7 @@ int _reset_graphics_input(EngineState *s) {
s->priority_first = 42; // Priority zone 0 ends here
- if (s->flags & GF_SCI0_OLDGFXFUNCS)
+ if (s->_flags & GF_SCI0_OLDGFXFUNCS)
s->priority_last = 200;
else
s->priority_last = 190;
@@ -259,7 +259,7 @@ static int create_class_table_sci0(EngineState *s) {
Resource *script = s->resmgr->findResource(kResourceTypeScript, scriptnr, 0);
if (script) {
- if (s->flags & GF_SCI0_OLD)
+ if (s->_flags & GF_SCI0_OLD)
magic_offset = seeker = 2;
else
magic_offset = seeker = 0;
@@ -324,13 +324,12 @@ static int create_class_table_sci0(EngineState *s) {
}
// Architectural stuff: Init/Unintialize engine
-int script_init_engine(EngineState *s, sci_version_t version) {
+int script_init_engine(EngineState *s) {
int result;
s->kernel_opt_flags = 0;
- s->version = version;
- if (s->version >= SCI_VERSION_1_1)
+ if (s->_version >= SCI_VERSION_1_1)
result = create_class_table_sci11(s);
else
result = create_class_table_sci0(s);
@@ -340,7 +339,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
return 1;
}
- s->seg_manager = new SegManager(s->version >= SCI_VERSION_1_1);
+ s->seg_manager = new SegManager(s->_version >= SCI_VERSION_1_1);
s->gc_countdown = GC_INTERVAL - 1;
SegmentId script_000_segment = script_get_segment(s, 0, SCRIPT_GET_LOCK);
@@ -370,7 +369,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->_executionStack.clear(); // Start without any execution stack
s->execution_stack_base = -1; // No vm is running yet
- s->_kernel = new Kernel(s->resmgr, (s->flags & GF_SCI0_OLD));
+ s->_kernel = new Kernel(s->resmgr, (s->_flags & GF_SCI0_OLD));
s->_vocabulary = new Vocabulary(s->resmgr);
s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING;
@@ -378,7 +377,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->bp_list = NULL; // No breakpoints defined
s->have_bp = 0;
- if ((s->flags & GF_SCI1_LOFSABSOLUTE) && s->version < SCI_VERSION_1_1)
+ if ((s->_flags & GF_SCI1_LOFSABSOLUTE) && s->_version < SCI_VERSION_1_1)
s->seg_manager->setExportWidth(1);
else
s->seg_manager->setExportWidth(0);
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index b275e9c0b9..66395035c8 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -42,7 +42,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = argv[1];
sci_event_t e;
int oldx, oldy;
- int modifier_mask = s->version <= SCI_VERSION_0 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK;
+ int modifier_mask = s->_version <= SCI_VERSION_0 ? SCI_EVM_ALL : SCI_EVM_NO_FOOLOCK;
if (s->kernel_opt_flags & KERNEL_OPT_FLAG_GOT_2NDEVENT) {
// Penalty time- too many requests to this function without waiting!
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 8413a7887b..fc23e4f6ef 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -163,7 +163,7 @@ int _find_view_priority(EngineState *s, int y) {
return j;
return 14; // Maximum
} else {
- if (!(s->flags & GF_SCI0_OLDGFXFUNCS))
+ if (!(s->_flags & GF_SCI0_OLDGFXFUNCS))
return SCI0_VIEW_PRIORITY_14_ZONES(y);
else
return SCI0_VIEW_PRIORITY(y) == 15 ? 14 : SCI0_VIEW_PRIORITY(y);
@@ -171,7 +171,7 @@ int _find_view_priority(EngineState *s, int y) {
}
int _find_priority_band(EngineState *s, int nr) {
- if (!(s->flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 14)) {
+ if (!(s->_flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 14)) {
if (nr == 15)
return 0xffff;
else {
@@ -180,7 +180,7 @@ int _find_priority_band(EngineState *s, int nr) {
return 0;
}
- if ((s->flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 15)) {
+ if ((s->_flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 15)) {
warning("Attempt to get priority band %d", nr);
return 0;
}
@@ -190,7 +190,7 @@ int _find_priority_band(EngineState *s, int nr) {
else {
int retval;
- if (!(s->flags & GF_SCI0_OLDGFXFUNCS))
+ if (!(s->_flags & GF_SCI0_OLDGFXFUNCS))
retval = SCI0_PRIORITY_BAND_FIRST_14_ZONES(nr);
else
retval = SCI0_PRIORITY_BAND_FIRST(nr);
@@ -303,7 +303,7 @@ static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int
reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
switch (argc) {
case 1 :
- if (s->version < SCI_VERSION_1_1) {
+ if (s->_version < SCI_VERSION_1_1) {
if (SKPV(0) == 0 || SKPV(0) == 1 || SKPV(0) == -1) {
// Newer (SCI1.1) semantics: show/hide cursor
g_system->showMouse(SKPV(0) != 0);
@@ -317,7 +317,7 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
break;
case 2 :
- if (s->version < SCI_VERSION_1_1) {
+ if (s->_version < SCI_VERSION_1_1) {
// Pre-SCI1.1: set cursor according to the first parameter, and toggle its
// visibility based on the second parameter
// Some late SCI1 games actually use the SCI1.1 version of this call (EcoQuest 1
@@ -685,7 +685,7 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc,
angle %= 360;
- if (!(s->flags & GF_SCI0_OLD)) {
+ if (!(s->_flags & GF_SCI0_OLD)) {
if (angle < 45)
loop = 3;
else if (angle < 136)
@@ -997,7 +997,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if ((argc > 1) && (UKPV(1) & K_DRAWPIC_FLAG_MIRRORED))
picFlags |= DRAWPIC1_FLAG_MIRRORED;
- if (s->flags & GF_SCI0_OLDGFXFUNCS) {
+ if (s->_flags & GF_SCI0_OLDGFXFUNCS) {
if (!SKPV_OR_ALT(2, 0))
add_to_pic = 0;
} else {
@@ -1050,7 +1050,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->priority_first = 42;
- if (s->flags & GF_SCI0_OLDGFXFUNCS)
+ if (s->_flags & GF_SCI0_OLDGFXFUNCS)
s->priority_last = 200;
else
s->priority_last = 190;
@@ -1135,7 +1135,7 @@ void _k_base_setter(EngineState *s, reg_t object) {
// does not exist (earliest one was KQ4 SCI, version 0.000.274). This code is left here
// for reference only
#if 0
- if (s->version <= SCI_VERSION_0)
+ if (s->_version <= SCI_VERSION_0)
--absrect.top; // Compensate for early SCI OB1 'bug'
#endif
@@ -1346,7 +1346,7 @@ static void _k_disable_delete_for_now(EngineState *s, reg_t obj) {
* that game - bringing the save/load dialog on a par with SCI0.
*/
if (type == K_CONTROL_BUTTON && text && (s->_gameName == "sq4") &&
- s->version < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) {
+ s->_version < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) {
PUT_SEL32V(obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled);
}
}
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 2cb3ecfb41..2e86362404 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -121,7 +121,7 @@ reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
g_system->getTimeAndDate(loc_time);
start_time = g_system->getMillis() - s->game_start_time;
- if ((s->flags & GF_SCI0_OLDGETTIME) && argc) { // Use old semantics
+ if ((s->_flags & GF_SCI0_OLDGETTIME) && argc) { // Use old semantics
retval = (loc_time.tm_hour % 12) * 3600 + loc_time.tm_min * 60 + loc_time.tm_sec;
debugC(2, kDebugLevelTime, "GetTime(timeofday) returns %d", retval);
return make_reg(0, retval);
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index cd4307678b..b116fa4093 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -273,7 +273,7 @@ static void bresenham_autodetect(EngineState *s) {
}
buf = s->seg_manager->getScript(fptr.segment)->buf + fptr.offset;
- handle_movecnt = (s->version <= SCI_VERSION_0 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
+ handle_movecnt = (s->_version <= SCI_VERSION_0 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
sciprintf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ? "ignore" : "increment");
} else {
warning("bresenham_autodetect failed");
@@ -292,7 +292,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int completed = 0;
int max_movcnt = GET_SEL32V(client, moveSpeed);
- if (s->version > SCI_VERSION_0)
+ if (s->_version > SCI_VERSION_0)
signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE;
if (handle_movecnt == UNINITIALIZED)
@@ -379,7 +379,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
completed = 1;
}
- if (s->version > SCI_VERSION_0)
+ if (s->_version > SCI_VERSION_0)
if (completed)
invoke_selector(INV_SEL(mover, moveDone, kStopOnInvalidSelector), 0);
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 3586b6b1ed..b0fbda36f9 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -154,7 +154,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
song_handle_t handle;
int cue;
- if (s->version >= SCI_VERSION_01)
+ if (s->_version >= SCI_VERSION_01)
return;
/* SCI01 and later explicitly poll for everything */
@@ -964,9 +964,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kDoSound(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- if (s->version >= SCI_VERSION_1_1 || s->flags & GF_SCI1_NEWDOSOUND)
+ if (s->_version >= SCI_VERSION_1_1 || s->_flags & GF_SCI1_NEWDOSOUND)
return kDoSound_SCI1(s, funct_nr, argc, argv);
- else if (s->version >= SCI_VERSION_01)
+ else if (s->_version >= SCI_VERSION_01)
return kDoSound_SCI01(s, funct_nr, argc, argv);
else
return kDoSound_SCI0(s, funct_nr, argc, argv);
@@ -978,7 +978,7 @@ reg_t kDoAudio(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int sampleLen = 0;
if (!s->_sound._audioResource)
- s->_sound._audioResource = new AudioResource(s->resmgr, s->version);
+ s->_sound._audioResource = new AudioResource(s->resmgr, s->_version);
switch (UKPV(0)) {
case kSciAudioWPlay:
diff --git a/engines/sci/engine/memobj.h b/engines/sci/engine/memobj.h
index 7b9c2e507a..c006caaddc 100644
--- a/engines/sci/engine/memobj.h
+++ b/engines/sci/engine/memobj.h
@@ -215,16 +215,16 @@ struct CodeBlock {
};
#define VM_OBJECT_GET_VARSELECTOR(obj, i) \
- (s->version < SCI_VERSION_1_1 ? \
+ (s->_version < SCI_VERSION_1_1 ? \
READ_LE_UINT16(obj->base_obj + obj->_variables.size() * 2 + i*2) : \
*(obj->base_vars + i))
#define VM_OBJECT_READ_PROPERTY(obj, i) (obj->_variables[i])
#define VM_OBJECT_GET_FUNCSELECTOR(obj, i) \
- (s->version < SCI_VERSION_1_1 ? \
+ (s->_version < SCI_VERSION_1_1 ? \
READ_LE_UINT16((byte *) (obj->base_method + i)) : \
READ_LE_UINT16((byte *) (obj->base_method + i*2 + 1)))
#define VM_OBJECT_READ_FUNCTION(obj, i) \
- (s->version < SCI_VERSION_1_1 ? \
+ (s->_version < SCI_VERSION_1_1 ? \
make_reg(obj->pos.segment, \
READ_LE_UINT16((byte *) (obj->base_method \
+ obj->methods_nr + 1 \
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index bf099816e3..a69e96eb3d 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -458,7 +458,7 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
SavegameMetadata meta;
meta.savegame_version = CURRENT_SAVEGAME_VERSION;
meta.savegame_name = savename;
- meta.version = s->version;
+ meta.version = s->_version;
meta.game_version = s->game_version;
meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
@@ -497,7 +497,7 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) {
}
static byte *find_unique_script_block(EngineState *s, byte *buf, int type) {
- if (s->flags & GF_SCI0_OLD)
+ if (s->_flags & GF_SCI0_OLD)
buf += 2;
do {
@@ -545,7 +545,7 @@ static void load_script(EngineState *s, SegmentId seg) {
assert(scr->buf);
script = s->resmgr->findResource(kResourceTypeScript, scr->nr, 0);
- if (s->version >= SCI_VERSION_1_1)
+ if (s->_version >= SCI_VERSION_1_1)
heap = s->resmgr->findResource(kResourceTypeHeap, scr->nr, 0);
memcpy(scr->buf, script->data, script->size);
@@ -759,11 +759,9 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
// FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch.
- retval = new EngineState();
+ retval = new EngineState(s->resmgr, s->_version, s->_flags);
// Copy some old data
- retval->version = s->version;
- retval->flags = s->flags;
retval->gfx_state = s->gfx_state;
retval->sound_mute = s->sound_mute;
retval->sound_volume = s->sound_volume;
@@ -781,8 +779,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
retval->gfx_state = s->gfx_state;
retval->old_screen = 0;
- retval->resmgr = s->resmgr;
-
temp = retval->_sound._songlib;
retval->_sound.sfx_init(retval->resmgr, s->sfx_init_flags);
retval->sfx_init_flags = s->sfx_init_flags;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index dd4173dd0f..4581c0a37c 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -271,7 +271,7 @@ int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) {
selectors = obj->_variables.size();
- if (s->version < SCI_VERSION_1_1)
+ if (s->_version < SCI_VERSION_1_1)
selectoroffset = ((byte *)(obj->base_obj)) + SCRIPT_SELECTOR_OFFSET + selectors * 2;
else {
if (!(obj->_variables[SCRIPT_INFO_SELECTOR].offset & SCRIPT_INFO_CLASS)) {
@@ -466,7 +466,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
int stackframe = (scr[pos.offset + 2] >> 1) + (*p_restadjust);
int argc = ((*p_sp)[- stackframe - 1]).offset;
- if (!(s->flags & GF_SCI0_OLD))
+ if (!(s->_flags & GF_SCI0_OLD))
argc += (*p_restadjust);
sciprintf(" Kernel params: (");
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 840c9bc525..dcf7180501 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -135,13 +135,13 @@ void SegManager::setScriptSize(Script &scr, EngineState *s, int script_nr) {
scr.script_size = script->size;
scr.heap_size = 0; // Set later
- if (!script || (s->version >= SCI_VERSION_1_1 && !heap)) {
+ if (!script || (s->_version >= SCI_VERSION_1_1 && !heap)) {
error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap");
}
- if (s->flags & GF_SCI0_OLD) {
+ if (s->_flags & GF_SCI0_OLD) {
scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2;
//locals_size = READ_LE_UINT16(script->data) * 2;
- } else if (s->version < SCI_VERSION_1_1) {
+ } else if (s->_version < SCI_VERSION_1_1) {
scr.buf_size = script->size;
} else {
scr.buf_size = script->size + heap->size;
@@ -189,7 +189,7 @@ int SegManager::initialiseScript(Script &scr, EngineState *s, int script_nr) {
scr.obj_indices = new IntMapper();
- if (s->version >= SCI_VERSION_1_1)
+ if (s->_version >= SCI_VERSION_1_1)
scr.heap_start = scr.buf + scr.script_size;
else
scr.heap_start = scr.buf;
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 2677ff4131..3040e4c462 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -27,7 +27,8 @@
namespace Sci {
-EngineState::EngineState() : _dirseeker(this) {
+EngineState::EngineState(ResourceManager *res, sci_version_t version, uint32 flags)
+: resmgr(res), _version(version), _flags(flags), _dirseeker(this) {
widget_serial_counter = 0;
resmgr = 0;
@@ -80,9 +81,6 @@ EngineState::EngineState() : _dirseeker(this) {
last_wait_time = 0;
- version = 0;
- flags = 0;
-
kernel_opt_flags = 0;
_fileHandles.resize(5);
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index 561db322ef..15c1c2e63e 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -109,7 +109,7 @@ public:
struct EngineState : public Common::Serializable {
public:
- EngineState();
+ EngineState(ResourceManager *res, sci_version_t version, uint32 flags);
virtual ~EngineState();
virtual void saveLoadWithSerializer(Common::Serializer &ser);
@@ -118,6 +118,9 @@ public:
ResourceManager *resmgr; /**< The resource manager */
+ const sci_version_t _version; /**< The approximated patchlevel of the version to emulate */
+ const uint32 _flags; /**< Specific game flags */
+
Common::String _gameName; /**< Designation of the primary object (which inherits from Game) */
char *game_version;
@@ -174,9 +177,6 @@ public:
uint32 game_start_time; /**< The time at which the interpreter was started */
uint32 last_wait_time; /**< The last time the game invoked Wait() */
- sci_version_t version; /**< The approximated patchlevel of the version to emulate */
- uint32 flags; /**< Specific game flags */
-
unsigned int kernel_opt_flags; /**< Kernel optimization flags- used for performance tweaking */
/* Kernel File IO stuff */
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 0e7f932333..fe9523197e 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -971,7 +971,7 @@ void run_vm(EngineState *s, int restoring) {
gc_countdown(s);
xs->sp -= (opparams[1] >> 1) + 1;
- if (!(s->flags & GF_SCI0_OLD)) {
+ if (!(s->_flags & GF_SCI0_OLD)) {
xs->sp -= restadjust;
s->r_amp_rest = 0; // We just used up the restadjust, remember?
}
@@ -981,7 +981,7 @@ void run_vm(EngineState *s, int restoring) {
} else {
int argc = ASSERT_ARITHMETIC(xs->sp[0]);
- if (!(s->flags & GF_SCI0_OLD))
+ if (!(s->_flags & GF_SCI0_OLD))
argc += restadjust;
if (s->_kernel->_kernelFuncs[opparams[0]].signature
@@ -998,7 +998,7 @@ void run_vm(EngineState *s, int restoring) {
xs_new = &(s->_executionStack.back());
s->_executionStackPosChanged = true;
- if (!(s->flags & GF_SCI0_OLD))
+ if (!(s->_flags & GF_SCI0_OLD))
restadjust = s->r_amp_rest;
}
@@ -1201,10 +1201,10 @@ void run_vm(EngineState *s, int restoring) {
case 0x39: // lofsa
s->r_acc.segment = xs->addr.pc.segment;
- if (s->version >= SCI_VERSION_1_1) {
+ if (s->_version >= SCI_VERSION_1_1) {
s->r_acc.offset = opparams[0] + local_script->script_size;
} else {
- if (s->flags & GF_SCI1_LOFSABSOLUTE)
+ if (s->_flags & GF_SCI1_LOFSABSOLUTE)
s->r_acc.offset = opparams[0];
else
s->r_acc.offset = xs->addr.pc.offset + opparams[0];
@@ -1221,7 +1221,7 @@ void run_vm(EngineState *s, int restoring) {
case 0x3a: // lofss
r_temp.segment = xs->addr.pc.segment;
- if (s->flags & GF_SCI1_LOFSABSOLUTE)
+ if (s->_flags & GF_SCI1_LOFSABSOLUTE)
r_temp.offset = opparams[0];
else
r_temp.offset = xs->addr.pc.offset + opparams[0];
@@ -1441,7 +1441,7 @@ static int _obj_locate_varselector(EngineState *s, Object *obj, Selector slc) {
// Determines if obj explicitly defines slc as a varselector
// Returns -1 if not found
- if (s->version < SCI_VERSION_1_1) {
+ if (s->_version < SCI_VERSION_1_1) {
int varnum = obj->variable_names_nr;
int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET;
int i;
@@ -1514,7 +1514,7 @@ SelectorType lookup_selector(EngineState *s, reg_t obj_location, Selector select
// Early SCI versions used the LSB in the selector ID as a read/write
// toggle, meaning that we must remove it for selector lookup.
- if (s->flags & GF_SCI0_OLD)
+ if (s->_flags & GF_SCI0_OLD)
selector_id &= ~1;
if (!obj) {
@@ -1608,12 +1608,12 @@ int script_instantiate_common(EngineState *s, int script_nr, Resource **script,
*was_new = 1;
*script = s->resmgr->findResource(kResourceTypeScript, script_nr, 0);
- if (s->version >= SCI_VERSION_1_1)
+ if (s->_version >= SCI_VERSION_1_1)
*heap = s->resmgr->findResource(kResourceTypeHeap, script_nr, 0);
- if (!*script || (s->version >= SCI_VERSION_1_1 && !heap)) {
+ if (!*script || (s->_version >= SCI_VERSION_1_1 && !heap)) {
sciprintf("Script 0x%x requested but not found\n", script_nr);
- if (s->version >= SCI_VERSION_1_1) {
+ if (s->_version >= SCI_VERSION_1_1) {
if (*heap)
sciprintf("Inconsistency: heap resource WAS found\n");
else if (*script)
@@ -1680,7 +1680,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) {
Script *scr = s->seg_manager->getScript(seg_id);
- if (s->flags & GF_SCI0_OLD) {
+ if (s->_flags & GF_SCI0_OLD) {
//
int locals_nr = READ_LE_UINT16(script->data);
@@ -1849,14 +1849,14 @@ int script_instantiate_sci11(EngineState *s, int script_nr) {
}
int script_instantiate(EngineState *s, int script_nr) {
- if (s->version >= SCI_VERSION_1_1)
+ if (s->_version >= SCI_VERSION_1_1)
return script_instantiate_sci11(s, script_nr);
else
return script_instantiate_sci0(s, script_nr);
}
void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) {
- reg_t reg = make_reg(seg, (s->flags & GF_SCI0_OLD) ? 2 : 0);
+ reg_t reg = make_reg(seg, (s->_flags & GF_SCI0_OLD) ? 2 : 0);
int objtype, objlength;
Script *scr = s->seg_manager->getScript(seg);
@@ -1900,7 +1900,7 @@ void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) {
}
void script_uninstantiate(EngineState *s, int script_nr) {
- reg_t reg = make_reg(0, (s->flags & GF_SCI0_OLD) ? 2 : 0);
+ reg_t reg = make_reg(0, (s->_flags & GF_SCI0_OLD) ? 2 : 0);
reg.segment = s->seg_manager->segGet(script_nr);
Script *scr = script_locate_by_segment(s, reg.segment);
@@ -1921,7 +1921,7 @@ void script_uninstantiate(EngineState *s, int script_nr) {
if (s->_classtable[i].reg.segment == reg.segment)
s->_classtable[i].reg = NULL_REG;
- if (s->version < SCI_VERSION_1_1)
+ if (s->_version < SCI_VERSION_1_1)
script_uninstantiate_sci0(s, script_nr, reg.segment);
else
sciprintf("FIXME: Add proper script uninstantiation for SCI 1.1\n");
@@ -1959,7 +1959,7 @@ static EngineState *_game_run(EngineState *s, int restoring) {
game_exit(s);
script_free_engine(s);
- script_init_engine(s, s->version);
+ script_init_engine(s);
game_init(s);
sfx_reset_player();
_init_stack_base_with_selector(s, s->_kernel->_selectorMap.play);
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 39ffbb2760..f8e11b9b88 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -67,12 +67,12 @@ struct Object;
#define SCRIPT_FUNCTAREAPTR_MAGIC 8 -8
/** Offset of the name pointer */
-#define SCRIPT_NAME_OFFSET (s->version < SCI_VERSION_1_1 ? 14 -8 : 16)
-#define SCRIPT_NAME_SELECTOR (s->version < SCI_VERSION_1_1 ? 3 : 8)
+#define SCRIPT_NAME_OFFSET (s->_version < SCI_VERSION_1_1 ? 14 -8 : 16)
+#define SCRIPT_NAME_SELECTOR (s->_version < SCI_VERSION_1_1 ? 3 : 8)
/** Object-relative offset of the -info- selector */
-#define SCRIPT_INFO_OFFSET (s->version < SCI_VERSION_1_1 ? 12 -8 : 14)
-#define SCRIPT_INFO_SELECTOR (s->version < SCI_VERSION_1_1 ? 2 : 7)
+#define SCRIPT_INFO_OFFSET (s->_version < SCI_VERSION_1_1 ? 12 -8 : 14)
+#define SCRIPT_INFO_SELECTOR (s->_version < SCI_VERSION_1_1 ? 2 : 7)
/** Flag fo the -info- selector */
#define SCRIPT_INFO_CLONE 0x0001
@@ -84,18 +84,18 @@ struct Object;
/** Magical object identifier */
#define SCRIPT_OBJECT_MAGIC_NUMBER 0x1234
/** Offset of this identifier */
-#define SCRIPT_OBJECT_MAGIC_OFFSET (s->version < SCI_VERSION_1_1 ? -8 : 0)
+#define SCRIPT_OBJECT_MAGIC_OFFSET (s->_version < SCI_VERSION_1_1 ? -8 : 0)
/** Script-relative offset of the species ID */
#define SCRIPT_SPECIES_OFFSET 8 -8
-#define SCRIPT_SUPERCLASS_OFFSET (s->version < SCI_VERSION_1_1 ? 10 -8 : 12)
+#define SCRIPT_SUPERCLASS_OFFSET (s->_version < SCI_VERSION_1_1 ? 10 -8 : 12)
/*---------------------------------*/
/* Script selector index variables */
/*---------------------------------*/
-#define SCRIPT_SPECIES_SELECTOR (s->version < SCI_VERSION_1_1 ? 0 : 5)
-#define SCRIPT_SUPERCLASS_SELECTOR (s->version < SCI_VERSION_1_1 ? 1 : 6)
+#define SCRIPT_SPECIES_SELECTOR (s->_version < SCI_VERSION_1_1 ? 0 : 5)
+#define SCRIPT_SUPERCLASS_SELECTOR (s->_version < SCI_VERSION_1_1 ? 1 : 6)
#define SCRIPT_CLASSSCRIPT_SELECTOR 4
/** Magic adjustment value for lofsa and lofss */
@@ -402,7 +402,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
** Returns : (void)
*/
-int script_init_engine(EngineState *s, sci_version_t version);
+int script_init_engine(EngineState *s);
/* Initializes a EngineState block
** Parameters: (EngineState *) s: The state to initialize
** Returns : 0 on success, 1 if vocab.996 (the class table) is missing or corrupted
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index eb75beab8f..8083ddad73 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -124,11 +124,10 @@ Common::Error SciEngine::run() {
// FIXME/TODO: Move some of the stuff below to init()
- sci_version_t version;
+ const sci_version_t version = getVersion();
+ const uint32 flags = getFlags();
int res_version = getResourceVersion();
- version = getVersion();
-
_resmgr = new ResourceManager(res_version, 256 * 1024);
if (!_resmgr) {
@@ -144,37 +143,34 @@ Common::Error SciEngine::run() {
map_MIDI_instruments(_resmgr);
#endif
- _gamestate = new EngineState();
- _gamestate->resmgr = _resmgr;
- _gamestate->gfx_state = NULL;
- _gamestate->flags = getFlags();
+ _gamestate = new EngineState(_resmgr, version, flags);
// Verify that we haven't got an invalid game detection entry
if (version < SCI_VERSION_1_EARLY) {
// SCI0/SCI01
- if (_gamestate->flags & GF_SCI1_EGA ||
- _gamestate->flags & GF_SCI1_LOFSABSOLUTE ||
- _gamestate->flags & GF_SCI1_NEWDOSOUND) {
+ if (flags & GF_SCI1_EGA ||
+ flags & GF_SCI1_LOFSABSOLUTE ||
+ flags & GF_SCI1_NEWDOSOUND) {
error("This game entry is erroneous. It's marked as SCI0/SCI01, but it has SCI1 flags set");
}
} else if (version >= SCI_VERSION_1_EARLY && version <= SCI_VERSION_1_LATE) {
// SCI1
- if (_gamestate->flags & GF_SCI0_OLD ||
- _gamestate->flags & GF_SCI0_OLDGFXFUNCS ||
- _gamestate->flags & GF_SCI0_OLDGETTIME) {
+ if (flags & GF_SCI0_OLD ||
+ flags & GF_SCI0_OLDGFXFUNCS ||
+ flags & GF_SCI0_OLDGETTIME) {
error("This game entry is erroneous. It's marked as SCI1, but it has SCI0 flags set");
}
} else if (version == SCI_VERSION_1_1 || version == SCI_VERSION_32) {
- if (_gamestate->flags & GF_SCI1_EGA ||
- _gamestate->flags & GF_SCI1_LOFSABSOLUTE ||
- _gamestate->flags & GF_SCI1_NEWDOSOUND) {
+ if (flags & GF_SCI1_EGA ||
+ flags & GF_SCI1_LOFSABSOLUTE ||
+ flags & GF_SCI1_NEWDOSOUND) {
error("This game entry is erroneous. It's marked as SCI1.1/SCI32, but it has SCI1 flags set");
}
- if (_gamestate->flags & GF_SCI0_OLD ||
- _gamestate->flags & GF_SCI0_OLDGFXFUNCS ||
- _gamestate->flags & GF_SCI0_OLDGETTIME) {
+ if (flags & GF_SCI0_OLD ||
+ flags & GF_SCI0_OLDGFXFUNCS ||
+ flags & GF_SCI0_OLDGETTIME) {
error("This game entry is erroneous. It's marked as SCI1.1/SCI32, but it has SCI0 flags set");
}
@@ -183,7 +179,7 @@ Common::Error SciEngine::run() {
error ("Unknown SCI version in game entry");
}
- if (script_init_engine(_gamestate, version))
+ if (script_init_engine(_gamestate))
return Common::kUnknownError;