diff options
author | Filippos Karapetis | 2009-05-14 09:12:27 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-05-14 09:12:27 +0000 |
commit | 999d46b241a4aade493f76b4f3623a39c4fed930 (patch) | |
tree | 56a1c2079395ab22ccae8a003691230f073635e3 /engines/sci/engine | |
parent | 2ca7605050c25eff88931fe523c2b005856803f1 (diff) | |
download | scummvm-rg350-999d46b241a4aade493f76b4f3623a39c4fed930.tar.gz scummvm-rg350-999d46b241a4aade493f76b4f3623a39c4fed930.tar.bz2 scummvm-rg350-999d46b241a4aade493f76b4f3623a39c4fed930.zip |
Started using game-specific flags and removed/replaced some SCI version checks with flags.
- The SCI0 new script header and the angles check have been replaced by the GF_SCI0_OLD flag
- The SCI0 new drawpic parameter and the new priority check have been replaced by the GF_SCI0_OLDGFXFUNCS flag
- Removed the code which retries to use the newer script header in SCI0 games if the detected one is wrong, as that case should be covered by the GF_SCI0_OLD flag
- Removed the leftover min_version and max_version variables from gamestate
- Cleaned up kGetTime() a bit
svn-id: r40552
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 11 | ||||
-rw-r--r-- | engines/sci/engine/kernel.cpp | 69 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 14 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 3 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 15 |
9 files changed, 54 insertions, 70 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 0066ebf239..c7909b76c1 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -56,7 +56,7 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat s->opcodes = vocabulary_get_opcodes(s->resmgr); - if (!vocabulary_get_snames(s->resmgr, s->version, s->_selectorNames)) { + if (!vocabulary_get_snames(s->resmgr, (s->flags & GF_SCI0_OLD), s->_selectorNames)) { sciprintf("_init_vocabulary(): Could not retrieve selector names (vocab.997)!\n"); return 1; } @@ -127,7 +127,7 @@ int _reset_graphics_input(EngineState *s) { s->priority_first = 42; // Priority zone 0 ends here - if (s->version < SCI_VERSION_FTU_PRIORITY_14_ZONES) + if (s->flags & GF_SCI0_OLDGFXFUNCS) s->priority_last = 200; else s->priority_last = 190; @@ -323,7 +323,7 @@ static int create_class_table_sci0(EngineState *s) { Resource *script = s->resmgr->findResource(kResourceTypeScript, scriptnr, 0); if (script) { - if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) + if (s->flags & GF_SCI0_OLD) magic_offset = seeker = 2; else magic_offset = seeker = 0; @@ -336,9 +336,8 @@ static int create_class_table_sci0(EngineState *s) { break; seeker += (int16)READ_LE_UINT16(script->data + seeker + 2); if (seeker <= lastseeker) { - warning("Script version is invalid"); s->_classtable.clear(); - return SCI_ERROR_INVALID_SCRIPT_VERSION; + error("Script version is invalid"); } } @@ -387,8 +386,6 @@ static int create_class_table_sci0(EngineState *s) { int script_init_engine(EngineState *s, sci_version_t version) { int result; - s->max_version = SCI_VERSION(9, 999, 999); - s->min_version = 0; //Set no real limits s->version = 0; s->kernel_opt_flags = 0; diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index b7ec82265d..8c4fc596ce 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -359,46 +359,35 @@ 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->version < SCI_VERSION_FTU_NEW_GETTIME) { // Use old semantics - if (argc) { // Get seconds since last am/pm switch - retval = loc_time.tm_sec + loc_time.tm_min * 60 + (loc_time.tm_hour % 12) * 3600; - debugC(2, kDebugLevelTime, "GetTime(timeofday) returns %d", retval); - } else { // Get time since game started - retval = start_time * 60 / 1000; - debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval); - } - } else { - int mode = UKPV_OR_ALT(0, 0); - // The same strange method is still used for distinguishing - // mode 0 and the others. We assume that this is safe, though - - switch (mode) { - case _K_NEW_GETTIME_TICKS : { - retval = start_time * 60 / 1000; - debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval); - break; - } - case _K_NEW_GETTIME_TIME_12HOUR : { - loc_time.tm_hour %= 12; - retval = (loc_time.tm_min << 6) | (loc_time.tm_hour << 12) | (loc_time.tm_sec); - debugC(2, kDebugLevelTime, "GetTime(12h) returns %d", retval); - break; - } - case _K_NEW_GETTIME_TIME_24HOUR : { - retval = (loc_time.tm_min << 5) | (loc_time.tm_sec >> 1) | (loc_time.tm_hour << 11); - debugC(2, kDebugLevelTime, "GetTime(24h) returns %d", retval); - break; - } - case _K_NEW_GETTIME_DATE : { - retval = ((loc_time.tm_mon + 1) << 5) | loc_time.tm_mday | (((loc_time.tm_year + 1900) & 0x7f) << 9); - debugC(2, kDebugLevelTime, "GetTime(date) returns %d", retval); - break; - } - default: { - warning("Attempt to use unknown GetTime mode %d", mode); - break; - } - } + if (argc && s->version < SCI_VERSION_FTU_NEW_GETTIME) { // Use old semantics + retval = loc_time.tm_sec + loc_time.tm_min * 60 + (loc_time.tm_hour % 12) * 3600; + debugC(2, kDebugLevelTime, "GetTime(timeofday) returns %d", retval); + return make_reg(0, retval); + } + + int mode = UKPV_OR_ALT(0, 0); + + switch (mode) { + case _K_NEW_GETTIME_TICKS : + retval = start_time * 60 / 1000; + debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval); + break; + case _K_NEW_GETTIME_TIME_12HOUR : + loc_time.tm_hour %= 12; + retval = (loc_time.tm_min << 6) | (loc_time.tm_hour << 12) | (loc_time.tm_sec); + debugC(2, kDebugLevelTime, "GetTime(12h) returns %d", retval); + break; + case _K_NEW_GETTIME_TIME_24HOUR : + retval = (loc_time.tm_min << 5) | (loc_time.tm_sec >> 1) | (loc_time.tm_hour << 11); + debugC(2, kDebugLevelTime, "GetTime(24h) returns %d", retval); + break; + case _K_NEW_GETTIME_DATE : + retval = ((loc_time.tm_mon + 1) << 5) | loc_time.tm_mday | (((loc_time.tm_year + 1900) & 0x7f) << 9); + debugC(2, kDebugLevelTime, "GetTime(date) returns %d", retval); + break; + default: + warning("Attempt to use unknown GetTime mode %d", mode); + break; } return make_reg(0, retval); diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index ab9bbcf354..c7e0102d18 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -160,7 +160,7 @@ int _find_view_priority(EngineState *s, int y) { return j; return 14; // Maximum } else { - if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES) + 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); @@ -168,7 +168,7 @@ int _find_view_priority(EngineState *s, int y) { } int _find_priority_band(EngineState *s, int nr) { - if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES && (nr < 0 || nr > 14)) { + if (!(s->flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 14)) { if (nr == 15) return 0xffff; else { @@ -177,7 +177,7 @@ int _find_priority_band(EngineState *s, int nr) { return 0; } - if (s->version < SCI_VERSION_FTU_PRIORITY_14_ZONES && (nr < 0 || nr > 15)) { + if ((s->flags & GF_SCI0_OLDGFXFUNCS) && (nr < 0 || nr > 15)) { warning("Attempt to get priority band %d", nr); return 0; } @@ -187,7 +187,7 @@ int _find_priority_band(EngineState *s, int nr) { else { int retval; - if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES) + if (!(s->flags & GF_SCI0_OLDGFXFUNCS)) retval = SCI0_PRIORITY_BAND_FIRST_14_ZONES(nr); else retval = SCI0_PRIORITY_BAND_FIRST(nr); @@ -675,7 +675,7 @@ void _k_dirloop(reg_t obj, uint16 angle, EngineState *s, int funct_nr, int argc, angle %= 360; - if (s->version >= SCI_VERSION_FTU_2ND_ANGLES) { + if (!(s->flags & GF_SCI0_OLD)) { if (angle < 45) loop = 3; else if (angle < 136) @@ -985,7 +985,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) { dp.nr = SKPV(0); dp.palette = SKPV_OR_ALT(3, 0); - if (s->version < SCI_VERSION_FTU_NEWER_DRAWPIC_PARAMETERS) { + 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->version < SCI_VERSION_FTU_PRIORITY_14_ZONES) + if (s->flags & GF_SCI0_OLDGFXFUNCS) s->priority_last = 200; else s->priority_last = 190; diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 363cf48392..a88deff5a1 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -513,9 +513,9 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { } static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { - int magic_pos_adder = s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER ? 0 : 2; + if (s->flags & GF_SCI0_OLD) + buf += 2; - buf += magic_pos_adder; do { int seeker_type = READ_LE_UINT16(buf); int seeker_size; @@ -857,8 +857,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t)); - retval->max_version = retval->version; - retval->min_version = retval->version; retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE); // Copy breakpoint information from current game instance diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 9e962a6449..5727062bbc 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -1379,7 +1379,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->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) + 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 62976dc548..df0561a5e1 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -23,6 +23,7 @@ * */ +#include "sci/sci.h" #include "sci/engine/seg_manager.h" #include "sci/engine/state.h" #include "sci/engine/intmap.h" @@ -146,7 +147,7 @@ void SegManager::setScriptSize(Script &scr, EngineState *s, int script_nr) { sciprintf("%s: failed to load %s\n", __FUNCTION__, !script ? "script" : "heap"); return; } - if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) { + 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, 001, 000)) { diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index 4661abeeda..948e10ff71 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -100,8 +100,6 @@ EngineState::EngineState() : _dirseeker(this) { version_lock_flag = 0; version = 0; - max_version = 0; - min_version = 0; _fileHandles.resize(5); diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index e361601444..8e7b92f5a1 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -196,7 +196,7 @@ public: byte version_lock_flag; /**< Set to 1 to disable any autodetection mechanisms */ sci_version_t version; /**< The approximated patchlevel of the version to emulate */ - sci_version_t max_version, min_version; /* Used for autodetect sanity checks */ + uint32 flags; /* Specific game flags */ unsigned int kernel_opt_flags; /**< Kernel optimization flags- used for performance tweaking */ diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 7b27decbda..46944eb020 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -26,6 +26,7 @@ #include "common/debug.h" #include "common/stack.h" +#include "sci/sci.h" #include "sci/scicore/resource.h" #include "sci/engine/state.h" #include "sci/scicore/versions.h" @@ -1005,7 +1006,7 @@ void run_vm(EngineState *s, int restoring) { gc_countdown(s); xs->sp -= (opparams[1] >> 1) + 1; - if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) { + if (!(s->flags & GF_SCI0_OLD)) { xs->sp -= restadjust; s->r_amp_rest = 0; // We just used up the restadjust, remember? } @@ -1016,7 +1017,7 @@ void run_vm(EngineState *s, int restoring) { } else { int argc = ASSERT_ARITHMETIC(xs->sp[0]); - if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) + if (!(s->flags & GF_SCI0_OLD)) argc += restadjust; if (s->_kfuncTable[opparams[0]].signature @@ -1034,7 +1035,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = &(s->_executionStack[s->execution_stack_pos]); s->_executionStackPosChanged = true; - if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) + if (!(s->flags & GF_SCI0_OLD)) restadjust = s->r_amp_rest; } @@ -1549,7 +1550,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->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) + if (s->flags & GF_SCI0_OLD) selector_id &= ~1; if (!obj) { @@ -1722,7 +1723,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) { reg.segment = seg_id; reg.offset = 0; - if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) { + if (s->flags & GF_SCI0_OLD) { // int locals_nr = READ_LE_UINT16(script->data); @@ -1899,7 +1900,7 @@ int script_instantiate(EngineState *s, int script_nr) { } void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) { - reg_t reg = make_reg(seg, (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 2 : 0); + reg_t reg = make_reg(seg, (s->flags & GF_SCI0_OLD) ? 2 : 0); int objtype, objlength; // Make a pass over the object in order uninstantiate all superclasses @@ -1941,7 +1942,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->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 2 : 0); + reg_t reg = make_reg(0, (s->flags & GF_SCI0_OLD) ? 2 : 0); reg.segment = s->seg_manager->segGet(script_nr); |