From b5ebd40d614ab7b1c2f1408750c09f528b7ae2de Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 13 Jun 2010 22:15:30 +0000 Subject: The offset of script local variables is now calculated when the script is loaded, thus we no longer need to save it. Merged scriptInitialiseLocals() with scriptInitialiseLocalsZero() svn-id: r49640 --- engines/sci/engine/segment.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 0e0a759d4b..4b3df11d8f 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -197,6 +197,7 @@ void Script::load(ResourceManager *resMan) { if (READ_LE_UINT16(_buf + 1 + 5) > 0) { _exportTable = (const uint16 *)(_buf + 1 + 5 + 2); _numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1); + _localsOffset = _scriptSize + 4; } } else { _exportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS); @@ -209,6 +210,9 @@ void Script::load(ResourceManager *resMan) { _numSynonyms = READ_SCI11ENDIAN_UINT16(_synonyms + 2) / 4; _synonyms += 4; // skip header } + const byte* localsBlock = findBlock(SCI_OBJ_LOCALVARS); + if (localsBlock) + _localsOffset = localsBlock - _buf + 4; } } -- cgit v1.2.3 From cd77cb96fc85ba2f681337630c4374ce0565927f Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 14 Jun 2010 12:44:57 +0000 Subject: Some cleanup of the script locals code svn-id: r49649 --- engines/sci/engine/segment.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 4b3df11d8f..c32823a7c2 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -100,6 +100,7 @@ Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) { _localsOffset = 0; _localsSegment = 0; _localsBlock = NULL; + _localsCount = 0; _markedAsDeleted = false; } @@ -122,6 +123,7 @@ void Script::init(int script_nr, ResourceManager *resMan) { _localsOffset = 0; _localsBlock = NULL; + _localsCount = 0; _codeBlocks.clear(); @@ -198,6 +200,7 @@ void Script::load(ResourceManager *resMan) { _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,8 +214,27 @@ void Script::load(ResourceManager *resMan) { _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 } } -- cgit v1.2.3 From 2a78b8279930212337c446948cc9a2943d685c94 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 14 Jun 2010 13:13:02 +0000 Subject: Fixed a bug with commit #49640 svn-id: r49650 --- engines/sci/engine/segment.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index c32823a7c2..c5afe57eea 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -196,12 +196,12 @@ void Script::load(ResourceManager *resMan) { _numSynonyms = 0; if (getSciVersion() >= SCI_VERSION_1_1) { - if (READ_LE_UINT16(_buf + 1 + 5) > 0) { + if (READ_LE_UINT16(_buf + 1 + 5) > 0) { // does the script have an export table? _exportTable = (const uint16 *)(_buf + 1 + 5 + 2); _numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1); - _localsOffset = _scriptSize + 4; - _localsCount = READ_SCI11ENDIAN_UINT16(_buf + _localsOffset - 2); } + _localsOffset = _scriptSize + 4; + _localsCount = READ_SCI11ENDIAN_UINT16(_buf + _localsOffset - 2); } else { _exportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS); if (_exportTable) { -- cgit v1.2.3 From 5230930d9577726d6f64fa8ffa73690314fd0a56 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 14 Jun 2010 13:41:06 +0000 Subject: Silenced warning svn-id: r49651 --- engines/sci/engine/segment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index c5afe57eea..99fcb1b821 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -226,7 +226,7 @@ void Script::load(ResourceManager *resMan) { _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); + warning("Locals extend beyond end of script: offset %04x, count %d vs size %d", _localsOffset, _localsCount, _bufSize); _localsCount = (_bufSize - _localsOffset) >> 1; } } else { -- cgit v1.2.3 From 4f3bb60cd59f7b24a4c1d29de7ba790d262b16ee Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 14 Jun 2010 13:53:15 +0000 Subject: Really silence the warning with _bufSize svn-id: r49652 --- engines/sci/engine/segment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 99fcb1b821..492e928e31 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -161,7 +161,7 @@ void Script::init(int script_nr, ResourceManager *resMan) { } // As mentioned above, the script and the heap together should not exceed 64KB - if (_bufSize > 65535) + if (script->size + heap->size > 65535) error("Script and heap sizes combined exceed 64K. This means a fundamental " "design bug was made regarding SCI1.1 and newer games.\nPlease " "report this error to the ScummVM team"); -- cgit v1.2.3 From 1fde7f1abceb5f7c52982e9b2bf18188037b63d5 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 14 Jun 2010 20:45:00 +0000 Subject: Removed the code used for tracking script code block relocations in SCI0-SCI1 games, as we don't actually relocate these blocks, and it was used solely for verification of the exports table. The issue that this warning was created for should no longer occur svn-id: r49669 --- engines/sci/engine/segment.cpp | 57 +++++++++--------------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 492e928e31..879cbc22ee 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -115,7 +115,6 @@ void Script::freeScript() { _bufSize = 0; _objects.clear(); - _codeBlocks.clear(); } void Script::init(int script_nr, ResourceManager *resMan) { @@ -125,8 +124,6 @@ void Script::init(int script_nr, ResourceManager *resMan) { _localsBlock = NULL; _localsCount = 0; - _codeBlocks.clear(); - _markedAsDeleted = false; _nr = script_nr; @@ -188,8 +185,6 @@ void Script::load(ResourceManager *resMan) { memcpy(_heapStart, heap->data, heap->size); } - _codeBlocks.clear(); - _exportTable = 0; _numExports = 0; _synonyms = 0; @@ -310,13 +305,6 @@ bool Script::relocateLocal(SegmentId segment, int location) { return false; } -void Script::scriptAddCodeBlock(reg_t location) { - CodeBlock cb; - cb.pos = location; - cb.size = READ_SCI11ENDIAN_UINT16(_buf + location.offset - 2); - _codeBlocks.push_back(cb); -} - void Script::relocate(reg_t block) { byte *heap = _buf; uint16 heapSize = (uint16)_bufSize; @@ -333,13 +321,14 @@ void Script::relocate(reg_t block) { int count = READ_SCI11ENDIAN_UINT16(heap + block.offset); int exportIndex = 0; + int pos = 0; for (int i = 0; i < count; i++) { - int pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; - // This occurs in SCI01/SCI1 games where every usually one export - // value is zero. It seems that in this situation, we should skip - // the export and move to the next one, though the total count - // of valid exports remains the same + pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; + // This occurs in SCI01/SCI1 games where usually one export value + // is zero. It seems that in this situation, we should skip the + // export and move to the next one, though the total count of valid + // exports remains the same if (!pos) { exportIndex++; pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; @@ -347,37 +336,15 @@ void Script::relocate(reg_t block) { error("Script::relocate(): Consecutive zero exports found"); } + // In SCI0-SCI1, script local variables, objects and code are relocated. We only relocate + // locals and objects here, and ignore relocation of code blocks. In SCI1.1 and newer + // versions, only locals and objects are relocated. if (!relocateLocal(block.segment, pos)) { - bool done = false; - uint k; - - ObjMap::iterator it; + // Not a local? It's probably an object or code block. If it's an object, relocate it. const ObjMap::iterator end = _objects.end(); - for (it = _objects.begin(); !done && it != end; ++it) { + for (ObjMap::iterator it = _objects.begin(); it != end; ++it) if (it->_value.relocate(block.segment, pos, _scriptSize)) - done = true; - } - - // Sanity check for SCI0-SCI1 - if (getSciVersion() < SCI_VERSION_1_1) { - for (k = 0; !done && k < _codeBlocks.size(); k++) { - if (pos >= _codeBlocks[k].pos.offset && - pos < _codeBlocks[k].pos.offset + _codeBlocks[k].size) - done = true; - } - } - - if (!done) { - debug("While processing relocation block %04x:%04x:\n", PRINT_REG(block)); - debug("Relocation failed for index %04x (%d/%d)\n", pos, exportIndex + 1, count); - if (_localsBlock) - debug("- locals: %d at %04x\n", _localsBlock->_locals.size(), _localsOffset); - else - debug("- No locals\n"); - for (it = _objects.begin(), k = 0; it != end; ++it, ++k) - debug("- obj#%d at %04x w/ %d vars\n", k, it->_value.getPos().offset, it->_value.getVarCount()); - debug("Trying to continue anyway...\n"); - } + break; } exportIndex++; -- cgit v1.2.3 From 9a1db3f77092f13829604701b419ffc38577388b Mon Sep 17 00:00:00 2001 From: Lars Skovlund Date: Tue, 15 Jun 2010 08:21:39 +0000 Subject: Add support for SCI32 segment types to seg_table and vr debug commands svn-id: r49686 --- engines/sci/engine/segment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 879cbc22ee..a6154e7512 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -435,7 +435,7 @@ bool Script::isValidOffset(uint16 offset) const { SegmentRef Script::dereference(reg_t pointer) { if (pointer.offset > _bufSize) { - warning("Script::dereference(): Attempt to dereference invalid pointer %04x:%04x into script segment (script size=%d)", + error("Script::dereference(): Attempt to dereference invalid pointer %04x:%04x into script segment (script size=%d)", PRINT_REG(pointer), (uint)_bufSize); return SegmentRef(); } -- cgit v1.2.3 From db70d66e4ae872ebdeb2a88ef0870708a30c7667 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 17 Jun 2010 23:50:28 +0000 Subject: Strict mode: Changed several warnings due to logic bugs into errors. If an error pops up from these ones, please add the game where it occurred and the steps to reproduce the error before turning it into a warning svn-id: r49973 --- engines/sci/engine/segment.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index a6154e7512..c2f72ecdbd 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -221,7 +221,7 @@ void Script::load(ResourceManager *resMan) { _localsOffset = 0; if (_localsOffset + _localsCount * 2 + 1 >= (int)_bufSize) { - warning("Locals extend beyond end of script: offset %04x, count %d vs size %d", _localsOffset, _localsCount, _bufSize); + error("Locals extend beyond end of script: offset %04x, count %d vs size %d", _localsOffset, _localsCount, _bufSize); _localsCount = (_bufSize - _localsOffset) >> 1; } } else { @@ -268,12 +268,14 @@ Object *Script::scriptObjInit(reg_t obj_pos, bool fullObjectInit) { return obj; } +#if 0 void Script::scriptObjRemove(reg_t obj_pos) { if (getSciVersion() < SCI_VERSION_1_1) obj_pos.offset += 8; _objects.erase(obj_pos.toUint16()); } +#endif // This helper function is used by Script::relocateLocal and Object::relocate static bool relocateBlock(Common::Array &block, int block_location, SegmentId segment, int location, size_t scriptSize) { @@ -288,7 +290,7 @@ static bool relocateBlock(Common::Array &block, int block_location, Segme return false; if (rel & 1) { - warning("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location); + error("Attempt to relocate odd variable #%d.5e (relative to %04x)\n", idx, block_location); return false; } block[idx].segment = segment; // Perform relocation @@ -372,7 +374,7 @@ uint16 Script::validateExportFunc(int pubfunct) { bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); if (_numExports <= pubfunct) { - warning("validateExportFunc(): pubfunct is invalid"); + error("validateExportFunc(): pubfunct is invalid"); return 0; } @@ -464,7 +466,7 @@ SegmentRef LocalVariables::dereference(reg_t pointer) { if (ret.maxSize > 0) { ret.reg = &_locals[pointer.offset / 2]; } else { - warning("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); + error("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); ret.reg = 0; } return ret; @@ -551,7 +553,7 @@ void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback not for (uint i = 0; i < obj->getVarCount(); i++) (*note)(param, obj->getVariable(i)); } else { - warning("Request for outgoing script-object reference at %04x:%04x failed", PRINT_REG(addr)); + error("Request for outgoing script-object reference at %04x:%04x failed", PRINT_REG(addr)); } } else { /* warning("Unexpected request for outgoing script-object references at %04x:%04x", PRINT_REG(addr));*/ @@ -642,7 +644,7 @@ void ListTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { void ListTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { if (!isValidEntry(addr.offset)) { - warning("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); + error("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; } @@ -662,7 +664,7 @@ void NodeTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { void NodeTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { if (!isValidEntry(addr.offset)) { - warning("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); + error("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; } const Node *node = &(_table[addr.offset]); @@ -736,7 +738,7 @@ int Object::propertyOffsetToId(SegManager *segMan, int propertyOffset) const { int selectors = getVarCount(); if (propertyOffset < 0 || (propertyOffset >> 1) >= selectors) { - warning("Applied propertyOffsetToId to invalid property offset %x (property #%d not in [0..%d])", + error("Applied propertyOffsetToId to invalid property offset %x (property #%d not in [0..%d])", propertyOffset, propertyOffset >> 1, selectors - 1); return -1; } @@ -814,7 +816,7 @@ void ArrayTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { void ArrayTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { if (!isValidEntry(addr.offset)) { - warning("Invalid array referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); + error("Invalid array referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); return; } -- cgit v1.2.3 From c28fa2cf196eec983ad2b33b4f5ca9e607a9652d Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 22 Jun 2010 15:03:19 +0000 Subject: Reverted the code which handles objects without a base object when loading, for now. This possibly indicates an issue related to the garbage collector svn-id: r50142 --- engines/sci/engine/segment.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index c2f72ecdbd..98f03ff18a 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -268,14 +268,12 @@ Object *Script::scriptObjInit(reg_t obj_pos, bool fullObjectInit) { return obj; } -#if 0 void Script::scriptObjRemove(reg_t obj_pos) { if (getSciVersion() < SCI_VERSION_1_1) obj_pos.offset += 8; _objects.erase(obj_pos.toUint16()); } -#endif // This helper function is used by Script::relocateLocal and Object::relocate static bool relocateBlock(Common::Array &block, int block_location, SegmentId segment, int location, size_t scriptSize) { -- cgit v1.2.3 From f65c4f988639b1ba5e6b2a95174aef3ec7fd8941 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 24 Jun 2010 07:32:34 +0000 Subject: Changed an error in LocalVariables::dereference() back to a warning, as it occurs in 2 places during the intro of LB2 (called from kMemory(peek)) svn-id: r50202 --- engines/sci/engine/segment.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 98f03ff18a..28cc03d175 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -464,7 +464,10 @@ SegmentRef LocalVariables::dereference(reg_t pointer) { if (ret.maxSize > 0) { ret.reg = &_locals[pointer.offset / 2]; } else { - error("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); + // Happens in two places during the intro of LB2CD, both from kMemory(peek): + // - room 160: Heap 160 has 83 local variables (0-82), and the game asks for variables at indices 83 - 90 too + // - room 220: Heap 220 has 114 local variables (0-113), and the game asks for variables at indices 114-120 too + warning("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); ret.reg = 0; } return ret; -- cgit v1.2.3 From 1e9977a725ca24a2d31cac56b0587bae09ab5b3a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 25 Jun 2010 16:11:00 +0000 Subject: SCI: Restrict some 'error' exceptions to the places they occur; cleanup svn-id: r50271 --- engines/sci/engine/segment.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 28cc03d175..6a564fcc57 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -464,10 +464,16 @@ SegmentRef LocalVariables::dereference(reg_t pointer) { if (ret.maxSize > 0) { ret.reg = &_locals[pointer.offset / 2]; } else { - // Happens in two places during the intro of LB2CD, both from kMemory(peek): - // - room 160: Heap 160 has 83 local variables (0-82), and the game asks for variables at indices 83 - 90 too - // - room 220: Heap 220 has 114 local variables (0-113), and the game asks for variables at indices 114-120 too - warning("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); + if ((g_sci->getEngineState()->currentRoomNumber() == 660 || g_sci->getEngineState()->currentRoomNumber() == 660) + && g_sci->getGameId() == "laurabow2") { + // Happens in two places during the intro of LB2CD, both from kMemory(peek): + // - room 160: Heap 160 has 83 local variables (0-82), and the game + // asks for variables at indices 83 - 90 too. + // - room 220: Heap 220 has 114 local variables (0-113), and the + // game asks for variables at indices 114-120 too. + } else { + error("LocalVariables::dereference: Offset at end or out of bounds %04x:%04x", PRINT_REG(pointer)); + } ret.reg = 0; } return ret; @@ -514,8 +520,11 @@ SegmentRef SystemStrings::dereference(reg_t pointer) { if (isValidOffset(pointer.offset)) ret.raw = (byte *)(_strings[pointer.offset]._value); else { - // This occurs in KQ5CD when interacting with certain objects - warning("SystemStrings::dereference(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer)); + if (g_sci->getGameId() == "kq5") { + // This occurs in KQ5CD when interacting with certain objects + } else { + error("SystemStrings::dereference(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer)); + } } return ret; -- cgit v1.2.3 From 6ee82a20276d213a06d43ff731d197f5a92a09d7 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 25 Jun 2010 16:16:29 +0000 Subject: SCI: Introduce SciGameId enum svn-id: r50273 --- engines/sci/engine/segment.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 6a564fcc57..0a39d950b0 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -465,7 +465,7 @@ SegmentRef LocalVariables::dereference(reg_t pointer) { ret.reg = &_locals[pointer.offset / 2]; } else { if ((g_sci->getEngineState()->currentRoomNumber() == 660 || g_sci->getEngineState()->currentRoomNumber() == 660) - && g_sci->getGameId() == "laurabow2") { + && g_sci->getGameId() == GID_LAURABOW2) { // Happens in two places during the intro of LB2CD, both from kMemory(peek): // - room 160: Heap 160 has 83 local variables (0-82), and the game // asks for variables at indices 83 - 90 too. @@ -520,7 +520,7 @@ SegmentRef SystemStrings::dereference(reg_t pointer) { if (isValidOffset(pointer.offset)) ret.raw = (byte *)(_strings[pointer.offset]._value); else { - if (g_sci->getGameId() == "kq5") { + if (g_sci->getGameId() == GID_KQ5) { // This occurs in KQ5CD when interacting with certain objects } else { error("SystemStrings::dereference(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer)); -- cgit v1.2.3 From 7a14846bdd99dc81a70baa43836282af47205e16 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 26 Jun 2010 23:48:27 +0000 Subject: Removed the misleading getHeap() function (only valid for SCI0-SCI1), plus removed some unused defines svn-id: r50358 --- engines/sci/engine/segment.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 0a39d950b0..4524241110 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -417,12 +417,6 @@ void Script::mcpyInOut(int dst, const void *src, size_t n) { } } -int16 Script::getHeap(uint16 offset) const { - assert(offset + 1 < (int)_bufSize); - return READ_SCI11ENDIAN_UINT16(_buf + offset); -// return (_buf[offset] | (_buf[offset+1]) << 8); -} - SegmentRef SegmentObj::dereference(reg_t pointer) { error("Error: Trying to dereference pointer %04x:%04x to inappropriate segment", PRINT_REG(pointer)); -- cgit v1.2.3 From daab502028761f8da7a4f75a7bbd265f8127892d Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 27 Jun 2010 00:08:00 +0000 Subject: Cleanup svn-id: r50359 --- engines/sci/engine/segment.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 4524241110..13c7904726 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -588,11 +588,9 @@ void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback void CloneTable::freeAtAddress(SegManager *segMan, reg_t addr) { #ifdef GC_DEBUG - Object *victim_obj; + // assert(addr.segment == _segId); -// assert(addr.segment == _segId); - - victim_obj = &(_table[addr.offset]); + Object *victim_obj = &(_table[addr.offset]); if (!(victim_obj->_flags & OBJECT_FLAG_FREED)) warning("[GC] Clone %04x:%04x not reachable and not freed (freeing now)", PRINT_REG(addr)); -- cgit v1.2.3 From bb992b0b93f3ee9dfad6524fd0721a350f12085a Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 27 Jun 2010 20:38:43 +0000 Subject: SCI: Moved all the script-related code inside script.cpp/.h, and all script opcode-related code inside vm.cpp/.h svn-id: r50396 --- engines/sci/engine/segment.cpp | 326 +---------------------------------------- 1 file changed, 1 insertion(+), 325 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 13c7904726..2bbedf2dcf 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -86,196 +86,8 @@ SegmentObj *SegmentObj::createSegmentObj(SegmentType type) { return mem; } -Script::Script() : SegmentObj(SEG_TYPE_SCRIPT) { - _nr = 0; - _buf = NULL; - _bufSize = 0; - _scriptSize = 0; - _heapSize = 0; - - _synonyms = NULL; - _heapStart = NULL; - _exportTable = NULL; - - _localsOffset = 0; - _localsSegment = 0; - _localsBlock = NULL; - _localsCount = 0; - - _markedAsDeleted = false; -} - -Script::~Script() { - freeScript(); -} - -void Script::freeScript() { - free(_buf); - _buf = NULL; - _bufSize = 0; - - _objects.clear(); -} - -void Script::init(int script_nr, ResourceManager *resMan) { - Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0); - - _localsOffset = 0; - _localsBlock = NULL; - _localsCount = 0; - - _markedAsDeleted = false; - - _nr = script_nr; - _buf = 0; - _heapStart = 0; - - _scriptSize = script->size; - _bufSize = script->size; - _heapSize = 0; - - _lockers = 1; - - if (getSciVersion() == SCI_VERSION_0_EARLY) { - _bufSize += READ_LE_UINT16(script->data) * 2; - } else if (getSciVersion() >= SCI_VERSION_1_1) { - /** - * In SCI11, the heap was in a separate space from the script. - * We append it to the end of the script, and adjust addressing accordingly. - * However, since we address the heap with a 16-bit pointer, the combined - * size of the stack and the heap must be 64KB. So far this has worked - * for SCI11, SCI2 and SCI21 games. SCI3 games use a different script format, - * and theoretically they can exceed the 64KB boundary using relocation. - */ - 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++; - } - - // As mentioned above, the script and the heap together should not exceed 64KB - if (script->size + heap->size > 65535) - error("Script and heap sizes combined exceed 64K. This means a fundamental " - "design bug was made regarding SCI1.1 and newer games.\nPlease " - "report this error to the ScummVM team"); - } -} - -void Script::load(ResourceManager *resMan) { - Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, _nr), 0); - assert(script != 0); - - _buf = (byte *)malloc(_bufSize); - assert(_buf); - - assert(_bufSize >= script->size); - memcpy(_buf, script->data, script->size); - - if (getSciVersion() >= SCI_VERSION_1_1) { - Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, _nr), 0); - assert(heap != 0); - - _heapStart = _buf + _scriptSize; - - assert(_bufSize - _scriptSize <= heap->size); - memcpy(_heapStart, heap->data, heap->size); - } - - _exportTable = 0; - _numExports = 0; - _synonyms = 0; - _numSynonyms = 0; - - if (getSciVersion() >= SCI_VERSION_1_1) { - if (READ_LE_UINT16(_buf + 1 + 5) > 0) { // does the script have an export table? - _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); - if (_exportTable) { - _numExports = READ_SCI11ENDIAN_UINT16(_exportTable + 1); - _exportTable += 3; // skip header plus 2 bytes (_exportTable is a uint16 pointer) - } - _synonyms = findBlock(SCI_OBJ_SYNONYMS); - if (_synonyms) { - _numSynonyms = READ_SCI11ENDIAN_UINT16(_synonyms + 2) / 4; - _synonyms += 4; // skip header - } - const byte* localsBlock = findBlock(SCI_OBJ_LOCALVARS); - 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) { - error("Locals extend beyond end of script: offset %04x, count %d vs size %d", _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) { - return &_objects[offset]; -} - -Object *Script::getObject(uint16 offset) { - if (_objects.contains(offset)) - return &_objects[offset]; - else - return 0; -} - -const Object *Script::getObject(uint16 offset) const { - if (_objects.contains(offset)) - return &_objects[offset]; - else - return 0; -} - -Object *Script::scriptObjInit(reg_t obj_pos, bool fullObjectInit) { - Object *obj; - - if (getSciVersion() < SCI_VERSION_1_1 && fullObjectInit) - obj_pos.offset += 8; // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET) - - VERIFY(obj_pos.offset < _bufSize, "Attempt to initialize object beyond end of script\n"); - - obj = allocateObject(obj_pos.offset); - - VERIFY(obj_pos.offset + kOffsetFunctionArea < (int)_bufSize, "Function area pointer stored beyond end of script\n"); - - obj->init(_buf, obj_pos, fullObjectInit); - - return obj; -} - -void Script::scriptObjRemove(reg_t obj_pos) { - if (getSciVersion() < SCI_VERSION_1_1) - obj_pos.offset += 8; - - _objects.erase(obj_pos.toUint16()); -} - // This helper function is used by Script::relocateLocal and Object::relocate +// Duplicate in segment.cpp and script.cpp static bool relocateBlock(Common::Array &block, int block_location, SegmentId segment, int location, size_t scriptSize) { int rel = location - block_location; @@ -298,148 +110,12 @@ static bool relocateBlock(Common::Array &block, int block_location, Segme return true; } -bool Script::relocateLocal(SegmentId segment, int location) { - if (_localsBlock) - return relocateBlock(_localsBlock->_locals, _localsOffset, segment, location, _scriptSize); - else - return false; -} - -void Script::relocate(reg_t block) { - byte *heap = _buf; - uint16 heapSize = (uint16)_bufSize; - uint16 heapOffset = 0; - - if (getSciVersion() >= SCI_VERSION_1_1) { - heap = _heapStart; - heapSize = (uint16)_heapSize; - heapOffset = _scriptSize; - } - - VERIFY(block.offset < (uint16)heapSize && READ_SCI11ENDIAN_UINT16(heap + block.offset) * 2 + block.offset < (uint16)heapSize, - "Relocation block outside of script\n"); - - int count = READ_SCI11ENDIAN_UINT16(heap + block.offset); - int exportIndex = 0; - int pos = 0; - - for (int i = 0; i < count; i++) { - pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; - // This occurs in SCI01/SCI1 games where usually one export value - // is zero. It seems that in this situation, we should skip the - // export and move to the next one, though the total count of valid - // exports remains the same - if (!pos) { - exportIndex++; - pos = READ_SCI11ENDIAN_UINT16(heap + block.offset + 2 + (exportIndex * 2)) + heapOffset; - if (!pos) - error("Script::relocate(): Consecutive zero exports found"); - } - - // In SCI0-SCI1, script local variables, objects and code are relocated. We only relocate - // locals and objects here, and ignore relocation of code blocks. In SCI1.1 and newer - // versions, only locals and objects are relocated. - if (!relocateLocal(block.segment, pos)) { - // Not a local? It's probably an object or code block. If it's an object, relocate it. - const ObjMap::iterator end = _objects.end(); - for (ObjMap::iterator it = _objects.begin(); it != end; ++it) - if (it->_value.relocate(block.segment, pos, _scriptSize)) - break; - } - - exportIndex++; - } -} - -void Script::incrementLockers() { - _lockers++; -} - -void Script::decrementLockers() { - if (_lockers > 0) - _lockers--; -} - -int Script::getLockers() const { - return _lockers; -} - -void Script::setLockers(int lockers) { - _lockers = lockers; -} - -uint16 Script::validateExportFunc(int pubfunct) { - bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); - - if (_numExports <= pubfunct) { - error("validateExportFunc(): pubfunct is invalid"); - return 0; - } - - if (exportsAreWide) - pubfunct *= 2; - uint16 offset = READ_SCI11ENDIAN_UINT16(_exportTable + pubfunct); - VERIFY(offset < _bufSize, "invalid export function pointer"); - - return offset; -} - -byte *Script::findBlock(int type) { - byte *buf = _buf; - bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY); - - if (oldScriptHeader) - buf += 2; - - do { - int seekerType = READ_LE_UINT16(buf); - - if (seekerType == 0) - break; - if (seekerType == type) - return buf; - - int seekerSize = READ_LE_UINT16(buf + 2); - assert(seekerSize > 0); - buf += seekerSize; - } while (1); - - return NULL; -} - - -// memory operations - -void Script::mcpyInOut(int dst, const void *src, size_t n) { - if (_buf) { - assert(dst + n <= _bufSize); - memcpy(_buf + dst, src, n); - } -} - SegmentRef SegmentObj::dereference(reg_t pointer) { error("Error: Trying to dereference pointer %04x:%04x to inappropriate segment", PRINT_REG(pointer)); return SegmentRef(); } -bool Script::isValidOffset(uint16 offset) const { - return offset < _bufSize; -} - -SegmentRef Script::dereference(reg_t pointer) { - if (pointer.offset > _bufSize) { - error("Script::dereference(): Attempt to dereference invalid pointer %04x:%04x into script segment (script size=%d)", - PRINT_REG(pointer), (uint)_bufSize); - return SegmentRef(); - } - - SegmentRef ret; - ret.isRaw = true; - ret.maxSize = _bufSize - pointer.offset; - ret.raw = _buf + pointer.offset; - return ret; -} bool LocalVariables::isValidOffset(uint16 offset) const { return offset < _locals.size() * 2; -- cgit v1.2.3 From 31b29027144e3a76ab6e8c71a0014ca6121218c0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 28 Jun 2010 11:22:41 +0000 Subject: SCI: Revise GC interface: use Common::Array instead of callbacks This means a little bit more overhead but makes the code much more readable and understandable. svn-id: r50429 --- engines/sci/engine/segment.cpp | 89 +++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 27 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 2bbedf2dcf..f8a941fa7a 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -218,20 +218,22 @@ void Script::freeAtAddress(SegManager *segMan, reg_t addr) { segMan->deallocateScript(_nr); } -void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) const { - (*note)(param, make_reg(segId, 0)); +Common::Array Script::listAllDeallocatable(SegmentId segId) const { + const reg_t r = make_reg(segId, 0); + return Common::Array(&r, 1); } -void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array Script::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) { const Object *obj = getObject(addr.offset); if (obj) { // Note all local variables, if we have a local variable environment if (_localsSegment) - (*note)(param, make_reg(_localsSegment, 0)); + tmp.push_back(make_reg(_localsSegment, 0)); for (uint i = 0; i < obj->getVarCount(); i++) - (*note)(param, obj->getVariable(i)); + tmp.push_back(obj->getVariable(i)); } else { error("Request for outgoing script-object reference at %04x:%04x failed", PRINT_REG(addr)); } @@ -239,12 +241,30 @@ void Script::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback not /* warning("Unexpected request for outgoing script-object references at %04x:%04x", PRINT_REG(addr));*/ /* Happens e.g. when we're looking into strings */ } + return tmp; } +Common::Array Script::listObjectReferences() const { + Common::Array tmp; + + // Locals, if present + if (_localsSegment) + tmp.push_back(make_reg(_localsSegment, 0)); + + // All objects (may be classes, may be indirectly reachable) + ObjMap::iterator it; + const ObjMap::iterator end = _objects.end(); + for (it = _objects.begin(); it != end; ++it) { + tmp.push_back(it->_value.getPos()); + } + + return tmp; +} //-------------------- clones -------------------- -void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array CloneTable::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; // assert(addr.segment == _segId); if (!isValidEntry(addr.offset)) { @@ -255,11 +275,13 @@ void CloneTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback // Emit all member variables (including references to the 'super' delegate) for (uint i = 0; i < clone->getVarCount(); i++) - (*note)(param, clone->getVariable(i)); + tmp.push_back(clone->getVariable(i)); // Note that this also includes the 'base' object, which is part of the script and therefore also emits the locals. - (*note)(param, clone->getPos()); + tmp.push_back(clone->getPos()); //debugC(2, kDebugLevelGC, "[GC] Reporting clone-pos %04x:%04x", PRINT_REG(clone->pos)); + + return tmp; } void CloneTable::freeAtAddress(SegManager *segMan, reg_t addr) { @@ -293,11 +315,14 @@ reg_t LocalVariables::findCanonicAddress(SegManager *segMan, reg_t addr) const { return make_reg(owner_seg, 0); } -void LocalVariables::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array LocalVariables::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; // assert(addr.segment == _segId); for (uint i = 0; i < _locals.size(); i++) - (*note)(param, _locals[i]); + tmp.push_back(_locals[i]); + + return tmp; } @@ -307,11 +332,14 @@ reg_t DataStack::findCanonicAddress(SegManager *segMan, reg_t addr) const { return addr; } -void DataStack::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array DataStack::listAllOutgoingReferences(reg_t object) const { + Common::Array tmp; fprintf(stderr, "Emitting %d stack entries\n", _capacity); for (int i = 0; i < _capacity; i++) - (*note)(param, _entries[i]); + tmp.push_back(_entries[i]); fprintf(stderr, "DONE"); + + return tmp; } @@ -320,18 +348,20 @@ void ListTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void ListTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array ListTable::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; if (!isValidEntry(addr.offset)) { error("Invalid list referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); - return; } const List *list = &(_table[addr.offset]); - note(param, list->first); - note(param, list->last); + tmp.push_back(list->first); + tmp.push_back(list->last); // We could probably get away with just one of them, but // let's be conservative here. + + return tmp; } @@ -340,19 +370,21 @@ void NodeTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void NodeTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array NodeTable::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; if (!isValidEntry(addr.offset)) { error("Invalid node referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); - return; } const Node *node = &(_table[addr.offset]); // We need all four here. Can't just stick with 'pred' OR 'succ' because node operations allow us // to walk around from any given node - note(param, node->pred); - note(param, node->succ); - note(param, node->key); - note(param, node->value); + tmp.push_back(node->pred); + tmp.push_back(node->succ); + tmp.push_back(node->key); + tmp.push_back(node->value); + + return tmp; } @@ -473,8 +505,9 @@ reg_t DynMem::findCanonicAddress(SegManager *segMan, reg_t addr) const { return addr; } -void DynMem::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) const { - (*note)(param, make_reg(segId, 0)); +Common::Array DynMem::listAllDeallocatable(SegmentId segId) const { + const reg_t r = make_reg(segId, 0); + return Common::Array(&r, 1); } #ifdef ENABLE_SCI32 @@ -492,10 +525,10 @@ void ArrayTable::freeAtAddress(SegManager *segMan, reg_t sub_addr) { freeEntry(sub_addr.offset); } -void ArrayTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback note) const { +Common::Array ArrayTable::listAllOutgoingReferences(reg_t addr) const { + Common::Array tmp; if (!isValidEntry(addr.offset)) { error("Invalid array referenced for outgoing references: %04x:%04x", PRINT_REG(addr)); - return; } const SciArray *array = &(_table[addr.offset]); @@ -503,8 +536,10 @@ void ArrayTable::listAllOutgoingReferences(reg_t addr, void *param, NoteCallback for (uint32 i = 0; i < array->getSize(); i++) { reg_t value = array->getValue(i); if (value.segment != 0) - note(param, value); + tmp.push_back(value); } + + return tmp; } Common::String SciString::toString() const { -- cgit v1.2.3 From 6c0205b104e30a60b2c5f9ff5c5e417fde497808 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 28 Jun 2010 11:23:00 +0000 Subject: SCI: Fix DEBUG_GC mode and permanently enable it svn-id: r50430 --- engines/sci/engine/segment.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index f8a941fa7a..21ca1fe9b4 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -86,6 +86,50 @@ SegmentObj *SegmentObj::createSegmentObj(SegmentType type) { return mem; } +const char *SegmentObj::getSegmentTypeName(SegmentType type) { + switch (type) { + case SEG_TYPE_SCRIPT: + return "script"; + break; + case SEG_TYPE_CLONES: + return "clones"; + break; + case SEG_TYPE_LOCALS: + return "locals"; + break; + case SEG_TYPE_SYS_STRINGS: + return "strings"; + break; + case SEG_TYPE_STACK: + return "stack"; + break; + case SEG_TYPE_HUNK: + return "hunk"; + break; + case SEG_TYPE_LISTS: + return "lists"; + break; + case SEG_TYPE_NODES: + return "nodes"; + break; + case SEG_TYPE_DYNMEM: + return "dynmem"; + break; +#ifdef ENABLE_SCI32 + case SEG_TYPE_ARRAY: + return "array"; + break; + case SEG_TYPE_STRING: + return "string"; + break; +#endif + default: + error("Unknown SegmentObj type %d", type); + break; + } + 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 &block, int block_location, SegmentId segment, int location, size_t scriptSize) { -- cgit v1.2.3 From 4fdbd14a60afc72c3b936b02dffd39935594e8e5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 28 Jun 2010 12:28:46 +0000 Subject: SCI: Move a few remaining Script methods to engine/script.cpp svn-id: r50441 --- engines/sci/engine/segment.cpp | 60 ------------------------------------------ 1 file changed, 60 deletions(-) (limited to 'engines/sci/engine/segment.cpp') diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index 21ca1fe9b4..cb908979a3 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -245,66 +245,6 @@ SegmentRef SystemStrings::dereference(reg_t pointer) { } -//-------------------- script -------------------- -reg_t Script::findCanonicAddress(SegManager *segMan, reg_t addr) const { - addr.offset = 0; - return addr; -} - -void Script::freeAtAddress(SegManager *segMan, reg_t addr) { - /* - debugC(2, kDebugLevelGC, "[GC] Freeing script %04x:%04x", PRINT_REG(addr)); - if (_localsSegment) - debugC(2, kDebugLevelGC, "[GC] Freeing locals %04x:0000", _localsSegment); - */ - - if (_markedAsDeleted) - segMan->deallocateScript(_nr); -} - -Common::Array Script::listAllDeallocatable(SegmentId segId) const { - const reg_t r = make_reg(segId, 0); - return Common::Array(&r, 1); -} - -Common::Array Script::listAllOutgoingReferences(reg_t addr) const { - Common::Array tmp; - if (addr.offset <= _bufSize && addr.offset >= -SCRIPT_OBJECT_MAGIC_OFFSET && RAW_IS_OBJECT(_buf + addr.offset)) { - const Object *obj = getObject(addr.offset); - if (obj) { - // Note all local variables, if we have a local variable environment - if (_localsSegment) - tmp.push_back(make_reg(_localsSegment, 0)); - - for (uint i = 0; i < obj->getVarCount(); i++) - tmp.push_back(obj->getVariable(i)); - } else { - error("Request for outgoing script-object reference at %04x:%04x failed", PRINT_REG(addr)); - } - } else { - /* warning("Unexpected request for outgoing script-object references at %04x:%04x", PRINT_REG(addr));*/ - /* Happens e.g. when we're looking into strings */ - } - return tmp; -} - -Common::Array Script::listObjectReferences() const { - Common::Array tmp; - - // Locals, if present - if (_localsSegment) - tmp.push_back(make_reg(_localsSegment, 0)); - - // All objects (may be classes, may be indirectly reachable) - ObjMap::iterator it; - const ObjMap::iterator end = _objects.end(); - for (it = _objects.begin(); it != end; ++it) { - tmp.push_back(it->_value.getPos()); - } - - return tmp; -} - //-------------------- clones -------------------- Common::Array CloneTable::listAllOutgoingReferences(reg_t addr) const { -- cgit v1.2.3