SCI: Get rid of EngineState::stack_segment
svn-id: r47833
This commit is contained in:
parent
b2d69649f7
commit
bb5e34a014
7 changed files with 16 additions and 16 deletions
|
@ -239,7 +239,7 @@ int game_init(EngineState *s) {
|
||||||
// FIXME Use new VM instantiation code all over the place
|
// FIXME Use new VM instantiation code all over the place
|
||||||
DataStack *stack;
|
DataStack *stack;
|
||||||
|
|
||||||
stack = s->_segMan->allocateStack(VM_STACK_SIZE, &s->stack_segment);
|
stack = s->_segMan->allocateStack(VM_STACK_SIZE, NULL);
|
||||||
s->stack_base = stack->_entries;
|
s->stack_base = stack->_entries;
|
||||||
s->stack_top = stack->_entries + stack->_capacity;
|
s->stack_top = stack->_entries + stack->_capacity;
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,11 @@ reg_t_hash_map *find_all_used_references(EngineState *s) {
|
||||||
debugC(2, kDebugLevelGC, "[GC] -- Finished explicitly loaded scripts, done with root set");
|
debugC(2, kDebugLevelGC, "[GC] -- Finished explicitly loaded scripts, done with root set");
|
||||||
|
|
||||||
// Run Worklist Algorithm
|
// Run Worklist Algorithm
|
||||||
|
SegmentId stack_seg = segMan->findSegmentByType(SEG_TYPE_STACK);
|
||||||
while (!wm._worklist.empty()) {
|
while (!wm._worklist.empty()) {
|
||||||
reg_t reg = wm._worklist.back();
|
reg_t reg = wm._worklist.back();
|
||||||
wm._worklist.pop_back();
|
wm._worklist.pop_back();
|
||||||
if (reg.segment != s->stack_segment) { // No need to repeat this one
|
if (reg.segment != stack_seg) { // No need to repeat this one
|
||||||
debugC(2, kDebugLevelGC, "[GC] Checking %04x:%04x", PRINT_REG(reg));
|
debugC(2, kDebugLevelGC, "[GC] Checking %04x:%04x", PRINT_REG(reg));
|
||||||
if (reg.segment < segMan->_heap.size() && segMan->_heap[reg.segment])
|
if (reg.segment < segMan->_heap.size() && segMan->_heap[reg.segment])
|
||||||
segMan->_heap[reg.segment]->listAllOutgoingReferences(reg, &wm, add_outgoing_refs);
|
segMan->_heap[reg.segment]->listAllOutgoingReferences(reg, &wm, add_outgoing_refs);
|
||||||
|
|
|
@ -765,7 +765,6 @@ static void reconstruct_stack(EngineState *retval) {
|
||||||
SegmentId stack_seg = retval->_segMan->findSegmentByType(SEG_TYPE_STACK);
|
SegmentId stack_seg = retval->_segMan->findSegmentByType(SEG_TYPE_STACK);
|
||||||
DataStack *stack = (DataStack *)(retval->_segMan->_heap[stack_seg]);
|
DataStack *stack = (DataStack *)(retval->_segMan->_heap[stack_seg]);
|
||||||
|
|
||||||
retval->stack_segment = stack_seg;
|
|
||||||
retval->stack_base = stack->_entries;
|
retval->stack_base = stack->_entries;
|
||||||
retval->stack_top = stack->_entries + stack->_capacity;
|
retval->stack_top = stack->_entries + stack->_capacity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,34 +113,36 @@ SegmentId SegManager::findFreeSegment() const {
|
||||||
|
|
||||||
SegmentObj *SegManager::allocSegment(SegmentObj *mem, SegmentId *segid) {
|
SegmentObj *SegManager::allocSegment(SegmentObj *mem, SegmentId *segid) {
|
||||||
// Find a free segment
|
// Find a free segment
|
||||||
*segid = findFreeSegment();
|
SegmentId id = findFreeSegment();
|
||||||
|
if (segid)
|
||||||
|
*segid = id;
|
||||||
|
|
||||||
if (!mem)
|
if (!mem)
|
||||||
error("SegManager: invalid mobj");
|
error("SegManager: invalid mobj");
|
||||||
|
|
||||||
// ... and put it into the (formerly) free segment.
|
// ... and put it into the (formerly) free segment.
|
||||||
if (*segid >= (int)_heap.size()) {
|
if (id >= (int)_heap.size()) {
|
||||||
assert(*segid == (int)_heap.size());
|
assert(id == (int)_heap.size());
|
||||||
_heap.push_back(0);
|
_heap.push_back(0);
|
||||||
}
|
}
|
||||||
_heap[*segid] = mem;
|
_heap[id] = mem;
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
Script *SegManager::allocateScript(int script_nr, SegmentId *seg_id) {
|
Script *SegManager::allocateScript(int script_nr, SegmentId *segid) {
|
||||||
// Check if the script already has an allocated segment. If it
|
// Check if the script already has an allocated segment. If it
|
||||||
// does, return that segment.
|
// does, return that segment.
|
||||||
*seg_id = _scriptSegMap.getVal(script_nr, 0);
|
*segid = _scriptSegMap.getVal(script_nr, 0);
|
||||||
if (*seg_id > 0) {
|
if (*segid > 0) {
|
||||||
return (Script *)_heap[*seg_id];
|
return (Script *)_heap[*segid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate the SegmentObj
|
// allocate the SegmentObj
|
||||||
SegmentObj *mem = allocSegment(new Script(), seg_id);
|
SegmentObj *mem = allocSegment(new Script(), segid);
|
||||||
|
|
||||||
// Add the script to the "script id -> segment id" hashmap
|
// Add the script to the "script id -> segment id" hashmap
|
||||||
_scriptSegMap[script_nr] = *seg_id;
|
_scriptSegMap[script_nr] = *segid;
|
||||||
|
|
||||||
return (Script *)mem;
|
return (Script *)mem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ EngineState::EngineState(ResourceManager *res, Kernel *kernel, Vocabulary *voc,
|
||||||
restAdjust = 0;
|
restAdjust = 0;
|
||||||
r_prev = NULL_REG;
|
r_prev = NULL_REG;
|
||||||
|
|
||||||
stack_segment = 0;
|
|
||||||
stack_base = 0;
|
stack_base = 0;
|
||||||
stack_top = 0;
|
stack_top = 0;
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,6 @@ public:
|
||||||
int16 restAdjust; /**< &rest register (only used for save games) */
|
int16 restAdjust; /**< &rest register (only used for save games) */
|
||||||
reg_t r_prev; /**< previous comparison result */
|
reg_t r_prev; /**< previous comparison result */
|
||||||
|
|
||||||
SegmentId stack_segment; /**< Heap area for the stack to use */
|
|
||||||
StackPtr stack_base; /**< Pointer to the least stack element */
|
StackPtr stack_base; /**< Pointer to the least stack element */
|
||||||
StackPtr stack_top; /**< First invalid stack element */
|
StackPtr stack_top; /**< First invalid stack element */
|
||||||
|
|
||||||
|
|
|
@ -568,7 +568,7 @@ void run_vm(EngineState *s, int restoring) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
scriptState.variables_seg[VAR_GLOBAL] = s->script_000->_localsSegment;
|
scriptState.variables_seg[VAR_GLOBAL] = s->script_000->_localsSegment;
|
||||||
scriptState.variables_seg[VAR_TEMP] = scriptState.variables_seg[VAR_PARAM] = s->stack_segment;
|
scriptState.variables_seg[VAR_TEMP] = scriptState.variables_seg[VAR_PARAM] = s->_segMan->findSegmentByType(SEG_TYPE_STACK);
|
||||||
scriptState.variables_base[VAR_TEMP] = scriptState.variables_base[VAR_PARAM] = s->stack_base;
|
scriptState.variables_base[VAR_TEMP] = scriptState.variables_base[VAR_PARAM] = s->stack_base;
|
||||||
|
|
||||||
// SCI code reads the zeroth argument to determine argc
|
// SCI code reads the zeroth argument to determine argc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue