aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-05-08 09:54:06 +0000
committerMax Horn2009-05-08 09:54:06 +0000
commit0223b7e490a6cdcc63aea0239cc6d079591c429f (patch)
tree51432101b0ab00afcb1721ec59e07ba4dafa46b4
parent8d4a4271bb0cf78508f600d80893874d436e9883 (diff)
downloadscummvm-rg350-0223b7e490a6cdcc63aea0239cc6d079591c429f.tar.gz
scummvm-rg350-0223b7e490a6cdcc63aea0239cc6d079591c429f.tar.bz2
scummvm-rg350-0223b7e490a6cdcc63aea0239cc6d079591c429f.zip
SCI: Moved findCanonicAddress from SegInterface to MemObject
svn-id: r40376
-rw-r--r--engines/sci/engine/gc.cpp10
-rw-r--r--engines/sci/engine/scriptdebug.cpp17
-rw-r--r--engines/sci/engine/seg_manager.cpp21
-rw-r--r--engines/sci/engine/seg_manager.h6
-rw-r--r--engines/sci/engine/vm.h10
5 files changed, 30 insertions, 34 deletions
diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp
index f5f9c51051..610ed853af 100644
--- a/engines/sci/engine/gc.cpp
+++ b/engines/sci/engine/gc.cpp
@@ -51,15 +51,15 @@ struct WorklistManager {
}
};
-static reg_t_hash_map *normalise_hashmap_ptrs(reg_t_hash_map &nonnormal_map, const Common::Array<SegInterface *> &interfaces) {
+static reg_t_hash_map *normalise_hashmap_ptrs(SegManager *sm, reg_t_hash_map &nonnormal_map) {
reg_t_hash_map *normal_map = new reg_t_hash_map();
for (reg_t_hash_map::iterator i = nonnormal_map.begin(); i != nonnormal_map.end(); ++i) {
reg_t reg = i->_key;
- SegInterface *interfce = (reg.segment < interfaces.size()) ? interfaces[reg.segment] : NULL;
+ MemObject *mobj = (reg.segment < sm->_heap.size()) ? sm->_heap[reg.segment] : NULL;
- if (interfce) {
- reg = interfce->findCanonicAddress(reg);
+ if (mobj) {
+ reg = mobj->findCanonicAddress(sm, reg);
normal_map->setVal(reg, true);
}
}
@@ -156,7 +156,7 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
}
// Normalise
- normal_map = normalise_hashmap_ptrs(wm._map, interfaces);
+ normal_map = normalise_hashmap_ptrs(sm, wm._map);
// Cleanup
for (i = 1; i < sm->_heap.size(); i++)
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 5c8af33b4c..555cef9dc2 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -2792,13 +2792,6 @@ static void _print_address(void * _, reg_t addr) {
sciprintf(" "PREG"\n", PRINT_REG(addr));
}
-#define GET_SEG_INTERFACE(seg_id) \
- SegInterface *seg_interface = s->seg_manager->getSegInterface(seg_id); \
- if (!seg_interface) { \
- sciprintf("Unknown segment : %x\n", seg_id); \
- return 1; \
- }
-
static int c_gc_show_reachable(EngineState *s) {
reg_t addr = cmd_params[0].reg;
@@ -2832,13 +2825,15 @@ static int c_gc_show_freeable(EngineState *s) {
static int c_gc_normalise(EngineState *s) {
reg_t addr = cmd_params[0].reg;
- GET_SEG_INTERFACE(addr.segment);
+ MemObject *mobj = GET_SEGMENT_ANY(*s->seg_manager, addr.segment);
+ if (!mobj) {
+ sciprintf("Unknown segment : %x\n", addr.segment);
+ return 1;
+ }
- addr = seg_interface->findCanonicAddress(addr);
+ addr = mobj->findCanonicAddress(s->seg_manager, addr);
sciprintf(" "PREG"\n", PRINT_REG(addr));
- delete seg_interface;
-
return 0;
}
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index dfd216e86e..5dc2833773 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -1188,20 +1188,15 @@ SegInterface::SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId,
VERIFY(_mobj->getType() == _typeId, "Invalid MemObject type");
}
-reg_t SegInterface::findCanonicAddress(reg_t addr) {
- return addr;
-}
-
//-------------------- base --------------------
class SegInterfaceBase : public SegInterface {
protected:
SegInterfaceBase(SegManager *segmgr, MemObject *mobj, SegmentId segId, MemObjectType typeId) :
SegInterface(segmgr, mobj, segId, typeId) {}
public:
- reg_t findCanonicAddress(reg_t addr);
};
-reg_t SegInterfaceBase::findCanonicAddress(reg_t addr) {
+reg_t Script::findCanonicAddress(SegManager *segmgr, reg_t addr) {
addr.offset = 0;
return addr;
}
@@ -1210,6 +1205,11 @@ void Script::listAllDeallocatable(SegmentId segId, void *param, NoteCallback not
(*note)(param, make_reg(segId, 0));
}
+reg_t DynMem::findCanonicAddress(SegManager *segmgr, reg_t addr) {
+ addr.offset = 0;
+ return addr;
+}
+
void DynMem::listAllDeallocatable(SegmentId segId, void *param, NoteCallback note) {
(*note)(param, make_reg(segId, 0));
}
@@ -1327,13 +1327,11 @@ class SegInterfaceLocals : public SegInterface {
public:
SegInterfaceLocals(SegManager *segmgr, MemObject *mobj, SegmentId segId) :
SegInterface(segmgr, mobj, segId, MEM_OBJ_LOCALS) {}
- reg_t findCanonicAddress(reg_t addr);
};
-reg_t SegInterfaceLocals::findCanonicAddress(reg_t addr) {
- LocalVariables *locals = (LocalVariables *)_mobj;
+reg_t LocalVariables::findCanonicAddress(SegManager *segmgr, reg_t addr) {
// Reference the owning script
- SegmentId owner_seg = _segmgr->segGet(locals->script_id);
+ SegmentId owner_seg = segmgr->segGet(script_id);
assert(owner_seg >= 0);
@@ -1353,10 +1351,9 @@ class SegInterfaceStack : public SegInterface {
public:
SegInterfaceStack(SegManager *segmgr, MemObject *mobj, SegmentId segId) :
SegInterface(segmgr, mobj, segId, MEM_OBJ_STACK) {}
- reg_t findCanonicAddress(reg_t addr);
};
-reg_t SegInterfaceStack::findCanonicAddress(reg_t addr) {
+reg_t DataStack::findCanonicAddress(SegManager *segmgr, reg_t addr) {
addr.offset = 0;
return addr;
}
diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h
index 1fac3287e9..ddeb09cbf1 100644
--- a/engines/sci/engine/seg_manager.h
+++ b/engines/sci/engine/seg_manager.h
@@ -452,12 +452,6 @@ public:
// Deallocates the segment interface
virtual ~SegInterface() {}
- // Finds the canonic address associated with sub_reg
- // Parameters: (reg_t) sub_addr: The base address whose canonic address is to be found
- // For each valid address a, there exists a canonic address c(a) such that c(a) = c(c(a)).
- // This address "governs" a in the sense that deallocating c(a) will deallocate a.
- virtual reg_t findCanonicAddress(reg_t sub_addr);
-
// Get the memory object
MemObject *getMobj() { return _mobj; }
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 5e617705f2..65ecb0584f 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -77,6 +77,12 @@ public:
inline MemObjectType getType() const { return _type; }
inline int getSegMgrId() const { return _segmgrId; }
+ // Finds the canonic address associated with sub_reg
+ // Parameters: (reg_t) sub_addr: The base address whose canonic address is to be found
+ // For each valid address a, there exists a canonic address c(a) such that c(a) = c(c(a)).
+ // This address "governs" a in the sense that deallocating c(a) will deallocate a.
+ virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr) { return sub_addr; }
+
// Deallocates all memory associated with the specified address
// Parameters: (reg_t) sub_addr: The address (within the given segment) to deallocate
virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr) {}
@@ -251,6 +257,7 @@ public:
}
virtual byte *dereference(reg_t pointer, int *size);
+ virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr);
virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note);
// virtual void saveLoadWithSerializer(Common::Serializer &ser);
@@ -368,6 +375,7 @@ public:
void freeScript();
virtual byte *dereference(reg_t pointer, int *size);
+ virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr);
virtual void freeAtAddress(SegManager *segmgr, reg_t sub_addr);
virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note);
virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note);
@@ -391,6 +399,7 @@ public:
}
virtual byte *dereference(reg_t pointer, int *size);
+ virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr);
virtual void listAllOutgoingReferences(EngineState *s, reg_t object, void *param, NoteCallback note);
// virtual void saveLoadWithSerializer(Common::Serializer &ser);
@@ -555,6 +564,7 @@ public:
}
virtual byte *dereference(reg_t pointer, int *size);
+ virtual reg_t findCanonicAddress(SegManager *segmgr, reg_t sub_addr);
virtual void listAllDeallocatable(SegmentId segId, void *param, NoteCallback note);
// virtual void saveLoadWithSerializer(Common::Serializer &ser);