aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorMax Horn2010-07-12 23:20:33 +0000
committerMax Horn2010-07-12 23:20:33 +0000
commit1d3a0f6decd54b017d2ca55a95048de4afdbd868 (patch)
treebc007a606364ea7565107201b72e0e09ebb4f655 /engines/sci/engine
parentdcd520ce310a593e7dbc5ecac60c5f3f3e8363a6 (diff)
downloadscummvm-rg350-1d3a0f6decd54b017d2ca55a95048de4afdbd868.tar.gz
scummvm-rg350-1d3a0f6decd54b017d2ca55a95048de4afdbd868.tar.bz2
scummvm-rg350-1d3a0f6decd54b017d2ca55a95048de4afdbd868.zip
SCI: Turn global object g_debugState into SciEngine member var
svn-id: r50836
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/kevent.cpp8
-rw-r--r--engines/sci/engine/kmisc.cpp4
-rw-r--r--engines/sci/engine/scriptdebug.cpp43
-rw-r--r--engines/sci/engine/vm.cpp27
4 files changed, 40 insertions, 42 deletions
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 4086d14a25..7547ad5ab6 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -78,8 +78,8 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
switch (curEvent.type) {
case SCI_EVENT_QUIT:
s->abortScriptProcessing = kAbortQuitGame; // Terminate VM
- g_debugState.seeking = kDebugSeekNothing;
- g_debugState.runningStep = 0;
+ g_sci->_debugState.seeking = kDebugSeekNothing;
+ g_sci->_debugState.runningStep = 0;
break;
case SCI_EVENT_KEYBOARD:
@@ -124,8 +124,8 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
s->r_acc = NULL_REG; // Unknown or no event
}
- if ((s->r_acc.offset) && (g_debugState.stopOnEvent)) {
- g_debugState.stopOnEvent = false;
+ if ((s->r_acc.offset) && (g_sci->_debugState.stopOnEvent)) {
+ g_sci->_debugState.stopOnEvent = false;
// A SCI event occurred, and we have been asked to stop, so open the debug console
Console *con = g_sci->getSciDebugger();
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 1ed12c092e..b8c62210f9 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -154,8 +154,8 @@ reg_t kFlushResources(EngineState *s, int argc, reg_t *argv) {
reg_t kSetDebug(EngineState *s, int argc, reg_t *argv) {
printf("Debug mode activated\n");
- g_debugState.seeking = kDebugSeekNothing;
- g_debugState.runningStep = 0;
+ g_sci->_debugState.seeking = kDebugSeekNothing;
+ g_sci->_debugState.runningStep = 0;
return s->r_acc;
}
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 4813e083fd..915a6fa994 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -63,8 +63,6 @@ const char *opcodeNames[] = {
"-sli", "-sti", "-spi"
};
-DebugState g_debugState; // FIXME: Avoid non-const global vars
-
// Disassembles one command from the heap, returns address of next command or 0 if a ret was encountered.
reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecode) {
SegmentObj *mobj = s->_segMan->getSegment(pos.segment, SEG_TYPE_SCRIPT);
@@ -277,30 +275,32 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
}
-void script_debug(EngineState *s) {
- if (g_debugState.seeking && !g_debugState.breakpointWasHit) { // Are we looking for something special?
- if (g_debugState.seeking == kDebugSeekStepOver) {
+void SciEngine::scriptDebug() {
+ EngineState *s = _gamestate;
+ if (_debugState.seeking && !_debugState.breakpointWasHit) { // Are we looking for something special?
+ if (_debugState.seeking == kDebugSeekStepOver) {
// are we above seek-level? resume then
- if (g_debugState.seekLevel < (int)s->_executionStack.size())
+ if (_debugState.seekLevel < (int)s->_executionStack.size())
return;
- g_debugState.seeking = kDebugSeekNothing;
+ _debugState.seeking = kDebugSeekNothing;
}
- if (g_debugState.seeking != kDebugSeekNothing) {
- SegmentObj *mobj = s->_segMan->getSegment(s->xs->addr.pc.segment, SEG_TYPE_SCRIPT);
+ if (_debugState.seeking != kDebugSeekNothing) {
+ const reg_t pc = s->xs->addr.pc;
+ SegmentObj *mobj = s->_segMan->getSegment(pc.segment, SEG_TYPE_SCRIPT);
if (mobj) {
Script *scr = (Script *)mobj;
const byte *code_buf = scr->getBuf();
int code_buf_size = scr->getBufSize();
- int opcode = s->xs->addr.pc.offset >= code_buf_size ? 0 : code_buf[s->xs->addr.pc.offset];
+ int opcode = pc.offset >= code_buf_size ? 0 : code_buf[pc.offset];
int op = opcode >> 1;
- int paramb1 = s->xs->addr.pc.offset + 1 >= code_buf_size ? 0 : code_buf[s->xs->addr.pc.offset + 1];
- int paramf1 = (opcode & 1) ? paramb1 : (s->xs->addr.pc.offset + 2 >= code_buf_size ? 0 : (int16)READ_SCI11ENDIAN_UINT16(code_buf + s->xs->addr.pc.offset + 1));
+ 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_SCI11ENDIAN_UINT16(code_buf + pc.offset + 1));
- switch (g_debugState.seeking) {
+ switch (_debugState.seeking) {
case kDebugSeekSpecialCallk:
- if (paramb1 != g_debugState.seekSpecial)
+ if (paramb1 != _debugState.seekSpecial)
return;
case kDebugSeekCallk:
@@ -309,7 +309,7 @@ void script_debug(EngineState *s) {
break;
case kDebugSeekLevelRet:
- if ((op != op_ret) || (g_debugState.seekLevel < (int)s->_executionStack.size()-1))
+ if ((op != op_ret) || (_debugState.seekLevel < (int)s->_executionStack.size()-1))
return;
break;
@@ -320,7 +320,7 @@ void script_debug(EngineState *s) {
return; // param or temp
if ((op & 0x3) && s->_executionStack.back().local_segment > 0)
return; // locals and not running in script.000
- if (paramf1 != g_debugState.seekSpecial)
+ if (paramf1 != _debugState.seekSpecial)
return; // CORRECT global?
break;
@@ -328,7 +328,7 @@ void script_debug(EngineState *s) {
break;
}
- g_debugState.seeking = kDebugSeekNothing;
+ _debugState.seeking = kDebugSeekNothing;
}
}
// OK, found whatever we were looking for
@@ -337,15 +337,14 @@ void script_debug(EngineState *s) {
printf("Step #%d\n", s->scriptStepCounter);
disassemble(s, s->xs->addr.pc, 0, 1);
- if (g_debugState.runningStep) {
- g_debugState.runningStep--;
+ if (_debugState.runningStep) {
+ _debugState.runningStep--;
return;
}
- g_debugState.debugging = false;
+ _debugState.debugging = false;
- Console *con = ((Sci::SciEngine *)g_engine)->getSciDebugger();
- con->attach();
+ _console->attach();
}
void Kernel::dumpScriptObject(char *data, int seeker, int objsize) {
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index d0dd5b6ad3..57c02f8c36 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -30,7 +30,6 @@
#include "sci/sci.h"
#include "sci/console.h"
-#include "sci/debug.h" // for g_debugState
#include "sci/resource.h"
#include "sci/engine/features.h"
#include "sci/engine/state.h"
@@ -474,18 +473,18 @@ ExecStack *execute_method(EngineState *s, uint16 script, uint16 pubfunct, StackP
}
// Check if a breakpoint is set on this method
- if (g_debugState._activeBreakpointTypes & BREAK_EXPORT) {
+ if (g_sci->_debugState._activeBreakpointTypes & BREAK_EXPORT) {
uint32 bpaddress;
bpaddress = (script << 16 | pubfunct);
Common::List<Breakpoint>::const_iterator bp;
- for (bp = g_debugState._breakpoints.begin(); bp != g_debugState._breakpoints.end(); ++bp) {
+ for (bp = g_sci->_debugState._breakpoints.begin(); bp != g_sci->_debugState._breakpoints.end(); ++bp) {
if (bp->type == BREAK_EXPORT && bp->address == bpaddress) {
Console *con = g_sci->getSciDebugger();
con->DebugPrintf("Break on script %d, export %d\n", script, pubfunct);
- g_debugState.debugging = true;
- g_debugState.breakpointWasHit = true;
+ g_sci->_debugState.debugging = true;
+ g_sci->_debugState.breakpointWasHit = true;
break;
}
}
@@ -553,13 +552,13 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
}
// Check if a breakpoint is set on this method
- if (g_debugState._activeBreakpointTypes & BREAK_SELECTOR) {
+ if (g_sci->_debugState._activeBreakpointTypes & BREAK_SELECTOR) {
char method_name[256];
sprintf(method_name, "%s::%s", s->_segMan->getObjectName(send_obj), g_sci->getKernel()->getSelectorName(selector).c_str());
Common::List<Breakpoint>::const_iterator bp;
- for (bp = g_debugState._breakpoints.begin(); bp != g_debugState._breakpoints.end(); ++bp) {
+ for (bp = g_sci->_debugState._breakpoints.begin(); bp != g_sci->_debugState._breakpoints.end(); ++bp) {
int cmplen = bp->name.size();
if (bp->name.lastChar() != ':')
cmplen = 256;
@@ -568,8 +567,8 @@ ExecStack *send_selector(EngineState *s, reg_t send_obj, reg_t work_obj, StackPt
Console *con = g_sci->getSciDebugger();
con->DebugPrintf("Break on %s (in [%04x:%04x])\n", method_name, PRINT_REG(send_obj));
printSendActions = true;
- g_debugState.debugging = true;
- g_debugState.breakpointWasHit = true;
+ g_sci->_debugState.debugging = true;
+ g_sci->_debugState.breakpointWasHit = true;
break;
}
}
@@ -1003,8 +1002,8 @@ void run_vm(EngineState *s, bool restoring) {
int var_type; // See description below
int var_number;
- g_debugState.old_pc_offset = s->xs->addr.pc.offset;
- g_debugState.old_sp = s->xs->sp;
+ g_sci->_debugState.old_pc_offset = s->xs->addr.pc.offset;
+ g_sci->_debugState.old_sp = s->xs->sp;
if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit())
return; // Stop processing
@@ -1046,9 +1045,9 @@ void run_vm(EngineState *s, bool restoring) {
// Debug if this has been requested:
// TODO: re-implement sci_debug_flags
- if (g_debugState.debugging /* sci_debug_flags*/) {
- script_debug(s);
- g_debugState.breakpointWasHit = false;
+ if (g_sci->_debugState.debugging /* sci_debug_flags*/) {
+ g_sci->scriptDebug();
+ g_sci->_debugState.breakpointWasHit = false;
}
Console *con = g_sci->getSciDebugger();
if (con->isAttached()) {