aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-06-04 11:28:05 +0000
committerMax Horn2009-06-04 11:28:05 +0000
commit382ebea3faa5f824ba385b9837c4106b6c1fe3c7 (patch)
treec6d6b2d141039bd8f4ea4e1cb4e90cc1dfdb8286
parent85950d6f6b25421c86ab79eea0c4cf96f6feb720 (diff)
downloadscummvm-rg350-382ebea3faa5f824ba385b9837c4106b6c1fe3c7.tar.gz
scummvm-rg350-382ebea3faa5f824ba385b9837c4106b6c1fe3c7.tar.bz2
scummvm-rg350-382ebea3faa5f824ba385b9837c4106b6c1fe3c7.zip
SCI: Renamed various debug related global variables to have a g_ prefix; and moved any 'extern' decls of them into a new header file
svn-id: r41163
-rw-r--r--engines/sci/console.cpp27
-rw-r--r--engines/sci/debug.h47
-rw-r--r--engines/sci/engine/kernel.h5
-rw-r--r--engines/sci/engine/kevent.cpp23
-rw-r--r--engines/sci/engine/kgraphics.cpp8
-rw-r--r--engines/sci/engine/kmisc.cpp3
-rw-r--r--engines/sci/engine/scriptdebug.cpp113
-rw-r--r--engines/sci/engine/vm.cpp34
-rw-r--r--engines/sci/engine/vm.h5
9 files changed, 148 insertions, 117 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index baf89a5082..047c18bbb4 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -27,6 +27,7 @@
#include "sci/sci.h"
#include "sci/console.h"
+#include "sci/debug.h"
#include "sci/resource.h"
#include "sci/vocabulary.h"
#include "sci/engine/savegame.h"
@@ -47,21 +48,21 @@ namespace Sci {
extern EngineState *g_EngineState;
-int debug_sleeptime_factor = 1;
-int debug_simulated_key = 0;
-bool debug_track_mouse_clicks = false;
-bool debug_weak_validations = true;
+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;
Console::Console(SciEngine *vm) : GUI::Debugger() {
_vm = vm;
// Variables
- DVar_Register("sleeptime_factor", &debug_sleeptime_factor, DVAR_INT, 0);
+ DVar_Register("sleeptime_factor", &g_debug_sleeptime_factor, DVAR_INT, 0);
DVar_Register("gc_interval", &script_gc_interval, DVAR_INT, 0);
- DVar_Register("simulated_key", &debug_simulated_key, DVAR_INT, 0);
- DVar_Register("track_mouse_clicks", &debug_track_mouse_clicks, DVAR_BOOL, 0);
- DVar_Register("weak_validations", &debug_weak_validations, DVAR_BOOL, 0);
+ DVar_Register("simulated_key", &g_debug_simulated_key, DVAR_INT, 0);
+ DVar_Register("track_mouse_clicks", &g_debug_track_mouse_clicks, DVAR_BOOL, 0);
+ DVar_Register("weak_validations", &g_debug_weak_validations, DVAR_BOOL, 0);
// General
DCmd_Register("help", WRAP_METHOD(Console, cmdHelp));
@@ -667,7 +668,7 @@ bool Console::cmdRestoreGame(int argc, const char **argv) {
g_EngineState->successor = newstate; // Set successor
script_abort_flag = SCRIPT_ABORT_WITH_REPLAY; // Abort current game
- _debugstate_valid = 0;
+ g_debugstate_valid = 0;
shrink_execution_stack(g_EngineState, g_EngineState->execution_stack_base + 1);
return 0;
@@ -698,7 +699,7 @@ bool Console::cmdRestartGame(int argc, const char **argv) {
g_EngineState->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW;
script_abort_flag = 1;
- _debugstate_valid = 0;
+ g_debugstate_valid = 0;
return false;
}
@@ -2347,9 +2348,9 @@ bool Console::cmdExit(int argc, const char **argv) {
if (!scumm_stricmp(argv[1], "game")) {
// Quit gracefully
script_abort_flag = 1; // Terminate VM
- _debugstate_valid = 0;
- _debug_seeking = 0;
- _debug_step_running = 0;
+ g_debugstate_valid = 0;
+ g_debug_seeking = 0;
+ g_debug_step_running = 0;
} else if (!scumm_stricmp(argv[1], "now")) {
// Quit ungracefully
diff --git a/engines/sci/debug.h b/engines/sci/debug.h
new file mode 100644
index 0000000000..ec44838826
--- /dev/null
+++ b/engines/sci/debug.h
@@ -0,0 +1,47 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCI_DEBUG_H
+#define SCI_DEBUG_H
+
+namespace Sci {
+
+// Various global variables used for debugging are declared here
+
+extern int g_stop_on_event;
+
+extern int g_debugstate_valid;
+extern int g_debug_seeking;
+extern int g_debug_step_running;
+
+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;
+
+
+} // End of namespace Sci
+
+#endif
diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h
index 862ca2514e..0db5b9205b 100644
--- a/engines/sci/engine/kernel.h
+++ b/engines/sci/engine/kernel.h
@@ -38,11 +38,6 @@ namespace Sci {
struct Node; // from vm.h
struct List; // from vm.h
-extern int stop_on_event;
-
-extern int _debug_seeking;
-extern int _debug_step_running;
-
#define AVOIDPATH_DYNMEM_STRING "AvoidPath polyline"
//#define DEBUG_PARSER // enable for parser debugging
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index c0a137469e..b275e9c0b9 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -28,13 +28,12 @@
#include "sci/engine/kernel.h"
#include "sci/gfx/gfx_widgets.h"
#include "sci/gfx/gfx_state_internal.h" // required for GfxPort, GfxVisual
-#include "sci/console.h" // for debug_simulated_key
+#include "sci/console.h"
+#include "sci/debug.h" // for g_debug_simulated_key
namespace Sci {
-int stop_on_event = 0;
-extern int debug_simulated_key;
-extern bool debug_track_mouse_clicks;
+int g_stop_on_event = 0;
#define SCI_VARIABLE_GAME_SPEED 3
@@ -53,13 +52,13 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// If there's a simkey pending, and the game wants a keyboard event, use the
// simkey instead of a normal event
- if (debug_simulated_key && (mask & SCI_EVT_KEYBOARD)) {
+ if (g_debug_simulated_key && (mask & SCI_EVT_KEYBOARD)) {
PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event
- PUT_SEL32V(obj, message, debug_simulated_key);
+ PUT_SEL32V(obj, message, g_debug_simulated_key);
PUT_SEL32V(obj, modifiers, SCI_EVM_NUMLOCK); // Numlock on
PUT_SEL32V(obj, x, s->gfx_state->pointer_pos.x);
PUT_SEL32V(obj, y, s->gfx_state->pointer_pos.y);
- debug_simulated_key = 0;
+ g_debug_simulated_key = 0;
return make_reg(0, 1);
}
@@ -91,10 +90,10 @@ 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");
- _debug_seeking = _debug_step_running = 0;
+ g_debug_seeking = g_debug_step_running = 0;
} else if ((e.buckybits & SCI_EVM_CTRL) && (e.data == '`')) {
sciprintf("Debug mode activated\n");
- _debug_seeking = _debug_step_running = 0;
+ g_debug_seeking = g_debug_step_running = 0;
} else {
PUT_SEL32V(obj, type, SCI_EVT_KEYBOARD); // Keyboard event
s->r_acc = make_reg(0, 1);
@@ -110,7 +109,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int extra_bits = 0;
// track left buttton clicks, if requested
- if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && debug_track_mouse_clicks) {
+ 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",
s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y);
}
@@ -138,8 +137,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) && (stop_on_event)) {
- stop_on_event = 0;
+ if ((s->r_acc.offset) && (g_stop_on_event)) {
+ g_stop_on_event = 0;
}
return s->r_acc;
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 4c4be0242c..4ccc125eb4 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -27,7 +27,7 @@
#include "common/events.h"
#include "sci/sci.h"
-#include "sci/console.h" // for debug_sleeptime_factor
+#include "sci/debug.h" // for g_debug_sleeptime_factor
#include "sci/resource.h"
#include "sci/engine/state.h"
#include "sci/engine/kernel.h"
@@ -369,8 +369,6 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-extern int oldx, oldy;
-
reg_t kMoveCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
Common::Point newpos;
@@ -647,8 +645,6 @@ reg_t kTextSize(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-extern int debug_sleeptime_factor;
-
reg_t kWait(EngineState *s, int funct_nr, int argc, reg_t *argv) {
uint32 time;
int sleep_time = UKPV(0);
@@ -660,7 +656,7 @@ reg_t kWait(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// Reset optimization flags: Game is playing along nicely anyway
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
- sleep_time *= debug_sleeptime_factor;
+ sleep_time *= g_debug_sleeptime_factor;
GFX_ASSERT(gfxop_sleep(s->gfx_state, sleep_time * 1000 / 60));
return s->r_acc;
diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index 34d8b5397c..3673dbe3c4 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -28,6 +28,7 @@
#include <time.h> // FIXME: For struct tm
#include "sci/sci.h"
+#include "sci/debug.h"
#include "sci/engine/state.h"
#include "sci/engine/kernel.h"
#include "sci/engine/gc.h"
@@ -95,7 +96,7 @@ reg_t kFlushResources(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
sciprintf("Debug mode activated\n");
- _debug_seeking = _debug_step_running = 0;
+ g_debug_seeking = g_debug_step_running = 0;
return s->r_acc;
}
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 1f750abe58..f78362a320 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -26,6 +26,7 @@
// Script debugger functionality. Absolutely not threadsafe.
#include "sci/sci.h"
+#include "sci/debug.h"
#include "sci/engine/state.h"
#include "sci/engine/gc.h"
#include "sci/engine/kernel_types.h"
@@ -46,13 +47,13 @@
namespace Sci {
-int _debugstate_valid = 0; // Set to 1 while script_debug is running
-int _debug_step_running = 0; // Set to >0 to allow multiple stepping
-int _debug_commands_not_hooked = 1; // Commands not hooked to the console yet?
-int _debug_seeking = 0; // Stepping forward until some special condition is met
-int _debug_seek_level = 0; // Used for seekers that want to check their exec stack depth
-int _debug_seek_special = 0; // Used for special seeks(1)
-reg_t _debug_seek_reg = NULL_REG; // Used for special seeks(2)
+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
+static bool s_debug_commands_hooked = false; // Commands hooked to the console yet?
+int g_debug_seeking = 0; // Stepping forward until some special condition is met
+static int s_debug_seek_level = 0; // Used for seekers that want to check their exec stack depth
+static int s_debug_seek_special = 0; // Used for special seeks(1)
+static reg_t s_debug_seek_reg = NULL_REG; // Used for special seeks(2)
#define _DEBUG_SEEK_NOTHING 0
#define _DEBUG_SEEK_CALLK 1 // Step forward until callk is found
@@ -121,9 +122,9 @@ static const char *_debug_get_input() {
}
int c_step(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- _debugstate_valid = 0;
+ g_debugstate_valid = 0;
if (cmdParams.size() && (cmdParams[0].val > 0))
- _debug_step_running = cmdParams[0].val - 1;
+ g_debug_step_running = cmdParams[0].val - 1;
return 0;
}
@@ -133,39 +134,39 @@ int c_step(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
int c_stepover(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
int opcode, opnumber;
- if (!_debugstate_valid) {
+ if (!g_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
}
- _debugstate_valid = 0;
+ g_debugstate_valid = 0;
opcode = s->_heap[*p_pc];
opnumber = opcode >> 1;
if (opnumber == 0x22 /* callb */ || opnumber == 0x23 /* calle */ ||
opnumber == 0x25 /* send */ || opnumber == 0x2a /* self */ || opnumber == 0x2b /* super */) {
- _debug_seeking = _DEBUG_SEEK_SO;
- _debug_seek_level = s->_executionStack.size()-1;
- // Store in _debug_seek_special the offset of the next command after send
+ g_debug_seeking = _DEBUG_SEEK_SO;
+ s_debug_seek_level = s->_executionStack.size()-1;
+ // Store in s_debug_seek_special the offset of the next command after send
switch (opcode) {
case 0x46: // calle W
- _debug_seek_special = *p_pc + 5;
+ s_debug_seek_special = *p_pc + 5;
break;
case 0x44: // callb W
case 0x47: // calle B
case 0x56: // super W
- _debug_seek_special = *p_pc + 4;
+ s_debug_seek_special = *p_pc + 4;
break;
case 0x45: // callb B
case 0x57: // super B
case 0x4A: // send W
case 0x54: // self W
- _debug_seek_special = *p_pc + 3;
+ s_debug_seek_special = *p_pc + 3;
break;
default:
- _debug_seek_special = *p_pc + 2;
+ s_debug_seek_special = *p_pc + 2;
}
}
@@ -319,7 +320,7 @@ reg_t disassemble(EngineState *s, reg_t pos, int print_bw_tag, int print_bytecod
opsize = scr[pos.offset];
opcode = opsize >> 1;
- if (!_debugstate_valid) {
+ if (!g_debugstate_valid) {
sciprintf("Not in debug state\n");
return retval;
}
@@ -540,7 +541,7 @@ extern GfxWidget *debug_widgets[];
extern int debug_widget_pos;
static int c_gfx_print_widget(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- if (!_debugstate_valid) {
+ if (!g_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
}
@@ -695,9 +696,9 @@ static int c_disasm(EngineState *s, const Common::Array<cmd_param_t> &cmdParams)
}
static int c_sg(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- _debug_seeking = _DEBUG_SEEK_GLOBAL;
- _debug_seek_special = cmdParams[0].val;
- _debugstate_valid = 0;
+ g_debug_seeking = _DEBUG_SEEK_GLOBAL;
+ s_debug_seek_special = cmdParams[0].val;
+ g_debugstate_valid = 0;
return 0;
}
@@ -706,7 +707,7 @@ static int c_snk(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
int callk_index;
char *endptr;
- if (!_debugstate_valid) {
+ if (!g_debugstate_valid) {
sciprintf("Not in debug state\n");
return 1;
}
@@ -730,27 +731,27 @@ static int c_snk(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
}
}
- _debug_seeking = _DEBUG_SEEK_SPECIAL_CALLK;
- _debug_seek_special = callk_index;
- _debugstate_valid = 0;
+ g_debug_seeking = _DEBUG_SEEK_SPECIAL_CALLK;
+ s_debug_seek_special = callk_index;
+ g_debugstate_valid = 0;
} else {
- _debug_seeking = _DEBUG_SEEK_CALLK;
- _debugstate_valid = 0;
+ g_debug_seeking = _DEBUG_SEEK_CALLK;
+ g_debugstate_valid = 0;
}
return 0;
}
static int c_sret(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- _debug_seeking = _DEBUG_SEEK_LEVEL_RET;
- _debug_seek_level = s->_executionStack.size()-1;
- _debugstate_valid = 0;
+ g_debug_seeking = _DEBUG_SEEK_LEVEL_RET;
+ s_debug_seek_level = s->_executionStack.size()-1;
+ g_debugstate_valid = 0;
return 0;
}
static int c_go(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- _debug_seeking = 0;
- _debugstate_valid = 0;
+ g_debug_seeking = 0;
+ g_debugstate_valid = 0;
return 0;
}
@@ -899,8 +900,8 @@ static void viewobjinfo(EngineState *s, HeapPtr pos) {
// Breakpoint commands
int c_se(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- stop_on_event = 1;
- _debugstate_valid = 0;
+ g_stop_on_event = 1;
+ g_debugstate_valid = 0;
return 0;
}
@@ -909,7 +910,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 = _debugstate_valid;
+ int old_debugstate = g_debugstate_valid;
p_var_segs = segids;
p_vars = variables;
@@ -921,15 +922,15 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
p_objp = objp;
p_restadjust = restadjust;
sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
- _debugstate_valid = 1;
+ g_debugstate_valid = 1;
disassemble(s, *pc, 0, 1);
- if (_debug_seeking == _DEBUG_SEEK_GLOBAL)
- sciprintf("Global %d (0x%x) = %04x:%04x\n", _debug_seek_special,
- _debug_seek_special, PRINT_REG(s->script_000->locals_block->_locals[_debug_seek_special]));
+ if (g_debug_seeking == _DEBUG_SEEK_GLOBAL)
+ sciprintf("Global %d (0x%x) = %04x:%04x\n", s_debug_seek_special,
+ s_debug_seek_special, PRINT_REG(s->script_000->locals_block->_locals[s_debug_seek_special]));
- _debugstate_valid = old_debugstate;
+ g_debugstate_valid = old_debugstate;
- if (_debug_seeking && !bp) { // Are we looking for something special?
+ if (g_debug_seeking && !bp) { // Are we looking for something special?
MemObject *mobj = GET_SEGMENT(*s->seg_manager, pc->segment, MEM_OBJ_SCRIPT);
if (mobj) {
@@ -941,9 +942,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 (_debug_seeking) {
+ switch (g_debug_seeking) {
case _DEBUG_SEEK_SPECIAL_CALLK:
- if (paramb1 != _debug_seek_special)
+ if (paramb1 != s_debug_seek_special)
return;
case _DEBUG_SEEK_CALLK: {
@@ -953,13 +954,13 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
}
case _DEBUG_SEEK_LEVEL_RET: {
- if ((op != op_ret) || (_debug_seek_level < (int)s->_executionStack.size()-1))
+ if ((op != op_ret) || (s_debug_seek_level < (int)s->_executionStack.size()-1))
return;
break;
}
case _DEBUG_SEEK_SO:
- if ((*pc != _debug_seek_reg) || (int)s->_executionStack.size()-1 != _debug_seek_level)
+ if ((*pc != s_debug_seek_reg) || (int)s->_executionStack.size()-1 != s_debug_seek_level)
return;
break;
@@ -971,20 +972,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 != _debug_seek_special)
+ if (paramf1 != s_debug_seek_special)
return; // CORRECT global?
break;
}
- _debug_seeking = _DEBUG_SEEK_NOTHING;
+ g_debug_seeking = _DEBUG_SEEK_NOTHING;
// OK, found whatever we were looking for
}
}
- _debugstate_valid = (_debug_step_running == 0);
+ g_debugstate_valid = (g_debug_step_running == 0);
- if (_debugstate_valid) {
+ if (g_debugstate_valid) {
p_pc = pc;
p_sp = sp;
p_pp = pp;
@@ -998,8 +999,8 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
sciprintf("Step #%d\n", script_step_counter);
disassemble(s, *pc, 0, 1);
- if (_debug_commands_not_hooked) {
- _debug_commands_not_hooked = 0;
+ if (!s_debug_commands_hooked) {
+ s_debug_commands_hooked = true;
con_hook_command(c_step, "s", "i*", "Executes one or several operations\n\nEXAMPLES\n\n"
" s 4\n\n Execute 4 commands\n\n s\n\n Execute next command");
@@ -1043,10 +1044,10 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
} // If commands were not hooked up
}
- if (_debug_step_running)
- _debug_step_running--;
+ if (g_debug_step_running)
+ g_debug_step_running--;
- while (_debugstate_valid) {
+ while (g_debugstate_valid) {
int skipfirst = 0;
const char *commandstring;
diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp
index 3539032760..345dcc5b9f 100644
--- a/engines/sci/engine/vm.cpp
+++ b/engines/sci/engine/vm.cpp
@@ -27,7 +27,7 @@
#include "common/stack.h"
#include "sci/sci.h"
-#include "sci/console.h" // for debug_weak_validations
+#include "sci/debug.h" // for g_debug_weak_validations
#include "sci/resource.h"
#include "sci/engine/state.h"
#include "sci/engine/intmap.h"
@@ -46,17 +46,13 @@ reg_t NULL_REG = {0, 0};
#undef STRICT_READ // Disallows reading from out-of-bounds parameters and locals
-int script_abort_flag = 0; // Set to 1 to abort execution
-int script_step_counter = 0; // Counts the number of steps executed
-int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs
+int script_abort_flag = 0; // Set to 1 to abort execution // 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 int _debug_step_running;
-extern int _debug_seeking;
-extern bool debug_weak_validations;
-
-static bool breakpointFlag = false;
-static reg_t _dummy_register;
+static bool breakpointFlag = false; // FIXME: Avoid non-const global vars
+static reg_t _dummy_register; // FIXME: Avoid non-const global vars
// validation functionality
@@ -90,7 +86,7 @@ static StackPtr validate_stack_addr(EngineState *s, StackPtr sp) {
static int validate_arithmetic(reg_t reg) {
if (reg.segment) {
- if (debug_weak_validations)
+ if (g_debug_weak_validations)
warning("[VM] Attempt to read arithmetic value from non-zero segment [%04x]\n", reg.segment);
else
error("[VM] Attempt to read arithmetic value from non-zero segment [%04x]\n", reg.segment);
@@ -102,7 +98,7 @@ static int validate_arithmetic(reg_t reg) {
static int signed_validate_arithmetic(reg_t reg) {
if (reg.segment) {
- if (debug_weak_validations)
+ if (g_debug_weak_validations)
warning("[VM] Attempt to read arithmetic value from non-zero segment [%04x]\n", reg.segment);
else
error("[VM] Attempt to read arithmetic value from non-zero segment [%04x]\n", reg.segment);
@@ -129,7 +125,7 @@ static int validate_variable(reg_t *r, reg_t *stack_base, int type, int max, int
strcat(txt, tmp);
}
- if (debug_weak_validations)
+ if (g_debug_weak_validations)
warning(txt);
else
error(txt);
@@ -400,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
- _debug_seeking = _debug_step_running = 0;
+ g_debug_seeking = g_debug_step_running = 0;
#endif
}
break;
@@ -1431,8 +1427,8 @@ void run_vm(EngineState *s, int restoring) {
#if 0
if (script_error_flag) {
- _debug_step_running = 0; // Stop multiple execution
- _debug_seeking = 0; // Stop special seeks
+ g_debug_step_running = 0; // Stop multiple execution
+ g_debug_seeking = 0; // Stop special seeks
xs->addr.pc.offset = old_pc_offset;
xs->sp = old_sp;
} else
@@ -2065,9 +2061,9 @@ const char *obj_get_name(EngineState *s, reg_t pos) {
void quit_vm() {
script_abort_flag = 1; // Terminate VM
- _debugstate_valid = 0;
- _debug_seeking = 0;
- _debug_step_running = 0;
+ g_debugstate_valid = 0;
+ g_debug_seeking = 0;
+ g_debug_step_running = 0;
}
void shrink_execution_stack(EngineState *s, uint size) {
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index 84e6cc4923..d7703e371e 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -806,11 +806,6 @@ extern int script_gc_interval;
extern int script_step_counter;
-extern int _debugstate_valid;
-extern int _debug_seeking;
-extern int _debug_step_running;
-
-
typedef int kernel_function(struct EngineState *s);
extern kernel_function* kfuncs[];