diff options
-rw-r--r-- | engines/sci/console.cpp | 60 | ||||
-rw-r--r-- | engines/sci/debug.h | 10 | ||||
-rw-r--r-- | engines/sci/engine/kevent.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/kmisc.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 22 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 17 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 31 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 8 |
8 files changed, 88 insertions, 76 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 3f4148fcc0..73ea0ad152 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -183,11 +183,11 @@ Console::Console(SciEngine *vm) : GUI::Debugger() { DCmd_Register("active_object", WRAP_METHOD(Console, cmdViewActiveObject)); DCmd_Register("acc_object", WRAP_METHOD(Console, cmdViewAccumulatorObject)); - scriptState.seeking = kDebugSeekNothing; - scriptState.seekLevel = 0; - scriptState.runningStep = 0; - scriptState.stopOnEvent = false; - scriptState.debugging = false; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.seekLevel = 0; + g_debugState.runningStep = 0; + g_debugState.stopOnEvent = false; + g_debugState.debugging = false; } Console::~Console() { @@ -2113,23 +2113,23 @@ bool Console::cmdBacktrace(int argc, const char **argv) { bool Console::cmdStep(int argc, const char **argv) { if (argc == 2 && atoi(argv[1]) > 0) - scriptState.runningStep = atoi(argv[1]) - 1; - scriptState.debugging = true; + g_debugState.runningStep = atoi(argv[1]) - 1; + g_debugState.debugging = true; return false; } bool Console::cmdStepEvent(int argc, const char **argv) { - scriptState.stopOnEvent = true; - scriptState.debugging = true; + g_debugState.stopOnEvent = true; + g_debugState.debugging = true; return false; } bool Console::cmdStepRet(int argc, const char **argv) { - scriptState.seeking = kDebugSeekLevelRet; - scriptState.seekLevel = _vm->_gamestate->_executionStack.size() - 1; - scriptState.debugging = true; + g_debugState.seeking = kDebugSeekLevelRet; + g_debugState.seekLevel = _vm->_gamestate->_executionStack.size() - 1; + g_debugState.debugging = true; return false; } @@ -2141,9 +2141,9 @@ bool Console::cmdStepGlobal(int argc, const char **argv) { return true; } - scriptState.seeking = kDebugSeekGlobal; - scriptState.seekSpecial = atoi(argv[1]); - scriptState.debugging = true; + g_debugState.seeking = kDebugSeekGlobal; + g_debugState.seekSpecial = atoi(argv[1]); + g_debugState.debugging = true; return false; } @@ -2171,12 +2171,12 @@ bool Console::cmdStepCallk(int argc, const char **argv) { } } - scriptState.seeking = kDebugSeekSpecialCallk; - scriptState.seekSpecial = callk_index; + g_debugState.seeking = kDebugSeekSpecialCallk; + g_debugState.seekSpecial = callk_index; } else { - scriptState.seeking = kDebugSeekCallk; + g_debugState.seeking = kDebugSeekCallk; } - scriptState.debugging = true; + g_debugState.debugging = true; return false; } @@ -2343,14 +2343,14 @@ bool Console::cmdSend(int argc, const char **argv) { xstack->fp += argc; _vm->_gamestate->_executionStackPosChanged = true; - scriptState.debugging = true; + g_debugState.debugging = true; return false; } bool Console::cmdGo(int argc, const char **argv) { // CHECKME: is this necessary? - scriptState.seeking = kDebugSeekNothing; + g_debugState.seeking = kDebugSeekNothing; return Cmd_Exit(argc, argv); } @@ -2764,8 +2764,8 @@ bool Console::cmdExit(int argc, const char **argv) { if (!scumm_stricmp(argv[1], "game")) { // Quit gracefully script_abort_flag = 1; // Terminate VM - scriptState.seeking = kDebugSeekNothing; - scriptState.runningStep = 0; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.runningStep = 0; } else if (!scumm_stricmp(argv[1], "now")) { // Quit ungracefully @@ -3255,29 +3255,29 @@ int c_stepover(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) { opnumber = opcode >> 1; if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ || opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ || opnumber == 0x2b /* super */) { - scriptState.seeking = kDebugSeekSO; - scriptState.seekLevel = s->_executionStack.size()-1; - // Store in scriptState.seekSpecial the offset of the next command after send + g_debugState.seeking = kDebugSeekSO; + g_debugState.seekLevel = s->_executionStack.size()-1; + // Store in g_debugState.seekSpecial the offset of the next command after send switch (opcode) { case 0x46: // calle W - scriptState.seekSpecial = *p_pc + 5; + g_debugState.seekSpecial = *p_pc + 5; break; case 0x44: // callb W case 0x47: // calle B case 0x56: // super W - scriptState.seekSpecial = *p_pc + 4; + g_debugState.seekSpecial = *p_pc + 4; break; case 0x45: // callb B case 0x57: // super B case 0x4A: // send W case 0x54: // self W - scriptState.seekSpecial = *p_pc + 3; + g_debugState.seekSpecial = *p_pc + 3; break; default: - scriptState.seekSpecial = *p_pc + 2; + g_debugState.seekSpecial = *p_pc + 2; } } diff --git a/engines/sci/debug.h b/engines/sci/debug.h index e3bca1f0c1..f331c1e7ed 100644 --- a/engines/sci/debug.h +++ b/engines/sci/debug.h @@ -40,7 +40,7 @@ enum DebugSeeking { kDebugSeekGlobal = 5 // Step forward until one specified global variable is modified }; -struct ScriptState { +struct DebugState { bool debugging; bool stopOnEvent; DebugSeeking seeking; // Stepping forward until some special condition is met @@ -49,12 +49,6 @@ struct ScriptState { int seekSpecial; // Used for special seeks int old_pc_offset; StackPtr old_sp; - ExecStack *xs; - int16 restAdjust; - reg_t *variables[4]; // global, local, temp, param, as immediate pointers - reg_t *variables_base[4]; // Used for referencing VM ops - SegmentId variables_seg[4]; // Same as above, contains segment IDs - int variables_max[4]; // Max. values for all variables }; // Various global variables used for debugging are declared here @@ -62,7 +56,7 @@ extern int g_debug_sleeptime_factor; extern int g_debug_simulated_key; extern bool g_debug_track_mouse_clicks; extern bool g_debug_weak_validations; -extern ScriptState scriptState; +extern DebugState g_debugState; } // End of namespace Sci diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index dc8ee6d296..44d49002ac 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -74,12 +74,12 @@ reg_t kGetEvent(EngineState *s, int, int argc, reg_t *argv) { case SCI_EVT_KEYBOARD: if ((e.buckybits & SCI_EVM_LSHIFT) && (e.buckybits & SCI_EVM_RSHIFT) && (e.data == '-')) { printf("Debug mode activated\n"); - scriptState.seeking = kDebugSeekNothing; - scriptState.runningStep = 0; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.runningStep = 0; } else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) { printf("Debug mode activated\n"); - scriptState.seeking = kDebugSeekNothing; - scriptState.runningStep = 0; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.runningStep = 0; } else { PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event s->r_acc = make_reg(0, 1); @@ -123,8 +123,8 @@ reg_t kGetEvent(EngineState *s, int, int argc, reg_t *argv) { s->r_acc = NULL_REG; // Unknown or no event } - if ((s->r_acc.offset) && (scriptState.stopOnEvent)) { - scriptState.stopOnEvent = false; + if ((s->r_acc.offset) && (g_debugState.stopOnEvent)) { + g_debugState.stopOnEvent = false; // A SCI event occured, and we have been asked to stop, so open the debug console Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index 5bb4737fb2..e045e75b5c 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -101,8 +101,8 @@ reg_t kFlushResources(EngineState *s, int, int argc, reg_t *argv) { reg_t kSetDebug(EngineState *s, int, int argc, reg_t *argv) { printf("Debug mode activated\n"); - scriptState.seeking = kDebugSeekNothing; - scriptState.runningStep = 0; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.runningStep = 0; return s->r_acc; } diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 670aee3981..8c086758d6 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -63,7 +63,7 @@ const char *opcodeNames[] = { extern const char *selector_name(EngineState *s, int selector); -ScriptState scriptState; +DebugState g_debugState; int propertyOffsetToId(SegManager *segMan, int prop_ofs, reg_t objp) { Object *obj = segMan->getObject(objp); @@ -355,11 +355,11 @@ void script_debug(EngineState *s, bool bp) { #endif #if 0 - if (!scriptState.debugging) + if (!g_debugState.debugging) return; #endif - if (scriptState.seeking && !bp) { // Are we looking for something special? + if (g_debugState.seeking && !bp) { // Are we looking for something special? SegmentObj *mobj = GET_SEGMENT(*s->segMan, scriptState.xs->addr.pc.segment, SEG_TYPE_SCRIPT); if (mobj) { @@ -371,9 +371,9 @@ void script_debug(EngineState *s, bool bp) { int paramb1 = scriptState.xs->addr.pc.offset + 1 >= code_buf_size ? 0 : code_buf[scriptState.xs->addr.pc.offset + 1]; int paramf1 = (opcode & 1) ? paramb1 : (scriptState.xs->addr.pc.offset + 2 >= code_buf_size ? 0 : (int16)READ_LE_UINT16(code_buf + scriptState.xs->addr.pc.offset + 1)); - switch (scriptState.seeking) { + switch (g_debugState.seeking) { case kDebugSeekSpecialCallk: - if (paramb1 != scriptState.seekSpecial) + if (paramb1 != g_debugState.seekSpecial) return; case kDebugSeekCallk: { @@ -383,7 +383,7 @@ void script_debug(EngineState *s, bool bp) { } case kDebugSeekLevelRet: { - if ((op != op_ret) || (scriptState.seekLevel < (int)s->_executionStack.size()-1)) + if ((op != op_ret) || (g_debugState.seekLevel < (int)s->_executionStack.size()-1)) return; break; } @@ -395,7 +395,7 @@ void script_debug(EngineState *s, bool bp) { return; // param or temp if ((op & 0x3) && s->_executionStack.back().local_segment > 0) return; // locals and not running in script.000 - if (paramf1 != scriptState.seekSpecial) + if (paramf1 != g_debugState.seekSpecial) return; // CORRECT global? break; @@ -408,7 +408,7 @@ void script_debug(EngineState *s, bool bp) { break; } - scriptState.seeking = kDebugSeekNothing; + g_debugState.seeking = kDebugSeekNothing; // OK, found whatever we were looking for } } @@ -416,12 +416,12 @@ void script_debug(EngineState *s, bool bp) { printf("Step #%d\n", script_step_counter); disassemble(s, scriptState.xs->addr.pc, 0, 1); - if (scriptState.runningStep) { - scriptState.runningStep--; + if (g_debugState.runningStep) { + g_debugState.runningStep--; return; } - scriptState.debugging = false; + g_debugState.debugging = false; Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger(); con->attach(); diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index c507d4ec14..959763ee74 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -46,6 +46,7 @@ reg_t NULL_REG = {0, 0}; #undef STRICT_SEND // Disallows variable sends with more than one parameter #undef STRICT_READ // Disallows reading from out-of-bounds parameters and locals +ScriptState scriptState; int script_abort_flag = 0; // Set to 1 to abort execution. Set to 2 to force a replay afterwards // FIXME: Avoid non-const global vars int script_step_counter = 0; // Counts the number of steps executed // FIXME: Avoid non-const global vars @@ -230,7 +231,7 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP if (bp->type == BREAK_EXPORT && bp->data.address == bpaddress) { Console *con = ((SciEngine *)g_engine)->getSciDebugger(); con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct); - scriptState.debugging = true; + g_debugState.debugging = true; breakpointFlag = true; break; } @@ -298,7 +299,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj)); print_send_action = 1; breakpointFlag = true; - scriptState.debugging = true; + g_debugState.debugging = true; break; } bp = bp->next; @@ -355,7 +356,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt break; #ifdef STRICT_SEND default: - scriptState.seeking = scriptState.runningStep = 0; + g_debugState.seeking = g_debugState.runningStep = 0; error("Send error: Variable selector %04x in %04x:%04x called with %04x params", selector, PRINT_REG(send_obj), argc); #endif } @@ -555,8 +556,8 @@ void run_vm(EngineState *s, int restoring) { int var_type; // See description below int var_number; - scriptState.old_pc_offset = scriptState.xs->addr.pc.offset; - scriptState.old_sp = scriptState.xs->sp; + g_debugState.old_pc_offset = scriptState.xs->addr.pc.offset; + g_debugState.old_sp = scriptState.xs->sp; if (s->_executionStackPosChanged) { Script *scr; @@ -616,7 +617,7 @@ void run_vm(EngineState *s, int restoring) { // Debug if this has been requested: // TODO: re-implement sci_debug_flags - if (scriptState.debugging /* sci_debug_flags*/) { + if (g_debugState.debugging /* sci_debug_flags*/) { script_debug(s, breakpointFlag); breakpointFlag = false; } @@ -1917,8 +1918,8 @@ int game_run(EngineState **_s) { void quit_vm() { script_abort_flag = 1; // Terminate VM - scriptState.seeking = kDebugSeekNothing; - scriptState.runningStep = 0; + g_debugState.seeking = kDebugSeekNothing; + g_debugState.runningStep = 0; } void shrink_execution_stack(EngineState *s, uint size) { diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 56fbb0bd64..cd37166d50 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -212,13 +212,6 @@ struct ViewObject { int real_y, z, index_nr; /* Used for sorting */ }; -enum { - VAR_GLOBAL = 0, - VAR_LOCAL = 1, - VAR_TEMP = 2, - VAR_PARAM = 3 -}; - enum ExecStackType { EXEC_STACK_TYPE_CALL = 0, EXEC_STACK_TYPE_KERNEL = 1, @@ -248,6 +241,30 @@ struct ExecStack { reg_t* getVarPointer(SegManager *segMan) const; }; +enum { + VAR_GLOBAL = 0, + VAR_LOCAL = 1, + VAR_TEMP = 2, + VAR_PARAM = 3 +}; + +/** + * Structure for storing the current internal state of the VM. + */ +struct ScriptState { + ExecStack *xs; + int16 restAdjust; + reg_t *variables[4]; // global, local, temp, param, as immediate pointers + reg_t *variables_base[4]; // Used for referencing VM ops + SegmentId variables_seg[4]; // Same as above, contains segment IDs + int variables_max[4]; // Max. values for all variables +}; + +/** + * The current internal state of the VM. + */ +extern ScriptState scriptState; + // These types are used both as identifiers and as elements of bitfields enum BreakpointType { diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index fc5371afe5..524e7920f0 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -208,12 +208,12 @@ Common::Error SciEngine::run() { GUI::Debugger *SciEngine::getDebugger() { if (_gamestate) { ExecStack *xs = &(_gamestate->_executionStack.back()); - xs->addr.pc.offset = scriptState.old_pc_offset; - xs->sp = scriptState.old_sp; + xs->addr.pc.offset = g_debugState.old_pc_offset; + xs->sp = g_debugState.old_sp; } - scriptState.runningStep = 0; // Stop multiple execution - scriptState.seeking = kDebugSeekNothing; // Stop special seeks + g_debugState.runningStep = 0; // Stop multiple execution + g_debugState.seeking = kDebugSeekNothing; // Stop special seeks return _console; } |