aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/console.cpp3
-rw-r--r--engines/sci/console.h1
-rw-r--r--engines/sci/debug.h15
-rw-r--r--engines/sci/engine/grammar.cpp4
-rw-r--r--engines/sci/engine/kevent.cpp6
-rw-r--r--engines/sci/engine/kmisc.cpp2
-rw-r--r--engines/sci/engine/vm.cpp18
-rw-r--r--engines/sci/gfx/operations.cpp5
-rw-r--r--engines/sci/sci.cpp13
-rw-r--r--engines/sci/sci.h1
-rw-r--r--engines/sci/tools.cpp2
-rw-r--r--engines/sci/vocabulary.cpp4
12 files changed, 38 insertions, 36 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 002acbae86..bf919c3a25 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -50,7 +50,6 @@ int g_debug_sleeptime_factor = 1;
int g_debug_simulated_key = 0;
bool g_debug_track_mouse_clicks = false;
bool g_debug_weak_validations = true;
-extern DebugState debugState;
Console::Console(SciEngine *vm) : GUI::Debugger() {
_vm = vm;
@@ -1598,7 +1597,7 @@ bool Console::cmdGCObjects(int argc, const char **argv) {
void _print_address(void * _, reg_t addr) {
if (addr.segment)
- ((SciEngine *)g_engine)->getDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr));
+ ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr));
}
bool Console::cmdGCShowReachable(int argc, const char **argv) {
diff --git a/engines/sci/console.h b/engines/sci/console.h
index c45202de16..84a8d2f942 100644
--- a/engines/sci/console.h
+++ b/engines/sci/console.h
@@ -154,6 +154,7 @@ private:
private:
SciEngine *_vm;
+ bool _mouseVisible;
};
} // End of namespace Sci
diff --git a/engines/sci/debug.h b/engines/sci/debug.h
index 60bf938300..fbd98e0d6f 100644
--- a/engines/sci/debug.h
+++ b/engines/sci/debug.h
@@ -28,12 +28,6 @@
namespace Sci {
-// Various global variables used for debugging are declared here
-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;
-
enum DebugSeeking {
kDebugSeekNothing = 0,
kDebugSeekCallk = 1, // Step forward until callk is found
@@ -50,6 +44,8 @@ struct DebugState {
int runningStep; // Set to > 0 to allow multiple stepping
int seekLevel; // Used for seekers that want to check their exec stack depth
int seekSpecial; // Used for special seeks
+ int old_pc_offset;
+ StackPtr old_sp;
reg_t *p_pc;
StackPtr *p_sp;
StackPtr *p_pp;
@@ -61,6 +57,13 @@ struct DebugState {
int *p_var_max; // May be NULL even in valid state!
};
+// Various global variables used for debugging are declared here
+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 DebugState debugState;
+
} // End of namespace Sci
#endif
diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp
index 275a31a0d4..e75441432d 100644
--- a/engines/sci/engine/grammar.cpp
+++ b/engines/sci/engine/grammar.cpp
@@ -351,7 +351,7 @@ parse_rule_list_t *Vocabulary::buildGNF(bool verbose) {
int ntrules_nr;
parse_rule_list_t *ntlist = NULL;
parse_rule_list_t *tlist, *new_tlist;
- GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+ Console *con = ((SciEngine *)g_engine)->getSciDebugger();
for (uint i = 1; i < _parserBranches.size(); i++) { // branch rule 0 is treated specially
parse_rule_t *rule = _vbuild_rule(&_parserBranches[i]);
@@ -477,7 +477,7 @@ static int _vbpt_write_subexpression(parse_tree_node_t *nodes, int *pos, parse_r
}
int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words, bool verbose) {
- GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+ Console *con = ((SciEngine *)g_engine)->getSciDebugger();
// Get the start rules:
parse_rule_list_t *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]);
parse_rule_list_t *results = NULL;
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 3b37506e6c..e40368a5c0 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -33,8 +33,6 @@
namespace Sci {
-extern DebugState debugState;
-
#define SCI_VARIABLE_GAME_SPEED 3
reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
@@ -112,7 +110,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// track left buttton clicks, if requested
if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && g_debug_track_mouse_clicks) {
- ((SciEngine *)g_engine)->getDebugger()->DebugPrintf("Mouse clicked at %d, %d\n",
+ ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n",
s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y);
}
@@ -143,7 +141,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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();
+ Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
con->DebugPrintf("SCI event occured: ");
switch (e.type) {
case SCI_EVT_QUIT:
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 99665bae7d..98fba97f0e 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -93,8 +93,6 @@ 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");
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 30b2f07edd..44b119ab46 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -49,7 +49,6 @@ 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
@@ -606,14 +605,12 @@ void run_vm(EngineState *s, int restoring) {
while (1) {
byte opcode;
- int old_pc_offset;
- StackPtr old_sp;
byte opnumber;
int var_type; // See description below
int var_number;
- old_pc_offset = xs->addr.pc.offset;
- old_sp = xs->sp;
+ debugState.old_pc_offset = xs->addr.pc.offset;
+ debugState.old_sp = xs->sp;
if (s->_executionStackPosChanged) {
Script *scr;
@@ -1424,16 +1421,7 @@ void run_vm(EngineState *s, int restoring) {
opnumber);
}
//#endif
-
-#if 0
- if (script_error_flag) {
- debugState.runningStep = 0; // Stop multiple execution
- debugState.seeking = 0; // Stop special seeks
- xs->addr.pc.offset = old_pc_offset;
- xs->sp = old_sp;
- } else
-#endif
- ++script_step_counter;
+ ++script_step_counter;
}
}
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index 7496c55868..82b5e78117 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -1418,8 +1418,9 @@ static sci_event_t scummvm_get_event(GfxDriver *drv) {
// Debug console
if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {
// Open debug console
- ((Sci::SciEngine*)g_engine)->getDebugger()->attach();
- ((Sci::SciEngine*)g_engine)->getDebugger()->onFrame();
+ Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
+ con->attach();
+ con->onFrame();
// Clear keyboard event
input.type = SCI_EVT_NONE;
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index f58d729bf6..aa9e2415f5 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -29,6 +29,7 @@
#include "engines/advancedDetector.h"
#include "sci/sci.h"
+#include "sci/debug.h"
#include "sci/console.h"
#include "sci/engine/state.h"
@@ -254,7 +255,19 @@ Common::Error SciEngine::run() {
return Common::kNoError;
}
+// Invoked by error() when a severe error occurs
GUI::Debugger *SciEngine::getDebugger() {
+ ExecStack *xs = &(_gamestate->_executionStack.back());
+ debugState.runningStep = 0; // Stop multiple execution
+ debugState.seeking = kDebugSeekNothing; // Stop special seeks
+ xs->addr.pc.offset = debugState.old_pc_offset;
+ xs->sp = debugState.old_sp;
+
+ return _console;
+}
+
+// Used to obtain the engine's console in order to print messages to it
+Console *SciEngine::getSciDebugger() {
return _console;
}
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index 91f491fe71..b68301546d 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -142,6 +142,7 @@ public:
virtual Common::Error run();
void pauseEngineIntern(bool pause);
virtual GUI::Debugger *getDebugger();
+ Console *getSciDebugger();
const char* getGameID() const;
int getResourceVersion() const;
diff --git a/engines/sci/tools.cpp b/engines/sci/tools.cpp
index 589ce298d7..d0e11aca09 100644
--- a/engines/sci/tools.cpp
+++ b/engines/sci/tools.cpp
@@ -70,7 +70,7 @@ void sciprintf(const char *fmt, ...) {
// Display the result suitably
if (g_redirect_sciprintf_to_gui)
- ((SciEngine *)g_engine)->getDebugger()->DebugPrintf("%s", buf);
+ ((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("%s", buf);
printf("%s", buf);
free(buf);
diff --git a/engines/sci/vocabulary.cpp b/engines/sci/vocabulary.cpp
index c877053060..6616ac362d 100644
--- a/engines/sci/vocabulary.cpp
+++ b/engines/sci/vocabulary.cpp
@@ -438,7 +438,7 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch
void Vocabulary::printSuffixes() const {
char word_buf[256], alt_buf[256];
- GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+ Console *con = ((SciEngine *)g_engine)->getSciDebugger();
int i = 0;
for (SuffixList::const_iterator suf = _parserSuffixes.begin(); suf != _parserSuffixes.end(); ++suf) {
@@ -453,7 +453,7 @@ void Vocabulary::printSuffixes() const {
}
void Vocabulary::printParserWords() const {
- GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
+ Console *con = ((SciEngine *)g_engine)->getSciDebugger();
int j = 0;
for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) {