aboutsummaryrefslogtreecommitdiff
path: root/engines/prince
diff options
context:
space:
mode:
authorKamil Zbróg2013-10-24 14:24:27 +0100
committerKamil Zbróg2013-10-24 14:24:27 +0100
commit026390145b0e947be7cccf3d9ba329eb2270a2ed (patch)
tree31dbd6414e1f0cb817995e320afd6d9876092b77 /engines/prince
parente64c3dc002a083cb7ff471be89817015b35345dd (diff)
downloadscummvm-rg350-026390145b0e947be7cccf3d9ba329eb2270a2ed.tar.gz
scummvm-rg350-026390145b0e947be7cccf3d9ba329eb2270a2ed.tar.bz2
scummvm-rg350-026390145b0e947be7cccf3d9ba329eb2270a2ed.zip
PRINCE: Another code cleanup
Diffstat (limited to 'engines/prince')
-rw-r--r--engines/prince/archive.cpp23
-rw-r--r--engines/prince/archive.h1
-rw-r--r--engines/prince/debugger.cpp98
-rw-r--r--engines/prince/debugger.h14
-rw-r--r--engines/prince/font.cpp18
-rw-r--r--engines/prince/font.h8
-rw-r--r--engines/prince/graphics.cpp24
-rw-r--r--engines/prince/prince.cpp14
-rw-r--r--engines/prince/prince.h22
-rw-r--r--engines/prince/script.cpp94
-rw-r--r--engines/prince/script.h3
11 files changed, 194 insertions, 125 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/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 29fbd6a611..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());
}
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index 1dd54bafd8..4fb2082baf 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -182,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..43d5759a0b 100644
--- a/engines/prince/script.h
+++ b/engines/prince/script.h
@@ -56,7 +56,8 @@ private:
bool _opcodeNF;
// Stack
- uint16 _stack[500];
+ static const uint32 _STACK_SIZE = 500;
+ uint16 _stack[_STACK_SIZE];
uint8 _stacktop;
uint8 _savedStacktop;