From cf6bc0e438e5a21fb053c4ccd562d6bed8c4b68d Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Fri, 1 Apr 2016 00:13:21 +0200 Subject: ADL: Add script dump and trace for hires2 --- engines/adl/adl.cpp | 28 ++-------------------------- engines/adl/adl.h | 28 ++++++++++++++++++++++++++++ engines/adl/adl_v2.cpp | 23 +++++++++++++++++++++++ engines/adl/adl_v2.h | 2 -- engines/adl/console.cpp | 13 +++++++++++++ engines/adl/console.h | 1 - 6 files changed, 66 insertions(+), 29 deletions(-) (limited to 'engines/adl') diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 038d4ec10a..0c27f8b76f 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -22,7 +22,6 @@ #include "common/scummsys.h" #include "common/config-manager.h" -#include "common/debug-channels.h" #include "common/debug.h" #include "common/error.h" #include "common/file.h" @@ -896,31 +895,6 @@ bool AdlEngine::op_debug(const char *fmt, ...) const { return false; } -#define OP_DEBUG_0(F) do { \ - if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F)) \ - return 0; \ -} while (0) - -#define OP_DEBUG_1(F, P1) do { \ - if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1)) \ - return 1; \ -} while (0) - -#define OP_DEBUG_2(F, P1, P2) do { \ - if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2)) \ - return 2; \ -} while (0) - -#define OP_DEBUG_3(F, P1, P2, P3) do { \ - if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3)) \ - return 3; \ -} while (0) - -#define OP_DEBUG_4(F, P1, P2, P3, P4) do { \ - if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3, P4)) \ - return 4; \ -} while (0) - int AdlEngine::o1_isItemInRoom(ScriptEnv &e) { OP_DEBUG_2("\t&& GET_ITEM_ROOM(%s) == %s", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); @@ -1258,6 +1232,8 @@ Common::String AdlEngine::itemRoomStr(uint i) const { return "CARRYING"; case IDI_VOID_ROOM: return "GONE"; + case IDI_CUR_ROOM: + return "HERE"; default: return Common::String::format("%d", i); } diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 42d6667cab..ac5e22c974 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -23,6 +23,7 @@ #ifndef ADL_ADL_H #define ADL_ADL_H +#include "common/debug-channels.h" #include "common/array.h" #include "common/rect.h" #include "common/str.h" @@ -63,6 +64,7 @@ enum kDebugChannels { #define IDO_ACT_SAVE 0x0f #define IDO_ACT_LOAD 0x10 +#define IDI_CUR_ROOM 0xfc #define IDI_VOID_ROOM 0xfd #define IDI_ANY 0xfe @@ -178,6 +180,32 @@ struct RoomData { Commands commands; }; +// Opcode debugging macros +#define OP_DEBUG_0(F) do { \ + if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F)) \ + return 0; \ +} while (0) + +#define OP_DEBUG_1(F, P1) do { \ + if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1)) \ + return 1; \ +} while (0) + +#define OP_DEBUG_2(F, P1, P2) do { \ + if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2)) \ + return 2; \ +} while (0) + +#define OP_DEBUG_3(F, P1, P2, P3) do { \ + if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3)) \ + return 3; \ +} while (0) + +#define OP_DEBUG_4(F, P1, P2, P3, P4) do { \ + if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3, P4)) \ + return 4; \ +} while (0) + class AdlEngine : public Engine { friend class Console; public: diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index cc38bebe3f..a682c29855 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -193,6 +193,8 @@ void AdlEngine_v2::printString(const Common::String &str) { } int AdlEngine_v2::o2_isFirstTime(ScriptEnv &e) { + OP_DEBUG_0("\t&& IS_FIRST_TIME()"); + bool oldFlag = getCurRoom().isFirstTime; getCurRoom().isFirstTime = false; @@ -204,6 +206,8 @@ int AdlEngine_v2::o2_isFirstTime(ScriptEnv &e) { } int AdlEngine_v2::o2_isRandomGT(ScriptEnv &e) { + OP_DEBUG_1("\t&& RAND() > %d", e.arg(1)); + byte rnd = _random->getRandomNumber(255); if (rnd > e.arg(1)) @@ -213,6 +217,8 @@ int AdlEngine_v2::o2_isRandomGT(ScriptEnv &e) { } int AdlEngine_v2::o2_isNounNotInRoom(ScriptEnv &e) { + OP_DEBUG_1("\t&& NO_SUCH_ITEMS_IN_ROOM(%s)", itemRoomStr(e.arg(1)).c_str()); + Common::List::const_iterator item; for (item = _state.items.begin(); item != _state.items.end(); ++item) @@ -223,6 +229,8 @@ int AdlEngine_v2::o2_isNounNotInRoom(ScriptEnv &e) { } int AdlEngine_v2::o2_isCarryingSomething(ScriptEnv &e) { + OP_DEBUG_0("\t&& IS_CARRYING_SOMETHING()"); + Common::List::const_iterator item; for (item = _state.items.begin(); item != _state.items.end(); ++item) @@ -232,6 +240,8 @@ int AdlEngine_v2::o2_isCarryingSomething(ScriptEnv &e) { } int AdlEngine_v2::o2_moveItem(ScriptEnv &e) { + OP_DEBUG_2("\tSET_ITEM_ROOM(%s, %s)", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); + byte room = roomArg(e.arg(2)); Item &item = getItem(e.arg(1)); @@ -245,6 +255,8 @@ int AdlEngine_v2::o2_moveItem(ScriptEnv &e) { } int AdlEngine_v2::o2_moveAllItems(ScriptEnv &e) { + OP_DEBUG_2("\tMOVE_ALL_ITEMS(%d %d)", roomStr(e.arg(1)), roomStr(e.arg(2))); + byte room1 = roomArg(e.arg(1)); byte room2 = roomArg(e.arg(2)); @@ -261,6 +273,8 @@ int AdlEngine_v2::o2_moveAllItems(ScriptEnv &e) { } int AdlEngine_v2::o2_save(ScriptEnv &e) { + OP_DEBUG_0("\tSAVE_GAME()"); + int slot = askForSlot(_strings_v2.saveInsert); if (slot < 0) @@ -274,6 +288,8 @@ int AdlEngine_v2::o2_save(ScriptEnv &e) { } int AdlEngine_v2::o2_restore(ScriptEnv &e) { + OP_DEBUG_0("\tRESTORE_GAME()"); + int slot = askForSlot(_strings_v2.restoreInsert); if (slot < 0) @@ -288,6 +304,8 @@ int AdlEngine_v2::o2_restore(ScriptEnv &e) { } int AdlEngine_v2::o2_placeItem(ScriptEnv &e) { + OP_DEBUG_4("\tPLACE_ITEM(%s, %s, (%d, %d))", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str(), e.arg(3), e.arg(4)); + Item &item = getItem(e.arg(1)); item.room = roomArg(e.arg(2)); @@ -299,6 +317,8 @@ int AdlEngine_v2::o2_placeItem(ScriptEnv &e) { } int AdlEngine_v2::o2_tellTime(ScriptEnv &e) { + OP_DEBUG_0("\tTELL_TIME()"); + Common::String time = _strings_v2.time; time.setChar(APPLECHAR('0') + _state.time.hours / 10, 12); @@ -312,12 +332,15 @@ int AdlEngine_v2::o2_tellTime(ScriptEnv &e) { } int AdlEngine_v2::o2_setRoomFromVar(ScriptEnv &e) { + OP_DEBUG_1("\tROOM = VAR[%d]", e.arg(1)); getCurRoom().curPicture = getCurRoom().picture; _state.room = getVar(e.arg(1)); return 1; } int AdlEngine_v2::o2_initDisk(ScriptEnv &e) { + OP_DEBUG_0("\tINIT_DISK()"); + _display->printAsciiString("NOT REQUIRED\r"); return 0; } diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index 39060217e7..40bd40a385 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -28,8 +28,6 @@ // Note: this version of ADL redraws only when necessary, but // this is not currently implemented. -#define IDI_CUR_ROOM 0xfc - namespace Common{ class RandomSource; } diff --git a/engines/adl/console.cpp b/engines/adl/console.cpp index 53e452a5f3..d690524212 100644 --- a/engines/adl/console.cpp +++ b/engines/adl/console.cpp @@ -78,6 +78,19 @@ bool Console::Cmd_DumpScripts(int argc, const char **argv) { _engine->_dumpFile = new Common::DumpFile(); + Common::Array::const_iterator room; + byte roomNr = 1; + for (room = _engine->_state.rooms.begin(); room != _engine->_state.rooms.end(); ++room) { + _engine->loadRoom(roomNr); + if (_engine->_roomData.commands.size() != 0) { + _engine->_dumpFile->open(Common::String::format("%03d.ADL", roomNr).c_str()); + _engine->doAllCommands(_engine->_roomData.commands, IDI_ANY, IDI_ANY); + _engine->_dumpFile->close(); + } + ++roomNr; + } + _engine->loadRoom(_engine->_state.room); + _engine->_dumpFile->open("GLOBAL.ADL"); _engine->doAllCommands(_engine->_globalCommands, IDI_ANY, IDI_ANY); _engine->_dumpFile->close(); diff --git a/engines/adl/console.h b/engines/adl/console.h index 86538def79..e007e09976 100644 --- a/engines/adl/console.h +++ b/engines/adl/console.h @@ -42,7 +42,6 @@ public: static Common::String toAscii(const Common::String &str); private: - bool Cmd_Help(int argc, const char **argv); bool Cmd_Nouns(int argc, const char **argv); bool Cmd_Verbs(int argc, const char **argv); bool Cmd_DumpScripts(int argc, const char **argv); -- cgit v1.2.3