[Scummvm-cvs-logs] SF.net SVN: scummvm:[49649] scummvm/trunk/engines/sci/engine
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Mon Jun 14 14:44:57 CEST 2010
Revision: 49649
http://scummvm.svn.sourceforge.net/scummvm/?rev=49649&view=rev
Author: thebluegr
Date: 2010-06-14 12:44:57 +0000 (Mon, 14 Jun 2010)
Log Message:
-----------
Some cleanup of the script locals code
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/script.cpp
scummvm/trunk/engines/sci/engine/seg_manager.cpp
scummvm/trunk/engines/sci/engine/seg_manager.h
scummvm/trunk/engines/sci/engine/segment.cpp
scummvm/trunk/engines/sci/engine/segment.h
Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp 2010-06-14 09:33:36 UTC (rev 49648)
+++ scummvm/trunk/engines/sci/engine/script.cpp 2010-06-14 12:44:57 UTC (rev 49649)
@@ -161,49 +161,19 @@
void SegManager::scriptInitialiseLocals(SegmentId segmentId) {
Script *scr = getScript(segmentId);
- uint16 count;
- if (getSciVersion() == SCI_VERSION_0_EARLY) {
- // Old script block. There won't be a localvar block in this case.
- // Instead, the script starts with a 16 bit int specifying the
- // number of locals we need; these are then allocated and zeroed.
- int localsCount = READ_LE_UINT16(scr->_buf);
- if (localsCount) {
- scr->_localsOffset = -localsCount * 2; // Make sure it's invalid
- LocalVariables *locals = allocLocalsSegment(scr, localsCount);
- if (locals) {
- for (int i = 0; i < localsCount; i++)
- locals->_locals[i] = NULL_REG;
- }
- }
-
- return;
- }
-
- // Check if the script actually has local variables
- if (scr->_localsOffset == 0)
- return;
-
- VERIFY(scr->_localsOffset + 1 < (uint16)scr->getBufSize(), "Locals beyond end of script\n");
-
- if (getSciVersion() >= SCI_VERSION_1_1)
- count = READ_SCI11ENDIAN_UINT16(scr->_buf + scr->_localsOffset - 2);
- else
- count = (READ_LE_UINT16(scr->_buf + scr->_localsOffset - 2) - 4) >> 1;
- // half block size
-
- if (!(scr->_localsOffset + count * 2 + 1 < (uint16)scr->getBufSize())) {
- warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", scr->_localsOffset, count, (uint)scr->getBufSize());
- count = (scr->getBufSize() - scr->_localsOffset) >> 1;
- }
-
- LocalVariables *locals = allocLocalsSegment(scr, count);
+ LocalVariables *locals = allocLocalsSegment(scr);
if (locals) {
- uint i;
- const byte *base = (const byte *)(scr->_buf + scr->_localsOffset);
+ if (getSciVersion() > SCI_VERSION_0_EARLY) {
+ const byte *base = (const byte *)(scr->_buf + scr->getLocalsOffset());
- for (i = 0; i < count; i++)
- locals->_locals[i] = make_reg(0, READ_SCI11ENDIAN_UINT16(base + i * 2));
+ for (uint16 i = 0; i < scr->getLocalsCount(); i++)
+ locals->_locals[i] = make_reg(0, READ_SCI11ENDIAN_UINT16(base + i * 2));
+ } else {
+ // In SCI0 early, locals are set at run time, thus zero them all here
+ for (uint16 i = 0; i < scr->getLocalsCount(); i++)
+ locals->_locals[i] = NULL_REG;
+ }
}
}
Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp 2010-06-14 09:33:36 UTC (rev 49648)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp 2010-06-14 12:44:57 UTC (rev 49649)
@@ -377,8 +377,8 @@
return segment;
}
-LocalVariables *SegManager::allocLocalsSegment(Script *scr, int count) {
- if (!count) { // No locals
+LocalVariables *SegManager::allocLocalsSegment(Script *scr) {
+ if (!scr->getLocalsCount()) { // No locals
scr->_localsSegment = 0;
scr->_localsBlock = NULL;
return NULL;
@@ -395,7 +395,7 @@
scr->_localsBlock = locals;
locals->script_id = scr->_nr;
- locals->_locals.resize(count);
+ locals->_locals.resize(scr->getLocalsCount());
return locals;
}
Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h 2010-06-14 09:33:36 UTC (rev 49648)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h 2010-06-14 12:44:57 UTC (rev 49649)
@@ -478,7 +478,7 @@
private:
SegmentObj *allocSegment(SegmentObj *mem, SegmentId *segid);
- LocalVariables *allocLocalsSegment(Script *scr, int count);
+ LocalVariables *allocLocalsSegment(Script *scr);
int deallocate(SegmentId seg, bool recursive);
void createClassTable();
Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp 2010-06-14 09:33:36 UTC (rev 49648)
+++ scummvm/trunk/engines/sci/engine/segment.cpp 2010-06-14 12:44:57 UTC (rev 49649)
@@ -100,6 +100,7 @@
_localsOffset = 0;
_localsSegment = 0;
_localsBlock = NULL;
+ _localsCount = 0;
_markedAsDeleted = false;
}
@@ -122,6 +123,7 @@
_localsOffset = 0;
_localsBlock = NULL;
+ _localsCount = 0;
_codeBlocks.clear();
@@ -198,6 +200,7 @@
_exportTable = (const uint16 *)(_buf + 1 + 5 + 2);
_numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1);
_localsOffset = _scriptSize + 4;
+ _localsCount = READ_SCI11ENDIAN_UINT16(_buf + _localsOffset - 2);
}
} else {
_exportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS);
@@ -211,9 +214,28 @@
_synonyms += 4; // skip header
}
const byte* localsBlock = findBlock(SCI_OBJ_LOCALVARS);
- if (localsBlock)
+ if (localsBlock) {
_localsOffset = localsBlock - _buf + 4;
+ _localsCount = (READ_LE_UINT16(_buf + _localsOffset - 2) - 4) >> 1; // half block size
+ }
}
+
+ if (getSciVersion() > SCI_VERSION_0_EARLY) {
+ // Does the script actually have locals? If not, set the locals offset to 0
+ if (!_localsCount)
+ _localsOffset = 0;
+
+ if (_localsOffset + _localsCount * 2 + 1 >= (int)_bufSize) {
+ warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", _localsOffset, _localsCount, _bufSize);
+ _localsCount = (_bufSize - _localsOffset) >> 1;
+ }
+ } else {
+ // Old script block. There won't be a localvar block in this case.
+ // Instead, the script starts with a 16 bit int specifying the
+ // number of locals we need; these are then allocated and zeroed.
+ _localsCount = READ_LE_UINT16(_buf);
+ _localsOffset = -_localsCount * 2; // Make sure it's invalid
+ }
}
Object *Script::allocateObject(uint16 offset) {
Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h 2010-06-14 09:33:36 UTC (rev 49648)
+++ scummvm/trunk/engines/sci/engine/segment.h 2010-06-14 12:44:57 UTC (rev 49649)
@@ -364,6 +364,9 @@
Common::Array<CodeBlock> _codeBlocks;
+ int _localsOffset;
+ uint16 _localsCount;
+
public:
/**
* Table for objects, contains property variables.
@@ -371,7 +374,8 @@
*/
ObjMap _objects;
- int _localsOffset;
+ int getLocalsOffset() const { return _localsOffset; }
+ uint16 getLocalsCount() const { return _localsCount; }
SegmentId _localsSegment; /**< The local variable segment */
LocalVariables *_localsBlock;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list