diff options
Diffstat (limited to 'engines/prince')
-rw-r--r-- | engines/prince/debugger.cpp | 2 | ||||
-rw-r--r-- | engines/prince/graphics.cpp | 56 | ||||
-rw-r--r-- | engines/prince/graphics.h | 22 | ||||
-rw-r--r-- | engines/prince/module.mk | 2 | ||||
-rw-r--r-- | engines/prince/musNum.h | 184 | ||||
-rw-r--r-- | engines/prince/object.cpp | 61 | ||||
-rw-r--r-- | engines/prince/object.h | 13 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 920 | ||||
-rw-r--r-- | engines/prince/prince.h | 244 | ||||
-rw-r--r-- | engines/prince/script.cpp | 1042 | ||||
-rw-r--r-- | engines/prince/script.h | 360 | ||||
-rw-r--r-- | engines/prince/sound.cpp | 70 | ||||
-rw-r--r-- | engines/prince/sound.h | 32 | ||||
-rw-r--r-- | engines/prince/variatxt.cpp | 16 | ||||
-rw-r--r-- | engines/prince/variatxt.h | 8 |
15 files changed, 1636 insertions, 1396 deletions
diff --git a/engines/prince/debugger.cpp b/engines/prince/debugger.cpp index 1a78049f91..2415c1c7ce 100644 --- a/engines/prince/debugger.cpp +++ b/engines/prince/debugger.cpp @@ -107,7 +107,7 @@ bool Debugger::Cmd_ViewFlc(int argc, const char **argv) { } int flagNum = strToInt(argv[1]); - _vm->loadAnim(flagNum); + _vm->loadAnim(flagNum, false); return true; } diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index 94cab7bb37..29d3a331df 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -29,51 +29,53 @@ namespace Prince { GraphicsMan::GraphicsMan(PrinceEngine *vm) - : _vm(vm), _changed(false) { - initGraphics(640, 480, true); - _frontScreen = new Graphics::Surface(); - _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); + : _vm(vm), _changed(false) { + initGraphics(640, 480, true); + _frontScreen = new Graphics::Surface(); + _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); } void GraphicsMan::update() { - if (_changed) { - _vm->_system->copyRectToScreen((byte*)_frontScreen->getBasePtr(0,0), 640, 0, 0, 640, 480); + if (_changed) { + _vm->_system->copyRectToScreen((byte*)_frontScreen->getBasePtr(0,0), 640, 0, 0, 640, 480); - _vm->_system->updateScreen(); - _changed = false; - } + _vm->_system->updateScreen(); + _changed = false; + } } void GraphicsMan::setPalette(const byte *palette) { - _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); + _vm->_system->getPaletteManager()->setPalette(palette, 0, 256); } void GraphicsMan::change() { - _changed = true; + _changed = true; } -void GraphicsMan::draw(const Graphics::Surface *s) +void GraphicsMan::draw(uint16 posX, uint16 posY, const Graphics::Surface *s) { - uint16 w = MIN(_frontScreen->w, s->w); - for (uint y = 0; y < s->h; y++) { - if (y < _frontScreen->h) { - memcpy((byte*)_frontScreen->getBasePtr(0, y), (byte*)s->getBasePtr(0, y), w); - } - } - change(); + uint16 w = MIN(_frontScreen->w, s->w); + for (uint y = 0; y < s->h; y++) { + if (y < _frontScreen->h) { + memcpy((byte*)_frontScreen->getBasePtr(0, y), (byte*)s->getBasePtr(0, y), w); + } + } + change(); } void GraphicsMan::drawTransparent(const Graphics::Surface *s) { - for (uint y = 0; y < s->h; ++y) { - for (uint x = 0; x < s->w; ++x) { - byte pixel = *((byte*)s->getBasePtr(x,y)); - if (pixel != 255) { - *((byte*)_frontScreen->getBasePtr(x, y)) = pixel; - } - } - } + for (uint y = 0; y < s->h; ++y) { + for (uint x = 0; x < s->w; ++x) { + byte pixel = *((byte*)s->getBasePtr(x,y)); + if (pixel != 255) { + *((byte*)_frontScreen->getBasePtr(x, y)) = pixel; + } + } + } change(); } } + +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h index 0e29c5c97a..3ef768a073 100644 --- a/engines/prince/graphics.h +++ b/engines/prince/graphics.h @@ -33,26 +33,26 @@ class PrinceEngine; class GraphicsMan { public: - GraphicsMan(PrinceEngine *vm); + GraphicsMan(PrinceEngine *vm); - void update(); + void update(); - void change(); + void change(); - void setPalette(const byte *palette); + void setPalette(const byte *palette); - void draw(const Graphics::Surface *s); - void drawTransparent(const Graphics::Surface *s); + void draw(uint16 x, uint16 y, const Graphics::Surface *s); + void drawTransparent(const Graphics::Surface *s); - Graphics::Surface *_frontScreen; - Graphics::Surface *_backScreen; - const Graphics::Surface *_roomBackground; + Graphics::Surface *_frontScreen; + Graphics::Surface *_backScreen; + const Graphics::Surface *_roomBackground; private: - PrinceEngine *_vm; + PrinceEngine *_vm; - bool _changed; + bool _changed; }; } diff --git a/engines/prince/module.mk b/engines/prince/module.mk index 6b519d4d57..8bdccdf74d 100644 --- a/engines/prince/module.mk +++ b/engines/prince/module.mk @@ -10,6 +10,8 @@ MODULE_OBJS = \ mob.o \
object.o \
sound.o \
+ flags.o \
+ variatxt.o \
prince.o
# This module can be built as a plugin
diff --git a/engines/prince/musNum.h b/engines/prince/musNum.h index 1319438940..cb81332604 100644 --- a/engines/prince/musNum.h +++ b/engines/prince/musNum.h @@ -1,92 +1,92 @@ -/* 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.
- *
- */
-
-/*
- * This code is based on original Soltys source code
- * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
- */
-
-namespace Prince {
-
-enum RoomMus {
-ROOM01MUS =3,
-ROOM02MUS =9,
-ROOM03MUS =9,
-ROOM04MUS =9,
-ROOM05MUS =13,
-ROOM06MUS =9,
-ROOM07MUS =9,
-ROOM08MUS =9,
-ROOM09MUS =14,
-ROOM10MUS =9,
-ROOM11MUS =9,
-ROOM12MUS =9,
-ROOM13MUS =9,
-ROOM14MUS =9,
-ROOM15MUS =5,
-ROOM16MUS =5,
-ROOM17MUS =5,
-ROOM18MUS =5,
-ROOM19MUS =5,
-ROOM20MUS =12,
-ROOM21MUS =9,
-ROOM22MUS =9,
-ROOM23MUS =1,
-ROOM24MUS =1,
-ROOM25MUS =2,
-ROOM26MUS =10,
-ROOM27MUS =7,
-ROOM28MUS =10,
-ROOM29MUS =10,
-ROOM30MUS =11,
-ROOM31MUS =14,
-ROOM32MUS =11,
-ROOM33MUS =7,
-ROOM34MUS =7,
-ROOM35MUS =7,
-ROOM36MUS =7,
-ROOM37MUS =7,
-ROOM38MUS =7,
-ROOM39MUS =7,
-ROOM40MUS =7,
-ROOM41MUS =7,
-ROOM42MUS =7,
-ROOM43MUS =15,
-ROOM46MUS =100,
-ROOM47MUS =100,
-ROOM48MUS =100,
-ROOM49MUS =100,
-ROOM50MUS =100,
-ROOM51MUS =12,
-ROOM52MUS =9,
-ROOM53MUS =5,
-ROOM54MUS =11,
-ROOM55MUS =11,
-ROOM56MUS =11,
-ROOM57MUS =7,
-ROOM58MUS =13,
-ROOM59MUS =16,
-ROOM60MUS =4,
-ROOM61MUS =0
-};
-
-}
+/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +namespace Prince { + +enum RoomMus { +ROOM01MUS =3, +ROOM02MUS =9, +ROOM03MUS =9, +ROOM04MUS =9, +ROOM05MUS =13, +ROOM06MUS =9, +ROOM07MUS =9, +ROOM08MUS =9, +ROOM09MUS =14, +ROOM10MUS =9, +ROOM11MUS =9, +ROOM12MUS =9, +ROOM13MUS =9, +ROOM14MUS =9, +ROOM15MUS =5, +ROOM16MUS =5, +ROOM17MUS =5, +ROOM18MUS =5, +ROOM19MUS =5, +ROOM20MUS =12, +ROOM21MUS =9, +ROOM22MUS =9, +ROOM23MUS =1, +ROOM24MUS =1, +ROOM25MUS =2, +ROOM26MUS =10, +ROOM27MUS =7, +ROOM28MUS =10, +ROOM29MUS =10, +ROOM30MUS =11, +ROOM31MUS =14, +ROOM32MUS =11, +ROOM33MUS =7, +ROOM34MUS =7, +ROOM35MUS =7, +ROOM36MUS =7, +ROOM37MUS =7, +ROOM38MUS =7, +ROOM39MUS =7, +ROOM40MUS =7, +ROOM41MUS =7, +ROOM42MUS =7, +ROOM43MUS =15, +ROOM46MUS =100, +ROOM47MUS =100, +ROOM48MUS =100, +ROOM49MUS =100, +ROOM50MUS =100, +ROOM51MUS =12, +ROOM52MUS =9, +ROOM53MUS =5, +ROOM54MUS =11, +ROOM55MUS =11, +ROOM56MUS =11, +ROOM57MUS =7, +ROOM58MUS =13, +ROOM59MUS =16, +ROOM60MUS =4, +ROOM61MUS =0 +}; + +} diff --git a/engines/prince/object.cpp b/engines/prince/object.cpp index 72d4f1103a..9f7efcfb88 100644 --- a/engines/prince/object.cpp +++ b/engines/prince/object.cpp @@ -36,42 +36,43 @@ Object::Object() : _surface(NULL) { } void Object::loadSurface(Common::SeekableReadStream &stream) { - stream.skip(4); + stream.skip(4); - _surface = new Graphics::Surface(); - _surface->create(stream.readUint16LE(), stream.readUint16LE(), Graphics::PixelFormat::createFormatCLUT8()); - for (int h = 0; h < _surface->h; ++h) { - stream.read(_surface->getBasePtr(0, h), _surface->w); - } + _surface = new Graphics::Surface(); + _surface->create(stream.readUint16LE(), stream.readUint16LE(), Graphics::PixelFormat::createFormatCLUT8()); + for (int h = 0; h < _surface->h; ++h) { + stream.read(_surface->getBasePtr(0, h), _surface->w); + } } bool Object::loadFromStream(Common::SeekableReadStream &stream) { - int32 pos = stream.pos(); - uint16 x = stream.readUint16LE(); - if (x == 0xFFFF) - return false; - _x = x; - _y = stream.readUint16LE(); - - const Common::String obStreamName = Common::String::format("OB%02d", stream.readUint16LE()); - Common::SeekableReadStream *obStream = SearchMan.createReadStreamForMember(obStreamName); - if (!obStream) { - error("Can't load %s", obStreamName.c_str()); - return false; - } - - loadSurface(*obStream); - delete obStream; - - _z = stream.readUint16LE(); - - stream.seek(pos + 16); - - debug("Object x %d, y %d, z %d", _x, _y, _z); - - return true; + int32 pos = stream.pos(); + uint16 x = stream.readUint16LE(); + if (x == 0xFFFF) + return false; + _x = x; + _y = stream.readUint16LE(); + + const Common::String obStreamName = Common::String::format("OB%02d", stream.readUint16LE()); + Common::SeekableReadStream *obStream = SearchMan.createReadStreamForMember(obStreamName); + if (!obStream) { + error("Can't load %s", obStreamName.c_str()); + return false; + } + + loadSurface(*obStream); + delete obStream; + + _z = stream.readUint16LE(); + + stream.seek(pos + 16); + + debug("Object x %d, y %d, z %d", _x, _y, _z); + + return true; } } +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/object.h b/engines/prince/object.h index 3a8859c196..2c2dbc9fbf 100644 --- a/engines/prince/object.h +++ b/engines/prince/object.h @@ -30,18 +30,19 @@ namespace Prince { class Object { public: - Object(); + Object(); - bool loadFromStream(Common::SeekableReadStream &stream); - Graphics::Surface *getSurface() const { return _surface; } + bool loadFromStream(Common::SeekableReadStream &stream); + Graphics::Surface *getSurface() const { return _surface; } private: - void loadSurface(Common::SeekableReadStream &stream); + void loadSurface(Common::SeekableReadStream &stream); - Graphics::Surface *_surface; - uint16 _x, _y, _z; + Graphics::Surface *_surface; + uint16 _x, _y, _z; }; } #endif +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index a9f243ce11..9ca7a62fad 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -1,415 +1,505 @@ -/* 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 "engines/util.h"
-#include "engines/advancedDetector.h"
-
-#include "audio/audiostream.h"
-
-#include "prince/prince.h"
-#include "prince/font.h"
-#include "prince/graphics.h"
-#include "prince/script.h"
-#include "prince/debugger.h"
-#include "prince/object.h"
-#include "prince/mob.h"
-#include "prince/sound.h"
-
-#include "video/flic_decoder.h"
-
-namespace Prince {
-
-Graphics::Surface *loadCursor(const char *curName)
-{
- Common::SeekableReadStream *curStream = SearchMan.createReadStreamForMember(curName);
- if (!curStream) {
- error("Can't load %s", curName);
- return NULL;
- }
-
- curStream->skip(4);
- uint16 w = curStream->readUint16LE();
- uint16 h = curStream->readUint16LE();
-
- debug("Loading cursor %s, w %d, h %d", curName, w, h);
-
- Graphics::Surface *curSurface = new Graphics::Surface();
- curSurface->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
- for (int ih = 0; ih < h; ++ih) {
- curStream->read(curSurface->getBasePtr(0, ih), w);
- }
-
- delete curStream;
- return curSurface;
-}
-
-
-
-PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) :
- Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL),
- _locationNr(0), _debugger(NULL), _objectList(NULL), _mobList(NULL), _midiPlayer(NULL) {
- _rnd = new Common::RandomSource("prince");
- _debugger = new Debugger(this);
- _midiPlayer = new MusicPlayer(this);
-}
-
-PrinceEngine::~PrinceEngine() {
- DebugMan.clearAllDebugChannels();
-
- delete _rnd;
- delete _debugger;
- delete _cur1;
- delete _cur2;
- delete _midiPlayer;
-}
-
-GUI::Debugger *PrinceEngine::getDebugger() {
- return _debugger;
-}
-
-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);
-
- Common::SeekableReadStream *font1stream = SearchMan.createReadStreamForMember("font1.raw");
- if (!font1stream)
- return Common::kPathNotFile;
-
- if (_font.load(*font1stream)) {
- _font.getCharWidth(103);
- }
- delete font1stream;
-
- Common::SeekableReadStream * walizka = SearchMan.createReadStreamForMember("walizka");
- if (!walizka)
- return Common::kPathDoesNotExist;
-
- debug("Loading walizka");
- if (!_walizkaBmp.loadStream(*walizka)) {
- return Common::kPathDoesNotExist;
- }
-
- Common::SeekableReadStream * skryptStream = SearchMan.createReadStreamForMember("skrypt.dat");
- if (!skryptStream)
- return Common::kPathNotFile;
-
- debug("Loading skrypt");
- _script = new Script(this);
- _script->loadFromStream(*skryptStream);
-
- delete skryptStream;
-
-
- _cur1 = loadCursor("mouse1.cur");
- _cur2 = loadCursor("mouse2.cur");
-
- Common::SeekableReadStream *logoStream = SearchMan.createReadStreamForMember("logo.raw");
- if (logoStream)
- {
- MhwanhDecoder logo;
- logo.loadStream(*logoStream);
- _graph->setPalette(logo.getPalette());
- _graph->draw(logo.getSurface());
- _graph->update();
- _system->delayMillis(700);
- }
- delete logoStream;
-
- mainLoop();
-
- return Common::kNoError;
-}
-
-class MobList {
-public:
- bool loadFromStream(Common::SeekableReadStream &stream);
-
- Common::Array<Mob> _mobList;
-};
-
-bool MobList::loadFromStream(Common::SeekableReadStream &stream)
-{
- Mob mob;
- while (mob.loadFromStream(stream))
- _mobList.push_back(mob);
-
- return true;
-}
-
-class ObjectList {
-public:
- bool loadFromStream(Common::SeekableReadStream &stream);
-
- Common::Array<Object> _objList;
-};
-
-bool ObjectList::loadFromStream(Common::SeekableReadStream &stream)
-{
- Object obj;
- while (obj.loadFromStream(stream))
- _objList.push_back(obj);
-
- return true;
-}
-
-bool PrinceEngine::loadLocation(uint16 locationNr) {
- debug("PrinceEngine::loadLocation %d", locationNr);
- const Common::FSNode gameDataDir(ConfMan.get("path"));
- SearchMan.remove(Common::String::format("%02d", _locationNr));
- _locationNr = locationNr;
-
- const Common::String locationNrStr = Common::String::format("%02d", _locationNr);
- debug("loadLocation %s", locationNrStr.c_str());
- SearchMan.addSubDirectoryMatching(gameDataDir, locationNrStr, 0, 2);
-
- // load location background
- Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room");
-
- if (!room) {
- error("Can't load room bitmap");
- return false;
- }
-
- if(_roomBmp.loadStream(*room)) {
- debug("Room bitmap loaded");
- }
-
- delete room;
-
- delete _mobList;
- _mobList = NULL;
-
- Common::SeekableReadStream *mobListStream = SearchMan.createReadStreamForMember("mob.lst");
- if (!mobListStream) {
- error("Can't read mob.lst");
- return false;
- }
-
- _mobList = new MobList();
- _mobList->loadFromStream(*mobListStream);
-
- delete mobListStream;
-
- delete _objectList;
- _objectList = NULL;
-
- Common::SeekableReadStream *objListStream = SearchMan.createReadStreamForMember("obj.lst");
- if (!objListStream) {
- error("Can't read obj.lst");
- return false;
- }
-
- _objectList = new ObjectList();
- _objectList->loadFromStream(*objListStream);
- delete objListStream;
-
- const char *musName = MusicPlayer::_musTable[MusicPlayer::_musRoomTable[locationNr]];
- _midiPlayer->loadMidi(musName);
-
- return true;
-}
-
-void PrinceEngine::changeCursor(uint16 curId)
-{
- Graphics::Surface *curSurface = NULL;
-
- uint16 hotspotX = 0;
- uint16 hotspotY = 0;
-
- switch(curId) {
- case 0:
- CursorMan.showMouse(false);
- return;
- case 1:
- curSurface = _cur1;
- break;
- case 2:
- curSurface = _cur2;
- hotspotX = curSurface->w >> 1;
- hotspotY = curSurface->h >> 1;
- break;
- }
-
- CursorMan.replaceCursorPalette(_roomBmp.getPalette(), 0, 255);
- CursorMan.replaceCursor(
- curSurface->getBasePtr(0, 0),
- curSurface->w, curSurface->h,
- hotspotX, hotspotY,
- 255, false,
- &curSurface->format
- );
- CursorMan.showMouse(true);
-}
-
-bool PrinceEngine::playNextFrame() {
- const Graphics::Surface *s = _flicPlayer.decodeNextFrame();
- if (s) {
- _graph->drawTransparent(s);
- _graph->change();
- }
-
- return true;
-}
-
-bool PrinceEngine::loadAnim(uint16 animNr) {
- Common::String streamName = Common::String::format("AN%02d", animNr);
- Common::SeekableReadStream * flicStream = SearchMan.createReadStreamForMember(streamName);
-
- if (!flicStream) {
- error("Can't open %s", streamName.c_str());
- return false;
- }
-
- if (!_flicPlayer.loadStream(flicStream)) {
- error("Can't load flic stream %s", streamName.c_str());
- }
-
- debug("%s loaded", streamName.c_str());
- _flicPlayer.start();
- return true;
-}
-
-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;
- }
- }
-}
-
-void PrinceEngine::hotspot() {
- Common::Point mousepos = _system->getEventManager()->getMousePos();
-
- Common::Array<Mob>::iterator it = _mobList->_mobList.begin();
- for (; it != _mobList->_mobList.end(); ++it) {
- if (it->_visible)
- continue;
- if (it->_rect.contains(mousepos)) {
- uint16 textW = 0;
- for (int i = 0; i < it->_name.size(); ++i)
- textW += _font.getCharWidth(it->_name[i]);
-
- uint16 x = mousepos.x - textW/2;
- if (x > _graph->_frontScreen->w)
- x = 0;
-
- if (x + textW > _graph->_frontScreen->w)
- x = _graph->_frontScreen->w - textW;
-
- _font.drawString(
- _graph->_frontScreen,
- it->_name,
- x,
- mousepos.y - _font.getFontHeight(),
- _graph->_frontScreen->w,
- 216
- );
- break;
- }
- }
-}
-
-void PrinceEngine::mainLoop() {
-
- loadLocation(1);
- changeCursor(1);
- CursorMan.showMouse(true);
-
- while (!shouldQuit()) {
- _debugger->onFrame();
- Common::Event event;
- Common::EventManager *eventMan = _system->getEventManager();
- while (eventMan->pollEvent(event)) {
- switch (event.type) {
- case Common::EVENT_KEYDOWN:
- keyHandler(event);
- 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();
-
- if (_roomBmp.getSurface()) {
- _graph->setPalette(_roomBmp.getPalette());
- _graph->draw(_roomBmp.getSurface());
- }
-
- playNextFrame();
-
- //debug("Cursor visible %d", CursorMan.isVisible());
-
- //if (_objectList)
- // _graph->drawTransparent(_objectList->getSurface());
-
- hotspot();
-
- _graph->update();
-
- _system->delayMillis(40);
-
- }
-}
-
-} // End of namespace Prince
+/* 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 "engines/util.h" +#include "engines/advancedDetector.h" + +#include "audio/audiostream.h" + +#include "prince/prince.h" +#include "prince/font.h" +#include "prince/graphics.h" +#include "prince/script.h" +#include "prince/debugger.h" +#include "prince/object.h" +#include "prince/mob.h" +#include "prince/sound.h" +#include "prince/variatxt.h" + +#include "video/flic_decoder.h" + +namespace Prince { + +Graphics::Surface *loadCursor(const char *curName) +{ + Common::SeekableReadStream *curStream = SearchMan.createReadStreamForMember(curName); + if (!curStream) { + error("Can't load %s", curName); + return NULL; + } + + curStream->skip(4); + uint16 w = curStream->readUint16LE(); + uint16 h = curStream->readUint16LE(); + + debug("Loading cursor %s, w %d, h %d", curName, w, h); + + Graphics::Surface *curSurface = new Graphics::Surface(); + curSurface->create(w, h, Graphics::PixelFormat::createFormatCLUT8()); + for (int ih = 0; ih < h; ++ih) { + curStream->read(curSurface->getBasePtr(0, ih), w); + } + + delete curStream; + return curSurface; +} + + + +PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) : + Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL), + _locationNr(0), _debugger(NULL), _objectList(NULL), _mobList(NULL), _midiPlayer(NULL), + _cameraX(0), _newCameraX(0) { + _rnd = new Common::RandomSource("prince"); + _debugger = new Debugger(this); + _midiPlayer = new MusicPlayer(this); + _textSlots[0] = ""; +} + +PrinceEngine::~PrinceEngine() { + DebugMan.clearAllDebugChannels(); + + delete _rnd; + delete _debugger; + delete _cur1; + delete _cur2; + delete _midiPlayer; +} + +GUI::Debugger *PrinceEngine::getDebugger() { + return _debugger; +} + +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); + + Common::SeekableReadStream *font1stream = SearchMan.createReadStreamForMember("font1.raw"); + if (!font1stream) + return Common::kPathNotFile; + + if (_font.load(*font1stream)) { + _font.getCharWidth(103); + } + delete font1stream; + + Common::SeekableReadStream * walizka = SearchMan.createReadStreamForMember("walizka"); + if (!walizka) + return Common::kPathDoesNotExist; + + debug("Loading walizka"); + if (!_walizkaBmp.loadStream(*walizka)) { + return Common::kPathDoesNotExist; + } + + Common::SeekableReadStream * skryptStream = SearchMan.createReadStreamForMember("skrypt.dat"); + if (!skryptStream) + return Common::kPathNotFile; + + debug("Loading skrypt"); + _script = new Script(this); + _script->loadFromStream(*skryptStream); + + delete skryptStream; + + Common::SeekableReadStream *variaTxtStream = SearchMan.createReadStreamForMember("variatxt.dat"); + + if (!variaTxtStream) { + error("Can't load variatxt.dat"); + return Common::kPathNotFile; + } + + _variaTxt = new VariaTxt(); + _variaTxt->loadFromStream(*variaTxtStream); + delete variaTxtStream; + + Common::SeekableReadStream *talkTxtStream = SearchMan.createReadStreamForMember("talktxt.dat"); + if (!talkTxtStream) { + error("Can't load talkTxtStream"); + return Common::kPathDoesNotExist; + } + + _talkTxtSize = talkTxtStream->size(); + _talkTxt = new byte[_talkTxtSize]; + talkTxtStream->read(_talkTxt, _talkTxtSize); + + delete talkTxtStream; + + + _cur1 = loadCursor("mouse1.cur"); + _cur2 = loadCursor("mouse2.cur"); +#if 0 + Common::SeekableReadStream *logoStream = SearchMan.createReadStreamForMember("logo.raw"); + if (logoStream) + { + MhwanhDecoder logo; + logo.loadStream(*logoStream); + _graph->setPalette(logo.getPalette()); + _graph->draw(0, 0, logo.getSurface()); + _graph->update(); + _system->delayMillis(700); + } + delete logoStream; +#endif + mainLoop(); + + return Common::kNoError; +} + +class MobList { +public: + bool loadFromStream(Common::SeekableReadStream &stream); + + Common::Array<Mob> _mobList; +}; + +bool MobList::loadFromStream(Common::SeekableReadStream &stream) +{ + Mob mob; + while (mob.loadFromStream(stream)) + _mobList.push_back(mob); + + return true; +} + +class ObjectList { +public: + bool loadFromStream(Common::SeekableReadStream &stream); + + Common::Array<Object> _objList; +}; + +bool ObjectList::loadFromStream(Common::SeekableReadStream &stream) +{ + Object obj; + while (obj.loadFromStream(stream)) + _objList.push_back(obj); + + return true; +} + +bool PrinceEngine::loadLocation(uint16 locationNr) { + debug("PrinceEngine::loadLocation %d", locationNr); + const Common::FSNode gameDataDir(ConfMan.get("path")); + SearchMan.remove(Common::String::format("%02d", _locationNr)); + _locationNr = locationNr; + + const Common::String locationNrStr = Common::String::format("%02d", _locationNr); + debug("loadLocation %s", locationNrStr.c_str()); + SearchMan.addSubDirectoryMatching(gameDataDir, locationNrStr, 0, 2); + + // load location background + Common::SeekableReadStream *room = SearchMan.createReadStreamForMember("room"); + + if (!room) { + error("Can't load room bitmap"); + return false; + } + + if(_roomBmp.loadStream(*room)) { + debug("Room bitmap loaded"); + _sceneWidth = _roomBmp.getSurface()->w; + } + + delete room; + + delete _mobList; + _mobList = NULL; + + Common::SeekableReadStream *mobListStream = SearchMan.createReadStreamForMember("mob.lst"); + if (!mobListStream) { + error("Can't read mob.lst"); + return false; + } + + _mobList = new MobList(); + _mobList->loadFromStream(*mobListStream); + + delete mobListStream; + + delete _objectList; + _objectList = NULL; + + Common::SeekableReadStream *objListStream = SearchMan.createReadStreamForMember("obj.lst"); + if (!objListStream) { + error("Can't read obj.lst"); + return false; + } + + _objectList = new ObjectList(); + _objectList->loadFromStream(*objListStream); + delete objListStream; + + const char *musName = MusicPlayer::_musTable[MusicPlayer::_musRoomTable[locationNr]]; + _midiPlayer->loadMidi(musName); + + return true; +} + +void PrinceEngine::changeCursor(uint16 curId) +{ + Graphics::Surface *curSurface = NULL; + + uint16 hotspotX = 0; + uint16 hotspotY = 0; + + switch(curId) { + case 0: + CursorMan.showMouse(false); + return; + case 1: + curSurface = _cur1; + break; + case 2: + curSurface = _cur2; + hotspotX = curSurface->w >> 1; + hotspotY = curSurface->h >> 1; + break; + } + + CursorMan.replaceCursorPalette(_roomBmp.getPalette(), 0, 255); + CursorMan.replaceCursor( + curSurface->getBasePtr(0, 0), + curSurface->w, curSurface->h, + hotspotX, hotspotY, + 255, false, + &curSurface->format + ); + CursorMan.showMouse(true); +} + +bool PrinceEngine::playNextFrame() { + if (!_flicPlayer.isVideoLoaded()) + return false; + + const Graphics::Surface *s = _flicPlayer.decodeNextFrame(); + if (s) { + _graph->drawTransparent(s); + _graph->change(); + } else if (_flicLooped) { + _flicPlayer.rewind(); + playNextFrame(); + } + + return true; +} + +bool PrinceEngine::loadAnim(uint16 animNr, bool loop) { + Common::String streamName = Common::String::format("AN%02d", animNr); + Common::SeekableReadStream * flicStream = SearchMan.createReadStreamForMember(streamName); + + if (!flicStream) { + error("Can't open %s", streamName.c_str()); + return false; + } + + if (!_flicPlayer.loadStream(flicStream)) { + error("Can't load flic stream %s", streamName.c_str()); + } + + debug("%s loaded", streamName.c_str()); + _flicLooped = loop; + _flicPlayer.start(); + playNextFrame(); + return true; +} + +void PrinceEngine::scrollCameraLeft(int16 delta) { + if (_newCameraX > 0) { + if (_newCameraX < delta) + _newCameraX = 0; + else + _newCameraX -= delta; + } +} + +void PrinceEngine::scrollCameraRight(int16 delta) { + if (_newCameraX != _sceneWidth - 640) { + if (_sceneWidth - 640 < delta + _newCameraX) + delta += (_sceneWidth - 640) - (delta + _newCameraX); + _newCameraX += delta; + debug(0, "PrinceEngine::scrollCameraRight() _newCameraX = %d; delta = %d", _newCameraX, delta); + } +} + +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(); + break; + case Common::KEYCODE_LEFT: + scrollCameraLeft(32); + break; + case Common::KEYCODE_RIGHT: + scrollCameraRight(32); + break; + } + } +} + +void PrinceEngine::hotspot() { + if (!_mobList) + return; + Common::Point mousepos = _system->getEventManager()->getMousePos(); + Common::Point mousePosCamera(mousepos.x + _cameraX, mousepos.y); + + for (Common::Array<Mob>::const_iterator it = _mobList->_mobList.begin() + ; it != _mobList->_mobList.end() ; ++it) { + if (it->_visible) + continue; + if (it->_rect.contains(mousePosCamera)) { + uint16 textW = 0; + for (int i = 0; i < it->_name.size(); ++i) + textW += _font.getCharWidth(it->_name[i]); + + uint16 x = mousepos.x - textW/2; + if (x > _graph->_frontScreen->w) + x = 0; + + if (x + textW > _graph->_frontScreen->w) + x = _graph->_frontScreen->w - textW; + + _font.drawString( + _graph->_frontScreen, + it->_name, + x, + mousepos.y - _font.getFontHeight(), + _graph->_frontScreen->w, + 216 + ); + break; + } + } +} + +void PrinceEngine::printAt(const char *s, uint16 x, uint16 y) { + _textSlots[0] = s; +} + +uint32 PrinceEngine::getTextWidth(const char *s) { + uint16 textW = 0; + while (*s) { + textW += *s; + ++s; + } + return textW; +} + + +void PrinceEngine::drawScreen() { + const Graphics::Surface *roomSurface = _roomBmp.getSurface(); + if (roomSurface) { + _graph->setPalette(_roomBmp.getPalette()); + const Graphics::Surface visiblePart = roomSurface->getSubArea(Common::Rect(_cameraX, 0, roomSurface->w, roomSurface->h)); + _graph->draw(0, 0, &visiblePart); + } + + playNextFrame(); + + //if (_objectList) + // _graph->drawTransparent(_objectList->getSurface()); + hotspot(); + + _font.drawString( + _graph->_frontScreen, + _textSlots[0], + 320 - getTextWidth(_textSlots[0])/2, + 470 - _font.getFontHeight(), + _graph->_frontScreen->w, + 216 + ); + + + getDebugger()->onFrame(); + + _graph->update(); +} + +void PrinceEngine::mainLoop() { + + //loadLocation(1); + //changeCursor(1); + //CursorMan.showMouse(true); + + while (!shouldQuit()) { + Common::Event event; + Common::EventManager *eventMan = _system->getEventManager(); + while (eventMan->pollEvent(event)) { + switch (event.type) { + case Common::EVENT_KEYDOWN: + keyHandler(event); + 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(); + drawScreen(); + + _system->delayMillis(10); + + _cameraX = _newCameraX; + } +} + +} // End of namespace Prince +/* vim: set tabstop=4 expandtab!: */ diff --git a/engines/prince/prince.h b/engines/prince/prince.h index 6340733255..080eca5ead 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -1,112 +1,132 @@ -/* 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 "common/events.h"
-
-#include "graphics/decoders/bmp.h"
-
-#include "gui/debugger.h"
-
-#include "engines/engine.h"
-#include "engines/util.h"
-
-#include "audio/mixer.h"
-
-#include "video/flic_decoder.h"
-
-#include "prince/font.h"
-#include "prince/mhwanh.h"
-
-namespace Prince {
-
-struct PrinceGameDescription;
-
-class PrinceEngine;
-class GraphicsMan;
-class Script;
-class Debugger;
-class ObjectList;
-class MobList;
-class MusicPlayer;
-
-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;
- Video::FlicDecoder _flicPlayer;
-
- bool loadLocation(uint16 locationNr);
- bool loadAnim(uint16 animNr);
-
- virtual GUI::Debugger *getDebugger();
-
- void changeCursor(uint16 curId);
-
-private:
- bool playNextFrame();
- void keyHandler(Common::Event event);
- void hotspot();
-
- Common::RandomSource *_rnd;
- Graphics::BitmapDecoder _roomBmp;
- uint16 _locationNr;
- MhwanhDecoder _walizkaBmp;
-
- Graphics::Surface *_cur1;
- Graphics::Surface *_cur2;
-
- Debugger *_debugger;
- GraphicsMan *_graph;
- Script *_script;
- Font _font;
- ObjectList *_objectList;
- MobList *_mobList;
- MusicPlayer *_midiPlayer;
-
- void mainLoop();
-
-};
-
-} // End of namespace Prince
-
-#endif
+/* 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 "common/events.h" + +#include "graphics/decoders/bmp.h" + +#include "gui/debugger.h" + +#include "engines/engine.h" +#include "engines/util.h" + +#include "audio/mixer.h" + +#include "video/flic_decoder.h" + +#include "prince/font.h" +#include "prince/mhwanh.h" + +namespace Prince { + +struct PrinceGameDescription; + +class PrinceEngine; +class GraphicsMan; +class Script; +class Debugger; +class ObjectList; +class MobList; +class MusicPlayer; +class VariaTxt; + +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; + Video::FlicDecoder _flicPlayer; + VariaTxt *_variaTxt; + + uint32 _talkTxtSize; + byte *_talkTxt; + + bool loadLocation(uint16 locationNr); + bool loadAnim(uint16 animNr, bool loop); + + virtual GUI::Debugger *getDebugger(); + + void changeCursor(uint16 curId); + void printAt(const char *s, uint16 x, uint16 y); + + const char * _textSlots[1000]; + +private: + bool playNextFrame(); + void keyHandler(Common::Event event); + void hotspot(); + void scrollCameraRight(int16 delta); + void scrollCameraLeft(int16 delta); + void drawScreen(); + + uint32 getTextWidth(const char *s); + + Common::RandomSource *_rnd; + Graphics::BitmapDecoder _roomBmp; + uint16 _locationNr; + MhwanhDecoder _walizkaBmp; + + Graphics::Surface *_cur1; + Graphics::Surface *_cur2; + + Debugger *_debugger; + GraphicsMan *_graph; + Script *_script; + Font _font; + ObjectList *_objectList; + MobList *_mobList; + MusicPlayer *_midiPlayer; + uint16 _cameraX; + uint16 _newCameraX; + uint16 _sceneWidth; + + bool _flicLooped; + + void mainLoop(); + +}; + +} // End of namespace Prince + +#endif + +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index e2360debc8..7ab723a4fb 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -22,6 +22,9 @@ #include "prince/script.h" #include "prince/prince.h" +#include "prince/flags.h" +#include "prince/variatxt.h" +#include "prince/font.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -32,459 +35,487 @@ 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); - debug("%s %s", str.c_str(), buf); + 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() { - //while (!_opcodeNF) - { - _lastInstruction = _currentInstruction; - // Prepare the base debug string - Common::String dstr = Common::String::format("@0x%04X: ", _currentInstruction); + while (!_opcodeNF) + { + _lastInstruction = _currentInstruction; + // Prepare the base debug string + Common::String dstr = Common::String::format("@0x%04X: ", _currentInstruction); - // Get the current opcode - _lastOpcode = readScript16bits(); + // Get the current opcode + _lastOpcode = readScript16bits(); - dstr += Common::String::format("op %02d: ", _lastOpcode); + dstr += Common::String::format("op %02d: ", _lastOpcode); - if (_lastOpcode > NUM_OPCODES) - error("Trying to execute unknown opcode %s", dstr.c_str()); + if (_lastOpcode > NUM_OPCODES) + error("Trying to execute unknown opcode %s", dstr.c_str()); - debug("%s", dstr.c_str()); + debug("%s", dstr.c_str()); - // Execute the current opcode - OpcodeFunc op = _opcodes[_lastOpcode]; - (this->*op)(); - } + // Execute the current opcode + OpcodeFunc op = _opcodes[_lastOpcode]; + (this->*op)(); + if (_opcodeNF) { + + _opcodeNF = 0; + break; + } + } } 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() { - debugScript("O_WAITFOREVER"); - _currentInstruction -= 2; + debugScript("O_WAITFOREVER"); + _opcodeNF = 1; + _currentInstruction -= 2; } void Script::O_BLACKPALETTE() { - debugScript("O_BLACKPALETTE"); + debugScript("O_BLACKPALETTE"); } void Script::O_SETUPPALETTE() { - debugScript("O_SETUPPALETTE"); + debugScript("O_SETUPPALETTE"); } void Script::O_INITROOM() { - uint16 roomId = readScript16bits(); - debugScript("O_INITROOM %d", roomId); - _vm->loadLocation(roomId); + uint16 roomId = readScript16bits(); + debugScript("O_INITROOM %d", roomId); + _vm->loadLocation(roomId); + _opcodeNF = 1; } void Script::O_SETSAMPLE() { - uint16 sampleId = readScript16bits(); - int32 sampleNameOffset = readScript32bits(); - const char * sampleName = (const char *)_code + _currentInstruction + sampleNameOffset - 4; - debugScript("O_SETSAMPLE %d %s", sampleId, sampleName); + uint16 sampleId = readScript16bits(); + int32 sampleNameOffset = readScript32bits(); + const char * sampleName = (const char *)_code + _currentInstruction + sampleNameOffset - 4; + debugScript("O_SETSAMPLE %d %s", sampleId, sampleName); } void Script::O_FREESAMPLE() { - uint16 sample = readScript16bits(); - debugScript("O_FREESAMPLE %d", sample); + 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); + 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); + 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(); + uint16 roomId = readScript16bits(); + uint16 objectId = readScript16bits(); - debugScript("O_REMOBJECT roomId %d objectId %d", roomId, objectId); + debugScript("O_REMOBJECT roomId %d objectId %d", roomId, objectId); } void Script::O_SHOWANIM() { - uint16 slot = readScript16bits(); - uint16 animId = readScript16bits(); + uint16 slot = readScript16bits(); + uint16 animId = readScript16bits(); - debugScript("O_SHOWANIM slot %d, animId %d", slot, animId); + debugScript("O_SHOWANIM slot %d, animId %d", slot, animId); } void Script::O_CHECKANIMEND() { - uint16 slot = readScript16bits(); - uint16 frameId = readScript16bits(); + uint16 slot = readScript16bits(); + uint16 frameId = readScript16bits(); - debugScript("O_CHECKANIMEND slot %d, frameId %d", slot, frameId); + debugScript("O_CHECKANIMEND slot %d, frameId %d", slot, frameId); + _opcodeNF = 1; } void Script::O_FREEANIM() { - uint16 slot = readScript16bits(); - debugScript("O_FREEANIM slot %d", slot); + uint16 slot = readScript16bits(); + debugScript("O_FREEANIM slot %d", slot); } void Script::O_CHECKANIMFRAME() { - uint16 slot = readScript16bits(); - uint16 frameId = readScript16bits(); + uint16 slot = readScript16bits(); + uint16 frameId = readScript16bits(); - debugScript("O_CHECKANIMFRAME slot %d, frameId %d", slot, frameId); + debugScript("O_CHECKANIMFRAME slot %d, frameId %d", slot, frameId); + _opcodeNF = 1; } 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); + 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(); + uint16 roomId = readScript16bits(); + uint16 slot = readScript16bits(); - debugScript("O_REMBACKANIM roomId %d, slot %d", roomId, slot); + debugScript("O_REMBACKANIM roomId %d, slot %d", roomId, slot); } void Script::O_CHECKBACKANIMFRAME() { - uint16 slotId = readScript16bits(); - uint16 frameId = readScript16bits(); + uint16 slotId = readScript16bits(); + uint16 frameId = readScript16bits(); - debugScript("O_CHECKBACKANIMFRAME slotId %d, frameId %d", slotId, frameId); + debugScript("O_CHECKBACKANIMFRAME slotId %d, frameId %d", slotId, frameId); + _opcodeNF = 1; } void Script::O_FREEALLSAMPLES() { - debugScript("O_FREEALLSAMPLES"); + debugScript("O_FREEALLSAMPLES"); } void Script::O_SETMUSIC() { - uint16 musicId = readScript16bits(); + uint16 musicId = readScript16bits(); - debugScript("O_SETMUSIC musicId %d", musicId); + debugScript("O_SETMUSIC musicId %d", musicId); } void Script::O_STOPMUSIC() { - debugScript("O_STOPMUSIC"); + debugScript("O_STOPMUSIC"); } void Script::O__WAIT() { - uint16 pause = readScript16bits(); + uint16 pause = readScript16bits(); + + debugScript("O__WAIT pause %d", pause); - debugScript("O__WAIT pause %d", pause); + _opcodeNF = 1; + } void Script::O_UPDATEOFF() { - debugScript("O_UPDATEOFF"); + debugScript("O_UPDATEOFF"); } void Script::O_UPDATEON() { - debugScript("O_UPDATEON"); + debugScript("O_UPDATEON"); } void Script::O_UPDATE () { - debugScript("O_UPDATE"); + debugScript("O_UPDATE"); } void Script::O_CLS() { - debugScript("O_CLS"); + debugScript("O_CLS"); } void Script::O__CALL() { - int32 address = readScript32bits(); - _stack[_stacktop] = _currentInstruction; - _stacktop++; - _currentInstruction += address - 4; - debugScript("O__CALL 0x%04X", _currentInstruction); + 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"); - } + // 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; + int32 opPC = readScript32bits(); + debugScript("O_GO 0x%04X", opPC); + _currentInstruction += opPC - 4; } void Script::O_BACKANIMUPDATEOFF() { - uint16 slotId = readScript32bits(); - debugScript("O_BACKANIMUPDATEOFF slotId %d", slotId); + uint16 slotId = readScript32bits(); + debugScript("O_BACKANIMUPDATEOFF slotId %d", slotId); } void Script::O_BACKANIMUPDATEON() { - uint16 slot = readScript16bits(); - debugScript("O_BACKANIMUPDATEON %d", slot); + uint16 slot = readScript16bits(); + debugScript("O_BACKANIMUPDATEON %d", slot); } void Script::O_CHANGECURSOR() { - uint16 cursorId = readScript16bits(); - debugScript("O_CHANGECURSOR %x", cursorId); + uint16 cursorId = readScript16bits(); + debugScript("O_CHANGECURSOR %x", cursorId); } void Script::O_CHANGEANIMTYPE() { - // NOT IMPLEMENTED + // NOT IMPLEMENTED } void Script::O__SETFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - debugScript("O__SETFLAG 0x%04X %d", flagId, value); - _flags[flagId - 0x8000] = value; + debugScript("O__SETFLAG 0x%04X (%s) = %d", flagId, Flags::getFlagName(flagId), value); + + _flags[flagId - 0x8000] = value; } void Script::O_COMPARE() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + + if (value & 0x8000) { + uint16 val = _flags[value - 0x8000]; + debugScript("GetFlagValue 0x%04X (%s), value %d", value, Flags::getFlagName(value), val); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + value = val; + } - debugScript("O_COMPARE flagId 0x%04X, value %d", flagId, value); - _result = (_flags[flagId - 0x8000] == value); + debugScript("O_COMPARE flagId 0x%04X (%s), value %d", flagId, Flags::getFlagName(flagId), value); + _result = (_flags[flagId - 0x8000] == value); } void Script::O_JUMPZ() { - int32 offset = readScript32bits(); - debugScript("O_JUMPZ offset 0x%04X", offset); - if (! _result) { - _currentInstruction += offset - 4; - } + int32 offset = readScript32bits(); + debugScript("O_JUMPZ offset 0x%04X", offset); + if (! _result) { + _currentInstruction += offset - 4; + } } void Script::O_JUMPNZ() { - int32 offset = readScript32bits(); - debugScript("O_JUMPNZ offset 0x%04X", offset); - if (_result) { - _currentInstruction += offset - 4; - } + int32 offset = readScript32bits(); + debugScript("O_JUMPNZ offset 0x%04X", offset); + if (_result) { + _currentInstruction += offset - 4; + } } void Script::O_EXIT() { - uint16 exitCode = readScript16bits(); - debugScript("O_EXIT exitCode %d", exitCode); + uint16 exitCode = readScript16bits(); + debugScript("O_EXIT exitCode %d", exitCode); } void Script::O_ADDFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - _flags[flagId - 0x8000] += value; - if (_flags[flagId - 0x8000]) - _result = 1; - else - _result = 0; + _flags[flagId - 0x8000] += value; + if (_flags[flagId - 0x8000]) + _result = 1; + else + _result = 0; - debugScript("O_ADDFLAG flagId %d, value %d", flagId, value); + debugScript("O_ADDFLAG flagId %04x (%s), value %d", flagId, Flags::getFlagName(flagId), value); } void Script::O_TALKANIM() { - uint16 animSlot = readScript16bits(); - uint16 slot = readScript16bits(); + uint16 animSlot = readScript16bits(); + uint16 slot = readScript16bits(); - debugScript("O_TALKANIM animSlot %d, slot %d", animSlot, slot); + debugScript("O_TALKANIM animSlot %d, slot %d", animSlot, slot); } void Script::O_SUBFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - _flags[flagId - 0x8000] -= value; - if (_flags[flagId - 0x8000]) - _result = 1; - else - _result = 0; + _flags[flagId - 0x8000] -= value; + if (_flags[flagId - 0x8000]) + _result = 1; + else + _result = 0; - debugScript("O_SUBFLAG flagId %d, value %d", flagId, value); + debugScript("O_SUBFLAG flagId %d, value %d", flagId, value); } void Script::O_SETSTRING() { - int32 offset = readScript32bits(); + int32 offset = readScript32bits(); - debugScript("O_SETSTRING 0x%04X", offset); + if (offset >= 80000) { + debug("GetVaria %s", _vm->_variaTxt->getString(offset - 80000)); + } + else if (offset < 2000) { + uint32 of = READ_LE_UINT32(_vm->_talkTxt+offset*4); + const char * txt = (const char *)&_vm->_talkTxt[of]; + _string = &_vm->_talkTxt[of]; + debug("TalkTxt %d %s", of, txt); + } + + debugScript("O_SETSTRING 0x%04X", offset); } void Script::O_ANDFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); - debugScript("O_ANDFLAG flagId %d, value %d", flagId, value); + debugScript("O_ANDFLAG flagId %d, value %d", flagId, value); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - _flags[flagId - 0x8000] &= value; + _flags[flagId - 0x8000] &= value; - if (_flags[flagId - 0x8000]) { - _result = 1; - } else { - _result = 0; - } + if (_flags[flagId - 0x8000]) { + _result = 1; + } else { + _result = 0; + } } void Script::O_GETMOBDATA() { - uint16 flagId = readScript16bits(); - uint16 mobId = readScript16bits(); - uint16 mobOffset = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 mobId = readScript16bits(); + uint16 mobOffset = readScript16bits(); - debugScript("O_GETMOBDATA flagId %d, modId %d, mobOffset %d", flagId, mobId, mobOffset); + debugScript("O_GETMOBDATA flagId %d, modId %d, mobOffset %d", flagId, mobId, mobOffset); } void Script::O_ORFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); - - debugScript("O_ORFLAG flagId %d, value %d", flagId, value); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); + + debugScript("O_ORFLAG flagId %d, value %d", flagId, value); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - _flags[flagId - 0x8000] |= value; + _flags[flagId - 0x8000] |= value; - if (_flags[flagId - 0x8000]) { - _result = 1; - } else { - _result = 0; - } + if (_flags[flagId - 0x8000]) { + _result = 1; + } else { + _result = 0; + } } void Script::O_SETMOBDATA() { - uint16 mobId = readScript16bits(); - uint16 mobOffset = readScript16bits(); - uint16 value = readScript16bits(); + uint16 mobId = readScript16bits(); + uint16 mobOffset = readScript16bits(); + uint16 value = readScript16bits(); - debugScript("O_SETMOBDATA mobId %d, mobOffset %d, value %d", mobId, mobOffset, value); + debugScript("O_SETMOBDATA mobId %d, mobOffset %d, value %d", mobId, mobOffset, value); } void Script::O_XORFLAG() { - uint16 flagId = readScript16bits(); - uint16 value = readScript16bits(); + uint16 flagId = readScript16bits(); + uint16 value = readScript16bits(); - debugScript("O_XORFLAG flagId %d, value %d", flagId, value); + debugScript("O_XORFLAG flagId %d, value %d", flagId, value); - if (value & 0x8000) { - value = _flags[value - 0x8000]; - } + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } - _flags[flagId - 0x8000] ^= value; + _flags[flagId - 0x8000] ^= value; - if (_flags[flagId - 0x8000]) { - _result = 1; - } else { - _result = 0; - } + if (_flags[flagId - 0x8000]) { + _result = 1; + } else { + _result = 0; + } } void Script::O_GETMOBTEXT() { - uint16 value = readScript16bits(); + uint16 value = readScript16bits(); - debugScript("O_GETMOBTEXT value %d", value); + debugScript("O_GETMOBTEXT value %d", value); } 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); + 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(); + uint16 heroId = readScript16bits(); - debugScript("O_WALKHERO %d", heroId); + debugScript("O_WALKHERO %d", heroId); + _opcodeNF = 1; } void Script::O_SETHERO() {} void Script::O_HEROOFF() { - uint16 heroId = readScript16bits(); - debugScript("O_HEROOFF %d", heroId); + uint16 heroId = readScript16bits(); + debugScript("O_HEROOFF %d", heroId); } void Script::O_HEROON() { - uint16 heroId = readScript16bits(); - debugScript("O_HEROON %d", heroId); + uint16 heroId = readScript16bits(); + debugScript("O_HEROON %d", heroId); } void Script::O_CLSTEXT() {} @@ -499,8 +530,8 @@ void Script::O_REMWALKAREA() {} void Script::O_RESTOREWALKAREA() {} void Script::O_WAITFRAME() { - debugScript("O_WAITFRAME"); - _opcodeNF = true; + debugScript("O_WAITFRAME"); + _opcodeNF = true; } void Script::O_SETFRAME() {} @@ -513,8 +544,9 @@ void Script::O_CHECKINV() {} void Script::O_TALKHERO() {} void Script::O_WAITTEXT() { - uint16 slot = readScript16bits(); - debugScript("O_WAITTEXT slot %d", slot); + uint16 slot = readScript16bits(); + debugScript("O_WAITTEXT slot %d", slot); + _opcodeNF = 1; } void Script::O_SETHEROANIM() {} @@ -526,8 +558,8 @@ void Script::O_CHANGEBACKFRAMES() {} void Script::O_GETBACKANIMDATA() {} void Script::O_GETANIMDATA() {} void Script::O_SETBGCODE() { - int32 bgcode = readScript32bits(); - debugScript("O_SETBGCODE %d", bgcode); + int32 bgcode = readScript32bits(); + debugScript("O_SETBGCODE %d", bgcode); } void Script::O_SETBACKFRAME() {} void Script::O_GETRND() {} @@ -535,13 +567,32 @@ void Script::O_TALKBACKANIM() {} void Script::O_LOADPATH() {} void Script::O_GETCHAR() { - uint16 flagId = readScript16bits(); - debugScript("O_GETCHAR %d", flagId); + uint16 flagId = readScript16bits(); + debugScript("O_GETCHAR %04X (%s)", flagId, Flags::getFlagName(flagId)); + + _flags[flagId - 0x8000] = *_string; + + _string++; } void Script::O_SETDFLAG() {} void Script::O_CALLDFLAG() {} -void Script::O_PRINTAT() {} + +void Script::O_PRINTAT() { + uint16 slot = readScript16bits(); + uint16 fr1 = readScript16bits(); + uint16 fr2 = readScript16bits(); + + debugScript("O_PRINTAT slot %d, fr1 %d, fr2 %d", slot, fr1, fr2); + + _vm->printAt((const char *)_string, 0, fr1); + + while (*_string) { + ++_string; + } + ++_string; +} + void Script::O_ZOOMIN() {} void Script::O_ZOOMOUT() {} void Script::O_SETSTRINGOFFSET() {} @@ -557,396 +608,409 @@ void Script::O_DISABLEDIALOGOPT() {} void Script::O_SHOWDIALOGBOX() {} void Script::O_STOPSAMPLE() { - uint16 slot = readScript16bits(); - debugScript("O_STOPSAMPLE slot %d", slot); + uint16 slot = readScript16bits(); + debugScript("O_STOPSAMPLE slot %d", slot); } void Script::O_BACKANIMRANGE() { - uint16 slotId = readScript16bits(); - uint16 animId = readScript16bits(); - uint16 low = readScript16bits(); - uint16 high = readScript16bits(); + uint16 slotId = readScript16bits(); + uint16 animId = readScript16bits(); + uint16 low = readScript16bits(); + uint16 high = readScript16bits(); - debugScript("O_BACKANIMRANGE slotId %d, animId %d, low %d, high %d", slotId, animId, low, high); + debugScript("O_BACKANIMRANGE slotId %d, animId %d, low %d, high %d", slotId, animId, low, high); } void Script::O_CLEARPATH() { - debugScript("O_CLEARPATH"); + debugScript("O_CLEARPATH"); } void Script::O_SETPATH() { - debugScript("O_SETPATH"); + debugScript("O_SETPATH"); } void Script::O_GETHEROX() { - uint16 heroId = readScript16bits(); - uint16 flagId = readScript16bits(); + uint16 heroId = readScript16bits(); + uint16 flagId = readScript16bits(); - debugScript("O_GETHEROX heroId %d, flagId %d", heroId, flagId); + debugScript("O_GETHEROX heroId %d, flagId %d", heroId, flagId); } void Script::O_GETHEROY() { - uint16 heroId = readScript16bits(); - uint16 flagId = readScript16bits(); + uint16 heroId = readScript16bits(); + uint16 flagId = readScript16bits(); - debugScript("O_GETHEROY heroId %d, flagId %d", heroId, flagId); + debugScript("O_GETHEROY heroId %d, flagId %d", heroId, flagId); } void Script::O_GETHEROD() { - uint16 heroId = readScript16bits(); - uint16 flagId = readScript16bits(); + uint16 heroId = readScript16bits(); + uint16 flagId = readScript16bits(); - debugScript("O_GETHEROD heroId %d, flagId %d", heroId, flagId); + debugScript("O_GETHEROD heroId %d, flagId %d", heroId, flagId); } void Script::O_PUSHSTRING() { - debugScript("O_PUSHSTRING"); + debugScript("O_PUSHSTRING"); } void Script::O_POPSTRING() { - debugScript("O_POPSTRING"); + debugScript("O_POPSTRING"); } void Script::O_SETFGCODE() { - int32 offset = readScript32bits(); + int32 offset = readScript32bits(); - debugScript("O_SETFGCODE offset %04X", offset); + debugScript("O_SETFGCODE offset %04X", offset); } void Script::O_STOPHERO() { - uint16 heroId = readScript16bits(); + uint16 heroId = readScript16bits(); - debugScript("O_STOPHERO heroId %d", heroId); + debugScript("O_STOPHERO heroId %d", heroId); } void Script::O_ANIMUPDATEOFF() { - uint16 slotId = readScript16bits(); - debugScript("O_ANIMUPDATEOFF slotId %d", slotId); + uint16 slotId = readScript16bits(); + debugScript("O_ANIMUPDATEOFF slotId %d", slotId); } void Script::O_ANIMUPDATEON() { - uint16 slotId = readScript16bits(); - debugScript("O_ANIMUPDATEON slotId %d", slotId); + uint16 slotId = readScript16bits(); + debugScript("O_ANIMUPDATEON slotId %d", slotId); } void Script::O_FREECURSOR() { - debugScript("O_FREECURSOR"); + debugScript("O_FREECURSOR"); } void Script::O_ADDINVQUIET() { - uint16 heroId = readScript16bits(); - uint16 itemId = readScript16bits(); + uint16 heroId = readScript16bits(); + uint16 itemId = readScript16bits(); - debugScript("O_ADDINVQUIET heorId %d, itemId %d", heroId, itemId); + debugScript("O_ADDINVQUIET heorId %d, itemId %d", heroId, itemId); } void Script::O_RUNHERO() { - uint16 heroId = readScript16bits(); - uint16 x = readScript16bits(); - uint16 y = readScript16bits(); - uint16 dir = readScript16bits(); + uint16 heroId = readScript16bits(); + uint16 x = readScript16bits(); + uint16 y = readScript16bits(); + uint16 dir = readScript16bits(); - debugScript("O_RUNHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); + debugScript("O_RUNHERO heroId %d, x %d, y %d, dir %d", heroId, x, y, dir); } void Script::O_SETBACKANIMDATA() { - uint16 animId = readScript16bits(); - uint16 animOffset = readScript16bits(); - uint16 wart = readScript16bits(); + uint16 animId = readScript16bits(); + uint16 animOffset = readScript16bits(); + uint16 wart = readScript16bits(); - debugScript("O_SETBACKANIMDATA animId %d, animOffset %d, wart %d", animId, animOffset, wart); + debugScript("O_SETBACKANIMDATA animId %d, animOffset %d, wart %d", animId, animOffset, wart); } void Script::O_VIEWFLC() { - uint16 animNr = readScript16bits(); - debugScript("O_VIEWFLC animNr %d", animNr); + uint16 animNr = readScript16bits(); + debugScript("O_VIEWFLC animNr %d", animNr); + _vm->loadAnim(animNr, false); } void Script::O_CHECKFLCFRAME() { - uint16 frameNr = readScript16bits(); + uint16 frameNr = readScript16bits(); - debugScript("O_CHECKFLCFRAME frame number %d", frameNr); + debugScript("O_CHECKFLCFRAME frame number %d", frameNr); - const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; + const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; - if (flicPlayer.getCurFrame() != frameNr) - { - // Move instruction pointer before current instruciton - // must do this check once again till it's false - _currentInstruction -= 2; - } + if (flicPlayer.getCurFrame() != frameNr) + { + // Move instruction pointer before current instruciton + // must do this check once again till it's false + _currentInstruction -= 2; + _opcodeNF = 1; + } } void Script::O_CHECKFLCEND() { - debugScript("O_CHECKFLCEND"); + debugScript("O_CHECKFLCEND"); + + const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; - const Video::FlicDecoder &flicPlayer = _vm->_flicPlayer; + //debug("frameCount %d, currentFrame %d", flicPlayer.getFrameCount(), flicPlayer.getCurFrame()); - if (flicPlayer.getFrameCount() - flicPlayer.getCurFrame() <= 1) - { - // Move instruction pointer before current instruciton - // must do this check once again till it's false - _currentInstruction -= 2; - } + if (flicPlayer.getFrameCount() - flicPlayer.getCurFrame() > 1) + { + // Move instruction pointer before current instruciton + // must do this check once again till it's false + _currentInstruction -= 2; + _opcodeNF = 1; + } } void Script::O_FREEFLC() { - debugScript("O_FREEFLC"); + debugScript("O_FREEFLC"); } void Script::O_TALKHEROSTOP() { - uint16 heroId = readScript16bits(); - debugScript("O_TALKHEROSTOP %d", heroId); + uint16 heroId = readScript16bits(); + debugScript("O_TALKHEROSTOP %d", heroId); } void Script::O_HEROCOLOR() { - uint16 heroId = readScript16bits(); - uint16 kolorr = readScript16bits(); - debugScript("O_HEROCOLOR heroId %d, kolorr %d", heroId, kolorr); + uint16 heroId = readScript16bits(); + uint16 kolorr = readScript16bits(); + debugScript("O_HEROCOLOR heroId %d, kolorr %d", heroId, kolorr); } void Script::O_GRABMAPA() { - debugScript("O_GRABMAPA"); + debugScript("O_GRABMAPA"); } void Script::O_ENABLENAK() { - uint16 nakId = readScript16bits(); - debugScript("O_ENABLENAK nakId %d", nakId); + uint16 nakId = readScript16bits(); + debugScript("O_ENABLENAK nakId %d", nakId); } void Script::O_DISABLENAK() { - uint16 nakId = readScript16bits(); - debugScript("O_DISABLENAK nakId %d", nakId); + uint16 nakId = readScript16bits(); + debugScript("O_DISABLENAK nakId %d", nakId); } void Script::O_GETMOBNAME() { - uint16 war = readScript16bits(); - debugScript("O_GETMOBNAME war %d", war); + uint16 war = readScript16bits(); + debugScript("O_GETMOBNAME war %d", war); } void Script::O_SWAPINVENTORY() { - uint16 heroId = readScript16bits(); - debugScript("O_SWAPINVENTORY heroId %d", heroId); + uint16 heroId = readScript16bits(); + debugScript("O_SWAPINVENTORY heroId %d", heroId); } void Script::O_CLEARINVENTORY() { - uint16 heroId = readScript16bits(); - debugScript("O_CLEARINVENTORY heroId %d", heroId); + uint16 heroId = readScript16bits(); + debugScript("O_CLEARINVENTORY heroId %d", heroId); } void Script::O_SKIPTEXT() { - debugScript("O_SKIPTEXT"); + debugScript("O_SKIPTEXT"); } void Script::O_SETVOICEH() { - uint16 txn = readScript16bits(); - debugScript("O_SETVOICEH txn %d", txn); + uint16 txn = readScript16bits(); + debugScript("O_SETVOICEH txn %d", txn); } void Script::O_SETVOICEA() { - uint16 txn = readScript16bits(); - debugScript("O_SETVOICEA txn %d", txn); + uint16 txn = readScript16bits(); + debugScript("O_SETVOICEA txn %d", txn); } void Script::O_SETVOICEB() { - uint16 txn = readScript16bits(); - debugScript("O_SETVOICEB txn %d", txn); + uint16 txn = readScript16bits(); + debugScript("O_SETVOICEB txn %d", txn); } void Script::O_SETVOICEC() { - uint16 txn = readScript16bits(); - debugScript("O_SETVOICEC txn %d", txn); + uint16 txn = readScript16bits(); + debugScript("O_SETVOICEC txn %d", txn); } void Script::O_VIEWFLCLOOP() { - uint16 animId = readScript16bits(); - debugScript("O_VIEWFLCLOOP animId %d", animId); + uint16 value = readScript16bits(); + debugScript("O_VIEWFLCLOOP animId %d", value); + + if (value & 0x8000) { + value = _flags[value - 0x8000]; + } + + _vm->loadAnim(value, true); } void Script::O_FLCSPEED() { - uint16 speed = readScript16bits(); - debugScript("O_FLCSPEED speed %d", speed); + uint16 speed = readScript16bits(); + debugScript("O_FLCSPEED speed %d", speed); } void Script::O_OPENINVENTORY() { - debugScript("O_OPENINVENTORY"); + debugScript("O_OPENINVENTORY"); + _opcodeNF = 1; } void Script::O_KRZYWA() { - debugScript("O_KRZYWA"); + debugScript("O_KRZYWA"); } void Script::O_GETKRZYWA() { - debugScript("O_GETKRZYWA"); + debugScript("O_GETKRZYWA"); } void Script::O_GETMOB() { - uint16 flagId = readScript16bits(); - uint16 mx = readScript16bits(); - uint16 my = readScript16bits(); - debugScript("O_GETMOB flagId %d, mx %d, my %d", flagId, mx, my); + uint16 flagId = readScript16bits(); + uint16 mx = readScript16bits(); + uint16 my = readScript16bits(); + debugScript("O_GETMOB flagId %d, mx %d, my %d", flagId, mx, my); } void Script::O_INPUTLINE() { - debugScript("O_INPUTLINE"); + debugScript("O_INPUTLINE"); } void Script::O_SETVOICED() { - uint16 txn = readScript16bits(); - debugScript("O_SETVOICED txn %d", txn); + uint16 txn = readScript16bits(); + debugScript("O_SETVOICED txn %d", txn); } void Script::O_BREAK_POINT() { - debugScript("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, + &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, }; } +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/script.h b/engines/prince/script.h index e801529187..dc050daeea 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -26,7 +26,7 @@ #include "common/random.h" namespace Common { - class SeekableReadStream; + class SeekableReadStream; } namespace Prince { @@ -35,189 +35,193 @@ class PrinceEngine; class Script { public: - Script(PrinceEngine *vm); - virtual ~Script(); + Script(PrinceEngine *vm); + virtual ~Script(); - bool loadFromStream(Common::SeekableReadStream &stream); + bool loadFromStream(Common::SeekableReadStream &stream); - void step(); + void step(); private: - PrinceEngine *_vm; - - byte *_code; - uint32 _codeSize; - uint32 _currentInstruction; - uint16 _lastOpcode; - uint32 _lastInstruction; - byte _result; - int16 _flags[2000]; - bool _opcodeNF; - - // Stack - static const uint32 _STACK_SIZE = 500; - uint16 _stack[_STACK_SIZE]; - 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(); + PrinceEngine *_vm; + + byte *_code; + uint32 _codeSize; + uint32 _currentInstruction; + uint16 _lastOpcode; + uint32 _lastInstruction; + byte _result; + int16 _flags[2000]; + bool _opcodeNF; + + // Stack + static const uint32 _STACK_SIZE = 500; + uint32 _stack[_STACK_SIZE]; + uint8 _stacktop; + uint8 _savedStacktop; + + const byte * _string; + + // 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(); }; } #endif + +/* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/sound.cpp b/engines/prince/sound.cpp index 3285390aca..40f182e630 100644 --- a/engines/prince/sound.cpp +++ b/engines/prince/sound.cpp @@ -27,6 +27,8 @@ #include "prince/prince.h" #include "prince/sound.h" +#include "prince/musNum.h" + #include "common/config-manager.h" #include "common/memstream.h" #include "common/archive.h" @@ -57,13 +59,67 @@ const char * MusicPlayer::_musTable[] = { const uint8 MusicPlayer::_musRoomTable[] = { 0, - 3, - 9, - 9, - 9, - 13, - 9, - 9 + ROOM01MUS, + ROOM02MUS, + ROOM03MUS, + ROOM04MUS, + ROOM05MUS, + ROOM06MUS, + ROOM07MUS, + ROOM08MUS, + ROOM09MUS, + ROOM10MUS, + ROOM11MUS, + ROOM12MUS, + ROOM13MUS, + ROOM14MUS, + ROOM15MUS, + ROOM16MUS, + ROOM17MUS, + ROOM18MUS, + ROOM19MUS, + ROOM20MUS, + ROOM21MUS, + ROOM22MUS, + ROOM23MUS, + ROOM24MUS, + ROOM25MUS, + ROOM26MUS, + ROOM27MUS, + ROOM28MUS, + ROOM29MUS, + ROOM30MUS, + ROOM31MUS, + ROOM32MUS, + ROOM33MUS, + ROOM34MUS, + ROOM35MUS, + ROOM36MUS, + ROOM37MUS, + ROOM38MUS, + ROOM39MUS, + ROOM40MUS, + ROOM41MUS, + ROOM42MUS, + ROOM43MUS, + 0, + 0, + ROOM46MUS, + ROOM47MUS, + ROOM48MUS, + ROOM49MUS, + ROOM50MUS, + ROOM51MUS, + ROOM52MUS, + ROOM53MUS, + ROOM54MUS, + ROOM55MUS, + ROOM56MUS, + ROOM57MUS, + ROOM58MUS, + ROOM59MUS, + ROOM60MUS, + ROOM61MUS }; diff --git a/engines/prince/sound.h b/engines/prince/sound.h index f4ba9ba45f..7219411b36 100644 --- a/engines/prince/sound.h +++ b/engines/prince/sound.h @@ -43,28 +43,28 @@ class PrinceEngine; class MusicPlayer: public Audio::MidiPlayer { private: - PrinceEngine *_vm; - byte *_data; - int _dataSize; - bool _isGM; + PrinceEngine *_vm; + byte *_data; + int _dataSize; + bool _isGM; - // Start MIDI File - void sndMidiStart(); + // Start MIDI File + void sndMidiStart(); - // Stop MIDI File - void sndMidiStop(); + // Stop MIDI File + void sndMidiStop(); public: - MusicPlayer(PrinceEngine *vm); - ~MusicPlayer(); + MusicPlayer(PrinceEngine *vm); + ~MusicPlayer(); - void loadMidi(const char *); - void killMidi(); + void loadMidi(const char *); + void killMidi(); - virtual void send(uint32 b); - virtual void sendToChannel(byte channel, uint32 b); + virtual void send(uint32 b); + virtual void sendToChannel(byte channel, uint32 b); - static const char * _musTable[]; - static const uint8 _musRoomTable[]; + static const char * _musTable[]; + static const uint8 _musRoomTable[]; }; } // End of namespace Prince diff --git a/engines/prince/variatxt.cpp b/engines/prince/variatxt.cpp index 073080e505..0788d449e3 100644 --- a/engines/prince/variatxt.cpp +++ b/engines/prince/variatxt.cpp @@ -29,21 +29,21 @@ VariaTxt::VariaTxt() : _dataSize(0), _data(NULL) { } VariaTxt::~VariaTxt() { - _dataSize = 0; - delete[] _data; - _dataSize = NULL; + _dataSize = 0; + delete[] _data; + _dataSize = NULL; } bool VariaTxt::loadFromStream(Common::SeekableReadStream &stream) { - _dataSize = stream.size(); - _data = new byte [_dataSize]; - stream.read(_data, _dataSize); - return true; + _dataSize = stream.size(); + _data = new byte [_dataSize]; + stream.read(_data, _dataSize); + return true; } const char * VariaTxt::getString(uint32 stringId) { - uint32 stringOffset = READ_LE_UINT32(_data + stringId); + uint32 stringOffset = READ_LE_UINT32(_data + stringId); if (stringOffset > _dataSize) { assert(false); diff --git a/engines/prince/variatxt.h b/engines/prince/variatxt.h index 5983054d57..dcdba7bd8a 100644 --- a/engines/prince/variatxt.h +++ b/engines/prince/variatxt.h @@ -30,13 +30,13 @@ public: ~VariaTxt(); - bool loadFromStream(Common::SeekableReadStream &stream); + bool loadFromStream(Common::SeekableReadStream &stream); - const char * getString(uint32 stringId); + const char * getString(uint32 stringId); private: - uint32 _dataSize; - byte *_data; + uint32 _dataSize; + byte *_data; }; } |