Simplified SCI versions to be SCI version generations, and fixed some game entries in the process. Also, added a sanity check for invalid game entries

svn-id: r40596
This commit is contained in:
Filippos Karapetis 2009-05-15 09:04:21 +00:00
parent adaa0472c5
commit 565cfa074d
16 changed files with 588 additions and 403 deletions

View File

@ -99,8 +99,7 @@ bool Console::cmdGetVersion(int argc, const char **argv) {
DebugPrintf("Resource file version: %s\n", sci_version_types[_vm->getResMgr()->_sciVersion]);
DebugPrintf("Emulated interpreter version: %d.%03d.%03d\n",
SCI_VERSION_MAJOR(ver), SCI_VERSION_MINOR(ver), SCI_VERSION_PATCHLEVEL(ver));
DebugPrintf("Emulated interpreter version: %s\n", versionNames[ver]);
return true;
}

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,7 @@ int _reset_graphics_input(EngineState *s) {
} else {
resource = s->resmgr->findResource(kResourceTypePalette, 999, 1);
if (resource) {
if (s->version < SCI_VERSION(1, 001, 000))
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));
@ -388,12 +388,12 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->kernel_opt_flags = 0;
s->version = version;
if (s->version >= SCI_VERSION(1, 001, 000))
if (s->version >= SCI_VERSION_1_1)
result = create_class_table_sci11(s);
else
result = create_class_table_sci0(s);
s->seg_manager = new SegManager(s->version >= SCI_VERSION(1, 001, 000));
s->seg_manager = new SegManager(s->version >= SCI_VERSION_1_1);
s->gc_countdown = GC_INTERVAL - 1;
if (result) {
@ -444,7 +444,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, 001, 000))
if (s->flags & GF_SCI1_LOFSABSOLUTE && s->version < SCI_VERSION_1_1)
s->seg_manager->setExportWidth(1);
else
s->seg_manager->setExportWidth(0);

View File

@ -40,7 +40,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 = SCI_VERSION_MAJOR(s->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

View File

@ -309,7 +309,7 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
case 2 :
case 4 :
if (s->version >= SCI_VERSION(1, 1, 0) || (s->flags & GF_SCI1_NEWSETCURSOR)) {
if (s->version >= SCI_VERSION_1_1 || (s->flags & GF_SCI1_NEWSETCURSOR)) {
GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, Common::Point(UKPV(0), UKPV(1))));
} else {
if (SKPV_OR_ALT(1, 1)) {
@ -1132,7 +1132,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,000,256))
if (s->version <= SCI_VERSION_0)
--absrect.top; // Compensate for early SCI OB1 'bug'
#endif
@ -1343,7 +1343,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, 001, 000) && !strcmp(text, " Delete ")) {
s->version < SCI_VERSION_1_1 && !strcmp(text, " Delete ")) {
PUT_SEL32V(obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled);
}
}

View File

@ -272,7 +272,7 @@ static void bresenham_autodetect(EngineState *s) {
}
buf = s->seg_manager->getScript(fptr.segment, SEG_ID)->buf + fptr.offset;
handle_movecnt = (SCI_VERSION_MAJOR(s->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");
@ -291,7 +291,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 (SCI_VERSION_MAJOR(s->version) > 0)
if (s->version > SCI_VERSION_0)
signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE;
if (handle_movecnt == UNINITIALIZED)
@ -378,7 +378,7 @@ reg_t kDoBresen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
completed = 1;
}
if (SCI_VERSION_MAJOR(s->version) > 0)
if (s->version > SCI_VERSION_0)
if (completed)
invoke_selector(INV_SEL(mover, moveDone, 0), 0);

View File

@ -137,7 +137,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
song_handle_t handle;
int cue;
if (s->version >= SCI_VERSION(1,000,000))
if (s->version >= SCI_VERSION_01)
return;
/* SCI01 and later explicitly poll for everything */
@ -983,9 +983,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,001,000) || 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(1,000,000))
else if (s->version >= SCI_VERSION_01)
return kDoSound_SCI01(s, funct_nr, argc, argv);
else
return kDoSound_SCI0(s, funct_nr, argc, argv);

View File

@ -561,7 +561,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,001,000))
if (s->version >= SCI_VERSION_1_1)
heap = s->resmgr->findResource(kResourceTypeHeap, scr->nr, 0);
memcpy(scr->buf, script->data, script->size);

View File

@ -1184,7 +1184,7 @@ int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) {
selectors = obj->_variables.size();
if (s->version < SCI_VERSION(1, 001, 000))
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)) {
@ -2768,8 +2768,7 @@ int c_sci_version(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
return 1;
}
sciprintf("Emulating SCI version %d.%03d.%03d\n", SCI_VERSION_MAJOR(s->version), SCI_VERSION_MINOR(s->version),
SCI_VERSION_PATCHLEVEL(s->version));
sciprintf("Emulating SCI version %s\n", versionNames[s->version]);
return 0;
}

View File

@ -143,14 +143,14 @@ 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, 001, 000) && !heap)) {
if (!script || (s->version >= SCI_VERSION_1_1 && !heap)) {
sciprintf("%s: failed to load %s\n", __FUNCTION__, !script ? "script" : "heap");
return;
}
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)) {
} else if (s->version < SCI_VERSION_1_1) {
scr.buf_size = script->size;
} else {
scr.buf_size = script->size + heap->size;
@ -198,7 +198,7 @@ int SegManager::initialiseScript(Script &scr, EngineState *s, int script_nr) {
scr.obj_indices = new IntMapper();
if (s->version >= SCI_VERSION(1, 001, 000))
if (s->version >= SCI_VERSION_1_1)
scr.heap_start = scr.buf + scr.script_size;
else
scr.heap_start = scr.buf;

View File

@ -1238,7 +1238,7 @@ void run_vm(EngineState *s, int restoring) {
case 0x39: // lofsa
s->r_acc.segment = xs->addr.pc.segment;
if (s->version >= SCI_VERSION(1, 001, 000)) {
if (s->version >= SCI_VERSION_1_1) {
s->r_acc.offset = opparams[0] + local_script->script_size;
} else {
if (s->flags & GF_SCI1_LOFSABSOLUTE)
@ -1475,7 +1475,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, 001, 000)) {
if (s->version < SCI_VERSION_1_1) {
int varnum = obj->variable_names_nr;
int selector_name_offset = varnum * 2 + SCRIPT_SELECTOR_OFFSET;
int i;
@ -1528,7 +1528,7 @@ static SelectorType _lookup_selector_function(EngineState *s, int seg_id, Object
if (index >= 0) {
if (fptr) {
if (s->version < SCI_VERSION(1, 001, 000))
if (s->version < SCI_VERSION_1_1)
*fptr = make_reg(obj->pos.segment, READ_LE_UINT16((byte *)(obj->base_method + index + obj->methods_nr + 1)));
else
*fptr = make_reg(obj->pos.segment, READ_LE_UINT16((byte *)(obj->base_method + index * 2 + 2)));
@ -1651,13 +1651,13 @@ 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, 001, 000))
if (s->version >= SCI_VERSION_1_1)
*heap = s->resmgr->findResource(kResourceTypeHeap, script_nr, 0);
if (!*script || (s->version >= SCI_VERSION(1, 001, 000) && !heap)) {
if (!*script || (s->version >= SCI_VERSION_1_1 && !heap)) {
sciprintf("Script 0x%x requested but not found\n", script_nr);
//script_debug_flag = script_error_flag = 1;
if (s->version >= SCI_VERSION(1, 001, 000)) {
if (s->version >= SCI_VERSION_1_1) {
if (*heap)
sciprintf("Inconsistency: heap resource WAS found\n");
else if (*script)
@ -1894,7 +1894,7 @@ int script_instantiate_sci11(EngineState *s, int script_nr) {
}
int script_instantiate(EngineState *s, int script_nr) {
if (s->version >= SCI_VERSION(1, 001, 000))
if (s->version >= SCI_VERSION_1_1)
return script_instantiate_sci11(s, script_nr);
else
return script_instantiate_sci0(s, script_nr);
@ -1963,7 +1963,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, 001, 000))
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");

View File

@ -174,12 +174,12 @@ public:
#define SCRIPT_FUNCTAREAPTR_MAGIC 8 -8
/** Offset of the name pointer */
#define SCRIPT_NAME_OFFSET (s->version < SCI_VERSION(1,001,000) ? 14 -8 : 16)
#define SCRIPT_NAME_SELECTOR (s->version < SCI_VERSION(1,001,000) ? 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,001,000) ? 12 -8 : 14)
#define SCRIPT_INFO_SELECTOR (s->version < SCI_VERSION(1,001,000) ? 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
@ -191,18 +191,18 @@ public:
/** Magical object identifier */
#define SCRIPT_OBJECT_MAGIC_NUMBER 0x1234
/** Offset of this identifier */
#define SCRIPT_OBJECT_MAGIC_OFFSET (s->version < SCI_VERSION(1,001,000) ? -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,001,000) ? 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,001,000) ? 0 : 5)
#define SCRIPT_SUPERCLASS_SELECTOR (s->version < SCI_VERSION(1,001,000) ? 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 */
@ -279,16 +279,16 @@ struct CodeBlock {
};
#define VM_OBJECT_GET_VARSELECTOR(obj, i) \
(s->version < SCI_VERSION(1,001,000) ? \
(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,001,000) ? \
(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,001,000) ? \
(s->version < SCI_VERSION_1_1 ? \
make_reg(obj->pos.segment, \
READ_LE_UINT16((byte *) (obj->base_method \
+ obj->methods_nr + 1 \

View File

@ -339,15 +339,16 @@ bool getSciVersionFromString(Common::String versionString, int *version, Common:
char *endptr[3];
const char *ver = mappedVersion.c_str();
int major = strtol(ver, &endptr[0], 10);
int minor = strtol(ver + 2, &endptr[1], 10);
int patchlevel = strtol(ver + 6, &endptr[2], 10);
//int minor = strtol(ver + 2, &endptr[1], 10);
//int patchlevel = strtol(ver + 6, &endptr[2], 10);
if (endptr[0] != ver + 1 || endptr[1] != ver + 5 || *endptr[2] != '\0') {
warning("Failed to parse version string '%s'", ver);
return true;
}
*version = SCI_VERSION(major, minor, patchlevel);
//printf("Detected version: %s, parsed version: %s\n", versionString, ver);
*version = major;
return false;
}

View File

@ -181,6 +181,42 @@ Common::Error SciEngine::run() {
gamestate->gfx_state = NULL;
gamestate->flags = getFlags();
// 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 ||
gamestate->flags & GF_SCI1_NEWSETCURSOR) {
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) {
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 ||
gamestate->flags & GF_SCI1_NEWSETCURSOR) {
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) {
error("This game entry is erroneous. It's marked as SCI1.1/SCI32, but it has SCI0 flags set");
}
// SCI1.1 / SCI32
} else {
error ("Unknown SCI version in game entry");
}
if (init_gamestate(gamestate, version))
return Common::kUnknownError;
@ -243,10 +279,7 @@ Common::Error SciEngine::run() {
return Common::kUnknownError;
}
printf("Emulating SCI version %d.%03d.%03d\n",
SCI_VERSION_MAJOR(version),
SCI_VERSION_MINOR(version),
SCI_VERSION_PATCHLEVEL(version));
printf("Emulating SCI version %s\n", versionNames[version]);
game_run(&gamestate); // Run the game

View File

@ -77,13 +77,17 @@ enum SciGameVersions {
SCI_VERSION_32 = 8
};
#define SCI_VERSION(_major_, _minor_, _patchlevel_) (((_major_)<<20) | ((_minor_)<<10) | _patchlevel_)
/* This allows version numbers to be compared directly */
#define SCI_VERSION_MAJOR(_version_) ((_version_) >> 20)
#define SCI_VERSION_MINOR(_version_) (((_version_) >> 10) & 0x3ff)
#define SCI_VERSION_PATCHLEVEL(_version_) ((_version_) & 0x3ff)
#define SCI_VERSION_IGNORE_PATCHLEVEL(_version_) ((_version) & ~0x3ff)
static const char *versionNames[9] = {
"Autodetected",
"SCI0",
"SCI01 EGA",
"SCI01 VGA",
"SCI01 VGA ODD",
"SCI1 early",
"SCI1 late",
"SCI1.1",
"SCI32"
};
enum SciGameFlags {
/*

View File

@ -496,7 +496,7 @@ void vocabulary_get_knames(ResourceManager *resmgr, Common::StringList &names) {
// HACK: KQ5 needs the SCI1 default vocabulary names to work correctly.
// Having more vocabulary names (like in SCI1) doesn't seem to have any
// ill effects, other than resulting in unmapped functions towards the
// end, which are never used by the game interpteter anyway
// end, which are never used by the game interpreter anyway
// return vocabulary_get_knames0(resmgr, count);
case SCI_VERSION_1_EARLY:
case SCI_VERSION_1_LATE: