More meaningful exit debug messages.
[scummvm-innocent.git] / engines / innocent / debugger.cpp
blob592c91dbbe534c2bc195520be5f05fc2b3a1ddf3
1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 #include "innocent/debugger.h"
28 #include "common/endian.h"
29 #include "common/rect.h"
31 #include "innocent/actor.h"
32 #include "innocent/exit.h"
33 #include "innocent/eventmanager.h"
34 #include "innocent/graphics.h"
35 #include "innocent/innocent.h"
36 #include "innocent/logic.h"
37 #include "innocent/resources.h"
38 #include "innocent/room.h"
39 #include "innocent/util.h"
41 namespace Innocent {
44 DECLARE_SINGLETON(Debugger);
46 Debugger::Debugger()
47 : _stepOpcodes(false),
48 _breakOnClickHandler(false),
49 _vm(0) {
50 DCmd_Register("setBackdrop", WRAP_METHOD(Debugger, cmd_setBackdrop));
51 DCmd_Register("paintText", WRAP_METHOD(Debugger, cmd_paintText));
52 DCmd_Register("listExits", WRAP_METHOD(Debugger, cmd_listExits));
53 DCmd_Register("showClickable", WRAP_METHOD(Debugger, cmd_showClickable));
54 DCmd_Register("paintSprite", WRAP_METHOD(Debugger, cmd_paintSprite));
55 DCmd_Register("break", WRAP_METHOD(Debugger, cmd_break));
56 DCmd_Register("step", WRAP_METHOD(Debugger, cmd_step));
57 DCmd_Register("setVar", WRAP_METHOD(Debugger, cmd_setVar));
58 #define CMD(x) DCmd_Register(#x, WRAP_METHOD(Debugger, cmd_##x));
59 CMD(debugActor);
60 #undef CMD
63 void Debugger::setEngine(Engine *vm) {
64 _vm = vm;
65 DVar_Register("currentRoom", &(_vm->logic()->_currentRoom), DVAR_INT);
68 Logic *Debugger::logic() const {
69 return _vm->logic();
72 #define CMD(x) bool Debugger::cmd_##x(int argc, const char **argv)
74 CMD(debugActor) {
75 if (argc == 2) {
76 Log.getActor(atoi(argv[1]))->toggleDebug();
77 DebugPrintf("Toggled debugging on actor %d. Remember to toggle proper levels, too!\n");
78 } else
79 DebugPrintf("Syntax: debugActor <id>\n");
80 return true;
83 CMD(break) {
84 if (argc == 2) {
85 if (!strcmp(argv[1], "click")) {
86 DebugPrintf("Will break execution on click handler.\n");
87 _breakOnClickHandler = true;
89 } else
90 DebugPrintf("Syntax: break <event> (events are: click)\n");
91 return true;
94 void Debugger::clickHandler() {
95 if (_breakOnClickHandler) {
96 attach();
97 onFrame();
101 CMD(step) {
102 _stepOpcodes = true;
103 _detach_now = true;
104 return false;
107 CMD(setVar) {
108 if (argc == 4) {
109 if (!strcmp(argv[1], "word")) {
110 int var = atoi(argv[2]);
111 int val = atoi(argv[3]);
112 DebugPrintf("word[%d] = %d\n", var, val);
113 WRITE_LE_UINT16(_vm->resources()->getGlobalWordVariable(var), val);
115 } else
116 DebugPrintf("Syntax: break <event> (events are: click)\n");
117 return true;
120 CMD(showClickable) {
121 EventManager::instance().toggleDebug();
122 return true;
125 CMD(listExits) {
126 DebugPrintf("Room exits:\n");
127 foreach (Exit *, logic()->room()->exits())
128 DebugPrintf(" %s\n", +(**it));
129 DebugPrintf("\n");
130 return true;
133 bool Debugger::cmd_setBackdrop(int argc, const char **argv) {
134 if (argc == 2) {
135 _vm->graphics()->setBackdrop(atoi(argv[1]));
136 _vm->graphics()->paintBackdrop();
137 } else
138 DebugPrintf("Syntax: set_backdrop <index>\n");
140 return true;
143 bool Debugger::cmd_paintText(int argc, const char **argv) {
144 if (argc >= 2) {
145 int left = 10;
146 int top = 10;
147 byte colour = 235;
148 if (argc >= 4) {
149 left = atoi(argv[2]);
150 top = atoi(argv[3]);
151 if (argc >= 5)
152 colour = atoi(argv[4]);
154 _vm->graphics()->paintText(left, top, colour, const_cast<byte *>(reinterpret_cast<const byte *>(argv[1])));
155 } else
156 DebugPrintf("Syntax: paint_text <text> [<left> <top> [<colour>]]\n");
158 return true;
161 bool Debugger::cmd_paintSprite(int argc, const char **argv) {
162 if (argc >= 2) {
163 int sprite = atoi(argv[1]);
164 int left = 10;
165 int top = 10;
166 if (argc >= 4) {
167 left = atoi(argv[2]);
168 top = atoi(argv[3]);
170 Sprite *s = _vm->resources()->loadSprite(sprite);
171 _vm->graphics()->paint(s, Common::Point(left, top));
172 _vm->graphics()->updateScreen();
173 } else
174 DebugPrintf("Syntax: paintSprite <text> [<left> <top>]\n");
176 return true;
179 } // End of namespace Innocent