diff options
author | Max Horn | 2009-09-06 12:58:16 +0000 |
---|---|---|
committer | Max Horn | 2009-09-06 12:58:16 +0000 |
commit | fdbb167ea3962bb9202c81af37da4ee4955f4626 (patch) | |
tree | b9ddb9c51da98157ed1541e36271c25ba540d03f | |
parent | d04b5d2c9b46c1bf0ad8a7b93981eae301163cb3 (diff) | |
download | scummvm-rg350-fdbb167ea3962bb9202c81af37da4ee4955f4626.tar.gz scummvm-rg350-fdbb167ea3962bb9202c81af37da4ee4955f4626.tar.bz2 scummvm-rg350-fdbb167ea3962bb9202c81af37da4ee4955f4626.zip |
SCI: Cleanup for some SegManager internals
- rename segGet and getSegment to getScriptSegment; the two can be
distinguished by the parameter count.
- rename type SCRIPT_GET to ScriptLoadType to conform with our code
formatting conventions
- rename get_class_address to getClassAddress
- some cleanup
svn-id: r43981
-rw-r--r-- | engines/sci/console.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/game.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/kscripts.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/kstring.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/memobj.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 24 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.h | 44 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 2 |
10 files changed, 51 insertions, 51 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 03cc1c8a07..c344b7ff62 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -2844,7 +2844,7 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on if (*endptr) return 1; - dest->segment = s->segMan->segGet(script_nr); + dest->segment = s->segMan->getScriptSegment(script_nr); if (!dest->segment) { return 1; diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index d00a3782a1..5cc5d5a25c 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -326,7 +326,7 @@ int script_init_engine(EngineState *s) { s->segMan = new SegManager(s->resMan); s->gc_countdown = GC_INTERVAL - 1; - SegmentId script_000_segment = s->segMan->getSegment(0, SCRIPT_GET_LOCK); + SegmentId script_000_segment = s->segMan->getScriptSegment(0, SCRIPT_GET_LOCK); if (script_000_segment <= 0) { debug(2, "Failed to instantiate script.000"); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index 551e7cd535..624c67cbd6 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -268,7 +268,7 @@ reg_t kScriptID(EngineState *s, int, int argc, reg_t *argv) { if (argv[0].segment) return argv[0]; - SegmentId scriptSeg = s->segMan->getSegment(script, SCRIPT_GET_LOAD); + SegmentId scriptSeg = s->segMan->getScriptSegment(script, SCRIPT_GET_LOAD); Script *scr; if (!scriptSeg) @@ -297,7 +297,7 @@ reg_t kDisposeScript(EngineState *s, int, int argc, reg_t *argv) { if (argv[0].segment) return s->r_acc; - int id = s->segMan->segGet(script); + int id = s->segMan->getScriptSegment(script); Script *scr = s->segMan->getScriptIfLoaded(id); if (scr) { if (s->_executionStack.back().addr.pc.segment != id) diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 3c18a14ea8..6fd438bd62 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -146,7 +146,7 @@ reg_t kSetSynonyms(EngineState *s, int, int argc, reg_t *argv) { int synonyms_nr = 0; script = GET_SEL32V(objpos, number); - seg = s->segMan->segGet(script); + seg = s->segMan->getScriptSegment(script); if (seg >= 0) synonyms_nr = s->segMan->getScript(seg)->getSynonymsNr(); diff --git a/engines/sci/engine/memobj.cpp b/engines/sci/engine/memobj.cpp index 5f31546b91..97572664de 100644 --- a/engines/sci/engine/memobj.cpp +++ b/engines/sci/engine/memobj.cpp @@ -319,9 +319,9 @@ void CloneTable::freeAtAddress(SegManager *segMan, reg_t addr) { //-------------------- locals -------------------- reg_t LocalVariables::findCanonicAddress(SegManager *segMan, reg_t addr) { // Reference the owning script - SegmentId owner_seg = segMan->segGet(script_id); + SegmentId owner_seg = segMan->getScriptSegment(script_id); - assert(owner_seg >= 0); + assert(owner_seg > 0); return make_reg(owner_seg, 0); } diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 96343cb300..70a39f32fd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -714,7 +714,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { reconstruct_scripts(retval, retval->segMan); retval->segMan->reconstructClones(); retval->game_obj = s->game_obj; - retval->script_000 = retval->segMan->getScript(retval->segMan->getSegment(0, SCRIPT_GET_DONT_LOAD)); + retval->script_000 = retval->segMan->getScript(retval->segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD)); retval->gc_countdown = GC_INTERVAL - 1; retval->sys_strings_segment = retval->segMan->findSegmentByType(MEM_OBJ_SYS_STRINGS); retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segMan, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 8881f54f8f..e3f746560b 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -235,7 +235,7 @@ bool SegManager::scriptIsMarkedAsDeleted(SegmentId seg) { int SegManager::deallocateScript(int script_nr) { - SegmentId seg = segGet(script_nr); + SegmentId seg = getScriptSegment(script_nr); deallocate(seg, true); @@ -262,13 +262,12 @@ MemObject *SegManager::memObjAllocate(SegmentId segid, int hash_id, MemObjectTyp } // return the seg if script_id is valid and in the map, else -1 -SegmentId SegManager::segGet(int script_id) const { +SegmentId SegManager::getScriptSegment(int script_id) const { return id_seg_map->lookupKey(script_id); } Script *SegManager::getScript(const SegmentId seg) { - // FIXME: We accept segment 0, but that is actually an invalid segment... - if (seg < 0 || (uint)seg >= _heap.size()) { + if (seg <= 0 || (uint)seg >= _heap.size()) { error("SegManager::getScript(): seg id %x out of bounds", seg); } if (!_heap[seg]) { @@ -282,7 +281,7 @@ Script *SegManager::getScript(const SegmentId seg) { Script *SegManager::getScriptIfLoaded(const SegmentId seg) { // FIXME: We accept segment 0, but that is actually an invalid segment... - if (seg < 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT) + if (seg <= 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT) return 0; return (Script *)_heap[seg]; } @@ -299,8 +298,7 @@ SegmentId SegManager::findSegmentByType(int type) { // false - invalid seg // true - valid seg bool SegManager::check(SegmentId seg) { - // FIXME: We accept segment 0, but that is actually an invalid segment... - if (seg < 0 || (uint)seg >= _heap.size()) { + if (seg <= 0 || (uint)seg >= _heap.size()) { return false; } if (!_heap[seg]) { @@ -443,13 +441,13 @@ void SegManager::heapRelocate(reg_t block) { } } -SegmentId SegManager::getSegment(int script_nr, SCRIPT_GET load) { +SegmentId SegManager::getScriptSegment(int script_nr, ScriptLoadType load) { SegmentId segment; if ((load & SCRIPT_GET_LOAD) == SCRIPT_GET_LOAD) script_instantiate(_resMan, this, script_nr); - segment = segGet(script_nr); + segment = getScriptSegment(script_nr); if (segment > 0) { if ((load & SCRIPT_GET_LOCK) == SCRIPT_GET_LOCK) @@ -457,19 +455,19 @@ SegmentId SegManager::getSegment(int script_nr, SCRIPT_GET load) { return segment; } else - return 0; + return -1; } -#define INST_LOOKUP_CLASS(id) ((id == 0xffff) ? NULL_REG : get_class_address(id, SCRIPT_GET_LOCK, NULL_REG)) +#define INST_LOOKUP_CLASS(id) ((id == 0xffff) ? NULL_REG : getClassAddress(id, SCRIPT_GET_LOCK, NULL_REG)) -reg_t SegManager::get_class_address(int classnr, SCRIPT_GET lock, reg_t caller) { +reg_t SegManager::getClassAddress(int classnr, ScriptLoadType lock, reg_t caller) { if (classnr < 0 || (int)_classtable.size() <= classnr || _classtable[classnr].script < 0) { error("[VM] Attempt to dereference class %x, which doesn't exist (max %x)", classnr, _classtable.size()); return NULL_REG; } else { Class *the_class = &_classtable[classnr]; if (!the_class->reg.segment) { - getSegment(the_class->script, lock); + getScriptSegment(the_class->script, lock); if (!the_class->reg.segment) { error("[VM] Trying to instantiate class %x by instantiating script 0x%x (%03d) failed;" diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 0bdb9a5a4e..933718624e 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -44,24 +44,24 @@ namespace Sci { : NULL): NULL) /** - * Parameters for getSegment() + * Parameters for getScriptSegment(). */ -typedef enum { +enum ScriptLoadType { SCRIPT_GET_DONT_LOAD = 0, /**< Fail if not loaded */ SCRIPT_GET_LOAD = 1, /**< Load, if neccessary */ SCRIPT_GET_LOCK = 3 /**< Load, if neccessary, and lock */ -} SCRIPT_GET; +}; class SegManager : public Common::Serializable { public: /** - * Initialize the segment manager + * Initialize the segment manager. */ SegManager(ResourceManager *resMan); /** - * Deallocate all memory associated with the segment manager + * Deallocate all memory associated with the segment manager. */ ~SegManager(); @@ -70,7 +70,7 @@ public: // 1. Scripts /** - * Allocate a script into the segment manager + * Allocate a script into the segment manager. * @param script_nr The number of the script to load * @param seg_id The segment ID of the newly allocated segment, * on success @@ -81,7 +81,7 @@ public: // The script must then be initialised; see section (1b.), below. /** - * Forcefully deallocate a previously allocated script + * Forcefully deallocate a previously allocated script. * @param script_nr number of the script to deallocate * @return 1 on success, 0 on failure */ @@ -95,7 +95,7 @@ public: /** * Validate whether the specified public function is exported by - * the script in the specified segment + * the script in the specified segment. * @param pubfunct Index of the function to validate * @param seg Segment ID of the script the check is to * be performed for @@ -105,12 +105,23 @@ public: uint16 validateExportFunc(int pubfunct, SegmentId seg); /** - * Get the segment ID associated with a script number + * Determines the segment occupied by a certain script, if any. * @param script_nr Number of the script to look up - * @return The associated segment ID, or -1 if no - * matching segment exists + * @return The script's segment ID, or -1 on failure + */ + SegmentId getScriptSegment(int script_nr) const; + + /** + * Determines the segment occupied by a certain script. Optionally + * load it, or load & lock it. + * @param[in] script_nr Number of the script to look up + * @param[in] load flag determining whether to load/lock the script + * @return The script's segment ID, or -1 on failure */ - SegmentId segGet(int script_nr) const; + SegmentId getScriptSegment(int script_nr, ScriptLoadType load); + + // TODO: document this + reg_t getClassAddress(int classnr, ScriptLoadType lock, reg_t caller); /** * Return a pointer to the specified script. @@ -335,15 +346,6 @@ public: */ byte *dereference(reg_t reg, int *size); - /** - * Determines the segment occupied by a certain script - * @param[in] script_id The script in question - * @param[in] load One of SCRIPT_GET_* - * @return The script's segment, or 0 on failure - */ - SegmentId getSegment(int script_nr, SCRIPT_GET load); - reg_t get_class_address(int classnr, SCRIPT_GET lock, reg_t caller); - void heapRelocate(reg_t block); void scriptRelocateExportsSci11(SegmentId seg); diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 505fc52d77..2eb02f3c14 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -204,7 +204,7 @@ static void validate_write_var(reg_t *r, reg_t *stack_base, int type, int max, i #define GET_OP_SIGNED_FLEX() ((opcode & 1)? GET_OP_SIGNED_BYTE() : GET_OP_SIGNED_WORD()) ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) { - int seg = s->segMan->segGet(script); + int seg = s->segMan->getScriptSegment(script); Script *scr = s->segMan->getScriptIfLoaded(seg); if (!scr) // Script not present yet? @@ -212,7 +212,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP else scr->unmarkDeleted(); - int temp = s->segMan->validateExportFunc(pubfunct, seg); + const int temp = s->segMan->validateExportFunc(pubfunct, seg); if (!temp) { error("Request for invalid exported function 0x%x of script 0x%x", pubfunct, script); return NULL; @@ -1042,7 +1042,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x28: // class - s->r_acc = s->segMan->get_class_address((unsigned)opparams[0], SCRIPT_GET_LOCK, + s->r_acc = s->segMan->getClassAddress((unsigned)opparams[0], SCRIPT_GET_LOCK, scriptState.xs->addr.pc); break; @@ -1062,7 +1062,7 @@ void run_vm(EngineState *s, int restoring) { break; case 0x2b: // super - r_temp = s->segMan->get_class_address(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); + r_temp = s->segMan->getClassAddress(opparams[0], SCRIPT_GET_LOAD, scriptState.xs->addr.pc); if (!r_temp.segment) error("[VM]: Invalid superclass in object"); @@ -1506,11 +1506,11 @@ SelectorType lookup_selector(SegManager *segMan, reg_t obj_location, Selector se } reg_t script_lookup_export(SegManager *segMan, int script_nr, int export_index) { - SegmentId seg = segMan->getSegment(script_nr, SCRIPT_GET_DONT_LOAD); + SegmentId seg = segMan->getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD); return make_reg(seg, segMan->validateExportFunc(export_index, seg)); } -#define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segMan->get_class_address(id, SCRIPT_GET_LOCK, reg)) +#define INST_LOOKUP_CLASS(id) ((id == 0xffff)? NULL_REG : segMan->getClassAddress(id, SCRIPT_GET_LOCK, reg)) int script_instantiate_common(ResourceManager *resMan, SegManager *segMan, int script_nr, Resource **script, Resource **heap, int *was_new) { int seg_id; @@ -1533,7 +1533,7 @@ int script_instantiate_common(ResourceManager *resMan, SegManager *segMan, int s return 0; } - seg_id = segMan->segGet(script_nr); + seg_id = segMan->getScriptSegment(script_nr); Script *scr = segMan->getScriptIfLoaded(seg_id); if (scr) { if (!scr->isMarkedAsDeleted()) { @@ -1821,7 +1821,7 @@ void script_uninstantiate_sci0(SegManager *segMan, int script_nr, SegmentId seg) } void script_uninstantiate(SegManager *segMan, int script_nr) { - SegmentId segment = segMan->segGet(script_nr); + SegmentId segment = segMan->getScriptSegment(script_nr); Script *scr = segMan->getScriptIfLoaded(segment); if (!scr) { // Is it already loaded? diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 99b0b4d9b7..54c268a502 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -344,7 +344,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPtr sp, int framesize, StackPtr argp); -#define SCI_XS_CALLEE_LOCALS -1 +#define SCI_XS_CALLEE_LOCALS ((SegmentId)-1) /** * Adds an entry to the top of the execution stack. |