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
This commit is contained in:
Filippos Karapetis 2009-05-14 09:12:27 +00:00
parent 2ca7605050
commit 999d46b241
17 changed files with 80 additions and 167 deletions

View file

@ -109,7 +109,7 @@ bool Console::cmdGetVersion(int argc, const char **argv) {
bool Console::cmdSelectors(int argc, const char **argv) { bool Console::cmdSelectors(int argc, const char **argv) {
Common::StringList selectorNames; Common::StringList selectorNames;
if (!vocabulary_get_snames(_vm->getResMgr(), _vm->getVersion(), selectorNames)) { if (!vocabulary_get_snames(_vm->getResMgr(), (_vm->getFlags() & GF_SCI0_OLD), selectorNames)) {
DebugPrintf("No selector name table found!\n"); DebugPrintf("No selector name table found!\n");
return true; return true;
} }

View file

@ -121,7 +121,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "f3d1be7752d30ba60614533d531e2e98", 474}, {"resource.map", 0, "f3d1be7752d30ba60614533d531e2e98", 474},
{"resource.001", 0, "6fd05926c2199af0af6f72f90d0d7260", 126895}, {"resource.001", 0, "6fd05926c2199af0af6f72f90d0d7260", 126895},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 453) SCI_VERSION(0, 000, 453)
}, },
@ -196,7 +196,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "39485580d34a72997f3d5b3aba4d24f1", 426}, {"resource.map", 0, "39485580d34a72997f3d5b3aba4d24f1", 426},
{"resource.001", 0, "11391434f41c834090d7a1e9488ce936", 129739}, {"resource.001", 0, "11391434f41c834090d7a1e9488ce936", 129739},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLD | GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.395 and 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 0, 294) SCI_VERSION(0, 0, 294)
}, },
@ -876,7 +876,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.006", 0, "851a62d00972dc4002f472cc0d84e71d", 333777}, {"resource.006", 0, "851a62d00972dc4002f472cc0d84e71d", 333777},
{"resource.007", 0, "851a62d00972dc4002f472cc0d84e71d", 341038}, {"resource.007", 0, "851a62d00972dc4002f472cc0d84e71d", 341038},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLD | GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.395 and 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 274) SCI_VERSION(0, 000, 274)
}, },
@ -892,7 +892,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.006", 0, "0c8566848a76eea19a6d6220914030a7", 337288}, {"resource.006", 0, "0c8566848a76eea19a6d6220914030a7", 337288},
{"resource.007", 0, "0c8566848a76eea19a6d6220914030a7", 343882}, {"resource.007", 0, "0c8566848a76eea19a6d6220914030a7", 343882},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLD | GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.395 and 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 253) SCI_VERSION(0, 000, 253)
}, },
@ -1374,7 +1374,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "03dba704bb77da55a91ad27b5a3cac09", 528}, {"resource.map", 0, "03dba704bb77da55a91ad27b5a3cac09", 528},
{"resource.001", 0, "9f5520f0297206928df0b0b36493cd33", 127532}, {"resource.001", 0, "9f5520f0297206928df0b0b36493cd33", 127532},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO},
0, GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 409) // FIXME: no version number in executable (x.yyy.zzz) SCI_VERSION(0, 000, 409) // FIXME: no version number in executable (x.yyy.zzz)
}, },
@ -1389,7 +1389,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.005", 0, "4a24443a25e2b1492462a52809605dc2", 277732}, {"resource.005", 0, "4a24443a25e2b1492462a52809605dc2", 277732},
{"resource.006", 0, "4a24443a25e2b1492462a52809605dc2", 345683}, {"resource.006", 0, "4a24443a25e2b1492462a52809605dc2", 345683},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 409) SCI_VERSION(0, 000, 409)
}, },
@ -1404,7 +1404,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.005", 0, "96033f57accfca903750413fd09193c8", 274953}, {"resource.005", 0, "96033f57accfca903750413fd09193c8", 274953},
{"resource.006", 0, "96033f57accfca903750413fd09193c8", 345818}, {"resource.006", 0, "96033f57accfca903750413fd09193c8", 345818},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLD | GF_SCI0_OLDGFXFUNCS, // version is older than 0.000.395 and 0.000.502
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 343) SCI_VERSION(0, 000, 343)
}, },
@ -2554,7 +2554,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.map", 0, "ec66ac2b1ce58b2575ba00b65058de1a", 612}, {"resource.map", 0, "ec66ac2b1ce58b2575ba00b65058de1a", 612},
{"resource.001", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 180245}, {"resource.001", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 180245},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO},
0, GF_SCI0_OLD, // version is older than 0.000.395
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 453) SCI_VERSION(0, 000, 453)
}, },
@ -2566,7 +2566,7 @@ static const struct SciGameDescription SciGameDescriptions[] = {
{"resource.002", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 720244}, {"resource.002", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 720244},
{"resource.003", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 688367}, {"resource.003", 0, "ceeda7202b96e5c85ecaa88a40a540fc", 688367},
{NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0}, {NULL, 0, NULL, 0}}, Common::EN_ANY, Common::kPlatformPC, 0},
0, GF_SCI0_OLD, // version is older than 0.000.395
SCI_VERSION_AUTODETECT, SCI_VERSION_AUTODETECT,
SCI_VERSION(0, 000, 453) SCI_VERSION(0, 000, 453)
}, },

View file

@ -56,7 +56,7 @@ static int _init_vocabulary(EngineState *s) { // initialize vocabulary and relat
s->opcodes = vocabulary_get_opcodes(s->resmgr); 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"); sciprintf("_init_vocabulary(): Could not retrieve selector names (vocab.997)!\n");
return 1; return 1;
} }
@ -127,7 +127,7 @@ int _reset_graphics_input(EngineState *s) {
s->priority_first = 42; // Priority zone 0 ends here 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; s->priority_last = 200;
else else
s->priority_last = 190; s->priority_last = 190;
@ -323,7 +323,7 @@ static int create_class_table_sci0(EngineState *s) {
Resource *script = s->resmgr->findResource(kResourceTypeScript, scriptnr, 0); Resource *script = s->resmgr->findResource(kResourceTypeScript, scriptnr, 0);
if (script) { if (script) {
if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) if (s->flags & GF_SCI0_OLD)
magic_offset = seeker = 2; magic_offset = seeker = 2;
else else
magic_offset = seeker = 0; magic_offset = seeker = 0;
@ -336,9 +336,8 @@ static int create_class_table_sci0(EngineState *s) {
break; break;
seeker += (int16)READ_LE_UINT16(script->data + seeker + 2); seeker += (int16)READ_LE_UINT16(script->data + seeker + 2);
if (seeker <= lastseeker) { if (seeker <= lastseeker) {
warning("Script version is invalid");
s->_classtable.clear(); 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 script_init_engine(EngineState *s, sci_version_t version) {
int result; int result;
s->max_version = SCI_VERSION(9, 999, 999);
s->min_version = 0; //Set no real limits
s->version = 0; s->version = 0;
s->kernel_opt_flags = 0; s->kernel_opt_flags = 0;

View file

@ -359,47 +359,36 @@ reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
g_system->getTimeAndDate(loc_time); g_system->getTimeAndDate(loc_time);
start_time = g_system->getMillis() - s->game_start_time; start_time = g_system->getMillis() - s->game_start_time;
if (s->version < SCI_VERSION_FTU_NEW_GETTIME) { // Use old semantics if (argc && 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; retval = loc_time.tm_sec + loc_time.tm_min * 60 + (loc_time.tm_hour % 12) * 3600;
debugC(2, kDebugLevelTime, "GetTime(timeofday) returns %d", retval); debugC(2, kDebugLevelTime, "GetTime(timeofday) returns %d", retval);
} else { // Get time since game started return make_reg(0, retval);
retval = start_time * 60 / 1000;
debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
} }
} else {
int mode = UKPV_OR_ALT(0, 0); 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) { switch (mode) {
case _K_NEW_GETTIME_TICKS : { case _K_NEW_GETTIME_TICKS :
retval = start_time * 60 / 1000; retval = start_time * 60 / 1000;
debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval); debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
break; break;
} case _K_NEW_GETTIME_TIME_12HOUR :
case _K_NEW_GETTIME_TIME_12HOUR : {
loc_time.tm_hour %= 12; loc_time.tm_hour %= 12;
retval = (loc_time.tm_min << 6) | (loc_time.tm_hour << 12) | (loc_time.tm_sec); retval = (loc_time.tm_min << 6) | (loc_time.tm_hour << 12) | (loc_time.tm_sec);
debugC(2, kDebugLevelTime, "GetTime(12h) returns %d", retval); debugC(2, kDebugLevelTime, "GetTime(12h) returns %d", retval);
break; break;
} case _K_NEW_GETTIME_TIME_24HOUR :
case _K_NEW_GETTIME_TIME_24HOUR : {
retval = (loc_time.tm_min << 5) | (loc_time.tm_sec >> 1) | (loc_time.tm_hour << 11); retval = (loc_time.tm_min << 5) | (loc_time.tm_sec >> 1) | (loc_time.tm_hour << 11);
debugC(2, kDebugLevelTime, "GetTime(24h) returns %d", retval); debugC(2, kDebugLevelTime, "GetTime(24h) returns %d", retval);
break; break;
} case _K_NEW_GETTIME_DATE :
case _K_NEW_GETTIME_DATE : {
retval = ((loc_time.tm_mon + 1) << 5) | loc_time.tm_mday | (((loc_time.tm_year + 1900) & 0x7f) << 9); 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); debugC(2, kDebugLevelTime, "GetTime(date) returns %d", retval);
break; break;
} default:
default: {
warning("Attempt to use unknown GetTime mode %d", mode); warning("Attempt to use unknown GetTime mode %d", mode);
break; break;
} }
}
}
return make_reg(0, retval); return make_reg(0, retval);
} }

View file

@ -160,7 +160,7 @@ int _find_view_priority(EngineState *s, int y) {
return j; return j;
return 14; // Maximum return 14; // Maximum
} else { } else {
if (s->version >= SCI_VERSION_FTU_PRIORITY_14_ZONES) if (!(s->flags & GF_SCI0_OLDGFXFUNCS))
return SCI0_VIEW_PRIORITY_14_ZONES(y); return SCI0_VIEW_PRIORITY_14_ZONES(y);
else else
return SCI0_VIEW_PRIORITY(y) == 15 ? 14 : SCI0_VIEW_PRIORITY(y); 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) { 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) if (nr == 15)
return 0xffff; return 0xffff;
else { else {
@ -177,7 +177,7 @@ int _find_priority_band(EngineState *s, int nr) {
return 0; 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); warning("Attempt to get priority band %d", nr);
return 0; return 0;
} }
@ -187,7 +187,7 @@ int _find_priority_band(EngineState *s, int nr) {
else { else {
int retval; 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); retval = SCI0_PRIORITY_BAND_FIRST_14_ZONES(nr);
else else
retval = SCI0_PRIORITY_BAND_FIRST(nr); 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; angle %= 360;
if (s->version >= SCI_VERSION_FTU_2ND_ANGLES) { if (!(s->flags & GF_SCI0_OLD)) {
if (angle < 45) if (angle < 45)
loop = 3; loop = 3;
else if (angle < 136) 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.nr = SKPV(0);
dp.palette = SKPV_OR_ALT(3, 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)) if (!SKPV_OR_ALT(2, 0))
add_to_pic = 0; add_to_pic = 0;
} else { } else {
@ -1050,7 +1050,7 @@ reg_t kDrawPic(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->priority_first = 42; s->priority_first = 42;
if (s->version < SCI_VERSION_FTU_PRIORITY_14_ZONES) if (s->flags & GF_SCI0_OLDGFXFUNCS)
s->priority_last = 200; s->priority_last = 200;
else else
s->priority_last = 190; s->priority_last = 190;

View file

@ -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) { 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 { do {
int seeker_type = READ_LE_UINT16(buf); int seeker_type = READ_LE_UINT16(buf);
int seeker_size; 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)); 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); retval->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
// Copy breakpoint information from current game instance // Copy breakpoint information from current game instance

View file

@ -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 stackframe = (scr[pos.offset + 2] >> 1) + (*p_restadjust);
int argc = ((*p_sp)[- stackframe - 1]).offset; 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); argc += (*p_restadjust);
sciprintf(" Kernel params: ("); sciprintf(" Kernel params: (");

View file

@ -23,6 +23,7 @@
* *
*/ */
#include "sci/sci.h"
#include "sci/engine/seg_manager.h" #include "sci/engine/seg_manager.h"
#include "sci/engine/state.h" #include "sci/engine/state.h"
#include "sci/engine/intmap.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"); sciprintf("%s: failed to load %s\n", __FUNCTION__, !script ? "script" : "heap");
return; 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; scr.buf_size = script->size + READ_LE_UINT16(script->data) * 2;
//locals_size = READ_LE_UINT16(script->data) * 2; //locals_size = READ_LE_UINT16(script->data) * 2;
} else if (s->version < SCI_VERSION(1, 001, 000)) { } else if (s->version < SCI_VERSION(1, 001, 000)) {

View file

@ -100,8 +100,6 @@ EngineState::EngineState() : _dirseeker(this) {
version_lock_flag = 0; version_lock_flag = 0;
version = 0; version = 0;
max_version = 0;
min_version = 0;
_fileHandles.resize(5); _fileHandles.resize(5);

View file

@ -196,7 +196,7 @@ public:
byte version_lock_flag; /**< Set to 1 to disable any autodetection mechanisms */ 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 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 */ unsigned int kernel_opt_flags; /**< Kernel optimization flags- used for performance tweaking */

View file

@ -26,6 +26,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "common/stack.h" #include "common/stack.h"
#include "sci/sci.h"
#include "sci/scicore/resource.h" #include "sci/scicore/resource.h"
#include "sci/engine/state.h" #include "sci/engine/state.h"
#include "sci/scicore/versions.h" #include "sci/scicore/versions.h"
@ -1005,7 +1006,7 @@ void run_vm(EngineState *s, int restoring) {
gc_countdown(s); gc_countdown(s);
xs->sp -= (opparams[1] >> 1) + 1; xs->sp -= (opparams[1] >> 1) + 1;
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) { if (!(s->flags & GF_SCI0_OLD)) {
xs->sp -= restadjust; xs->sp -= restadjust;
s->r_amp_rest = 0; // We just used up the restadjust, remember? s->r_amp_rest = 0; // We just used up the restadjust, remember?
} }
@ -1016,7 +1017,7 @@ void run_vm(EngineState *s, int restoring) {
} else { } else {
int argc = ASSERT_ARITHMETIC(xs->sp[0]); int argc = ASSERT_ARITHMETIC(xs->sp[0]);
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) if (!(s->flags & GF_SCI0_OLD))
argc += restadjust; argc += restadjust;
if (s->_kfuncTable[opparams[0]].signature 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]); xs_new = &(s->_executionStack[s->execution_stack_pos]);
s->_executionStackPosChanged = true; s->_executionStackPosChanged = true;
if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) if (!(s->flags & GF_SCI0_OLD))
restadjust = s->r_amp_rest; 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 // Early SCI versions used the LSB in the selector ID as a read/write
// toggle, meaning that we must remove it for selector lookup. // 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; selector_id &= ~1;
if (!obj) { if (!obj) {
@ -1722,7 +1723,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) {
reg.segment = seg_id; reg.segment = seg_id;
reg.offset = 0; 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); 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) { 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; int objtype, objlength;
// Make a pass over the object in order uninstantiate all superclasses // 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) { 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); reg.segment = s->seg_manager->segGet(script_nr);

View file

@ -81,50 +81,7 @@ static void init_console() {
} }
static int init_gamestate(EngineState *gamestate, sci_version_t version) { static int init_gamestate(EngineState *gamestate, sci_version_t version) {
int errc; return script_init_engine(gamestate, version);
if ((errc = script_init_engine(gamestate, version))) { // Initialize game state
int recovered = 0;
if (errc == SCI_ERROR_INVALID_SCRIPT_VERSION) {
int tversion = SCI_VERSION_FTU_NEW_SCRIPT_HEADER - ((version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) ? 0 : 1);
while (!recovered && tversion) {
printf("Trying version %d.%03x.%03d instead\n", SCI_VERSION_MAJOR(tversion),
SCI_VERSION_MINOR(tversion), SCI_VERSION_PATCHLEVEL(tversion));
errc = script_init_engine(gamestate, tversion);
if ((recovered = !errc))
version = tversion;
if (errc != SCI_ERROR_INVALID_SCRIPT_VERSION)
break;
switch (tversion) {
case SCI_VERSION_FTU_NEW_SCRIPT_HEADER - 1:
if (version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)
tversion = 0;
else
tversion = SCI_VERSION_FTU_NEW_SCRIPT_HEADER;
break;
case SCI_VERSION_FTU_NEW_SCRIPT_HEADER:
tversion = 0;
break;
}
}
if (recovered)
printf("Success.\n");
}
if (!recovered) {
fprintf(stderr, "Script initialization failed. Aborting...\n");
return 1;
}
}
return 0;
} }
SciEngine::SciEngine(OSystem *syst, const SciGameDescription *desc) SciEngine::SciEngine(OSystem *syst, const SciGameDescription *desc)
@ -222,6 +179,7 @@ Common::Error SciEngine::run() {
EngineState *gamestate = new EngineState(); EngineState *gamestate = new EngineState();
gamestate->resmgr = _resmgr; gamestate->resmgr = _resmgr;
gamestate->gfx_state = NULL; gamestate->gfx_state = NULL;
gamestate->flags = getFlags();
if (init_gamestate(gamestate, version)) if (init_gamestate(gamestate, version))
return Common::kUnknownError; return Common::kUnknownError;
@ -328,7 +286,7 @@ Common::Platform SciEngine::getPlatform() const {
} }
uint32 SciEngine::getFlags() const { uint32 SciEngine::getFlags() const {
return _gameDescription->desc.flags; return _gameDescription->flags;
} }
Common::String SciEngine::getSavegameName(int nr) const { Common::String SciEngine::getSavegameName(int nr) const {

View file

@ -81,18 +81,14 @@ enum SciGameFlags {
** SCI0 flags ** SCI0 flags
*/ */
/* Applies to all versions before 0.000.395 /* Applies to all versions before 0.000.395 (i.e. KQ4 old, XMAS 1988 and LSL2)
** Old SCI versions used two word header for script blocks (first word equal ** Old SCI versions used two word header for script blocks (first word equal
** to 0x82, meaning of the second one unknown). New SCI versions used one ** to 0x82, meaning of the second one unknown). New SCI versions used one
** word header. ** word header.
** Also, old SCI versions assign 120 degrees to left & right, and 60 to up
** and down. Later versions use an even 90 degree distribution.
*/ */
GF_OLDSCRIPTHEADER = (1 << 0), GF_SCI0_OLD = (1 << 0),
/* Applies to all versions before 0.000.395
** Earlier versions assign 120 degrees to left & right , and 60 to up and down.
** Later versions use an even 90 degree distribution.
*/
GF_OLDANGLES = (1 << 1),
/* Applies to all versions before 0.000.502 /* Applies to all versions before 0.000.502
** Old SCI versions used to interpret the third DrawPic() parameter inversely, ** Old SCI versions used to interpret the third DrawPic() parameter inversely,
@ -100,12 +96,12 @@ enum SciGameFlags {
** Also, they used 15 priority zones from 42 to 200 instead of 14 priority ** Also, they used 15 priority zones from 42 to 200 instead of 14 priority
** zones from 42 to 190. ** zones from 42 to 190.
*/ */
GF_OLDGFXFUNCTIONS = (1 << 2), GF_SCI0_OLDGFXFUNCS = (1 << 1),
/* Applies to all versions before 0.000.629 /* Applies to all versions before 0.000.629
** Older SCI versions had simpler code for GetTime() ** Older SCI versions had simpler code for GetTime()
*/ */
GF_OLDGETTIME = (1 << 3), GF_SCI0_OLDGETTIME = (1 << 2),
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -117,12 +113,12 @@ enum SciGameFlags {
** In later SCI1 versions, the argument of lofs[as] ** In later SCI1 versions, the argument of lofs[as]
** instructions is absolute rather than relative. ** instructions is absolute rather than relative.
*/ */
GF_LOFSABSOLUTE = (1 << 4), GF_LOFSABSOLUTE = (1 << 3),
/* Applies to all versions from 1.000.510 onwards /* Applies to all versions from 1.000.510 onwards
** kDoSound() is different than in earlier SCI1 versions. ** kDoSound() is different than in earlier SCI1 versions.
*/ */
GF_NEWDOSOUND = (1 << 5) GF_NEWDOSOUND = (1 << 4)
}; };
class SciEngine : public Engine { class SciEngine : public Engine {

View file

@ -66,7 +66,6 @@ enum ResourceStatus {
#define SCI_ERROR_RESOURCE_TOO_BIG 9 #define SCI_ERROR_RESOURCE_TOO_BIG 9
/* Resource size exceeds SCI_MAX_RESOURCE_SIZE */ /* Resource size exceeds SCI_MAX_RESOURCE_SIZE */
#define SCI_ERROR_UNSUPPORTED_VERSION 10 #define SCI_ERROR_UNSUPPORTED_VERSION 10
#define SCI_ERROR_INVALID_SCRIPT_VERSION 11
#define SCI_ERROR_CRITICAL SCI_ERROR_NO_RESOURCE_FILES_FOUND #define SCI_ERROR_CRITICAL SCI_ERROR_NO_RESOURCE_FILES_FOUND
/* the first critical error number */ /* the first critical error number */

View file

@ -46,30 +46,6 @@ namespace Sci {
** - "FTU" means "First To Use" ** - "FTU" means "First To Use"
*/ */
#define SCI_VERSION_FTU_NEW_SCRIPT_HEADER SCI_VERSION(0,000,395)
/* Last version known not to do this: 0.000.343
** Old SCI versions used two word header for script blocks (first word equal
** to 0x82, meaning of the second one unknown). New SCI versions used one
** word header.
*/
#define SCI_VERSION_FTU_2ND_ANGLES SCI_VERSION(0,000,395)
/* Last version known not to use this: ?
** Earlier versions assign 120 degrees to left & right , and 60 to up and down.
** Later versions use an even 90 degree distribution.
*/
#define SCI_VERSION_FTU_NEWER_DRAWPIC_PARAMETERS SCI_VERSION(0,000,502)
/* Last version known not to do this: 0.000.435
** Old SCI versions used to interpret the third DrawPic() parameter inversely,
** with the opposite default value (obviously)
*/
#define SCI_VERSION_FTU_PRIORITY_14_ZONES SCI_VERSION(0,000,502)
/* Last version known to do this: 0.000.490
* Uses 14 zones from 42 to 190 instead of 15 zones from 42 to 200.
*/
#define SCI_VERSION_FTU_NEW_GETTIME SCI_VERSION(0,000,629) #define SCI_VERSION_FTU_NEW_GETTIME SCI_VERSION(0,000,629)
/* These versions of SCI has a different set of subfunctions in GetTime() */ /* These versions of SCI has a different set of subfunctions in GetTime() */

View file

@ -308,7 +308,7 @@ int vocabulary_get_class_count(ResourceManager *resmgr) {
} }
#endif #endif
bool vocabulary_get_snames(ResourceManager *resmgr, sci_version_t version, Common::StringList &selectorNames) { bool vocabulary_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames) {
int count; int count;
Resource *r = resmgr->findResource(kResourceTypeVocab, 997, 0); Resource *r = resmgr->findResource(kResourceTypeVocab, 997, 0);
@ -324,12 +324,12 @@ bool vocabulary_get_snames(ResourceManager *resmgr, sci_version_t version, Commo
Common::String tmp((const char *)r->data + offset + 2, len); Common::String tmp((const char *)r->data + offset + 2, len);
selectorNames.push_back(tmp); selectorNames.push_back(tmp);
if ((version != 0) && (version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER)) {
// Early SCI versions used the LSB in the selector ID as a read/write // Early SCI versions used the LSB in the selector ID as a read/write
// toggle. To compensate for that, we add every selector name twice. // toggle. To compensate for that, we add every selector name twice.
if (isOldSci0)
selectorNames.push_back(tmp); selectorNames.push_back(tmp);
} }
}
return true; return true;
} }

View file

@ -195,7 +195,7 @@ int vocabulary_get_class_count(ResourceManager *resmgr);
* Fills the given StringList with selector names. * Fills the given StringList with selector names.
* Returns true upon success, false oterwise. * Returns true upon success, false oterwise.
*/ */
bool vocabulary_get_snames(ResourceManager *resmgr, sci_version_t version, Common::StringList &selectorNames); bool vocabulary_get_snames(ResourceManager *resmgr, bool isOldSci0, Common::StringList &selectorNames);
/* Look up a selector name in an array, return the index */ /* Look up a selector name in an array, return the index */
int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char *sname); int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char *sname);