Moved setScriptSize() inside Script::init(), and removed a FIXME - the SCI1.1 word-align is done inside Script::init()
svn-id: r49330
This commit is contained in:
parent
29c2f30558
commit
016862ac3a
4 changed files with 23 additions and 50 deletions
|
@ -437,13 +437,6 @@ int script_instantiate_sci11(ResourceManager *resMan, SegManager *segMan, int sc
|
||||||
scr->setExportTableOffset(6);
|
scr->setExportTableOffset(6);
|
||||||
|
|
||||||
int heapStart = scr->getScriptSize();
|
int heapStart = scr->getScriptSize();
|
||||||
|
|
||||||
// FIXME: This code was used to ensure that the heap address is word-aligned
|
|
||||||
// Make sure that this is used in all places where the heap is referenced,
|
|
||||||
// not just here...
|
|
||||||
//if (heapStart & 2)
|
|
||||||
// heapStart++;
|
|
||||||
|
|
||||||
segMan->scriptInitialiseLocals(make_reg(seg_id, heapStart + 4));
|
segMan->scriptInitialiseLocals(make_reg(seg_id, heapStart + 4));
|
||||||
segMan->scriptInitialiseObjectsSci11(seg_id);
|
segMan->scriptInitialiseObjectsSci11(seg_id);
|
||||||
scr->heapRelocate(make_reg(seg_id, READ_SCI11ENDIAN_UINT16(scr->_heapStart)));
|
scr->heapRelocate(make_reg(seg_id, READ_SCI11ENDIAN_UINT16(scr->_heapStart)));
|
||||||
|
|
|
@ -117,8 +117,8 @@ void Script::freeScript() {
|
||||||
_codeBlocks.clear();
|
_codeBlocks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Script::init(int script_nr, ResourceManager *resMan) {
|
void Script::init(int script_nr, ResourceManager *resMan) {
|
||||||
setScriptSize(script_nr, resMan);
|
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
|
||||||
|
|
||||||
_localsOffset = 0;
|
_localsOffset = 0;
|
||||||
_localsBlock = NULL;
|
_localsBlock = NULL;
|
||||||
|
@ -132,7 +132,25 @@ bool Script::init(int script_nr, ResourceManager *resMan) {
|
||||||
_buf = 0;
|
_buf = 0;
|
||||||
_heapStart = 0;
|
_heapStart = 0;
|
||||||
|
|
||||||
return true;
|
_scriptSize = script->size;
|
||||||
|
_bufSize = script->size;
|
||||||
|
_heapSize = 0;
|
||||||
|
|
||||||
|
if (getSciVersion() == SCI_VERSION_0_EARLY) {
|
||||||
|
_bufSize += READ_LE_UINT16(script->data) * 2;
|
||||||
|
} else if (getSciVersion() >= SCI_VERSION_1_1) {
|
||||||
|
Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, script_nr), 0);
|
||||||
|
_bufSize += heap->size;
|
||||||
|
_heapSize = heap->size;
|
||||||
|
|
||||||
|
// Ensure that the start of the heap resource can be word-aligned.
|
||||||
|
if (script->size & 2) {
|
||||||
|
_bufSize++;
|
||||||
|
_scriptSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(_bufSize <= 65535);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Script::load(ResourceManager *resMan) {
|
void Script::load(ResourceManager *resMan) {
|
||||||
|
@ -156,42 +174,6 @@ void Script::load(ResourceManager *resMan) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Script::setScriptSize(int script_nr, ResourceManager *resMan) {
|
|
||||||
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);
|
|
||||||
Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, script_nr), 0);
|
|
||||||
bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
|
|
||||||
|
|
||||||
_scriptSize = script->size;
|
|
||||||
_heapSize = 0; // Set later
|
|
||||||
|
|
||||||
if (!script || (getSciVersion() >= SCI_VERSION_1_1 && !heap)) {
|
|
||||||
error("SegManager::setScriptSize: failed to load %s", !script ? "script" : "heap");
|
|
||||||
}
|
|
||||||
if (oldScriptHeader) {
|
|
||||||
_bufSize = script->size + READ_LE_UINT16(script->data) * 2;
|
|
||||||
//locals_size = READ_LE_UINT16(script->data) * 2;
|
|
||||||
} else if (getSciVersion() < SCI_VERSION_1_1) {
|
|
||||||
_bufSize = script->size;
|
|
||||||
} else {
|
|
||||||
_bufSize = script->size + heap->size;
|
|
||||||
_heapSize = heap->size;
|
|
||||||
|
|
||||||
// Ensure that the start of the heap resource can be word-aligned.
|
|
||||||
if (script->size & 2) {
|
|
||||||
_bufSize++;
|
|
||||||
_scriptSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_bufSize > 65535) {
|
|
||||||
error("Script and heap sizes combined exceed 64K."
|
|
||||||
"This means a fundamental design bug was made in SCI\n"
|
|
||||||
"regarding SCI1.1 games.\nPlease report this so it can be"
|
|
||||||
"fixed in the next major version");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object *Script::allocateObject(uint16 offset) {
|
Object *Script::allocateObject(uint16 offset) {
|
||||||
return &_objects[offset];
|
return &_objects[offset];
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,7 +363,7 @@ public:
|
||||||
~Script();
|
~Script();
|
||||||
|
|
||||||
void freeScript();
|
void freeScript();
|
||||||
bool init(int script_nr, ResourceManager *resMan);
|
void init(int script_nr, ResourceManager *resMan);
|
||||||
void load(ResourceManager *resMan);
|
void load(ResourceManager *resMan);
|
||||||
|
|
||||||
virtual bool isValidOffset(uint16 offset) const;
|
virtual bool isValidOffset(uint16 offset) const;
|
||||||
|
@ -512,9 +512,6 @@ public:
|
||||||
* Finds the pointer where a block of a specific type starts from
|
* Finds the pointer where a block of a specific type starts from
|
||||||
*/
|
*/
|
||||||
byte *findBlock(int type);
|
byte *findBlock(int type);
|
||||||
|
|
||||||
private:
|
|
||||||
void setScriptSize(int script_nr, ResourceManager *resMan);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data stack */
|
/** Data stack */
|
||||||
|
|
|
@ -1926,6 +1926,7 @@ reg_t ResourceManager::findGameObject(bool addSci11ScriptOffset) {
|
||||||
if (getSciVersion() >= SCI_VERSION_1_1 && addSci11ScriptOffset) {
|
if (getSciVersion() >= SCI_VERSION_1_1 && addSci11ScriptOffset) {
|
||||||
offset += script->size;
|
offset += script->size;
|
||||||
|
|
||||||
|
// Ensure that the start of the heap is word-aligned - same as in Script::init()
|
||||||
if (script->size & 2)
|
if (script->size & 2)
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue