diff options
Diffstat (limited to 'engines/sci/engine/segment.cpp')
-rw-r--r-- | engines/sci/engine/segment.cpp | 139 |
1 files changed, 2 insertions, 137 deletions
diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index b16dd5a5e5..e40777755f 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -26,7 +26,9 @@ #include "common/endian.h" #include "sci/sci.h" +#include "sci/engine/kernel.h" #include "sci/engine/features.h" +#include "sci/engine/object.h" #include "sci/engine/script.h" // for SCI_OBJ_EXPORTS and SCI_OBJ_SYNONYMS #include "sci/engine/segment.h" #include "sci/engine/seg_manager.h" @@ -130,30 +132,6 @@ const char *SegmentObj::getSegmentTypeName(SegmentType type) { return NULL; } -// This helper function is used by Script::relocateLocal and Object::relocate -// Duplicate in segment.cpp and script.cpp -static bool relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location, size_t scriptSize) { - int rel = location - block_location; - - if (rel < 0) - return false; - - uint idx = rel >> 1; - - if (idx >= block.size()) - return false; - - if (rel & 1) { - error("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location); - return false; - } - block[idx].segment = segment; // Perform relocation - if (getSciVersion() >= SCI_VERSION_1_1) - block[idx].offset += scriptSize; - - return true; -} - SegmentRef SegmentObj::dereference(reg_t pointer) { error("Error: Trying to dereference pointer %04x:%04x to inappropriate segment", PRINT_REG(pointer)); @@ -318,10 +296,8 @@ reg_t DataStack::findCanonicAddress(SegManager *segMan, reg_t addr) const { Common::Array<reg_t> DataStack::listAllOutgoingReferences(reg_t object) const { Common::Array<reg_t> tmp; - fprintf(stderr, "Emitting %d stack entries\n", _capacity); for (int i = 0; i < _capacity; i++) tmp.push_back(_entries[i]); - fprintf(stderr, "DONE"); return tmp; } @@ -371,117 +347,6 @@ Common::Array<reg_t> NodeTable::listAllOutgoingReferences(reg_t addr) const { return tmp; } - -//-------------------- hunk -------------------- - -//-------------------- object ---------------------------- - -void Object::init(byte *buf, reg_t obj_pos, bool initVariables) { - byte *data = buf + obj_pos.offset; - _baseObj = data; - _pos = obj_pos; - - if (getSciVersion() < SCI_VERSION_1_1) { - _variables.resize(READ_LE_UINT16(data + kOffsetSelectorCounter)); - _baseVars = (const uint16 *)(_baseObj + _variables.size() * 2); - _baseMethod = (const uint16 *)(data + READ_LE_UINT16(data + kOffsetFunctionArea)); - _methodCount = READ_LE_UINT16(_baseMethod - 1); - } else { - _variables.resize(READ_SCI11ENDIAN_UINT16(data + 2)); - _baseVars = (const uint16 *)(buf + READ_SCI11ENDIAN_UINT16(data + 4)); - _baseMethod = (const uint16 *)(buf + READ_SCI11ENDIAN_UINT16(data + 6)); - _methodCount = READ_SCI11ENDIAN_UINT16(_baseMethod); - } - - if (initVariables) { - for (uint i = 0; i < _variables.size(); i++) - _variables[i] = make_reg(0, READ_SCI11ENDIAN_UINT16(data + (i * 2))); - } -} - -const Object *Object::getClass(SegManager *segMan) const { - return isClass() ? this : segMan->getObject(getSuperClassSelector()); -} - -int Object::locateVarSelector(SegManager *segMan, Selector slc) const { - const byte *buf; - uint varnum; - - if (getSciVersion() < SCI_VERSION_1_1) { - varnum = getVarCount(); - int selector_name_offset = varnum * 2 + kOffsetSelectorSegment; - buf = _baseObj + selector_name_offset; - } else { - const Object *obj = getClass(segMan); - varnum = obj->getVariable(1).toUint16(); - buf = (const byte *)obj->_baseVars; - } - - for (uint i = 0; i < varnum; i++) - if (READ_SCI11ENDIAN_UINT16(buf + (i << 1)) == slc) // Found it? - return i; // report success - - return -1; // Failed -} - -bool Object::relocate(SegmentId segment, int location, size_t scriptSize) { - return relocateBlock(_variables, getPos().offset, segment, location, scriptSize); -} - -int Object::propertyOffsetToId(SegManager *segMan, int propertyOffset) const { - int selectors = getVarCount(); - - if (propertyOffset < 0 || (propertyOffset >> 1) >= selectors) { - error("Applied propertyOffsetToId to invalid property offset %x (property #%d not in [0..%d])", - propertyOffset, propertyOffset >> 1, selectors - 1); - return -1; - } - - if (getSciVersion() < SCI_VERSION_1_1) { - const byte *selectoroffset = ((const byte *)(_baseObj)) + kOffsetSelectorSegment + selectors * 2; - return READ_SCI11ENDIAN_UINT16(selectoroffset + propertyOffset); - } else { - const Object *obj = this; - if (!isClass()) - obj = segMan->getObject(getSuperClassSelector()); - - return READ_SCI11ENDIAN_UINT16((const byte *)obj->_baseVars + propertyOffset); - } -} - -void Object::initSpecies(SegManager *segMan, reg_t addr) { - uint16 speciesOffset = getSpeciesSelector().offset; - - if (speciesOffset == 0xffff) // -1 - setSpeciesSelector(NULL_REG); // no species - else - setSpeciesSelector(segMan->getClassAddress(speciesOffset, SCRIPT_GET_LOCK, addr)); -} - -void Object::initSuperClass(SegManager *segMan, reg_t addr) { - uint16 superClassOffset = getSuperClassSelector().offset; - - if (superClassOffset == 0xffff) // -1 - setSuperClassSelector(NULL_REG); // no superclass - else - setSuperClassSelector(segMan->getClassAddress(superClassOffset, SCRIPT_GET_LOCK, addr)); -} - -bool Object::initBaseObject(SegManager *segMan, reg_t addr, bool doInitSuperClass) { - const Object *baseObj = segMan->getObject(getSpeciesSelector()); - - if (baseObj) { - _variables.resize(baseObj->getVarCount()); - // Copy base from species class, as we need its selector IDs - _baseObj = baseObj->_baseObj; - if (doInitSuperClass) - initSuperClass(segMan, addr); - return true; - } - - return false; -} - //-------------------- dynamic memory -------------------- reg_t DynMem::findCanonicAddress(SegManager *segMan, reg_t addr) const { |