diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/configure.engines | 1 | ||||
-rw-r--r-- | engines/engines.mk | 5 | ||||
-rw-r--r-- | engines/plugins_table.h | 3 | ||||
-rw-r--r-- | engines/prince/archive.cpp | 0 | ||||
-rw-r--r-- | engines/prince/archive.h | 34 | ||||
-rw-r--r-- | engines/prince/detection.cpp | 145 | ||||
-rw-r--r-- | engines/prince/font.cpp | 85 | ||||
-rw-r--r-- | engines/prince/font.h | 66 | ||||
-rw-r--r-- | engines/prince/graphics.cpp | 30 | ||||
-rw-r--r-- | engines/prince/graphics.h | 58 | ||||
-rw-r--r-- | engines/prince/mhwanh.cpp | 73 | ||||
-rw-r--r-- | engines/prince/mhwanh.h | 52 | ||||
-rw-r--r-- | engines/prince/module.mk | 17 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 170 | ||||
-rw-r--r-- | engines/prince/prince.h | 74 | ||||
-rw-r--r-- | engines/prince/script.cpp | 635 | ||||
-rw-r--r-- | engines/prince/script.h | 372 |
17 files changed, 1820 insertions, 0 deletions
diff --git a/engines/configure.engines b/engines/configure.engines index ec7d4667ca..195d0a3426 100644 --- a/engines/configure.engines +++ b/engines/configure.engines @@ -34,6 +34,7 @@ add_engine myst "Myst" no "" "" "16bit" add_engine neverhood "Neverhood" no add_engine parallaction "Parallaction" yes add_engine pegasus "The Journeyman Project: Pegasus Prime" yes "" "" "16bit" +add_engine prince "The Prince & The Coward" no add_engine queen "Flight of the Amazon Queen" yes add_engine saga "SAGA" yes "ihnm saga2" "ITE" add_engine ihnm "IHNM" yes diff --git a/engines/engines.mk b/engines/engines.mk index 1d9d8fd89b..c15b0ad43c 100644 --- a/engines/engines.mk +++ b/engines/engines.mk @@ -160,6 +160,11 @@ DEFINES += -DENABLE_PEGASUS=$(ENABLE_PEGASUS) MODULES += engines/pegasus endif +ifdef ENABLE_PRINCE +DEFINES += -DENABLE_PRINCE=$(ENABLE_PRINCE) +MODULES += engines/prince +endif + ifdef ENABLE_QUEEN DEFINES += -DENABLE_QUEEN=$(ENABLE_QUEEN) MODULES += engines/queen diff --git a/engines/plugins_table.h b/engines/plugins_table.h index 38cd43ac74..de2a8069de 100644 --- a/engines/plugins_table.h +++ b/engines/plugins_table.h @@ -125,6 +125,9 @@ LINK_PLUGIN(TUCKER) #if PLUGIN_ENABLED_STATIC(WINTERMUTE) LINK_PLUGIN(WINTERMUTE) #endif +#if PLUGIN_ENABLED_STATIC(PRINCE) +LINK_PLUGIN(PRINCE) +#endif #if PLUGIN_ENABLED_STATIC(ZVISION) LINK_PLUGIN(ZVISION) #endif diff --git a/engines/prince/archive.cpp b/engines/prince/archive.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/engines/prince/archive.cpp diff --git a/engines/prince/archive.h b/engines/prince/archive.h new file mode 100644 index 0000000000..3624a87a33 --- /dev/null +++ b/engines/prince/archive.h @@ -0,0 +1,34 @@ +/* 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. + * + */ +#ifndef PRINCE_ARCHIVE_H +#define PRINCE_ARCHIVE_H + +#include "common/archive.h" + +namespace Price { + +class Archive : public Common::Archive { +}; + +} + +#endif diff --git a/engines/prince/detection.cpp b/engines/prince/detection.cpp new file mode 100644 index 0000000000..e7f1ac01dd --- /dev/null +++ b/engines/prince/detection.cpp @@ -0,0 +1,145 @@ +/* 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 "base/plugins.h"
+#include "engines/advancedDetector.h"
+
+#include "prince/prince.h"
+
+namespace Prince {
+
+struct PrinceGameDescription {
+ ADGameDescription desc;
+
+ int gameType;
+};
+
+int PrinceEngine::getGameType() const {
+ return _gameDescription->gameType;
+}
+
+const char *PrinceEngine::getGameId() const {
+ return _gameDescription->desc.gameid;
+}
+
+uint32 PrinceEngine::getFeatures() const {
+ return _gameDescription->desc.flags;
+}
+
+Common::Language PrinceEngine::getLanguage() const {
+ return _gameDescription->desc.language;
+}
+
+}
+
+static const PlainGameDescriptor princeGames[] = {
+ {"prince", "Prince Game"},
+ {0, 0}
+};
+
+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
+ },
+ // 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 }
+};
+
+} // End of namespace Prince
+
+using namespace Prince;
+
+// we match from data too, to stop detection from a non-top-level directory
+const static char *directoryGlobs[] = {
+ "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;
+};
+
+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;
+}
+
+bool PrinceMetaEngine::hasFeature(MetaEngineFeature f) const {
+ return false;
+}
+
+bool Prince::PrinceEngine::hasFeature(EngineFeature f) const {
+ return false;//(f == kSupportsRTL);
+}
+
+#if PLUGIN_ENABLED_DYNAMIC(PRINCE)
+REGISTER_PLUGIN_DYNAMIC(PRINCE, PLUGIN_TYPE_ENGINE, PrinceMetaEngine);
+#else
+REGISTER_PLUGIN_STATIC(PRINCE, PLUGIN_TYPE_ENGINE, PrinceMetaEngine);
+#endif
diff --git a/engines/prince/font.cpp b/engines/prince/font.cpp new file mode 100644 index 0000000000..e72d73e61a --- /dev/null +++ b/engines/prince/font.cpp @@ -0,0 +1,85 @@ +/* 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 "common/archive.h" +#include "common/debug.h" +#include "common/stream.h" +#include "common/str.h" + +#include "graphics/surface.h" + +#include "prince/font.h" + +namespace Prince { + +Font::Font() { +} + +Font::~Font() { + delete [] _fontData; +} + +bool Font::load(Common::SeekableReadStream &stream) { + stream.seek(0); + _fontData = new byte[stream.size()]; + stream.read(_fontData, stream.size()); + return true; +} + +int Font::getFontHeight() const { + debug("Font::getFontHeight %d", _fontData[5]); + return _fontData[5]; +} + +int Font::getMaxCharWidth() const { + return 0; +} + +Font::ChrData Font::getChrData(byte chr) const { + chr -= 32; + uint16 chrOffset = 4*chr+6; + + ChrData chrData; + chrData._width = _fontData[chrOffset+2]; + chrData._height = _fontData[chrOffset+3]; + chrData._pixels = _fontData + READ_LE_UINT16(_fontData + chrOffset); + + return chrData; +} + +int Font::getCharWidth(byte chr) const { + return getChrData(chr)._width; +} + +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; + } +} + +} diff --git a/engines/prince/font.h b/engines/prince/font.h new file mode 100644 index 0000000000..ceae67df85 --- /dev/null +++ b/engines/prince/font.h @@ -0,0 +1,66 @@ +/* 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. + */ + +#ifndef PRINCE_FONT_H +#define PRINCE_FONT_H + +#include "graphics/font.h" + +namespace Graphics { + struct Surface; +} + +namespace Common { + class String; +} + +namespace Prince { + +class Font : public Graphics::Font { +public: + Font(); + virtual ~Font(); + + bool load(Common::SeekableReadStream &stream); + + virtual int getFontHeight() const override; + + virtual int getMaxCharWidth() 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; + +private: + struct ChrData { + byte * _pixels; + byte _width; + byte _height; + }; + + ChrData getChrData(byte chr) const; + + byte * _fontData; +}; + +} + +#endif diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp new file mode 100644 index 0000000000..356b35f832 --- /dev/null +++ b/engines/prince/graphics.cpp @@ -0,0 +1,30 @@ +#include "prince/graphics.h" + +#include "prince/prince.h" + +#include "graphics/palette.h" + +namespace Prince { + +GraphicsMan::GraphicsMan(PrinceEngine *vm) + : _vm(vm), _changed(false) { + initGraphics(640, 480, true); +} + +void GraphicsMan::update() { + if (_changed) { + _vm->_system->copyRectToScreen((byte*)_roomBackground->getBasePtr(0,0), 640, 0, 0, 640, 480); + + _vm->_system->updateScreen(); + } +} + +void GraphicsMan::setPalette(const byte *palette) { + _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); +} + +void GraphicsMan::change() { + _changed = true; +} + +} diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h new file mode 100644 index 0000000000..3599cbc346 --- /dev/null +++ b/engines/prince/graphics.h @@ -0,0 +1,58 @@ +/* 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. + * + */ + +#ifndef PRINCE_GRAPHICS_H +#define PRINCE_GRAPHICS_H + +#include "graphics/surface.h" + + +namespace Prince { + +class PrinceEngine; + +class GraphicsMan +{ +public: + GraphicsMan(PrinceEngine *vm); + + void update(); + + void change(); + + void setPalette(const byte *palette); + + Graphics::Surface *_backScreen; + const Graphics::Surface *_roomBackground; + +private: + + PrinceEngine *_vm; + + bool _changed; + byte _palette[3 * 256]; + Graphics::Surface *_frontScreen; +}; + +} + +#endif diff --git a/engines/prince/mhwanh.cpp b/engines/prince/mhwanh.cpp new file mode 100644 index 0000000000..4240ed4097 --- /dev/null +++ b/engines/prince/mhwanh.cpp @@ -0,0 +1,73 @@ +/* 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 "common/stream.h" + +#include "graphics/surface.h" + +#include "prince/mhwanh.h" + +namespace Prince { + +MhwanhDecoder::MhwanhDecoder() + : _surface(NULL), _palette(0), _paletteColorCount(0) { +} + +MhwanhDecoder::~MhwanhDecoder() { + destroy(); +} + +void MhwanhDecoder::destroy() { + if (_surface) { + _surface->free(); + delete _surface; _surface = 0; + } + + delete [] _palette; _palette = 0; + _paletteColorCount = 0; +} + +bool MhwanhDecoder::loadStream(Common::SeekableReadStream &stream) { + destroy(); + _paletteColorCount = 256; + stream.seek(0); + stream.skip(0x20); + // Read the palette + _palette = new byte[_paletteColorCount * 3]; + for (uint16 i = 0; i < _paletteColorCount; i++) { + _palette[i * 3 + 0] = stream.readByte(); + _palette[i * 3 + 1] = stream.readByte(); + _palette[i * 3 + 2] = stream.readByte(); + } + + _surface = new Graphics::Surface(); + _surface->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); + for (int h = 0; h < 480; ++h) { + stream.read(_surface->getBasePtr(0, h), 640); + } + + return true; +} + +} + + diff --git a/engines/prince/mhwanh.h b/engines/prince/mhwanh.h new file mode 100644 index 0000000000..44f957372e --- /dev/null +++ b/engines/prince/mhwanh.h @@ -0,0 +1,52 @@ +/* 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. + * + */ + +#ifndef PRINCE_MHWANH_H +#define PRINCE_MHWANH_H + +#include "graphics/decoders/image_decoder.h" + +namespace Prince { + +class MhwanhDecoder : public Graphics::ImageDecoder +{ +public: + MhwanhDecoder(); + virtual ~MhwanhDecoder(); + + // ImageDecoder API + void destroy(); + virtual bool loadStream(Common::SeekableReadStream &stream); + virtual Graphics::Surface *getSurface() const { return _surface; } + const byte *getPalette() const { return _palette; } + uint16 getPaletteCount() const { return _paletteColorCount; } + +private: + Graphics::Surface *_surface; + byte *_palette; + uint16 _paletteColorCount; +}; + +} + + +#endif diff --git a/engines/prince/module.mk b/engines/prince/module.mk new file mode 100644 index 0000000000..853592b503 --- /dev/null +++ b/engines/prince/module.mk @@ -0,0 +1,17 @@ +MODULE := engines/prince
+
+MODULE_OBJS = \
+ script.o \
+ graphics.o \
+ mhwanh.o \
+ detection.o \
+ font.o \
+ prince.o
+
+# This module can be built as a plugin
+ifeq ($(ENABLE_PRINCE), DYNAMIC_PLUGIN)
+PLUGIN := 1
+endif
+
+# Include common rules
+include $(srcdir)/rules.mk
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp new file mode 100644 index 0000000000..c82dfd6723 --- /dev/null +++ b/engines/prince/prince.cpp @@ -0,0 +1,170 @@ +/* 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 "common/scummsys.h"
+
+#include "common/config-manager.h"
+#include "common/debug-channels.h"
+#include "common/debug.h"
+#include "common/events.h"
+#include "common/file.h"
+#include "common/random.h"
+#include "common/fs.h"
+#include "common/keyboard.h"
+#include "common/substream.h"
+
+#include "graphics/cursorman.h"
+#include "graphics/surface.h"
+#include "graphics/palette.h"
+#include "graphics/pixelformat.h"
+#include "graphics/decoders/bmp.h"
+
+#include "engines/util.h"
+#include "engines/advancedDetector.h"
+
+#include "audio/audiostream.h"
+
+#include "prince/prince.h"
+#include "prince/font.h"
+#include "prince/mhwanh.h"
+#include "prince/graphics.h"
+#include "prince/script.h"
+
+namespace Prince {
+
+PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) :
+ Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL) {
+ _rnd = new Common::RandomSource("prince");
+
+}
+
+PrinceEngine::~PrinceEngine() {
+ DebugMan.clearAllDebugChannels();
+
+ delete _rnd;
+}
+
+Common::Error PrinceEngine::run() {
+
+ _graph = new GraphicsMan(this);
+
+ const Common::FSNode gameDataDir(ConfMan.get("path"));
+
+ debug("Adding all path: %s", gameDataDir.getPath().c_str());
+
+ SearchMan.addSubDirectoryMatching(gameDataDir, "all", 0, 2);
+ SearchMan.addSubDirectoryMatching(gameDataDir, "01", 0, 2);
+
+ Common::SeekableReadStream * walizka = SearchMan.createReadStreamForMember("walizka");
+
+ Common::SeekableReadStream *font1stream = SearchMan.createReadStreamForMember("font1.raw");
+ if (!font1stream)
+ return Common::kPathNotFile;
+
+ Font font1 = Font();
+ if (font1.load(*font1stream)) {
+ font1.getCharWidth(103);
+ }
+ delete font1stream;
+
+ Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");
+
+ //_frontScreen = new Graphics::Surface();
+ //_frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
+
+ if (room) {
+ Graphics::BitmapDecoder roomBmp;
+ roomBmp.loadStream(*room);
+ //_roomBackground = roomBmp.getSurface();
+ _system->getPaletteManager()->setPalette(roomBmp.getPalette(), 0, 256);
+
+ //font1.drawString(_frontScreen, "Hello World", 10, 10, 640, 1);
+ //
+ _graph->_roomBackground = roomBmp.getSurface();
+#if 1
+ MhwanhDecoder *walizkaBmp = new MhwanhDecoder();
+ if (walizka) {
+ debug("Loading walizka");
+ if (walizkaBmp->loadStream(*walizka)) {
+ _graph->_roomBackground = walizkaBmp->getSurface();
+ _graph->setPalette(walizkaBmp->getPalette());
+ }
+ }
+#endif
+ _graph->change();
+
+ Common::SeekableReadStream * skryptStream = SearchMan.createReadStreamForMember("skrypt.dat");
+ if (!skryptStream)
+ return Common::kPathNotFile;
+
+ _script = new Script(this);
+ _script->loadFromStream(*skryptStream);
+
+ delete skryptStream;
+
+ mainLoop();
+ delete room;
+ delete walizkaBmp;
+ }
+
+ return Common::kNoError;
+}
+
+void PrinceEngine::mainLoop() {
+ //uint32 nextFrameTime = 0;
+ while (!shouldQuit()) {
+ Common::Event event;
+ Common::EventManager *eventMan = _system->getEventManager();
+ while (eventMan->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_KEYDOWN:
+ break;
+ case Common::EVENT_KEYUP:
+ break;
+ case Common::EVENT_MOUSEMOVE:
+ break;
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_RBUTTONDOWN:
+ break;
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ break;
+ case Common::EVENT_QUIT:
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (shouldQuit())
+ return;
+
+ _script->step();
+
+ _graph->update();
+
+ _system->delayMillis(40);
+
+ }
+}
+
+} // End of namespace Prince
diff --git a/engines/prince/prince.h b/engines/prince/prince.h new file mode 100644 index 0000000000..966cee982e --- /dev/null +++ b/engines/prince/prince.h @@ -0,0 +1,74 @@ +/* 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.
+ *
+ */
+
+#ifndef PRINCE_H
+#define PRINCE_H
+
+#include "common/random.h"
+#include "common/system.h"
+#include "common/debug.h"
+#include "common/debug-channels.h"
+#include "common/textconsole.h"
+#include "common/rect.h"
+
+#include "engines/engine.h"
+#include "engines/util.h"
+
+#include "audio/mixer.h"
+
+namespace Prince {
+
+struct PrinceGameDescription;
+
+class PrinceEngine;
+class GraphicsMan;
+class Script;
+
+class PrinceEngine : public Engine {
+protected:
+ Common::Error run();
+
+public:
+ PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc);
+ virtual ~PrinceEngine();
+
+ virtual bool hasFeature(EngineFeature f) const;
+
+ int getGameType() const;
+ const char *getGameId() const;
+ uint32 getFeatures() const;
+ Common::Language getLanguage() const;
+
+ const PrinceGameDescription *_gameDescription;
+
+private:
+ Common::RandomSource *_rnd;
+ GraphicsMan *_graph;
+ Script *_script;
+
+ void mainLoop();
+
+};
+
+} // End of namespace Prince
+
+#endif
diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp new file mode 100644 index 0000000000..d59b373a2b --- /dev/null +++ b/engines/prince/script.cpp @@ -0,0 +1,635 @@ +#include "prince/script.h" + +#include "common/debug.h" +#include "common/debug-channels.h" +#include "common/stream.h" + +namespace Prince { + +static const uint16 NUM_OPCODES = 144; + +Script::Script(PrinceEngine *vm) : + _code(NULL), _stacktop(0), _vm(vm), _random("GroovieScripts") { +} + +Script::~Script() { + delete[] _code; +} + +bool Script::loadFromStream(Common::SeekableReadStream &stream) { + _codeSize = stream.size(); + _code = new byte[_codeSize]; + + if (!_code) + return false; + + stream.read(_code, _codeSize); + // Initialize the script + _currentInstruction = READ_LE_UINT32(_code + 4); + + return true; +} + +void Script::debugScript(const char *s, ...) { + char buf[STRINGBUFLEN]; + va_list 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); + debug("%s %s", str.c_str(), buf); +} + +void Script::step() { + _lastInstruction = _currentInstruction; + // Prepare the base debug string + Common::String dstr = Common::String::format("@0x%04X: ", _currentInstruction); + + // Get the current opcode + _lastOpcode = readScript16bits(); + + dstr += Common::String::format("op %02d: ", _lastOpcode); + + if (_lastOpcode > NUM_OPCODES) + error("Trying to execute unknown opcode %s", dstr.c_str()); + + + debug("%s", dstr.c_str()); + + // Execute the current opcode + OpcodeFunc op = _opcodes[_lastOpcode]; + (this->*op)(); +} + +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]; +} + +uint8 Script::readScript8bits() { + uint8 data = getCodeByte(_currentInstruction); + _currentInstruction++; + return data; +} + +uint16 Script::readScript16bits() { + uint8 lower = readScript8bits(); + uint8 upper = readScript8bits(); + return lower | (upper << 8); +} + +uint32 Script::readScript32bits() { + uint16 lower = readScript16bits(); + uint16 upper = readScript16bits(); + return lower | (upper << 16); +} + +void Script::O_WAITFOREVER() { + debugScript("O_WAITFOREVER"); +} + +void Script::O_BLACKPALETTE() { + debugScript("O_BLACKPALETTE"); +} + +void Script::O_SETUPPALETTE() { + debugScript("O_SETUPPALETTE"); +} + +void Script::O_INITROOM() { + uint16 roomId = readScript16bits(); + debugScript("O_INITROOM %d", roomId); +} + +void Script::O_SETSAMPLE() { + uint16 sampleId = readScript16bits(); + int32 sampleNameOffset = readScript32bits(); + const char * sampleName = (const char *)_code + _currentInstruction + sampleNameOffset - 4; + debugScript("O_SETSAMPLE %d %s", sampleName, sampleName); +} + +void Script::O_FREESAMPLE() { + uint16 sample = readScript16bits(); + debugScript("O_FREESAMPLE %d", sample); +} + +void Script::O_PLAYSAMPLE() { + uint16 sampleId = readScript16bits(); + uint16 loopType = readScript16bits(); + debugScript("O_PLAYSAMPLE sampleId %d loopType %d", sampleId, loopType); +} + +void Script::O_PUTOBJECT() { + uint16 roomId = readScript16bits(); + uint16 slot = readScript16bits(); + uint16 objectId = readScript16bits(); + debugScript("O_PUTOBJECT roomId %d, slot %d, objectId %d", roomId, slot, objectId); +} + +void Script::O_REMOBJECT() { + uint16 roomId = readScript16bits(); + uint16 objectId = readScript16bits(); + + debugScript("O_REMOBJECT roomId %d objectId %d", roomId, objectId); +} + +void Script::O_SHOWANIM() { + uint16 slot = readScript16bits(); + uint16 animId = readScript16bits(); + + debugScript("O_SHOWANIM slot %d, animId %d", slot, animId); +} + +void Script::O_CHECKANIMEND() { + uint16 slot = readScript16bits(); + uint16 frameId = readScript16bits(); + + debugScript("O_CHECKANIMEND slot %d, frameId %d", slot, frameId); +} + +void Script::O_FREEANIM() { + uint16 slot = readScript16bits(); + debugScript("O_FREEANIM slot %d", slot); +} + +void Script::O_CHECKANIMFRAME() { + uint16 slot = readScript16bits(); + uint16 frameId = readScript16bits(); + + debugScript("O_CHECKANIMFRAME slot %d, frameId %d", slot, frameId); +} + +void Script::O_PUTBACKANIM() { + uint16 roomId = readScript16bits(); + uint16 slot = readScript16bits(); + uint32 animId = readScript32bits(); + debugScript("O_PUTBACKANIM roomId %d, slot %d, animId %d", roomId, slot, animId); +} + +void Script::O_REMBACKANIM() { + uint16 roomId = readScript16bits(); + uint16 slot = readScript16bits(); + + debugScript("O_REMBACKANIM roomId %d, slot %d", roomId, slot); +} + +void Script::O_CHECKBACKANIMFRAME() {} + +void Script::O_FREEALLSAMPLES() {} + +void Script::O_SETMUSIC() {} + +void Script::O_STOPMUSIC() {} + +void Script::O__WAIT() {} + +void Script::O_UPDATEOFF() {} + +void Script::O_UPDATEON() {} + +void Script::O_UPDATE () {} + +void Script::O_CLS() {} + + +void Script::O__CALL() { + int32 address = readScript32bits(); + _stack[_stacktop] = _currentInstruction; + _stacktop++; + _currentInstruction += address - 4; + debugScript("O__CALL 0x%04X", _currentInstruction); +} +void Script::O_RETURN() { + // Get the return address + if (_stacktop > 0) { + _stacktop--; + _currentInstruction = _stack[_stacktop]; + debugScript("O_RETURN 0x%04X", _currentInstruction); + } else { + error("Return: Stack is empty"); + } +} +void Script::O_GO() { + int32 opPC = readScript32bits(); + debugScript("O_GO 0x%04X", opPC); + _currentInstruction += opPC - 4; +} +void Script::O_BACKANIMUPDATEOFF() {} + +void Script::O_BACKANIMUPDATEON() { + uint16 slot = readScript16bits(); + debugScript("O_BACKANIMUPDATEON %d", slot); +} + +void Script::O_CHANGECURSOR() { + uint16 cursorId = readScript16bits(); + debugScript("O_CHANGECURSOR %x", cursorId); +} +void Script::O_CHANGEANIMTYPE() {} +void Script::O__SETFLAG() { + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + debugScript("O__SETFLAG 0x%04X %d", flagId, value); + _flags[flagId-0x8000] = value; +} + +void Script::O_COMPARE() { + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + debugScript("O_COMPARE flagId 0x%04X, value %d", flagId, value); + _result = (_flags[flagId-0x8000] == value); +} + +void Script::O_JUMPZ() { + int32 offset = readScript32bits(); + debugScript("O_JUMPZ offset 0x%04X", offset); + if (_result == 0) + { + _currentInstruction += offset - 4; + } +} + +void Script::O_JUMPNZ() { + int32 offset = readScript32bits(); + debugScript("O_JUMPNZ offset 0x%04X", offset); + if (_result) + { + _currentInstruction += offset - 4; + } +} + +void Script::O_EXIT() {} + +void Script::O_ADDFLAG() { + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + + _flags[flagId-0x8000] += value; + if (_flags[flagId-0x8000]) + _result = 1; + else + _result = 0; + + debugScript("O_ADDFLAG flagId %d, value %d", flagId, value); +} + +void Script::O_TALKANIM() { + uint16 animSlot = readScript16bits(); + uint16 slot = readScript16bits(); + + debugScript("O_TALKANIM animSlot %d, slot %d", animSlot, slot); +} + +void Script::O_SUBFLAG() { + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + + _flags[flagId-0x8000] -= value; + if (_flags[flagId-0x8000]) + _result = 1; + else + _result = 0; + + debugScript("O_SUBFLAG flagId %d, value %d", flagId, value); +} + +void Script::O_SETSTRING() { + int32 offset = readScript32bits(); + + debugScript("O_SETSTRING 0x%04X", offset); +} + +void Script::O_ANDFLAG() {} + +void Script::O_GETMOBDATA() {} + +void Script::O_ORFLAG() {} + +void Script::O_SETMOBDATA() {} + +void Script::O_XORFLAG() {} + +void Script::O_GETMOBTEXT() {} + +void Script::O_MOVEHERO() { + uint16 heroId = readScript16bits(); + uint16 x = readScript16bits(); + uint16 y = readScript16bits(); + uint16 dir = readScript16bits(); + + debugScript("O_MOVEHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); +} + +void Script::O_WALKHERO() { + uint16 heroId = readScript16bits(); + + debugScript("O_WALKHERO %d", heroId); +} + +void Script::O_SETHERO() {} +void Script::O_HEROOFF() { + uint16 heroId = readScript16bits(); + debugScript("O_HEROOFF %d", heroId); +} + +void Script::O_HEROON() { + uint16 heroId = readScript16bits(); + debugScript("O_HEROON %d", heroId); +} + +void Script::O_CLSTEXT() {} +void Script::O_CALLTABLE() {} +void Script::O_CHANGEMOB() {} +void Script::O_ADDINV() {} +void Script::O_REMINV() {} +void Script::O_REPINV() {} +void Script::O_OBSOLETE_GETACTION() {} +void Script::O_ADDWALKAREA() {} +void Script::O_REMWALKAREA() {} +void Script::O_RESTOREWALKAREA() {} +void Script::O_WAITFRAME() {} +void Script::O_SETFRAME() {} +void Script::O_RUNACTION() {} +void Script::O_COMPAREHI() {} +void Script::O_COMPARELO() {} +void Script::O_PRELOADSET() {} +void Script::O_FREEPRELOAD() {} +void Script::O_CHECKINV() {} +void Script::O_TALKHERO() {} + +void Script::O_WAITTEXT() { + uint16 slot = readScript16bits(); + debugScript("O_WAITTEXT slot %d", slot); +} + +void Script::O_SETHEROANIM() {} +void Script::O_WAITHEROANIM() {} +void Script::O_GETHERODATA() {} +void Script::O_GETMOUSEBUTTON() {} +void Script::O_CHANGEFRAMES() {} +void Script::O_CHANGEBACKFRAMES() {} +void Script::O_GETBACKANIMDATA() {} +void Script::O_GETANIMDATA() {} +void Script::O_SETBGCODE() { + int32 bgcode = readScript32bits(); + debugScript("O_SETBGCODE %d", bgcode); +} +void Script::O_SETBACKFRAME() {} +void Script::O_GETRND() {} +void Script::O_TALKBACKANIM() {} +void Script::O_LOADPATH() {} + +void Script::O_GETCHAR() { + uint16 flagId = readScript16bits(); + debugScript("O_GETCHAR %d", flagId); +} + +void Script::O_SETDFLAG() {} +void Script::O_CALLDFLAG() {} +void Script::O_PRINTAT() {} +void Script::O_ZOOMIN() {} +void Script::O_ZOOMOUT() {} +void Script::O_SETSTRINGOFFSET() {} +void Script::O_GETOBJDATA() {} +void Script::O_SETOBJDATA() {} +void Script::O_SWAPOBJECTS() {} +void Script::O_CHANGEHEROSET() {} +void Script::O_ADDSTRING() {} +void Script::O_SUBSTRING() {} +void Script::O_INITDIALOG() {} +void Script::O_ENABLEDIALOGOPT() {} +void Script::O_DISABLEDIALOGOPT() {} +void Script::O_SHOWDIALOGBOX() {} + +void Script::O_STOPSAMPLE() { + uint16 slot = readScript16bits(); + debugScript("O_STOPSAMPLE slot %d", slot); +} + +void Script::O_BACKANIMRANGE() {} +void Script::O_CLEARPATH() {} +void Script::O_SETPATH() {} +void Script::O_GETHEROX() {} +void Script::O_GETHEROY() {} +void Script::O_GETHEROD() {} +void Script::O_PUSHSTRING() {} +void Script::O_POPSTRING() {} +void Script::O_SETFGCODE() {} +void Script::O_STOPHERO() {} +void Script::O_ANIMUPDATEOFF() {} +void Script::O_ANIMUPDATEON() {} + +void Script::O_FREECURSOR() { + debugScript("O_FREECURSOR"); +} + +void Script::O_ADDINVQUIET() {} +void Script::O_RUNHERO() {} +void Script::O_SETBACKANIMDATA() {} +void Script::O_VIEWFLC() {} +void Script::O_CHECKFLCFRAME() {} +void Script::O_CHECKFLCEND() {} +void Script::O_FREEFLC() {} +void Script::O_TALKHEROSTOP() {} +void Script::O_HEROCOLOR() {} +void Script::O_GRABMAPA() {} +void Script::O_ENABLENAK() {} +void Script::O_DISABLENAK() {} +void Script::O_GETMOBNAME() {} +void Script::O_SWAPINVENTORY() {} +void Script::O_CLEARINVENTORY() {} + +void Script::O_SKIPTEXT() { + debugScript("O_SKIPTEXT"); +} + +void Script::O_SETVOICEH() {} + +void Script::O_SETVOICEA() {} + +void Script::O_SETVOICEB() {} + +void Script::O_SETVOICEC() {} + +void Script::O_VIEWFLCLOOP() {} + +void Script::O_FLCSPEED() {} + +void Script::O_OPENINVENTORY() { + debugScript("O_OPENINVENTORY"); +} + +void Script::O_KRZYWA() { + debugScript("O_KRZYWA"); +} + +void Script::O_GETKRZYWA() { + debugScript("O_GETKRZYWA"); +} + +void Script::O_GETMOB() {} + +void Script::O_INPUTLINE() { + debugScript("O_INPUTLINE"); +} + +void Script::O_SETVOICED() {} + +void Script::O_BREAK_POINT() { + debugScript("O_BREAK_POINT"); +} + +Script::OpcodeFunc Script::_opcodes[NUM_OPCODES] = { + &Script::O_WAITFOREVER, + &Script::O_BLACKPALETTE, + &Script::O_SETUPPALETTE, + &Script::O_INITROOM, + &Script::O_SETSAMPLE, + &Script::O_FREESAMPLE, + &Script::O_PLAYSAMPLE, + &Script::O_PUTOBJECT, + &Script::O_REMOBJECT, + &Script::O_SHOWANIM, + &Script::O_CHECKANIMEND, + &Script::O_FREEANIM, + &Script::O_CHECKANIMFRAME, + &Script::O_PUTBACKANIM, + &Script::O_REMBACKANIM, + &Script::O_CHECKBACKANIMFRAME, + &Script::O_FREEALLSAMPLES, + &Script::O_SETMUSIC, + &Script::O_STOPMUSIC, + &Script::O__WAIT, + &Script::O_UPDATEOFF, + &Script::O_UPDATEON, + &Script::O_UPDATE , + &Script::O_CLS, + &Script::O__CALL, + &Script::O_RETURN, + &Script::O_GO, + &Script::O_BACKANIMUPDATEOFF, + &Script::O_BACKANIMUPDATEON, + &Script::O_CHANGECURSOR, + &Script::O_CHANGEANIMTYPE, + &Script::O__SETFLAG, + &Script::O_COMPARE, + &Script::O_JUMPZ, + &Script::O_JUMPNZ, + &Script::O_EXIT, + &Script::O_ADDFLAG, + &Script::O_TALKANIM, + &Script::O_SUBFLAG, + &Script::O_SETSTRING, + &Script::O_ANDFLAG, + &Script::O_GETMOBDATA, + &Script::O_ORFLAG, + &Script::O_SETMOBDATA, + &Script::O_XORFLAG, + &Script::O_GETMOBTEXT, + &Script::O_MOVEHERO, + &Script::O_WALKHERO, + &Script::O_SETHERO, + &Script::O_HEROOFF, + &Script::O_HEROON, + &Script::O_CLSTEXT, + &Script::O_CALLTABLE, + &Script::O_CHANGEMOB, + &Script::O_ADDINV, + &Script::O_REMINV, + &Script::O_REPINV, + &Script::O_OBSOLETE_GETACTION, + &Script::O_ADDWALKAREA, + &Script::O_REMWALKAREA, + &Script::O_RESTOREWALKAREA, + &Script::O_WAITFRAME, + &Script::O_SETFRAME, + &Script::O_RUNACTION, + &Script::O_COMPAREHI, + &Script::O_COMPARELO, + &Script::O_PRELOADSET, + &Script::O_FREEPRELOAD, + &Script::O_CHECKINV, + &Script::O_TALKHERO, + &Script::O_WAITTEXT, + &Script::O_SETHEROANIM, + &Script::O_WAITHEROANIM, + &Script::O_GETHERODATA, + &Script::O_GETMOUSEBUTTON, + &Script::O_CHANGEFRAMES, + &Script::O_CHANGEBACKFRAMES, + &Script::O_GETBACKANIMDATA, + &Script::O_GETANIMDATA, + &Script::O_SETBGCODE, + &Script::O_SETBACKFRAME, + &Script::O_GETRND, + &Script::O_TALKBACKANIM, + &Script::O_LOADPATH, + &Script::O_GETCHAR, + &Script::O_SETDFLAG, + &Script::O_CALLDFLAG, + &Script::O_PRINTAT, + &Script::O_ZOOMIN, + &Script::O_ZOOMOUT, + &Script::O_SETSTRINGOFFSET, + &Script::O_GETOBJDATA, + &Script::O_SETOBJDATA, + &Script::O_SWAPOBJECTS, + &Script::O_CHANGEHEROSET, + &Script::O_ADDSTRING, + &Script::O_SUBSTRING, + &Script::O_INITDIALOG, + &Script::O_ENABLEDIALOGOPT, + &Script::O_DISABLEDIALOGOPT, + &Script::O_SHOWDIALOGBOX, + &Script::O_STOPSAMPLE, + &Script::O_BACKANIMRANGE, + &Script::O_CLEARPATH, + &Script::O_SETPATH, + &Script::O_GETHEROX, + &Script::O_GETHEROY, + &Script::O_GETHEROD, + &Script::O_PUSHSTRING, + &Script::O_POPSTRING, + &Script::O_SETFGCODE, + &Script::O_STOPHERO, + &Script::O_ANIMUPDATEOFF, + &Script::O_ANIMUPDATEON, + &Script::O_FREECURSOR, + &Script::O_ADDINVQUIET, + &Script::O_RUNHERO, + &Script::O_SETBACKANIMDATA, + &Script::O_VIEWFLC, + &Script::O_CHECKFLCFRAME, + &Script::O_CHECKFLCEND, + &Script::O_FREEFLC, + &Script::O_TALKHEROSTOP, + &Script::O_HEROCOLOR, + &Script::O_GRABMAPA, + &Script::O_ENABLENAK, + &Script::O_DISABLENAK, + &Script::O_GETMOBNAME, + &Script::O_SWAPINVENTORY, + &Script::O_CLEARINVENTORY, + &Script::O_SKIPTEXT, + &Script::O_SETVOICEH, + &Script::O_SETVOICEA, + &Script::O_SETVOICEB, + &Script::O_SETVOICEC, + &Script::O_VIEWFLCLOOP, + &Script::O_FLCSPEED, + &Script::O_OPENINVENTORY, + &Script::O_KRZYWA, + &Script::O_GETKRZYWA, + &Script::O_GETMOB, + &Script::O_INPUTLINE, + &Script::O_SETVOICED, + &Script::O_BREAK_POINT, +}; + +} + diff --git a/engines/prince/script.h b/engines/prince/script.h new file mode 100644 index 0000000000..08488d3877 --- /dev/null +++ b/engines/prince/script.h @@ -0,0 +1,372 @@ +/* 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. + * + */ + +#ifndef PRINCE_SCRIPT_H +#define PRINCE_SCRIPT_H + +#include "common/random.h" + +namespace Common { + class SeekableReadStream; +} + +namespace Prince { + +class PrinceEngine; + +class Script +{ +public: + Script(PrinceEngine *vm); + virtual ~Script(); + + bool loadFromStream(Common::SeekableReadStream &stream); + + void step(); + +private: + PrinceEngine *_vm; + + Common::RandomSource _random; + + byte *_code; + uint32 _codeSize; + uint32 _currentInstruction; + uint16 _lastOpcode; + uint32 _lastInstruction; + byte _result; + int16 _flags[2000]; + + // Stack + uint16 _stack[500]; + uint8 _stacktop; + uint8 _savedStacktop; + + // Helper functions + void checkPC(uint32 address); + uint8 getCodeByte(uint32 address); + uint8 readScript8bits(); + uint16 readScript16bits(); + uint32 readScript32bits(); + uint16 readScript8or16bits(); + void debugScript(const char *s, ...); + + typedef void (Script::*OpcodeFunc)(); + static OpcodeFunc _opcodes[]; + + void O_WAITFOREVER(); + void O_BLACKPALETTE(); + void O_SETUPPALETTE(); + void O_INITROOM(); + void O_SETSAMPLE(); + void O_FREESAMPLE(); + void O_PLAYSAMPLE(); + void O_PUTOBJECT(); + void O_REMOBJECT(); + void O_SHOWANIM(); + void O_CHECKANIMEND(); + void O_FREEANIM(); + void O_CHECKANIMFRAME(); + void O_PUTBACKANIM(); + void O_REMBACKANIM(); + void O_CHECKBACKANIMFRAME(); + void O_FREEALLSAMPLES(); + void O_SETMUSIC(); + void O_STOPMUSIC(); + void O__WAIT(); + void O_UPDATEOFF(); + void O_UPDATEON(); + void O_UPDATE (); + void O_CLS(); + void O__CALL(); + void O_RETURN(); + void O_GO(); + void O_BACKANIMUPDATEOFF(); + void O_BACKANIMUPDATEON(); + void O_CHANGECURSOR(); + void O_CHANGEANIMTYPE(); + void O__SETFLAG(); + void O_COMPARE(); + void O_JUMPZ(); + void O_JUMPNZ(); + void O_EXIT(); + void O_ADDFLAG(); + void O_TALKANIM(); + void O_SUBFLAG(); + void O_SETSTRING(); + void O_ANDFLAG(); + void O_GETMOBDATA(); + void O_ORFLAG(); + void O_SETMOBDATA(); + void O_XORFLAG(); + void O_GETMOBTEXT(); + void O_MOVEHERO(); + void O_WALKHERO(); + void O_SETHERO(); + void O_HEROOFF(); + void O_HEROON(); + void O_CLSTEXT(); + void O_CALLTABLE(); + void O_CHANGEMOB(); + void O_ADDINV(); + void O_REMINV(); + void O_REPINV(); + void O_OBSOLETE_GETACTION(); + void O_ADDWALKAREA(); + void O_REMWALKAREA(); + void O_RESTOREWALKAREA(); + void O_WAITFRAME(); + void O_SETFRAME(); + void O_RUNACTION(); + void O_COMPAREHI(); + void O_COMPARELO(); + void O_PRELOADSET(); + void O_FREEPRELOAD(); + void O_CHECKINV(); + void O_TALKHERO(); + void O_WAITTEXT(); + void O_SETHEROANIM(); + void O_WAITHEROANIM(); + void O_GETHERODATA(); + void O_GETMOUSEBUTTON(); + void O_CHANGEFRAMES(); + void O_CHANGEBACKFRAMES(); + void O_GETBACKANIMDATA(); + void O_GETANIMDATA(); + void O_SETBGCODE(); + void O_SETBACKFRAME(); + void O_GETRND(); + void O_TALKBACKANIM(); + void O_LOADPATH(); + void O_GETCHAR(); + void O_SETDFLAG(); + void O_CALLDFLAG(); + void O_PRINTAT(); + void O_ZOOMIN(); + void O_ZOOMOUT(); + void O_SETSTRINGOFFSET(); + void O_GETOBJDATA(); + void O_SETOBJDATA(); + void O_SWAPOBJECTS(); + void O_CHANGEHEROSET(); + void O_ADDSTRING(); + void O_SUBSTRING(); + void O_INITDIALOG(); + void O_ENABLEDIALOGOPT(); + void O_DISABLEDIALOGOPT(); + void O_SHOWDIALOGBOX(); + void O_STOPSAMPLE(); + void O_BACKANIMRANGE(); + void O_CLEARPATH(); + void O_SETPATH(); + void O_GETHEROX(); + void O_GETHEROY(); + void O_GETHEROD(); + void O_PUSHSTRING(); + void O_POPSTRING(); + void O_SETFGCODE(); + void O_STOPHERO(); + void O_ANIMUPDATEOFF(); + void O_ANIMUPDATEON(); + void O_FREECURSOR(); + void O_ADDINVQUIET(); + void O_RUNHERO(); + void O_SETBACKANIMDATA(); + void O_VIEWFLC(); + void O_CHECKFLCFRAME(); + void O_CHECKFLCEND(); + void O_FREEFLC(); + void O_TALKHEROSTOP(); + void O_HEROCOLOR(); + void O_GRABMAPA(); + void O_ENABLENAK(); + void O_DISABLENAK(); + void O_GETMOBNAME(); + void O_SWAPINVENTORY(); + void O_CLEARINVENTORY(); + void O_SKIPTEXT(); + void O_SETVOICEH(); + void O_SETVOICEA(); + void O_SETVOICEB(); + void O_SETVOICEC(); + void O_VIEWFLCLOOP(); + void O_FLCSPEED(); + void O_OPENINVENTORY(); + void O_KRZYWA(); + void O_GETKRZYWA(); + void O_GETMOB(); + void O_INPUTLINE(); + void O_SETVOICED(); + void O_BREAK_POINT(); + + +#if 0 + O_WAITFOREVER ;00 + O_BLACKPALETTE ;01 + O_SETUPPALETTE ;02 + O_INITROOM ;03 + O_SETSAMPLE ;04 + O_FREESAMPLE ;05 + O_PLAYSAMPLE ;06 + O_PUTOBJECT ;07 + O_REMOBJECT ;08 + O_SHOWANIM ;09 + O_CHECKANIMEND ;10 + O_FREEANIM ;11 + O_CHECKANIMFRAME ;12 + O_PUTBACKANIM ;13 + O_REMBACKANIM ;14 + O_CHECKBACKANIMFRAME ;15 + O_FREEALLSAMPLES ;16 + O_SETMUSIC ;17 + O_STOPMUSIC ;18 + O__WAIT ;19 + O_UPDATEOFF ;20 + O_UPDATEON ;21 + O_UPDATE ;22 + O_CLS ;23 + O__CALL ;24 + O_RETURN ;25 + O_GO ;26 + O_BACKANIMUPDATEOFF ;27 + O_BACKANIMUPDATEON ;28 + O_CHANGECURSOR ;29 + O_CHANGEANIMTYPE ;30 + O__SETFLAG ;31 + O_COMPARE ;32 + O_JUMPZ ;33 + O_JUMPNZ ;34 + O_EXIT ;35 + O_ADDFLAG ;36 + O_TALKANIM ;37 + O_SUBFLAG ;38 + O_SETSTRING ;39 + O_ANDFLAG ;40 + O_GETMOBDATA ;41 + O_ORFLAG ;42 + O_SETMOBDATA ;43 + O_XORFLAG ;44 + O_GETMOBTEXT ;45 + O_MOVEHERO ;46 + O_WALKHERO ;47 + O_SETHERO ;48 + O_HEROOFF ;49 + O_HEROON ;50 + O_CLSTEXT ;51 + O_CALLTABLE ;52 + O_CHANGEMOB ;53 + O_ADDINV ;54 + O_REMINV ;55 + O_REPINV ;56 + O_OBSOLETE_GETACTION ;57 + O_ADDWALKAREA ;58 + O_REMWALKAREA ;59 + O_RESTOREWALKAREA ;60 + O_WAITFRAME ;61 + O_SETFRAME ;62 + O_RUNACTION ;63 + O_COMPAREHI ;64 + O_COMPARELO ;65 + O_PRELOADSET ;66 + O_FREEPRELOAD ;67 + O_CHECKINV ;68 + O_TALKHERO ;69 + O_WAITTEXT ;70 + O_SETHEROANIM ;71 + O_WAITHEROANIM ;72 + O_GETHERODATA ;73 + O_GETMOUSEBUTTON ;74 + O_CHANGEFRAMES ;75 + O_CHANGEBACKFRAMES ;76 + O_GETBACKANIMDATA ;77 + O_GETANIMDATA ;78 + O_SETBGCODE ;79 + O_SETBACKFRAME ;80 + O_GETRND ;81 + O_TALKBACKANIM ;82 + O_LOADPATH ;83 + O_GETCHAR ;84 + O_SETDFLAG ;85 + O_CALLDFLAG ;86 + O_PRINTAT ;87 + O_ZOOMIN ;88 + O_ZOOMOUT ;89 + O_SETSTRINGOFFSET ;90 + O_GETOBJDATA ;91 + O_SETOBJDATA ;92 + O_SWAPOBJECTS ;93 + O_CHANGEHEROSET ;94 + O_ADDSTRING ;95 + O_SUBSTRING ;96 + O_INITDIALOG ;97 + O_ENABLEDIALOGOPT ;98 + O_DISABLEDIALOGOPT ;99 + O_SHOWDIALOGBOX ;100 + O_STOPSAMPLE ;101 + O_BACKANIMRANGE ;102 + O_CLEARPATH ;103 + O_SETPATH ;104 + O_GETHEROX ;105 + O_GETHEROY ;106 + O_GETHEROD ;107 + O_PUSHSTRING ;108 + O_POPSTRING ;109 + O_SETFGCODE ;110 + O_STOPHERO ;111 + O_ANIMUPDATEOFF ;112 + O_ANIMUPDATEON ;113 + O_FREECURSOR ;114 + O_ADDINVQUIET ;115 + O_RUNHERO ;116 + O_SETBACKANIMDATA ;117 + O_VIEWFLC ;118 + O_CHECKFLCFRAME ;119 + O_CHECKFLCEND ;120 + O_FREEFLC ;121 + O_TALKHEROSTOP ;122 + O_HEROCOLOR ;123 + O_GRABMAPA ;124 + O_ENABLENAK ;125 + O_DISABLENAK ;126 + O_GETMOBNAME ;127 + O_SWAPINVENTORY ;128 + O_CLEARINVENTORY ;129 + O_SKIPTEXT ;130 + O_SETVOICEH ;131 + O_SETVOICEA ;132 + O_SETVOICEB ;133 + O_SETVOICEC ;134 + O_VIEWFLCLOOP ;135 + O_FLCSPEED ;136 + O_OPENINVENTORY ;137 + O_KRZYWA ;138 + O_GETKRZYWA ;139 + O_GETMOB ;140 + O_INPUTLINE ;141 + O_SETVOICED ;142 + O_BREAK_POINT ;143 +#endif +}; + +} + +#endif |