aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorFilippos Karapetis2009-07-02 23:58:05 +0000
committerFilippos Karapetis2009-07-02 23:58:05 +0000
commitc3403ac7395cf9df9c4dad57b42e600b200660b5 (patch)
tree3795df52aaa5052473792548b7d7fdae8f0566e6 /engines/sci/engine
parent80cb18e87fb2a0a6ecc3c7f96c5b8366550648ea (diff)
downloadscummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.tar.gz
scummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.tar.bz2
scummvm-rg350-c3403ac7395cf9df9c4dad57b42e600b200660b5.zip
Moved some more debug state related variables in the DebugState struct
svn-id: r42044
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/kevent.cpp12
-rw-r--r--engines/sci/engine/kmisc.cpp5
-rw-r--r--engines/sci/engine/scriptdebug.cpp34
-rw-r--r--engines/sci/engine/vm.cpp15
4 files changed, 34 insertions, 32 deletions
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index d5a725a230..3b37506e6c 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -33,7 +33,7 @@
namespace Sci {
-int g_stop_on_event = 0;
+extern DebugState debugState;
#define SCI_VARIABLE_GAME_SPEED 3
@@ -90,10 +90,12 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
case SCI_EVT_KEYBOARD:
if ((e.buckybits & SCI_EVM_LSHIFT) && (e.buckybits & SCI_EVM_RSHIFT) && (e.data == '-')) {
sciprintf("Debug mode activated\n");
- g_debug_seeking = g_debug_step_running = 0;
+ debugState.seeking = kDebugSeekNothing;
+ debugState.runningStep = 0;
} else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) {
sciprintf("Debug mode activated\n");
- g_debug_seeking = g_debug_step_running = 0;
+ debugState.seeking = kDebugSeekNothing;
+ debugState.runningStep = 0;
} else {
PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event
s->r_acc = make_reg(0, 1);
@@ -137,8 +139,8 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->r_acc = NULL_REG; // Unknown or no event
}
- if ((s->r_acc.offset) && (g_stop_on_event)) {
- g_stop_on_event = 0;
+ if ((s->r_acc.offset) && (debugState.stopOnEvent)) {
+ debugState.stopOnEvent = false;
// A SCI event occured, and we have been asked to stop, so open the debug console
GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger();
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 7954dc5783..99665bae7d 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -93,10 +93,13 @@ reg_t kFlushResources(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
+extern DebugState debugState;
+
reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
sciprintf("Debug mode activated\n");
- g_debug_seeking = g_debug_step_running = 0;
+ debugState.seeking = kDebugSeekNothing;
+ debugState.runningStep = 0;
return s->r_acc;
}
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 0bd1442cf4..dbcd778160 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -32,10 +32,6 @@
namespace Sci {
-int g_debugstate_valid = 0; // Set to 1 while script_debug is running
-int g_debug_step_running = 0; // Set to >0 to allow multiple stepping
-extern int g_debug_seek_special;
-
extern const char *selector_name(EngineState *s, int selector);
DebugState debugState;
@@ -101,7 +97,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
opsize = scr[pos.offset];
opcode = opsize >> 1;
- if (!g_debugstate_valid) {
+ if (!debugState.isValid) {
sciprintf("Not in debug state\n");
return retval;
}
@@ -321,7 +317,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) {
// Do we support a separate console?
- int old_debugstate = g_debugstate_valid;
+ bool old_debugstate = debugState.isValid;
debugState.p_var_segs = segids;
debugState.p_vars = variables;
@@ -333,15 +329,15 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
debugState.p_objp = objp;
debugState.p_restadjust = restadjust;
sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
- g_debugstate_valid = 1;
+ debugState.isValid = true;
disassemble(s, *pc, 0, 1);
- if (g_debug_seeking == kDebugSeekGlobal)
- sciprintf("Global %d (0x%x) = %04x:%04x\n", g_debug_seek_special,
- g_debug_seek_special, PRINT_REG(s->script_000->locals_block->_locals[g_debug_seek_special]));
+ if (debugState.seeking == kDebugSeekGlobal)
+ sciprintf("Global %d (0x%x) = %04x:%04x\n", debugState.seekSpecial,
+ debugState.seekSpecial, PRINT_REG(s->script_000->locals_block->_locals[debugState.seekSpecial]));
- g_debugstate_valid = old_debugstate;
+ debugState.isValid = old_debugstate;
- if (g_debug_seeking && !bp) { // Are we looking for something special?
+ if (debugState.seeking && !bp) { // Are we looking for something special?
MemObject *mobj = GET_SEGMENT(*s->seg_manager, pc->segment, MEM_OBJ_SCRIPT);
if (mobj) {
@@ -353,9 +349,9 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
int paramb1 = pc->offset + 1 >= code_buf_size ? 0 : code_buf[pc->offset + 1];
int paramf1 = (opcode & 1) ? paramb1 : (pc->offset + 2 >= code_buf_size ? 0 : (int16)READ_LE_UINT16(code_buf + pc->offset + 1));
- switch (g_debug_seeking) {
+ switch (debugState.seeking) {
case kDebugSeekSpecialCallk:
- if (paramb1 != g_debug_seek_special)
+ if (paramb1 != debugState.seekSpecial)
return;
case kDebugSeekCallk: {
@@ -365,7 +361,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
}
case kDebugSeekLevelRet: {
- if ((op != op_ret) || (g_debug_seek_level < (int)s->_executionStack.size()-1))
+ if ((op != op_ret) || (debugState.seekLevel < (int)s->_executionStack.size()-1))
return;
break;
}
@@ -377,20 +373,20 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
return; // param or temp
if ((op & 0x3) && s->_executionStack.back().local_segment > 0)
return; // locals and not running in script.000
- if (paramf1 != g_debug_seek_special)
+ if (paramf1 != debugState.seekSpecial)
return; // CORRECT global?
break;
}
- g_debug_seeking = kDebugSeekNothing;
+ debugState.seeking = kDebugSeekNothing;
// OK, found whatever we were looking for
}
}
- g_debugstate_valid = (g_debug_step_running == 0);
+ debugState.isValid = (debugState.runningStep == 0);
- if (g_debugstate_valid) {
+ if (debugState.isValid) {
debugState.p_pc = pc;
debugState.p_sp = sp;
debugState.p_pp = pp;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index cbd0b0cfbb..30b2f07edd 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -49,7 +49,7 @@ reg_t NULL_REG = {0, 0};
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
int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs // FIXME: Avoid non-const global vars
-
+extern DebugState debugState;
static bool breakpointFlag = false; // FIXME: Avoid non-const global vars
static reg_t _dummy_register; // FIXME: Avoid non-const global vars
@@ -396,7 +396,7 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
default:
sciprintf("Send error: Variable selector %04x in %04x:%04x called with %04x params\n", selector, PRINT_REG(send_obj), argc);
script_debug_flag = 1; // Enter debug mode
- g_debug_seeking = g_debug_step_running = 0;
+ debugState.seeking = debugState.runningStep = 0;
#endif
}
break;
@@ -1427,8 +1427,8 @@ void run_vm(EngineState *s, int restoring) {
#if 0
if (script_error_flag) {
- g_debug_step_running = 0; // Stop multiple execution
- g_debug_seeking = 0; // Stop special seeks
+ debugState.runningStep = 0; // Stop multiple execution
+ debugState.seeking = 0; // Stop special seeks
xs->addr.pc.offset = old_pc_offset;
xs->sp = old_sp;
} else
@@ -2057,11 +2057,12 @@ const char *obj_get_name(EngineState *s, reg_t pos) {
return name;
}
+
void quit_vm() {
script_abort_flag = 1; // Terminate VM
- g_debugstate_valid = 0;
- g_debug_seeking = 0;
- g_debug_step_running = 0;
+ debugState.isValid = false;
+ debugState.seeking = kDebugSeekNothing;
+ debugState.runningStep = 0;
}
void shrink_execution_stack(EngineState *s, uint size) {