aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorFilippos Karapetis2009-06-06 16:43:13 +0000
committerFilippos Karapetis2009-06-06 16:43:13 +0000
commite572811aedc5141189d4c1db9069a9ad564f21dd (patch)
treeb76caa079239e8d749047e5dc680635a9ca18c0f /engines/sci/engine
parentcf194d7bb73fd6c4173dbe810c5219e8e4f42a4b (diff)
downloadscummvm-rg350-e572811aedc5141189d4c1db9069a9ad564f21dd.tar.gz
scummvm-rg350-e572811aedc5141189d4c1db9069a9ad564f21dd.tar.bz2
scummvm-rg350-e572811aedc5141189d4c1db9069a9ad564f21dd.zip
Moved some more debug commands to ScummVM's coneole
svn-id: r41227
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/game.cpp2
-rw-r--r--engines/sci/engine/grammar.cpp16
-rw-r--r--engines/sci/engine/kevent.cpp21
-rw-r--r--engines/sci/engine/kgraphics.cpp26
-rw-r--r--engines/sci/engine/said.cpp8
-rw-r--r--engines/sci/engine/scriptdebug.cpp164
6 files changed, 69 insertions, 168 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index bfd38f2c1b..5a250529cd 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -499,7 +499,7 @@ int game_init(EngineState *s) {
s->game_obj = game_obj;
// Mark parse tree as unused
- s->parser_nodes[0].type = PARSE_TREE_NODE_LEAF;
+ s->parser_nodes[0].type = kParseTreeLeafNode;
s->parser_nodes[0].content.value = 0;
s->_menubar = new Menubar(); // Create menu bar
diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp
index 2c035fcb53..275a31a0d4 100644
--- a/engines/sci/engine/grammar.cpp
+++ b/engines/sci/engine/grammar.cpp
@@ -414,7 +414,7 @@ parse_rule_list_t *Vocabulary::buildGNF(bool verbose) {
static int _vbpt_pareno(parse_tree_node_t *nodes, int *pos, int base) {
// Opens parentheses
nodes[base].content.branches[0] = (*pos) + 1;
- nodes[++(*pos)].type = PARSE_TREE_NODE_BRANCH;
+ nodes[++(*pos)].type = kParseTreeBranchNode;
nodes[*pos].content.branches[0] = 0;
nodes[*pos].content.branches[1] = 0;
return *pos;
@@ -423,7 +423,7 @@ static int _vbpt_pareno(parse_tree_node_t *nodes, int *pos, int base) {
static int _vbpt_parenc(parse_tree_node_t *nodes, int *pos, int paren) {
// Closes parentheses for appending
nodes[paren].content.branches[1] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
+ nodes[*pos].type = kParseTreeBranchNode;
nodes[*pos].content.branches[0] = 0;
nodes[*pos].content.branches[1] = 0;
return *pos;
@@ -432,10 +432,10 @@ static int _vbpt_parenc(parse_tree_node_t *nodes, int *pos, int paren) {
static int _vbpt_append(parse_tree_node_t *nodes, int *pos, int base, int value) {
// writes one value to an existing base node and creates a successor node for writing
nodes[base].content.branches[0] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_LEAF;
+ nodes[*pos].type = kParseTreeLeafNode;
nodes[*pos].content.value = value;
nodes[base].content.branches[1] = ++(*pos);
- nodes[*pos].type = PARSE_TREE_NODE_BRANCH;
+ nodes[*pos].type = kParseTreeBranchNode;
nodes[*pos].content.branches[0] = 0;
nodes[*pos].content.branches[1] = 0;
return *pos;
@@ -443,7 +443,7 @@ static int _vbpt_append(parse_tree_node_t *nodes, int *pos, int base, int value)
static int _vbpt_terminate(parse_tree_node_t *nodes, int *pos, int base, int value) {
// Terminates, overwriting a nextwrite forknode
- nodes[base].type = PARSE_TREE_NODE_LEAF;
+ nodes[base].type = kParseTreeLeafNode;
nodes[base].content.value = value;
return *pos;
}
@@ -554,14 +554,14 @@ int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words,
{
int temp, pos;
- nodes[0].type = PARSE_TREE_NODE_BRANCH;
+ nodes[0].type = kParseTreeBranchNode;
nodes[0].content.branches[0] = 1;
nodes[0].content.branches[1] = 2;
- nodes[1].type = PARSE_TREE_NODE_LEAF;
+ nodes[1].type = kParseTreeLeafNode;
nodes[1].content.value = 0x141;
- nodes[2].type = PARSE_TREE_NODE_BRANCH;
+ nodes[2].type = kParseTreeBranchNode;
nodes[2].content.branches[0] = 0;
nodes[2].content.branches[1] = 0;
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index 66395035c8..d6db12b2f8 100644
--- a/engines/sci/engine/kevent.cpp
+++ b/engines/sci/engine/kevent.cpp
@@ -139,6 +139,27 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
if ((s->r_acc.offset) && (g_stop_on_event)) {
g_stop_on_event = 0;
+
+ // A SCI event occured, and we have been asked to stop, so open the debug console
+ GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger();
+ con->DebugPrintf("SCI event occured: ");
+ switch (e.type) {
+ case SCI_EVT_QUIT:
+ con->DebugPrintf("quit event\n");
+ break;
+ case SCI_EVT_KEYBOARD:
+ con->DebugPrintf("keyboard event\n");
+ break;
+ case SCI_EVT_MOUSE_RELEASE:
+ case SCI_EVT_MOUSE_PRESS:
+ con->DebugPrintf("mouse click event\n");
+ break;
+ default:
+ con->DebugPrintf("unknown or no event (event type %d)\n", e.type);
+ }
+
+ con->attach();
+ con->onFrame();
}
return s->r_acc;
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 1f35f6ed04..994a4f7902 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -348,8 +348,8 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// Set pointer position, if requested
if (argc > 2) {
- Common::Point newpos = Common::Point(SKPV(2) + s->port->_bounds.x, SKPV(3) + s->port->_bounds.y);
- GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newpos));
+ Common::Point newPos = Common::Point(SKPV(2) + s->port->_bounds.x, SKPV(3) + s->port->_bounds.y);
+ GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newPos));
}
break;
case 3 :
@@ -370,26 +370,26 @@ reg_t kSetCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
}
reg_t kMoveCursor(EngineState *s, int funct_nr, int argc, reg_t *argv) {
- Common::Point newpos;
+ Common::Point newPos;
- newpos = s->gfx_state->pointer_pos;
+ newPos = s->gfx_state->pointer_pos;
if (argc == 1) {
// Case ignored on IBM PC
} else {
- newpos.x = SKPV(0) + s->port->zone.x;
- newpos.y = SKPV(1) + s->port->zone.y;
+ newPos.x = SKPV(0) + s->port->zone.x;
+ newPos.y = SKPV(1) + s->port->zone.y;
- if (newpos.x > s->port->zone.x + s->port->zone.width)
- newpos.x = s->port->zone.x + s->port->zone.width;
- if (newpos.y > s->port->zone.y + s->port->zone.height)
- newpos.y = s->port->zone.y + s->port->zone.height;
+ if (newPos.x > s->port->zone.x + s->port->zone.width)
+ newPos.x = s->port->zone.x + s->port->zone.width;
+ if (newPos.y > s->port->zone.y + s->port->zone.height)
+ newPos.y = s->port->zone.y + s->port->zone.height;
- if (newpos.x < 0) newpos.x = 0;
- if (newpos.y < 0) newpos.y = 0;
+ if (newPos.x < 0) newPos.x = 0;
+ if (newPos.y < 0) newPos.y = 0;
}
- GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newpos));
+ GFX_ASSERT(gfxop_set_pointer_position(s->gfx_state, newPos));
return s->r_acc;
}
diff --git a/engines/sci/engine/said.cpp b/engines/sci/engine/said.cpp
index 7d0467efa6..327231857e 100644
--- a/engines/sci/engine/said.cpp
+++ b/engines/sci/engine/said.cpp
@@ -1918,7 +1918,7 @@ static int said_next_node() {
#define SAID_NEXT_NODE said_next_node()
static int said_leaf_node(tree_t pos, int value) {
- said_tree[pos].type = PARSE_TREE_NODE_LEAF;
+ said_tree[pos].type = kParseTreeLeafNode;
if (value != VALUE_IGNORE)
said_tree[pos].content.value = value;
@@ -1927,7 +1927,7 @@ static int said_leaf_node(tree_t pos, int value) {
}
static int said_branch_node(tree_t pos, int left, int right) {
- said_tree[pos].type = PARSE_TREE_NODE_BRANCH;
+ said_tree[pos].type = kParseTreeBranchNode;
if (left != VALUE_IGNORE)
said_tree[pos].content.branches[0] = left;
@@ -2057,12 +2057,12 @@ static int said_parse_spec(EngineState *s, byte *spec) {
// primitive functions
#define AUG_READ_BRANCH(a, br, p) \
- if (tree[p].type != PARSE_TREE_NODE_BRANCH) \
+ if (tree[p].type != kParseTreeBranchNode) \
return 0; \
a = tree[p].content.branches[br];
#define AUG_READ_VALUE(a, p) \
- if (tree[p].type != PARSE_TREE_NODE_LEAF) \
+ if (tree[p].type != kParseTreeLeafNode) \
return 0; \
a = tree[p].content.value;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 64ab86a3e1..1e243fafc1 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -49,17 +49,7 @@ 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
-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)
-
-#define _DEBUG_SEEK_NOTHING 0
-#define _DEBUG_SEEK_CALLK 1 // Step forward until callk is found
-#define _DEBUG_SEEK_LEVEL_RET 2 // Step forward until returned from this level
-#define _DEBUG_SEEK_SPECIAL_CALLK 3 // Step forward until a /special/ callk is found
-#define _DEBUG_SEEK_SO 5 // Step forward until specified PC (after the send command) and stack depth
-#define _DEBUG_SEEK_GLOBAL 6 // Step forward until one specified global variable is modified
+extern int g_debug_seek_special;
static reg_t *p_pc;
static StackPtr *p_sp;
@@ -105,89 +95,6 @@ int c_step(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
return 0;
}
-enum {
- _parse_eoi,
- _parse_token_pareno,
- _parse_token_parenc,
- _parse_token_nil,
- _parse_token_number
-};
-
-int _parse_getinp(int *i, int *nr, const Common::Array<cmd_param_t> &cmdParams) {
- const char *token;
-
- if ((unsigned)*i == cmdParams.size())
- return _parse_eoi;
-
- token = cmdParams[(*i)++].str;
-
- if (!strcmp(token, "("))
- return _parse_token_pareno;
-
- if (!strcmp(token, ")"))
- return _parse_token_parenc;
-
- if (!strcmp(token, "nil"))
- return _parse_token_nil;
-
- *nr = strtol(token, NULL, 0);
-
- return _parse_token_number;
-}
-
-int _parse_nodes(EngineState *s, int *i, int *pos, int type, int nr, const Common::Array<cmd_param_t> &cmdParams) {
- int nexttk, nextval, newpos, oldpos;
-
- if (type == _parse_token_nil)
- return 0;
-
- if (type == _parse_token_number) {
- s->parser_nodes[*pos += 1].type = PARSE_TREE_NODE_LEAF;
- s->parser_nodes[*pos].content.value = nr;
- return *pos;
- }
- if (type == _parse_eoi) {
- sciprintf("Unbalanced parentheses\n");
- return -1;
- }
- if (type == _parse_token_parenc) {
- sciprintf("Syntax error at token %d\n", *i);
- return -1;
- }
- s->parser_nodes[oldpos = ++(*pos)].type = PARSE_TREE_NODE_BRANCH;
-
- nexttk = _parse_getinp(i, &nextval, cmdParams);
- if ((newpos = s->parser_nodes[oldpos].content.branches[0] = _parse_nodes(s, i, pos, nexttk, nextval, cmdParams)) == -1)
- return -1;
-
- nexttk = _parse_getinp(i, &nextval, cmdParams);
- if ((newpos = s->parser_nodes[oldpos].content.branches[1] = _parse_nodes(s, i, pos, nexttk, nextval, cmdParams)) == -1)
- return -1;
-
- if (_parse_getinp(i, &nextval, cmdParams) != _parse_token_parenc)
- sciprintf("Expected ')' at token %d\n", *i);
-
- return oldpos;
-}
-
-int c_set_parse_nodes(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- int i = 0;
- int foo, bar;
- int pos = -1;
-
- if (!s) {
- sciprintf("Not in debug state\n");
- return 1;
- }
-
- bar = _parse_getinp(&i, &foo, cmdParams);
- if (_parse_nodes(s, &i, &pos, bar, foo, cmdParams) == -1)
- return 1;
-
- vocab_dump_parse_tree("debug-parse-tree", s->parser_nodes);
- return 0;
-}
-
extern const char *selector_name(EngineState *s, int selector);
int prop_ofs_to_id(EngineState *s, int prop_ofs, reg_t objp) {
@@ -528,15 +435,10 @@ static int c_disasm(EngineState *s, const Common::Array<cmd_param_t> &cmdParams)
return 0;
}
-static int c_sg(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- g_debug_seeking = _DEBUG_SEEK_GLOBAL;
- s_debug_seek_special = cmdParams[0].val;
- g_debugstate_valid = 0;
-
- return 0;
-}
-
static int c_snk(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
+// TODO: disabled till this is moved in console.cpp
+#if 0
+
int callk_index;
char *endptr;
@@ -564,24 +466,18 @@ static int c_snk(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
}
}
- g_debug_seeking = _DEBUG_SEEK_SPECIAL_CALLK;
- s_debug_seek_special = callk_index;
+ g_debug_seeking = kDebugSeekSpecialCallk;
+ g_debug_seek_special = callk_index;
g_debugstate_valid = 0;
} else {
- g_debug_seeking = _DEBUG_SEEK_CALLK;
+ g_debug_seeking = kDebugSeekCallk;
g_debugstate_valid = 0;
}
+#endif
return 0;
}
-static int c_sret(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- 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) {
g_debug_seeking = 0;
g_debugstate_valid = 0;
@@ -645,15 +541,10 @@ static int c_send(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
// Breakpoint commands
-int c_se(EngineState *s, const Common::Array<cmd_param_t> &cmdParams) {
- g_stop_on_event = 1;
- g_debugstate_valid = 0;
-
- return 0;
-}
-
void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *objp, int *restadjust,
SegmentId *segids, reg_t **variables, reg_t **variables_base, int *variables_nr, int bp) {
+// TODO: disabled till this is moved in console.cpp
+#if 0
// Do we support a separate console?
int old_debugstate = g_debugstate_valid;
@@ -670,9 +561,9 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
sciprintf("%d: acc=%04x:%04x ", script_step_counter, PRINT_REG(s->r_acc));
g_debugstate_valid = 1;
disassemble(s, *pc, 0, 1);
- 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]));
+ 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]));
g_debugstate_valid = old_debugstate;
@@ -689,39 +580,40 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
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) {
- case _DEBUG_SEEK_SPECIAL_CALLK:
- if (paramb1 != s_debug_seek_special)
+ case kDebugSeekSpecialCallk:
+ if (paramb1 != g_debug_seek_special)
return;
- case _DEBUG_SEEK_CALLK: {
+ case kDebugSeekCallk: {
if (op != op_callk)
return;
break;
}
- case _DEBUG_SEEK_LEVEL_RET: {
- if ((op != op_ret) || (s_debug_seek_level < (int)s->_executionStack.size()-1))
+ case kDebugSeekLevelRet: {
+ if ((op != op_ret) || (g_debug_seek_level < (int)s->_executionStack.size()-1))
return;
break;
}
- case _DEBUG_SEEK_GLOBAL:
+ case kDebugSeekGlobal:
if (op < op_sag)
return;
if ((op & 0x3) > 1)
return; // param or temp
if ((op & 0x3) && s->_executionStack.back().local_segment > 0)
return; // locals and not running in script.000
- if (paramf1 != s_debug_seek_special)
+ if (paramf1 != g_debug_seek_special)
return; // CORRECT global?
break;
}
- g_debug_seeking = _DEBUG_SEEK_NOTHING;
+ g_debug_seeking = kDebugSeekNothing;
// OK, found whatever we were looking for
}
}
+#endif
g_debugstate_valid = (g_debug_step_running == 0);
@@ -739,9 +631,6 @@ 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 (!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");
con_hook_command(c_disasm_addr, "disasm-addr", "!as*", "Disassembles one or more commands\n\n"
@@ -753,17 +642,8 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t *
con_hook_command(c_disasm, "disasm", "!as", "Disassembles a method by name\n\nUSAGE\n\n disasm <obj> <method>\n\n");
con_hook_command(c_snk, "snk", "s*", "Steps forward until it hits the next\n callk operation.\n"
" If invoked with a parameter, it will\n look for that specific callk.\n");
- con_hook_command(c_se, "se", "", "Steps forward until an SCI event is received.\n");
con_hook_command(c_send, "send", "!asa*", "Sends a message to an object\nExample: send ?fooScript cue");
- con_hook_command(c_sret, "sret", "", "Steps forward until ret is called\n on the current execution stack\n level.");
con_hook_command(c_go, "go", "", "Executes the script.\n");
- con_hook_command(c_set_parse_nodes, "set_parse_nodes", "s*", "Sets the contents of all parse nodes.\n"
- " Input token must be separated by\n blanks.");
- con_hook_command(c_sg, "sg", "!i",
- "Steps until the global variable with the\n"
- "specified index is modified.\n\nSEE ALSO\n\n"
- " s.1, snk.1, so.1, bpx.1");
- } // If commands were not hooked up
}
if (g_debug_step_running)