diff options
author | Max Horn | 2009-04-28 15:58:19 +0000 |
---|---|---|
committer | Max Horn | 2009-04-28 15:58:19 +0000 |
commit | 294bd0dc071d0e38719de1c1260ad30be8199618 (patch) | |
tree | 684ce45ac90d0fc89e28fdabad794b8e789c3aea | |
parent | 01fceec37c83ba855ed60b284d47c7e6a84d2f1d (diff) | |
download | scummvm-rg350-294bd0dc071d0e38719de1c1260ad30be8199618.tar.gz scummvm-rg350-294bd0dc071d0e38719de1c1260ad30be8199618.tar.bz2 scummvm-rg350-294bd0dc071d0e38719de1c1260ad30be8199618.zip |
SCI: Renamed execution_stack -> _executionStack and turned it into a Common::Array
svn-id: r40182
-rw-r--r-- | engines/sci/engine/game.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/gc.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/kscripts.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/scriptconsole.cpp | 8 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 78 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 5 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 80 |
8 files changed, 91 insertions, 108 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 48e70eb801..0130ee7afe 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -444,7 +444,7 @@ int script_init_engine(EngineState *s, sci_version_t version) { s->r_acc = s->r_prev = NULL_REG; s->r_amp_rest = 0; - s->execution_stack = NULL; // Start without any execution stack + s->_executionStack.clear(); // Start without any execution stack s->execution_stack_base = -1; // No vm is running yet s->execution_stack_pos = -1; // Start at execution stack position 0 @@ -620,7 +620,7 @@ int game_init(EngineState *s) { } int game_exit(EngineState *s) { - free(s->execution_stack); + s->_executionStack.clear(); if (!s->successor) { sfx_exit(&s->sound); diff --git a/engines/sci/engine/gc.cpp b/engines/sci/engine/gc.cpp index ae0b9fefed..c3fcfff75f 100644 --- a/engines/sci/engine/gc.cpp +++ b/engines/sci/engine/gc.cpp @@ -153,10 +153,10 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Init: Value Stack // We do this one by hand since the stack doesn't know the current execution stack { - ExecStack *xs = s->execution_stack + s->execution_stack_pos; + ExecStack &xs = s->_executionStack[s->execution_stack_pos]; reg_t *pos; - for (pos = s->stack_base; pos < xs->sp; pos++) + for (pos = s->stack_base; pos < xs.sp; pos++) worklist_push(&worklist, nonnormal_map, *pos); } #ifdef DEBUG_GC_VERBOSE @@ -165,13 +165,13 @@ reg_t_hash_map *find_all_used_references(EngineState *s) { // Init: Execution Stack for (i = 0; i <= s->execution_stack_pos; i++) { - ExecStack *es = s->execution_stack + i; + ExecStack &es = s->_executionStack[i]; - if (es->type != EXEC_STACK_TYPE_KERNEL) { - worklist_push(&worklist, nonnormal_map, es->objp); - worklist_push(&worklist, nonnormal_map, es->sendp); - if (es->type == EXEC_STACK_TYPE_VARSELECTOR) - worklist_push(&worklist, nonnormal_map, *(es->addr.varp)); + if (es.type != EXEC_STACK_TYPE_KERNEL) { + worklist_push(&worklist, nonnormal_map, es.objp); + worklist_push(&worklist, nonnormal_map, es.sendp); + if (es.type == EXEC_STACK_TYPE_VARSELECTOR) + worklist_push(&worklist, nonnormal_map, *(es.addr.varp)); } } #ifdef DEBUG_GC_VERBOSE diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index df40781c95..9559c792c9 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -271,12 +271,12 @@ reg_t kDisposeScript(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (s->seg_manager->scriptIsLoaded(script, SCRIPT_ID)) { int id = s->seg_manager->segGet(script); - if (s->execution_stack[s->execution_stack_pos].addr.pc.segment != id) + if (s->_executionStack[s->execution_stack_pos].addr.pc.segment != id) s->seg_manager->setLockers(1, script, SCRIPT_ID); } script_uninstantiate(s, script); - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; return s->r_acc; } diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index b6f09ce8bc..decfd167dc 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -227,10 +227,10 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on rel_offsetting = 1; if (!scumm_strnicmp(str + 1, "PC", 2)) { - *dest = s->execution_stack[s->execution_stack_pos].addr.pc; + *dest = s->_executionStack[s->execution_stack_pos].addr.pc; offsetting = str + 3; } else if (!scumm_strnicmp(str + 1, "P", 1)) { - *dest = s->execution_stack[s->execution_stack_pos].addr.pc; + *dest = s->_executionStack[s->execution_stack_pos].addr.pc; offsetting = str + 2; } else if (!scumm_strnicmp(str + 1, "PREV", 4)) { *dest = s->r_prev; @@ -242,10 +242,10 @@ int parse_reg_t(EngineState *s, const char *str, reg_t *dest) { // Returns 0 on *dest = s->r_acc; offsetting = str + 2; } else if (!scumm_strnicmp(str + 1, "OBJ", 3)) { - *dest = s->execution_stack[s->execution_stack_pos].objp; + *dest = s->_executionStack[s->execution_stack_pos].objp; offsetting = str + 4; } else if (!scumm_strnicmp(str + 1, "O", 1)) { - *dest = s->execution_stack[s->execution_stack_pos].objp; + *dest = s->_executionStack[s->execution_stack_pos].objp; offsetting = str + 2; } else return 1; // No matching register diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 27c41795ec..76ac53ec81 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -693,21 +693,16 @@ int c_seginfo(EngineState *s) { } int c_debuginfo(EngineState *s) { - ExecStack *eframe = NULL; - if (!_debugstate_valid) { sciprintf("Not in debug state\n"); return 1; } - if (s->execution_stack && s->execution_stack_pos >= 0) - eframe = s->execution_stack + s->execution_stack_pos; - sciprintf("acc="PREG" prev="PREG" &rest=%x\n", PRINT_REG(s->r_acc), PRINT_REG(s->r_prev), *p_restadjust); - if (eframe) + if (!s->_executionStack.empty() && s->execution_stack_pos >= 0) { sciprintf("pc="PREG" obj="PREG" fp="PSTK" sp="PSTK"\n", PRINT_REG(*p_pc), PRINT_REG(*p_objp), PRINT_STK(*p_pp), PRINT_STK(*p_sp)); - else + } else sciprintf("<no execution stack: pc,obj,fp omitted>\n"); return 0; @@ -1155,26 +1150,23 @@ int c_restart_game(EngineState *s) { } int c_stack(EngineState *s) { - int i; - ExecStack *xs; - if (!s) { sciprintf("Not in debug state\n"); return 1; } - if (s->execution_stack_pos >= 0) - xs = s->execution_stack + s->execution_stack_pos; - else { + if (s->execution_stack_pos < 0) { sciprintf("No exec stack!"); return 1; } - for (i = cmd_params[0].val ; i > 0; i--) { - if ((xs->sp - xs->fp - i) == 0) + ExecStack &xs = s->_executionStack[s->execution_stack_pos]; + + for (int i = cmd_params[0].val ; i > 0; i--) { + if ((xs.sp - xs.fp - i) == 0) sciprintf("-- temp variables --\n"); - if (xs->sp - i >= s->stack_base) - sciprintf(PSTK" = "PREG"\n", PRINT_STK(xs->sp - i), PRINT_REG(xs->sp[-i])); + if (xs.sp - i >= s->stack_base) + sciprintf(PSTK" = "PREG"\n", PRINT_STK(xs.sp - i), PRINT_REG(xs.sp[-i])); } return 0; @@ -1547,58 +1539,58 @@ static int c_backtrace(EngineState *s) { sciprintf("Call stack (current base: 0x%x):\n", s->execution_stack_base); for (i = 0; i <= s->execution_stack_pos; i++) { - ExecStack *call = &(s->execution_stack[i]); - const char *objname = obj_get_name(s, call->sendp); + ExecStack &call = s->_executionStack[i]; + const char *objname = obj_get_name(s, call.sendp); int paramc, totalparamc; - switch (call->type) { + switch (call.type) { case EXEC_STACK_TYPE_CALL: {// Normal function - sciprintf(" %x:[%x] %s::%s(", i, call->origin, objname, (call->selector == -1) ? "<call[be]?>" : - selector_name(s, call->selector)); + sciprintf(" %x:[%x] %s::%s(", i, call.origin, objname, (call.selector == -1) ? "<call[be]?>" : + selector_name(s, call.selector)); } break; case EXEC_STACK_TYPE_KERNEL: // Kernel function - sciprintf(" %x:[%x] k%s(", i, call->origin, s->_kernelNames[-(call->selector)-42].c_str()); + sciprintf(" %x:[%x] k%s(", i, call.origin, s->_kernelNames[-(call.selector)-42].c_str()); break; case EXEC_STACK_TYPE_VARSELECTOR: - sciprintf(" %x:[%x] vs%s %s::%s (", i, call->origin, (call->argc) ? "write" : "read", - objname, s->_selectorNames[call->selector].c_str()); + sciprintf(" %x:[%x] vs%s %s::%s (", i, call.origin, (call.argc) ? "write" : "read", + objname, s->_selectorNames[call.selector].c_str()); break; } - totalparamc = call->argc; + totalparamc = call.argc; if (totalparamc > 16) totalparamc = 16; for (paramc = 1; paramc <= totalparamc; paramc++) { - sciprintf(PREG, PRINT_REG(call->variables_argp[paramc])); + sciprintf(PREG, PRINT_REG(call.variables_argp[paramc])); - if (paramc < call->argc) + if (paramc < call.argc) sciprintf(", "); } - if (call->argc > 16) + if (call.argc > 16) sciprintf("..."); - sciprintf(")\n obj@"PREG, PRINT_REG(call->objp)); - if (call->type == EXEC_STACK_TYPE_CALL) { - sciprintf(" pc="PREG, PRINT_REG(call->addr.pc)); - if (call->sp == CALL_SP_CARRY) + sciprintf(")\n obj@"PREG, PRINT_REG(call.objp)); + if (call.type == EXEC_STACK_TYPE_CALL) { + sciprintf(" pc="PREG, PRINT_REG(call.addr.pc)); + if (call.sp == CALL_SP_CARRY) sciprintf(" sp,fp:carry"); else { - sciprintf(" sp="PSTK, PRINT_STK(call->sp)); - sciprintf(" fp="PSTK, PRINT_STK(call->fp)); + sciprintf(" sp="PSTK, PRINT_STK(call.sp)); + sciprintf(" fp="PSTK, PRINT_STK(call.fp)); } } else sciprintf(" pc:none"); - sciprintf(" argp:"PSTK, PRINT_STK(call->variables_argp)); - if (call->type == EXEC_STACK_TYPE_CALL) - sciprintf(" script: %d", s->seg_manager->heap[call->addr.pc.segment]->data.script.nr); + sciprintf(" argp:"PSTK, PRINT_STK(call.variables_argp)); + if (call.type == EXEC_STACK_TYPE_CALL) + sciprintf(" script: %d", s->seg_manager->heap[call.addr.pc.segment]->data.script.nr); sciprintf("\n"); } @@ -2153,7 +2145,7 @@ static int c_set_acc(EngineState *s) { static int c_send(EngineState *s) { reg_t object = cmd_params[0].reg; char *selector_name = cmd_params[1].str; - StackPtr stackframe = s->execution_stack->sp; + StackPtr stackframe = s->_executionStack[0].sp; int selector_id; unsigned int i; ExecStack *xstack; @@ -2187,8 +2179,8 @@ static int c_send(EngineState *s) { for (i = 2; i < cmd_paramlength; i++) stackframe[i] = cmd_params[i].reg; - xstack = add_exec_stack_entry(s, fptr, s->execution_stack->sp + cmd_paramlength, object, cmd_paramlength - 2, - s->execution_stack->sp - 1, 0, object, s->execution_stack_pos, SCI_XS_CALLEE_LOCALS); + xstack = add_exec_stack_entry(s, fptr, s->_executionStack[0].sp + cmd_paramlength, object, cmd_paramlength - 2, + s->_executionStack[0].sp - 1, 0, object, s->execution_stack_pos, SCI_XS_CALLEE_LOCALS); xstack->selector = selector_id; xstack->type = selector_type == kSelectorVariable ? EXEC_STACK_TYPE_VARSELECTOR : EXEC_STACK_TYPE_CALL; @@ -2198,7 +2190,7 @@ static int c_send(EngineState *s) { xstack->sp += cmd_paramlength; xstack->fp += cmd_paramlength; - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; return 0; } @@ -2934,7 +2926,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * return; if ((op & 0x3) > 1) return; // param or temp - if ((op & 0x3) && s->execution_stack[s->execution_stack_pos].local_segment > 0) + if ((op & 0x3) && s->_executionStack[s->execution_stack_pos].local_segment > 0) return; // locals and not running in script.000 if (paramf1 != _debug_seek_special) return; // CORRECT global? diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index e6266c65a2..21f0452aee 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -111,11 +111,9 @@ EngineState::EngineState() : _dirseeker(this) { kernel_opt_flags = 0; - execution_stack = 0; - execution_stack_size = 0; execution_stack_pos = 0; execution_stack_base = 0; - execution_stack_pos_changed = 0; + _executionStackPosChanged = false; r_acc = NULL_REG; r_amp_rest = 0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index e522176a9b..849076fa3e 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -209,15 +209,14 @@ public: /* VM Information */ - ExecStack *execution_stack; /**< The execution stack */ - int execution_stack_size; /**< Number of stack frames allocated */ + Common::Array<ExecStack> _executionStack; /**< The execution stack */ int execution_stack_pos; /**< Position on the execution stack */ /** * When called from kernel functions, the vm is re-started recursively on * the same stack. This variable contains the stack base for the current vm. */ int execution_stack_base; - int execution_stack_pos_changed; /**< Set to 1 if the execution stack position should be re-evaluated by the vm */ + bool _executionStackPosChanged; /**< Set to true if the execution stack position should be re-evaluated by the vm */ reg_t r_acc; /**< Accumulator */ unsigned int r_amp_rest; /**< &rest register (only used for save games) */ diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 6f93da093e..e776b9e598 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -297,14 +297,14 @@ static void _exec_varselectors(EngineState *s) { // Executes all varselector read/write ops on the TOS // Now check the TOS to execute all varselector entries if (s->execution_stack_pos >= 0) - while (s->execution_stack[s->execution_stack_pos].type == EXEC_STACK_TYPE_VARSELECTOR) { + while (s->_executionStack[s->execution_stack_pos].type == EXEC_STACK_TYPE_VARSELECTOR) { // varselector access? - if (s->execution_stack[s->execution_stack_pos].argc) { // write? - reg_t temp = s->execution_stack[s->execution_stack_pos].variables_argp[1]; - *(s->execution_stack[s->execution_stack_pos].addr.varp) = temp; + if (s->_executionStack[s->execution_stack_pos].argc) { // write? + reg_t temp = s->_executionStack[s->execution_stack_pos].variables_argp[1]; + *(s->_executionStack[s->execution_stack_pos].addr.varp) = temp; } else // No, read - s->r_acc = *(s->execution_stack[s->execution_stack_pos].addr.varp); + s->r_acc = *(s->_executionStack[s->execution_stack_pos].addr.varp); --(s->execution_stack_pos); } @@ -321,7 +321,6 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt int selector; int argc; int origin = s->execution_stack_pos; // Origin: Used for debugging - ExecStack *retval = s->execution_stack + s->execution_stack_pos; int print_send_action = 0; // We return a pointer to the new active ExecStack @@ -460,18 +459,17 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt while (!sendCalls.empty()) { CallsStruct call = sendCalls.pop(); if (call.type == EXEC_STACK_TYPE_VARSELECTOR) // Write/read variable? - retval = add_exec_stack_varselector(s, work_obj, call.argc, call.argp, + add_exec_stack_varselector(s, work_obj, call.argc, call.argp, call.selector, call.address.var, origin); else - retval = add_exec_stack_entry(s, call.address.func, call.sp, work_obj, + add_exec_stack_entry(s, call.address.func, call.sp, work_obj, call.argc, call.argp, call.selector, send_obj, origin, SCI_XS_CALLEE_LOCALS); } _exec_varselectors(s); - retval = s->execution_stack + s->execution_stack_pos; - return retval; + return &(s->_executionStack[s->execution_stack_pos]); } ExecStack *add_exec_stack_varselector(EngineState *s, reg_t objp, int argc, StackPtr argp, Selector selector, reg_t *address, int origin) { @@ -488,17 +486,14 @@ ExecStack *add_exec_stack_entry(EngineState *s, reg_t pc, StackPtr sp, reg_t obj StackPtr argp, Selector selector, reg_t sendp, int origin, SegmentId locals_segment) { // Returns new TOS element for the execution stack // locals_segment may be -1 if derived from the called object - ExecStack *xstack = NULL; - if (!s->execution_stack) - s->execution_stack = (ExecStack *)sci_malloc(sizeof(ExecStack) * (s->execution_stack_size = 16)); + ++s->execution_stack_pos; + if (s->execution_stack_pos >= (int)s->_executionStack.size()) // Out of stack space? + s->_executionStack.resize(s->execution_stack_pos+1); - if (++(s->execution_stack_pos) == s->execution_stack_size) // Out of stack space? - s->execution_stack = (ExecStack*)sci_realloc(s->execution_stack, sizeof(ExecStack) * (s->execution_stack_size += 8)); + //sciprintf("Exec stack: [%d/%d], origin %d, at %p\n", s->execution_stack_pos, s->_executionStack.size(), origin, s->execution_stack); - //sciprintf("Exec stack: [%d/%d], origin %d, at %p\n", s->execution_stack_pos, s->execution_stack_size, origin, s->execution_stack); - - xstack = s->execution_stack + s->execution_stack_pos; + ExecStack *xstack = &(s->_executionStack[s->execution_stack_pos]); xstack->objp = objp; if (locals_segment != SCI_XS_CALLEE_LOCALS) @@ -596,7 +591,7 @@ void run_vm(EngineState *s, int restoring) { int restadjust = s->r_amp_rest; // &rest adjusts the parameter count by this value // Current execution data: - ExecStack *xs = s->execution_stack + s->execution_stack_pos; + ExecStack *xs = &(s->_executionStack[s->execution_stack_pos]); ExecStack *xs_new = NULL; Object *obj = obj_get(s, xs->objp); Script *local_script = script_locate_by_segment(s, xs->local_segment); @@ -637,7 +632,7 @@ void run_vm(EngineState *s, int restoring) { - s->execution_stack_pos_changed = 1; // Force initialization + s->_executionStackPosChanged = true; // Force initialization while (1) { byte opcode; @@ -649,10 +644,10 @@ void run_vm(EngineState *s, int restoring) { old_pc_offset = xs->addr.pc.offset; - if (s->execution_stack_pos_changed) { + if (s->_executionStackPosChanged) { Script *scr; - xs = s->execution_stack + s->execution_stack_pos; - s->execution_stack_pos_changed = 0; + xs = &(s->_executionStack[s->execution_stack_pos]); + s->_executionStackPosChanged = false; scr = script_locate_by_segment(s, xs->addr.pc.segment); if (!scr) { @@ -1003,7 +998,7 @@ void run_vm(EngineState *s, int restoring) { restadjust = 0; // Used up the &rest adjustment xs->sp = call_base; - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; break; } @@ -1037,8 +1032,8 @@ void run_vm(EngineState *s, int restoring) { // Calculate xs again: The kernel function might // have spawned a new VM - xs_new = s->execution_stack + s->execution_stack_pos; - s->execution_stack_pos_changed = 1; + xs_new = &(s->_executionStack[s->execution_stack_pos]); + s->_executionStackPosChanged = true; if (s->version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER) restadjust = s->r_amp_rest; @@ -1055,7 +1050,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = execute_method(s, 0, opparams[0], s_temp, xs->objp, xs->sp[0].offset, xs->sp); restadjust = 0; // Used up the &rest adjustment if (xs_new) // in case of error, keep old stack - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; break; case 0x23: // calle @@ -1068,21 +1063,21 @@ void run_vm(EngineState *s, int restoring) { restadjust = 0; // Used up the &rest adjustment if (xs_new) // in case of error, keep old stack - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; break; case 0x24: // ret do { StackPtr old_sp2 = xs->sp; StackPtr old_fp = xs->fp; - ExecStack *old_xs = s->execution_stack + s->execution_stack_pos; + ExecStack *old_xs = &(s->_executionStack[s->execution_stack_pos]); if (s->execution_stack_pos == s->execution_stack_base) { // Have we reached the base? s->execution_stack_base = old_execution_stack_base; // Restore stack base --(s->execution_stack_pos); - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; s->r_amp_rest = restadjust; // Update &rest return; // "Hard" return } @@ -1098,8 +1093,8 @@ void run_vm(EngineState *s, int restoring) { // Not reached the base, so let's do a soft return --(s->execution_stack_pos); xs = old_xs - 1; - s->execution_stack_pos_changed = 1; - xs = s->execution_stack + s->execution_stack_pos; + s->_executionStackPosChanged = true; + xs = &(s->_executionStack[s->execution_stack_pos]); if (xs->sp == CALL_SP_CARRY // Used in sends to 'carry' the stack pointer || xs->type != EXEC_STACK_TYPE_CALL) { @@ -1109,7 +1104,7 @@ void run_vm(EngineState *s, int restoring) { } while (xs->type == EXEC_STACK_TYPE_VARSELECTOR); // Iterate over all varselector accesses - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; xs_new = xs; break; @@ -1122,7 +1117,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = send_selector(s, s->r_acc, s->r_acc, s_temp, (int)(opparams[0] >> 1) + (uint16)restadjust, xs->sp); if (xs_new && xs_new != xs) - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; restadjust = 0; @@ -1140,7 +1135,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = send_selector(s, xs->objp, xs->objp, s_temp, (int)(opparams[0] >> 1) + (uint16)restadjust, xs->sp); if (xs_new && xs_new != xs) - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; restadjust = 0; break; @@ -1158,7 +1153,7 @@ void run_vm(EngineState *s, int restoring) { xs_new = send_selector(s, r_temp, xs->objp, s_temp, (int)(opparams[1] >> 1) + (uint16)restadjust, xs->sp); if (xs_new && xs_new != xs) - s->execution_stack_pos_changed = 1; + s->_executionStackPosChanged = true; restadjust = 0; } @@ -1457,12 +1452,12 @@ void run_vm(EngineState *s, int restoring) { } // switch(opcode >> 1) - if (s->execution_stack_pos_changed) // Force initialization + if (s->_executionStackPosChanged) // Force initialization xs = xs_new; #ifndef DISABLE_VALIDATIONS - if (xs != s->execution_stack + s->execution_stack_pos) { - sciprintf("Error: xs is stale (%d vs %d); last command was %02x\n", (int)(xs - s->execution_stack), s->execution_stack_pos, opnumber); + if (xs != &(s->_executionStack[s->execution_stack_pos])) { + sciprintf("Error: xs is stale (%d vs %d); last command was %02x\n", (int)(xs - &s->_executionStack[0]), s->execution_stack_pos, opnumber); } #endif if (script_error_flag) { @@ -2018,14 +2013,13 @@ static EngineState *_game_run(EngineState *s, int restoring) { EngineState *successor = NULL; int game_is_finished = 0; do { - s->execution_stack_pos_changed = 0; + s->_executionStackPosChanged = false; run_vm(s, (successor || restoring) ? 1 : 0); if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) { // Restart was requested? successor = NULL; - free(s->execution_stack); - s->execution_stack = NULL; + s->_executionStack.clear(); s->execution_stack_pos = -1; - s->execution_stack_pos_changed = 0; + s->_executionStackPosChanged = false; game_exit(s); script_free_engine(s); |