aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorMax Horn2009-09-07 06:07:18 +0000
committerMax Horn2009-09-07 06:07:18 +0000
commit44b60d27507156f6a2d072845f3428483021865a (patch)
tree6d3709cbe4feb969b57238ef22bddbe822726464 /engines/sci/engine
parent9d13de7f88fc7e7307adba722bedcc657748b02f (diff)
downloadscummvm-rg350-44b60d27507156f6a2d072845f3428483021865a.tar.gz
scummvm-rg350-44b60d27507156f6a2d072845f3428483021865a.tar.bz2
scummvm-rg350-44b60d27507156f6a2d072845f3428483021865a.zip
SCI: Replace GET_SEGMENT_ANY and GET_OBJECT_SEGMENT macros by new segman methods
svn-id: r43999
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/savegame.cpp6
-rw-r--r--engines/sci/engine/seg_manager.cpp15
-rw-r--r--engines/sci/engine/seg_manager.h31
-rw-r--r--engines/sci/engine/vm.cpp4
4 files changed, 32 insertions, 24 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index a35916ddf5..87906cd7b3 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -533,10 +533,8 @@ static void reconstruct_stack(EngineState *retval) {
retval->stack_top = retval->stack_base + VM_STACK_SIZE;
}
-static void load_script(EngineState *s, SegmentId seg) {
+static void load_script(EngineState *s, Script *scr) {
Resource *script, *heap = NULL;
- Script *scr = (Script *)(s->segMan->_heap[seg]);
- assert(scr);
scr->buf = (byte *)malloc(scr->buf_size);
assert(scr->buf);
@@ -566,7 +564,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) {
Script *scr = (Script *)mobj;
// FIXME: Unify this code with script_instantiate_*
- load_script(s, i);
+ load_script(s, scr);
scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->segMan->_heap[scr->locals_segment]);
if (s->resMan->sciVersion() >= SCI_VERSION_1_1) {
scr->export_table = 0;
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 0d226e1d49..9d37b2ac75 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -246,8 +246,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 <= 1 || (uint)seg >= _heap.size() || !_heap[seg] || _heap[seg]->getType() != MEM_OBJ_SCRIPT)
return 0;
return (Script *)_heap[seg];
}
@@ -259,6 +258,18 @@ SegmentId SegManager::findSegmentByType(int type) {
return -1;
}
+MemObject *SegManager::getMemObject(SegmentId seg) {
+ if (seg <= 1 || (uint)seg >= _heap.size() || !_heap[seg])
+ return 0;
+ return _heap[seg];
+}
+
+MemObjectType SegManager::getMemObjectType(SegmentId seg) {
+ if (seg <= 1 || (uint)seg >= _heap.size() || !_heap[seg])
+ return MEM_OBJ_INVALID;
+ return _heap[seg]->getType();
+}
+
// validate the seg
// return:
// false - invalid seg
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index 7a84634f33..b84fa9f560 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -33,15 +33,7 @@
namespace Sci {
-#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)
-
-#define GET_SEGMENT_ANY(mgr, index) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
- (((mgr)._heap[index])? (mgr)._heap[index] : NULL) : NULL)
-
-#define GET_OBJECT_SEGMENT(mgr, index) (((index) > 0 && (int)(mgr)._heap.size() > index) ? \
- (((mgr)._heap[index] && ((mgr)._heap[index]->getType() == MEM_OBJ_SCRIPT || (mgr)._heap[index]->getType() == MEM_OBJ_CLONES))? (mgr)._heap[index] \
- : NULL): NULL)
+#define GET_SEGMENT(mgr, index, rtype) (((mgr).getMemObjectType(index) == (rtype))? (mgr)._heap[index] : NULL)
/**
* Parameters for getScriptSegment().
@@ -132,6 +124,7 @@ public:
*/
Script *getScript(SegmentId seg);
+
/**
* Return a pointer to the specified script.
* If the id is invalid, does not refer to a script, or
@@ -141,13 +134,6 @@ public:
*/
Script *getScriptIfLoaded(SegmentId seg);
- /**
- * Finds a unique segment by type
- * @param type The type of the segment to find
- * @return The segment number, or -1 if the segment wasn't found
- */
- SegmentId findSegmentByType(int type);
-
// 1b. Script Initialisation
@@ -346,6 +332,19 @@ public:
*/
byte *dereference(reg_t reg, int *size);
+ /**
+ * Finds a unique segment by type
+ * @param type The type of the segment to find
+ * @return The segment number, or -1 if the segment wasn't found
+ */
+ SegmentId findSegmentByType(int type);
+
+ // TODO: document this
+ MemObject *getMemObject(SegmentId seg);
+
+ // TODO: document this
+ MemObjectType getMemObjectType(SegmentId seg);
+
void heapRelocate(reg_t block);
void scriptRelocateExportsSci11(SegmentId seg);
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index a1cdf2b822..06161c27ae 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -467,7 +467,7 @@ void vm_handle_fatal_error(EngineState *s, int line, const char *file) {
}
static reg_t pointer_add(EngineState *s, reg_t base, int offset) {
- MemObject *mobj = GET_SEGMENT_ANY(*s->segMan, base.segment);
+ MemObject *mobj = s->segMan->getMemObject(base.segment);
if (!mobj) {
error("[VM] Error: Attempt to add %d to invalid pointer %04x:%04x", offset, PRINT_REG(base));
@@ -1933,7 +1933,7 @@ int game_run(EngineState **_s) {
}
Object *obj_get(SegManager *segMan, reg_t offset) {
- MemObject *mobj = GET_OBJECT_SEGMENT(*segMan, offset.segment);
+ MemObject *mobj = segMan->getMemObject(offset.segment);
SciVersion version = segMan->sciVersion();
Object *obj = NULL;