diff options
author | Kamil Zbróg | 2013-10-24 20:31:08 +0100 |
---|---|---|
committer | Kamil Zbróg | 2013-10-24 20:31:08 +0100 |
commit | 5357724657bff809b10b1f2bfe8547d1b53d6dcb (patch) | |
tree | 30b80321182fea4cc375c8734402b84a34dd0e1b | |
parent | accb9e10e8ee0c607c9fd2ec048af34b5058336f (diff) | |
download | scummvm-rg350-5357724657bff809b10b1f2bfe8547d1b53d6dcb.tar.gz scummvm-rg350-5357724657bff809b10b1f2bfe8547d1b53d6dcb.tar.bz2 scummvm-rg350-5357724657bff809b10b1f2bfe8547d1b53d6dcb.zip |
PRINCE: code cleanup
-rw-r--r-- | engines/prince/archive.cpp | 23 | ||||
-rw-r--r-- | engines/prince/archive.h | 1 | ||||
-rw-r--r-- | engines/prince/debugger.cpp | 98 | ||||
-rw-r--r-- | engines/prince/debugger.h | 14 | ||||
-rw-r--r-- | engines/prince/detection.cpp | 120 | ||||
-rw-r--r-- | engines/prince/font.cpp | 18 | ||||
-rw-r--r-- | engines/prince/font.h | 8 | ||||
-rw-r--r-- | engines/prince/graphics.cpp | 33 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 42 | ||||
-rw-r--r-- | engines/prince/prince.h | 22 | ||||
-rw-r--r-- | engines/prince/script.cpp | 94 | ||||
-rw-r--r-- | engines/prince/script.h | 6 |
12 files changed, 267 insertions, 212 deletions
diff --git a/engines/prince/archive.cpp b/engines/prince/archive.cpp index e69de29bb2..b474c95172 100644 --- a/engines/prince/archive.cpp +++ b/engines/prince/archive.cpp @@ -0,0 +1,23 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + + * 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. + + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "prince/archive.h" diff --git a/engines/prince/archive.h b/engines/prince/archive.h index 3624a87a33..3f5c5be4ef 100644 --- a/engines/prince/archive.h +++ b/engines/prince/archive.h @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ + #ifndef PRINCE_ARCHIVE_H #define PRINCE_ARCHIVE_H diff --git a/engines/prince/debugger.cpp b/engines/prince/debugger.cpp index 56053afb28..5da11acd88 100644 --- a/engines/prince/debugger.cpp +++ b/engines/prince/debugger.cpp @@ -11,7 +11,7 @@ * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License @@ -26,86 +26,86 @@ namespace Prince { Debugger::Debugger(PrinceEngine *vm) : GUI::Debugger(), _vm(vm) { - DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit)); - DCmd_Register("setflag", WRAP_METHOD(Debugger, Cmd_SetFlag)); - DCmd_Register("getflag", WRAP_METHOD(Debugger, Cmd_GetFlag)); - DCmd_Register("clearflag", WRAP_METHOD(Debugger, Cmd_ClearFlag)); - DCmd_Register("viewflc", WRAP_METHOD(Debugger, Cmd_ViewFlc)); + DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit)); + DCmd_Register("setflag", WRAP_METHOD(Debugger, Cmd_SetFlag)); + DCmd_Register("getflag", WRAP_METHOD(Debugger, Cmd_GetFlag)); + DCmd_Register("clearflag", WRAP_METHOD(Debugger, Cmd_ClearFlag)); + DCmd_Register("viewflc", WRAP_METHOD(Debugger, Cmd_ViewFlc)); } static int strToInt(const char *s) { - if (!*s) - // No string at all - return 0; - else if (toupper(s[strlen(s) - 1]) != 'H') - // Standard decimal string - return atoi(s); + if (!*s) + // No string at all + return 0; + else if (toupper(s[strlen(s) - 1]) != 'H') + // Standard decimal string + return atoi(s); - // Hexadecimal string - uint tmp = 0; - int read = sscanf(s, "%xh", &tmp); - if (read < 1) - error("strToInt failed on string \"%s\"", s); - return (int)tmp; + // Hexadecimal string + uint tmp = 0; + int read = sscanf(s, "%xh", &tmp); + if (read < 1) + error("strToInt failed on string \"%s\"", s); + return (int)tmp; } /* * This command sets a flag */ bool Debugger::Cmd_SetFlag(int argc, const char **argv) { - // Check for a flag to set - if (argc != 2) { - DebugPrintf("Usage: %s <flag number>\n", argv[0]); - return true; - } + // Check for a flag to set + if (argc != 2) { + DebugPrintf("Usage: %s <flag number>\n", argv[0]); + return true; + } - int flagNum = strToInt(argv[1]); - //g_globals->setFlag(flagNum); - return true; + int flagNum = strToInt(argv[1]); + //g_globals->setFlag(flagNum); + return true; } /* * This command gets the value of a flag */ bool Debugger::Cmd_GetFlag(int argc, const char **argv) { - // Check for an flag to display - if (argc != 2) { - DebugPrintf("Usage: %s <flag number>\n", argv[0]); - return true; - } + // Check for an flag to display + if (argc != 2) { + DebugPrintf("Usage: %s <flag number>\n", argv[0]); + return true; + } - int flagNum = strToInt(argv[1]); - //DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum)); - return true; + int flagNum = strToInt(argv[1]); + //DebugPrintf("Value: %d\n", g_globals->getFlag(flagNum)); + return true; } /* * This command clears a flag */ bool Debugger::Cmd_ClearFlag(int argc, const char **argv) { - // Check for a flag to clear - if (argc != 2) { - DebugPrintf("Usage: %s <flag number>\n", argv[0]); - return true; - } + // Check for a flag to clear + if (argc != 2) { + DebugPrintf("Usage: %s <flag number>\n", argv[0]); + return true; + } - int flagNum = strToInt(argv[1]); - //g_globals->clearFlag(flagNum); - return true; + int flagNum = strToInt(argv[1]); + //g_globals->clearFlag(flagNum); + return true; } /* * This command starts new flc anim */ bool Debugger::Cmd_ViewFlc(int argc, const char **argv) { - // Check for a flag to clear - if (argc != 2) { - DebugPrintf("Usage: %s <anim number>\n", argv[0]); - return true; - } + // Check for a flag to clear + if (argc != 2) { + DebugPrintf("Usage: %s <anim number>\n", argv[0]); + return true; + } - int flagNum = strToInt(argv[1]); + int flagNum = strToInt(argv[1]); _vm->loadAnim(flagNum); - return true; + return true; } } diff --git a/engines/prince/debugger.h b/engines/prince/debugger.h index d47e439c8b..c5a8be60c6 100644 --- a/engines/prince/debugger.h +++ b/engines/prince/debugger.h @@ -11,7 +11,7 @@ * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License @@ -32,14 +32,14 @@ class PrinceEngine; class Debugger : public GUI::Debugger { public: - Debugger(PrinceEngine *vm); - virtual ~Debugger() {} // we need this for __SYMBIAN32__ archaic gcc/UIQ + Debugger(PrinceEngine *vm); + virtual ~Debugger() {} // we need this for __SYMBIAN32__ archaic gcc/UIQ private: - bool Cmd_SetFlag(int argc, const char **argv); - bool Cmd_GetFlag(int argc, const char **argv); - bool Cmd_ClearFlag(int argc, const char **argv); - bool Cmd_ViewFlc(int argc, const char **argv); + bool Cmd_SetFlag(int argc, const char **argv); + bool Cmd_GetFlag(int argc, const char **argv); + bool Cmd_ClearFlag(int argc, const char **argv); + bool Cmd_ViewFlc(int argc, const char **argv); PrinceEngine *_vm; }; diff --git a/engines/prince/detection.cpp b/engines/prince/detection.cpp index e7f1ac01dd..c5f6039ca1 100644 --- a/engines/prince/detection.cpp +++ b/engines/prince/detection.cpp @@ -28,32 +28,32 @@ namespace Prince {
struct PrinceGameDescription {
- ADGameDescription desc;
+ ADGameDescription desc;
- int gameType;
+ int gameType;
};
int PrinceEngine::getGameType() const {
- return _gameDescription->gameType;
+ return _gameDescription->gameType;
}
const char *PrinceEngine::getGameId() const {
- return _gameDescription->desc.gameid;
+ return _gameDescription->desc.gameid;
}
uint32 PrinceEngine::getFeatures() const {
- return _gameDescription->desc.flags;
+ return _gameDescription->desc.flags;
}
Common::Language PrinceEngine::getLanguage() const {
- return _gameDescription->desc.language;
+ return _gameDescription->desc.language;
}
}
static const PlainGameDescriptor princeGames[] = {
- {"prince", "Prince Game"},
- {0, 0}
+ {"prince", "Prince Game"},
+ {0, 0}
};
namespace Prince {
@@ -61,34 +61,34 @@ namespace Prince { static const PrinceGameDescription gameDescriptions[] = {
// German
- {
- {
- "prince",
- "Galador",
- AD_ENTRY1s("databank.ptc", "5fa03833177331214ec1354761b1d2ee", 3565031),
- Common::DE_DEU,
- Common::kPlatformWindows,
- ADGF_NO_FLAGS,
- GUIO1(GUIO_NONE)
- },
- 0
- },
+ {
+ {
+ "prince",
+ "Galador",
+ AD_ENTRY1s("databank.ptc", "5fa03833177331214ec1354761b1d2ee", 3565031),
+ Common::DE_DEU,
+ Common::kPlatformWindows,
+ ADGF_NO_FLAGS,
+ GUIO1(GUIO_NONE)
+ },
+ 0
+ },
// Polish
- {
- {
- "prince",
- "Ksiaze i Tchorz",
- AD_ENTRY1s("databank.ptc", "48ec9806bda9d152acbea8ce31c93c49", 3435298),
- Common::PL_POL,
- Common::kPlatformWindows,
- ADGF_NO_FLAGS,
- GUIO1(GUIO_NONE)
- },
- 1
- },
-
-
- { AD_TABLE_END_MARKER, 0 }
+ {
+ {
+ "prince",
+ "Ksiaze i Tchorz",
+ AD_ENTRY1s("databank.ptc", "48ec9806bda9d152acbea8ce31c93c49", 3435298),
+ Common::PL_POL,
+ Common::kPlatformWindows,
+ ADGF_NO_FLAGS,
+ GUIO1(GUIO_NONE)
+ },
+ 1
+ },
+
+
+ { AD_TABLE_END_MARKER, 0 }
};
} // End of namespace Prince
@@ -97,45 +97,45 @@ using namespace Prince; // we match from data too, to stop detection from a non-top-level directory
const static char *directoryGlobs[] = {
- "all",
- 0
+ "all",
+ 0
};
class PrinceMetaEngine : public AdvancedMetaEngine {
public:
- PrinceMetaEngine() : AdvancedMetaEngine(Prince::gameDescriptions, sizeof(Prince::PrinceGameDescription), princeGames) {
- _singleid = "prince";
- _maxScanDepth = 2;
- _directoryGlobs = directoryGlobs;
- }
-
- virtual const char *getName() const {
- return "Prince Engine";
- }
-
- virtual const char *getOriginalCopyright() const {
- return "Copyright (C)";
- }
-
- virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
- virtual bool hasFeature(MetaEngineFeature f) const;
+ PrinceMetaEngine() : AdvancedMetaEngine(Prince::gameDescriptions, sizeof(Prince::PrinceGameDescription), princeGames) {
+ _singleid = "prince";
+ _maxScanDepth = 2;
+ _directoryGlobs = directoryGlobs;
+ }
+
+ virtual const char *getName() const {
+ return "Prince Engine";
+ }
+
+ virtual const char *getOriginalCopyright() const {
+ return "Copyright (C)";
+ }
+
+ virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
+ virtual bool hasFeature(MetaEngineFeature f) const;
};
bool PrinceMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
using namespace Prince;
- const PrinceGameDescription *gd = (const PrinceGameDescription *)desc;
- if (gd) {
- *engine = new PrinceEngine(syst, gd);
- }
- return gd != 0;
+ const PrinceGameDescription *gd = (const PrinceGameDescription *)desc;
+ if (gd) {
+ *engine = new PrinceEngine(syst, gd);
+ }
+ return gd != 0;
}
bool PrinceMetaEngine::hasFeature(MetaEngineFeature f) const {
- return false;
+ return false;
}
bool Prince::PrinceEngine::hasFeature(EngineFeature f) const {
- return false;//(f == kSupportsRTL);
+ return false;//(f == kSupportsRTL);
}
#if PLUGIN_ENABLED_DYNAMIC(PRINCE)
diff --git a/engines/prince/font.cpp b/engines/prince/font.cpp index e72d73e61a..8c72f1b912 100644 --- a/engines/prince/font.cpp +++ b/engines/prince/font.cpp @@ -71,15 +71,15 @@ int Font::getCharWidth(byte chr) const { } void Font::drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const { - const ChrData chrData = getChrData(chr); - const byte *src = chrData._pixels; - byte *target = (byte *)dst->getBasePtr(x, y); - - for (int i = 0; i < chrData._height; i++) { - memcpy(target, src, chrData._width); - src += chrData._width; - target += dst->pitch; - } + const ChrData chrData = getChrData(chr); + const byte *src = chrData._pixels; + byte *target = (byte *)dst->getBasePtr(x, y); + + for (int i = 0; i < chrData._height; i++) { + memcpy(target, src, chrData._width); + src += chrData._width; + target += dst->pitch; + } } } diff --git a/engines/prince/font.h b/engines/prince/font.h index ceae67df85..54e6b6b0a5 100644 --- a/engines/prince/font.h +++ b/engines/prince/font.h @@ -41,13 +41,13 @@ public: bool load(Common::SeekableReadStream &stream); - virtual int getFontHeight() const override; + virtual int getFontHeight() const override; - virtual int getMaxCharWidth() const override; + virtual int getMaxCharWidth() const override; - virtual int getCharWidth(byte chr) const override; + virtual int getCharWidth(byte chr) const override; - virtual void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const override; + virtual void drawChar(Graphics::Surface *dst, byte chr, int x, int y, uint32 color) const override; private: struct ChrData { diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index eae94748f6..74b46aad4c 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -1,3 +1,25 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + + * 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. + + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + #include "prince/graphics.h" #include "prince/prince.h" @@ -8,7 +30,7 @@ namespace Prince { GraphicsMan::GraphicsMan(PrinceEngine *vm) : _vm(vm), _changed(false) { - initGraphics(640, 480, true); + initGraphics(640, 480, true); _frontScreen = new Graphics::Surface(); _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); } @@ -38,13 +60,10 @@ void GraphicsMan::draw(const Graphics::Surface *s) void GraphicsMan::drawTransparent(const Graphics::Surface *s) { - for (uint y = 0; y < 480; ++y) - { - for (uint x = 0; x < 640; ++x) - { + for (uint y = 0; y < 480; ++y) { + for (uint x = 0; x < 640; ++x) { byte pixel = *((byte*)s->getBasePtr(x,y)); - if (pixel != 255) - { + if (pixel != 255) { *((byte*)_frontScreen->getBasePtr(x, y)) = pixel; } } diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index aec84684a7..4fb2082baf 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -67,13 +67,11 @@ PrinceEngine::~PrinceEngine() { delete _debugger;
}
-GUI::Debugger *PrinceEngine::getDebugger()
-{
+GUI::Debugger *PrinceEngine::getDebugger() {
return _debugger;
}
Common::Error PrinceEngine::run() {
-
_graph = new GraphicsMan(this);
const Common::FSNode gameDataDir(ConfMan.get("path"));
@@ -127,8 +125,7 @@ Common::Error PrinceEngine::run() { return Common::kNoError;
}
-bool PrinceEngine::loadLocation(uint16 locationNr)
-{
+bool PrinceEngine::loadLocation(uint16 locationNr) {
debug("PrinceEngine::loadLocation %d", locationNr);
const Common::FSNode gameDataDir(ConfMan.get("path"));
SearchMan.remove(Common::String::format("%02d", _locationNr));
@@ -141,14 +138,12 @@ bool PrinceEngine::loadLocation(uint16 locationNr) // load location background
Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");
- if (!room)
- {
+ if (!room) {
error("Can't load room bitmap");
return false;
}
- if(_roomBmp.loadStream(*room))
- {
+ if(_roomBmp.loadStream(*room)) {
debug("Room bitmap loaded");
_system->getPaletteManager()->setPalette(_roomBmp.getPalette(), 0, 256);
}
@@ -158,11 +153,9 @@ bool PrinceEngine::loadLocation(uint16 locationNr) return true;
}
-bool PrinceEngine::playNextFrame()
-{
+bool PrinceEngine::playNextFrame() {
const Graphics::Surface *s = _flicPlayer.decodeNextFrame();
- if (s)
- {
+ if (s) {
_graph->drawTransparent(s);
_graph->change();
}
@@ -170,19 +163,16 @@ bool PrinceEngine::playNextFrame() return true;
}
-bool PrinceEngine::loadAnim(uint16 animNr)
-{
+bool PrinceEngine::loadAnim(uint16 animNr) {
Common::String streamName = Common::String::format("AN%02d", animNr);
Common::SeekableReadStream * flicStream = SearchMan.createReadStreamForMember(streamName);
- if (!flicStream)
- {
+ if (!flicStream) {
error("Can't open %s", streamName.c_str());
return false;
}
- if (!_flicPlayer.loadStream(flicStream))
- {
+ if (!_flicPlayer.loadStream(flicStream)) {
error("Can't load flic stream %s", streamName.c_str());
}
@@ -192,13 +182,13 @@ bool PrinceEngine::loadAnim(uint16 animNr) }
void PrinceEngine::keyHandler(Common::Event event) {
- uint16 nChar = event.kbd.keycode;
- if (event.kbd.hasFlags(Common::KBD_CTRL)) {
- switch (nChar) {
- case Common::KEYCODE_d:
- getDebugger()->attach();
- getDebugger()->onFrame();
- break;
+ uint16 nChar = event.kbd.keycode;
+ if (event.kbd.hasFlags(Common::KBD_CTRL)) {
+ switch (nChar) {
+ case Common::KEYCODE_d:
+ getDebugger()->attach();
+ getDebugger()->onFrame();
+ break;
}
}
}
diff --git a/engines/prince/prince.h b/engines/prince/prince.h index efaf643cb7..b289c75553 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -56,20 +56,20 @@ class Debugger; class PrinceEngine : public Engine {
protected:
- Common::Error run();
+ Common::Error run();
public:
- PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc);
- virtual ~PrinceEngine();
+ PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc);
+ virtual ~PrinceEngine();
- virtual bool hasFeature(EngineFeature f) const;
+ virtual bool hasFeature(EngineFeature f) const;
- int getGameType() const;
- const char *getGameId() const;
- uint32 getFeatures() const;
- Common::Language getLanguage() const;
+ int getGameType() const;
+ const char *getGameId() const;
+ uint32 getFeatures() const;
+ Common::Language getLanguage() const;
- const PrinceGameDescription *_gameDescription;
+ const PrinceGameDescription *_gameDescription;
Video::FlicDecoder _flicPlayer;
bool loadLocation(uint16 locationNr);
@@ -81,7 +81,7 @@ private: bool playNextFrame();
void keyHandler(Common::Event event);
- Common::RandomSource *_rnd;
+ Common::RandomSource *_rnd;
Graphics::BitmapDecoder _roomBmp;
uint16 _locationNr;
MhwanhDecoder _walizkaBmp;
@@ -90,7 +90,7 @@ private: GraphicsMan *_graph;
Script *_script;
Font _font;
-
+
void mainLoop();
};
diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 66e0c598f9..d790d6d9c3 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -1,3 +1,25 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + + * 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. + + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + #include "prince/script.h" #include "prince/prince.h" @@ -10,37 +32,37 @@ namespace Prince { static const uint16 NUM_OPCODES = 144; Script::Script(PrinceEngine *vm) : - _code(NULL), _stacktop(0), _vm(vm), _opcodeNF(false) { + _code(NULL), _stacktop(0), _vm(vm), _opcodeNF(false) { } Script::~Script() { - delete[] _code; + delete[] _code; } bool Script::loadFromStream(Common::SeekableReadStream &stream) { - _codeSize = stream.size(); - _code = new byte[_codeSize]; + _codeSize = stream.size(); + _code = new byte[_codeSize]; - if (!_code) - return false; + if (!_code) + return false; - stream.read(_code, _codeSize); - // Initialize the script - _currentInstruction = READ_LE_UINT32(_code + 4); + stream.read(_code, _codeSize); + // Initialize the script + _currentInstruction = READ_LE_UINT32(_code + 4); - return true; + return true; } void Script::debugScript(const char *s, ...) { - char buf[STRINGBUFLEN]; - va_list va; + char buf[STRINGBUFLEN]; + va_list va; - va_start(va, s); - vsnprintf(buf, STRINGBUFLEN, s, va); - va_end(va); + va_start(va, s); + vsnprintf(buf, STRINGBUFLEN, s, va); + va_end(va); Common::String str = Common::String::format("@0x%04X: ", _lastInstruction); - str += Common::String::format("op %02d: ", _lastOpcode); + str += Common::String::format("op %02d: ", _lastOpcode); debug("%s %s", str.c_str(), buf); } @@ -69,28 +91,28 @@ void Script::step() { } uint8 Script::getCodeByte(uint32 address) { - if (address >= _codeSize) - error("Trying to read a script byte at address 0x%04X, while the " - "script is just 0x%04X bytes long", address, _codeSize); - return _code[address]; + if (address >= _codeSize) + error("Trying to read a script byte at address 0x%04X, while the " + "script is just 0x%04X bytes long", address, _codeSize); + return _code[address]; } uint8 Script::readScript8bits() { - uint8 data = getCodeByte(_currentInstruction); - _currentInstruction++; - return data; + uint8 data = getCodeByte(_currentInstruction); + _currentInstruction++; + return data; } uint16 Script::readScript16bits() { - uint8 lower = readScript8bits(); - uint8 upper = readScript8bits(); - return lower | (upper << 8); + uint8 lower = readScript8bits(); + uint8 upper = readScript8bits(); + return lower | (upper << 8); } uint32 Script::readScript32bits() { - uint16 lower = readScript16bits(); - uint16 upper = readScript16bits(); - return lower | (upper << 16); + uint16 lower = readScript16bits(); + uint16 upper = readScript16bits(); + return lower | (upper << 16); } void Script::O_WAITFOREVER() { @@ -211,14 +233,14 @@ void Script::O__CALL() { debugScript("O__CALL 0x%04X", _currentInstruction); } void Script::O_RETURN() { - // Get the return address - if (_stacktop > 0) { - _stacktop--; - _currentInstruction = _stack[_stacktop]; + // Get the return address + if (_stacktop > 0) { + _stacktop--; + _currentInstruction = _stack[_stacktop]; debugScript("O_RETURN 0x%04X", _currentInstruction); - } else { - error("Return: Stack is empty"); - } + } else { + error("Return: Stack is empty"); + } } void Script::O_GO() { int32 opPC = readScript32bits(); diff --git a/engines/prince/script.h b/engines/prince/script.h index 982e7aae61..e801529187 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -33,8 +33,7 @@ namespace Prince { class PrinceEngine; -class Script -{ +class Script { public: Script(PrinceEngine *vm); virtual ~Script(); @@ -56,7 +55,8 @@ private: bool _opcodeNF; // Stack - uint16 _stack[500]; + static const uint32 _STACK_SIZE = 500; + uint16 _stack[_STACK_SIZE]; uint8 _stacktop; uint8 _savedStacktop; |