aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/access/room.cpp8
-rw-r--r--engines/access/scripts.cpp245
-rw-r--r--engines/access/scripts.h152
3 files changed, 207 insertions, 198 deletions
diff --git a/engines/access/room.cpp b/engines/access/room.cpp
index fb70e35ee0..e0acf1c32a 100644
--- a/engines/access/room.cpp
+++ b/engines/access/room.cpp
@@ -193,9 +193,11 @@ void Room::loadRoomData(const byte *roomData) {
// Load script data
_vm->_scripts->freeScriptData();
- if (roomInfo._scriptFile._fileNum != -1)
- _vm->_scripts->_script = _vm->_files->loadFile(roomInfo._scriptFile._fileNum,
- roomInfo._scriptFile._subfile);
+ if (roomInfo._scriptFile._fileNum != -1) {
+ const byte *data = _vm->_files->loadFile(roomInfo._scriptFile._fileNum,
+ roomInfo._scriptFile._subfile);
+ _vm->_scripts->setScript(data, _vm->_files->_filesize);
+ }
// Load animation data
_vm->_animation->freeAnimationData();
diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp
index 2705d70d9f..bc86e09fcb 100644
--- a/engines/access/scripts.cpp
+++ b/engines/access/scripts.cpp
@@ -29,8 +29,8 @@
namespace Access {
Scripts::Scripts(AccessEngine *vm) : _vm(vm) {
- _script = nullptr;
- _scriptLoc = nullptr;
+ _rawData = nullptr;
+ _data = nullptr;
_sequence = 0;
_endFlag = false;
_returnCode = 0;
@@ -40,43 +40,47 @@ Scripts::~Scripts() {
freeScriptData();
}
+void Scripts::setScript(const byte *data, int size) {
+ _rawData = data;
+ _data = new Common::MemoryReadStream(data, size, DisposeAfterUse::NO);
+}
+
void Scripts::freeScriptData() {
- delete[] _script;
- _script = nullptr;
+ delete[] _rawData;
+ delete _data;
+ _data = nullptr;
+ _rawData = nullptr;
}
-const byte *Scripts::searchForSequence() {
- assert(_script);
- const byte *pSrc = _script;
+void Scripts::searchForSequence() {
+ assert(_data);
+
+ _data->seek(0);
int sequenceId;
do {
- while (*pSrc++ != SCRIPT_START_BYTE) ;
- sequenceId = READ_LE_UINT16(pSrc);
- pSrc += 2;
+ while (_data->readByte() != SCRIPT_START_BYTE) ;
+ sequenceId = _data->readUint16LE();
} while (sequenceId != _sequence);
-
- _scriptLoc = pSrc;
- return pSrc;
}
int Scripts::executeScript() {
- assert(_scriptLoc);
- _endFlag = 0;
+ assert(_data);
+ _endFlag = false;
_returnCode = 0;
do {
- const byte *pSrc = _scriptLoc;
- for (pSrc = _scriptLoc; *pSrc == SCRIPT_START_BYTE; pSrc += 3) ;
- _scriptCommand = *pSrc++;
+ // Get next command, skipping over script start start if it's being pointed to
+ for (_scriptCommand = _data->readByte(); _scriptCommand == SCRIPT_START_BYTE;
+ _data->skip(2));
- executeCommand(_scriptCommand - 0x80, pSrc);
- _scriptLoc = pSrc;
+ assert(_scriptCommand >= 0x80);
+ executeCommand(_scriptCommand - 0x80);
} while (!_endFlag);
return _returnCode;
}
-void Scripts::executeCommand(int commandIndex, const byte *&pScript) {
+void Scripts::executeCommand(int commandIndex) {
static const ScriptMethodPtr COMMAND_LIST[] = {
&Scripts::CMDOBJECT, &Scripts::CMDENDOBJECT, &Scripts::cmdJumpLook,
&Scripts::cmdJumpHelp, &Scripts::cmdJumpGet, &Scripts::cmdJumpMove,
@@ -107,179 +111,178 @@ void Scripts::executeCommand(int commandIndex, const byte *&pScript) {
&Scripts::cmdMainPanel, &Scripts::CMDRETFLASH
};
- (this->*COMMAND_LIST[commandIndex])(pScript);
+ (this->*COMMAND_LIST[commandIndex])();
}
-void Scripts::CMDOBJECT(const byte *&pScript) { }
+void Scripts::CMDOBJECT() { }
-void Scripts::CMDENDOBJECT(const byte *&pScript) { }
+void Scripts::CMDENDOBJECT() { }
-void Scripts::cmdJumpLook(const byte *&pScript) {
+void Scripts::cmdJumpLook() {
if (_vm->_selectCommand == 0)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdJumpHelp(const byte *&pScript) {
+void Scripts::cmdJumpHelp() {
if (_vm->_selectCommand == 8)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdJumpGet(const byte *&pScript) {
+void Scripts::cmdJumpGet() {
if (_vm->_selectCommand == 3)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdJumpMove(const byte *&pScript) {
+void Scripts::cmdJumpMove() {
if (_vm->_selectCommand == 2)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdJumpUse(const byte *&pScript) {
+void Scripts::cmdJumpUse() {
if (_vm->_selectCommand == 4)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdJumpTalk(const byte *&pScript) {
+void Scripts::cmdJumpTalk() {
if (_vm->_selectCommand == 6)
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdNull(const byte *&pScript) {
+void Scripts::cmdNull() {
}
-void Scripts::CMDPRINT(const byte *&pScript) { }
+void Scripts::CMDPRINT() { }
-void Scripts::cmdRetPos(const byte *&pScript) {
+void Scripts::cmdRetPos() {
_endFlag = true;
_returnCode = 0;
}
-void Scripts::CMDANIM(const byte *&pScript) { }
+void Scripts::CMDANIM() { }
-void Scripts::cmdSetFlag(const byte *&pScript) {
- int flagNum = *pScript++;
- byte flagVal = *pScript++;
+void Scripts::cmdSetFlag() {
+ int flagNum = _data->readByte();
+ byte flagVal = _data->readByte();
assert(flagNum < 100);
_vm->_flags[flagNum] = flagVal;
}
-void Scripts::CMDCHECKFLAG(const byte *&pScript) {
- int flagNum = READ_LE_UINT16(pScript);
- int flagVal = READ_LE_UINT16(pScript + 2);
- pScript += 4;
+void Scripts::CMDCHECKFLAG() {
+ int flagNum = _data->readUint16LE();
+ int flagVal = _data->readUint16LE();
assert(flagNum < 100);
if (_vm->_flags[flagNum] == (flagVal & 0xff))
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdGoto(const byte *&pScript) {
- _sequence = READ_LE_UINT16(pScript);
- pScript = searchForSequence();
+void Scripts::cmdGoto() {
+ _sequence = _data->readUint16LE();
+ searchForSequence();
}
-void Scripts::CMDSETINV(const byte *&pScript) { }
-void Scripts::CMDCHECKINV(const byte *&pScript) { }
-void Scripts::CMDSETTEX(const byte *&pScript) { }
-void Scripts::CMDNEWROOM(const byte *&pScript) { }
-void Scripts::CMDCONVERSE(const byte *&pScript) { }
-void Scripts::CMDCHECKFRAME(const byte *&pScript) { }
-void Scripts::CMDCHECKANIM(const byte *&pScript) { }
-void Scripts::CMDSND(const byte *&pScript) { }
-void Scripts::CMDRETNEG(const byte *&pScript) { }
-
-void Scripts::cmdCheckLoc(const byte *&pScript) {
- int minX = READ_LE_UINT16(pScript);
- int minY = READ_LE_UINT16(pScript);
- int maxX = READ_LE_UINT16(pScript);
- int maxY = READ_LE_UINT16(pScript);
+void Scripts::CMDSETINV() { }
+void Scripts::CMDCHECKINV() { }
+void Scripts::CMDSETTEX() { }
+void Scripts::CMDNEWROOM() { }
+void Scripts::CMDCONVERSE() { }
+void Scripts::CMDCHECKFRAME() { }
+void Scripts::CMDCHECKANIM() { }
+void Scripts::CMDSND() { }
+void Scripts::CMDRETNEG() { }
+
+void Scripts::cmdCheckLoc() {
+ int minX = _data->readUint16LE();
+ int minY = _data->readUint16LE();
+ int maxX = _data->readUint16LE();
+ int maxY = _data->readUint16LE();
int curX = _vm->_player->_rawPlayer.x + _vm->_player->_playerOffset.x;
int curY = _vm->_player->_rawPlayer.y;
if ((curX >= minX) && (curX <= maxX) && (curY >= minY) && (curY <= maxY))
- cmdGoto(pScript);
+ cmdGoto();
else
- pScript += 2;
+ _data->skip(2);
}
-void Scripts::cmdSetAnim(const byte *&pScript) {
- int animId = *pScript++;
+void Scripts::cmdSetAnim() {
+ int animId = _data->readByte();
Animation *anim = _vm->_animation->setAnimation(animId);
_vm->_animation->setAnimTimer(anim);
}
-void Scripts::CMDDISPINV(const byte *&pScript) { }
-void Scripts::CMDSETTIMER(const byte *&pScript) { }
-void Scripts::CMDCHECKTIMER(const byte *&pScript) { }
-void Scripts::CMDSETTRAVEL(const byte *&pScript) { }
-void Scripts::CMDSETVID(const byte *&pScript) { }
-void Scripts::CMDPLAYVID(const byte *&pScript) { }
-void Scripts::CMDPLOTIMAGE(const byte *&pScript) { }
-void Scripts::CMDSETDISPLAY(const byte *&pScript) { }
-void Scripts::CMDSETBUFFER(const byte *&pScript) { }
-void Scripts::CMDSETSCROLL(const byte *&pScript) { }
-void Scripts::CMDSAVERECT(const byte *&pScript) { }
-void Scripts::CMDSETBUFVID(const byte *&pScript) { }
-void Scripts::CMDPLAYBUFVID(const byte *&pScript) { }
-void Scripts::CMDREMOVELAST(const byte *&pScript) { }
-void Scripts::CMDSPECIAL(const byte *&pScript) { }
-void Scripts::CMDSETCYCLE(const byte *&pScript) { }
-void Scripts::CMDCYCLE(const byte *&pScript) { }
-void Scripts::CMDCHARSPEAK(const byte *&pScript) { }
-void Scripts::CMDTEXSPEAK(const byte *&pScript) { }
-void Scripts::CMDTEXCHOICE(const byte *&pScript) { }
-void Scripts::CMDWAIT(const byte *&pScript) { }
-void Scripts::CMDSETCONPOS(const byte *&pScript) { }
-void Scripts::CMDCHECKVFRAME(const byte *&pScript) { }
-void Scripts::CMDJUMPCHOICE(const byte *&pScript) { }
-void Scripts::CMDRETURNCHOICE(const byte *&pScript) { }
-void Scripts::CMDCLEARBLOCK(const byte *&pScript) { }
-void Scripts::CMDLOADSOUND(const byte *&pScript) { }
-void Scripts::CMDFREESOUND(const byte *&pScript) { }
-void Scripts::CMDSETVIDSND(const byte *&pScript) { }
-void Scripts::CMDPLAYVIDSND(const byte *&pScript) { }
-void Scripts::CMDPUSHLOCATION(const byte *&pScript) { }
-
-void Scripts::cmdPlayerOff(const byte *&pScript) {
+void Scripts::CMDDISPINV() { }
+void Scripts::CMDSETTIMER() { }
+void Scripts::CMDCHECKTIMER() { }
+void Scripts::CMDSETTRAVEL() { }
+void Scripts::CMDSETVID() { }
+void Scripts::CMDPLAYVID() { }
+void Scripts::CMDPLOTIMAGE() { }
+void Scripts::CMDSETDISPLAY() { }
+void Scripts::CMDSETBUFFER() { }
+void Scripts::CMDSETSCROLL() { }
+void Scripts::CMDSAVERECT() { }
+void Scripts::CMDSETBUFVID() { }
+void Scripts::CMDPLAYBUFVID() { }
+void Scripts::CMDREMOVELAST() { }
+void Scripts::CMDSPECIAL() { }
+void Scripts::CMDSETCYCLE() { }
+void Scripts::CMDCYCLE() { }
+void Scripts::CMDCHARSPEAK() { }
+void Scripts::CMDTEXSPEAK() { }
+void Scripts::CMDTEXCHOICE() { }
+void Scripts::CMDWAIT() { }
+void Scripts::CMDSETCONPOS() { }
+void Scripts::CMDCHECKVFRAME() { }
+void Scripts::CMDJUMPCHOICE() { }
+void Scripts::CMDRETURNCHOICE() { }
+void Scripts::CMDCLEARBLOCK() { }
+void Scripts::CMDLOADSOUND() { }
+void Scripts::CMDFREESOUND() { }
+void Scripts::CMDSETVIDSND() { }
+void Scripts::CMDPLAYVIDSND() { }
+void Scripts::CMDPUSHLOCATION() { }
+
+void Scripts::cmdPlayerOff() {
_vm->_player->_playerOff = true;
}
-void Scripts::cmdPlayerOn(const byte *&pScript) {
+void Scripts::cmdPlayerOn() {
_vm->_player->_playerOff = false;
}
-void Scripts::CMDDEAD(const byte *&pScript) { }
-void Scripts::CMDFADEOUT(const byte *&pScript) { }
-void Scripts::CMDENDVID(const byte *&pScript) { }
-void Scripts::CMDHELP(const byte *&pScript) { }
-void Scripts::CMDCYCLEBACK(const byte *&pScript) { }
-void Scripts::CMDCHAPTER(const byte *&pScript) { }
-void Scripts::CMDSETHELP(const byte *&pScript) { }
-void Scripts::CMDCENTERPANEL(const byte *&pScript) { }
+void Scripts::CMDDEAD() { }
+void Scripts::CMDFADEOUT() { }
+void Scripts::CMDENDVID() { }
+void Scripts::CMDHELP() { }
+void Scripts::CMDCYCLEBACK() { }
+void Scripts::CMDCHAPTER() { }
+void Scripts::CMDSETHELP() { }
+void Scripts::CMDCENTERPANEL() { }
-void Scripts::cmdMainPanel(const byte *&pScript) {
+void Scripts::cmdMainPanel() {
if (_vm->_screen->_vesaMode) {
_vm->_room->init4Quads();
_vm->_screen->setPanel(0);
}
}
-void Scripts::CMDRETFLASH(const byte *&pScript) { }
+void Scripts::CMDRETFLASH() { }
} // End of namespace Access
diff --git a/engines/access/scripts.h b/engines/access/scripts.h
index d78b74840d..4375934b7c 100644
--- a/engines/access/scripts.h
+++ b/engines/access/scripts.h
@@ -24,96 +24,98 @@
#define ACCESS_SCRIPTS_H
#include "common/scummsys.h"
+#include "common/memstream.h"
namespace Access {
class AccessEngine;
class Scripts;
-typedef void(Scripts::*ScriptMethodPtr)(const byte *&pScript);
+typedef void(Scripts::*ScriptMethodPtr)();
class Scripts {
+private:
+ const byte *_rawData;
+ Common::MemoryReadStream *_data;
protected:
AccessEngine *_vm;
- virtual void executeCommand(int commandIndex, const byte *&pScript);
- void CMDOBJECT(const byte *&pScript);
- void CMDENDOBJECT(const byte *&pScript);
- void cmdJumpLook(const byte *&pScript);
- void cmdJumpHelp(const byte *&pScript);
- void cmdJumpGet(const byte *&pScript);
- void cmdJumpMove(const byte *&pScript);
- void cmdJumpUse(const byte *&pScript);
- void cmdJumpTalk(const byte *&pScript);
- void cmdNull(const byte *&pScript);
- void CMDPRINT(const byte *&pScript);
- void cmdRetPos(const byte *&pScript);
- void CMDANIM(const byte *&pScript);
- void cmdSetFlag(const byte *&pScript);
- void CMDCHECKFLAG(const byte *&pScript);
+ virtual void executeCommand(int commandIndex);
+ void CMDOBJECT();
+ void CMDENDOBJECT();
+ void cmdJumpLook();
+ void cmdJumpHelp();
+ void cmdJumpGet();
+ void cmdJumpMove();
+ void cmdJumpUse();
+ void cmdJumpTalk();
+ void cmdNull();
+ void CMDPRINT();
+ void cmdRetPos();
+ void CMDANIM();
+ void cmdSetFlag();
+ void CMDCHECKFLAG();
/**
* Jump to another script
*/
- void cmdGoto(const byte *&pScript);
+ void cmdGoto();
- void CMDSETINV(const byte *&pScript);
- void CMDCHECKINV(const byte *&pScript);
- void CMDSETTEX(const byte *&pScript);
- void CMDNEWROOM(const byte *&pScript);
- void CMDCONVERSE(const byte *&pScript);
- void CMDCHECKFRAME(const byte *&pScript);
- void CMDCHECKANIM(const byte *&pScript);
- void CMDSND(const byte *&pScript);
- void CMDRETNEG(const byte *&pScript);
- void cmdCheckLoc(const byte *&pScript);
- void cmdSetAnim(const byte *&pScript);
- void CMDDISPINV(const byte *&pScript);
- void CMDSETTIMER(const byte *&pScript);
- void CMDCHECKTIMER(const byte *&pScript);
- void CMDSETTRAVEL(const byte *&pScript);
- void CMDSETVID(const byte *&pScript);
- void CMDPLAYVID(const byte *&pScript);
- void CMDPLOTIMAGE(const byte *&pScript);
- void CMDSETDISPLAY(const byte *&pScript);
- void CMDSETBUFFER(const byte *&pScript);
- void CMDSETSCROLL(const byte *&pScript);
- void CMDSAVERECT(const byte *&pScript);
- void CMDSETBUFVID(const byte *&pScript);
- void CMDPLAYBUFVID(const byte *&pScript);
- void CMDREMOVELAST(const byte *&pScript);
- void CMDSPECIAL(const byte *&pScript);
- void CMDSETCYCLE(const byte *&pScript);
- void CMDCYCLE(const byte *&pScript);
- void CMDCHARSPEAK(const byte *&pScript);
- void CMDTEXSPEAK(const byte *&pScript);
- void CMDTEXCHOICE(const byte *&pScript);
- void CMDWAIT(const byte *&pScript);
- void CMDSETCONPOS(const byte *&pScript);
- void CMDCHECKVFRAME(const byte *&pScript);
- void CMDJUMPCHOICE(const byte *&pScript);
- void CMDRETURNCHOICE(const byte *&pScript);
- void CMDCLEARBLOCK(const byte *&pScript);
- void CMDLOADSOUND(const byte *&pScript);
- void CMDFREESOUND(const byte *&pScript);
- void CMDSETVIDSND(const byte *&pScript);
- void CMDPLAYVIDSND(const byte *&pScript);
- void CMDPUSHLOCATION(const byte *&pScript);
- void cmdPlayerOff(const byte *&pScript);
- void cmdPlayerOn(const byte *&pScript);
- void CMDDEAD(const byte *&pScript);
- void CMDFADEOUT(const byte *&pScript);
- void CMDENDVID(const byte *&pScript);
- void CMDHELP(const byte *&pScript);
- void CMDCYCLEBACK(const byte *&pScript);
- void CMDCHAPTER(const byte *&pScript);
- void CMDSETHELP(const byte *&pScript);
- void CMDCENTERPANEL(const byte *&pScript);
- void cmdMainPanel(const byte *&pScript);
- void CMDRETFLASH(const byte *&pScript);
+ void CMDSETINV();
+ void CMDCHECKINV();
+ void CMDSETTEX();
+ void CMDNEWROOM();
+ void CMDCONVERSE();
+ void CMDCHECKFRAME();
+ void CMDCHECKANIM();
+ void CMDSND();
+ void CMDRETNEG();
+ void cmdCheckLoc();
+ void cmdSetAnim();
+ void CMDDISPINV();
+ void CMDSETTIMER();
+ void CMDCHECKTIMER();
+ void CMDSETTRAVEL();
+ void CMDSETVID();
+ void CMDPLAYVID();
+ void CMDPLOTIMAGE();
+ void CMDSETDISPLAY();
+ void CMDSETBUFFER();
+ void CMDSETSCROLL();
+ void CMDSAVERECT();
+ void CMDSETBUFVID();
+ void CMDPLAYBUFVID();
+ void CMDREMOVELAST();
+ void CMDSPECIAL();
+ void CMDSETCYCLE();
+ void CMDCYCLE();
+ void CMDCHARSPEAK();
+ void CMDTEXSPEAK();
+ void CMDTEXCHOICE();
+ void CMDWAIT();
+ void CMDSETCONPOS();
+ void CMDCHECKVFRAME();
+ void CMDJUMPCHOICE();
+ void CMDRETURNCHOICE();
+ void CMDCLEARBLOCK();
+ void CMDLOADSOUND();
+ void CMDFREESOUND();
+ void CMDSETVIDSND();
+ void CMDPLAYVIDSND();
+ void CMDPUSHLOCATION();
+ void cmdPlayerOff();
+ void cmdPlayerOn();
+ void CMDDEAD();
+ void CMDFADEOUT();
+ void CMDENDVID();
+ void CMDHELP();
+ void CMDCYCLEBACK();
+ void CMDCHAPTER();
+ void CMDSETHELP();
+ void CMDCENTERPANEL();
+ void cmdMainPanel();
+ void CMDRETFLASH();
public:
- const byte *_script;
- const byte *_scriptLoc;
int _sequence;
bool _endFlag;
int _returnCode;
@@ -123,9 +125,11 @@ public:
virtual ~Scripts();
+ void setScript(const byte *data, int size);
+
void freeScriptData();
- const byte *searchForSequence();
+ void searchForSequence();
int executeScript();
};