aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorMax Horn2009-09-17 13:21:19 +0000
committerMax Horn2009-09-17 13:21:19 +0000
commitb2c386ed000bce9a34a3d392b57a5d9abe8dfa7e (patch)
tree758e42e9b29478e0ddd79d2031788956643edf1c /engines/sci/engine
parentd861f5c854fb47e7f0a15a70738ab24f04c8036c (diff)
downloadscummvm-rg350-b2c386ed000bce9a34a3d392b57a5d9abe8dfa7e.tar.gz
scummvm-rg350-b2c386ed000bce9a34a3d392b57a5d9abe8dfa7e.tar.bz2
scummvm-rg350-b2c386ed000bce9a34a3d392b57a5d9abe8dfa7e.zip
SCI: Move parts of struct ScriptState into a new struct DebugState
svn-id: r44151
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/kevent.cpp12
-rw-r--r--engines/sci/engine/kmisc.cpp4
-rw-r--r--engines/sci/engine/scriptdebug.cpp22
-rw-r--r--engines/sci/engine/vm.cpp17
-rw-r--r--engines/sci/engine/vm.h31
5 files changed, 52 insertions, 34 deletions
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 {