From e4c967a3014eebff5e2c4fd02a3268749eed4122 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 17 Nov 2010 09:10:43 +0000 Subject: SCI: Added the SCI3 equivalent of initialiseObjects(), from a patch by lskovlun svn-id: r54281 --- engines/sci/console.cpp | 2 +- engines/sci/engine/script.cpp | 28 +++++++++++++++++++++++++++- engines/sci/engine/script.h | 9 ++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 509daf0206..5915c14fba 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -3670,7 +3670,7 @@ int Console::printObject(reg_t pos) { DebugPrintf("[%04x:%04x] %s : %3d vars, %3d methods\n", PRINT_REG(pos), s->_segMan->getObjectName(pos), obj->getVarCount(), obj->getMethodCount()); - if (!obj->isClass()) + if (!obj->isClass() && getSciVersion() != SCI_VERSION_3) var_container = s->_segMan->getObject(obj->getSuperClassSelector()); DebugPrintf(" -- member variables:\n"); for (i = 0; (uint)i < obj->getVarCount(); i++) { diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index c4ff0cc699..088cd9cb89 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -566,13 +566,39 @@ void Script::initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId) { relocate(make_reg(segmentId, READ_SCI11ENDIAN_UINT16(_heapStart))); } +void Script::initialiseObjectsSci3(SegManager *segMan, SegmentId segmentId) { + const byte *seeker = _buf; + + // SCI3 local variables always start dword-aligned + if (_numExports % 2) + seeker = _buf + 22 + _numExports * 2; + else + seeker = _buf + 24 + _numExports * 2; + + // SCI3 object structures always start dword-aligned + if (_localsCount % 2) + seeker = seeker + 2 + _localsCount * 2; + else + seeker = seeker + _localsCount * 2; + + while (READ_SCI11ENDIAN_UINT16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) { + reg_t reg = make_reg(segmentId, seeker - _buf); + Object *obj = scriptObjInit(reg); + + obj->setSuperClassSelector(segMan->getClassAddress(obj->getSuperClassSelector().offset, SCRIPT_GET_LOCK, NULL_REG)); + seeker += READ_SCI11ENDIAN_UINT16(seeker + 2); + } + + relocate(make_reg(segmentId, 0)); +} + void Script::initialiseObjects(SegManager *segMan, SegmentId segmentId) { if (getSciVersion() <= SCI_VERSION_1_LATE) initialiseObjectsSci0(segMan, segmentId); else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1) initialiseObjectsSci11(segMan, segmentId); else if (getSciVersion() == SCI_VERSION_3) - warning("TODO: initialiseObjects(): SCI3 equivalent"); + initialiseObjectsSci3(segMan, segmentId); } reg_t Script::findCanonicAddress(SegManager *segMan, reg_t addr) const { diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h index bc263edc8c..211427942d 100644 --- a/engines/sci/engine/script.h +++ b/engines/sci/engine/script.h @@ -268,11 +268,18 @@ private: void initialiseObjectsSci0(SegManager *segMan, SegmentId segmentId); /** - * Initializes the script's objects (SCI1.1+) + * Initializes the script's objects (SCI1.1 - SCI2.1) * @param segMan A reference to the segment manager * @param segmentId The script's segment id */ void initialiseObjectsSci11(SegManager *segMan, SegmentId segmentId); + + /** + * Initializes the script's objects (SCI3) + * @param segMan A reference to the segment manager + * @param segmentId The script's segment id + */ + void initialiseObjectsSci3(SegManager *segMan, SegmentId segmentId); }; } // End of namespace Sci -- cgit v1.2.3