diff options
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/game.cpp | 22 | ||||
-rw-r--r-- | engines/sci/engine/kernel.cpp | 112 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 48 | ||||
-rw-r--r-- | engines/sci/engine/kgraphics.cpp | 22 | ||||
-rw-r--r-- | engines/sci/engine/ksound.cpp | 10 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/script.cpp | 7 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 27 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 4 |
11 files changed, 162 insertions, 98 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 7eb4c6731a..861294cfa6 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -43,10 +43,8 @@ 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_EGA || (s->_flags & GF_SCI1_EGA)) { - int i; - - for (i = 0; i < 16; i++) { + if (!s->resmgr->isVGA()) { + for (int i = 0; i < 16; i++) { if (gfxop_set_color(s->gfx_state, &(s->ega_colors[i]), gfx_sci0_image_colors[sci0_palette][i].r, gfx_sci0_image_colors[sci0_palette][i].g, gfx_sci0_image_colors[sci0_palette][i].b, 0, -1, -1)) { return 1; @@ -97,7 +95,7 @@ int _reset_graphics_input(EngineState *s) { font_nr = -1; do { resource = s->resmgr->testResource(ResourceId(kResourceTypeFont, ++font_nr)); - } while ((!resource) && (font_nr < sci_max_resource_nr[s->resmgr->_sciVersion])); + } while ((!resource) && (font_nr < 65536)); if (!resource) { debug(2, "No text font was found."); @@ -111,7 +109,7 @@ int _reset_graphics_input(EngineState *s) { 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) { + if (s->resmgr->isVGA()) { // This bit sets the foreground and background colors in VGA SCI games gfx_color_t fgcolor; gfx_color_t bgcolor; @@ -181,7 +179,7 @@ static void _free_graphics_input(EngineState *s) { } int game_init_sound(EngineState *s, int sound_flags) { - if (s->resmgr->_sciVersion >= SCI_VERSION_01_EGA) + if (s->resmgr->_sciVersion >= SCI_VERSION_01) sound_flags |= SFX_STATE_FLAG_MULTIPLAY; s->sfx_init_flags = sound_flags; @@ -259,7 +257,7 @@ static int create_class_table_sci0(EngineState *s) { Resource *script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scriptnr), 0); if (script) { - if (s->_flags & GF_SCI0_OLD) + if (s->_kernel->hasOldScriptHeader()) magic_offset = seeker = 2; else magic_offset = seeker = 0; @@ -329,6 +327,9 @@ int script_init_engine(EngineState *s) { s->kernel_opt_flags = 0; + s->_kernel = new Kernel(s->resmgr); + s->_vocabulary = new Vocabulary(s->resmgr); + if (s->_version >= SCI_VERSION_1_1) result = create_class_table_sci11(s); else @@ -369,9 +370,6 @@ int script_init_engine(EngineState *s) { 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->_vocabulary = new Vocabulary(s->resmgr); - s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING; s->bp_list = NULL; // No breakpoints defined @@ -466,7 +464,7 @@ int game_init(EngineState *s) { s->successor = NULL; // No successor s->_statusBarText.clear(); // Status bar is blank s->status_bar_foreground = 0; - s->status_bar_background = (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) ? 255 : 15; + s->status_bar_background = !s->resmgr->isVGA() ? 15 : 255; SystemString *str = &s->sys_strings->strings[SYS_STRING_PARSER_BASE]; str->name = strdup("parser-base"); diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 80071b2847..dd2d0dc61a 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -367,59 +367,102 @@ static const char *argtype_description[] = { "Arithmetic" }; -Kernel::Kernel(ResourceManager *resmgr, bool isOldSci0) : _resmgr(resmgr) { +Kernel::Kernel(ResourceManager *resmgr) : _resmgr(resmgr) { memset(&_selectorMap, 0, sizeof(_selectorMap)); // FIXME: Remove this once/if we C++ify selector_map_t - loadSelectorNames(isOldSci0); - mapSelectors(); // Map a few special selectors for later use + detectSciFeatures(); // must be called before loadSelectorNames() + loadSelectorNames(); + mapSelectors(); // Map a few special selectors for later use loadOpcodes(); loadKernelNames(); - mapFunctions(); // Map the kernel functions - - // SCI0 games using old graphics functions (before version 0.000.502) did not have a - // motionCue selector - _oldGfxFunctions = (_selectorMap.motionCue == -1 && _resmgr->_sciVersion == SCI_VERSION_0); - - // SCI1 games which use absolute lofs have the egoMoveSpeed selector - _hasLofsAbsolute = (_selectorMap.egoMoveSpeed != -1 && _resmgr->_sciVersion < SCI_VERSION_1_1); - - printAutoDetectedFeatures(); + mapFunctions(); // Map the kernel functions } Kernel::~Kernel() { } -void Kernel::printAutoDetectedFeatures() { - if (_oldGfxFunctions) - printf("Kernel auto-detection: game found to be using old graphics functions\n"); +void Kernel::detectSciFeatures() { + Resource *r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); + + if (!r) // No such resource? + error("Kernel: Could not retrieve selector names"); + + int count = READ_LE_UINT16(r->data) + 1; // Counter is slightly off + features = 0; + + // Initialize features based on SCI version + if (_resmgr->_sciVersion == SCI_VERSION_0) { + features |= kFeatureOldScriptHeader; + features |= kFeatureOldGfxFunctions; + } + + for (int i = 0; i < count; i++) { + int offset = READ_LE_UINT16(r->data + 2 + i * 2); + int len = READ_LE_UINT16(r->data + offset); + + Common::String tmp((const char *)r->data + offset + 2, len); + + if (tmp == "setTarget") // "motionInited" can also be used + features &= ~kFeatureOldScriptHeader; + + if (tmp == "motionCue") + features &= ~kFeatureOldGfxFunctions; + + if (tmp == "egoMoveSpeed" && _resmgr->_sciVersion < SCI_VERSION_1_1) + features |= kFeatureLofsAbsolute; + + if (tmp == "sightAngle" && _resmgr->_sciVersion == SCI_VERSION_0) + features |= kFeatureSci0Sci1Table; + + if (tmp == "setVol") + features |= kFeatureSci1Sound; + + if (tmp == "nodePtr") + features |= kFeatureSci01Sound; + } + + if (features & kFeatureSci1Sound) + features &= ~kFeatureSci01Sound; + + printf("Kernel auto-detected features:\n"); + + printf("Script block headers: "); + if (features & kFeatureOldScriptHeader) + printf("old\n"); else - printf("Kernel auto-detection: game found to be using newer graphics functions\n"); + printf("new\n"); - if (_hasLofsAbsolute) - printf("Kernel auto-detection: game found to be using absolute parameters for lofs\n"); + printf("Graphics functions: "); + if (features & kFeatureOldGfxFunctions) + printf("old\n"); else - printf("Kernel auto-detection: game found to be using relative parameters for lofs\n"); + printf("new\n"); - if (_selectorMap.setVol != -1) - printf("Kernel auto-detection: using SCI1 sound functions\n"); - else if (_selectorMap.nodePtr != -1) - printf("Kernel auto-detection: using SCI01 sound functions\n"); + printf("lofs parameters: "); + if (features & kFeatureLofsAbsolute) + printf("absolute\n"); else - printf("Kernel auto-detection: using SCI0 sound functions\n"); + printf("relative\n"); - if (_resmgr->_sciVersion == SCI_VERSION_0 && _selectorMap.sightAngle != -1) - printf("Kernel auto-detection: found SCI0 game using a SCI1 kernel table\n"); -} + printf("Sound functions: "); + if (features & kFeatureSci1Sound) + printf("SCI1\n"); + else if (features & kFeatureSci01Sound) + printf("SCI01\n"); + else + printf("SCI0\n"); -void Kernel::loadSelectorNames(bool isOldSci0) { - int count; + if (features & kFeatureSci0Sci1Table) + printf("Found SCI0 game using a SCI1 kernel table\n"); +} +void Kernel::loadSelectorNames() { Resource *r = _resmgr->findResource(ResourceId(kResourceTypeVocab, VOCAB_RESOURCE_SNAMES), 0); if (!r) // No such resource? error("Kernel: Could not retrieve selector names"); - count = READ_LE_UINT16(r->data) + 1; // Counter is slightly off + int count = READ_LE_UINT16(r->data) + 1; // Counter is slightly off for (int i = 0; i < count; i++) { int offset = READ_LE_UINT16(r->data + 2 + i * 2); @@ -431,7 +474,7 @@ void Kernel::loadSelectorNames(bool isOldSci0) { // 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. - if (isOldSci0) + if (features & kFeatureOldScriptHeader) _selectorNames.push_back(tmp); } } @@ -771,7 +814,7 @@ void Kernel::setDefaultKernelNames() { // Check if we have a SCI01 game which uses a SCI1 kernel table (e.g. the KQ1 demo // and full version). We do this by checking if the sightAngle selector exists, as no // SCI0 game seems to have it - if (_selectorMap.sightAngle != -1 && isSci0) + if (features & kFeatureSci0Sci1Table) isSci0 = false; _kernelNames.resize(SCI_KNAMES_DEFAULT_ENTRIES_NR + (isSci0 ? 4 : 0)); @@ -832,8 +875,7 @@ bool Kernel::loadKernelNames() { switch (_resmgr->_sciVersion) { case SCI_VERSION_0: - case SCI_VERSION_01_EGA: - case SCI_VERSION_01_VGA: + case SCI_VERSION_01: case SCI_VERSION_01_VGA_ODD: case SCI_VERSION_1: case SCI_VERSION_1_1: diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 9c92519cf0..4814bd0317 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -55,9 +55,18 @@ struct KernelFuncWithSignature { Common::String orig_name; /**< Original name, in case we couldn't map it */ }; +enum AutoDetectedFeatures { + kFeatureOldScriptHeader = 1 << 0, + kFeatureOldGfxFunctions = 1 << 1, + kFeatureLofsAbsolute = 1 << 2, + kFeatureSci01Sound = 1 << 3, + kFeatureSci1Sound = 1 << 4, + kFeatureSci0Sci1Table = 1 << 5 +}; + class Kernel { public: - Kernel(ResourceManager *resmgr, bool isOldSci0); + Kernel(ResourceManager *resmgr); ~Kernel(); uint getOpcodesSize() const { return _opcodes.size(); } @@ -84,20 +93,40 @@ public: bool hasKernelFunction(const char *functionName) const; /** + * 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 + * to 0x82, meaning of the second one unknown). New SCI versions used one + * 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. + */ + bool hasOldScriptHeader() const { return (features & kFeatureOldScriptHeader); } + + /** * Applies to all versions before 0.000.502 * Old SCI versions used to interpret the third DrawPic() parameter inversely, * with the opposite default value (obviously). * Also, they used 15 priority zones from 42 to 200 instead of 14 priority * zones from 42 to 190. */ - bool usesOldGfxFunctions() const { return _oldGfxFunctions; } + bool usesOldGfxFunctions() const { return (features & kFeatureOldGfxFunctions); } /** * Applies to all SCI1 versions after 1.000.200 * In late SCI1 versions, the argument of lofs[as] instructions * is absolute rather than relative. */ - bool hasLofsAbsolute() const { return _hasLofsAbsolute; } + bool hasLofsAbsolute() const { return (features & kFeatureLofsAbsolute); } + + /** + * Determines if the game is using SCI01 sound functions + */ + bool usesSci01SoundFunctions() const { return (features & kFeatureSci01Sound); } + + /** + * Determines if the game is using SCI1 sound functions + */ + bool usesSci1SoundFunctions() const { return (features & kFeatureSci1Sound); } // Script dissection/dumping functions void dissectScript(int scriptNumber, Vocabulary *vocab); @@ -127,17 +156,17 @@ private: /** * Loads the kernel selector names. */ - void loadSelectorNames(bool isOldSci0); + void loadSelectorNames(); /** - * Prints auto-detected features from selectors + * Maps special selectors */ - void printAutoDetectedFeatures(); + void mapSelectors(); /** - * Maps special selectors + * Detects SCI features based on the existence of certain selectors */ - void mapSelectors(); + void detectSciFeatures(); /** * Maps kernel functions @@ -151,8 +180,7 @@ private: bool loadOpcodes(); ResourceManager *_resmgr; - bool _oldGfxFunctions; - bool _hasLofsAbsolute; + uint32 features; // Kernel-related lists /** diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 487813a4c7..d46ce3b938 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -269,7 +269,7 @@ void graph_restore_box(EngineState *s, reg_t handle) { } PaletteEntry get_pic_color(EngineState *s, int color) { - if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA) + if (!s->resmgr->isVGA()) return s->ega_colors[color].visual; if (color == -1 || color == 255) // -1 occurs in Eco Quest 1. Not sure if this is the best approach, but it seems to work @@ -286,7 +286,7 @@ PaletteEntry get_pic_color(EngineState *s, int color) { static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int control) { gfx_color_t retval; - if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA) { + if (!s->resmgr->isVGA()) { retval = s->ega_colors[(color >=0 && color < 16)? color : 0]; gfxop_set_color(s->gfx_state, &retval, (color < 0) ? -1 : retval.visual.r, retval.visual.g, retval.visual.b, (color == -1) ? 255 : 0, priority, control); @@ -502,7 +502,7 @@ reg_t kGraph(EngineState *s, int funct_nr, int argc, reg_t *argv) { case K_GRAPH_GET_COLORS_NR: - return make_reg(0, s->resmgr->_sciVersion < SCI_VERSION_01_VGA ? 0x10 : 0x100); + return make_reg(0, !s->resmgr->isVGA() ? 0x10 : 0x100); break; case K_GRAPH_DRAW_LINE: { @@ -696,7 +696,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->_kernel->hasOldScriptHeader()) { if (angle < 45) loop = 3; else if (angle < 136) @@ -2502,7 +2502,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { int16 bgColor = (argc > 8 + argextra) ? argv[8 + argextra].toSint16() : 255; if (bgColor >= 0) { - if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA) + if (!s->resmgr->isVGA()) bgcolor.visual = get_pic_color(s, MIN<int>(bgColor, 15)); else bgcolor.visual = get_pic_color(s, bgColor); @@ -2528,7 +2528,7 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { black.alpha = 0; black.control = -1; black.priority = -1; - lWhite.visual = get_pic_color(s, s->resmgr->_sciVersion < SCI_VERSION_01_VGA ? 15 : 255); + lWhite.visual = get_pic_color(s, !s->resmgr->isVGA() ? 15 : 255); lWhite.mask = GFX_MASK_VISUAL; lWhite.alpha = 0; lWhite.priority = -1; @@ -3149,7 +3149,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { bg_color = port->_bgcolor; // TODO: in SCI1VGA the default colors for text and background are #0 (black) // SCI0 case should be checked - if (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) { + if (s->resmgr->isVGA()) { // This priority check fixes the colors in the menus in KQ5 // TODO/FIXME: Is this correct? if (color0.priority >= 0) @@ -3191,10 +3191,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_color(%d)\n", temp); - if ((s->resmgr->_sciVersion < SCI_VERSION_01_VGA) && temp >= 0 && temp <= 15) + if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) color0 = (s->ega_colors[temp]); else - if (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA && temp >= 0 && temp < 256) { + if (s->resmgr->isVGA() && temp >= 0 && temp < 256) { color0.visual = get_pic_color(s, temp); color0.mask = GFX_MASK_VISUAL; } else @@ -3208,10 +3208,10 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { temp = argv[argpt++].toSint16(); debugC(2, kDebugLevelGraphics, "Display: set_bg_color(%d)\n", temp); - if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA && temp >= 0 && temp <= 15) + if (!s->resmgr->isVGA() && temp >= 0 && temp <= 15) bg_color = s->ega_colors[temp]; else - if ((s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) && temp >= 0 && temp <= 256) { + if (s->resmgr->isVGA() && temp >= 0 && temp <= 256) { bg_color.visual = get_pic_color(s, temp); bg_color.mask = GFX_MASK_VISUAL; } else diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index ef02f8ee21..7614b2bc10 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 SongHandle handle; int cue; - if (s->_version >= SCI_VERSION_01_EGA) + if (s->_version >= SCI_VERSION_01) return; /* SCI01 and later explicitly poll for everything */ @@ -940,14 +940,14 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { case SI_ABSOLUTE_CUE: signal = cue; - fprintf(stderr, "[CUE] %04x:%04x Absolute Cue: %d\n", + debugC(2, kDebugLevelSound, "[CUE] %04x:%04x Absolute Cue: %d\n", PRINT_REG(obj), signal); PUT_SEL32V(obj, signal, signal); break; case SI_RELATIVE_CUE: - fprintf(stderr, "[CUE] %04x:%04x Relative Cue: %d\n", + debugC(2, kDebugLevelSound, "[CUE] %04x:%04x Relative Cue: %d\n", PRINT_REG(obj), cue); PUT_SEL32V(obj, dataInc, cue); @@ -982,9 +982,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { * Used for synthesized music playback */ reg_t kDoSound(EngineState *s, int funct_nr, int argc, reg_t *argv) { - if (s->_kernel->_selectorMap.setVol != -1) + if (s->_kernel->usesSci1SoundFunctions()) return kDoSound_SCI1(s, funct_nr, argc, argv); - else if (s->_kernel->_selectorMap.nodePtr != -1) + else if (s->_kernel->usesSci01SoundFunctions()) return kDoSound_SCI01(s, funct_nr, argc, argv); else return kDoSound_SCI0(s, funct_nr, argc, argv); diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index ade0304683..f44af2b1cd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -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->_kernel->hasOldScriptHeader()) buf += 2; do { @@ -693,7 +693,7 @@ int _reset_graphics_input(EngineState *s); static void reconstruct_sounds(EngineState *s) { Song *seeker; - SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01_EGA ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0; + SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0; seeker = s->_sound._songlib._lib; diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index e78f3fd77f..b7529c33bd 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -91,9 +91,8 @@ opcode_format g_opcode_formats[128][4] = { void script_adjust_opcode_formats(int res_version) { switch (res_version) { case SCI_VERSION_0: - case SCI_VERSION_01_EGA: break; - case SCI_VERSION_01_VGA: + case SCI_VERSION_01: case SCI_VERSION_01_VGA_ODD: case SCI_VERSION_1: case SCI_VERSION_1_1: @@ -200,10 +199,6 @@ void Kernel::mapSelectors() { FIND_SELECTOR(printLang); FIND_SELECTOR(subtitleLang); FIND_SELECTOR(parseLang); - FIND_SELECTOR(motionCue); - FIND_SELECTOR(sightAngle); - FIND_SELECTOR(setVol); - FIND_SELECTOR(egoMoveSpeed); } void Kernel::dumpScriptObject(char *data, int seeker, int objsize) { diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index a524ddd365..d5f0a21385 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -243,7 +243,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod int stackframe = (scr[pos.offset + 2] >> 1) + (*debugState.p_restadjust); int argc = ((*debugState.p_sp)[- stackframe - 1]).offset; - if (!(s->_flags & GF_SCI0_OLD)) + if (!s->_kernel->hasOldScriptHeader()) argc += (*debugState.p_restadjust); printf(" Kernel params: ("); diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index d81768c9c8..74486ef015 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -138,7 +138,7 @@ void SegManager::setScriptSize(Script &scr, EngineState *s, int script_nr) { 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->_kernel->hasOldScriptHeader()) { 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) { diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 09ed541d17..c6643b8a90 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -961,7 +961,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->_kernel->hasOldScriptHeader()) { xs->sp -= restadjust; s->r_amp_rest = 0; // We just used up the restadjust, remember? } @@ -971,7 +971,7 @@ void run_vm(EngineState *s, int restoring) { } else { int argc = ASSERT_ARITHMETIC(xs->sp[0]); - if (!(s->_flags & GF_SCI0_OLD)) + if (!s->_kernel->hasOldScriptHeader()) argc += restadjust; if (s->_kernel->_kernelFuncs[opparams[0]].signature @@ -988,7 +988,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = &(s->_executionStack.back()); s->_executionStackPosChanged = true; - if (!(s->_flags & GF_SCI0_OLD)) + if (!s->_kernel->hasOldScriptHeader()) restadjust = s->r_amp_rest; } @@ -1211,10 +1211,15 @@ void run_vm(EngineState *s, int restoring) { case 0x3a: // lofss r_temp.segment = xs->addr.pc.segment; - if (s->_kernel->hasLofsAbsolute()) - r_temp.offset = opparams[0]; - else - r_temp.offset = xs->addr.pc.offset + opparams[0]; + if (s->_version >= SCI_VERSION_1_1) { + r_temp.offset = opparams[0] + local_script->script_size; + } else { + if (s->_kernel->hasLofsAbsolute()) + r_temp.offset = opparams[0]; + else + r_temp.offset = xs->addr.pc.offset + opparams[0]; + } + #ifndef DISABLE_VALIDATIONS if (r_temp.offset >= code_buf_size) { error("VM: lofss operation overflowed: %04x:%04x beyond end" @@ -1495,7 +1500,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->_kernel->hasOldScriptHeader()) selector_id &= ~1; if (!obj) { @@ -1654,7 +1659,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->_kernel->hasOldScriptHeader()) { // int locals_nr = READ_LE_UINT16(script->data); @@ -1830,7 +1835,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->_flags & GF_SCI0_OLD) ? 2 : 0); + reg_t reg = make_reg(seg, s->_kernel->hasOldScriptHeader() ? 2 : 0); int objtype, objlength; Script *scr = s->seg_manager->getScript(seg); @@ -1874,7 +1879,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->_kernel->hasOldScriptHeader() ? 2 : 0); reg.segment = s->seg_manager->segGet(script_nr); Script *scr = script_locate_by_segment(s, reg.segment); diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index adaa064a6c..a3fabbe44b 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -203,10 +203,6 @@ struct selector_map_t { Selector printLang; /**< Used for i18n */ Selector subtitleLang; Selector parseLang; - Selector motionCue; // Used to detect newer graphics functions semantics. - Selector sightAngle; // Used to detect some SCI0/SCI01 games which need a SCI1 table - Selector setVol; // Used to detect newer sound semantics - Selector egoMoveSpeed; // Used to detect SCI1 games which use absolute values in lofs }; // A reference to an object's variable. |