diff options
author | Max Horn | 2010-05-29 23:09:00 +0000 |
---|---|---|
committer | Max Horn | 2010-05-29 23:09:00 +0000 |
commit | 4ecacdad164d95154ac8a645058c2de0e2be73a9 (patch) | |
tree | f87728c335baad1cdbd1608a3d291993441babe2 /engines/sci/engine/segment.cpp | |
parent | 42d6ed880b92e19c469c70da92397bd860abb483 (diff) | |
download | scummvm-rg350-4ecacdad164d95154ac8a645058c2de0e2be73a9.tar.gz scummvm-rg350-4ecacdad164d95154ac8a645058c2de0e2be73a9.tar.bz2 scummvm-rg350-4ecacdad164d95154ac8a645058c2de0e2be73a9.zip |
SCI: Merge Script::relocateBlock and Object::relocate
The shared code now resides in a new static function named
relocateBlock, which is invoked by the two methods.
svn-id: r49316
Diffstat (limited to 'engines/sci/engine/segment.cpp')
-rw-r--r-- | engines/sci/engine/segment.cpp | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 17d0b67cf1..7e7da81125 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -225,33 +225,34 @@ void Script::scriptObjRemove(reg_t obj_pos) { _objects.erase(obj_pos.toUint16()); } -int Script::relocateBlock(Common::Array<reg_t> &block, int block_location, SegmentId segment, int location) { +// This helper function is used by Script::relocateLocal and Object::relocate +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 0; + return false; uint idx = rel >> 1; if (idx >= block.size()) - return 0; + return false; if (rel & 1) { warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location); - return 0; + return false; } block[idx].segment = segment; // Perform relocation if (getSciVersion() >= SCI_VERSION_1_1) - block[idx].offset += _scriptSize; + block[idx].offset += scriptSize; - return 1; + return true; } -int Script::relocateLocal(SegmentId segment, int location) { +bool Script::relocateLocal(SegmentId segment, int location) { if (_localsBlock) - return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location); + return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location, _scriptSize); else - return 0; // No hands, no cookies + return false; } void Script::scriptAddCodeBlock(reg_t location) { @@ -745,25 +746,7 @@ int Object::locateVarSelector(SegManager *segMan, Selector slc) const { } bool Object::relocate(SegmentId segment, int location, size_t scriptSize) { - int rel = location - getPos().offset; - - if (rel < 0) - return false; - - uint idx = rel >> 1; - - if (idx >= _variables.size()) - return false; - - if (rel & 1) { - warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, getPos().offset); - return false; - } - _variables[idx].segment = segment; // Perform relocation - if (getSciVersion() >= SCI_VERSION_1_1) - _variables[idx].offset += scriptSize; - - return true; + return relocateBlock(_variables, getPos().offset, segment, location, scriptSize); } int Object::propertyOffsetToId(SegManager *segMan, int propertyOffset) const { |