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.
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"
44 DECLARE_SINGLETON(Debugger
);
47 : _stepOpcodes(false),
48 _breakOnClickHandler(false),
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));
63 void Debugger::setEngine(Engine
*vm
) {
65 DVar_Register("currentRoom", &(_vm
->logic()->_currentRoom
), DVAR_INT
);
68 Logic
*Debugger::logic() const {
72 #define CMD(x) bool Debugger::cmd_##x(int argc, const char **argv)
76 Log
.getActor(atoi(argv
[1]))->toggleDebug();
77 DebugPrintf("Toggled debugging on actor %d. Remember to toggle proper levels, too!\n");
79 DebugPrintf("Syntax: debugActor <id>\n");
85 if (!strcmp(argv
[1], "click")) {
86 DebugPrintf("Will break execution on click handler.\n");
87 _breakOnClickHandler
= true;
90 DebugPrintf("Syntax: break <event> (events are: click)\n");
94 void Debugger::clickHandler() {
95 if (_breakOnClickHandler
) {
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
);
116 DebugPrintf("Syntax: break <event> (events are: click)\n");
121 EventManager::instance().toggleDebug();
126 DebugPrintf("Room exits:\n");
127 foreach (Exit
*, logic()->room()->exits())
128 DebugPrintf(" %s\n", +(**it
));
133 bool Debugger::cmd_setBackdrop(int argc
, const char **argv
) {
135 _vm
->graphics()->setBackdrop(atoi(argv
[1]));
136 _vm
->graphics()->paintBackdrop();
138 DebugPrintf("Syntax: set_backdrop <index>\n");
143 bool Debugger::cmd_paintText(int argc
, const char **argv
) {
149 left
= atoi(argv
[2]);
152 colour
= atoi(argv
[4]);
154 _vm
->graphics()->paintText(left
, top
, colour
, const_cast<byte
*>(reinterpret_cast<const byte
*>(argv
[1])));
156 DebugPrintf("Syntax: paint_text <text> [<left> <top> [<colour>]]\n");
161 bool Debugger::cmd_paintSprite(int argc
, const char **argv
) {
163 int sprite
= atoi(argv
[1]);
167 left
= atoi(argv
[2]);
170 Sprite
*s
= _vm
->resources()->loadSprite(sprite
);
171 _vm
->graphics()->paint(s
, Common::Point(left
, top
));
172 _vm
->graphics()->updateScreen();
174 DebugPrintf("Syntax: paintSprite <text> [<left> <top>]\n");
179 } // End of namespace Innocent