diff options
-rw-r--r-- | engines/sci/engine/game.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/kscripts.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 5 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.h | 21 | ||||
-rw-r--r-- | engines/sci/engine/segment.cpp | 19 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 10 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 6 |
8 files changed, 27 insertions, 50 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 721ba31f24..4ac2a22531 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -218,11 +218,6 @@ int script_init_engine(EngineState *s) { s->restarting_flags = SCI_GAME_IS_NOT_RESTARTING; - if (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE) - s->_segMan->setExportAreWide(true); - else - s->_segMan->setExportAreWide(false); - debug(2, "Engine initialized"); return 0; diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index 99cfe2c01f..ba29f64966 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -187,12 +187,11 @@ reg_t kScriptID(EngineState *s, int argc, reg_t *argv) { return argv[0]; SegmentId scriptSeg = s->_segMan->getScriptSegment(script, SCRIPT_GET_LOAD); - Script *scr; if (!scriptSeg) return NULL_REG; - scr = s->_segMan->getScript(scriptSeg); + Script *scr = s->_segMan->getScript(scriptSeg); if (!scr->_numExports) { // FIXME: Is this fatal? This occurs in SQ4CD @@ -205,7 +204,7 @@ reg_t kScriptID(EngineState *s, int argc, reg_t *argv) { return NULL_REG; } - return make_reg(scriptSeg, s->_segMan->validateExportFunc(index, scriptSeg)); + return make_reg(scriptSeg, scr->validateExportFunc(index)); } reg_t kDisposeScript(EngineState *s, int argc, reg_t *argv) { diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index ce905ac008..dd7e7221fe 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -221,9 +221,9 @@ void syncWithSerializer(Common::Serializer &s, reg_t &obj) { } void SegManager::saveLoadWithSerializer(Common::Serializer &s) { - s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be reserved_id - s.syncAsSint32LE(_exportsAreWide); - s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be gc_mark_bits + s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be reserved_id + s.skip(4, VER(18), VER(18)); // OBSOLETE: Used to be _exportsAreWide + s.skip(4, VER(9), VER(9)); // OBSOLETE: Used to be gc_mark_bits if (s.isLoading()) { // Reset _scriptSegMap, to be restored below diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 12398ce686..b18d76e1a7 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -49,7 +49,6 @@ SegManager::SegManager(ResourceManager *resMan) { String_seg_id = 0; #endif - _exportsAreWide = false; _resMan = resMan; createClassTable(); @@ -340,10 +339,6 @@ bool SegManager::check(SegmentId seg) { return true; } -void SegManager::setExportAreWide(bool flag) { - _exportsAreWide = flag; -} - // return the seg if script_id is valid and in the map, else 0 SegmentId SegManager::getScriptSegment(int script_id) const { return _scriptSegMap.getVal(script_id, 0); diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index c8c386cb2a..e8bbdbdb3f 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -96,17 +96,6 @@ public: void reconstructScripts(EngineState *s); /** - * Validate whether the specified public function is exported by - * the script in the specified segment. - * @param pubfunct Index of the function to validate - * @param seg Segment ID of the script the check is to - * be performed for - * @return NULL if the public function is invalid, its - * offset into the script's segment otherwise - */ - uint16 validateExportFunc(int pubfunct, SegmentId seg); - - /** * Determines the segment occupied by a certain script, if any. * @param script_nr Number of the script to look up * @return The script's segment ID, or 0 on failure @@ -125,7 +114,7 @@ public: // TODO: document this reg_t lookupScriptExport(int script_nr, int export_index) { SegmentId seg = getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD); - return make_reg(seg, validateExportFunc(export_index, seg)); + return make_reg(seg, getScript(seg)->validateExportFunc(export_index)); } // TODO: document this @@ -171,12 +160,6 @@ public: */ void scriptInitialiseLocals(reg_t location); - /** - * Tells the segment manager whether exports are wide (32-bit) or not. - * @param flag true if exports are wide, false otherwise - */ - void setExportAreWide(bool flag); - // 2. Clones /** @@ -472,8 +455,6 @@ private: ResourceManager *_resMan; - bool _exportsAreWide; - SegmentId Clones_seg_id; ///< ID of the (a) clones segment SegmentId Lists_seg_id; ///< ID of the (a) list segment SegmentId Nodes_seg_id; ///< ID of the (a) node segment diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 0c6bb93aed..ab1a68d165 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -26,6 +26,7 @@ #include "common/endian.h" #include "sci/sci.h" +#include "sci/engine/features.h" #include "sci/engine/segment.h" #include "sci/engine/seg_manager.h" #include "sci/engine/state.h" @@ -366,22 +367,18 @@ void Script::setExportTableOffset(int offset) { } } -// TODO: This method should be Script method. The only reason -// that it isn't is that it uses _exportsAreWide, which is true if -// detectLofsType() == SCI_VERSION_1_MIDDLE -// Maybe _exportsAreWide should become a Script member var, e.g. set -// by setExportTableOffset? -uint16 SegManager::validateExportFunc(int pubfunct, SegmentId seg) { - Script *scr = getScript(seg); - if (scr->_numExports <= pubfunct) { +uint16 Script::validateExportFunc(int pubfunct) { + bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); + + if (_numExports <= pubfunct) { warning("validateExportFunc(): pubfunct is invalid"); return 0; } - if (_exportsAreWide) + if (exportsAreWide) pubfunct *= 2; - uint16 offset = READ_SCI11ENDIAN_UINT16((byte *)(scr->_exportTable + pubfunct)); - VERIFY(offset < scr->_bufSize, "invalid export function pointer"); + uint16 offset = READ_SCI11ENDIAN_UINT16((byte *)(_exportTable + pubfunct)); + VERIFY(offset < _bufSize, "invalid export function pointer"); return offset; } diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index 28959f087a..1089ada475 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -446,7 +446,6 @@ public: */ int getSynonymsNr() const; - /** * Sets the script-relative offset of the exports table. * @param offset script-relative exports table offset @@ -454,6 +453,15 @@ public: void setExportTableOffset(int offset); /** + * Validate whether the specified public function is exported by + * the script in the specified segment. + * @param pubfunct Index of the function to validate + * @return NULL if the public function is invalid, its + * offset into the script's segment otherwise + */ + uint16 validateExportFunc(int pubfunct); + + /** * Sets the script-relative offset of the synonyms associated with this script. * @param offset script-relative offset of the synonyms block */ diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 913c4a0c66..e2ee2e1971 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -258,10 +258,12 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP int seg = s->_segMan->getScriptSegment(script); Script *scr = s->_segMan->getScriptIfLoaded(seg); - if (!scr || scr->isMarkedAsDeleted()) // Script not present yet? + if (!scr || scr->isMarkedAsDeleted()) { // Script not present yet? seg = script_instantiate(g_sci->getResMan(), s->_segMan, script); + scr = s->_segMan->getScript(seg); + } - const int temp = s->_segMan->validateExportFunc(pubfunct, seg); + const int temp = scr->validateExportFunc(pubfunct); if (!temp) { #ifdef ENABLE_SCI32 // HACK: Temporarily switch to a warning in SCI32 games until we can figure out why Torin has |