2001-10-23 19:51:50 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
|
|
|
*
|
|
|
|
* 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.
|
2001-11-19 00:04:34 +00:00
|
|
|
*
|
2001-10-23 19:51:50 +00:00
|
|
|
* 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.
|
2001-11-19 00:04:34 +00:00
|
|
|
*
|
2001-10-23 19:51:50 +00:00
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-23 19:51:50 +00:00
|
|
|
*/
|
|
|
|
|
2001-11-19 00:04:34 +00:00
|
|
|
/*
|
|
|
|
* Readline and command completion support by Tom Dunstan <tommyd@senet.com.au>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-02-19 18:04:21 +00:00
|
|
|
|
|
|
|
|
2001-10-23 19:51:50 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "scumm.h"
|
|
|
|
|
2001-11-19 00:04:34 +00:00
|
|
|
#ifdef HAVE_READLINE
|
|
|
|
#include "debugrl.h"
|
|
|
|
#endif
|
2001-10-23 19:51:50 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CMD_INVALID,
|
|
|
|
CMD_HELP,
|
|
|
|
CMD_QUIT,
|
|
|
|
CMD_GO,
|
2001-10-26 17:34:50 +00:00
|
|
|
CMD_ACTOR,
|
|
|
|
CMD_SCRIPTS,
|
2001-12-27 17:51:58 +00:00
|
|
|
CMD_LOAD_ROOM,
|
2002-03-06 10:03:00 +00:00
|
|
|
CMD_DUMPBOX,
|
|
|
|
CMD_VAR,
|
|
|
|
CMD_WATCH,
|
2001-11-07 18:10:52 +00:00
|
|
|
CMD_EXIT
|
2001-10-23 19:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ScummDebugger::attach(Scumm *s) {
|
|
|
|
if (_s)
|
2001-10-23 19:56:57 +00:00
|
|
|
detach();
|
2001-10-23 19:51:50 +00:00
|
|
|
|
|
|
|
_welcome = true;
|
|
|
|
_s = s;
|
|
|
|
s->_debugger = this;
|
|
|
|
|
|
|
|
_go_amount = 1;
|
2001-11-19 00:04:34 +00:00
|
|
|
#ifdef HAVE_READLINE
|
|
|
|
initialize_readline();
|
|
|
|
#endif
|
2001-10-23 19:51:50 +00:00
|
|
|
}
|
|
|
|
|
2002-02-19 18:04:21 +00:00
|
|
|
void BoxTest(int num);
|
2001-10-23 19:51:50 +00:00
|
|
|
bool ScummDebugger::do_command() {
|
|
|
|
switch(get_command()) {
|
|
|
|
case CMD_HELP:
|
2001-11-07 18:10:52 +00:00
|
|
|
printf(
|
|
|
|
"Debugger commands:\n"
|
|
|
|
"(h)elp -> display this help text\n"
|
|
|
|
"(q)uit -> quit the debugger\n"
|
|
|
|
"(g)o [numframes] -> increase frame\n"
|
|
|
|
"(a)ctor [actornum] -> show actor information\n"
|
2001-12-27 17:51:58 +00:00
|
|
|
"(r)oom roomnum -> load room\n"
|
2001-11-07 18:10:52 +00:00
|
|
|
"(s)cripts -> show running scripts\n"
|
2002-03-08 13:31:29 +00:00
|
|
|
"(b)oxes -> list and draw boxen\n"
|
|
|
|
"(w)atch [varnum] -> set a variable watch. 0 means all variables.\n"
|
2001-11-07 18:10:52 +00:00
|
|
|
"(e)xit -> exit game\n"
|
2001-10-23 19:51:50 +00:00
|
|
|
);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case CMD_QUIT:
|
|
|
|
detach();
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case CMD_GO:
|
|
|
|
if (!_parameters[0])
|
|
|
|
_go_amount = 1;
|
|
|
|
else
|
|
|
|
_go_amount = atoi(_parameters);
|
|
|
|
return false;
|
2001-10-26 17:34:50 +00:00
|
|
|
case CMD_ACTOR:
|
|
|
|
if (!_parameters[0])
|
|
|
|
printActors(-1);
|
|
|
|
else
|
|
|
|
printActors(atoi(_parameters));
|
|
|
|
return true;
|
|
|
|
case CMD_SCRIPTS:
|
|
|
|
printScripts();
|
|
|
|
return true;
|
2001-12-27 17:51:58 +00:00
|
|
|
case CMD_LOAD_ROOM:
|
|
|
|
if (!_parameters[0]) {
|
|
|
|
printf("Enter a room number...\n");
|
|
|
|
} else {
|
|
|
|
int room=atoi(_parameters);
|
2002-02-23 23:23:28 +00:00
|
|
|
_s->actor[_s->_vars[_s->VAR_EGO]].room=room;
|
2001-12-27 17:51:58 +00:00
|
|
|
_s->startScene(room, 0, 0);
|
|
|
|
_s->_fullRedraw = 1;
|
|
|
|
}
|
|
|
|
return true;
|
2002-02-19 18:04:21 +00:00
|
|
|
case CMD_DUMPBOX:
|
|
|
|
{
|
2002-03-08 08:27:45 +00:00
|
|
|
int num, i = 0, rows = 0;
|
|
|
|
BoxCoords box;
|
|
|
|
byte *boxm = _s->getBoxMatrixBaseAddr();
|
|
|
|
num = _s->getNumBoxes();
|
|
|
|
|
|
|
|
printf("Walk matrix:\n");
|
|
|
|
while (*boxm != 0xFF) {
|
|
|
|
printf("%d ", *boxm);
|
|
|
|
i++; *boxm++;
|
|
|
|
if (i >= num) {i = 0; rows++; printf("\n");}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows < num)
|
|
|
|
printf("\nERROR: Box Matrix invalid, missing or incomplete: %d row(s)", num - rows);
|
|
|
|
|
|
|
|
printf("\nWalk boxes:\n");
|
|
|
|
for (i=0; i<num; i++) {
|
2002-02-19 18:04:21 +00:00
|
|
|
BoxTest(i);
|
|
|
|
_s->getBoxCoordinates(i, &box);
|
|
|
|
printf("%d: [%d x %d] [%d x %d] [%d x %d] [%d x %d]\n", i,
|
2002-03-08 08:27:45 +00:00
|
|
|
box.ul.x, box.ul.y, box.ll.x, box.ll.y,
|
|
|
|
box.ur.x, box.ur.y, box.lr.x, box.lr.y);
|
2002-02-19 18:04:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2002-03-06 10:03:00 +00:00
|
|
|
case CMD_VAR:
|
|
|
|
if (!_parameters[0]) {
|
|
|
|
printf("Enter a variable\n");
|
|
|
|
} else {
|
|
|
|
char *tok = strtok(_parameters, " ");
|
|
|
|
int var = atoi(tok);
|
|
|
|
tok = strtok(NULL, "");
|
|
|
|
if (tok)
|
|
|
|
_s->writeVar(var, atoi(tok));
|
|
|
|
|
|
|
|
printf("Var[%d] = %d\n", var, _s->readVar(var));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case CMD_WATCH:
|
|
|
|
if (!_parameters[0]) {
|
|
|
|
printf("Clearing all watches..\n");
|
|
|
|
_s->_varwatch = -1;
|
|
|
|
} else {
|
|
|
|
_s->_varwatch = atoi(_parameters);
|
|
|
|
if (_s->_varwatch == 0)
|
|
|
|
printf("Watching all variables\n");
|
|
|
|
else
|
|
|
|
printf("Watching vars[%d]\n", _s->_varwatch);
|
|
|
|
}
|
|
|
|
return true;
|
2001-11-07 18:10:52 +00:00
|
|
|
case CMD_EXIT:
|
|
|
|
exit(1);
|
2002-02-24 17:25:03 +00:00
|
|
|
|
|
|
|
default: /* this line is never reached */
|
|
|
|
error("Unknown debug command");
|
2002-03-06 12:24:56 +00:00
|
|
|
return true;
|
2001-10-23 19:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScummDebugger::enter() {
|
|
|
|
if (_welcome) {
|
|
|
|
_welcome = false;
|
|
|
|
printf("Debugging Mode entered!, please switch to this console for input.\n"
|
|
|
|
"Enter h to list all the debug commands\n");
|
|
|
|
}
|
|
|
|
while(do_command()) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScummDebugger::on_frame() {
|
|
|
|
if (_go_amount==0)
|
|
|
|
return;
|
|
|
|
if (!--_go_amount)
|
|
|
|
enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScummDebugger::detach() {
|
|
|
|
_s->_debugger = NULL;
|
|
|
|
_s = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DebuggerCommands {
|
|
|
|
char text[8];
|
|
|
|
byte len;
|
|
|
|
byte id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const DebuggerCommands debugger_commands[] = {
|
|
|
|
{ "h", 1, CMD_HELP },
|
|
|
|
{ "q", 1, CMD_QUIT },
|
|
|
|
{ "g", 1, CMD_GO },
|
2001-10-26 17:34:50 +00:00
|
|
|
{ "a", 1, CMD_ACTOR },
|
|
|
|
{ "s", 1, CMD_SCRIPTS },
|
2001-12-27 17:51:58 +00:00
|
|
|
{ "r", 1, CMD_LOAD_ROOM },
|
2002-03-06 10:03:00 +00:00
|
|
|
{ "b", 1, CMD_DUMPBOX},
|
|
|
|
{ "v", 1, CMD_VAR},
|
|
|
|
{ "w", 1, CMD_WATCH},
|
2001-11-07 18:10:52 +00:00
|
|
|
{ "e", 1, CMD_EXIT },
|
2001-10-23 19:51:50 +00:00
|
|
|
{ 0, 0, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
int ScummDebugger::get_command() {
|
|
|
|
const DebuggerCommands *dc;
|
|
|
|
char *s;
|
|
|
|
int i;
|
2001-11-19 00:04:34 +00:00
|
|
|
static char *buf;
|
2001-10-23 19:51:50 +00:00
|
|
|
|
|
|
|
do {
|
2001-11-19 00:04:34 +00:00
|
|
|
#ifndef HAVE_READLINE
|
|
|
|
buf = _cmd_buffer;
|
2001-10-23 19:51:50 +00:00
|
|
|
printf("debug> ");
|
|
|
|
if (!fgets(_cmd_buffer, sizeof(_cmd_buffer), stdin))
|
|
|
|
return CMD_QUIT;
|
|
|
|
|
|
|
|
i = strlen(_cmd_buffer);
|
|
|
|
while (i>0 && _cmd_buffer[i-1]==10)
|
|
|
|
_cmd_buffer[--i] = 0;
|
|
|
|
|
|
|
|
if (i==0)
|
|
|
|
continue;
|
2001-11-19 00:04:34 +00:00
|
|
|
|
|
|
|
#else // yes we do have readline
|
|
|
|
if(buf) {
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
buf = readline("debug> ");
|
|
|
|
if(!buf) {
|
|
|
|
printf("\n");
|
|
|
|
return CMD_QUIT;
|
|
|
|
}
|
|
|
|
if(strlen(buf) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
add_history(buf);
|
|
|
|
#endif
|
|
|
|
|
2001-10-23 19:51:50 +00:00
|
|
|
dc = debugger_commands;
|
|
|
|
do {
|
2001-11-19 00:04:34 +00:00
|
|
|
if (!strncmp(buf, dc->text, dc->len)) {
|
|
|
|
for(s=buf;*s;s++) {
|
2001-10-23 19:51:50 +00:00
|
|
|
if (*s==32) { s++; break; }
|
|
|
|
}
|
|
|
|
_parameters = s;
|
|
|
|
return _command = dc->id;
|
|
|
|
}
|
|
|
|
} while ((++dc)->text[0]);
|
|
|
|
|
2001-11-19 00:04:34 +00:00
|
|
|
for(s=buf;*s;s++)
|
2001-10-23 19:51:50 +00:00
|
|
|
if (*s==32) { *s=0; break; }
|
2001-11-19 00:04:34 +00:00
|
|
|
printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", buf);
|
2001-10-23 19:51:50 +00:00
|
|
|
} while (1);
|
2001-10-26 17:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScummDebugger::printActors(int act) {
|
|
|
|
int i;
|
|
|
|
Actor *a;
|
|
|
|
|
2001-11-07 18:10:52 +00:00
|
|
|
printf("+--------------------------------------------------------------+\n");
|
|
|
|
printf("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n");
|
|
|
|
printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n");
|
2001-11-10 19:12:32 +00:00
|
|
|
for(i=1; i<NUM_ACTORS; i++) {
|
2001-11-07 18:10:52 +00:00
|
|
|
if (act==-1 || act==i) {
|
2001-10-26 17:34:50 +00:00
|
|
|
a = &_s->actor[i];
|
|
|
|
if (a->visible)
|
|
|
|
printf("|%2d|%4d|%3d %3d|%4d|%3d|%5d|%3d|%3d|%2d|%5d|%5d|%3d|%3d|\n",
|
2001-11-27 17:56:04 +00:00
|
|
|
i,a->room,a->x,a->y,a->elevation,a->costume,a->width,a->walkbox,a->moving,a->forceClip,a->frame,a->scalex,a->speedx,a->facing);
|
2001-10-26 17:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-07 18:10:52 +00:00
|
|
|
printf("+--------------------------------------------------------------+\n");
|
2001-10-26 17:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScummDebugger::printScripts() {
|
|
|
|
int i;
|
|
|
|
ScriptSlot *ss;
|
|
|
|
|
|
|
|
printf("+---------------------------------+\n");
|
|
|
|
printf("|# |num|sta|typ|un1|un2|fc|cut|un5|\n");
|
|
|
|
printf("+--+---+---+---+---+---+--+---+---+\n");
|
|
|
|
for(i=0; i<25; i++) {
|
|
|
|
ss = &_s->vm.slot[i];
|
|
|
|
if (ss->number) {
|
|
|
|
printf("|%2d|%3d|%3d|%3d|%3d|%3d|%2d|%3d|%3d|\n",
|
2001-11-12 20:50:36 +00:00
|
|
|
i, ss->number, ss->status, ss->where, ss->unk1, ss->unk2, ss->freezeCount, ss->cutsceneOverride, ss->unk5);
|
2001-10-26 17:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("+---------------------------------+\n");
|
2001-11-19 00:04:34 +00:00
|
|
|
}
|