aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/engine/game.cpp2
-rw-r--r--engines/sci/engine/kmovement.cpp2
-rw-r--r--engines/sci/engine/kscripts.cpp8
-rw-r--r--engines/sci/engine/kstring.cpp4
-rw-r--r--engines/sci/engine/savegame.cpp2
-rw-r--r--engines/sci/engine/scriptdebug.cpp4
-rw-r--r--engines/sci/engine/seg_manager.cpp42
-rw-r--r--engines/sci/engine/seg_manager.h28
-rw-r--r--engines/sci/engine/vm.cpp24
9 files changed, 46 insertions, 70 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 720bf04176..b0df4aacde 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -408,7 +408,7 @@ int script_init_engine(EngineState *s, sci_version_t version) {
return 1;
}
- s->script_000 = s->seg_manager->getScript(s->script_000_segment, SEG_ID);
+ s->script_000 = s->seg_manager->getScript(s->script_000_segment);
s->sys_strings = s->seg_manager->allocateSysStrings(&s->sys_strings_segment);
s->string_frag_segment = s->seg_manager->allocateStringFrags();
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index a2e244d265..8b3c2d0db0 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -271,7 +271,7 @@ static void bresenham_autodetect(EngineState *s) {
return;
}
- buf = s->seg_manager->getScript(fptr.segment, SEG_ID)->buf + fptr.offset;
+ buf = s->seg_manager->getScript(fptr.segment)->buf + fptr.offset;
handle_movecnt = (s->version <= SCI_VERSION_0 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
sciprintf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ? "ignore" : "increment");
} else {
diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp
index 9464ba92c8..f00731aab4 100644
--- a/engines/sci/engine/kscripts.cpp
+++ b/engines/sci/engine/kscripts.cpp
@@ -184,8 +184,8 @@ reg_t kClone(EngineState *s, int funct_nr, int argc, reg_t *argv) {
clone_obj->_variables[SCRIPT_SPECIES_SELECTOR] = clone_obj->pos;
if (IS_CLASS(parent_obj))
clone_obj->_variables[SCRIPT_SUPERCLASS_SELECTOR] = parent_obj->pos;
- s->seg_manager->getScript(parent_obj->pos.segment, SEG_ID)->incrementLockers();
- s->seg_manager->getScript(clone_obj->pos.segment, SEG_ID)->incrementLockers();
+ s->seg_manager->getScript(parent_obj->pos.segment)->incrementLockers();
+ s->seg_manager->getScript(clone_obj->pos.segment)->incrementLockers();
return clone_addr;
}
@@ -243,7 +243,7 @@ reg_t kScriptID(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if (!scriptid)
return NULL_REG;
- scr = s->seg_manager->getScript(scriptid, SEG_ID);
+ scr = s->seg_manager->getScript(scriptid);
if (!scr->exports_nr) {
SCIkdebug(SCIkERROR, "Script 0x%x does not have a dispatch table\n", script);
@@ -266,7 +266,7 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
int id = s->seg_manager->segGet(script);
- Script *scr = s->seg_manager->getScriptIfLoaded(id, SEG_ID);
+ Script *scr = s->seg_manager->getScriptIfLoaded(id);
if (scr) {
if (s->_executionStack[s->execution_stack_pos].addr.pc.segment != id)
scr->setLockers(1);
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 9c9eb6ede8..edb5424219 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -200,12 +200,12 @@ reg_t kSetSynonyms(EngineState *s, int funct_nr, int argc, reg_t *argv) {
seg = s->seg_manager->segGet(script);
if (seg >= 0)
- synonyms_nr = s->seg_manager->getScript(seg, SEG_ID)->getSynonymsNr();
+ synonyms_nr = s->seg_manager->getScript(seg)->getSynonymsNr();
if (synonyms_nr) {
byte *synonyms;
- synonyms = s->seg_manager->getScript(seg, SEG_ID)->getSynonyms();
+ synonyms = s->seg_manager->getScript(seg)->getSynonyms();
if (synonyms) {
SCIkdebug(SCIkPARSER, "Setting %d synonyms for script.%d\n",
synonyms_nr, script);
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 69275e8ada..72e96c6e8f 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -817,7 +817,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
reconstruct_scripts(retval, retval->seg_manager);
reconstruct_clones(retval, retval->seg_manager);
retval->game_obj = s->game_obj;
- retval->script_000 = retval->seg_manager->getScript(script_get_segment(s, 0, SCRIPT_GET_DONT_LOAD), SEG_ID);
+ retval->script_000 = retval->seg_manager->getScript(script_get_segment(s, 0, SCRIPT_GET_DONT_LOAD));
retval->gc_countdown = GC_INTERVAL - 1;
retval->save_dir_copy = make_reg(s->sys_strings_segment, SYS_STRING_SAVEDIR);
retval->save_dir_edit_offset = 0;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index ae538554d7..5dcf42cf59 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -639,7 +639,7 @@ int c_segkill(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
while (i < cmdParams.size()) {
int nr = cmdParams[i++].val;
- s->seg_manager->getScript(nr, SEG_ID)->setLockers(0);
+ s->seg_manager->getScript(nr)->setLockers(0);
}
return 0;
}
@@ -2551,7 +2551,7 @@ int objinfo(EngineState *s, reg_t pos) {
sciprintf(" [%03x] %s = "PREG"\n", VM_OBJECT_GET_FUNCSELECTOR(obj, i), selector_name(s, VM_OBJECT_GET_FUNCSELECTOR(obj, i)), PRINT_REG(fptr));
}
if (s->seg_manager->_heap[pos.segment]->getType() == MEM_OBJ_SCRIPT)
- sciprintf("\nOwner script:\t%d\n", s->seg_manager->getScript(pos.segment, SEG_ID)->nr);
+ sciprintf("\nOwner script:\t%d\n", s->seg_manager->getScript(pos.segment)->nr);
return 0;
}
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index ad7b2e8fc1..80909bba8c 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -387,23 +387,20 @@ int SegManager::segGet(int script_id) const {
return id_seg_map->lookupKey(script_id);
}
-Script *SegManager::getScript(const int id, idFlag flag) {
- const int seg = (flag == SCRIPT_ID) ? segGet(id) : id;
-
+Script *SegManager::getScript(const int seg) {
if (seg < 0 || (uint)seg >= _heap.size()) {
- error("SegManager::getScript(%d,%d): seg id %x out of bounds", id, flag, seg);
+ error("SegManager::getScript(): seg id %x out of bounds", seg);
}
if (!_heap[seg]) {
- error("SegManager::getScript(%d,%d): seg id %x is not in memory", id, flag, seg);
+ error("SegManager::getScript(): seg id %x is not in memory", seg);
}
if (_heap[seg]->getType() != MEM_OBJ_SCRIPT) {
- error("SegManager::getScript(%d,%d): seg id %x refers to type %d != MEM_OBJ_SCRIPT", id, flag, seg, _heap[seg]->getType());
+ error("SegManager::getScript(): seg id %x refers to type %d != MEM_OBJ_SCRIPT", seg, _heap[seg]->getType());
}
return (Script *)_heap[seg];
}
-Script *SegManager::getScriptIfLoaded(const int id, idFlag flag) {
- const int seg = (flag == SCRIPT_ID) ? segGet(id) : id;
+Script *SegManager::getScriptIfLoaded(const int seg) {
if (seg < 0 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT)
return 0;
return (Script *)_heap[seg];
@@ -424,11 +421,8 @@ bool SegManager::check(int seg) {
return true;
}
-int SegManager::scriptIsLoaded(int id, idFlag flag) {
- if (flag == SCRIPT_ID)
- id = segGet(id);
-
- return check(id);
+bool SegManager::scriptIsLoaded(int seg) {
+ return getScriptIfLoaded(seg) != 0;
}
void Script::incrementLockers() {
@@ -495,7 +489,7 @@ int SegManager::relocateBlock(Common::Array<reg_t> &block, int block_location, S
}
block[idx].segment = segment; // Perform relocation
if (isSci1_1)
- block[idx].offset += getScript(segment, SEG_ID)->script_size;
+ block[idx].offset += getScript(segment)->script_size;
return 1;
}
@@ -512,7 +506,7 @@ int SegManager::relocateObject(Object *obj, SegmentId segment, int location) {
}
void SegManager::scriptAddCodeBlock(reg_t location) {
- Script *scr = getScript(location.segment, SEG_ID);
+ Script *scr = getScript(location.segment);
CodeBlock cb;
cb.pos = location;
@@ -521,7 +515,7 @@ void SegManager::scriptAddCodeBlock(reg_t location) {
}
void SegManager::scriptRelocate(reg_t block) {
- Script *scr = getScript(block.segment, SEG_ID);
+ Script *scr = getScript(block.segment);
VERIFY(block.offset < (uint16)scr->buf_size && READ_LE_UINT16(scr->buf + block.offset) * 2 + block.offset < (uint16)scr->buf_size,
"Relocation block outside of script\n");
@@ -567,7 +561,7 @@ void SegManager::scriptRelocate(reg_t block) {
}
void SegManager::heapRelocate(EngineState *s, reg_t block) {
- Script *scr = getScript(block.segment, SEG_ID);
+ Script *scr = getScript(block.segment);
VERIFY(block.offset < (uint16)scr->heap_size && READ_LE_UINT16(scr->heap_start + block.offset) * 2 + block.offset < (uint16)scr->buf_size,
"Relocation block outside of script\n");
@@ -615,7 +609,7 @@ Object *SegManager::scriptObjInit0(EngineState *s, reg_t obj_pos) {
unsigned int base = obj_pos.offset - SCRIPT_OBJECT_MAGIC_OFFSET;
reg_t temp;
- Script *scr = getScript(obj_pos.segment, SEG_ID);
+ Script *scr = getScript(obj_pos.segment);
VERIFY(base < scr->buf_size, "Attempt to initialize object beyond end of script\n");
@@ -670,7 +664,7 @@ Object *SegManager::scriptObjInit11(EngineState *s, reg_t obj_pos) {
int id;
int base = obj_pos.offset;
- Script *scr = getScript(obj_pos.segment, SEG_ID);
+ Script *scr = getScript(obj_pos.segment);
VERIFY(base < (uint16)scr->buf_size, "Attempt to initialize object beyond end of script\n");
@@ -751,7 +745,7 @@ LocalVariables *SegManager::allocLocalsSegment(Script *scr, int count) {
}
void SegManager::scriptInitialiseLocalsZero(SegmentId seg, int count) {
- Script *scr = getScript(seg, SEG_ID);
+ Script *scr = getScript(seg);
scr->locals_offset = -count * 2; // Make sure it's invalid
@@ -759,7 +753,7 @@ void SegManager::scriptInitialiseLocalsZero(SegmentId seg, int count) {
}
void SegManager::scriptInitialiseLocals(reg_t location) {
- Script *scr = getScript(location.segment, SEG_ID);
+ Script *scr = getScript(location.segment);
unsigned int count;
VERIFY(location.offset + 1 < (uint16)scr->buf_size, "Locals beyond end of script\n");
@@ -788,7 +782,7 @@ void SegManager::scriptInitialiseLocals(reg_t location) {
}
void SegManager::scriptRelocateExportsSci11(int seg) {
- Script *scr = getScript(seg, SEG_ID);
+ Script *scr = getScript(seg);
for (int i = 0; i < scr->exports_nr; i++) {
/* We are forced to use an ugly heuristic here to distinguish function
exports from object/class exports. The former kind points into the
@@ -804,7 +798,7 @@ void SegManager::scriptRelocateExportsSci11(int seg) {
}
void SegManager::scriptInitialiseObjectsSci11(EngineState *s, int seg) {
- Script *scr = getScript(seg, SEG_ID);
+ Script *scr = getScript(seg);
byte *seeker = scr->heap_start + 4 + READ_LE_UINT16(scr->heap_start + 2) * 2;
while (READ_LE_UINT16(seeker) == SCRIPT_OBJECT_MAGIC_NUMBER) {
@@ -895,7 +889,7 @@ SegmentId SegManager::allocateStringFrags() {
}
uint16 SegManager::validateExportFunc(int pubfunct, int seg) {
- Script *scr = getScript(seg, SEG_ID);
+ Script *scr = getScript(seg);
if (scr->exports_nr <= pubfunct) {
sciprintf("pubfunct is invalid");
return 0;
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index 549363b9aa..264e39a684 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -32,12 +32,6 @@
namespace Sci {
-// SCRIPT_ID must be 0
-enum idFlag {
- SCRIPT_ID,
- SEG_ID
-};
-
#define GET_SEGMENT(mgr, index, rtype) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
(((mgr)._heap[index] && (mgr)._heap[index]->getType() == rtype)? (mgr)._heap[index] : NULL) : NULL)
@@ -77,12 +71,9 @@ public:
/**
* Determines whether a script has been loaded yet.
- * @param id number of the script or ID of the script segment to check for
- * @param flag whether to address the script by script number (SCRIPT_ID) or
- * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
- * but less convenient.
+ * @param seg ID of the script segment to check for
*/
- int scriptIsLoaded(int id, idFlag flag);
+ bool scriptIsLoaded(int seg);
// Validate whether the specified public function is exported by the script in the specified segment
// Parameters: (int) pubfunct: Index of the function to validate
@@ -99,24 +90,17 @@ public:
/**
* Return a pointer to the specified script. If the id is invalid, does not refer
* to a script or the script is not loaded, this will invoke error().
- * @param id number of the script or ID of the script segment to check for
- * @param flag whether to address the script by script number (SCRIPT_ID) or
- * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
- * but less convenient.
+ * @param seg ID of the script segment to check for
* @return pointer to the Script object
*/
- Script *getScript(int id, idFlag flag);
+ Script *getScript(int seg);
/**
* Return a pointer to the specified script. If the id is invalid, does not refer
- * to a script or the script is not loaded, this will return NULL.
- * @param id number of the script or ID of the script segment to check for
- * @param flag whether to address the script by script number (SCRIPT_ID) or
- * by its segment (SEG_ID). SEG_ID is faster than SCRIPT_ID,
- * but less convenient.
+ * @param seg ID of the script segment to check for
* @return pointer to the Script object, or NULL
*/
- Script *getScriptIfLoaded(int id, idFlag flag);
+ Script *getScriptIfLoaded(int seg);
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index c425d462fc..81b279f00f 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -222,7 +222,7 @@ reg_t get_class_address(EngineState *s, int classnr, int lock, reg_t caller) {
}
} else
if (caller.segment != the_class->reg.segment)
- s->seg_manager->getScript(the_class->reg.segment, SEG_ID)->incrementLockers();
+ s->seg_manager->getScript(the_class->reg.segment)->incrementLockers();
return the_class->reg;
}
@@ -252,17 +252,15 @@ reg_t get_class_address(EngineState *s, int classnr, int lock, reg_t caller) {
// Returns an object's superclass
ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackPtr sp, reg_t calling_obj, uint16 argc, StackPtr argp) {
- int seg;
- uint16 temp;
+ int seg = s->seg_manager->segGet(script);
+ Script *scr = s->seg_manager->getScriptIfLoaded(seg);
- seg = s->seg_manager->segGet(script);
-
- if (!s->seg_manager->scriptIsLoaded(seg, SEG_ID)) // Script not present yet?
+ if (!scr) // Script not present yet?
seg = script_instantiate(s, script);
else
- s->seg_manager->getScript(seg, SEG_ID)->unmarkDeleted();
+ scr->unmarkDeleted();
- temp = s->seg_manager->validateExportFunc(pubfunct, seg);
+ int temp = s->seg_manager->validateExportFunc(pubfunct, seg);
if (!temp) {
sciprintf("Request for invalid exported function 0x%x of script 0x%x\n", pubfunct, script);
script_error_flag = script_debug_flag = 1;
@@ -528,7 +526,7 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) {
}
static Script *script_locate_by_segment(EngineState *s, SegmentId seg) {
- return s->seg_manager->getScriptIfLoaded(seg, SEG_ID);
+ return s->seg_manager->getScriptIfLoaded(seg);
}
static reg_t pointer_add(EngineState *s, reg_t base, int offset) {
@@ -1591,7 +1589,7 @@ SegmentId script_get_segment(EngineState *s, int script_nr, int load) {
if (segment > 0) {
if ((load & SCRIPT_GET_LOCK) == SCRIPT_GET_LOCK)
- s->seg_manager->getScript(segment, SEG_ID)->incrementLockers();
+ s->seg_manager->getScript(segment)->incrementLockers();
return segment;
} else
@@ -1713,7 +1711,7 @@ int script_instantiate_sci0(EngineState *s, int script_nr) {
reg.segment = seg_id;
reg.offset = 0;
- Script *scr = s->seg_manager->getScript(seg_id, SEG_ID);
+ Script *scr = s->seg_manager->getScript(seg_id);
if (s->flags & GF_SCI0_OLD) {
//
@@ -1861,7 +1859,7 @@ int script_instantiate_sci11(EngineState *s, int script_nr) {
if (was_new)
return seg_id;
- Script *scr = s->seg_manager->getScript(seg_id, SEG_ID);
+ Script *scr = s->seg_manager->getScript(seg_id);
heap_start = script->size;
if (script->size & 2)
@@ -1896,7 +1894,7 @@ int script_instantiate(EngineState *s, int script_nr) {
void script_uninstantiate_sci0(EngineState *s, int script_nr, SegmentId seg) {
reg_t reg = make_reg(seg, (s->flags & GF_SCI0_OLD) ? 2 : 0);
int objtype, objlength;
- Script *scr = s->seg_manager->getScript(seg, SEG_ID);
+ Script *scr = s->seg_manager->getScript(seg);
// Make a pass over the object in order uninstantiate all superclasses
objlength = 0;