aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/gob/draw.cpp10
-rw-r--r--engines/gob/draw_v2.cpp3
-rw-r--r--engines/gob/game.cpp128
-rw-r--r--engines/gob/game.h9
-rw-r--r--engines/gob/game_fascin.cpp1
-rw-r--r--engines/gob/game_v1.cpp254
-rw-r--r--engines/gob/game_v2.cpp207
-rw-r--r--engines/gob/game_v6.cpp209
-rw-r--r--engines/gob/init.cpp1
-rw-r--r--engines/gob/inter.cpp46
-rw-r--r--engines/gob/inter.h7
-rw-r--r--engines/gob/inter_fascin.cpp24
-rw-r--r--engines/gob/inter_v1.cpp673
-rw-r--r--engines/gob/inter_v2.cpp441
-rw-r--r--engines/gob/inter_v3.cpp8
-rw-r--r--engines/gob/inter_v4.cpp26
-rw-r--r--engines/gob/inter_v5.cpp76
-rw-r--r--engines/gob/inter_v6.cpp93
-rw-r--r--engines/gob/map_v2.cpp8
-rw-r--r--engines/gob/map_v4.cpp8
-rw-r--r--engines/gob/module.mk1
-rw-r--r--engines/gob/mult.cpp8
-rw-r--r--engines/gob/mult_v1.cpp12
-rw-r--r--engines/gob/mult_v2.cpp40
-rw-r--r--engines/gob/parse.cpp208
-rw-r--r--engines/gob/scenery.cpp35
-rw-r--r--engines/gob/script.cpp361
-rw-r--r--engines/gob/script.h126
28 files changed, 1701 insertions, 1322 deletions
diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index 8619e08e8b..5c0cb47352 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -30,6 +30,7 @@
#include "gob/global.h"
#include "gob/util.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/inter.h"
#include "gob/video.h"
#include "gob/palanim.h"
@@ -389,11 +390,10 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
adjustCoords(1, &left, &top);
adjustCoords(1, &right, &bottom);
- if (READ_LE_UINT16(_vm->_game->_totFileData + 0x7E) != 0) {
- byte *storedIP = _vm->_global->_inter_execPtr;
+ if (READ_LE_UINT16(_vm->_game->_script->getData() + 0x7E) != 0) {
+ uint32 startPos = _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr = _vm->_game->_totFileData +
- READ_LE_UINT16(_vm->_game->_totFileData + 0x7E);
+ _vm->_game->_script->seek(READ_LE_UINT16(_vm->_game->_script->getData() + 0x7E));
WRITE_VAR(17, (uint32) id);
WRITE_VAR(18, (uint32) left);
WRITE_VAR(19, (uint32) top);
@@ -401,7 +401,7 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
WRITE_VAR(21, (uint32) (bottom - top + 1));
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = storedIP;
+ _vm->_game->_script->seek(startPos);
}
if (str[0] == '\0')
diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp
index 86b8794f1c..8a5b42f679 100644
--- a/engines/gob/draw_v2.cpp
+++ b/engines/gob/draw_v2.cpp
@@ -32,6 +32,7 @@
#include "gob/global.h"
#include "gob/util.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/scenery.h"
#include "gob/inter.h"
#include "gob/video.h"
@@ -328,7 +329,7 @@ void Draw_v2::printTotText(int16 id) {
ptrEnd = ptr;
while (((ptrEnd - dataPtr) < size) && (*ptrEnd != 1)) {
// Converting to unknown commands/characters to spaces
- if ((_vm->_game->_totFileData[0x29] < 0x32) && (*ptrEnd > 3) && (*ptrEnd < 32))
+ if ((_vm->_game->_script->getData()[0x29] < 0x32) && (*ptrEnd > 3) && (*ptrEnd < 32))
*ptrEnd = 32;
switch (*ptrEnd) {
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp
index 8ead71411c..8251219ed1 100644
--- a/engines/gob/game.cpp
+++ b/engines/gob/game.cpp
@@ -31,8 +31,8 @@
#include "gob/global.h"
#include "gob/util.h"
#include "gob/dataio.h"
+#include "gob/script.h"
#include "gob/inter.h"
-#include "gob/parse.h"
#include "gob/draw.h"
#include "gob/mult.h"
#include "gob/videoplayer.h"
@@ -42,7 +42,6 @@ namespace Gob {
Game::Game(GobEngine *vm) : _vm(vm) {
_extTable = 0;
- _totFileData = 0;
_totResourceTable = 0;
_imFileData = 0;
_extHandle = 0;
@@ -95,7 +94,6 @@ Game::Game(GobEngine *vm) : _vm(vm) {
_cursorHotspotXArray[i] = 0;
_cursorHotspotYArray[i] = 0;
_totTextDataArray[i] = 0;
- _totFileDataArray[i] = 0;
_totResourceTableArray[i] = 0;
_extTableArray[i] = 0;
_extHandleArray[i] = 0;
@@ -103,19 +101,22 @@ Game::Game(GobEngine *vm) : _vm(vm) {
_variablesArray[i] = 0;
_curTotFileArray[i][0] = 0;
}
+
+ _script = new Script(_vm);
}
Game::~Game() {
- delete[] _vm->_game->_totFileData;
- if (_vm->_game->_totTextData) {
- if (_vm->_game->_totTextData->items)
- delete[] _vm->_game->_totTextData->items;
- delete _vm->_game->_totTextData;
+ if (_totTextData) {
+ if (_totTextData->items)
+ delete[] _totTextData->items;
+ delete _totTextData;
}
- if (_vm->_game->_totResourceTable) {
- delete[] _vm->_game->_totResourceTable->items;
- delete _vm->_game->_totResourceTable;
+ if (_totResourceTable) {
+ delete[] _totResourceTable->items;
+ delete _totResourceTable;
}
+
+ delete _script;
}
byte *Game::loadExtData(int16 itemId, int16 *pResWidth,
@@ -175,7 +176,7 @@ byte *Game::loadExtData(int16 itemId, int16 *pResWidth,
tableSize = 0;
_vm->_dataIO->closeData(_extHandle);
strcpy(path, "commun.ex1");
- path[strlen(path) - 1] = *(_totFileData + 0x3C) + '0';
+ path[strlen(path) - 1] = *(_script->getData() + 0x3C) + '0';
commonHandle = _vm->_dataIO->openData(path);
handle = commonHandle;
} else
@@ -287,7 +288,7 @@ byte *Game::loadTotResource(int16 id,
TotResItem *itemPtr;
int32 offset;
- if (id >= _vm->_game->_totResourceTable->itemsCount) {
+ if (id >= _totResourceTable->itemsCount) {
warning("Trying to load non-existent TOT resource (%s, %d/%d)",
_curTotFile, id, _totResourceTable->itemsCount - 1);
return 0;
@@ -313,7 +314,7 @@ byte *Game::loadTotResource(int16 id,
void Game::freeSoundSlot(int16 slot) {
if (slot == -1)
- slot = _vm->_parse->parseValExpr();
+ slot = _script->readValExpr();
_vm->_sound->sampleFree(_vm->_sound->sampleGetBySlot(slot));
}
@@ -416,50 +417,6 @@ int16 Game::adjustKey(int16 key) {
return key - 0x20;
}
-int32 Game::loadTotFile(const char *path) {
- int32 size;
-
- _lomHandle = -1;
-
- size = -1;
- if (_vm->_dataIO->existData(path)) {
- if (!scumm_stricmp(path + strlen(path) - 3, "LOM")) {
- warning("Urban Stub: loadTotFile %s", path);
-
- _lomHandle = _vm->_dataIO->openData(path);
-
- DataStream *stream = _vm->_dataIO->openAsStream(_lomHandle);
-
- stream->seek(48);
- size = stream->readUint32LE();
- stream->seek(0);
-
- _totFileData = new byte[size];
- stream->read(_totFileData, size);
-
- delete stream;
- } else {
- size = _vm->_dataIO->getDataSize(path);
- _totFileData = _vm->_dataIO->getData(path);
- }
-
- } else {
- Common::MemoryReadStream *videoExtraData = _vm->_vidPlayer->getExtraData(path);
-
- if (videoExtraData) {
- warning("Found \"%s\" in video file", path);
-
- size = videoExtraData->size();
- _totFileData = new byte[size];
- videoExtraData->read(_totFileData, size);
- delete videoExtraData;
- } else
- _totFileData = 0;
- }
-
- return size;
-}
-
void Game::loadExtTable(void) {
int16 count;
@@ -494,12 +451,12 @@ void Game::loadExtTable(void) {
void Game::loadImFile(void) {
char path[20];
- if ((_totFileData[0x3D] != 0) && (_totFileData[0x3B] == 0))
+ if ((_script->getData()[0x3D] != 0) && (_script->getData()[0x3B] == 0))
return;
strcpy(path, "commun.im1");
- if (_totFileData[0x3B] != 0)
- path[strlen(path) - 1] = '0' + _totFileData[0x3B];
+ if (_script->getData()[0x3B] != 0)
+ path[strlen(path) - 1] = '0' + _script->getData()[0x3B];
if (!_vm->_dataIO->existData(path))
return;
@@ -524,6 +481,8 @@ void Game::start(void) {
// flagbits: 0 = freeInterVariables, 1 = skipPlay
void Game::totSub(int8 flags, const char *newTotFile) {
+ warning("totSub");
+
int8 curBackupPos;
if (_backupedCount >= 5)
@@ -531,8 +490,8 @@ void Game::totSub(int8 flags, const char *newTotFile) {
_cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar;
_cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar;
+ _scriptArray[_backupedCount] = _script;
_totTextDataArray[_backupedCount] = _totTextData;
- _totFileDataArray[_backupedCount] = _totFileData;
_totResourceTableArray[_backupedCount] = _totResourceTable;
_extTableArray[_backupedCount] = _extTable;
_extHandleArray[_backupedCount] = _extHandle;
@@ -545,7 +504,7 @@ void Game::totSub(int8 flags, const char *newTotFile) {
_curBackupPos = _backupedCount;
_totTextData = 0;
- _totFileData = 0;
+ _script = new Script(_vm);
_totResourceTable = 0;
if (flags & 1)
_vm->_inter->_variables = 0;
@@ -581,7 +540,7 @@ void Game::totSub(int8 flags, const char *newTotFile) {
_vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_backupedCount];
_vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_backupedCount];
_totTextData = _totTextDataArray[_backupedCount];
- _totFileData = _totFileDataArray[_backupedCount];
+ _script = _scriptArray[_backupedCount];
_totResourceTable = _totResourceTableArray[_backupedCount];
_extTable = _extTableArray[_backupedCount];
_extHandle = _extHandleArray[_backupedCount];
@@ -594,6 +553,8 @@ void Game::totSub(int8 flags, const char *newTotFile) {
}
void Game::switchTotSub(int16 index, int16 skipPlay) {
+ warning("switchTotSub");
+
int16 backupedCount;
int16 curBackupPos;
@@ -613,7 +574,7 @@ void Game::switchTotSub(int16 index, int16 skipPlay) {
_cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar;
_cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar;
_totTextDataArray[_backupedCount] = _totTextData;
- _totFileDataArray[_backupedCount] = _totFileData;
+ _scriptArray[_backupedCount] = _script;
_totResourceTableArray[_backupedCount] = _totResourceTable;
_extTableArray[_backupedCount] = _extTable;
_extHandleArray[_backupedCount] = _extHandle;
@@ -629,7 +590,7 @@ void Game::switchTotSub(int16 index, int16 skipPlay) {
_vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_curBackupPos];
_vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_curBackupPos];
_totTextData = _totTextDataArray[_curBackupPos];
- _totFileData = _totFileDataArray[_curBackupPos];
+ _script = _scriptArray[_curBackupPos];
_totResourceTable = _totResourceTableArray[_curBackupPos];
_imFileData = _imFileDataArray[_curBackupPos];
_extTable = _extTableArray[_curBackupPos];
@@ -643,20 +604,20 @@ void Game::switchTotSub(int16 index, int16 skipPlay) {
if (_vm->_inter->_terminate != 0)
return;
- _vm->_game->pushCollisions(0);
- _vm->_game->playTot(skipPlay);
+ pushCollisions(0);
+ playTot(skipPlay);
if (_vm->_inter->_terminate != 2)
_vm->_inter->_terminate = 0;
- _vm->_game->popCollisions();
+ popCollisions();
_curBackupPos = curBackupPos;
_backupedCount = backupedCount;
_vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_curBackupPos];
_vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_curBackupPos];
_totTextData = _totTextDataArray[_curBackupPos];
- _totFileData = _totFileDataArray[_curBackupPos];
+ _script = _scriptArray[_curBackupPos];
_totResourceTable = _totResourceTableArray[_curBackupPos];
_extTable = _extTableArray[_curBackupPos];
_extHandle = _extHandleArray[_curBackupPos];
@@ -761,7 +722,6 @@ byte *Game::loadLocTexts(int32 *dataSize) {
}
void Game::setCollisions(byte arg_0) {
- byte *savedIP;
uint16 left;
uint16 top;
uint16 width;
@@ -772,12 +732,14 @@ void Game::setCollisions(byte arg_0) {
if (((collArea->id & 0xC000) != 0x8000) || (collArea->funcSub == 0))
continue;
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData + collArea->funcSub;
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ uint32 startPos = _script->pos();
+
+ _script->seek(collArea->funcSub);
+
+ left = _script->readValExpr();
+ top = _script->readValExpr();
+ width = _script->readValExpr();
+ height = _script->readValExpr();
if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) &&
(left != 0xFFFF)) {
left += _vm->_draw->_backDeltaX;
@@ -796,16 +758,17 @@ void Game::setCollisions(byte arg_0) {
collArea->top = top;
collArea->right = left + width - 1;
collArea->bottom = top + height - 1;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
}
void Game::collSub(uint16 offset) {
- byte *savedIP;
int16 collStackSize;
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData + offset;
+ uint32 startPos = _script->pos();
+
+ _script->seek(offset);
_shouldPushColls = 1;
collStackSize = _collStackSize;
@@ -816,7 +779,8 @@ void Game::collSub(uint16 offset) {
popCollisions();
_shouldPushColls = 0;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
setCollisions();
}
diff --git a/engines/gob/game.h b/engines/gob/game.h
index 8ab3521633..26881c2253 100644
--- a/engines/gob/game.h
+++ b/engines/gob/game.h
@@ -30,6 +30,8 @@
namespace Gob {
+class Script;
+
class Game {
public:
@@ -47,6 +49,7 @@ public:
uint16 funcLeave;
uint16 funcSub;
byte *totFileData;
+ uint32 totSize;
} PACKED_STRUCT;
#define szGame_TotTextItem (2 + 2)
@@ -77,11 +80,12 @@ public:
bool _foundTotLoc;
TotTextTable *_totTextData;
+ Script *_script;
+
char _curTotFile[14];
char _curExtFile[14];
byte *_imFileData;
- byte *_totFileData;
int16 _extHandle;
int16 _lomHandle;
@@ -211,20 +215,19 @@ protected:
int16 _cursorHotspotXArray[5];
int16 _cursorHotspotYArray[5];
TotTextTable *_totTextDataArray[5];
- byte *_totFileDataArray[5];
TotResTable *_totResourceTableArray[5];
ExtTable *_extTableArray[5];
int16 _extHandleArray[5];
byte *_imFileDataArray[5];
Variables *_variablesArray[5];
char _curTotFileArray[5][14];
+ Script *_scriptArray[5];
GobEngine *_vm;
virtual int16 adjustKey(int16 key);
byte *loadLocTexts(int32 *dataSize = 0);
- int32 loadTotFile(const char *path);
void loadExtTable(void);
void loadImFile(void);
diff --git a/engines/gob/game_fascin.cpp b/engines/gob/game_fascin.cpp
index 8e77141ce6..38ad03f0f8 100644
--- a/engines/gob/game_fascin.cpp
+++ b/engines/gob/game_fascin.cpp
@@ -35,7 +35,6 @@
#include "gob/goblin.h"
#include "gob/inter.h"
#include "gob/mult.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/video.h"
#include "gob/videoplayer.h"
diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp
index ad24d7d9c6..c4fbe49bcc 100644
--- a/engines/gob/game_v1.cpp
+++ b/engines/gob/game_v1.cpp
@@ -32,11 +32,11 @@
#include "gob/global.h"
#include "gob/util.h"
#include "gob/dataio.h"
+#include "gob/script.h"
#include "gob/draw.h"
#include "gob/inter.h"
#include "gob/mult.h"
#include "gob/video.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/sound/sound.h"
@@ -54,7 +54,8 @@ void Game_v1::playTot(int16 skipPlay) {
int16 *oldNestLevel = _vm->_inter->_nestLevel;
int16 *oldBreakFrom = _vm->_inter->_breakFromLevel;
int16 *oldCaptureCounter = _vm->_scenery->_pCaptureCounter;
- byte *savedIP = _vm->_global->_inter_execPtr;
+
+ uint32 startPos = _script->pos();
_vm->_inter->_nestLevel = &nestLevel;
_vm->_inter->_breakFromLevel = &breakFrom;
@@ -101,11 +102,10 @@ void Game_v1::playTot(int16 skipPlay) {
_totToLoad[0] = 0;
- if ((_curTotFile[0] == 0) && (_totFileData == 0))
+ if ((_curTotFile[0] == 0) && !_script->isLoaded())
break;
- loadTotFile(_curTotFile);
- if (_totFileData == 0) {
+ if (!_script->load(_curTotFile)) {
_vm->_draw->blitCursor();
break;
}
@@ -122,13 +122,13 @@ void Game_v1::playTot(int16 skipPlay) {
debugC(4, kDebugFileIO, "IMA: %s", _curImaFile);
debugC(4, kDebugFileIO, "EXT: %s", _curExtFile);
- byte *filePtr = _totFileData + 0x30;
+ byte *filePtr = _script->getData() + 0x30;
_totTextData = 0;
if (READ_LE_UINT32(filePtr) != (uint32) -1) {
_totTextData = new TotTextTable;
_totTextData->dataPtr =
- (_totFileData + READ_LE_UINT32(_totFileData + 0x30));
+ (_script->getData() + READ_LE_UINT32(_script->getData() + 0x30));
Common::MemoryReadStream totTextData(_totTextData->dataPtr,
4294967295U);
@@ -141,12 +141,12 @@ void Game_v1::playTot(int16 skipPlay) {
}
}
- filePtr = _totFileData + 0x34;
+ filePtr = _script->getData() + 0x34;
_totResourceTable = 0;
if (READ_LE_UINT32(filePtr) != (uint32) -1) {
_totResourceTable = new TotResTable;
_totResourceTable->dataPtr =
- _totFileData + READ_LE_UINT32( _totFileData + 0x34);
+ _script->getData() + READ_LE_UINT32(_script->getData() + 0x34);
Common::MemoryReadStream totResTable(_totResourceTable->dataPtr,
4294967295U);
@@ -167,12 +167,11 @@ void Game_v1::playTot(int16 skipPlay) {
loadExtTable();
_vm->_global->_inter_animDataSize =
- READ_LE_UINT16(_totFileData + 0x38);
+ READ_LE_UINT16(_script->getData() + 0x38);
if (!_vm->_inter->_variables)
- _vm->_inter->allocateVars(READ_LE_UINT16(_totFileData + 0x2C));
+ _vm->_inter->allocateVars(READ_LE_UINT16(_script->getData() + 0x2C));
- _vm->_global->_inter_execPtr = _totFileData;
- _vm->_global->_inter_execPtr += READ_LE_UINT32(_totFileData + 0x64);
+ _script->seek(READ_LE_UINT32(_script->getData() + 0x64));
_vm->_inter->renewTimeInVars();
@@ -182,14 +181,15 @@ void Game_v1::playTot(int16 skipPlay) {
WRITE_VAR(16, _vm->_global->_language);
_vm->_inter->callSub(2);
+ _script->setFinished(false);
if (_totToLoad[0] != 0)
_vm->_inter->_terminate = 0;
- variablesCount = READ_LE_UINT32(_totFileData + 0x2C);
+ variablesCount = READ_LE_UINT32(_script->getData() + 0x2C);
_vm->_draw->blitInvalidated();
- delete[] _totFileData;
- _totFileData = 0;
+
+ _script->unload();
if (_totTextData) {
delete[] _totTextData->items;
@@ -241,7 +241,8 @@ void Game_v1::playTot(int16 skipPlay) {
_vm->_inter->_nestLevel = oldNestLevel;
_vm->_inter->_breakFromLevel = oldBreakFrom;
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
void Game_v1::clearCollisions() {
@@ -280,6 +281,7 @@ int16 Game_v1::addNewCollision(int16 id, uint16 left, uint16 top,
ptr->funcLeave = funcLeave;
ptr->funcSub = funcSub;
ptr->totFileData = 0;
+ ptr->totSize = 0;
return i;
}
@@ -331,7 +333,6 @@ void Game_v1::popCollisions(void) {
int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
int16 *pResId, int16 *pResIndex) {
- byte *savedIP;
int16 resIndex;
int16 key;
int16 oldIndex;
@@ -357,12 +358,13 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
_lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcEnter;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
}
@@ -423,12 +425,14 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcLeave;
+
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
_lastCollKey = 0;
@@ -463,12 +467,13 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcLeave;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
_lastCollKey = 0;
return key;
@@ -476,24 +481,26 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if ((_lastCollKey != 0) &&
(_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcLeave;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcLeave);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
_lastCollKey =
checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcEnter;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
} else {
@@ -507,23 +514,26 @@ int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime,
if (key != _lastCollKey) {
if ((_lastCollKey != 0) && ((oldId & 0x8000) != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[oldIndex].funcLeave;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[oldIndex].funcLeave);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
_lastCollKey = key;
if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_lastCollAreaIndex].funcEnter;
+ uint32 startPos = _script->pos();
+
+ _script->seek(_collisionAreas[_lastCollAreaIndex].funcEnter);
_vm->_inter->funcBlock(0);
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
+
}
}
}
@@ -588,7 +598,6 @@ void Game_v1::collisionsBlock(void) {
int16 array[250];
byte count;
int16 collResId;
- byte *startIP;
int16 curCmd;
int16 cmd;
int16 cmdHigh;
@@ -615,27 +624,27 @@ void Game_v1::collisionsBlock(void) {
int16 collStackPos;
Collision *collPtr;
uint32 timeKey;
- byte *savedIP;
if (_shouldPushColls)
pushCollisions(1);
collResId = -1;
- _vm->_global->_inter_execPtr++;
- count = *_vm->_global->_inter_execPtr++;
- _handleMouse = _vm->_global->_inter_execPtr[0];
- deltaTime = 1000 * _vm->_global->_inter_execPtr[1];
- descIndex2 = _vm->_global->_inter_execPtr[2];
- stackPos2 = _vm->_global->_inter_execPtr[3];
- descIndex = _vm->_global->_inter_execPtr[4];
+ _script->skip(1);
+ count = _script->readByte();
+ _handleMouse = _script->readByte();
+ deltaTime = 1000 * _script->readByte();
+ descIndex2 = _script->readByte();
+ stackPos2 = _script->readByte();
+ descIndex = _script->readByte();
if ((stackPos2 != 0) || (descIndex != 0))
deltaTime /= 100;
timeVal = deltaTime;
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(1);
+
+ uint32 startPos = _script->pos();
- startIP = _vm->_global->_inter_execPtr;
WRITE_VAR(16, 0);
var_22 = 0;
index = 0;
@@ -643,26 +652,25 @@ void Game_v1::collisionsBlock(void) {
for (curCmd = 0; curCmd < count; curCmd++) {
array[curCmd] = 0;
- cmd = *_vm->_global->_inter_execPtr++;
+ cmd = _script->readByte();
if ((cmd & 0x40) != 0) {
cmd -= 0x40;
- cmdHigh = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr++;
+ cmdHigh = _script->readByte();
cmdHigh <<= 8;
} else
cmdHigh = 0;
if ((cmd & 0x80) != 0) {
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ left = _script->readValExpr();
+ top = _script->readValExpr();
+ width = _script->readValExpr();
+ height = _script->readValExpr();
} else {
- left = _vm->_inter->load16();
- top = _vm->_inter->load16();
- width = _vm->_inter->load16();
- height = _vm->_inter->load16();
+ left = _script->readUint16();
+ top = _script->readUint16();
+ width = _script->readUint16();
+ height = _script->readUint16();
}
cmd &= 0x7F;
@@ -680,16 +688,16 @@ void Game_v1::collisionsBlock(void) {
_vm->_util->clearKeyBuf();
var_22 = 1;
- key = _vm->_parse->parseVarIndex();
- descArray[index].fontIndex = _vm->_inter->load16();
- descArray[index].backColor = *_vm->_global->_inter_execPtr++;
- descArray[index].frontColor = *_vm->_global->_inter_execPtr++;
+ key = _script->readVarIndex();
+ descArray[index].fontIndex = _script->readInt16();
+ descArray[index].backColor = _script->readByte();
+ descArray[index].frontColor = _script->readByte();
if ((cmd < 5) || (cmd > 8)) {
descArray[index].ptr = 0;
} else {
- descArray[index].ptr = _vm->_global->_inter_execPtr + 2;
- _vm->_global->_inter_execPtr += _vm->_inter->load16();
+ descArray[index].ptr = _script->getData() + _script->pos() + 2;
+ _script->skip(_script->readInt16());
}
if (left == 0xFFFF)
@@ -698,12 +706,9 @@ void Game_v1::collisionsBlock(void) {
if ((cmd & 1) == 0) {
addNewCollision(curCmd + 0x8000, left, top, left + width *
_vm->_draw->_fonts[descArray[index].fontIndex]->itemWidth - 1,
- top + height - 1, cmd, key, 0,
- _vm->_global->_inter_execPtr - _totFileData);
+ top + height - 1, cmd, key, 0, _script->pos());
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
} else {
addNewCollision(curCmd + 0x8000, left, top, left + width *
_vm->_draw->_fonts[descArray[index].fontIndex]->itemWidth - 1,
@@ -713,18 +718,15 @@ void Game_v1::collisionsBlock(void) {
break;
case 21:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16() & 3;
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16() & 3;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
- (flags << 4) + cmdHigh + 2, key,
- _vm->_global->_inter_execPtr - _totFileData, 0);
+ (flags << 4) + cmdHigh + 2, key, _script->pos(), 0);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 20:
@@ -732,61 +734,48 @@ void Game_v1::collisionsBlock(void) {
// Fall through to case 2
case 2:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16() & 3;
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16() & 3;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1,
top + height - 1,
- (flags << 4) + cmdHigh + 2, key, 0,
- _vm->_global->_inter_execPtr - _totFileData);
+ (flags << 4) + cmdHigh + 2, key, 0, _script->pos());
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 0:
- _vm->_global->_inter_execPtr += 6;
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(6);
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
cmd + cmdHigh, key,
- startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData);
+ startPos, _script->pos());
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 1:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16() & 3;
-
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16() & 3;
+
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
if (key == 0)
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
(flags << 4) + cmd + cmdHigh, key,
- startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData);
+ startPos, _script->pos());
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
}
}
@@ -895,9 +884,11 @@ void Game_v1::collisionsBlock(void) {
if (collPtr->funcLeave != 0) {
timeKey = _vm->_util->getTimeKey();
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr =
- _totFileData + collPtr->funcLeave;
+
+ uint32 savedPos = _script->pos();
+
+ _script->seek(collPtr->funcLeave);
+
_shouldPushColls = 1;
savedCollStackSize = _collStackSize;
_vm->_inter->funcBlock(0);
@@ -906,7 +897,8 @@ void Game_v1::collisionsBlock(void) {
popCollisions();
_shouldPushColls = 0;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(savedPos);
deltaTime = timeVal -
(_vm->_util->getTimeKey() - timeKey);
@@ -986,9 +978,9 @@ void Game_v1::collisionsBlock(void) {
WRITE_VAR(16, array[(uint16) _activeCollResId & ~0x8000]);
if (_collisionAreas[_activeCollIndex].funcEnter != 0) {
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData +
- _collisionAreas[_activeCollIndex].funcEnter;
+ uint32 savedPos = _script->pos();
+
+ _script->seek(_collisionAreas[_activeCollIndex].funcEnter);
_shouldPushColls = 1;
@@ -997,7 +989,8 @@ void Game_v1::collisionsBlock(void) {
if (collStackPos != _collStackSize)
popCollisions();
_shouldPushColls = 0;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(savedPos);
}
WRITE_VAR(16, 0);
@@ -1071,10 +1064,8 @@ void Game_v1::collisionsBlock(void) {
WRITE_VAR(17, 1);
}
- savedIP = 0;
if (!_vm->_inter->_terminate) {
- savedIP = _totFileData +
- _collisionAreas[_activeCollIndex].funcLeave;
+ _script->seek(_collisionAreas[_activeCollIndex].funcLeave);
WRITE_VAR(2, _vm->_global->_inter_mouseX);
WRITE_VAR(3, _vm->_global->_inter_mouseY);
@@ -1082,12 +1073,11 @@ void Game_v1::collisionsBlock(void) {
if (VAR(16) == 0)
WRITE_VAR(16, array[(uint16) _activeCollResId & ~0x8000]);
- }
+ } else
+ _script->setFinished(true);
for (curCmd = 0; curCmd < count; curCmd++)
freeCollision(curCmd + 0x8000);
-
- _vm->_global->_inter_execPtr = savedIP;
}
int16 Game_v1::multiEdit(int16 time, int16 index, int16 *pCurPos,
diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp
index e9656efa32..4ed9a49e8c 100644
--- a/engines/gob/game_v2.cpp
+++ b/engines/gob/game_v2.cpp
@@ -32,11 +32,11 @@
#include "gob/global.h"
#include "gob/util.h"
#include "gob/dataio.h"
+#include "gob/script.h"
#include "gob/draw.h"
#include "gob/goblin.h"
#include "gob/inter.h"
#include "gob/mult.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/video.h"
#include "gob/videoplayer.h"
@@ -55,15 +55,14 @@ void Game_v2::playTot(int16 skipPlay) {
int16 _captureCounter;
int16 breakFrom;
int16 nestLevel;
- int32 totSize;
byte *filePtr;
- byte *savedIP;
bool totTextLoc;
oldNestLevel = _vm->_inter->_nestLevel;
oldBreakFrom = _vm->_inter->_breakFromLevel;
oldCaptureCounter = _vm->_scenery->_pCaptureCounter;
- savedIP = _vm->_global->_inter_execPtr;
+
+ uint32 startPos = _script->pos();
_vm->_inter->_nestLevel = &nestLevel;
_vm->_inter->_breakFromLevel = &breakFrom;
@@ -103,17 +102,15 @@ void Game_v2::playTot(int16 skipPlay) {
_vm->_draw->_cursorHotspotXVar = -1;
_totToLoad[0] = 0;
- if ((_curTotFile[0] == 0) && (_totFileData == 0))
+ if ((_curTotFile[0] == 0) && (!_script->isLoaded()))
break;
- totSize = loadTotFile(_curTotFile);
-
if (skipPlay == -2) {
_vm->_vidPlayer->primaryClose();
skipPlay = 0;
}
- if (_totFileData == 0) {
+ if (!_script->load(_curTotFile)) {
_vm->_draw->blitCursor();
_vm->_inter->_terminate = 2;
break;
@@ -131,7 +128,7 @@ void Game_v2::playTot(int16 skipPlay) {
debugC(4, kDebugFileIO, "IMA: %s", _curImaFile);
debugC(4, kDebugFileIO, "EXT: %s", _curExtFile);
- filePtr = _totFileData + 0x30;
+ filePtr = _script->getData() + 0x30;
_totTextData = 0;
totTextLoc = false;
@@ -145,8 +142,8 @@ void Game_v2::playTot(int16 skipPlay) {
totTextLoc = true;
} else {
_totTextData->dataPtr =
- (_totFileData + READ_LE_UINT32(_totFileData + 0x30));
- size = totSize;
+ (_script->getData() + READ_LE_UINT32(_script->getData() + 0x30));
+ size = _script->getSize();
_vm->_global->_language = _vm->_global->_languageWanted;
}
@@ -164,19 +161,19 @@ void Game_v2::playTot(int16 skipPlay) {
}
}
- filePtr = _totFileData + 0x34;
+ filePtr = _script->getData() + 0x34;
_totResourceTable = 0;
int32 resSize;
if (READ_LE_UINT32(filePtr) != (uint32) -1) {
_totResourceTable = new TotResTable;
_totResourceTable->dataPtr =
- _totFileData + READ_LE_UINT32(_totFileData + 0x34);
+ _script->getData() + READ_LE_UINT32(_script->getData() + 0x34);
Common::MemoryReadStream totResTable(_totResourceTable->dataPtr,
4294967295U);
_totResourceTable->itemsCount = totResTable.readSint16LE();
resSize = _totResourceTable->itemsCount * szGame_TotResItem + szGame_TotResTable;
- if (totSize > (resSize + 0x34)) {
+ if (_script->getSize() > (resSize + 0x34)) {
_totResourceTable->unknown = totResTable.readByte();
_totResourceTable->items =
@@ -196,7 +193,7 @@ void Game_v2::playTot(int16 skipPlay) {
// pointer with the real one.
debugC(1, kDebugFileIO,
"Attempted to load invalid resource table (size = %d, totSize = %d)",
- resSize, totSize);
+ resSize, _script->getSize());
delete _totResourceTable;
_totResourceTable = 0;
}
@@ -206,13 +203,11 @@ void Game_v2::playTot(int16 skipPlay) {
loadExtTable();
_vm->_global->_inter_animDataSize =
- READ_LE_UINT16(_totFileData + 0x38);
+ READ_LE_UINT16(_script->getData() + 0x38);
if (!_vm->_inter->_variables)
- _vm->_inter->allocateVars(READ_LE_UINT16(_totFileData + 0x2C));
+ _vm->_inter->allocateVars(READ_LE_UINT16(_script->getData() + 0x2C));
- _vm->_global->_inter_execPtr = _totFileData;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_totFileData + 0x64);
+ _script->seek(READ_LE_UINT16(_script->getData() + 0x64));
_vm->_inter->renewTimeInVars();
@@ -227,8 +222,8 @@ void Game_v2::playTot(int16 skipPlay) {
_vm->_inter->_terminate = 0;
_vm->_draw->blitInvalidated();
- delete[] _totFileData;
- _totFileData = 0;
+
+ _script->unload();
if (_totTextData) {
delete[] _totTextData->items;
@@ -282,9 +277,7 @@ void Game_v2::playTot(int16 skipPlay) {
} else {
_vm->_inter->initControlVars(0);
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
- _vm->_global->_inter_execPtr = _totFileData;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_totFileData + (skipPlay << 1) + 0x66);
+ _script->seek(READ_LE_UINT16(_script->getData() + (skipPlay << 1) + 0x66));
_menuLevel++;
_vm->_inter->callSub(2);
@@ -299,7 +292,8 @@ void Game_v2::playTot(int16 skipPlay) {
_vm->_inter->_nestLevel = oldNestLevel;
_vm->_inter->_breakFromLevel = oldBreakFrom;
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(startPos);
}
void Game_v2::clearCollisions() {
@@ -338,6 +332,7 @@ int16 Game_v2::addNewCollision(int16 id, uint16 left, uint16 top,
ptr->funcLeave = funcLeave;
ptr->funcSub = funcSub;
ptr->totFileData = 0;
+ ptr->totSize = 0;
return i;
}
@@ -604,7 +599,6 @@ void Game_v2::collisionsBlock(void) {
int16 array[250];
byte count;
int16 collResId;
- byte *startIP;
int16 curCmd;
int16 cmd;
int16 cmdHigh;
@@ -621,7 +615,6 @@ void Game_v2::collisionsBlock(void) {
int16 stackPos2;
int16 descIndex;
int16 timeVal;
- int16 offsetIP;
char *str;
int16 i;
int16 counter;
@@ -631,8 +624,9 @@ void Game_v2::collisionsBlock(void) {
Collision *collPtr;
Collision *collArea;
int16 timeKey;
- byte *savedIP;
byte collAreaStart;
+ uint32 startPos;
+ uint32 offsetPos;
if (_shouldPushColls)
pushCollisions(0);
@@ -645,21 +639,22 @@ void Game_v2::collisionsBlock(void) {
_shouldPushColls = 0;
collResId = -1;
- _vm->_global->_inter_execPtr++;
- count = *_vm->_global->_inter_execPtr++;
+ _script->skip(1);
+ count = _script->readByte();
- _handleMouse = _vm->_global->_inter_execPtr[0];
- deltaTime = 1000 * _vm->_global->_inter_execPtr[1];
- stackPos2 = _vm->_global->_inter_execPtr[3];
- descIndex = _vm->_global->_inter_execPtr[4];
+ _handleMouse = _script->readByte();
+ deltaTime = 1000 * _script->readByte();
+ _script->skip(1);
+ stackPos2 = _script->readByte();
+ descIndex = _script->readByte();
if ((stackPos2 != 0) || (descIndex != 0))
deltaTime /= 100;
timeVal = deltaTime;
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(1);
- startIP = _vm->_global->_inter_execPtr;
+ startPos = _script->pos();
WRITE_VAR(16, 0);
var_1C = 0;
@@ -668,28 +663,27 @@ void Game_v2::collisionsBlock(void) {
for (curCmd = 0; curCmd < count; curCmd++) {
array[curCmd] = 0;
- cmd = *_vm->_global->_inter_execPtr++;
+ cmd = _script->readByte();
if ((cmd & 0x40) != 0) {
cmd -= 0x40;
- cmdHigh = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr++;
+ cmdHigh = _script->readByte();
cmdHigh <<= 8;
} else
cmdHigh = 0;
if ((cmd & 0x80) != 0) {
- offsetIP = _vm->_global->_inter_execPtr - _totFileData;
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ offsetPos = _script->pos();
+ left = _script->readValExpr();
+ top = _script->readValExpr();
+ width = _script->readValExpr();
+ height = _script->readValExpr();
} else {
- offsetIP = 0;
- left = _vm->_inter->load16();
- top = _vm->_inter->load16();
- width = _vm->_inter->load16();
- height = _vm->_inter->load16();
+ offsetPos = 0;
+ left = _script->readUint16();
+ top = _script->readUint16();
+ width = _script->readUint16();
+ height = _script->readUint16();
}
if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != 0xFFFF)) {
@@ -712,46 +706,37 @@ void Game_v2::collisionsBlock(void) {
switch (cmd) {
case 0:
- _vm->_global->_inter_execPtr += 6;
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(6);
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
- cmd + cmdHigh, key, startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
+ cmd + cmdHigh, key, startPos,
+ _script->pos(), offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 1:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16();
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16();
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
if (key == 0)
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
- (flags << 4) + cmd + cmdHigh, key, startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
-
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ (flags << 4) + cmd + cmdHigh, key, startPos,
+ _script->pos(), offsetPos);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 3:
@@ -764,23 +749,20 @@ void Game_v2::collisionsBlock(void) {
case 10:
_vm->_util->clearKeyBuf();
var_1C = 1;
- key = _vm->_parse->parseVarIndex();
- descArray[index].fontIndex = _vm->_inter->load16();
- descArray[index].backColor = *_vm->_global->_inter_execPtr++;
- descArray[index].frontColor = *_vm->_global->_inter_execPtr++;
+ key = _script->readVarIndex();
+ descArray[index].fontIndex = _script->readInt16();
+ descArray[index].backColor = _script->readByte();
+ descArray[index].frontColor = _script->readByte();
if ((cmd >= 5) && (cmd <= 8)) {
- descArray[index].ptr = _vm->_global->_inter_execPtr + 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr) + 2;
+ descArray[index].ptr = _script->getData() + _script->pos() + 2;
+ _script->skip(_script->peekUint16() + 2);
} else
descArray[index].ptr = 0;
if (left == 0xFFFF) {
if ((cmd & 1) == 0) {
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
}
break;
}
@@ -789,11 +771,9 @@ void Game_v2::collisionsBlock(void) {
addNewCollision(curCmd + 0x8000, left, top, left + width *
_vm->_draw->_fonts[descArray[index].fontIndex]-> itemWidth - 1,
top + height - 1, cmd, key, 0,
- _vm->_global->_inter_execPtr - _totFileData);
+ _script->pos());
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
} else
addNewCollision(curCmd + 0x8000, left, top, left + width *
_vm->_draw->_fonts[descArray[index].fontIndex]-> itemWidth - 1,
@@ -803,35 +783,31 @@ void Game_v2::collisionsBlock(void) {
break;
case 11:
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(6);
for (i = 0; i < 150; i++) {
if ((_collisionAreas[i].id & 0xF000) == 0xE000) {
_collisionAreas[i].id &= 0xBFFF;
_collisionAreas[i].funcEnter =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
_collisionAreas[i].funcLeave =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
}
}
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 12:
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(6);
for (i = 0; i < 150; i++) {
if ((_collisionAreas[i].id & 0xF000) == 0xD000) {
_collisionAreas[i].id &= 0xBFFF;
_collisionAreas[i].funcEnter =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
_collisionAreas[i].funcLeave =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
}
}
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 20:
@@ -839,34 +815,30 @@ void Game_v2::collisionsBlock(void) {
// Fall through to case 2
case 2:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16();
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16();
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
(flags << 4) + cmdHigh + 2, key, 0,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
+ _script->pos(), offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 21:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16() & 3;
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16() & 3;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
(flags << 4) + cmdHigh + 2, key,
- _vm->_global->_inter_execPtr - _totFileData, 0, offsetIP);
+ _script->pos(), 0, offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
}
@@ -1116,10 +1088,8 @@ void Game_v2::collisionsBlock(void) {
if (_handleMouse == 1)
_vm->_draw->blitCursor();
- savedIP = 0;
if (!_vm->_inter->_terminate) {
- savedIP = _totFileData +
- _collisionAreas[_activeCollIndex].funcLeave;
+ _script->seek(_collisionAreas[_activeCollIndex].funcLeave);
_vm->_inter->storeMouse();
if (VAR(16) == 0) {
@@ -1128,7 +1098,8 @@ void Game_v2::collisionsBlock(void) {
else
WRITE_VAR(16, _activeCollResId & 0xFFF);
}
- }
+ } else
+ _script->setFinished(true);
for (curCmd = 0; curCmd < count; curCmd++)
freeCollision(curCmd + 0x8000);
@@ -1138,8 +1109,6 @@ void Game_v2::collisionsBlock(void) {
((_collisionAreas[i].id & 0xF000) == 0x9000))
_collisionAreas[i].id |= 0x4000;
}
-
- _vm->_global->_inter_execPtr = savedIP;
}
int16 Game_v2::multiEdit(int16 time, int16 index, int16 *pCurPos,
diff --git a/engines/gob/game_v6.cpp b/engines/gob/game_v6.cpp
index 9d9bd1faa3..7396901943 100644
--- a/engines/gob/game_v6.cpp
+++ b/engines/gob/game_v6.cpp
@@ -31,9 +31,9 @@
#include "gob/game.h"
#include "gob/helper.h"
#include "gob/global.h"
+#include "gob/script.h"
#include "gob/inter.h"
#include "gob/draw.h"
-#include "gob/parse.h"
namespace Gob {
@@ -54,7 +54,7 @@ void Game_v6::totSub(int8 flags, const char *newTotFile) {
_cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar;
_cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar;
_totTextDataArray[_backupedCount] = _totTextData;
- _totFileDataArray[_backupedCount] = _totFileData;
+ _scriptArray[_backupedCount] = _script;
_totResourceTableArray[_backupedCount] = _totResourceTable;
_extTableArray[_backupedCount] = _extTable;
_extHandleArray[_backupedCount] = _extHandle;
@@ -66,8 +66,8 @@ void Game_v6::totSub(int8 flags, const char *newTotFile) {
_backupedCount++;
_curBackupPos = _backupedCount;
+ _script = new Script(_vm);
_totTextData = 0;
- _totFileData = 0;
_totResourceTable = 0;
if (flags & 0x80)
@@ -105,7 +105,7 @@ void Game_v6::totSub(int8 flags, const char *newTotFile) {
_vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_backupedCount];
_vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_backupedCount];
_totTextData = _totTextDataArray[_backupedCount];
- _totFileData = _totFileDataArray[_backupedCount];
+ _script = _scriptArray[_backupedCount];
_totResourceTable = _totResourceTableArray[_backupedCount];
_extTable = _extTableArray[_backupedCount];
_extHandle = _extHandleArray[_backupedCount];
@@ -148,7 +148,8 @@ int16 Game_v6::addNewCollision(int16 id, uint16 left, uint16 top,
ptr->funcEnter = funcEnter;
ptr->funcLeave = funcLeave;
ptr->funcSub = funcSub;
- ptr->totFileData = _totFileData;
+ ptr->totFileData = _script->getData();
+ ptr->totSize = _script->getSize();
return i;
}
@@ -383,7 +384,6 @@ void Game_v6::collisionsBlock(void) {
int16 array[300];
byte count;
int16 collResId;
- byte *startIP;
int16 curCmd;
int16 cmd;
int16 cmdHigh;
@@ -397,7 +397,6 @@ void Game_v6::collisionsBlock(void) {
int16 stackPos2;
int16 descIndex;
int16 timeVal;
- int16 offsetIP;
char *str;
int16 i;
int16 counter;
@@ -406,10 +405,11 @@ void Game_v6::collisionsBlock(void) {
int16 collStackPos;
Collision *collPtr;
Collision *collArea;
- byte *savedIP;
byte collAreaStart;
int16 activeCollResId = 0;
int16 activeCollIndex = 0;
+ uint32 startPos;
+ uint32 offsetPos;
if (_shouldPushColls)
pushCollisions(0);
@@ -422,25 +422,25 @@ void Game_v6::collisionsBlock(void) {
_shouldPushColls = 0;
collResId = -1;
- _vm->_global->_inter_execPtr++;
- count = *_vm->_global->_inter_execPtr++;
+ _script->skip(1);
+ count = _script->readByte();
- _handleMouse = _vm->_global->_inter_execPtr[0];
- deltaTime = 1000 * _vm->_global->_inter_execPtr[1];
- stackPos2 = _vm->_global->_inter_execPtr[3];
- descIndex = _vm->_global->_inter_execPtr[4];
- byte var_42 = _vm->_global->_inter_execPtr[5];
+ _handleMouse = _script->peekByte(0);
+ deltaTime = 1000 * _script->peekByte(1);
+ stackPos2 = _script->peekByte(3);
+ descIndex = _script->peekByte(4);
+ byte var_42 = _script->peekByte(5);
if ((stackPos2 != 0) || (descIndex != 0)) {
deltaTime /= 100;
- if (_vm->_global->_inter_execPtr[1] == 100)
+ if (_script->peekByte(1) == 100)
deltaTime = 2;
}
timeVal = deltaTime;
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(6);
- startIP = _vm->_global->_inter_execPtr;
+ startPos = _script->pos();
WRITE_VAR(16, 0);
byte var_41 = 0;
@@ -452,28 +452,27 @@ void Game_v6::collisionsBlock(void) {
for (curCmd = 0; curCmd < count; curCmd++) {
array[curCmd] = 0;
- cmd = *_vm->_global->_inter_execPtr++;
+ cmd = _script->readByte();
if ((cmd & 0x40) != 0) {
cmd -= 0x40;
- cmdHigh = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr++;
+ cmdHigh = _script->readByte();
cmdHigh <<= 8;
} else
cmdHigh = 0;
if ((cmd & 0x80) != 0) {
- offsetIP = _vm->_global->_inter_execPtr - _totFileData;
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ offsetPos = _script->pos();
+ left = _script->readValExpr();
+ top = _script->readValExpr();
+ width = _script->readValExpr();
+ height = _script->readValExpr();
} else {
- offsetIP = 0;
- left = _vm->_inter->load16();
- top = _vm->_inter->load16();
- width = _vm->_inter->load16();
- height = _vm->_inter->load16();
+ offsetPos = 0;
+ left = _script->readUint16();
+ top = _script->readUint16();
+ width = _script->readUint16();
+ height = _script->readUint16();
}
if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != 0xFFFF)) {
@@ -496,45 +495,37 @@ void Game_v6::collisionsBlock(void) {
switch (cmd) {
case 0:
- _vm->_global->_inter_execPtr += 6;
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(6);
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
- cmd + cmdHigh, key, startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
+ cmd + cmdHigh, key, startPos,
+ _script->pos(), offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 1:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16();
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16();
- startIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ startPos = _script->pos();
+ _script->skip(_script->peekUint16(2) + 2);
if (key == 0)
key = curCmd + 0xA000;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
- (flags << 4) + cmd + cmdHigh, key, startIP - _totFileData,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
+ (flags << 4) + cmd + cmdHigh, key, startPos,
+ _script->pos(), offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
@@ -548,23 +539,20 @@ void Game_v6::collisionsBlock(void) {
case 10:
_vm->_util->clearKeyBuf();
var_1C = 1;
- key = _vm->_parse->parseVarIndex();
- descArray[index].fontIndex = _vm->_inter->load16();
- descArray[index].backColor = *_vm->_global->_inter_execPtr++;
- descArray[index].frontColor = *_vm->_global->_inter_execPtr++;
+ key = _script->readVarIndex();
+ descArray[index].fontIndex = _script->readInt16();
+ descArray[index].backColor = _script->readByte();
+ descArray[index].frontColor = _script->readByte();
if ((cmd >= 5) && (cmd <= 8)) {
- descArray[index].ptr = _vm->_global->_inter_execPtr + 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr) + 2;
+ descArray[index].ptr = _script->getData() + _script->pos() + 2;
+ _script->skip(_script->peekUint16() + 2);
} else
descArray[index].ptr = 0;
if (left == 0xFFFF) {
if ((cmd & 1) == 0) {
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
}
break;
}
@@ -575,50 +563,44 @@ void Game_v6::collisionsBlock(void) {
funcLeave = 0;
if (!(cmd & 1))
- funcLeave = _vm->_global->_inter_execPtr - _totFileData;
+ funcLeave = _script->pos();
addNewCollision(curCmd + 0x8000, left, top, right,
top + height - 1, cmd, key, 0, funcLeave, 0);
if (!(cmd & 1)) {
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
}
index++;
break;
case 11:
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(6);
for (i = 0; i < 150; i++) {
if ((_collisionAreas[i].id & 0xF000) == 0xE000) {
_collisionAreas[i].id &= 0xBFFF;
_collisionAreas[i].funcEnter =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
_collisionAreas[i].funcLeave =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
}
}
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 12:
- _vm->_global->_inter_execPtr += 6;
+ _script->skip(6);
for (i = 0; i < 150; i++) {
if ((_collisionAreas[i].id & 0xF000) == 0xD000) {
_collisionAreas[i].id &= 0xBFFF;
_collisionAreas[i].funcEnter =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
_collisionAreas[i].funcLeave =
- _vm->_global->_inter_execPtr - _totFileData;
+ _script->pos();
}
}
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 20:
@@ -626,34 +608,30 @@ void Game_v6::collisionsBlock(void) {
// Fall through to case 2
case 2:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16();
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16();
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
(flags << 4) + cmdHigh + 2, key, 0,
- _vm->_global->_inter_execPtr - _totFileData, offsetIP);
+ _script->pos(), offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
case 21:
- key = _vm->_inter->load16();
- array[curCmd] = _vm->_inter->load16();
- flags = _vm->_inter->load16() & 3;
+ key = _script->readInt16();
+ array[curCmd] = _script->readInt16();
+ flags = _script->readInt16() & 3;
addNewCollision(curCmd + 0x8000, left, top,
left + width - 1, top + height - 1,
(flags << 4) + cmdHigh + 2, key,
- _vm->_global->_inter_execPtr - _totFileData, 0, offsetIP);
+ _script->pos(), 0, offsetPos);
- _vm->_global->_inter_execPtr += 2;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _script->skip(_script->peekUint16(2) + 2);
break;
}
@@ -915,10 +893,8 @@ void Game_v6::collisionsBlock(void) {
if (_handleMouse == 1)
_vm->_draw->blitCursor();
- savedIP = 0;
if (!_vm->_inter->_terminate && (var_41 == 0)) {
- savedIP = _totFileData +
- _collisionAreas[activeCollIndex].funcLeave;
+ _script->seek(_collisionAreas[activeCollIndex].funcLeave);
_vm->_inter->storeMouse();
if (VAR(16) == 0) {
@@ -927,7 +903,8 @@ void Game_v6::collisionsBlock(void) {
else
WRITE_VAR(16, activeCollResId & 0xFFF);
}
- }
+ } else
+ _script->setFinished(true);
for (curCmd = 0; curCmd < count; curCmd++)
freeCollision(curCmd + 0x8000);
@@ -937,8 +914,6 @@ void Game_v6::collisionsBlock(void) {
((_collisionAreas[i].id & 0xF000) == 0x9000))
_collisionAreas[i].id |= 0x4000;
}
-
- _vm->_global->_inter_execPtr = savedIP;
}
void Game_v6::setCollisions(byte arg_0) {
@@ -951,22 +926,28 @@ void Game_v6::setCollisions(byte arg_0) {
continue;
byte *totFileData = collArea->totFileData;
+ uint32 totSize = collArea->totSize;
- if (!totFileData)
- totFileData = _totFileData;
+ if (!totFileData || (totSize == 0)) {
+ totFileData = _script->getData();
+ totSize = _script->getSize();
+ }
- byte *savedIP = _vm->_global->_inter_execPtr;
+ uint32 savedPos = _script->pos();
+ byte *savedData = _script->getData();
+ uint32 savedSize = _script->getSize();
- _vm->_global->_inter_execPtr = totFileData + collArea->funcSub;
+ _script->cuckoo(totFileData, totSize);
+ _script->seek(collArea->funcSub);
- int16 left = _vm->_parse->parseValExpr();
- int16 top = _vm->_parse->parseValExpr();
- int16 width = _vm->_parse->parseValExpr();
- int16 height = _vm->_parse->parseValExpr();
+ int16 left = _script->readValExpr();
+ int16 top = _script->readValExpr();
+ int16 width = _script->readValExpr();
+ int16 height = _script->readValExpr();
uint16 flags = 0;
if ((collArea->id & 0xF000) == 0xA000)
- flags = _vm->_parse->parseValExpr();
+ flags = _script->readValExpr();
if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) &&
(left != -1)) {
@@ -1001,16 +982,17 @@ void Game_v6::setCollisions(byte arg_0) {
if ((collArea->id & 0xF000) == 0xA000)
collArea->flags = flags;
- _vm->_global->_inter_execPtr = savedIP;
+ _script->cuckoo(savedData, savedSize);
+ _script->seek(savedPos);
}
}
void Game_v6::collSub(uint16 offset) {
- byte *savedIP;
int16 collStackSize;
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _totFileData + offset;
+ uint32 savedPos = _script->pos();
+
+ _script->seek(offset);
_shouldPushColls = 1;
collStackSize = _collStackSize;
@@ -1021,7 +1003,8 @@ void Game_v6::collSub(uint16 offset) {
popCollisions();
_shouldPushColls = 0;
- _vm->_global->_inter_execPtr = savedIP;
+
+ _script->seek(savedPos);
if ((_vm->_util->getTimeKey() - _someTimeDly) > 500)
setCollisions(0);
diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp
index 9d17e6b054..4ac3ef5fc5 100644
--- a/engines/gob/init.cpp
+++ b/engines/gob/init.cpp
@@ -99,7 +99,6 @@ void Init::initGame() {
_vm->_global->_mouseYShift = 1;
_vm->_game->_totTextData = 0;
- _vm->_game->_totFileData = 0;
_palDesc = new Video::PalDesc;
_vm->validateVideoMode(_vm->_global->_videoMode);
diff --git a/engines/gob/inter.cpp b/engines/gob/inter.cpp
index 61bf99e727..5a65cb5366 100644
--- a/engines/gob/inter.cpp
+++ b/engines/gob/inter.cpp
@@ -33,9 +33,10 @@
#include "gob/util.h"
#include "gob/draw.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
#include "gob/scenery.h"
#include "gob/sound/sound.h"
+#include "gob/parse.h"
namespace Gob {
@@ -114,7 +115,7 @@ void Inter::executeOpcodeGob(int i, OpGobParams &params) {
return;
}
- _vm->_global->_inter_execPtr += params.paramCount << 1;
+ _vm->_game->_script->skip(params.paramCount << 1);
warning("unimplemented opcodeGob: %d [0x%X]", i, i);
}
@@ -156,24 +157,18 @@ void Inter::initControlVars(char full) {
}
}
-int16 Inter::load16() {
- int16 tmp = (int16) READ_LE_UINT16(_vm->_global->_inter_execPtr);
- _vm->_global->_inter_execPtr += 2;
- return tmp;
-}
-
char Inter::evalExpr(int16 *pRes) {
byte type;
_vm->_parse->printExpr(99);
- _vm->_parse->parseExpr(99, &type);
+ _vm->_game->_script->readExpr(99, &type);
if (!pRes)
return type;
switch (type) {
case TYPE_IMM_INT16:
- *pRes = _vm->_parse->getResultInt();
+ *pRes = _vm->_game->_script->getResultInt();
break;
case TYPE_IMM_STR:
@@ -194,9 +189,9 @@ bool Inter::evalBoolResult() {
_vm->_parse->printExpr(99);
- _vm->_parse->parseExpr(99, &type);
+ _vm->_game->_script->readExpr(99, &type);
if ( (type == GOB_TRUE) ||
- ((type == TYPE_IMM_INT16) && _vm->_parse->getResultInt()))
+ ((type == TYPE_IMM_INT16) && _vm->_game->_script->getResultInt()))
return true;
else
return false;
@@ -283,20 +278,20 @@ void Inter::funcBlock(int16 retFlag) {
params.retFlag = retFlag;
- if (!_vm->_global->_inter_execPtr)
+ if (_vm->_game->_script->isFinished())
return;
_break = false;
- _vm->_global->_inter_execPtr++;
- params.cmdCount = *_vm->_global->_inter_execPtr++;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(1);
+ params.cmdCount = _vm->_game->_script->readByte();
+ _vm->_game->_script->skip(2);
if (params.cmdCount == 0) {
- _vm->_global->_inter_execPtr = 0;
+ _vm->_game->_script->setFinished(true);
return;
}
- int startaddr = _vm->_global->_inter_execPtr - _vm->_game->_totFileData;
+ int startaddr = _vm->_game->_script->pos();
params.counter = 0;
do {
@@ -311,7 +306,7 @@ void Inter::funcBlock(int16 retFlag) {
(_vm->getPlatform() == Common::kPlatformMacintosh) ||
(_vm->getPlatform() == Common::kPlatformWindows))) {
- int addr = _vm->_global->_inter_execPtr-_vm->_game->_totFileData;
+ int addr = _vm->_game->_script->pos();
if ((startaddr == 0x18B4 && addr == 0x1A7F && // Zombie, EGA
!strncmp(_vm->_game->_curTotFile, "avt005.tot", 10)) ||
@@ -337,14 +332,13 @@ void Inter::funcBlock(int16 retFlag) {
} // End of workaround
- cmd = *_vm->_global->_inter_execPtr;
+ cmd = _vm->_game->_script->readByte();
if ((cmd >> 4) >= 12) {
cmd2 = 16 - (cmd >> 4);
cmd &= 0xF;
} else
cmd2 = 0;
- _vm->_global->_inter_execPtr++;
params.counter++;
if (cmd2 == 0)
@@ -366,17 +360,17 @@ void Inter::funcBlock(int16 retFlag) {
}
} while (params.counter != params.cmdCount);
- _vm->_global->_inter_execPtr = 0;
+ _vm->_game->_script->setFinished(true);
return;
}
void Inter::callSub(int16 retFlag) {
byte block;
- while (!_vm->shouldQuit() && _vm->_global->_inter_execPtr &&
- (_vm->_global->_inter_execPtr != _vm->_game->_totFileData)) {
+ while (!_vm->shouldQuit() && !_vm->_game->_script->isFinished() &&
+ (_vm->_game->_script->pos() != 0)) {
- block = *_vm->_global->_inter_execPtr;
+ block = _vm->_game->_script->peekByte();
if (block == 1)
funcBlock(retFlag);
else if (block == 2)
@@ -385,7 +379,7 @@ void Inter::callSub(int16 retFlag) {
error("Unknown block type %d in Inter::callSub()", block);
}
- if (_vm->_global->_inter_execPtr == _vm->_game->_totFileData)
+ if (!_vm->_game->_script->isFinished() && (_vm->_game->_script->pos() == 0))
_terminate = 1;
}
diff --git a/engines/gob/inter.h b/engines/gob/inter.h
index 852a99f9db..a7c17ecafc 100644
--- a/engines/gob/inter.h
+++ b/engines/gob/inter.h
@@ -100,7 +100,6 @@ public:
void setupOpcodes();
void initControlVars(char full);
- int16 load16();
char evalExpr(int16 *pRes);
bool evalBoolResult();
void renewTimeInVars();
@@ -152,7 +151,7 @@ protected:
virtual void setupOpcodesFunc() = 0;
virtual void setupOpcodesGob() = 0;
- virtual void checkSwitchTable(byte **ppExec) = 0;
+ virtual void checkSwitchTable(uint32 &offset) = 0;
void o_drawNOP() {}
bool o_funcNOP(OpFuncParams &params) { return false; }
@@ -172,7 +171,7 @@ protected:
virtual void setupOpcodesFunc();
virtual void setupOpcodesGob();
- virtual void checkSwitchTable(byte **ppExec);
+ virtual void checkSwitchTable(uint32 &offset);
void o1_loadMult();
void o1_playMult();
@@ -343,7 +342,7 @@ protected:
virtual void setupOpcodesFunc();
virtual void setupOpcodesGob();
- virtual void checkSwitchTable(byte **ppExec);
+ virtual void checkSwitchTable(uint32 &offset);
void o2_playMult();
void o2_freeMultKeys();
diff --git a/engines/gob/inter_fascin.cpp b/engines/gob/inter_fascin.cpp
index 1e47f2408e..73274eb819 100644
--- a/engines/gob/inter_fascin.cpp
+++ b/engines/gob/inter_fascin.cpp
@@ -31,8 +31,8 @@
#include "gob/util.h"
#include "gob/dataio.h"
#include "gob/draw.h"
-#include "gob/parse.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/palanim.h"
#include "gob/video.h"
#include "gob/videoplayer.h"
@@ -205,15 +205,15 @@ void Inter_Fascination::oFascin_cdUnknown3() {
warning("Fascination oFascin_cdUnknown3 - Variables initialisations");
- resVar = (uint16) load16();
- resVar2 = (uint16) load16();
- retVal1 = _vm->_parse->parseVarIndex();
- retVal2 = _vm->_parse->parseVarIndex();
- retVal3 = _vm->_parse->parseVarIndex();
- retVal4 = _vm->_parse->parseVarIndex();
- retVal5 = _vm->_parse->parseVarIndex();
- retVal6 = _vm->_parse->parseVarIndex();
- retVal7 = _vm->_parse->parseVarIndex();
+ resVar = _vm->_game->_script->readUint16();
+ resVar2 = _vm->_game->_script->readUint16();
+ retVal1 = _vm->_game->_script->readVarIndex();
+ retVal2 = _vm->_game->_script->readVarIndex();
+ retVal3 = _vm->_game->_script->readVarIndex();
+ retVal4 = _vm->_game->_script->readVarIndex();
+ retVal5 = _vm->_game->_script->readVarIndex();
+ retVal6 = _vm->_game->_script->readVarIndex();
+ retVal7 = _vm->_game->_script->readVarIndex();
warning ("Width? :%d Height? :%d",resVar, resVar2);
warning ("Fetched variables 1:%d 2:%d 3:%d 4:%d 5:%d 6:%d 7:%d", retVal1, retVal2, retVal3, retVal4, retVal5, retVal6, retVal7);
}
@@ -229,7 +229,7 @@ void Inter_Fascination::oFascin_cdUnknown5() {
int16 retVal1,expr;
warning("Fascination oFascin_cdUnknown5");
evalExpr(&expr);
- retVal1 = _vm->_parse->parseVarIndex();
+ retVal1 = _vm->_game->_script->readVarIndex();
warning ("evalExpr: %d Variable index %d, the rest is not yet implemented",expr, retVal1);
}
@@ -237,7 +237,7 @@ void Inter_Fascination::oFascin_cdUnknown6() {
int16 retVal1,expr;
warning("Fascination oFascin_cdUnknown6");
evalExpr(&expr);
- retVal1 = _vm->_parse->parseVarIndex();
+ retVal1 = _vm->_game->_script->readVarIndex();
warning ("evalExpr: %d Variable index %d, the rest is not yet implemented",expr, retVal1);
}
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index 9368965585..bf24e8ef28 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -34,12 +34,13 @@
#include "gob/dataio.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
+#include "gob/parse.h"
#include "gob/goblin.h"
#include "gob/inter.h"
#include "gob/map.h"
#include "gob/mult.h"
#include "gob/palanim.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/video.h"
#include "gob/sound/sound.h"
@@ -239,7 +240,7 @@ void Inter_v1::setupOpcodesGob() {
OPCODEGOB(2005, o1_initGoblin);
}
-void Inter_v1::checkSwitchTable(byte **ppExec) {
+void Inter_v1::checkSwitchTable(uint32 &offset) {
int16 len;
int32 value;
bool found;
@@ -247,10 +248,10 @@ void Inter_v1::checkSwitchTable(byte **ppExec) {
found = false;
notFound = true;
- *ppExec = 0;
- value = VAR_OFFSET(_vm->_parse->parseVarIndex());
+ offset = 0;
+ value = VAR_OFFSET(_vm->_game->_script->readVarIndex());
- len = (int8) *_vm->_global->_inter_execPtr++;
+ len = _vm->_game->_script->readInt8();
while (len != -5) {
for (int i = 0; i < len; i++) {
evalExpr(0);
@@ -258,45 +259,43 @@ void Inter_v1::checkSwitchTable(byte **ppExec) {
if (_terminate)
return;
- if (_vm->_parse->getResultInt() == value) {
+ if (_vm->_game->_script->getResultInt() == value) {
found = true;
notFound = false;
}
}
if (found)
- *ppExec = _vm->_global->_inter_execPtr;
+ offset = _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
found = false;
- len = (int8) *_vm->_global->_inter_execPtr++;
+ len = _vm->_game->_script->readInt8();
}
- if ((*_vm->_global->_inter_execPtr >> 4) != 4)
+ if ((_vm->_game->_script->peekByte() >> 4) != 4)
return;
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
if (notFound)
- *ppExec = _vm->_global->_inter_execPtr;
+ offset = _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
}
void Inter_v1::o1_loadMult() {
- _vm->_mult->loadMult(load16());
+ _vm->_mult->loadMult(_vm->_game->_script->readInt16());
}
void Inter_v1::o1_playMult() {
int16 checkEscape;
- checkEscape = load16();
+ checkEscape = _vm->_game->_script->readInt16();
_vm->_mult->playMult(VAR(57), -1, checkEscape, 0);
}
void Inter_v1::o1_freeMultKeys() {
- load16();
+ _vm->_game->_script->readInt16();
_vm->_mult->freeMultKeys();
}
@@ -305,20 +304,20 @@ void Inter_v1::o1_initCursor() {
int16 height;
int16 count;
- _vm->_draw->_cursorHotspotXVar = _vm->_parse->parseVarIndex() / 4;
- _vm->_draw->_cursorHotspotYVar = _vm->_parse->parseVarIndex() / 4;
+ _vm->_draw->_cursorHotspotXVar = _vm->_game->_script->readVarIndex() / 4;
+ _vm->_draw->_cursorHotspotYVar = _vm->_game->_script->readVarIndex() / 4;
- width = load16();
+ width = _vm->_game->_script->readInt16();
if (width < 16)
width = 16;
- height = load16();
+ height = _vm->_game->_script->readInt16();
if (height < 16)
height = 16;
_vm->_draw->adjustCoords(0, &width, &height);
- count = load16();
+ count = _vm->_game->_script->readInt16();
if (count < 2)
count = 2;
@@ -366,24 +365,24 @@ void Inter_v1::o1_initCursorAnim() {
int16 ind;
_vm->_draw->_showCursor = 3;
- ind = _vm->_parse->parseValExpr();
- _vm->_draw->_cursorAnimLow[ind] = load16();
- _vm->_draw->_cursorAnimHigh[ind] = load16();
- _vm->_draw->_cursorAnimDelays[ind] = load16();
+ ind = _vm->_game->_script->readValExpr();
+ _vm->_draw->_cursorAnimLow[ind] = _vm->_game->_script->readInt16();
+ _vm->_draw->_cursorAnimHigh[ind] = _vm->_game->_script->readInt16();
+ _vm->_draw->_cursorAnimDelays[ind] = _vm->_game->_script->readInt16();
}
void Inter_v1::o1_clearCursorAnim() {
int16 ind;
_vm->_draw->_showCursor = 0;
- ind = _vm->_parse->parseValExpr();
+ ind = _vm->_game->_script->readValExpr();
_vm->_draw->_cursorAnimLow[ind] = -1;
_vm->_draw->_cursorAnimHigh[ind] = 0;
_vm->_draw->_cursorAnimDelays[ind] = 0;
}
void Inter_v1::o1_setRenderFlags() {
- _vm->_draw->_renderFlags = _vm->_parse->parseValExpr();
+ _vm->_draw->_renderFlags = _vm->_game->_script->readValExpr();
}
void Inter_v1::o1_loadAnim() {
@@ -407,7 +406,7 @@ void Inter_v1::o1_updateAnim() {
evalExpr(&animation);
evalExpr(&layer);
evalExpr(&frame);
- flags = load16();
+ flags = _vm->_game->_script->readInt16();
_vm->_scenery->updateAnim(layer, frame, animation, flags,
deltaX, deltaY, 1);
}
@@ -424,14 +423,14 @@ void Inter_v1::o1_initMult() {
oldAnimHeight = _vm->_mult->_animHeight;
oldObjCount = _vm->_mult->_objCount;
- _vm->_mult->_animLeft = load16();
- _vm->_mult->_animTop = load16();
- _vm->_mult->_animWidth = load16();
- _vm->_mult->_animHeight = load16();
- _vm->_mult->_objCount = load16();
- posXVar = _vm->_parse->parseVarIndex();
- posYVar = _vm->_parse->parseVarIndex();
- animDataVar = _vm->_parse->parseVarIndex();
+ _vm->_mult->_animLeft = _vm->_game->_script->readInt16();
+ _vm->_mult->_animTop = _vm->_game->_script->readInt16();
+ _vm->_mult->_animWidth = _vm->_game->_script->readInt16();
+ _vm->_mult->_animHeight = _vm->_game->_script->readInt16();
+ _vm->_mult->_objCount = _vm->_game->_script->readInt16();
+ posXVar = _vm->_game->_script->readVarIndex();
+ posYVar = _vm->_game->_script->readVarIndex();
+ animDataVar = _vm->_game->_script->readVarIndex();
if (_vm->_mult->_objects && (oldObjCount != _vm->_mult->_objCount)) {
@@ -464,8 +463,8 @@ void Inter_v1::o1_initMult() {
uint32 offPosY = i * 4 + (posYVar / 4) * 4;
uint32 offAnim = animDataVar + i * 4 * _vm->_global->_inter_animDataSize;
- _vm->_mult->_objects[i].pPosX = new VariableReference(*_vm->_inter->_variables, offPosX);
- _vm->_mult->_objects[i].pPosY = new VariableReference(*_vm->_inter->_variables, offPosY);
+ _vm->_mult->_objects[i].pPosX = new VariableReference(*_variables, offPosX);
+ _vm->_mult->_objects[i].pPosY = new VariableReference(*_variables, offPosY);
_vm->_mult->_objects[i].pAnimData =
(Mult::Mult_AnimData *) _variables->getAddressOff8(offAnim);
@@ -528,11 +527,11 @@ void Inter_v1::o1_loadMultObject() {
multData = (byte *) _vm->_mult->_objects[objIndex].pAnimData;
for (int i = 0; i < 11; i++) {
- if (READ_LE_UINT16(_vm->_global->_inter_execPtr) != 99) {
+ if (_vm->_game->_script->peekUint16() != 99) {
evalExpr(&val);
multData[i] = val;
} else
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
}
}
@@ -546,10 +545,10 @@ void Inter_v1::o1_getAnimLayerInfo() {
evalExpr(&anim);
evalExpr(&layer);
- varDX = _vm->_parse->parseVarIndex();
- varDY = _vm->_parse->parseVarIndex();
- varUnk0 = _vm->_parse->parseVarIndex();
- varFrames = _vm->_parse->parseVarIndex();
+ varDX = _vm->_game->_script->readVarIndex();
+ varDY = _vm->_game->_script->readVarIndex();
+ varUnk0 = _vm->_game->_script->readVarIndex();
+ varFrames = _vm->_game->_script->readVarIndex();
_vm->_scenery->writeAnimLayerInfo(anim, layer,
varDX, varDY, varUnk0, varFrames);
@@ -568,10 +567,10 @@ void Inter_v1::o1_getObjAnimSize() {
_vm->_scenery->_toRedrawLeft = MAX(_vm->_scenery->_toRedrawLeft, (int16) 0);
_vm->_scenery->_toRedrawTop = MAX(_vm->_scenery->_toRedrawTop, (int16) 0);
- WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->_toRedrawLeft);
- WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->_toRedrawTop);
- WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->_toRedrawRight);
- WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->_toRedrawBottom);
+ WRITE_VAR_OFFSET(_vm->_game->_script->readVarIndex(), _vm->_scenery->_toRedrawLeft);
+ WRITE_VAR_OFFSET(_vm->_game->_script->readVarIndex(), _vm->_scenery->_toRedrawTop);
+ WRITE_VAR_OFFSET(_vm->_game->_script->readVarIndex(), _vm->_scenery->_toRedrawRight);
+ WRITE_VAR_OFFSET(_vm->_game->_script->readVarIndex(), _vm->_scenery->_toRedrawBottom);
}
void Inter_v1::o1_loadStatic() {
@@ -586,8 +585,8 @@ void Inter_v1::o1_renderStatic() {
int16 layer;
int16 index;
- _vm->_inter->evalExpr(&index);
- _vm->_inter->evalExpr(&layer);
+ evalExpr(&index);
+ evalExpr(&layer);
_vm->_scenery->renderStatic(index, layer);
}
@@ -599,7 +598,7 @@ void Inter_v1::o1_loadCurLayer() {
void Inter_v1::o1_playCDTrack() {
evalExpr(0);
_vm->_sound->adlibPlayBgMusic(); // Mac version
- _vm->_sound->cdPlay(_vm->_parse->getResultStr()); // PC CD version
+ _vm->_sound->cdPlay(_vm->_game->_script->getResultStr()); // PC CD version
}
void Inter_v1::o1_getCDTrackPos() {
@@ -623,15 +622,15 @@ void Inter_v1::o1_stopCD() {
}
void Inter_v1::o1_loadFontToSprite() {
- int16 i = load16();
- _vm->_draw->_fontToSprite[i].sprite = load16();
- _vm->_draw->_fontToSprite[i].base = load16();
- _vm->_draw->_fontToSprite[i].width = load16();
- _vm->_draw->_fontToSprite[i].height = load16();
+ int16 i = _vm->_game->_script->readInt16();
+ _vm->_draw->_fontToSprite[i].sprite = _vm->_game->_script->readInt16();
+ _vm->_draw->_fontToSprite[i].base = _vm->_game->_script->readInt16();
+ _vm->_draw->_fontToSprite[i].width = _vm->_game->_script->readInt16();
+ _vm->_draw->_fontToSprite[i].height = _vm->_game->_script->readInt16();
}
void Inter_v1::o1_freeFontToSprite() {
- int16 i = load16();
+ int16 i = _vm->_game->_script->readInt16();
_vm->_draw->_fontToSprite[i].sprite = -1;
_vm->_draw->_fontToSprite[i].base = -1;
_vm->_draw->_fontToSprite[i].width = -1;
@@ -639,11 +638,11 @@ void Inter_v1::o1_freeFontToSprite() {
}
bool Inter_v1::o1_callSub(OpFuncParams &params) {
- byte *storedIP;
uint16 offset;
- offset = load16();
- storedIP = _vm->_global->_inter_execPtr;
+ offset = _vm->_game->_script->readUint16();
+
+ uint32 startPos = _vm->_game->_script->pos();
debugC(5, kDebugGameFlow, "tot = \"%s\", offset = %d",
_vm->_game->_curTotFile, offset);
@@ -667,19 +666,20 @@ bool Inter_v1::o1_callSub(OpFuncParams &params) {
return false;
}
- _vm->_global->_inter_execPtr = _vm->_game->_totFileData + offset;
+ _vm->_game->_script->seek(offset);
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
callSub(2);
- _vm->_global->_inter_execPtr = storedIP;
+
+ _vm->_game->_script->seek(startPos);
return false;
}
bool Inter_v1::o1_printTotText(OpFuncParams &params) {
- _vm->_draw->printTotText(load16());
+ _vm->_draw->printTotText(_vm->_game->_script->readInt16());
return false;
}
@@ -689,8 +689,8 @@ bool Inter_v1::o1_loadCursor(OpFuncParams &params) {
int16 id;
int8 index;
- id = load16();
- index = (int8) *_vm->_global->_inter_execPtr++;
+ id = _vm->_game->_script->readInt16();
+ index = _vm->_game->_script->readInt8();
if ((index * _vm->_draw->_cursorWidth) >= _vm->_draw->_cursorSprites->getWidth())
return false;
@@ -710,35 +710,41 @@ bool Inter_v1::o1_loadCursor(OpFuncParams &params) {
}
bool Inter_v1::o1_switch(OpFuncParams &params) {
- byte *callAddr;
+ uint32 offset;
+
+ checkSwitchTable(offset);
- checkSwitchTable(&callAddr);
- byte *storedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = callAddr;
+ uint32 startPos = _vm->_game->_script->pos();
+
+ _vm->_game->_script->seek(offset);
+ if (offset == 0)
+ _vm->_game->_script->setFinished(true);
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
funcBlock(0);
- _vm->_global->_inter_execPtr = storedIP;
+ _vm->_game->_script->seek(startPos);
return false;
}
bool Inter_v1::o1_repeatUntil(OpFuncParams &params) {
- byte *blockPtr;
int16 size;
bool flag;
_nestLevel[0]++;
- blockPtr = _vm->_global->_inter_execPtr;
+
+ uint32 blockPos = _vm->_game->_script->pos();
do {
- _vm->_global->_inter_execPtr = blockPtr;
- size = READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->seek(blockPos);
+ size = _vm->_game->_script->peekUint16(2) + 2;
funcBlock(1);
- _vm->_global->_inter_execPtr = blockPtr + size + 1;
+
+ _vm->_game->_script->seek(blockPos + size + 1);
+
flag = evalBoolResult();
} while (!flag && !_break && !_terminate && !_vm->shouldQuit());
@@ -752,32 +758,31 @@ bool Inter_v1::o1_repeatUntil(OpFuncParams &params) {
}
bool Inter_v1::o1_whileDo(OpFuncParams &params) {
- byte *blockPtr;
- byte *savedIP;
bool flag;
int16 size;
_nestLevel[0]++;
do {
- savedIP = _vm->_global->_inter_execPtr;
+ uint32 startPos = _vm->_game->_script->pos();
+
flag = evalBoolResult();
if (_terminate)
return false;
- blockPtr = _vm->_global->_inter_execPtr;
+ uint32 blockPos = _vm->_game->_script->pos();
- size = READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ size = _vm->_game->_script->peekUint16(2) + 2;
if (flag) {
funcBlock(1);
- _vm->_global->_inter_execPtr = savedIP;
+ _vm->_game->_script->seek(startPos);
} else
- _vm->_global->_inter_execPtr += size;
+ _vm->_game->_script->skip(size);
if (_break || _terminate || _vm->shouldQuit()) {
- _vm->_global->_inter_execPtr = blockPtr;
- _vm->_global->_inter_execPtr += size;
+ _vm->_game->_script->seek(blockPos);
+ _vm->_game->_script->skip(size);
break;
}
} while (flag);
@@ -793,58 +798,52 @@ bool Inter_v1::o1_whileDo(OpFuncParams &params) {
bool Inter_v1::o1_if(OpFuncParams &params) {
byte cmd;
bool boolRes;
- byte *storedIP;
boolRes = evalBoolResult();
if (boolRes) {
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
- storedIP = _vm->_global->_inter_execPtr;
+ uint32 startPos = _vm->_game->_script->pos();
funcBlock(0);
- _vm->_global->_inter_execPtr = storedIP;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->seek(startPos);
+
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
- debugC(5, kDebugGameFlow, "cmd = %d",
- (int16) *_vm->_global->_inter_execPtr);
+ debugC(5, kDebugGameFlow, "cmd = %d", (int16) _vm->_game->_script->peekByte());
- cmd = *_vm->_global->_inter_execPtr >> 4;
- _vm->_global->_inter_execPtr++;
+ cmd = _vm->_game->_script->readByte() >> 4;
if (cmd != 12)
return false;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
} else {
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
- debugC(5, kDebugGameFlow, "cmd = %d",
- (int16) *_vm->_global->_inter_execPtr);
+ debugC(5, kDebugGameFlow, "cmd = %d", (int16) _vm->_game->_script->peekByte());
- cmd = *_vm->_global->_inter_execPtr >> 4;
- _vm->_global->_inter_execPtr++;
+ cmd = _vm->_game->_script->readByte() >> 4;
if (cmd != 12)
return false;
if ((params.counter == params.cmdCount) && (params.retFlag == 2))
return true;
- storedIP = _vm->_global->_inter_execPtr;
+ uint32 startPos = _vm->_game->_script->pos();
+
funcBlock(0);
- _vm->_global->_inter_execPtr = storedIP;
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->seek(startPos);
+
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
}
return false;
}
bool Inter_v1::o1_assign(OpFuncParams &params) {
- byte destType = *_vm->_global->_inter_execPtr;
- int16 dest = _vm->_parse->parseVarIndex();
+ byte destType = _vm->_game->_script->peekByte();
+ int16 dest = _vm->_game->_script->readVarIndex();
int16 result;
int16 srcType = evalExpr(&result);
@@ -852,7 +851,7 @@ bool Inter_v1::o1_assign(OpFuncParams &params) {
switch (destType) {
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
- WRITE_VAR_OFFSET(dest, _vm->_parse->getResultInt());
+ WRITE_VAR_OFFSET(dest, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_STR:
@@ -860,7 +859,7 @@ bool Inter_v1::o1_assign(OpFuncParams &params) {
if (srcType == TYPE_IMM_INT16)
WRITE_VARO_UINT8(dest, result);
else
- WRITE_VARO_STR(dest, _vm->_parse->getResultStr());
+ WRITE_VARO_STR(dest, _vm->_game->_script->getResultStr());
break;
}
@@ -868,17 +867,17 @@ bool Inter_v1::o1_assign(OpFuncParams &params) {
}
bool Inter_v1::o1_loadSpriteToPos(OpFuncParams &params) {
- _vm->_draw->_spriteLeft = load16();
+ _vm->_draw->_spriteLeft = _vm->_game->_script->readInt16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
- _vm->_draw->_transparency = *_vm->_global->_inter_execPtr & 1;
- _vm->_draw->_destSurface = ((int16) (*_vm->_global->_inter_execPtr >> 1)) - 1;
+ _vm->_draw->_transparency = _vm->_game->_script->peekByte() & 1;
+ _vm->_draw->_destSurface = ((int16) (_vm->_game->_script->peekByte() >> 1)) - 1;
if (_vm->_draw->_destSurface < 0)
_vm->_draw->_destSurface = 101;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
_vm->_draw->spriteOperation(DRAW_LOADSPRITE);
@@ -889,12 +888,12 @@ bool Inter_v1::o1_printText(OpFuncParams &params) {
char buf[60];
int i;
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
- _vm->_draw->_backColor = _vm->_parse->parseValExpr();
- _vm->_draw->_frontColor = _vm->_parse->parseValExpr();
- _vm->_draw->_fontIndex = _vm->_parse->parseValExpr();
+ _vm->_draw->_backColor = _vm->_game->_script->readValExpr();
+ _vm->_draw->_frontColor = _vm->_game->_script->readValExpr();
+ _vm->_draw->_fontIndex = _vm->_game->_script->readValExpr();
_vm->_draw->_destSurface = 21;
_vm->_draw->_textToPrint = buf;
_vm->_draw->_transparency = 0;
@@ -905,35 +904,35 @@ bool Inter_v1::o1_printText(OpFuncParams &params) {
}
do {
- for (i = 0; (((char) *_vm->_global->_inter_execPtr) != '.') &&
- (*_vm->_global->_inter_execPtr != 200);
- i++, _vm->_global->_inter_execPtr++) {
- buf[i] = (char) *_vm->_global->_inter_execPtr;
+ for (i = 0; ((_vm->_game->_script->peekChar()) != '.') &&
+ (_vm->_game->_script->peekByte() != 200);
+ i++, _vm->_game->_script->skip(1)) {
+ buf[i] = _vm->_game->_script->peekChar();
}
- if (*_vm->_global->_inter_execPtr != 200) {
- _vm->_global->_inter_execPtr++;
- switch (*_vm->_global->_inter_execPtr) {
+ if (_vm->_game->_script->peekByte() != 200) {
+ _vm->_game->_script->skip(1);
+ switch (_vm->_game->_script->peekByte()) {
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
sprintf(buf + i, "%d",
- VAR_OFFSET(_vm->_parse->parseVarIndex()));
+ VAR_OFFSET(_vm->_game->_script->readVarIndex()));
break;
case TYPE_VAR_STR:
case TYPE_ARRAY_STR:
sprintf(buf + i, "%s",
- GET_VARO_STR(_vm->_parse->parseVarIndex()));
+ GET_VARO_STR(_vm->_game->_script->readVarIndex()));
break;
}
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
} else
buf[i] = 0;
_vm->_draw->spriteOperation(DRAW_PRINTTEXT);
- } while (*_vm->_global->_inter_execPtr != 200);
+ } while (_vm->_game->_script->peekByte() != 200);
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
return false;
}
@@ -942,16 +941,14 @@ bool Inter_v1::o1_loadTot(OpFuncParams &params) {
char buf[20];
int8 size;
- if ((*_vm->_global->_inter_execPtr & 0x80) != 0) {
- _vm->_global->_inter_execPtr++;
+ if ((_vm->_game->_script->peekByte() & 0x80) != 0) {
+ _vm->_game->_script->skip(1);
evalExpr(0);
- strncpy0(buf, _vm->_parse->getResultStr(), 15);
+ strncpy0(buf, _vm->_game->_script->getResultStr(), 15);
} else {
- size = (int8) *_vm->_global->_inter_execPtr++;
- for (int i = 0; i < size; i++)
- buf[i] = *_vm->_global->_inter_execPtr++;
-
- buf[size] = 0;
+ size = _vm->_game->_script->readInt8();
+ memcpy(buf, _vm->_game->_script->readString(size), size);
+ buf[size] = '\0';
}
// if (_vm->getGameType() == kGameTypeGeisha)
@@ -971,12 +968,12 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
byte *palPtr;
byte cmd;
- cmd = *_vm->_global->_inter_execPtr++;
+ cmd = _vm->_game->_script->readByte();
switch (cmd & 0x7F) {
case 48:
if ((_vm->_global->_fakeVideoMode < 0x32) ||
(_vm->_global->_fakeVideoMode > 0x63)) {
- _vm->_global->_inter_execPtr += 48;
+ _vm->_game->_script->skip(48);
return false;
}
break;
@@ -984,35 +981,35 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
case 49:
if ((_vm->_global->_fakeVideoMode != 5) &&
(_vm->_global->_fakeVideoMode != 7)) {
- _vm->_global->_inter_execPtr += 18;
+ _vm->_game->_script->skip(18);
return false;
}
break;
case 50:
if (_vm->_global->_colorCount == 256) {
- _vm->_global->_inter_execPtr += 16;
+ _vm->_game->_script->skip(16);
return false;
}
break;
case 51:
if (_vm->_global->_fakeVideoMode < 0x64) {
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
return false;
}
break;
case 52:
if (_vm->_global->_colorCount == 256) {
- _vm->_global->_inter_execPtr += 48;
+ _vm->_game->_script->skip(48);
return false;
}
break;
case 53:
if (_vm->_global->_colorCount != 256) {
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
return false;
}
break;
@@ -1025,14 +1022,14 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
case 61:
if (_vm->_global->_fakeVideoMode < 0x13) {
- _vm->_global->_inter_execPtr += 4;
+ _vm->_game->_script->skip(4);
return false;
}
break;
}
if ((cmd & 0x7F) == 0x30) {
- _vm->_global->_inter_execPtr += 48;
+ _vm->_game->_script->skip(48);
return false;
}
@@ -1043,7 +1040,7 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
bool allZero = true;
for (int i = 2; i < 18; i++) {
- if (_vm->_global->_inter_execPtr[i] != 0) {
+ if (_vm->_game->_script->peekByte(i) != 0) {
allZero = false;
break;
}
@@ -1051,28 +1048,30 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
if (!allZero) {
_vm->_video->clearSurf(*_vm->_draw->_frontSurface);
_vm->_draw->_noInvalidated57 = true;
- _vm->_global->_inter_execPtr += 18;
+ _vm->_game->_script->skip(48);
return false;
}
_vm->_draw->_noInvalidated57 = false;
- for (int i = 0; i < 18; i++, _vm->_global->_inter_execPtr++) {
+ for (int i = 0; i < 18; i++) {
if (i < 2) {
if (!_vm->_draw->_applyPal)
continue;
- _vm->_draw->_unusedPalette1[i] = *_vm->_global->_inter_execPtr;
+ _vm->_draw->_unusedPalette1[i] = _vm->_game->_script->peekByte();
continue;
}
- index1 = *_vm->_global->_inter_execPtr >> 4;
- index2 = (*_vm->_global->_inter_execPtr & 0xF);
+ index1 = _vm->_game->_script->peekByte() >> 4;
+ index2 = _vm->_game->_script->peekByte() & 0xF;
_vm->_draw->_unusedPalette1[i] =
((_vm->_draw->_palLoadData1[index1] +
_vm->_draw->_palLoadData2[index2]) << 8) +
(_vm->_draw->_palLoadData2[index1] +
_vm->_draw->_palLoadData1[index2]);
+
+ _vm->_game->_script->skip(1);
}
_vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1;
@@ -1082,20 +1081,20 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
switch (cmd) {
case 50:
- for (int i = 0; i < 16; i++, _vm->_global->_inter_execPtr++)
- _vm->_draw->_unusedPalette2[i] = *_vm->_global->_inter_execPtr;
+ for (int i = 0; i < 16; i++)
+ _vm->_draw->_unusedPalette2[i] = _vm->_game->_script->readByte();
break;
case 52:
- for (int i = 0; i < 16; i++, _vm->_global->_inter_execPtr += 3) {
- _vm->_draw->_vgaPalette[i].red = _vm->_global->_inter_execPtr[0];
- _vm->_draw->_vgaPalette[i].green = _vm->_global->_inter_execPtr[1];
- _vm->_draw->_vgaPalette[i].blue = _vm->_global->_inter_execPtr[2];
+ for (int i = 0; i < 16; i++) {
+ _vm->_draw->_vgaPalette[i].red = _vm->_game->_script->readByte();
+ _vm->_draw->_vgaPalette[i].green = _vm->_game->_script->readByte();
+ _vm->_draw->_vgaPalette[i].blue = _vm->_game->_script->readByte();
}
break;
case 53:
- palPtr = _vm->_game->loadTotResource(_vm->_inter->load16());
+ palPtr = _vm->_game->loadTotResource(_vm->_game->_script->readInt16());
memcpy((char *) _vm->_draw->_vgaPalette, palPtr, 768);
break;
@@ -1104,9 +1103,9 @@ bool Inter_v1::o1_palLoad(OpFuncParams &params) {
break;
case 61:
- index1 = *_vm->_global->_inter_execPtr++;
- index2 = (*_vm->_global->_inter_execPtr++ - index1 + 1) * 3;
- palPtr = _vm->_game->loadTotResource(_vm->_inter->load16());
+ index1 = _vm->_game->_script->readByte();
+ index2 = (_vm->_game->_script->readByte() - index1 + 1) * 3;
+ palPtr = _vm->_game->loadTotResource(_vm->_game->_script->readInt16());
memcpy((char *) _vm->_draw->_vgaPalette + index1 * 3,
palPtr + index1 * 3, index2);
@@ -1146,7 +1145,7 @@ bool Inter_v1::o1_keyFunc(OpFuncParams &params) {
int16 key;
uint32 now;
- cmd = load16();
+ cmd = _vm->_game->_script->readInt16();
animPalette();
_vm->_draw->blitInvalidated();
@@ -1161,7 +1160,7 @@ bool Inter_v1::o1_keyFunc(OpFuncParams &params) {
// to become 5000. We deliberately slow down busy-waiting, so we shorten
// the counting, too.
if ((_vm->getGameType() == kGameTypeWeen) && (VAR(59) < 4000) &&
- ((_vm->_global->_inter_execPtr - _vm->_game->_totFileData) == 729) &&
+ (_vm->_game->_script->pos() == 729) &&
!scumm_stricmp(_vm->_game->_curTotFile, "intro5.tot"))
WRITE_VAR(59, 4000);
@@ -1207,10 +1206,10 @@ bool Inter_v1::o1_capturePush(OpFuncParams &params) {
int16 left, top;
int16 width, height;
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ left = _vm->_game->_script->readValExpr();
+ top = _vm->_game->_script->readValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
if ((width < 0) || (height < 0))
return false;
@@ -1229,16 +1228,16 @@ bool Inter_v1::o1_capturePop(OpFuncParams &params) {
}
bool Inter_v1::o1_animPalInit(OpFuncParams &params) {
- _animPalDir[0] = load16();
- _animPalLowIndex[0] = _vm->_parse->parseValExpr();
- _animPalHighIndex[0] = _vm->_parse->parseValExpr();
+ _animPalDir[0] = _vm->_game->_script->readInt16();
+ _animPalLowIndex[0] = _vm->_game->_script->readValExpr();
+ _animPalHighIndex[0] = _vm->_game->_script->readValExpr();
return false;
}
bool Inter_v1::o1_drawOperations(OpFuncParams &params) {
byte cmd;
- cmd = *_vm->_global->_inter_execPtr++;
+ cmd = _vm->_game->_script->readByte();
executeOpcodeDraw(cmd);
@@ -1246,7 +1245,7 @@ bool Inter_v1::o1_drawOperations(OpFuncParams &params) {
}
bool Inter_v1::o1_setcmdCount(OpFuncParams &params) {
- params.cmdCount = *_vm->_global->_inter_execPtr++;
+ params.cmdCount = _vm->_game->_script->readByte();
params.counter = 0;
return false;
}
@@ -1255,7 +1254,7 @@ bool Inter_v1::o1_return(OpFuncParams &params) {
if (params.retFlag != 2)
_break = true;
- _vm->_global->_inter_execPtr = 0;
+ _vm->_game->_script->setFinished(true);
return true;
}
@@ -1265,7 +1264,7 @@ bool Inter_v1::o1_renewTimeInVars(OpFuncParams &params) {
}
bool Inter_v1::o1_speakerOn(OpFuncParams &params) {
- _vm->_sound->speakerOn(_vm->_parse->parseValExpr(), -1);
+ _vm->_sound->speakerOn(_vm->_game->_script->readValExpr(), -1);
return false;
}
@@ -1275,11 +1274,11 @@ bool Inter_v1::o1_speakerOff(OpFuncParams &params) {
}
bool Inter_v1::o1_putPixel(OpFuncParams &params) {
- _vm->_draw->_destSurface = load16();
+ _vm->_draw->_destSurface = _vm->_game->_script->readInt16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
- _vm->_draw->_frontColor = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
+ _vm->_draw->_frontColor = _vm->_game->_script->readValExpr();
_vm->_draw->spriteOperation(DRAW_PUTPIXEL);
return false;
}
@@ -1291,33 +1290,33 @@ bool Inter_v1::o1_goblinFunc(OpFuncParams &params) {
gobParams.extraData = 0;
gobParams.objDesc = 0;
- gobParams.retVarPtr.set(*_vm->_inter->_variables, 236);
+ gobParams.retVarPtr.set(*_variables, 236);
- cmd = load16();
- _vm->_global->_inter_execPtr += 2;
+ cmd = _vm->_game->_script->readInt16();
+ _vm->_game->_script->skip(2);
if ((cmd > 0) && (cmd < 17)) {
objDescSet = true;
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
gobParams.objDesc = _vm->_goblin->_objects[gobParams.extraData];
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
}
if ((cmd > 90) && (cmd < 107)) {
objDescSet = true;
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
gobParams.objDesc = _vm->_goblin->_goblins[gobParams.extraData];
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
cmd -= 90;
}
if ((cmd > 110) && (cmd < 128)) {
objDescSet = true;
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
gobParams.objDesc = _vm->_goblin->_goblins[gobParams.extraData];
cmd -= 90;
} else if ((cmd > 20) && (cmd < 38)) {
objDescSet = true;
- gobParams.extraData = load16();
+ gobParams.extraData = _vm->_game->_script->readInt16();
gobParams.objDesc = _vm->_goblin->_objects[gobParams.extraData];
}
@@ -1343,31 +1342,31 @@ bool Inter_v1::o1_createSprite(OpFuncParams &params) {
int16 width, height;
int16 flag;
- if (_vm->_global->_inter_execPtr[1] == 0) {
- index = load16();
- width = load16();
- height = load16();
+ if (_vm->_game->_script->peekByte(1) == 0) {
+ index = _vm->_game->_script->readInt16();
+ width = _vm->_game->_script->readInt16();
+ height = _vm->_game->_script->readInt16();
} else {
- index = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ index = _vm->_game->_script->readValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
}
- flag = load16();
+ flag = _vm->_game->_script->readInt16();
_vm->_draw->initSpriteSurf(index, width, height, flag ? 2 : 0);
return false;
}
bool Inter_v1::o1_freeSprite(OpFuncParams &params) {
- _vm->_draw->freeSprite(load16());
+ _vm->_draw->freeSprite(_vm->_game->_script->readInt16());
return false;
}
bool Inter_v1::o1_returnTo(OpFuncParams &params) {
if (params.retFlag == 1) {
_break = true;
- _vm->_global->_inter_execPtr = 0;
+ _vm->_game->_script->setFinished(true);
return true;
}
@@ -1376,14 +1375,14 @@ bool Inter_v1::o1_returnTo(OpFuncParams &params) {
*_breakFromLevel = *_nestLevel;
_break = true;
- _vm->_global->_inter_execPtr = 0;
+ _vm->_game->_script->setFinished(true);
return true;
}
bool Inter_v1::o1_loadSpriteContent(OpFuncParams &params) {
- _vm->_draw->_spriteLeft = load16();
- _vm->_draw->_destSurface = load16();
- _vm->_draw->_transparency = load16();
+ _vm->_draw->_spriteLeft = _vm->_game->_script->readInt16();
+ _vm->_draw->_destSurface = _vm->_game->_script->readInt16();
+ _vm->_draw->_transparency = _vm->_game->_script->readInt16();
_vm->_draw->_destSpriteX = 0;
_vm->_draw->_destSpriteY = 0;
@@ -1392,25 +1391,25 @@ bool Inter_v1::o1_loadSpriteContent(OpFuncParams &params) {
}
bool Inter_v1::o1_copySprite(OpFuncParams &params) {
- if (_vm->_global->_inter_execPtr[1] == 0)
- _vm->_draw->_sourceSurface = load16();
+ if (_vm->_game->_script->peekByte(1) == 0)
+ _vm->_draw->_sourceSurface = _vm->_game->_script->readInt16();
else
- _vm->_draw->_sourceSurface = _vm->_parse->parseValExpr();
+ _vm->_draw->_sourceSurface = _vm->_game->_script->readValExpr();
- if (_vm->_global->_inter_execPtr[1] == 0)
- _vm->_draw->_destSurface = load16();
+ if (_vm->_game->_script->peekByte(1) == 0)
+ _vm->_draw->_destSurface = _vm->_game->_script->readInt16();
else
- _vm->_draw->_destSurface = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSurface = _vm->_game->_script->readValExpr();
- _vm->_draw->_spriteLeft = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteTop = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteRight = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteBottom = _vm->_parse->parseValExpr();
+ _vm->_draw->_spriteLeft = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteTop = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
- _vm->_draw->_transparency = load16();
+ _vm->_draw->_transparency = _vm->_game->_script->readInt16();
_vm->_draw->spriteOperation(DRAW_BLITSURF);
return false;
@@ -1419,14 +1418,14 @@ bool Inter_v1::o1_copySprite(OpFuncParams &params) {
bool Inter_v1::o1_fillRect(OpFuncParams &params) {
int16 destSurf;
- _vm->_draw->_destSurface = destSurf = load16();
+ _vm->_draw->_destSurface = destSurf = _vm->_game->_script->readInt16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteRight = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteBottom = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr();
- _vm->_draw->_backColor = _vm->_parse->parseValExpr();
+ _vm->_draw->_backColor = _vm->_game->_script->readValExpr();
if (!_vm->_draw->_spritesArray[(destSurf >= 100) ? (destSurf - 80) : destSurf])
return false;
@@ -1445,14 +1444,14 @@ bool Inter_v1::o1_fillRect(OpFuncParams &params) {
}
bool Inter_v1::o1_drawLine(OpFuncParams &params) {
- _vm->_draw->_destSurface = load16();
+ _vm->_draw->_destSurface = _vm->_game->_script->readInt16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteRight = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteBottom = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr();
- _vm->_draw->_frontColor = _vm->_parse->parseValExpr();
+ _vm->_draw->_frontColor = _vm->_game->_script->readValExpr();
_vm->_draw->spriteOperation(DRAW_DRAWLINE);
return false;
}
@@ -1463,28 +1462,28 @@ bool Inter_v1::o1_strToLong(OpFuncParams &params) {
int16 destVar;
int32 res;
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
strncpy0(str, GET_VARO_STR(strVar), 19);
res = atoi(str);
- destVar = _vm->_parse->parseVarIndex();
+ destVar = _vm->_game->_script->readVarIndex();
WRITE_VAR_OFFSET(destVar, res);
return false;
}
bool Inter_v1::o1_invalidate(OpFuncParams &params) {
- _vm->_draw->_destSurface = load16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteRight = _vm->_parse->parseValExpr();
- _vm->_draw->_frontColor = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSurface = _vm->_game->_script->readInt16();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
+ _vm->_draw->_frontColor = _vm->_game->_script->readValExpr();
_vm->_draw->spriteOperation(DRAW_INVALIDATE);
return false;
}
bool Inter_v1::o1_setBackDelta(OpFuncParams &params) {
- _vm->_draw->_backDeltaX = _vm->_parse->parseValExpr();
- _vm->_draw->_backDeltaY = _vm->_parse->parseValExpr();
+ _vm->_draw->_backDeltaX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_backDeltaY = _vm->_game->_script->readValExpr();
return false;
}
@@ -1495,9 +1494,9 @@ bool Inter_v1::o1_playSound(OpFuncParams &params) {
int16 index;
int16 endRep;
- index = _vm->_parse->parseValExpr();
- repCount = _vm->_parse->parseValExpr();
- frequency = _vm->_parse->parseValExpr();
+ index = _vm->_game->_script->readValExpr();
+ repCount = _vm->_game->_script->readValExpr();
+ frequency = _vm->_game->_script->readValExpr();
SoundDesc *sample = _vm->_sound->sampleGetBySlot(index);
@@ -1533,7 +1532,7 @@ bool Inter_v1::o1_playSound(OpFuncParams &params) {
bool Inter_v1::o1_stopSound(OpFuncParams &params) {
_vm->_sound->adlibStop();
- _vm->_sound->blasterStop(_vm->_parse->parseValExpr());
+ _vm->_sound->blasterStop(_vm->_game->_script->readValExpr());
_soundEndTimeKey = 0;
return false;
@@ -1559,8 +1558,8 @@ bool Inter_v1::o1_playComposition(OpFuncParams &params) {
int16 dataVar;
int16 freqVal;
- dataVar = _vm->_parse->parseVarIndex();
- freqVal = _vm->_parse->parseValExpr();
+ dataVar = _vm->_game->_script->readVarIndex();
+ freqVal = _vm->_game->_script->readValExpr();
for (int i = 0; i < 50; i++)
composition[i] = (int16) VAR_OFFSET(dataVar + i * 4);
@@ -1572,8 +1571,8 @@ bool Inter_v1::o1_getFreeMem(OpFuncParams &params) {
int16 freeVar;
int16 maxFreeVar;
- freeVar = _vm->_parse->parseVarIndex();
- maxFreeVar = _vm->_parse->parseVarIndex();
+ freeVar = _vm->_game->_script->readVarIndex();
+ maxFreeVar = _vm->_game->_script->readVarIndex();
// HACK
WRITE_VAR_OFFSET(freeVar, 1000000);
@@ -1586,21 +1585,21 @@ bool Inter_v1::o1_checkData(OpFuncParams &params) {
int16 varOff;
evalExpr(0);
- varOff = _vm->_parse->parseVarIndex();
- handle = _vm->_dataIO->openData(_vm->_parse->getResultStr());
+ varOff = _vm->_game->_script->readVarIndex();
+ handle = _vm->_dataIO->openData(_vm->_game->_script->getResultStr());
WRITE_VAR_OFFSET(varOff, handle);
if (handle >= 0)
_vm->_dataIO->closeData(handle);
else
- warning("File \"%s\" not found", _vm->_parse->getResultStr());
+ warning("File \"%s\" not found", _vm->_game->_script->getResultStr());
return false;
}
bool Inter_v1::o1_prepareStr(OpFuncParams &params) {
int16 strVar;
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
_vm->_util->prepareStr(GET_VARO_FSTR(strVar));
return false;
}
@@ -1609,12 +1608,12 @@ bool Inter_v1::o1_insertStr(OpFuncParams &params) {
int16 pos;
int16 strVar;
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
evalExpr(0);
- pos = _vm->_parse->parseValExpr();
+ pos = _vm->_game->_script->readValExpr();
char *str = GET_VARO_FSTR(strVar);
- _vm->_util->insertStr(_vm->_parse->getResultStr(), str, pos);
+ _vm->_util->insertStr(_vm->_game->_script->getResultStr(), str, pos);
return false;
}
@@ -1623,9 +1622,9 @@ bool Inter_v1::o1_cutStr(OpFuncParams &params) {
int16 pos;
int16 size;
- strVar = _vm->_parse->parseVarIndex();
- pos = _vm->_parse->parseValExpr();
- size = _vm->_parse->parseValExpr();
+ strVar = _vm->_game->_script->readVarIndex();
+ pos = _vm->_game->_script->readValExpr();
+ size = _vm->_game->_script->readValExpr();
_vm->_util->cutFromStr(GET_VARO_STR(strVar), pos, size);
return false;
}
@@ -1635,11 +1634,11 @@ bool Inter_v1::o1_strstr(OpFuncParams &params) {
int16 resVar;
int16 pos;
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
evalExpr(0);
- resVar = _vm->_parse->parseVarIndex();
+ resVar = _vm->_game->_script->readVarIndex();
- char *res = strstr(GET_VARO_STR(strVar), _vm->_parse->getResultStr());
+ char *res = strstr(GET_VARO_STR(strVar), _vm->_game->_script->getResultStr());
pos = res ? (res - (GET_VARO_STR(strVar))) : -1;
WRITE_VAR_OFFSET(resVar, pos);
return false;
@@ -1649,17 +1648,17 @@ bool Inter_v1::o1_istrlen(OpFuncParams &params) {
int16 len;
int16 strVar;
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
len = strlen(GET_VARO_STR(strVar));
- strVar = _vm->_parse->parseVarIndex();
+ strVar = _vm->_game->_script->readVarIndex();
WRITE_VAR_OFFSET(strVar, len);
return false;
}
bool Inter_v1::o1_setMousePos(OpFuncParams &params) {
- _vm->_global->_inter_mouseX = _vm->_parse->parseValExpr();
- _vm->_global->_inter_mouseY = _vm->_parse->parseValExpr();
+ _vm->_global->_inter_mouseX = _vm->_game->_script->readValExpr();
+ _vm->_global->_inter_mouseY = _vm->_game->_script->readValExpr();
_vm->_global->_inter_mouseX -= _vm->_video->_scrollOffsetX;
_vm->_global->_inter_mouseY -= _vm->_video->_scrollOffsetY;
if (_vm->_global->_useMouse != 0)
@@ -1669,7 +1668,7 @@ bool Inter_v1::o1_setMousePos(OpFuncParams &params) {
}
bool Inter_v1::o1_setFrameRate(OpFuncParams &params) {
- _vm->_util->setFrameRate(_vm->_parse->parseValExpr());
+ _vm->_util->setFrameRate(_vm->_game->_script->readValExpr());
return false;
}
@@ -1696,7 +1695,7 @@ bool Inter_v1::o1_loadFont(OpFuncParams &params) {
int16 index;
evalExpr(0);
- index = load16();
+ index = _vm->_game->_script->readInt16();
delete _vm->_draw->_fonts[index];
@@ -1705,7 +1704,7 @@ bool Inter_v1::o1_loadFont(OpFuncParams &params) {
_vm->_dataIO->closeData(_vm->_game->_extHandle);
_vm->_draw->_fonts[index] =
- _vm->_util->loadFont(_vm->_parse->getResultStr());
+ _vm->_util->loadFont(_vm->_game->_script->getResultStr());
if (_vm->_game->_extHandle >= 0)
_vm->_game->_extHandle = _vm->_dataIO->openData(_vm->_game->_curExtFile);
@@ -1715,7 +1714,7 @@ bool Inter_v1::o1_loadFont(OpFuncParams &params) {
bool Inter_v1::o1_freeFont(OpFuncParams &params) {
int16 index;
- index = load16();
+ index = _vm->_game->_script->readInt16();
delete _vm->_draw->_fonts[index];
_vm->_draw->_fonts[index] = 0;
return false;
@@ -1729,16 +1728,16 @@ bool Inter_v1::o1_readData(OpFuncParams &params) {
int16 handle;
evalExpr(0);
- dataVar = _vm->_parse->parseVarIndex();
- size = _vm->_parse->parseValExpr();
- offset = _vm->_parse->parseValExpr();
+ dataVar = _vm->_game->_script->readVarIndex();
+ size = _vm->_game->_script->readValExpr();
+ offset = _vm->_game->_script->readValExpr();
retSize = 0;
if (_vm->_game->_extHandle >= 0)
_vm->_dataIO->closeData(_vm->_game->_extHandle);
WRITE_VAR(1, 1);
- handle = _vm->_dataIO->openData(_vm->_parse->getResultStr());
+ handle = _vm->_dataIO->openData(_vm->_game->_script->getResultStr());
if (handle >= 0) {
DataStream *stream = _vm->_dataIO->openAsStream(handle, true);
@@ -1774,11 +1773,11 @@ bool Inter_v1::o1_writeData(OpFuncParams &params) {
// called regardless.
evalExpr(0);
- dataVar = _vm->_parse->parseVarIndex();
- size = _vm->_parse->parseValExpr();
- offset = _vm->_parse->parseValExpr();
+ dataVar = _vm->_game->_script->readVarIndex();
+ size = _vm->_game->_script->readValExpr();
+ offset = _vm->_game->_script->readValExpr();
- warning("Attempted to write to file \"%s\"", _vm->_parse->getResultStr());
+ warning("Attempted to write to file \"%s\"", _vm->_game->_script->getResultStr());
WRITE_VAR(1, 0);
return false;
@@ -1787,8 +1786,8 @@ bool Inter_v1::o1_writeData(OpFuncParams &params) {
bool Inter_v1::o1_manageDataFile(OpFuncParams &params) {
evalExpr(0);
- if (_vm->_parse->getResultStr()[0] != 0)
- _vm->_dataIO->openDataFile(_vm->_parse->getResultStr());
+ if (_vm->_game->_script->getResultStr()[0] != 0)
+ _vm->_dataIO->openDataFile(_vm->_game->_script->getResultStr());
else
_vm->_dataIO->closeDataFile();
return false;
@@ -1952,16 +1951,16 @@ void Inter_v1::o1_getMaxTick(OpGobParams &params) {
}
void Inter_v1::o1_manipulateMap(OpGobParams &params) {
- int16 xPos = load16();
- int16 yPos = load16();
- int16 item = load16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
+ int16 item = _vm->_game->_script->readInt16();
manipulateMap(xPos, yPos, item);
}
void Inter_v1::o1_getItem(OpGobParams &params) {
- int16 xPos = load16();
- int16 yPos = load16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
if ((_vm->_map->getItem(xPos, yPos) & 0xFF00) != 0)
params.retVarPtr = (uint32) ((_vm->_map->getItem(xPos, yPos) & 0xFF00) >> 8);
@@ -1970,9 +1969,9 @@ void Inter_v1::o1_getItem(OpGobParams &params) {
}
void Inter_v1::o1_manipulateMapIndirect(OpGobParams &params) {
- int16 xPos = load16();
- int16 yPos = load16();
- int16 item = load16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
+ int16 item = _vm->_game->_script->readInt16();
xPos = VAR(xPos);
yPos = VAR(yPos);
@@ -1982,8 +1981,8 @@ void Inter_v1::o1_manipulateMapIndirect(OpGobParams &params) {
}
void Inter_v1::o1_getItemIndirect(OpGobParams &params) {
- int16 xPos = load16();
- int16 yPos = load16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
xPos = VAR(xPos);
yPos = VAR(yPos);
@@ -1995,17 +1994,17 @@ void Inter_v1::o1_getItemIndirect(OpGobParams &params) {
}
void Inter_v1::o1_setPassMap(OpGobParams &params) {
- int16 xPos = load16();
- int16 yPos = load16();
- int16 val = load16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
+ int16 val = _vm->_game->_script->readInt16();
_vm->_map->setPass(xPos, yPos, val);
}
void Inter_v1::o1_setGoblinPosH(OpGobParams &params) {
int16 layer;
- int16 item = load16();
- int16 xPos = load16();
- int16 yPos = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
_vm->_goblin->_gobPositions[item].x = xPos * 2;
_vm->_goblin->_gobPositions[item].y = yPos * 2;
@@ -2040,20 +2039,20 @@ void Inter_v1::o1_setGoblinPosH(OpGobParams &params) {
}
void Inter_v1::o1_getGoblinPosXH(OpGobParams &params) {
- int16 item = load16();
+ int16 item = _vm->_game->_script->readInt16();
params.retVarPtr = (uint32) (_vm->_goblin->_gobPositions[item].x >> 1);
}
void Inter_v1::o1_getGoblinPosYH(OpGobParams &params) {
- int16 item = load16();
+ int16 item = _vm->_game->_script->readInt16();
params.retVarPtr = (uint32) (_vm->_goblin->_gobPositions[item].y >> 1);
}
void Inter_v1::o1_setGoblinMultState(OpGobParams &params) {
int16 layer;
- int16 item = load16();
- int16 xPos = load16();
- int16 yPos = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_goblins[item];
if (yPos == 0) {
@@ -2112,18 +2111,18 @@ void Inter_v1::o1_setGoblinMultState(OpGobParams &params) {
}
void Inter_v1::o1_setGoblinUnk14(OpGobParams &params) {
- int16 item = load16();
- int16 val = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 val = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_objects[item];
params.objDesc->unk14 = val;
}
void Inter_v1::o1_setItemIdInPocket(OpGobParams &params) {
- _vm->_goblin->_itemIdInPocket = load16();
+ _vm->_goblin->_itemIdInPocket = _vm->_game->_script->readInt16();
}
void Inter_v1::o1_setItemIndInPocket(OpGobParams &params) {
- _vm->_goblin->_itemIndInPocket = load16();
+ _vm->_goblin->_itemIndInPocket = _vm->_game->_script->readInt16();
}
void Inter_v1::o1_getItemIdInPocket(OpGobParams &params) {
@@ -2136,9 +2135,9 @@ void Inter_v1::o1_getItemIndInPocket(OpGobParams &params) {
void Inter_v1::o1_setGoblinPos(OpGobParams &params) {
int16 layer;
- int16 item = load16();
- int16 xPos = load16();
- int16 yPos = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
_vm->_goblin->_gobPositions[item].x = xPos;
_vm->_goblin->_gobPositions[item].y = yPos;
@@ -2173,8 +2172,8 @@ void Inter_v1::o1_setGoblinPos(OpGobParams &params) {
void Inter_v1::o1_setGoblinState(OpGobParams &params) {
int16 layer;
- int16 item = load16();
- int16 state = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 state = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_goblins[item];
params.objDesc->nextState = state;
@@ -2198,8 +2197,8 @@ void Inter_v1::o1_setGoblinState(OpGobParams &params) {
void Inter_v1::o1_setGoblinStateRedraw(OpGobParams &params) {
int16 layer;
- int16 item = load16();
- int16 state = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 state = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_objects[item];
params.objDesc->nextState = state;
@@ -2226,7 +2225,7 @@ void Inter_v1::o1_setGoblinStateRedraw(OpGobParams &params) {
}
void Inter_v1::o1_decRelaxTime(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_objects[params.extraData];
params.objDesc->relaxTime--;
@@ -2240,12 +2239,12 @@ void Inter_v1::o1_decRelaxTime(OpGobParams &params) {
}
void Inter_v1::o1_getGoblinPosX(OpGobParams &params) {
- int16 item = load16();
+ int16 item = _vm->_game->_script->readInt16();
params.retVarPtr = (uint32) _vm->_goblin->_gobPositions[item].x;
}
void Inter_v1::o1_getGoblinPosY(OpGobParams &params) {
- int16 item = load16();
+ int16 item = _vm->_game->_script->readInt16();
params.retVarPtr = (uint32) _vm->_goblin->_gobPositions[item].y;
}
@@ -2254,18 +2253,18 @@ void Inter_v1::o1_clearPathExistence(OpGobParams &params) {
}
void Inter_v1::o1_setGoblinVisible(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
_vm->_goblin->_goblins[params.extraData]->visible = 1;
}
void Inter_v1::o1_setGoblinInvisible(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
_vm->_goblin->_goblins[params.extraData]->visible = 0;
}
void Inter_v1::o1_getObjectIntersect(OpGobParams &params) {
- params.extraData = load16();
- int16 item = load16();
+ params.extraData = _vm->_game->_script->readInt16();
+ int16 item = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_objects[params.extraData];
if (_vm->_goblin->objIntersected(params.objDesc,
@@ -2276,8 +2275,8 @@ void Inter_v1::o1_getObjectIntersect(OpGobParams &params) {
}
void Inter_v1::o1_getGoblinIntersect(OpGobParams &params) {
- params.extraData = load16();
- int16 item = load16();
+ params.extraData = _vm->_game->_script->readInt16();
+ int16 item = _vm->_game->_script->readInt16();
params.objDesc = _vm->_goblin->_goblins[params.extraData];
if (_vm->_goblin->objIntersected(params.objDesc,
@@ -2288,10 +2287,10 @@ void Inter_v1::o1_getGoblinIntersect(OpGobParams &params) {
}
void Inter_v1::o1_setItemPos(OpGobParams &params) {
- int16 item = load16();
- int16 xPos = load16();
- int16 yPos = load16();
- int16 val = load16();
+ int16 item = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
+ int16 yPos = _vm->_game->_script->readInt16();
+ int16 val = _vm->_game->_script->readInt16();
_vm->_map->_itemPoses[item].x = xPos;
_vm->_map->_itemPoses[item].y = yPos;
@@ -2299,7 +2298,7 @@ void Inter_v1::o1_setItemPos(OpGobParams &params) {
}
void Inter_v1::o1_loadObjects(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
if (_vm->_game->_extHandle >= 0)
_vm->_dataIO->closeData(_vm->_game->_extHandle);
@@ -2329,8 +2328,8 @@ void Inter_v1::o1_loadMap(OpGobParams &params) {
void Inter_v1::o1_moveGoblin(OpGobParams &params) {
int16 item;
- params.extraData = load16();
- int16 xPos = load16();
+ params.extraData = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
if ((uint16) VAR(xPos) == 0) {
item =
@@ -2355,9 +2354,9 @@ void Inter_v1::o1_loadGoblin(OpGobParams &params) {
}
void Inter_v1::o1_writeTreatItem(OpGobParams &params) {
- params.extraData = load16();
- int16 cmd = load16();
- int16 xPos = load16();
+ params.extraData = _vm->_game->_script->readInt16();
+ int16 cmd = _vm->_game->_script->readInt16();
+ int16 xPos = _vm->_game->_script->readInt16();
if ((uint16) VAR(xPos) == 0) {
WRITE_VAR(cmd, _vm->_goblin->treatItem((uint16) VAR(params.extraData)));
@@ -2373,7 +2372,7 @@ void Inter_v1::o1_moveGoblin0(OpGobParams &params) {
}
void Inter_v1::o1_setGoblinTarget(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
if (VAR(params.extraData) != 0)
_vm->_goblin->_goesAtTarget = 1;
else
@@ -2381,11 +2380,11 @@ void Inter_v1::o1_setGoblinTarget(OpGobParams &params) {
}
void Inter_v1::o1_setGoblinObjectsPos(OpGobParams &params) {
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
params.extraData = VAR(params.extraData);
_vm->_goblin->_objects[10]->xPos = params.extraData;
- params.extraData = load16();
+ params.extraData = _vm->_game->_script->readInt16();
params.extraData = VAR(params.extraData);
_vm->_goblin->_objects[10]->yPos = params.extraData;
}
@@ -2485,11 +2484,11 @@ int16 Inter_v1::loadSound(int16 slot) {
SoundSource source;
if (slot == -1)
- slot = _vm->_parse->parseValExpr();
+ slot = _vm->_game->_script->readValExpr();
- id = load16();
+ id = _vm->_game->_script->readInt16();
if (id == -1) {
- _vm->_global->_inter_execPtr += 9;
+ _vm->_game->_script->skip(9);
return 0;
}
diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp
index 5c846a1105..00adaef38c 100644
--- a/engines/gob/inter_v2.cpp
+++ b/engines/gob/inter_v2.cpp
@@ -36,10 +36,11 @@
#include "gob/dataio.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
+#include "gob/parse.h"
#include "gob/goblin.h"
#include "gob/map.h"
#include "gob/mult.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/video.h"
#include "gob/save/saveload.h"
@@ -147,20 +148,20 @@ void Inter_v2::setupOpcodesGob() {
OPCODEGOB(501, o2_stopProtracker);
}
-void Inter_v2::checkSwitchTable(byte **ppExec) {
- byte cmd;
+void Inter_v2::checkSwitchTable(uint32 &offset) {
+ byte type;
int16 len;
int32 value;
bool found;
found = false;
- *ppExec = 0;
+ offset = 0;
- cmd = *_vm->_global->_inter_execPtr;
+ type = _vm->_game->_script->peekByte();
- value = _vm->_parse->parseVarIndex();
+ value = _vm->_game->_script->readVarIndex();
- switch (cmd) {
+ switch (type) {
case TYPE_VAR_INT8:
case TYPE_ARRAY_INT8:
value = (int8) READ_VARO_UINT8(value);
@@ -179,78 +180,74 @@ void Inter_v2::checkSwitchTable(byte **ppExec) {
if (_terminate)
return;
- len = (int8) *_vm->_global->_inter_execPtr++;
+ len = _vm->_game->_script->readInt8();
while (len != -5) {
for (int i = 0; i < len; i++) {
- cmd = *_vm->_global->_inter_execPtr;
+ type = _vm->_game->_script->peekByte();
- switch (cmd) {
+ switch (type) {
case TYPE_IMM_INT32:
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
if (!found &&
- (value ==
- (int32) (READ_LE_UINT32(_vm->_global->_inter_execPtr))))
+ (value == _vm->_game->_script->peekInt32()))
found = true;
- _vm->_global->_inter_execPtr += 5;
+ _vm->_game->_script->skip(5);
break;
case TYPE_IMM_INT16:
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
if (!found &&
- (value ==
- (int16) (READ_LE_UINT16(_vm->_global->_inter_execPtr))))
+ (value == _vm->_game->_script->peekInt16()))
found = true;
- _vm->_global->_inter_execPtr += 3;
+ _vm->_game->_script->skip(3);
break;
case TYPE_IMM_INT8:
- _vm->_global->_inter_execPtr++;
- if (!found && (value == (int8) *_vm->_global->_inter_execPtr))
+ _vm->_game->_script->skip(1);
+ if (!found && (value == _vm->_game->_script->peekInt8()))
found = true;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
break;
default:
if (!found) {
evalExpr(0);
- if (value == _vm->_parse->getResultInt())
+ if (value == _vm->_game->_script->getResultInt())
found = true;
} else
- _vm->_parse->skipExpr(99);
+ _vm->_game->_script->skipExpr(99);
break;
}
}
- if (found && !*ppExec)
- *ppExec = _vm->_global->_inter_execPtr;
+ if (found && (offset == 0))
+ offset = _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
- len = (int8) *_vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
+ len = _vm->_game->_script->readInt8();
}
- if ((*_vm->_global->_inter_execPtr >> 4) != 4)
+ if ((_vm->_game->_script->peekByte() >> 4) != 4)
return;
- _vm->_global->_inter_execPtr++;
- if (!*ppExec)
- *ppExec = _vm->_global->_inter_execPtr;
+ _vm->_game->_script->skip(1);
+ if (offset == 0)
+ offset = _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr +=
- READ_LE_UINT16(_vm->_global->_inter_execPtr + 2) + 2;
+ _vm->_game->_script->skip(_vm->_game->_script->peekUint16(2) + 2);
}
void Inter_v2::o2_playMult() {
int16 checkEscape;
- checkEscape = load16();
+ checkEscape = _vm->_game->_script->readInt16();
_vm->_mult->setMultData(checkEscape >> 1);
_vm->_mult->playMult(VAR(57), -1, checkEscape & 0x1, 0);
}
void Inter_v2::o2_freeMultKeys() {
- uint16 index = load16();
+ uint16 index = _vm->_game->_script->readUint16();
if (!_vm->_mult->hasMultData(index))
return;
@@ -263,7 +260,7 @@ void Inter_v2::o2_freeMultKeys() {
void Inter_v2::o2_setRenderFlags() {
int16 expr;
- expr = _vm->_parse->parseValExpr();
+ expr = _vm->_game->_script->readValExpr();
if (expr & 0x8000) {
_vm->_draw->_renderFlags |= expr & 0x3FFF;
@@ -276,7 +273,7 @@ void Inter_v2::o2_setRenderFlags() {
}
void Inter_v2::o2_multSub() {
- _vm->_mult->multSub(_vm->_parse->parseValExpr());
+ _vm->_mult->multSub(_vm->_game->_script->readValExpr());
}
void Inter_v2::o2_initMult() {
@@ -291,14 +288,14 @@ void Inter_v2::o2_initMult() {
oldAnimHeight = _vm->_mult->_animHeight;
oldObjCount = _vm->_mult->_objCount;
- _vm->_mult->_animLeft = load16();
- _vm->_mult->_animTop = load16();
- _vm->_mult->_animWidth = load16();
- _vm->_mult->_animHeight = load16();
- _vm->_mult->_objCount = load16();
- posXVar = _vm->_parse->parseVarIndex();
- posYVar = _vm->_parse->parseVarIndex();
- animDataVar = _vm->_parse->parseVarIndex();
+ _vm->_mult->_animLeft = _vm->_game->_script->readInt16();
+ _vm->_mult->_animTop = _vm->_game->_script->readInt16();
+ _vm->_mult->_animWidth = _vm->_game->_script->readInt16();
+ _vm->_mult->_animHeight = _vm->_game->_script->readInt16();
+ _vm->_mult->_objCount = _vm->_game->_script->readInt16();
+ posXVar = _vm->_game->_script->readVarIndex();
+ posYVar = _vm->_game->_script->readVarIndex();
+ animDataVar = _vm->_game->_script->readVarIndex();
if (_vm->_mult->_objects && (oldObjCount != _vm->_mult->_objCount)) {
warning("Initializing new objects without having "
@@ -400,20 +397,20 @@ void Inter_v2::o2_loadMultObject() {
int16 layer;
byte *multData;
- objIndex = _vm->_parse->parseValExpr();
- val = _vm->_parse->parseValExpr();
+ objIndex = _vm->_game->_script->readValExpr();
+ val = _vm->_game->_script->readValExpr();
*_vm->_mult->_objects[objIndex].pPosX = val;
- val = _vm->_parse->parseValExpr();
+ val = _vm->_game->_script->readValExpr();
*_vm->_mult->_objects[objIndex].pPosY = val;
debugC(4, kDebugGameFlow, "Loading mult object %d", objIndex);
multData = (byte *) _vm->_mult->_objects[objIndex].pAnimData;
for (int i = 0; i < 11; i++) {
- if (*_vm->_global->_inter_execPtr != 99)
- multData[i] = _vm->_parse->parseValExpr();
+ if (_vm->_game->_script->peekByte() != 99)
+ multData[i] = _vm->_game->_script->readValExpr();
else
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
}
Mult::Mult_Object &obj = _vm->_mult->_objects[objIndex];
@@ -496,14 +493,14 @@ void Inter_v2::o2_renderStatic() {
int16 layer;
int16 index;
- index = _vm->_parse->parseValExpr();
- layer = _vm->_parse->parseValExpr();
+ index = _vm->_game->_script->readValExpr();
+ layer = _vm->_game->_script->readValExpr();
_vm->_scenery->renderStatic(index, layer);
}
void Inter_v2::o2_loadCurLayer() {
- _vm->_scenery->_curStatic = _vm->_parse->parseValExpr();
- _vm->_scenery->_curStaticLayer = _vm->_parse->parseValExpr();
+ _vm->_scenery->_curStatic = _vm->_game->_script->readValExpr();
+ _vm->_scenery->_curStaticLayer = _vm->_game->_script->readValExpr();
}
void Inter_v2::o2_playCDTrack() {
@@ -511,7 +508,7 @@ void Inter_v2::o2_playCDTrack() {
_vm->_draw->blitInvalidated();
evalExpr(0);
- _vm->_sound->cdPlay(_vm->_parse->getResultStr());
+ _vm->_sound->cdPlay(_vm->_game->_script->getResultStr());
}
void Inter_v2::o2_waitCDTrackEnd() {
@@ -529,7 +526,7 @@ void Inter_v2::o2_readLIC() {
char path[40];
evalExpr(0);
- strncpy0(path, _vm->_parse->getResultStr(), 35);
+ strncpy0(path, _vm->_game->_script->getResultStr(), 35);
strcat(path, ".LIC");
_vm->_sound->cdLoadLIC(path);
@@ -545,24 +542,24 @@ void Inter_v2::o2_getCDTrackPos() {
_vm->_util->longDelay(1);
- varPos = _vm->_parse->parseVarIndex();
- varName = _vm->_parse->parseVarIndex();
+ varPos = _vm->_game->_script->readVarIndex();
+ varName = _vm->_game->_script->readVarIndex();
WRITE_VAR_OFFSET(varPos, _vm->_sound->cdGetTrackPos(GET_VARO_STR(varName)));
WRITE_VARO_STR(varName, _vm->_sound->cdGetCurrentTrack());
}
void Inter_v2::o2_loadFontToSprite() {
- int16 i = load16();
-
- _vm->_draw->_fontToSprite[i].sprite = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_draw->_fontToSprite[i].base = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_draw->_fontToSprite[i].width = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
- _vm->_draw->_fontToSprite[i].height = *_vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += 2;
+ int16 i = _vm->_game->_script->readInt16();
+
+ _vm->_draw->_fontToSprite[i].sprite = _vm->_game->_script->readByte();
+ _vm->_game->_script->skip(1);
+ _vm->_draw->_fontToSprite[i].base = _vm->_game->_script->readByte();
+ _vm->_game->_script->skip(1);
+ _vm->_draw->_fontToSprite[i].width = _vm->_game->_script->readByte();
+ _vm->_game->_script->skip(1);
+ _vm->_draw->_fontToSprite[i].height = _vm->_game->_script->readByte();
+ _vm->_game->_script->skip(1);
}
void Inter_v2::o2_totSub() {
@@ -571,16 +568,16 @@ void Inter_v2::o2_totSub() {
int flags;
int i;
- length = *_vm->_global->_inter_execPtr++;
+ length = _vm->_game->_script->readByte();
if ((length & 0x7F) > 13)
error("Length in o2_totSub is greater than 13 (%d)", length);
if (length & 0x80) {
evalExpr(0);
- strcpy(totFile, _vm->_parse->getResultStr());
+ strcpy(totFile, _vm->_game->_script->getResultStr());
} else {
for (i = 0; i < length; i++)
- totFile[i] = (char) *_vm->_global->_inter_execPtr++;
+ totFile[i] = _vm->_game->_script->readChar();
totFile[i] = 0;
}
@@ -588,7 +585,7 @@ void Inter_v2::o2_totSub() {
if (!scumm_stricmp(totFile, "edit"))
_vm->_util->forceMouseUp();
- flags = *_vm->_global->_inter_execPtr++;
+ flags = _vm->_game->_script->readByte();
_vm->_game->totSub(flags, totFile);
}
@@ -596,8 +593,8 @@ void Inter_v2::o2_switchTotSub() {
int16 index;
int16 skipPlay;
- index = load16();
- skipPlay = load16();
+ index = _vm->_game->_script->readInt16();
+ skipPlay = _vm->_game->_script->readInt16();
_vm->_game->switchTotSub(index, skipPlay);
}
@@ -606,13 +603,13 @@ void Inter_v2::o2_pushVars() {
byte count;
int16 varOff;
- count = *_vm->_global->_inter_execPtr++;
+ count = _vm->_game->_script->readByte();
for (int i = 0; i < count; i++, _varStackPos++) {
- if ((*_vm->_global->_inter_execPtr == 25) ||
- (*_vm->_global->_inter_execPtr == 28)) {
+ if ((_vm->_game->_script->peekByte() == 25) ||
+ (_vm->_game->_script->peekByte() == 28)) {
- varOff = _vm->_parse->parseVarIndex();
- _vm->_global->_inter_execPtr++;
+ varOff = _vm->_game->_script->readVarIndex();
+ _vm->_game->_script->skip(1);
_variables->copyTo(varOff, _varStack + _varStackPos, _vm->_global->_inter_animDataSize * 4);
@@ -620,7 +617,7 @@ void Inter_v2::o2_pushVars() {
_varStack[_varStackPos] = _vm->_global->_inter_animDataSize * 4;
} else {
- int32 n = _vm->_parse->getResultInt();
+ int32 n = _vm->_game->_script->getResultInt();
if (evalExpr(&varOff) != 20)
n = 0;
@@ -637,9 +634,9 @@ void Inter_v2::o2_popVars() {
int16 varOff;
int16 size;
- count = *_vm->_global->_inter_execPtr++;
+ count = _vm->_game->_script->readByte();
for (int i = 0; i < count; i++) {
- varOff = _vm->_parse->parseVarIndex();
+ varOff = _vm->_game->_script->readVarIndex();
size = _varStack[--_varStackPos];
_varStackPos -= size;
@@ -659,9 +656,9 @@ void Inter_v2::o2_moveGoblin() {
int16 destX, destY;
int16 index;
- destX = _vm->_parse->parseValExpr();
- destY = _vm->_parse->parseValExpr();
- index = _vm->_parse->parseValExpr();
+ destX = _vm->_game->_script->readValExpr();
+ destY = _vm->_game->_script->readValExpr();
+ index = _vm->_game->_script->readValExpr();
_vm->_goblin->move(destX, destY, index);
}
@@ -669,15 +666,15 @@ void Inter_v2::o2_writeGoblinPos() {
int16 varX, varY;
int16 index;
- varX = _vm->_parse->parseVarIndex();
- varY = _vm->_parse->parseVarIndex();
- index = _vm->_parse->parseValExpr();
+ varX = _vm->_game->_script->readVarIndex();
+ varY = _vm->_game->_script->readVarIndex();
+ index = _vm->_game->_script->readValExpr();
WRITE_VAR_OFFSET(varX, _vm->_mult->_objects[index].goblinX);
WRITE_VAR_OFFSET(varY, _vm->_mult->_objects[index].goblinY);
}
void Inter_v2::o2_stopGoblin() {
- int16 index = _vm->_parse->parseValExpr();
+ int16 index = _vm->_game->_script->readValExpr();
_vm->_mult->_objects[index].pAnimData->pathExistence = 4;
}
@@ -691,9 +688,9 @@ void Inter_v2::o2_setGoblinState() {
int16 deltaX, deltaY;
int16 deltaWidth, deltaHeight;
- index = _vm->_parse->parseValExpr();
- state = _vm->_parse->parseValExpr();
- type = _vm->_parse->parseValExpr();
+ index = _vm->_game->_script->readValExpr();
+ state = _vm->_game->_script->readValExpr();
+ type = _vm->_game->_script->readValExpr();
Mult::Mult_Object &obj = _vm->_mult->_objects[index];
Mult::Mult_AnimData &objAnim = *(obj.pAnimData);
@@ -789,10 +786,10 @@ void Inter_v2::o2_placeGoblin() {
int16 x, y;
int16 state;
- index = _vm->_parse->parseValExpr();
- x = _vm->_parse->parseValExpr();
- y = _vm->_parse->parseValExpr();
- state = _vm->_parse->parseValExpr();
+ index = _vm->_game->_script->readValExpr();
+ x = _vm->_game->_script->readValExpr();
+ y = _vm->_game->_script->readValExpr();
+ state = _vm->_game->_script->readValExpr();
_vm->_goblin->placeObject(0, 0, index, x, y, state);
}
@@ -802,13 +799,13 @@ void Inter_v2::o2_initScreen() {
int16 videoMode;
int16 width, height;
- offY = load16();
+ offY = _vm->_game->_script->readInt16();
videoMode = offY & 0xFF;
offY = (offY >> 8) & 0xFF;
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
_vm->_video->clearScreen();
@@ -896,16 +893,16 @@ void Inter_v2::o2_scroll() {
int16 curX;
int16 curY;
- startX = CLIP((int) _vm->_parse->parseValExpr(), 0,
+ startX = CLIP((int) _vm->_game->_script->readValExpr(), 0,
_vm->_video->_surfWidth - _vm->_width);
- startY = CLIP((int) _vm->_parse->parseValExpr(), 0,
+ startY = CLIP((int) _vm->_game->_script->readValExpr(), 0,
_vm->_video->_surfHeight - _vm->_height);
- endX = CLIP((int) _vm->_parse->parseValExpr(), 0,
+ endX = CLIP((int) _vm->_game->_script->readValExpr(), 0,
_vm->_video->_surfWidth - _vm->_width);
- endY = CLIP((int) _vm->_parse->parseValExpr(), 0,
+ endY = CLIP((int) _vm->_game->_script->readValExpr(), 0,
_vm->_video->_surfHeight - _vm->_height);
- stepX = _vm->_parse->parseValExpr();
- stepY = _vm->_parse->parseValExpr();
+ stepX = _vm->_game->_script->readValExpr();
+ stepY = _vm->_game->_script->readValExpr();
curX = startX;
curY = startY;
@@ -925,8 +922,8 @@ void Inter_v2::o2_scroll() {
void Inter_v2::o2_setScrollOffset() {
int16 offsetX, offsetY;
- offsetX = _vm->_parse->parseValExpr();
- offsetY = _vm->_parse->parseValExpr();
+ offsetX = _vm->_game->_script->readValExpr();
+ offsetY = _vm->_game->_script->readValExpr();
if (offsetX == -1) {
WRITE_VAR(2, _vm->_draw->_scrollOffsetX);
@@ -962,21 +959,21 @@ void Inter_v2::o2_playImd() {
bool close;
evalExpr(0);
- _vm->_parse->getResultStr()[8] = 0;
- strncpy0(imd, _vm->_parse->getResultStr(), 127);
-
- x = _vm->_parse->parseValExpr();
- y = _vm->_parse->parseValExpr();
- startFrame = _vm->_parse->parseValExpr();
- lastFrame = _vm->_parse->parseValExpr();
- breakKey = _vm->_parse->parseValExpr();
- flags = _vm->_parse->parseValExpr();
- palStart = _vm->_parse->parseValExpr();
- palEnd = _vm->_parse->parseValExpr();
+ _vm->_game->_script->getResultStr()[8] = 0;
+ strncpy0(imd, _vm->_game->_script->getResultStr(), 127);
+
+ x = _vm->_game->_script->readValExpr();
+ y = _vm->_game->_script->readValExpr();
+ startFrame = _vm->_game->_script->readValExpr();
+ lastFrame = _vm->_game->_script->readValExpr();
+ breakKey = _vm->_game->_script->readValExpr();
+ flags = _vm->_game->_script->readValExpr();
+ palStart = _vm->_game->_script->readValExpr();
+ palEnd = _vm->_game->_script->readValExpr();
palCmd = 1 << (flags & 0x3F);
debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, "
- "paletteCmd %d (%d - %d), flags %X", _vm->_parse->getResultStr(), x, y,
+ "paletteCmd %d (%d - %d), flags %X", _vm->_game->_script->getResultStr(), x, y,
startFrame, lastFrame, palCmd, palStart, palEnd, flags);
if ((imd[0] != 0) && !_vm->_vidPlayer->primaryOpen(imd, x, y, flags)) {
@@ -1006,19 +1003,19 @@ void Inter_v2::o2_getImdInfo() {
int16 varWidth, varHeight;
evalExpr(0);
- varX = _vm->_parse->parseVarIndex();
- varY = _vm->_parse->parseVarIndex();
- varFrames = _vm->_parse->parseVarIndex();
- varWidth = _vm->_parse->parseVarIndex();
- varHeight = _vm->_parse->parseVarIndex();
+ varX = _vm->_game->_script->readVarIndex();
+ varY = _vm->_game->_script->readVarIndex();
+ varFrames = _vm->_game->_script->readVarIndex();
+ varWidth = _vm->_game->_script->readVarIndex();
+ varHeight = _vm->_game->_script->readVarIndex();
// WORKAROUND: The nut rolling animation in the administration center
// in Woodruff is called "noixroul", but the scripts think it's "noixroule".
if ((_vm->getGameType() == kGameTypeWoodruff) &&
- (!scumm_stricmp(_vm->_parse->getResultStr(), "noixroule")))
- strcpy(_vm->_parse->getResultStr(), "noixroul");
+ (!scumm_stricmp(_vm->_game->_script->getResultStr(), "noixroule")))
+ strcpy(_vm->_game->_script->getResultStr(), "noixroul");
- _vm->_vidPlayer->writeVideoInfo(_vm->_parse->getResultStr(), varX, varY,
+ _vm->_vidPlayer->writeVideoInfo(_vm->_game->_script->getResultStr(), varX, varY,
varFrames, varWidth, varHeight);
}
@@ -1026,7 +1023,7 @@ void Inter_v2::o2_openItk() {
char fileName[32];
evalExpr(0);
- strncpy0(fileName, _vm->_parse->getResultStr(), 27);
+ strncpy0(fileName, _vm->_game->_script->getResultStr(), 27);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");
@@ -1044,13 +1041,13 @@ void Inter_v2::o2_resetImdFrontSurf() {
}
bool Inter_v2::o2_assign(OpFuncParams &params) {
- byte destType = *_vm->_global->_inter_execPtr;
- int16 dest = _vm->_parse->parseVarIndex();
+ byte destType = _vm->_game->_script->peekByte();
+ int16 dest = _vm->_game->_script->readVarIndex();
byte loopCount;
- if (*_vm->_global->_inter_execPtr == 99) {
- _vm->_global->_inter_execPtr++;
- loopCount = *_vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 99) {
+ _vm->_game->_script->skip(1);
+ loopCount = _vm->_game->_script->readByte();
} else
loopCount = 1;
@@ -1061,21 +1058,21 @@ bool Inter_v2::o2_assign(OpFuncParams &params) {
switch (destType) {
case TYPE_VAR_INT8:
case TYPE_ARRAY_INT8:
- WRITE_VARO_UINT8(dest + i, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT8(dest + i, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT16:
case TYPE_ARRAY_INT16:
- WRITE_VARO_UINT16(dest + i * 2, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT16(dest + i * 2, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
- WRITE_VAR_OFFSET(dest + i * 4, _vm->_parse->getResultInt());
+ WRITE_VAR_OFFSET(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32_AS_INT16:
- WRITE_VARO_UINT16(dest + i * 4, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT16(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_STR:
@@ -1083,7 +1080,7 @@ bool Inter_v2::o2_assign(OpFuncParams &params) {
if (srcType == TYPE_IMM_INT16)
WRITE_VARO_UINT8(dest, result);
else
- WRITE_VARO_STR(dest, _vm->_parse->getResultStr());
+ WRITE_VARO_STR(dest, _vm->_game->_script->getResultStr());
break;
}
}
@@ -1095,12 +1092,12 @@ bool Inter_v2::o2_printText(OpFuncParams &params) {
char buf[60];
int i;
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
- _vm->_draw->_backColor = _vm->_parse->parseValExpr();
- _vm->_draw->_frontColor = _vm->_parse->parseValExpr();
- _vm->_draw->_fontIndex = _vm->_parse->parseValExpr();
+ _vm->_draw->_backColor = _vm->_game->_script->readValExpr();
+ _vm->_draw->_frontColor = _vm->_game->_script->readValExpr();
+ _vm->_draw->_fontIndex = _vm->_game->_script->readValExpr();
_vm->_draw->_destSurface = 21;
_vm->_draw->_textToPrint = buf;
_vm->_draw->_transparency = 0;
@@ -1111,48 +1108,47 @@ bool Inter_v2::o2_printText(OpFuncParams &params) {
}
do {
- for (i = 0; (((char) *_vm->_global->_inter_execPtr) != '.') &&
- (*_vm->_global->_inter_execPtr != 200);
- i++, _vm->_global->_inter_execPtr++) {
- buf[i] = (char) *_vm->_global->_inter_execPtr;
+ for (i = 0; (_vm->_game->_script->peekChar() != '.') &&
+ (_vm->_game->_script->peekByte() != 200); i++) {
+ buf[i] = _vm->_game->_script->readChar();
}
- if (*_vm->_global->_inter_execPtr != 200) {
- _vm->_global->_inter_execPtr++;
- switch (*_vm->_global->_inter_execPtr) {
+ if (_vm->_game->_script->peekByte() != 200) {
+ _vm->_game->_script->skip(1);
+ switch (_vm->_game->_script->peekByte()) {
case TYPE_VAR_INT8:
case TYPE_ARRAY_INT8:
sprintf(buf + i, "%d",
- (int8) READ_VARO_UINT8(_vm->_parse->parseVarIndex()));
+ (int8) READ_VARO_UINT8(_vm->_game->_script->readVarIndex()));
break;
case TYPE_VAR_INT16:
case TYPE_VAR_INT32_AS_INT16:
case TYPE_ARRAY_INT16:
sprintf(buf + i, "%d",
- (int16) READ_VARO_UINT16(_vm->_parse->parseVarIndex()));
+ (int16) READ_VARO_UINT16(_vm->_game->_script->readVarIndex()));
break;
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
sprintf(buf + i, "%d",
- VAR_OFFSET(_vm->_parse->parseVarIndex()));
+ VAR_OFFSET(_vm->_game->_script->readVarIndex()));
break;
case TYPE_VAR_STR:
case TYPE_ARRAY_STR:
sprintf(buf + i, "%s",
- GET_VARO_STR(_vm->_parse->parseVarIndex()));
+ GET_VARO_STR(_vm->_game->_script->readVarIndex()));
break;
}
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
} else
buf[i] = 0;
_vm->_draw->spriteOperation(DRAW_PRINTTEXT);
- } while (*_vm->_global->_inter_execPtr != 200);
+ } while (_vm->_game->_script->peekByte() != 200);
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
return false;
}
@@ -1160,20 +1156,20 @@ bool Inter_v2::o2_printText(OpFuncParams &params) {
bool Inter_v2::o2_animPalInit(OpFuncParams &params) {
int16 index;
- index = load16();
+ index = _vm->_game->_script->readInt16();
if (index > 0) {
index--;
- _animPalLowIndex[index] = _vm->_parse->parseValExpr();
- _animPalHighIndex[index] = _vm->_parse->parseValExpr();
+ _animPalLowIndex[index] = _vm->_game->_script->readValExpr();
+ _animPalHighIndex[index] = _vm->_game->_script->readValExpr();
_animPalDir[index] = 1;
} else if (index == 0) {
memset(_animPalDir, 0, 8 * sizeof(int16));
- _vm->_parse->parseValExpr();
- _vm->_parse->parseValExpr();
+ _vm->_game->_script->readValExpr();
+ _vm->_game->_script->readValExpr();
} else {
index = -index - 1;
- _animPalLowIndex[index] = _vm->_parse->parseValExpr();
- _animPalHighIndex[index] = _vm->_parse->parseValExpr();
+ _animPalLowIndex[index] = _vm->_game->_script->readValExpr();
+ _animPalHighIndex[index] = _vm->_game->_script->readValExpr();
_animPalDir[index] = -1;
}
return false;
@@ -1186,14 +1182,14 @@ bool Inter_v2::o2_addCollision(OpFuncParams &params) {
int16 key;
int16 funcSub;
- id = _vm->_parse->parseValExpr();
- funcSub = _vm->_global->_inter_execPtr - _vm->_game->_totFileData;
- left = _vm->_parse->parseValExpr();
- top = _vm->_parse->parseValExpr();
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
- flags = _vm->_parse->parseValExpr();
- key = load16();
+ id = _vm->_game->_script->readValExpr();
+ funcSub = _vm->_game->_script->pos();
+ left = _vm->_game->_script->readValExpr();
+ top = _vm->_game->_script->readValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
+ flags = _vm->_game->_script->readValExpr();
+ key = _vm->_game->_script->readInt16();
if (key == 0)
key = ABS(id) + 41960;
@@ -1227,7 +1223,7 @@ bool Inter_v2::o2_addCollision(OpFuncParams &params) {
bool Inter_v2::o2_freeCollision(OpFuncParams &params) {
int16 id;
- id = _vm->_parse->parseValExpr();
+ id = _vm->_game->_script->readValExpr();
if (id == -2) {
for (int i = 0; i < 150; i++) {
if ((_vm->_game->_collisionAreas[i].id & 0xF000) == 0xD000)
@@ -1249,9 +1245,9 @@ bool Inter_v2::o2_goblinFunc(OpFuncParams &params) {
// It's not yet implemented, so we fudge our way through
// and pretend we've won.
if (_vm->getGameType() == kGameTypeInca2) {
- _vm->_global->_inter_execPtr += 4;
- uint16 resVar = (uint16) load16();
- _vm->_global->_inter_execPtr += 4;
+ _vm->_game->_script->skip(4);
+ uint16 resVar = _vm->_game->_script->readUint16();
+ _vm->_game->_script->skip(4);
WRITE_VAR(resVar, 1);
return false;
@@ -1260,9 +1256,9 @@ bool Inter_v2::o2_goblinFunc(OpFuncParams &params) {
OpGobParams gobParams;
int16 cmd;
- cmd = load16();
+ cmd = _vm->_game->_script->readInt16();
- gobParams.paramCount = load16();
+ gobParams.paramCount = _vm->_game->_script->readInt16();
gobParams.extraData = cmd;
if (cmd != 101)
@@ -1273,7 +1269,7 @@ bool Inter_v2::o2_goblinFunc(OpFuncParams &params) {
bool Inter_v2::o2_stopSound(OpFuncParams &params) {
int16 expr;
- expr = _vm->_parse->parseValExpr();
+ expr = _vm->_game->_script->readValExpr();
if (expr < 0) {
_vm->_sound->adlibStop();
@@ -1293,13 +1289,13 @@ bool Inter_v2::o2_getFreeMem(OpFuncParams &params) {
int16 freeVar;
int16 maxFreeVar;
- freeVar = _vm->_parse->parseVarIndex();
- maxFreeVar = _vm->_parse->parseVarIndex();
+ freeVar = _vm->_game->_script->readVarIndex();
+ maxFreeVar = _vm->_game->_script->readVarIndex();
// HACK
WRITE_VAR_OFFSET(freeVar, 1000000);
WRITE_VAR_OFFSET(maxFreeVar, 1000000);
- WRITE_VAR(16, READ_LE_UINT32(_vm->_game->_totFileData + 0x2C) * 4);
+ WRITE_VAR(16, READ_LE_UINT32(_vm->_game->_script->getData() + 0x2C) * 4);
return false;
}
@@ -1310,21 +1306,21 @@ bool Inter_v2::o2_checkData(OpFuncParams &params) {
SaveLoad::SaveMode mode;
evalExpr(0);
- varOff = _vm->_parse->parseVarIndex();
+ varOff = _vm->_game->_script->readVarIndex();
size = -1;
handle = 1;
- mode = _vm->_saveLoad->getSaveMode(_vm->_parse->getResultStr());
+ mode = _vm->_saveLoad->getSaveMode(_vm->_game->_script->getResultStr());
if (mode == SaveLoad::kSaveModeNone) {
- if (_vm->_dataIO->existData(_vm->_parse->getResultStr()))
- size = _vm->_dataIO->getDataSize(_vm->_parse->getResultStr());
+ if (_vm->_dataIO->existData(_vm->_game->_script->getResultStr()))
+ size = _vm->_dataIO->getDataSize(_vm->_game->_script->getResultStr());
else
- warning("File \"%s\" not found", _vm->_parse->getResultStr());
+ warning("File \"%s\" not found", _vm->_game->_script->getResultStr());
} else if (mode == SaveLoad::kSaveModeSave)
- size = _vm->_saveLoad->getSize(_vm->_parse->getResultStr());
+ size = _vm->_saveLoad->getSize(_vm->_game->_script->getResultStr());
else if (mode == SaveLoad::kSaveModeExists)
size = 23;
@@ -1332,7 +1328,7 @@ bool Inter_v2::o2_checkData(OpFuncParams &params) {
handle = -1;
debugC(2, kDebugFileIO, "Requested size of file \"%s\": %d",
- _vm->_parse->getResultStr(), size);
+ _vm->_game->_script->getResultStr(), size);
WRITE_VAR_OFFSET(varOff, handle);
WRITE_VAR(16, (uint32) size);
@@ -1350,19 +1346,19 @@ bool Inter_v2::o2_readData(OpFuncParams &params) {
SaveLoad::SaveMode mode;
evalExpr(0);
- dataVar = _vm->_parse->parseVarIndex();
- size = _vm->_parse->parseValExpr();
+ dataVar = _vm->_game->_script->readVarIndex();
+ size = _vm->_game->_script->readValExpr();
evalExpr(0);
- offset = _vm->_parse->getResultInt();
+ offset = _vm->_game->_script->getResultInt();
retSize = 0;
debugC(2, kDebugFileIO, "Read from file \"%s\" (%d, %d bytes at %d)",
- _vm->_parse->getResultStr(), dataVar, size, offset);
+ _vm->_game->_script->getResultStr(), dataVar, size, offset);
- mode = _vm->_saveLoad->getSaveMode(_vm->_parse->getResultStr());
+ mode = _vm->_saveLoad->getSaveMode(_vm->_game->_script->getResultStr());
if (mode == SaveLoad::kSaveModeSave) {
WRITE_VAR(1, 1);
- if (_vm->_saveLoad->load(_vm->_parse->getResultStr(), dataVar, size, offset))
+ if (_vm->_saveLoad->load(_vm->_game->_script->getResultStr(), dataVar, size, offset))
WRITE_VAR(1, 0);
return false;
} else if (mode == SaveLoad::kSaveModeIgnore)
@@ -1370,22 +1366,22 @@ bool Inter_v2::o2_readData(OpFuncParams &params) {
if (size < 0) {
warning("Attempted to read a raw sprite from file \"%s\"",
- _vm->_parse->getResultStr());
+ _vm->_game->_script->getResultStr());
return false ;
} else if (size == 0) {
dataVar = 0;
- size = READ_LE_UINT32(_vm->_game->_totFileData + 0x2C) * 4;
+ size = READ_LE_UINT32(_vm->_game->_script->getData() + 0x2C) * 4;
}
buf = _variables->getAddressOff8(dataVar);
- if (_vm->_parse->getResultStr()[0] == 0) {
+ if (_vm->_game->_script->getResultStr()[0] == 0) {
WRITE_VAR(1, size);
return false;
}
WRITE_VAR(1, 1);
- handle = _vm->_dataIO->openData(_vm->_parse->getResultStr());
+ handle = _vm->_dataIO->openData(_vm->_game->_script->getResultStr());
if (handle < 0)
return false;
@@ -1421,22 +1417,22 @@ bool Inter_v2::o2_writeData(OpFuncParams &params) {
SaveLoad::SaveMode mode;
evalExpr(0);
- dataVar = _vm->_parse->parseVarIndex();
- size = _vm->_parse->parseValExpr();
+ dataVar = _vm->_game->_script->readVarIndex();
+ size = _vm->_game->_script->readValExpr();
evalExpr(0);
- offset = _vm->_parse->getResultInt();
+ offset = _vm->_game->_script->getResultInt();
debugC(2, kDebugFileIO, "Write to file \"%s\" (%d, %d bytes at %d)",
- _vm->_parse->getResultStr(), dataVar, size, offset);
+ _vm->_game->_script->getResultStr(), dataVar, size, offset);
WRITE_VAR(1, 1);
- mode = _vm->_saveLoad->getSaveMode(_vm->_parse->getResultStr());
+ mode = _vm->_saveLoad->getSaveMode(_vm->_game->_script->getResultStr());
if (mode == SaveLoad::kSaveModeSave) {
- if (_vm->_saveLoad->save(_vm->_parse->getResultStr(), dataVar, size, offset))
+ if (_vm->_saveLoad->save(_vm->_game->_script->getResultStr(), dataVar, size, offset))
WRITE_VAR(1, 0);
} else if (mode == SaveLoad::kSaveModeNone)
- warning("Attempted to write to file \"%s\"", _vm->_parse->getResultStr());
+ warning("Attempted to write to file \"%s\"", _vm->_game->_script->getResultStr());
return false;
}
@@ -1445,7 +1441,7 @@ void Inter_v2::o2_loadInfogramesIns(OpGobParams &params) {
int16 varName;
char fileName[20];
- varName = load16();
+ varName = _vm->_game->_script->readInt16();
strncpy0(fileName, GET_VAR_STR(varName), 15);
strcat(fileName, ".INS");
@@ -1457,7 +1453,7 @@ void Inter_v2::o2_playInfogrames(OpGobParams &params) {
int16 varName;
char fileName[20];
- varName = load16();
+ varName = _vm->_game->_script->readInt16();
strncpy0(fileName, GET_VAR_STR(varName), 15);
strcat(fileName, ".DUM");
@@ -1467,13 +1463,13 @@ void Inter_v2::o2_playInfogrames(OpGobParams &params) {
}
void Inter_v2::o2_startInfogrames(OpGobParams &params) {
- load16();
+ _vm->_game->_script->readInt16();
_vm->_sound->infogramesPlay();
}
void Inter_v2::o2_stopInfogrames(OpGobParams &params) {
- load16();
+ _vm->_game->_script->readInt16();
_vm->_sound->infogramesStop();
}
@@ -1487,12 +1483,12 @@ void Inter_v2::o2_stopProtracker(OpGobParams &params) {
}
void Inter_v2::o2_handleGoblins(OpGobParams &params) {
- _vm->_goblin->_gob1NoTurn = VAR(load16()) != 0;
- _vm->_goblin->_gob2NoTurn = VAR(load16()) != 0;
- _vm->_goblin->_gob1RelaxTimeVar = load16();
- _vm->_goblin->_gob2RelaxTimeVar = load16();
- _vm->_goblin->_gob1Busy = VAR(load16()) != 0;
- _vm->_goblin->_gob2Busy = VAR(load16()) != 0;
+ _vm->_goblin->_gob1NoTurn = VAR(_vm->_game->_script->readInt16()) != 0;
+ _vm->_goblin->_gob2NoTurn = VAR(_vm->_game->_script->readInt16()) != 0;
+ _vm->_goblin->_gob1RelaxTimeVar = _vm->_game->_script->readInt16();
+ _vm->_goblin->_gob2RelaxTimeVar = _vm->_game->_script->readInt16();
+ _vm->_goblin->_gob1Busy = VAR(_vm->_game->_script->readInt16()) != 0;
+ _vm->_goblin->_gob2Busy = VAR(_vm->_game->_script->readInt16()) != 0;
_vm->_goblin->handleGoblins();
}
@@ -1510,14 +1506,14 @@ int16 Inter_v2::loadSound(int16 search) {
dataSize = 0;
if (!search) {
- slot = _vm->_parse->parseValExpr();
+ slot = _vm->_game->_script->readValExpr();
if (slot < 0) {
type = SOUND_ADL;
slot = -slot;
}
- id = load16();
+ id = _vm->_game->_script->readInt16();
} else {
- id = load16();
+ id = _vm->_game->_script->readInt16();
for (slot = 0; slot < Sound::kSoundsCount; slot++)
if (_vm->_sound->sampleGetBySlot(slot)->isId(id)) {
@@ -1548,8 +1544,7 @@ int16 Inter_v2::loadSound(int16 search) {
source = SOUND_FILE;
- strncpy0(sndfile, (const char *) _vm->_global->_inter_execPtr, 9);
- _vm->_global->_inter_execPtr += 9;
+ strncpy0(sndfile, _vm->_game->_script->readString(9), 9);
if (type == SOUND_ADL)
strcat(sndfile, ".ADL");
diff --git a/engines/gob/inter_v3.cpp b/engines/gob/inter_v3.cpp
index 4a8bc8f218..8ac9a751b3 100644
--- a/engines/gob/inter_v3.cpp
+++ b/engines/gob/inter_v3.cpp
@@ -32,7 +32,7 @@
#include "gob/dataio.h"
#include "gob/draw.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
namespace Gob {
@@ -74,9 +74,9 @@ bool Inter_v3::o3_getTotTextItemPart(OpFuncParams &params) {
uint32 stringStartVar, stringVar;
bool end;
- totTextItem = load16();
- stringStartVar = _vm->_parse->parseVarIndex();
- part = _vm->_parse->parseValExpr();
+ totTextItem = _vm->_game->_script->readInt16();
+ stringStartVar = _vm->_game->_script->readVarIndex();
+ part = _vm->_game->_script->readValExpr();
stringVar = stringStartVar;
WRITE_VARO_UINT8(stringVar, 0);
diff --git a/engines/gob/inter_v4.cpp b/engines/gob/inter_v4.cpp
index 057f71a227..95e720c988 100644
--- a/engines/gob/inter_v4.cpp
+++ b/engines/gob/inter_v4.cpp
@@ -32,7 +32,7 @@
#include "gob/global.h"
#include "gob/draw.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
#include "gob/videoplayer.h"
#include "gob/sound/sound.h"
@@ -65,13 +65,13 @@ void Inter_v4::o4_initScreen() {
int16 videoMode;
int16 width, height;
- offY = load16();
+ offY = _vm->_game->_script->readInt16();
videoMode = offY & 0xFF;
offY = (offY >> 8) & 0xFF;
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
_vm->_video->clearScreen();
@@ -153,7 +153,7 @@ void Inter_v4::o4_playVmdOrMusic() {
bool close;
evalExpr(0);
- strncpy0(fileName, _vm->_parse->getResultStr(), 127);
+ strncpy0(fileName, _vm->_game->_script->getResultStr(), 127);
// WORKAROUND: The nut rolling animation in the administration center
// in Woodruff is called "noixroul", but the scripts think it's "noixroule".
@@ -161,14 +161,14 @@ void Inter_v4::o4_playVmdOrMusic() {
(!scumm_stricmp(fileName, "noixroule")))
strcpy(fileName, "noixroul");
- x = _vm->_parse->parseValExpr();
- y = _vm->_parse->parseValExpr();
- startFrame = _vm->_parse->parseValExpr();
- lastFrame = _vm->_parse->parseValExpr();
- breakKey = _vm->_parse->parseValExpr();
- flags = _vm->_parse->parseValExpr();
- palStart = _vm->_parse->parseValExpr();
- palEnd = _vm->_parse->parseValExpr();
+ x = _vm->_game->_script->readValExpr();
+ y = _vm->_game->_script->readValExpr();
+ startFrame = _vm->_game->_script->readValExpr();
+ lastFrame = _vm->_game->_script->readValExpr();
+ breakKey = _vm->_game->_script->readValExpr();
+ flags = _vm->_game->_script->readValExpr();
+ palStart = _vm->_game->_script->readValExpr();
+ palEnd = _vm->_game->_script->readValExpr();
palCmd = 1 << (flags & 0x3F);
debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, "
diff --git a/engines/gob/inter_v5.cpp b/engines/gob/inter_v5.cpp
index 4221a56654..bc1d60e318 100644
--- a/engines/gob/inter_v5.cpp
+++ b/engines/gob/inter_v5.cpp
@@ -30,7 +30,7 @@
#include "gob/inter.h"
#include "gob/global.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
#include "gob/draw.h"
namespace Gob {
@@ -96,7 +96,7 @@ void Inter_v5::setupOpcodesGob() {
void Inter_v5::o5_deleteFile() {
evalExpr(0);
- warning("Dynasty Stub: deleteFile \"%s\"", _vm->_parse->getResultStr());
+ warning("Dynasty Stub: deleteFile \"%s\"", _vm->_game->_script->getResultStr());
}
void Inter_v5::o5_initScreen() {
@@ -104,13 +104,13 @@ void Inter_v5::o5_initScreen() {
int16 videoMode;
int16 width, height;
- offY = load16();
+ offY = _vm->_game->_script->readInt16();
videoMode = offY & 0xFF;
offY = (offY >> 8) & 0xFF;
- width = _vm->_parse->parseValExpr();
- height = _vm->_parse->parseValExpr();
+ width = _vm->_game->_script->readValExpr();
+ height = _vm->_game->_script->readValExpr();
warning("initScreen: %d, %d, %d, %d", width, height, offY, videoMode);
@@ -205,18 +205,18 @@ bool Inter_v5::o5_istrlen(OpFuncParams &params) {
int16 len;
uint16 type;
- if (*_vm->_global->_inter_execPtr == 0x80) {
- _vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 0x80) {
+ _vm->_game->_script->skip(1);
- strVar1 = _vm->_parse->parseVarIndex();
- strVar2 = _vm->_parse->parseVarIndex(0, &type);
+ strVar1 = _vm->_game->_script->readVarIndex();
+ strVar2 = _vm->_game->_script->readVarIndex(0, &type);
len = _vm->_draw->stringLength(GET_VARO_STR(strVar1), READ_VARO_UINT16(strVar2));
} else {
- strVar1 = _vm->_parse->parseVarIndex();
- strVar2 = _vm->_parse->parseVarIndex(0, &type);
+ strVar1 = _vm->_game->_script->readVarIndex();
+ strVar2 = _vm->_game->_script->readVarIndex(0, &type);
if (_vm->_global->_language == 10) {
// Extra handling for Japanese strings
@@ -240,15 +240,15 @@ void Inter_v5::o5_spaceShooter(OpGobParams &params) {
if (params.paramCount < 4) {
warning("Space shooter variable counter < 4");
- _vm->_global->_inter_execPtr += params.paramCount * 2;
+ _vm->_game->_script->skip(params.paramCount * 2);
return;
}
- uint32 var1 = load16() * 4;
- uint32 var2 = load16() * 4;
+ uint32 var1 = _vm->_game->_script->readInt16() * 4;
+ uint32 var2 = _vm->_game->_script->readInt16() * 4;
- load16();
- load16();
+ _vm->_game->_script->readInt16();
+ _vm->_game->_script->readInt16();
if (params.extraData != 0) {
WRITE_VARO_UINT32(var1, 2);
@@ -259,12 +259,12 @@ void Inter_v5::o5_spaceShooter(OpGobParams &params) {
return;
}
- _vm->_global->_inter_execPtr += (params.paramCount - 4) * 2;
+ _vm->_game->_script->skip((params.paramCount - 4) * 2);
}
}
void Inter_v5::o5_getSystemCDSpeed(OpGobParams &params) {
- WRITE_VAR_UINT32(load16(), 100); // Fudging 100%
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100%
Video::FontDesc *font;
if ((font = _vm->_util->loadFont("SPEED.LET"))) {
@@ -276,7 +276,7 @@ void Inter_v5::o5_getSystemCDSpeed(OpGobParams &params) {
}
void Inter_v5::o5_getSystemRAM(OpGobParams &params) {
- WRITE_VAR_UINT32(load16(), 100); // Fudging 100%
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100%
Video::FontDesc *font;
if ((font = _vm->_util->loadFont("SPEED.LET"))) {
@@ -288,7 +288,7 @@ void Inter_v5::o5_getSystemRAM(OpGobParams &params) {
}
void Inter_v5::o5_getSystemCPUSpeed(OpGobParams &params) {
- WRITE_VAR_UINT32(load16(), 100); // Fudging 100%
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100%
Video::FontDesc *font;
if ((font = _vm->_util->loadFont("SPEED.LET"))) {
@@ -300,7 +300,7 @@ void Inter_v5::o5_getSystemCPUSpeed(OpGobParams &params) {
}
void Inter_v5::o5_getSystemDrawSpeed(OpGobParams &params) {
- WRITE_VAR_UINT32(load16(), 100); // Fudging 100%
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100%
Video::FontDesc *font;
if ((font = _vm->_util->loadFont("SPEED.LET"))) {
@@ -312,7 +312,7 @@ void Inter_v5::o5_getSystemDrawSpeed(OpGobParams &params) {
}
void Inter_v5::o5_totalSystemSpecs(OpGobParams &params) {
- WRITE_VAR_UINT32(load16(), 100); // Fudging 100%
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100%
Video::FontDesc *font;
if ((font = _vm->_util->loadFont("SPEED.LET"))) {
@@ -376,26 +376,26 @@ void Inter_v5::o5_loadSystemSpecs(OpGobParams &params) {
void Inter_v5::o5_gob92(OpGobParams &params) {
warning("Dynasty Stub: GobFunc 92");
- WRITE_VAR_UINT32(load16(), 0 /* (uint32) ((int32) ((int8) _gob92_1)) */);
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 0 /* (uint32) ((int32) ((int8) _gob92_1)) */);
}
void Inter_v5::o5_gob95(OpGobParams &params) {
warning("Dynasty Stub: GobFunc 95");
- WRITE_VAR_UINT32(load16(), 0 /* (uint32) ((int32) ((int16) speedThrottle4)) */);
- WRITE_VAR_UINT32(load16(), 0 /* (uint32) ((int32) ((int8) speedThrottle3)) */);
- WRITE_VAR_UINT32(load16(), 0 /* (uint32) ((int32) ((int8) speedThrottle2)) */);
- WRITE_VAR_UINT32(load16(), 0 /* (uint32) ((int32) ((int16) speedThrottle1)) */);
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 0 /* (uint32) ((int32) ((int16) speedThrottle4)) */);
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 0 /* (uint32) ((int32) ((int8) speedThrottle3)) */);
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 0 /* (uint32) ((int32) ((int8) speedThrottle2)) */);
+ WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 0 /* (uint32) ((int32) ((int16) speedThrottle1)) */);
}
void Inter_v5::o5_gob96(OpGobParams &params) {
int16 speedThrottle4, speedThrottle1;
byte speedThrottle3, speedThrottle2;
- speedThrottle4 = READ_VAR_UINT16(load16());
- speedThrottle3 = READ_VAR_UINT8(load16());
- speedThrottle2 = READ_VAR_UINT8(load16());
- speedThrottle1 = READ_VAR_UINT16(load16());
+ speedThrottle4 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
+ speedThrottle3 = READ_VAR_UINT8(_vm->_game->_script->readInt16());
+ speedThrottle2 = READ_VAR_UINT8(_vm->_game->_script->readInt16());
+ speedThrottle1 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
warning("Dynasty Stub: GobFunc 96: %d, %d, %d, %d",
speedThrottle4, speedThrottle3, speedThrottle2, speedThrottle1);
@@ -412,10 +412,10 @@ void Inter_v5::o5_gob98(OpGobParams &params) {
}
void Inter_v5::o5_gob100(OpGobParams &params) {
- uint16 var1 = READ_VAR_UINT16(load16());
- uint16 var2 = READ_VAR_UINT16(load16());
- uint16 var3 = READ_VAR_UINT16(load16());
- uint16 var4 = READ_VAR_UINT16(load16());
+ uint16 var1 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
+ uint16 var2 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
+ uint16 var3 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
+ uint16 var4 = READ_VAR_UINT16(_vm->_game->_script->readInt16());
warning("Dynasty Stub: GobFunc 100: %d, %d, %d, %d", var1, var2, var3, var4);
@@ -424,9 +424,9 @@ void Inter_v5::o5_gob100(OpGobParams &params) {
}
void Inter_v5::o5_gob200(OpGobParams &params) {
- uint16 var1 = load16(); // index into the spritesArray
- uint16 var2 = load16();
- uint16 var3 = load16();
+ uint16 var1 = _vm->_game->_script->readUint16(); // index into the spritesArray
+ uint16 var2 = _vm->_game->_script->readUint16();
+ uint16 var3 = _vm->_game->_script->readUint16();
warning("Dynasty Stub: GobFunc 200: %d, %d, %d", var1, var2, var3);
}
diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp
index a37164c283..1fc073d2ff 100644
--- a/engines/gob/inter_v6.cpp
+++ b/engines/gob/inter_v6.cpp
@@ -32,6 +32,7 @@
#include "gob/helper.h"
#include "gob/global.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/parse.h"
#include "gob/draw.h"
#include "gob/sound/sound.h"
@@ -75,20 +76,20 @@ void Inter_v6::o6_totSub() {
int flags;
int i;
- length = *_vm->_global->_inter_execPtr++;
+ length = _vm->_game->_script->readByte();
if ((length & 0x7F) > 13)
error("Length in o2_totSub is greater than 13 (%d)", length);
if (length & 0x80) {
evalExpr(0);
- strcpy(totFile, _vm->_parse->getResultStr());
+ strcpy(totFile, _vm->_game->_script->getResultStr());
} else {
for (i = 0; i < length; i++)
- totFile[i] = (char) *_vm->_global->_inter_execPtr++;
+ totFile[i] = _vm->_game->_script->readChar();
totFile[i] = 0;
}
- flags = *_vm->_global->_inter_execPtr++;
+ flags = _vm->_game->_script->readByte();
if (flags & 0x40)
warning("Urban Stub: o6_totSub(), flags & 0x40");
@@ -109,16 +110,16 @@ void Inter_v6::o6_playVmdOrMusic() {
bool close;
evalExpr(0);
- strncpy0(fileName, _vm->_parse->getResultStr(), 127);
-
- x = _vm->_parse->parseValExpr();
- y = _vm->_parse->parseValExpr();
- startFrame = _vm->_parse->parseValExpr();
- lastFrame = _vm->_parse->parseValExpr();
- breakKey = _vm->_parse->parseValExpr();
- flags = _vm->_parse->parseValExpr();
- palStart = _vm->_parse->parseValExpr();
- palEnd = _vm->_parse->parseValExpr();
+ strncpy0(fileName, _vm->_game->_script->getResultStr(), 127);
+
+ x = _vm->_game->_script->readValExpr();
+ y = _vm->_game->_script->readValExpr();
+ startFrame = _vm->_game->_script->readValExpr();
+ lastFrame = _vm->_game->_script->readValExpr();
+ breakKey = _vm->_game->_script->readValExpr();
+ flags = _vm->_game->_script->readValExpr();
+ palStart = _vm->_game->_script->readValExpr();
+ palEnd = _vm->_game->_script->readValExpr();
palCmd = 1 << (flags & 0x3F);
debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, "
@@ -175,7 +176,7 @@ void Inter_v6::o6_openItk() {
char fileName[32];
evalExpr(0);
- strncpy0(fileName, _vm->_parse->getResultStr(), 27);
+ strncpy0(fileName, _vm->_game->_script->getResultStr(), 27);
if (!strchr(fileName, '.'))
strcat(fileName, ".ITK");
@@ -193,21 +194,21 @@ void Inter_v6::o6_openItk() {
}
bool Inter_v6::o6_loadCursor(OpFuncParams &params) {
- int16 id = load16();
+ int16 id = _vm->_game->_script->readInt16();
if ((id == -1) || (id == -2)) {
char file[10];
if (id == -1) {
for (int i = 0; i < 9; i++)
- file[i] = *_vm->_global->_inter_execPtr++;
+ file[i] = _vm->_game->_script->readChar();
} else
- strncpy(file, GET_VAR_STR(load16()), 10);
+ strncpy(file, GET_VAR_STR(_vm->_game->_script->readInt16()), 10);
file[9] = '\0';
- uint16 start = load16();
- int8 index = (int8) *_vm->_global->_inter_execPtr++;
+ uint16 start = _vm->_game->_script->readUint16();
+ int8 index = _vm->_game->_script->readInt8();
int vmdSlot = _vm->_vidPlayer->slotOpen(file);
@@ -235,7 +236,7 @@ bool Inter_v6::o6_loadCursor(OpFuncParams &params) {
return false;
}
- int8 index = (int8) *_vm->_global->_inter_execPtr++;
+ int8 index = _vm->_game->_script->readInt8();
if ((index * _vm->_draw->_cursorWidth) >= _vm->_draw->_cursorSprites->getWidth())
return false;
@@ -257,19 +258,19 @@ bool Inter_v6::o6_loadCursor(OpFuncParams &params) {
bool Inter_v6::o6_assign(OpFuncParams &params) {
uint16 size, destType;
- int16 dest = _vm->_parse->parseVarIndex(&size, &destType);
+ int16 dest = _vm->_game->_script->readVarIndex(&size, &destType);
if (size != 0) {
int16 src;
- byte *savedPos = _vm->_global->_inter_execPtr;
+ uint32 startPos = _vm->_game->_script->pos();
- src = _vm->_parse->parseVarIndex(&size, 0);
+ src = _vm->_game->_script->readVarIndex(&size, 0);
memcpy(_vm->_inter->_variables->getAddressOff8(dest),
_vm->_inter->_variables->getAddressOff8(src), size * 4);
- _vm->_global->_inter_execPtr = savedPos;
+ _vm->_game->_script->seek(startPos);
evalExpr(&src);
@@ -277,13 +278,13 @@ bool Inter_v6::o6_assign(OpFuncParams &params) {
}
byte loopCount;
- if (*_vm->_global->_inter_execPtr == 98) {
- _vm->_global->_inter_execPtr++;
- loopCount = *_vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 98) {
+ _vm->_game->_script->skip(1);
+ loopCount = _vm->_game->_script->readByte();
for (int i = 0; i < loopCount; i++) {
- uint8 c = *_vm->_global->_inter_execPtr++;
- uint16 n = load16();
+ uint8 c = _vm->_game->_script->readByte();
+ uint16 n = _vm->_game->_script->readUint16();
memset(_vm->_inter->_variables->getAddressOff8(dest), c, n);
@@ -292,9 +293,9 @@ bool Inter_v6::o6_assign(OpFuncParams &params) {
return false;
- } else if (*_vm->_global->_inter_execPtr == 99) {
- _vm->_global->_inter_execPtr++;
- loopCount = *_vm->_global->_inter_execPtr++;
+ } else if (_vm->_game->_script->peekByte() == 99) {
+ _vm->_game->_script->skip(1);
+ loopCount = _vm->_game->_script->readByte();
} else
loopCount = 1;
@@ -305,21 +306,21 @@ bool Inter_v6::o6_assign(OpFuncParams &params) {
switch (destType) {
case TYPE_VAR_INT8:
case TYPE_ARRAY_INT8:
- WRITE_VARO_UINT8(dest + i, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT8(dest + i, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT16:
case TYPE_ARRAY_INT16:
- WRITE_VARO_UINT16(dest + i * 2, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT16(dest + i * 2, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32:
case TYPE_ARRAY_INT32:
- WRITE_VAR_OFFSET(dest + i * 4, _vm->_parse->getResultInt());
+ WRITE_VAR_OFFSET(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_INT32_AS_INT16:
- WRITE_VARO_UINT16(dest + i * 4, _vm->_parse->getResultInt());
+ WRITE_VARO_UINT16(dest + i * 4, _vm->_game->_script->getResultInt());
break;
case TYPE_VAR_STR:
@@ -327,7 +328,7 @@ bool Inter_v6::o6_assign(OpFuncParams &params) {
if (srcType == TYPE_IMM_INT16)
WRITE_VARO_UINT8(dest, result);
else
- WRITE_VARO_STR(dest, _vm->_parse->getResultStr());
+ WRITE_VARO_STR(dest, _vm->_game->_script->getResultStr());
break;
}
}
@@ -349,7 +350,7 @@ bool Inter_v6::o6_palLoad(OpFuncParams &params) {
bool Inter_v6::o6_freeCollision(OpFuncParams &params) {
int16 id;
- id = _vm->_parse->parseValExpr();
+ id = _vm->_game->_script->readValExpr();
switch (id + 5) {
case 0:
@@ -385,17 +386,17 @@ bool Inter_v6::o6_freeCollision(OpFuncParams &params) {
bool Inter_v6::o6_fillRect(OpFuncParams &params) {
int16 destSurf;
- _vm->_draw->_destSurface = destSurf = load16();
+ _vm->_draw->_destSurface = destSurf = _vm->_game->_script->readInt16();
- _vm->_draw->_destSpriteX = _vm->_parse->parseValExpr();
- _vm->_draw->_destSpriteY = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteRight = _vm->_parse->parseValExpr();
- _vm->_draw->_spriteBottom = _vm->_parse->parseValExpr();
+ _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr();
+ _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr();
+ _vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr();
evalExpr(0);
- _vm->_draw->_backColor = _vm->_parse->getResultInt() & 0xFFFF;
- uint16 extraVar = _vm->_parse->getResultInt() >> 16;
+ _vm->_draw->_backColor = _vm->_game->_script->getResultInt() & 0xFFFF;
+ uint16 extraVar = _vm->_game->_script->getResultInt() >> 16;
if (extraVar != 0)
warning("Urban Stub: o6_fillRect(), extraVar = %d", extraVar);
diff --git a/engines/gob/map_v2.cpp b/engines/gob/map_v2.cpp
index db4f2075e1..040285e004 100644
--- a/engines/gob/map_v2.cpp
+++ b/engines/gob/map_v2.cpp
@@ -31,7 +31,7 @@
#include "gob/goblin.h"
#include "gob/inter.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
#include "gob/mult.h"
namespace Gob {
@@ -55,10 +55,10 @@ void Map_v2::loadMapObjects(const char *avjFile) {
uint32 tmpPos;
uint32 passPos;
- var = _vm->_parse->parseVarIndex();
+ var = _vm->_game->_script->readVarIndex();
variables = _vm->_inter->_variables->getAddressOff8(var);
- id = _vm->_inter->load16();
+ id = _vm->_game->_script->readInt16();
if (id == -1) {
_passMap = (int8 *) _vm->_inter->_variables->getAddressOff8(var);
@@ -130,7 +130,7 @@ void Map_v2::loadMapObjects(const char *avjFile) {
for (int i = 0; i < _vm->_goblin->_gobsCount; i++)
loadGoblinStates(mapData, i);
- _vm->_goblin->_soundSlotsCount = _vm->_inter->load16();
+ _vm->_goblin->_soundSlotsCount = _vm->_game->_script->readInt16();
for (int i = 0; i < _vm->_goblin->_soundSlotsCount; i++)
_vm->_goblin->_soundSlots[i] = _vm->_inter->loadSound(1);
diff --git a/engines/gob/map_v4.cpp b/engines/gob/map_v4.cpp
index 858e7972bc..76492eae1b 100644
--- a/engines/gob/map_v4.cpp
+++ b/engines/gob/map_v4.cpp
@@ -31,7 +31,7 @@
#include "gob/goblin.h"
#include "gob/inter.h"
#include "gob/game.h"
-#include "gob/parse.h"
+#include "gob/script.h"
#include "gob/mult.h"
namespace Gob {
@@ -53,10 +53,10 @@ void Map_v4::loadMapObjects(const char *avjFile) {
uint32 tmpPos;
uint32 passPos;
- var = _vm->_parse->parseVarIndex();
+ var = _vm->_game->_script->readVarIndex();
variables = _vm->_inter->_variables->getAddressOff8(var);
- id = _vm->_inter->load16();
+ id = _vm->_game->_script->readInt16();
if (((uint16) id) >= 65520) {
warning("Woodruff Stub: loadMapObjects ID >= 65520");
@@ -146,7 +146,7 @@ void Map_v4::loadMapObjects(const char *avjFile) {
for (int i = 0; i < _vm->_goblin->_gobsCount; i++)
loadGoblinStates(mapData, i);
- _vm->_goblin->_soundSlotsCount = _vm->_inter->load16();
+ _vm->_goblin->_soundSlotsCount = _vm->_game->_script->readInt16();
for (int i = 0; i < _vm->_goblin->_soundSlotsCount; i++)
_vm->_goblin->_soundSlots[i] = _vm->_inter->loadSound(1);
diff --git a/engines/gob/module.mk b/engines/gob/module.mk
index 22a5cd37b9..52ad177f1f 100644
--- a/engines/gob/module.mk
+++ b/engines/gob/module.mk
@@ -1,6 +1,7 @@
MODULE := engines/gob
MODULE_OBJS := \
+ script.o \
dataio.o \
detection.o \
draw.o \
diff --git a/engines/gob/mult.cpp b/engines/gob/mult.cpp
index 1670c26ea5..5aec5ff76e 100644
--- a/engines/gob/mult.cpp
+++ b/engines/gob/mult.cpp
@@ -31,6 +31,7 @@
#include "gob/util.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/palanim.h"
#include "gob/scenery.h"
#include "gob/video.h"
@@ -251,8 +252,6 @@ void Mult::playMult(int16 startFrame, int16 endFrame, char checkEscape,
}
void Mult::drawText(bool &stop, bool &stopNoClear) {
- byte *savedIP;
-
int16 cmd;
for (_index = 0; _index < _multData->textKeysCount; _index++) {
if (_multData->textKeys[_index].frame != _frame)
@@ -265,9 +264,10 @@ void Mult::drawText(bool &stop, bool &stopNoClear) {
stopNoClear = true;
_multData->frameStart = 0;
} else if (cmd == 3) {
+ warning("Mult::drawText, cmd == 3");
stop = false;
- savedIP = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr = _multData->textKeys[_index].script;
+// uint32 startPos = _vm->_game->_script->pos();
+// _vm->_global->_inter_execPtr = _multData->textKeys[_index].script;
}
}
}
diff --git a/engines/gob/mult_v1.cpp b/engines/gob/mult_v1.cpp
index e2c16674c9..6891d443b0 100644
--- a/engines/gob/mult_v1.cpp
+++ b/engines/gob/mult_v1.cpp
@@ -1,4 +1,4 @@
-/* ScummVM - Graphic Adventure Engine
+/* 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
@@ -32,6 +32,7 @@
#include "gob/util.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/inter.h"
#include "gob/scenery.h"
@@ -157,15 +158,14 @@ void Mult_v1::loadMult(int16 resId) {
switch (_multData->sndKeys[i].cmd) {
case 1:
case 4:
- _multData->sndKeys[i].resId =
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _multData->sndKeys[i].resId = _vm->_game->_script->peekUint16();
for (j = 0; j < i; j++) {
if (_multData->sndKeys[i].resId ==
_multData->sndKeys[j].resId) {
_multData->sndKeys[i].soundIndex =
_multData->sndKeys[j].soundIndex;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
break;
}
}
@@ -178,11 +178,11 @@ void Mult_v1::loadMult(int16 resId) {
break;
case 3:
- _vm->_global->_inter_execPtr += 6;
+ _vm->_game->_script->skip(6);
break;
case 5:
- _vm->_global->_inter_execPtr += _multData->sndKeys[i].freq * 2;
+ _vm->_game->_script->skip(_multData->sndKeys[i].freq * 2);
break;
}
}
diff --git a/engines/gob/mult_v2.cpp b/engines/gob/mult_v2.cpp
index 1ee12af899..489e5b0e54 100644
--- a/engines/gob/mult_v2.cpp
+++ b/engines/gob/mult_v2.cpp
@@ -32,9 +32,9 @@
#include "gob/util.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/goblin.h"
#include "gob/inter.h"
-#include "gob/parse.h"
#include "gob/scenery.h"
#include "gob/video.h"
#include "gob/videoplayer.h"
@@ -64,7 +64,7 @@ void Mult_v2::loadMult(int16 resId) {
byte *extData;
bool hasImds;
- index = (resId & 0x8000) ? *_vm->_global->_inter_execPtr++ : 0;
+ index = (resId & 0x8000) ? _vm->_game->_script->readByte() : 0;
resId &= 0x7FFF;
debugC(4, kDebugGameFlow, "Loading mult %d", index);
@@ -206,14 +206,13 @@ void Mult_v2::loadMult(int16 resId) {
switch (_multData->sndKeys[i].cmd) {
case 1:
case 4:
- _multData->sndKeys[i].resId =
- READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ _multData->sndKeys[i].resId = _vm->_game->_script->peekUint16();
for (j = 0; j < i; j++) {
if (_multData->sndKeys[j].resId ==
_multData->sndKeys[i].resId) {
_multData->sndKeys[i].soundIndex =
_multData->sndKeys[j].soundIndex;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
break;
}
}
@@ -226,7 +225,7 @@ void Mult_v2::loadMult(int16 resId) {
}
break;
case 3:
- _vm->_global->_inter_execPtr += 4;
+ _vm->_game->_script->skip(4);
break;
case -1:
@@ -250,11 +249,11 @@ void Mult_v2::loadMult(int16 resId) {
void Mult_v2::loadImds(Common::SeekableReadStream &data) {
int16 size;
- size = _vm->_inter->load16();
- _multData->execPtr = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += size * 2;
+ size = _vm->_game->_script->readInt16();
+ _multData->execPtr = _vm->_game->_script->getData() + _vm->_game->_script->pos();
+ _vm->_game->_script->skip(size * 2);
- if (_vm->_game->_totFileData[0x29] < 51)
+ if (_vm->_game->_script->getData()[0x29] < 51)
return;
size = data.readSint16LE();
@@ -263,12 +262,13 @@ void Mult_v2::loadImds(Common::SeekableReadStream &data) {
data.read(_multData->somepointer10, size * 20);
}
- size = _vm->_inter->load16();
+ size = _vm->_game->_script->readInt16();
if (size <= 0)
return;
_multData->imdFiles = new char[size * 14];
- memcpy(_multData->imdFiles, _vm->_global->_inter_execPtr, size * 14);
+ memcpy(_multData->imdFiles,
+ _vm->_game->_script->getData() + _vm->_game->_script->pos(), size * 14);
// WORKAROUND: The Windows version of Lost in Time has VMD not IMD files,
// but they are still referenced as IMD.
@@ -282,7 +282,7 @@ void Mult_v2::loadImds(Common::SeekableReadStream &data) {
}
}
- _vm->_global->_inter_execPtr += size * 14;
+ _vm->_game->_script->skip(size * 14);
data.seek(2, SEEK_CUR);
for (int i = 0; i < 4; i++) {
_multData->imdKeysCount[i] = data.readSint16LE();
@@ -401,10 +401,10 @@ void Mult_v2::multSub(uint16 multIndex) {
_multData = _multDatas[multIndex];
if (!_multData) {
- _vm->_parse->parseValExpr();
- _vm->_parse->parseValExpr();
- _vm->_parse->parseValExpr();
- _vm->_parse->parseValExpr();
+ _vm->_game->_script->readValExpr();
+ _vm->_game->_script->readValExpr();
+ _vm->_game->_script->readValExpr();
+ _vm->_game->_script->readValExpr();
return;
}
@@ -427,9 +427,9 @@ void Mult_v2::multSub(uint16 multIndex) {
_multData->animObjs[index][0] = flags;
for (int i = 1; i < 4; i++)
- _multData->animObjs[index][i] = _vm->_parse->parseValExpr();
+ _multData->animObjs[index][i] = _vm->_game->_script->readValExpr();
- expr = _vm->_parse->parseValExpr();
+ expr = _vm->_game->_script->readValExpr();
_multData->animKeysFrames[index] = expr;
_multData->animKeysStartFrames[index] = expr;
@@ -871,7 +871,7 @@ void Mult_v2::animate() {
animObj.newBottom =
MAX(animObj.lastBottom, _vm->_scenery->_toRedrawBottom);
- if ((_vm->_game->_totFileData[0x29] > 50) &&
+ if ((_vm->_game->_script->getData()[0x29] > 50) &&
(animObj.newLeft == animObj.lastLeft) &&
(animObj.newTop == animObj.lastTop) &&
(animObj.newRight == animObj.lastRight) &&
diff --git a/engines/gob/parse.cpp b/engines/gob/parse.cpp
index 48442be483..09edc8b66c 100644
--- a/engines/gob/parse.cpp
+++ b/engines/gob/parse.cpp
@@ -29,6 +29,7 @@
#include "gob/parse.h"
#include "gob/global.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/inter.h"
namespace Gob {
@@ -73,7 +74,7 @@ int32 Parse::encodePtr(byte *ptr, int type) {
switch (type) {
case kExecPtr:
- offset = ptr - _vm->_game->_totFileData;
+ offset = _vm->_game->_script->getOffset(ptr);
break;
case kInterVar:
offset = ptr - ((byte *) _vm->_inter->_variables->getAddressOff8(0));
@@ -93,7 +94,7 @@ byte *Parse::decodePtr(int32 n) {
switch (n >> 28) {
case kExecPtr:
- ptr = _vm->_game->_totFileData;
+ ptr = _vm->_game->_script->getData();
break;
case kInterVar:
ptr = (byte *) _vm->_inter->_variables->getAddressOff8(0);
@@ -115,14 +116,14 @@ void Parse::skipExpr(char stopToken) {
num = 0;
while (true) {
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
if ((operation >= 14) && (operation <= OP_FUNC)) {
switch (operation) {
case 14:
- _vm->_global->_inter_execPtr += 4;
- if (*_vm->_global->_inter_execPtr == 97)
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(4);
+ if (_vm->_game->_script->peekByte() == 97)
+ _vm->_game->_script->skip(1);
break;
case OP_LOAD_VAR_INT16:
@@ -130,52 +131,51 @@ void Parse::skipExpr(char stopToken) {
case OP_LOAD_IMM_INT16:
case OP_LOAD_VAR_INT32:
case OP_LOAD_VAR_INT32_AS_INT16:
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
break;
case OP_LOAD_IMM_INT32:
- _vm->_global->_inter_execPtr += 4;
+ _vm->_game->_script->skip(4);
break;
case OP_LOAD_IMM_INT8:
- _vm->_global->_inter_execPtr += 1;
+ _vm->_game->_script->skip(1);
break;
case OP_LOAD_IMM_STR:
- _vm->_global->_inter_execPtr +=
- strlen((char *) _vm->_global->_inter_execPtr) + 1;
+ _vm->_game->_script->skip(strlen(_vm->_game->_script->peekString()) + 1);
break;
case OP_LOAD_VAR_STR:
- _vm->_global->_inter_execPtr += 2;
- if (*_vm->_global->_inter_execPtr == 13) {
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(2);
+ if (_vm->_game->_script->peekByte() == 13) {
+ _vm->_game->_script->skip(1);
skipExpr(OP_END_MARKER);
}
break;
case 15:
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
case OP_ARRAY_INT8:
case OP_ARRAY_INT32:
case OP_ARRAY_INT16:
case OP_ARRAY_STR:
- dimCount = _vm->_global->_inter_execPtr[2];
+ dimCount = _vm->_game->_script->peekByte(2);
// skip header and dimensions
- _vm->_global->_inter_execPtr += 3 + dimCount;
+ _vm->_game->_script->skip(3 + dimCount);
// skip indices
for (dim = 0; dim < dimCount; dim++)
skipExpr(OP_END_MARKER);
- if ((operation == OP_ARRAY_STR) && (*_vm->_global->_inter_execPtr == 13)) {
- _vm->_global->_inter_execPtr++;
+ if ((operation == OP_ARRAY_STR) && (_vm->_game->_script->peekByte() == 13)) {
+ _vm->_game->_script->skip(1);
skipExpr(OP_END_MARKER);
}
break;
case OP_FUNC:
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
skipExpr(OP_END_EXPR);
}
continue;
@@ -207,11 +207,11 @@ void Parse::printExpr(char stopToken) {
// Expression printing disabled by default
return;
- byte *savedPos = _vm->_global->_inter_execPtr;
+ int32 savedPos = _vm->_game->_script->pos();
printExpr_internal(stopToken);
// restore IP to start of expression
- _vm->_global->_inter_execPtr = savedPos;
+ _vm->_game->_script->seek(savedPos);
}
void Parse::printExpr_internal(char stopToken) {
@@ -224,48 +224,45 @@ void Parse::printExpr_internal(char stopToken) {
num = 0;
while (true) {
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
if ((operation >= OP_ARRAY_INT8) && (operation <= OP_FUNC)) {
// operands
switch (operation) {
case OP_LOAD_VAR_INT16: // int16 variable load
- debugN(5, "var16_%d", _vm->_inter->load16());
+ debugN(5, "var16_%d", _vm->_game->_script->readUint16());
break;
case OP_LOAD_VAR_INT8: // int8 variable load:
- debugN(5, "var8_%d", _vm->_inter->load16());
+ debugN(5, "var8_%d", _vm->_game->_script->readUint16());
break;
case OP_LOAD_IMM_INT32: // int32/uint32 immediate
- debugN(5, "%d", READ_LE_UINT32(_vm->_global->_inter_execPtr));
- _vm->_global->_inter_execPtr += 4;
+ debugN(5, "%d", _vm->_game->_script->readInt32());
break;
case OP_LOAD_IMM_INT16: // int16 immediate
- debugN(5, "%d", _vm->_inter->load16());
+ debugN(5, "%d", _vm->_game->_script->readInt16());
break;
case OP_LOAD_IMM_INT8: // int8 immediate
- debugN(5, "%d", (int8) *_vm->_global->_inter_execPtr++);
+ debugN(5, "%d", _vm->_game->_script->readInt8());
break;
case OP_LOAD_IMM_STR: // string immediate
- debugN(5, "\42%s\42", _vm->_global->_inter_execPtr);
- _vm->_global->_inter_execPtr +=
- strlen((char *) _vm->_global->_inter_execPtr) + 1;
+ debugN(5, "\42%s\42", _vm->_game->_script->readString());
break;
case OP_LOAD_VAR_INT32:
case OP_LOAD_VAR_INT32_AS_INT16:
- debugN(5, "var_%d", _vm->_inter->load16());
+ debugN(5, "var_%d", _vm->_game->_script->readUint16());
break;
case OP_LOAD_VAR_STR: // string variable load
- debugN(5, "(&var_%d)", _vm->_inter->load16());
- if (*_vm->_global->_inter_execPtr == 13) {
- _vm->_global->_inter_execPtr++;
+ debugN(5, "(&var_%d)", _vm->_game->_script->readUint16());
+ if (_vm->_game->_script->peekByte() == 13) {
+ _vm->_game->_script->skip(1);
debugN(5, "{");
printExpr_internal(OP_END_MARKER); // this also prints the closing }
}
@@ -279,10 +276,10 @@ void Parse::printExpr_internal(char stopToken) {
if (operation == OP_ARRAY_STR)
debugN(5, "(&");
- debugN(5, "var_%d[", _vm->_inter->load16());
- dimCount = *_vm->_global->_inter_execPtr++;
- arrDesc = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += dimCount;
+ debugN(5, "var_%d[", _vm->_game->_script->readInt16());
+ dimCount = _vm->_game->_script->readByte();
+ arrDesc = _vm->_game->_script->getData() + _vm->_game->_script->pos();
+ _vm->_game->_script->skip(dimCount);
for (dim = 0; dim < dimCount; dim++) {
printExpr_internal(OP_END_MARKER);
debugN(5, " of %d", (int16) arrDesc[dim]);
@@ -293,15 +290,15 @@ void Parse::printExpr_internal(char stopToken) {
if (operation == OP_ARRAY_STR)
debugN(5, ")");
- if ((operation == OP_ARRAY_STR) && (*_vm->_global->_inter_execPtr == 13)) {
- _vm->_global->_inter_execPtr++;
+ if ((operation == OP_ARRAY_STR) && (_vm->_game->_script->peekByte() == 13)) {
+ _vm->_game->_script->skip(1);
debugN(5, "{");
printExpr_internal(OP_END_MARKER); // this also prints the closing }
}
break;
case OP_FUNC: // function
- func = *_vm->_global->_inter_execPtr++;
+ func = _vm->_game->_script->readByte();
if (func == FUNC_SQR)
debugN(5, "sqr(");
else if (func == FUNC_RAND)
@@ -443,16 +440,16 @@ void Parse::printVarIndex() {
int16 operation;
int16 temp;
- byte *pos = _vm->_global->_inter_execPtr;
+ int32 pos = _vm->_game->_script->pos();
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
switch (operation) {
case OP_LOAD_VAR_INT32:
case OP_LOAD_VAR_STR:
- temp = _vm->_inter->load16() * 4;
+ temp = _vm->_game->_script->readUint16() * 4;
debugN(5, "&var_%d", temp);
- if ((operation == OP_LOAD_VAR_STR) && (*_vm->_global->_inter_execPtr == 13)) {
- _vm->_global->_inter_execPtr++;
+ if ((operation == OP_LOAD_VAR_STR) && (_vm->_game->_script->peekByte() == 13)) {
+ _vm->_game->_script->skip(1);
debugN(5, "+");
printExpr(OP_END_MARKER);
}
@@ -460,10 +457,10 @@ void Parse::printVarIndex() {
case OP_ARRAY_INT32:
case OP_ARRAY_STR:
- debugN(5, "&var_%d[", _vm->_inter->load16());
- dimCount = *_vm->_global->_inter_execPtr++;
- arrDesc = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += dimCount;
+ debugN(5, "&var_%d[", _vm->_game->_script->readUint16());
+ dimCount = _vm->_game->_script->readByte();
+ arrDesc = _vm->_game->_script->getData() + _vm->_game->_script->pos();
+ _vm->_game->_script->skip(dimCount);
for (dim = 0; dim < dimCount; dim++) {
printExpr(OP_END_MARKER);
debugN(5, " of %d", (int16) arrDesc[dim]);
@@ -472,8 +469,8 @@ void Parse::printVarIndex() {
}
debugN(5, "]");
- if ((operation == OP_ARRAY_STR) && (*_vm->_global->_inter_execPtr == 13)) {
- _vm->_global->_inter_execPtr++;
+ if ((operation == OP_ARRAY_STR) && (_vm->_game->_script->peekByte() == 13)) {
+ _vm->_game->_script->skip(1);
debugN(5, "+");
printExpr(OP_END_MARKER);
}
@@ -484,7 +481,8 @@ void Parse::printVarIndex() {
break;
}
debugN(5, "\n");
- _vm->_global->_inter_execPtr = pos;
+
+ _vm->_game->_script->seek(pos);
return;
}
@@ -510,46 +508,46 @@ bool Parse::getVarBase(uint32 &varBase, bool mindStop,
varBase = 0;
- byte operation = *_vm->_global->_inter_execPtr;
+ byte operation = _vm->_game->_script->peekByte();
while ((operation == 14) || (operation == 15)) {
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
if (operation == 14) {
// Add a direct offset
- varBase += _vm->_inter->load16() * 4;
+ varBase += _vm->_game->_script->readInt16() * 4;
if (size)
- *size = READ_LE_UINT16(_vm->_global->_inter_execPtr);
+ *size = _vm->_game->_script->peekUint16();
if (type)
*type = 14;
- _vm->_global->_inter_execPtr += 2;
+ _vm->_game->_script->skip(2);
debugC(2, kDebugParser, "varBase: %d, by %d", varBase, operation);
- if (*_vm->_global->_inter_execPtr != 97) {
+ if (_vm->_game->_script->peekByte() != 97) {
if (mindStop)
return true;
} else
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
} else if (operation == 15) {
// Add an offset from an array
- varBase += _vm->_inter->load16() * 4;
+ varBase += _vm->_game->_script->readInt16() * 4;
- uint16 offset1 = _vm->_inter->load16();
+ uint16 offset1 = _vm->_game->_script->readUint16();
if (size)
*size = offset1;
if (type)
*type = 15;
- uint8 dimCount = *_vm->_global->_inter_execPtr++;
- byte *dimArray = _vm->_global->_inter_execPtr;
+ uint8 dimCount = _vm->_game->_script->readByte();
+ byte *dimArray = _vm->_game->_script->getData() + _vm->_game->_script->pos();
- _vm->_global->_inter_execPtr += dimCount;
+ _vm->_game->_script->skip(dimCount);
uint16 offset2 = 0;
for (int i = 0; i < dimCount; i++) {
@@ -562,14 +560,14 @@ bool Parse::getVarBase(uint32 &varBase, bool mindStop,
debugC(2, kDebugParser, "varBase: %d, by %d", varBase, operation);
- if (*_vm->_global->_inter_execPtr != 97) {
+ if (_vm->_game->_script->peekByte() != 97) {
if (mindStop)
return true;
} else
- _vm->_global->_inter_execPtr++;
+ _vm->_game->_script->skip(1);
}
- operation = *_vm->_global->_inter_execPtr;
+ operation = _vm->_game->_script->peekByte();
}
return false;
@@ -589,7 +587,7 @@ int16 Parse::parseVarIndex(uint16 *size, uint16 *type) {
if (getVarBase(varBase, true, size, type))
return varBase;
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
if (size)
*size = 0;
@@ -602,10 +600,10 @@ int16 Parse::parseVarIndex(uint16 *size, uint16 *type) {
case OP_ARRAY_INT32:
case OP_ARRAY_INT16:
case OP_ARRAY_STR:
- temp = _vm->_inter->load16();
- dimCount = *_vm->_global->_inter_execPtr++;
- arrDesc = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += dimCount;
+ temp = _vm->_game->_script->readInt16();
+ dimCount = _vm->_game->_script->readByte();
+ arrDesc = _vm->_game->_script->getData() + _vm->_game->_script->pos();
+ _vm->_game->_script->skip(dimCount);
offset = 0;
for (dim = 0; dim < dimCount; dim++) {
temp2 = parseValExpr(OP_END_MARKER);
@@ -619,26 +617,25 @@ int16 Parse::parseVarIndex(uint16 *size, uint16 *type) {
return varBase + (temp + offset) * 2;
temp *= 4;
offset *= 4;
- if (*_vm->_global->_inter_execPtr == 13) {
- _vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 13) {
+ _vm->_game->_script->skip(1);
temp += parseValExpr(OP_END_MARKER);
}
return varBase + offset * _vm->_global->_inter_animDataSize + temp;
case OP_LOAD_VAR_INT16:
- return varBase + _vm->_inter->load16() * 2;
+ return varBase + _vm->_game->_script->readInt16() * 2;
case OP_LOAD_VAR_INT8:
- return varBase + _vm->_inter->load16();
+ return varBase + _vm->_game->_script->readInt16();
case OP_LOAD_VAR_INT32:
case OP_LOAD_VAR_INT32_AS_INT16:
case OP_LOAD_VAR_STR:
- temp = _vm->_inter->load16() * 4;
- debugC(5, kDebugParser, "oper = %d",
- (int16) *_vm->_global->_inter_execPtr);
- if ((operation == OP_LOAD_VAR_STR) && (*_vm->_global->_inter_execPtr == 13)) {
- _vm->_global->_inter_execPtr++;
+ temp = _vm->_game->_script->readInt16() * 4;
+ debugC(5, kDebugParser, "oper = %d", _vm->_game->_script->peekInt16());
+ if ((operation == OP_LOAD_VAR_STR) && (_vm->_game->_script->peekByte() == 13)) {
+ _vm->_game->_script->skip(1);
val = parseValExpr(OP_END_MARKER);
temp += val;
debugC(5, kDebugParser, "parse subscript = %d", val);
@@ -674,10 +671,10 @@ void Parse::loadValue(byte operation, uint32 varBase, const StackFrame &stackFra
case OP_ARRAY_INT16:
case OP_ARRAY_STR:
*stackFrame.opers = (operation == OP_ARRAY_STR) ? OP_LOAD_IMM_STR : OP_LOAD_IMM_INT16;
- temp = _vm->_inter->load16();
- dimCount = *_vm->_global->_inter_execPtr++;
- arrDescPtr = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += dimCount;
+ temp = _vm->_game->_script->readInt16();
+ dimCount = _vm->_game->_script->readByte();
+ arrDescPtr = _vm->_game->_script->getData() + _vm->_game->_script->pos();
+ _vm->_game->_script->skip(dimCount);
offset = 0;
for (dim = 0; dim < dimCount; dim++) {
temp2 = parseValExpr(OP_END_MARKER);
@@ -693,8 +690,8 @@ void Parse::loadValue(byte operation, uint32 varBase, const StackFrame &stackFra
*stackFrame.values = encodePtr(_vm->_inter->_variables->getAddressOff8(
varBase + temp * 4 + offset * _vm->_global->_inter_animDataSize * 4),
kInterVar);
- if (*_vm->_global->_inter_execPtr == 13) {
- _vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 13) {
+ _vm->_game->_script->skip(1);
temp2 = parseValExpr(OP_END_MARKER);
*stackFrame.opers = OP_LOAD_IMM_INT16;
*stackFrame.values = READ_VARO_UINT8(varBase + temp * 4 +
@@ -705,53 +702,50 @@ void Parse::loadValue(byte operation, uint32 varBase, const StackFrame &stackFra
case OP_LOAD_VAR_INT16:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = (int16) READ_VARO_UINT16(varBase + _vm->_inter->load16() * 2);
+ *stackFrame.values = (int16) READ_VARO_UINT16(varBase + _vm->_game->_script->readInt16() * 2);
break;
case OP_LOAD_VAR_INT8:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = (int8) READ_VARO_UINT8(varBase + _vm->_inter->load16());
+ *stackFrame.values = (int8) READ_VARO_UINT8(varBase + _vm->_game->_script->readInt16());
break;
case OP_LOAD_IMM_INT32:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = READ_LE_UINT32(varBase + _vm->_global->_inter_execPtr);
- _vm->_global->_inter_execPtr += 4;
+ *stackFrame.values = _vm->_game->_script->readInt32();
break;
case OP_LOAD_IMM_INT16:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = _vm->_inter->load16();
+ *stackFrame.values = _vm->_game->_script->readInt16();
break;
case OP_LOAD_IMM_INT8:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = (int8) *_vm->_global->_inter_execPtr++;
+ *stackFrame.values = _vm->_game->_script->readInt8();
break;
case OP_LOAD_IMM_STR:
*stackFrame.opers = OP_LOAD_IMM_STR;
- *stackFrame.values = encodePtr(_vm->_global->_inter_execPtr, kExecPtr);
- _vm->_global->_inter_execPtr +=
- strlen((char *) _vm->_global->_inter_execPtr) + 1;
+ *stackFrame.values = encodePtr((byte *) _vm->_game->_script->readString(), kExecPtr);
break;
case OP_LOAD_VAR_INT32:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = READ_VARO_UINT32(varBase + _vm->_inter->load16() * 4);
+ *stackFrame.values = READ_VARO_UINT32(varBase + _vm->_game->_script->readInt16() * 4);
break;
case OP_LOAD_VAR_INT32_AS_INT16:
*stackFrame.opers = OP_LOAD_IMM_INT16;
- *stackFrame.values = (int16) READ_VARO_UINT16(varBase + _vm->_inter->load16() * 4);
+ *stackFrame.values = (int16) READ_VARO_UINT16(varBase + _vm->_game->_script->readInt16() * 4);
break;
case OP_LOAD_VAR_STR:
*stackFrame.opers = OP_LOAD_IMM_STR;
- temp = _vm->_inter->load16() * 4;
+ temp = _vm->_game->_script->readInt16() * 4;
*stackFrame.values = encodePtr(_vm->_inter->_variables->getAddressOff8(varBase + temp), kInterVar);
- if (*_vm->_global->_inter_execPtr == 13) {
- _vm->_global->_inter_execPtr++;
+ if (_vm->_game->_script->peekByte() == 13) {
+ _vm->_game->_script->skip(1);
temp += parseValExpr(OP_END_MARKER);
*stackFrame.opers = OP_LOAD_IMM_INT16;
*stackFrame.values = READ_VARO_UINT8(varBase + temp);
@@ -759,7 +753,7 @@ void Parse::loadValue(byte operation, uint32 varBase, const StackFrame &stackFra
break;
case OP_FUNC:
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
parseExpr(OP_END_EXPR, 0);
switch (operation) {
@@ -1017,7 +1011,7 @@ int16 Parse::parseExpr(byte stopToken, byte *type) {
stackFrame.push();
- operation = *_vm->_global->_inter_execPtr++;
+ operation = _vm->_game->_script->readByte();
if ((operation >= OP_ARRAY_INT8) && (operation <= OP_FUNC)) {
loadValue(operation, varBase, stackFrame);
@@ -1088,7 +1082,7 @@ int16 Parse::parseExpr(byte stopToken, byte *type) {
} else {
skipExpr(stopToken);
}
- operation = _vm->_global->_inter_execPtr[-1];
+ operation = _vm->_game->_script->peekByte(-1);
if ((stackFrame.pos > 0) && (stackFrame.opers[-1] == OP_NOT)) {
if (stackFrame.opers[0] == GOB_FALSE)
stackFrame.opers[-1] = GOB_TRUE;
diff --git a/engines/gob/scenery.cpp b/engines/gob/scenery.cpp
index 71750509b4..4c538aa714 100644
--- a/engines/gob/scenery.cpp
+++ b/engines/gob/scenery.cpp
@@ -31,6 +31,7 @@
#include "gob/global.h"
#include "gob/draw.h"
#include "gob/game.h"
+#include "gob/script.h"
#include "gob/inter.h"
#include "gob/map.h"
#include "gob/videoplayer.h"
@@ -107,18 +108,18 @@ int16 Scenery::loadStatic(char search) {
_vm->_inter->evalExpr(&sceneryIndex);
- size = _vm->_inter->load16();
- backsPtr = (int16 *) _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += size * 2;
- picsCount = _vm->_inter->load16();
- resId = _vm->_inter->load16();
+ size = _vm->_game->_script->readInt16();
+ backsPtr = (int16 *) (_vm->_game->_script->getData() + _vm->_game->_script->pos());
+ _vm->_game->_script->skip(size * 2);
+ picsCount = _vm->_game->_script->readInt16();
+ resId = _vm->_game->_script->readInt16();
if (search) {
int i;
for (i = 0; i < 10; i++) {
if ((_staticPictCount[i] != -1) && (_staticResId[i] == resId)) {
- _vm->_global->_inter_execPtr += 8 * _staticPictCount[i];
+ _vm->_game->_script->skip(8 * _staticPictCount[i]);
return i;
}
@@ -167,13 +168,13 @@ int16 Scenery::loadStatic(char search) {
ptr->piecesCount = new uint32[picsCount];
for (int i = 0; i < picsCount; i++) {
- int16 pictDescId = _vm->_inter->load16();
+ int16 pictDescId = _vm->_game->_script->readInt16();
loadPieces(pictDescId, ptr->pieces[i], ptr->piecesCount[i]);
- width = _vm->_inter->load16();
- height = _vm->_inter->load16();
- sprResId = _vm->_inter->load16();
+ width = _vm->_game->_script->readInt16();
+ height = _vm->_game->_script->readInt16();
+ sprResId = _vm->_game->_script->readInt16();
for (sprIndex = 0; sprIndex < 20; sprIndex++) {
if (_spriteResId[sprIndex] == sprResId)
break;
@@ -433,13 +434,13 @@ int16 Scenery::loadAnim(char search) {
extData = 0;
_vm->_inter->evalExpr(&sceneryIndex);
- picsCount = _vm->_inter->load16();
- resId = _vm->_inter->load16();
+ picsCount = _vm->_game->_script->readInt16();
+ resId = _vm->_game->_script->readInt16();
if (search) {
for (i = 0; i < 10; i++) {
if ((_animPictCount[i] != 0) && (_animResId[i] == resId)) {
- _vm->_global->_inter_execPtr += 8 * _animPictCount[i];
+ _vm->_game->_script->skip(8 * _animPictCount[i]);
return i;
}
@@ -502,13 +503,13 @@ int16 Scenery::loadAnim(char search) {
ptr->piecesCount = new uint32[picsCount];
for (i = 0; i < picsCount; i++) {
- int16 pictDescId = _vm->_inter->load16();
+ int16 pictDescId = _vm->_game->_script->readInt16();
loadPieces(pictDescId, ptr->pieces[i], ptr->piecesCount[i]);
- width = _vm->_inter->load16();
- height = _vm->_inter->load16();
- sprResId = _vm->_inter->load16();
+ width = _vm->_game->_script->readInt16();
+ height = _vm->_game->_script->readInt16();
+ sprResId = _vm->_game->_script->readInt16();
for (sprIndex = 0; sprIndex < 20; sprIndex++)
if (_spriteResId[sprIndex] == sprResId)
break;
diff --git a/engines/gob/script.cpp b/engines/gob/script.cpp
new file mode 100644
index 0000000000..f731ed33e9
--- /dev/null
+++ b/engines/gob/script.cpp
@@ -0,0 +1,361 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/util.h"
+#include "common/endian.h"
+
+#include "gob/gob.h"
+#include "gob/script.h"
+#include "gob/dataio.h"
+#include "gob/parse.h"
+
+namespace Gob {
+
+Script::Script(GobEngine *vm) : _vm(vm) {
+ _parser = new Parse(vm);
+
+ _finished = true;
+
+ _totData = 0;
+
+ _totSize = 0;
+
+ _totPtr = 0;
+
+ _lomHandle = -1;
+}
+
+Script::~Script() {
+ unload();
+
+ delete _parser;
+}
+
+uint32 Script::read(byte *data, uint32 size) {
+ uint32 toRead = MIN<uint32>(size, _totSize - (_totPtr - _totData));
+
+ memcpy(data, _totPtr, toRead);
+ _totPtr += toRead;
+
+ return toRead;
+}
+
+uint32 Script::peek(byte *data, uint32 size, int32 offset) {
+ int32 totOffset = ((_totPtr + offset) - _totData);
+
+ if (totOffset < 0)
+ return 0;
+ if (((uint32) totOffset) >= _totSize)
+ return 0;
+
+ uint32 toPeek = MIN<uint32>(size, _totSize - totOffset);
+
+ memcpy(data, _totPtr + offset, toPeek);
+
+ return toPeek;
+}
+
+int32 Script::pos() const {
+ if (!_totData)
+ return -1;
+
+ return _totPtr - _totData;
+}
+
+int32 Script::getSize() const {
+ if (!_totData)
+ return -1;
+
+ return _totSize;
+}
+
+bool Script::seek(int32 offset, int whence) {
+ if (!_totData)
+ return false;
+
+ if (whence == SEEK_CUR)
+ offset += pos();
+ else if (whence == SEEK_END)
+ offset += _totSize;
+
+ if ((offset < 0) || (((uint32) offset) >= _totSize))
+ return false;
+
+ _finished = false;
+
+ _totPtr = _totData + offset;
+
+ return true;
+}
+
+bool Script::skip(uint32 offset) {
+ return seek(offset, SEEK_CUR);
+}
+
+uint32 Script::getOffset(byte *ptr) {
+ if (!_totData)
+ return 0;
+
+ return ptr - _totData;
+}
+
+byte *Script::getData() {
+ return _totData;
+}
+
+byte Script::readByte() {
+ byte v;
+
+ read(&v, 1);
+
+ return v;
+}
+
+char Script::readChar() {
+ return (char) readByte();
+}
+
+uint8 Script::readUint8() {
+ return (uint8) readByte();
+}
+
+uint16 Script::readUint16() {
+ byte v[2];
+
+ read(v, 2);
+
+ return READ_LE_UINT16(v);
+}
+
+uint32 Script::readUint32() {
+ byte v[4];
+
+ read(v, 4);
+
+ return READ_LE_UINT32(v);
+}
+
+int8 Script::readInt8() {
+ return (int8) readByte();
+}
+
+int16 Script::readInt16() {
+ return (int16) readUint16();
+}
+
+int32 Script::readInt32() {
+ return (int32) readUint32();
+}
+
+char *Script::readString(int32 length) {
+ if (length < 0) {
+ length = 0;
+ while (_totPtr[length++] != '\0');
+ }
+
+ char *string = (char *) _totPtr;
+
+ _totPtr += length;
+
+ return string;
+}
+
+byte Script::peekByte(int32 offset) {
+ byte v;
+
+ peek(&v, 1, offset);
+
+ return v;
+}
+
+char Script::peekChar(int32 offset) {
+ return (char) peekByte(offset);
+}
+
+uint8 Script::peekUint8(int32 offset) {
+ return (uint8) peekByte(offset);
+}
+
+uint16 Script::peekUint16(int32 offset) {
+ byte v[2];
+
+ peek(v, 2, offset);
+
+ return READ_LE_UINT16(v);
+}
+
+uint32 Script::peekUint32(int32 offset) {
+ byte v[4];
+
+ peek(v, 4, offset);
+
+ return READ_LE_UINT32(v);
+}
+
+int8 Script::peekInt8(int32 offset) {
+ return (int8) peekByte(offset);
+}
+
+int16 Script::peekInt16(int32 offset) {
+ return (int16) peekUint16(offset);
+}
+
+int32 Script::peekInt32(int32 offset) {
+ return (int32) peekUint32(offset);
+}
+
+char *Script::peekString(int32 offset) {
+ return (char *) (_totPtr + offset);
+}
+
+int16 Script::readVarIndex(uint16 *size, uint16 *type) {
+ return _parser->parseVarIndex(size, type);
+}
+
+int16 Script::readValExpr(byte stopToken) {
+ return _parser->parseValExpr(stopToken);
+}
+
+int16 Script::readExpr(byte stopToken, byte *type) {
+ return _parser->parseExpr(stopToken, type);
+}
+
+void Script::skipExpr(char stopToken) {
+ _parser->skipExpr(stopToken);
+}
+
+int32 Script::getResultInt() {
+ return _parser->getResultInt();
+}
+
+char *Script::getResultStr() {
+ return _parser->getResultStr();
+}
+
+bool Script::load(const char *fileName) {
+ unload();
+
+ _finished = false;
+
+ bool lom = false;
+
+ Common::String *fileBase;
+
+ char *dot;
+ if ((dot = strrchr(fileName, '.'))) {
+ fileBase = new Common::String(fileName, dot);
+
+ if (!scumm_stricmp(dot + 1, "LOM"))
+ lom = true;
+ } else
+ fileBase = new Common::String(fileName);
+
+ _totFile = *fileBase + (lom ? ".lom" : ".tot");
+
+ delete fileBase;
+
+ if (_vm->_dataIO->existData(_totFile.c_str())) {
+ if (lom) {
+ if (!loadLOM(_totFile)) {
+ unload();
+ return false;
+ }
+ } else {
+ if (!loadTOT(_totFile)) {
+ unload();
+ return false;
+ }
+ }
+ } else
+ return false;
+
+ return true;
+}
+
+bool Script::loadTOT(const Common::String &fileName) {
+ _totSize = _vm->_dataIO->getDataSize(_totFile.c_str());
+ _totData = _vm->_dataIO->getData(_totFile.c_str());
+
+ return (_totData != 0);
+}
+
+bool Script::loadLOM(const Common::String &fileName) {
+ warning("Urban Stub: loadLOM %s", _totFile.c_str());
+
+ _lomHandle = _vm->_dataIO->openData(_totFile.c_str());
+
+ DataStream *stream = _vm->_dataIO->openAsStream(_lomHandle);
+
+ stream->seek(48);
+ _totSize = stream->readUint32LE();
+ stream->seek(0);
+
+ _totData = new byte[_totSize];
+ stream->read(_totData, _totSize);
+
+ delete stream;
+
+ return true;
+}
+
+void Script::unload() {
+ unloadTOT();
+}
+
+void Script::unloadTOT() {
+ if (_lomHandle >= 0)
+ _vm->_dataIO->closeData(_lomHandle);
+
+ delete[] _totData;
+
+ _totData = 0;
+ _totSize = 0;
+ _totPtr = 0;
+ _lomHandle = -1;
+ _totFile.clear();
+
+ _finished = true;
+}
+
+bool Script::isLoaded() const {
+ return _totData != 0;
+}
+
+void Script::setFinished(bool finished) {
+ _finished = finished;
+}
+
+bool Script::isFinished() const {
+ return _finished;
+}
+
+void Script::cuckoo(byte *totData, uint32 totSize) {
+ _finished = false;
+ _totData = totData;
+ _totPtr = _totData;
+ _totSize = totSize;
+}
+
+} // End of namespace Gob
diff --git a/engines/gob/script.h b/engines/gob/script.h
new file mode 100644
index 0000000000..c88d284e82
--- /dev/null
+++ b/engines/gob/script.h
@@ -0,0 +1,126 @@
+/* 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.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef GOB_SCRIPT_H
+#define GOB_SCRIPT_H
+
+#include "common/str.h"
+
+namespace Gob {
+
+class GobEngine;
+
+class Script {
+public:
+ Script(GobEngine *vm);
+ ~Script();
+
+ uint32 read(byte *data, uint32 size);
+ uint32 peek(byte *data, uint32 size, int32 offset = 0);
+
+ byte readByte();
+ char readChar();
+ uint8 readUint8();
+ uint16 readUint16();
+ uint32 readUint32();
+ int8 readInt8();
+ int16 readInt16();
+ int32 readInt32();
+
+ char *readString(int32 length = -1);
+
+ byte peekByte(int32 offset = 0);
+ char peekChar(int32 offset = 0);
+ uint8 peekUint8(int32 offset = 0);
+ uint16 peekUint16(int32 offset = 0);
+ uint32 peekUint32(int32 offset = 0);
+ int8 peekInt8(int32 offset = 0);
+ int16 peekInt16(int32 offset = 0);
+ int32 peekInt32(int32 offset = 0);
+
+ char *peekString(int32 offset = 0);
+
+ int16 readVarIndex(uint16 *size = 0, uint16 *type = 0);
+ int16 readValExpr(byte stopToken = 99);
+ int16 readExpr(byte stopToken, byte *type);
+ void skipExpr(char stopToken);
+
+ int32 getResultInt();
+ char *getResultStr();
+
+ int32 pos() const;
+ int32 getSize() const;
+ bool seek(int32 offset, int whence = SEEK_SET);
+ bool skip(uint32 offset);
+
+ uint32 getOffset(byte *ptr);
+ byte *getData();
+
+ bool load(const char *fileName);
+
+ void unload();
+
+ bool isLoaded() const;
+
+ void setFinished(bool finished);
+ bool isFinished() const;
+
+ void cuckoo(byte *totData, uint32 totSize);
+
+/* byte *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize = 0);
+ byte *loadTotResource(int16 id, int16 *dataSize = 0, int16 *width = 0, int16 *height = 0);
+
+ byte *loadLocTexts(int32 *dataSize = 0);
+ int32 loadTotFile(const char *path);
+ void loadExtTable(void);
+ void loadImFile(void);
+
+ int16 openLocTextFile(char *locTextFile, int language);*/
+
+private:
+ GobEngine *_vm;
+ Parse *_parser;
+
+ bool _finished;
+
+ Common::String _totFile;
+
+ byte *_totData;
+
+ uint32 _totSize;
+
+ byte *_totPtr;
+
+ int16 _lomHandle;
+
+ bool loadTOT(const Common::String &fileName);
+ bool loadLOM(const Common::String &fileName);
+
+ void unloadTOT();
+};
+
+} // End of namespace Gob
+
+#endif // GOB_SCRIPT_H