From 8d29dec888e8b1287cea20490e3c5abb7f0226a2 Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Tue, 13 Sep 2022 22:16:14 +0800 Subject: [PATCH] DIRECTOR: Implement channels debugger command --- engines/director/debugger.cpp | 22 +++++++++++++- engines/director/debugger.h | 1 + engines/director/frame.cpp | 49 ++++++++++++++++++++------------ engines/director/frame.h | 2 ++ engines/director/lingo/lingo.cpp | 2 +- 5 files changed, 56 insertions(+), 20 deletions(-) diff --git a/engines/director/debugger.cpp b/engines/director/debugger.cpp index 9c133d1425a..fe996da4fd6 100644 --- a/engines/director/debugger.cpp +++ b/engines/director/debugger.cpp @@ -22,6 +22,7 @@ #include "common/language.h" #include "director/director.h" #include "director/debugger.h" +#include "director/frame.h" #include "director/movie.h" #include "director/score.h" #include "director/lingo/lingo.h" @@ -42,6 +43,8 @@ Debugger::Debugger(): GUI::Debugger() { registerCmd("version", WRAP_METHOD(Debugger, cmdVersion)); registerCmd("frame", WRAP_METHOD(Debugger, cmdFrame)); registerCmd("f", WRAP_METHOD(Debugger, cmdFrame)); + registerCmd("channels", WRAP_METHOD(Debugger, cmdChannels)); + registerCmd("chan", WRAP_METHOD(Debugger, cmdChannels)); registerCmd("nextframe", WRAP_METHOD(Debugger, cmdNextFrame)); registerCmd("nf", WRAP_METHOD(Debugger, cmdNextFrame)); @@ -89,7 +92,7 @@ bool Debugger::cmdHelp(int argc, const char **argv) { //debugPrintf(" movie [moviePath] - Get or sets the current movie\n"); //debugPrintf(" movieinfo - Show information for the current movie\n"); debugPrintf(" frame / f [frameNum] - Gets or sets the current score frame\n"); - //debugPrintf(" channels / chan [frameNum] - Shows channel information for a score frame\n"); + debugPrintf(" channels / chan [frameNum] - Shows channel information for a score frame\n"); //debugPrintf(" cast - Shows the cast list for the current movie\n"); debugPrintf(" nextframe / nf [n] - Steps forward one or more score frames\n"); //debugPrintf(" nextmovie / nm - Steps forward until the next change of movie\n"); @@ -149,6 +152,23 @@ bool Debugger::cmdFrame(int argc, const char **argv) { return true; } +bool Debugger::cmdChannels(int argc, const char **argv) { + Lingo *lingo = g_director->getLingo(); + Score *score = g_director->getCurrentMovie()->getScore(); + + int maxSize = (int)score->_frames.size(); + int frameId = score->getCurrentFrame(); + if (argc == 2) + frameId = atoi(argv[1]); + + if (frameId >= 1 && frameId <= maxSize) { + debugPrintf("%s\n", score->_frames[frameId-1]->formatChannelInfo().c_str()); + } else { + debugPrintf("Must specify a frame number between 1 and %d\n", maxSize); + } + return true; +} + bool Debugger::cmdNextFrame(int argc, const char **argv) { _nextFrame = true; if (argc == 2 && atoi(argv[1]) > 0) { diff --git a/engines/director/debugger.h b/engines/director/debugger.h index 5af429d71c6..1f3712478e8 100644 --- a/engines/director/debugger.h +++ b/engines/director/debugger.h @@ -42,6 +42,7 @@ private: bool cmdVersion(int argc, const char **argv); bool cmdFrame(int argc, const char **argv); + bool cmdChannels(int argc, const char **argv); bool cmdNextFrame(int argc, const char **argv); bool cmdRepl(int argc, const char **argv); bool cmdBacktrace(int argc, const char **argv); diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index 2304945f9de..540f6a9aa36 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -263,22 +263,6 @@ void Frame::readChannels(Common::ReadStreamEndian *stream, uint16 version) { // Script } - debugC(4, kDebugLoading, "TMPO: tempo: %d, skipFrameFlag: %d, blend: %d", - _tempo, _skipFrameFlag, _blend); - if (_palette.paletteId) { - debugC(4, kDebugLoading, "PAL: paletteId: %d, firstColor: %d, lastColor: %d, flags: %d, cycleCount: %d, speed: %d, frameCount: %d, fade: %d, delay: %d, style: %d", - _palette.paletteId, _palette.firstColor, _palette.lastColor, _palette.flags, - _palette.cycleCount, _palette.speed, _palette.frameCount, - _palette.fade, _palette.delay, _palette.style); - } else { - debugC(4, kDebugLoading, "PAL: paletteId: 000"); - } - debugC(4, kDebugLoading, "TRAN: transType: %d, transDuration: %d, transChunkSize: %d", - _transType, _transDuration, _transChunkSize); - debugC(4, kDebugLoading, "SND: 1 sound1: %d, soundType1: %d", _sound1.member, _soundType1); - debugC(4, kDebugLoading, "SND: 2 sound2: %d, soundType2: %d", _sound2.member, _soundType2); - debugC(4, kDebugLoading, "LSCR: actionId: %d", _actionId.member); - _transChunkSize = CLIP(_transChunkSize, 0, 128); _transDuration = CLIP(_transDuration, 0, 32000); // restrict to 32 secs @@ -388,19 +372,48 @@ void Frame::readChannels(Common::ReadStreamEndian *stream, uint16 version) { sprite._trails = 0; sprite._moveable = ((sprite._colorcode & 0x80) == 0x80); + } + if (debugChannelSet(4, kDebugLoading)) { + debugC(4, kDebugLoading, "%s", formatChannelInfo().c_str()); + } +} + +Common::String Frame::formatChannelInfo() { + Common::String result; + result += Common::String::format("TMPO: tempo: %d, skipFrameFlag: %d, blend: %d\n", + _tempo, _skipFrameFlag, _blend); + if (_palette.paletteId) { + result += Common::String::format("PAL: paletteId: %d, firstColor: %d, lastColor: %d, flags: %d, cycleCount: %d, speed: %d, frameCount: %d, fade: %d, delay: %d, style: %d\n", + _palette.paletteId, _palette.firstColor, _palette.lastColor, _palette.flags, + _palette.cycleCount, _palette.speed, _palette.frameCount, + _palette.fade, _palette.delay, _palette.style); + } else { + result += Common::String::format("PAL: paletteId: 000\n"); + } + result += Common::String::format("TRAN: transType: %d, transDuration: %d, transChunkSize: %d\n", + _transType, _transDuration, _transChunkSize); + result += Common::String::format("SND: 1 sound1: %d, soundType1: %d\n", _sound1.member, _soundType1); + result += Common::String::format("SND: 2 sound2: %d, soundType2: %d\n", _sound2.member, _soundType2); + result += Common::String::format("LSCR: actionId: %d\n", _actionId.member); + + for (int i = 0; i < _numChannels; i++) { + Sprite &sprite = *_sprites[i + 1]; if (sprite._castId.member) { - debugC(4, kDebugLoading, "CH: %-3d castId: %s [inkData:%02x [ink: %x trails: %d line: %d], %dx%d@%d,%d type: %d fg: %d bg: %d] script: %s, flags2: %x, unk2: %x, unk3: %x", + result += Common::String::format("CH: %-3d castId: %s [inkData:%02x [ink: %x trails: %d line: %d], %dx%d@%d,%d type: %d fg: %d bg: %d] script: %s, flags2: %x, unk2: %x, unk3: %x\n", i + 1, sprite._castId.asString().c_str(), sprite._inkData, sprite._ink, sprite._trails, sprite._thickness, sprite._width, sprite._height, sprite._startPoint.x, sprite._startPoint.y, sprite._spriteType, sprite._foreColor, sprite._backColor, sprite._scriptId.asString().c_str(), sprite._colorcode, sprite._blendAmount, sprite._unk3); } else { - debugC(4, kDebugLoading, "CH: %-3d castId: 000", i + 1); + result += Common::String::format("CH: %-3d castId: 000\n", i + 1); } } + + return result; } + void Frame::readMainChannels(Common::SeekableReadStreamEndian &stream, uint16 offset, uint16 size) { uint16 finishPosition = offset + size; diff --git a/engines/director/frame.h b/engines/director/frame.h index c4d262744f6..d66f45da71d 100644 --- a/engines/director/frame.h +++ b/engines/director/frame.h @@ -96,6 +96,8 @@ public: void executeImmediateScripts(); + Common::String formatChannelInfo(); + private: void readPaletteInfo(Common::SeekableReadStreamEndian &stream); diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp index 002d2dca5e7..6b0345c2ecf 100644 --- a/engines/director/lingo/lingo.cpp +++ b/engines/director/lingo/lingo.cpp @@ -462,7 +462,7 @@ Common::String Lingo::decodeInstruction(ScriptData *sd, uint pc, uint *newPc) { void Lingo::execute() { uint localCounter = 0; - while (!_abort && !_freezeContext && (*_currentScript)[_pc] != STOP) { + while (!_abort && !_freezeContext && _currentScript && (*_currentScript)[_pc] != STOP) { if (_globalCounter > 1000 && debugChannelSet(-1, kDebugFewFramesOnly)) { warning("Lingo::execute(): Stopping due to debug few frames only"); _vm->getCurrentMovie()->getScore()->_playState = kPlayStopped;