aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2007-04-15 14:38:02 +0000
committerJohannes Schickel2007-04-15 14:38:02 +0000
commitb9443dfb60e533d614c4914dfabb4e75e45cdf38 (patch)
tree66bef48dd8ccea80d14c07e2f4646aa0ff5c9fc0
parent5668e15b2efb2aa9ab5bff3cf6b257a3986602ff (diff)
downloadscummvm-rg350-b9443dfb60e533d614c4914dfabb4e75e45cdf38.tar.gz
scummvm-rg350-b9443dfb60e533d614c4914dfabb4e75e45cdf38.tar.bz2
scummvm-rg350-b9443dfb60e533d614c4914dfabb4e75e45cdf38.zip
More cleanup.
svn-id: r26502
-rw-r--r--engines/kyra/kyra.cpp15
-rw-r--r--engines/kyra/script.cpp55
-rw-r--r--engines/kyra/script.h12
-rw-r--r--engines/kyra/script_v1.cpp4
4 files changed, 44 insertions, 42 deletions
diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp
index 448e32f4ef..8092f405ef 100644
--- a/engines/kyra/kyra.cpp
+++ b/engines/kyra/kyra.cpp
@@ -505,21 +505,20 @@ void KyraEngine::startup() {
_animator->initAnimStateList();
setCharactersInDefaultScene();
- if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData)) {
+ if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData))
error("Could not load \"_STARTUP.EMC\" script");
- }
_scriptInterpreter->initScript(_scriptMain, _npcScriptData);
- if (!_scriptInterpreter->startScript(_scriptMain, 0)) {
+
+ if (!_scriptInterpreter->startScript(_scriptMain, 0))
error("Could not start script function 0 of script \"_STARTUP.EMC\"");
- }
- while (_scriptInterpreter->validScript(_scriptMain)) {
+
+ while (_scriptInterpreter->validScript(_scriptMain))
_scriptInterpreter->runScript(_scriptMain);
- }
_scriptInterpreter->unloadScript(_npcScriptData);
- if (!_scriptInterpreter->loadScript("_NPC.EMC", _npcScriptData)) {
+
+ if (!_scriptInterpreter->loadScript("_NPC.EMC", _npcScriptData))
error("Could not load \"_NPC.EMC\" script");
- }
snd_playTheme(1);
enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1);
diff --git a/engines/kyra/script.cpp b/engines/kyra/script.cpp
index 2e893ced9e..762288a8e0 100644
--- a/engines/kyra/script.cpp
+++ b/engines/kyra/script.cpp
@@ -71,7 +71,7 @@ ScriptHelper::ScriptHelper(KyraEngine *vm) : _vm(vm) {
bool ScriptHelper::loadScript(const char *filename, ScriptData *scriptData) {
uint32 size = 0;
uint8 *data = _vm->resource()->fileData(filename, &size);
- byte *curData = data;
+ const byte *curData = data;
uint32 formBlockSize = getFORMBlockSize(curData);
if (formBlockSize == (uint32)-1) {
@@ -99,20 +99,19 @@ bool ScriptHelper::loadScript(const char *filename, ScriptData *scriptData) {
error("No ORDR chunk found in file: '%s'", filename);
return false;
}
+ chunkSize >>= 1;
- scriptData->ordr = new byte[chunkSize];
+ scriptData->ordr = new uint16[chunkSize];
- if (!loadIFFBlock(data, curData, size, ORDR_CHUNK, scriptData->ordr, chunkSize)) {
+ if (!loadIFFBlock(data, curData, size, ORDR_CHUNK, scriptData->ordr, chunkSize << 1)) {
delete [] data;
unloadScript(scriptData);
error("Couldn't load ORDR chunk from file: '%s'", filename);
return false;
}
- chunkSize = chunkSize / 2;
- while (chunkSize--) {
- ((uint16*)scriptData->ordr)[chunkSize] = READ_BE_UINT16(&((uint16*)scriptData->ordr)[chunkSize]);
- }
+ while (chunkSize--)
+ scriptData->ordr[chunkSize] = READ_BE_UINT16(&scriptData->ordr[chunkSize]);
chunkSize = getIFFBlockSize(data, curData, size, DATA_CHUNK);
if (chunkSize == (uint32)-1) {
@@ -121,16 +120,20 @@ bool ScriptHelper::loadScript(const char *filename, ScriptData *scriptData) {
error("No DATA chunk found in file: '%s'", filename);
return false;
}
+ chunkSize >>= 1;
- scriptData->data = new byte[chunkSize];
+ scriptData->data = new uint16[chunkSize];
- if (!loadIFFBlock(data, curData, size, DATA_CHUNK, scriptData->data, chunkSize)) {
+ if (!loadIFFBlock(data, curData, size, DATA_CHUNK, scriptData->data, chunkSize << 1)) {
delete [] data;
unloadScript(scriptData);
error("Couldn't load DATA chunk from file: '%s'", filename);
return false;
}
- scriptData->dataSize = chunkSize / 2;
+ scriptData->dataSize = chunkSize;
+
+ while (chunkSize--)
+ scriptData->data[chunkSize] = READ_BE_UINT16(&scriptData->data[chunkSize]);
delete [] data;
return true;
@@ -144,7 +147,8 @@ void ScriptHelper::unloadScript(ScriptData *data) {
delete [] data->ordr;
delete [] data->data;
- data->text = data->ordr = data->data = 0;
+ data->text = 0;
+ data->ordr = data->data = 0;
}
void ScriptHelper::initScript(ScriptState *scriptStat, const ScriptData *data) {
@@ -159,14 +163,14 @@ bool ScriptHelper::startScript(ScriptState *script, int function) {
if (!script->dataPtr)
return false;
- uint16 functionOffset = ((uint16*)script->dataPtr->ordr)[function];
+ uint16 functionOffset = script->dataPtr->ordr[function];
if (functionOffset == 0xFFFF)
return false;
if (_vm->gameFlags().platform == Common::kPlatformFMTowns)
- script->ip = &script->dataPtr->data[functionOffset*2+2];
+ script->ip = &script->dataPtr->data[functionOffset+1];
else
- script->ip = &script->dataPtr->data[functionOffset*2];
+ script->ip = &script->dataPtr->data[functionOffset];
return true;
}
@@ -184,7 +188,7 @@ bool ScriptHelper::runScript(ScriptState *script) {
if (!script->ip)
return false;
- int16 code = READ_BE_UINT16(script->ip); script->ip += 2;
+ int16 code = *script->ip++;
int16 opcode = (code >> 8) & 0x1F;
if (code & 0x8000) {
@@ -193,7 +197,7 @@ bool ScriptHelper::runScript(ScriptState *script) {
} else if (code & 0x4000) {
_parameter = (int8)(code);
} else if (code & 0x2000) {
- _parameter = READ_BE_UINT16(script->ip); script->ip += 2;
+ _parameter = *script->ip++;
} else {
_parameter = 0;
}
@@ -208,7 +212,7 @@ bool ScriptHelper::runScript(ScriptState *script) {
return _continue;
}
-uint32 ScriptHelper::getFORMBlockSize(byte *&data) const {
+uint32 ScriptHelper::getFORMBlockSize(const byte *&data) const {
static const uint32 chunkName = FORM_CHUNK;
if (READ_LE_UINT32(data) != chunkName)
@@ -219,7 +223,7 @@ uint32 ScriptHelper::getFORMBlockSize(byte *&data) const {
return retValue;
}
-uint32 ScriptHelper::getIFFBlockSize(byte *start, byte *&data, uint32 maxSize, const uint32 chunkName) const {
+uint32 ScriptHelper::getIFFBlockSize(const byte *start, const byte *&data, uint32 maxSize, const uint32 chunkName) const {
uint32 size = (uint32)-1;
bool special = false;
@@ -247,7 +251,7 @@ uint32 ScriptHelper::getIFFBlockSize(byte *start, byte *&data, uint32 maxSize, c
return size;
}
-bool ScriptHelper::loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const uint32 chunkName, byte *loadTo, uint32 ptrSize) const {
+bool ScriptHelper::loadIFFBlock(const byte *start, const byte *&data, uint32 maxSize, const uint32 chunkName, void *loadTo, uint32 ptrSize) const {
bool special = false;
if (data == (start + maxSize))
@@ -271,9 +275,8 @@ bool ScriptHelper::loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const
loadSize = ptrSize;
memcpy(loadTo, data, loadSize);
chunkSize = (chunkSize + 1) & 0xFFFFFFFE;
- if (chunkSize > loadSize) {
+ if (chunkSize > loadSize)
data += (chunkSize - loadSize);
- }
return true;
}
}
@@ -286,7 +289,7 @@ bool ScriptHelper::loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const
#pragma mark -
void ScriptHelper::c1_jmpTo(ScriptState* script) {
- script->ip = script->dataPtr->data + (_parameter << 1);
+ script->ip = script->dataPtr->data + _parameter;
}
void ScriptHelper::c1_setRetValue(ScriptState* script) {
@@ -300,7 +303,7 @@ void ScriptHelper::c1_pushRetOrPos(ScriptState* script) {
break;
case 1:
- script->stack[--script->sp] = (script->ip - script->dataPtr->data) / 2 + 1;
+ script->stack[--script->sp] = script->ip - script->dataPtr->data + 1;
script->stack[--script->sp] = script->bp;
script->bp = script->sp + 2;
break;
@@ -340,7 +343,7 @@ void ScriptHelper::c1_popRetOrPos(ScriptState* script) {
script->ip = 0;
} else {
script->bp = script->stack[script->sp++];
- script->ip = script->dataPtr->data + (script->stack[script->sp++] << 1);
+ script->ip = script->dataPtr->data + script->stack[script->sp++];
}
break;
@@ -378,7 +381,7 @@ void ScriptHelper::c1_execOpcode(ScriptState* script) {
void ScriptHelper::c1_ifNotJmp(ScriptState* script) {
if (!script->stack[script->sp++]) {
_parameter &= 0x7FFF;
- script->ip = script->dataPtr->data + (_parameter << 1);
+ script->ip = script->dataPtr->data + _parameter;
}
}
@@ -532,7 +535,7 @@ void ScriptHelper::c1_setRetAndJmp(ScriptState* script) {
script->retValue = script->stack[script->sp++];
uint16 temp = script->stack[script->sp++];
script->stack[60] = 0;
- script->ip = &script->dataPtr->data[temp*2];
+ script->ip = &script->dataPtr->data[temp];
}
}
} // end of namespace Kyra
diff --git a/engines/kyra/script.h b/engines/kyra/script.h
index 653f8c9181..67a57e7590 100644
--- a/engines/kyra/script.h
+++ b/engines/kyra/script.h
@@ -28,15 +28,15 @@
namespace Kyra {
struct ScriptData {
byte *text;
- byte *data;
- byte *ordr;
+ uint16 *data;
+ uint16 *ordr;
uint16 dataSize;
int opcodeTable; // indicates which opcode table to use (for Kyra3 and Kyra2)
};
struct ScriptState {
- byte *ip;
+ uint16 *ip;
const ScriptData *dataPtr;
int16 retValue;
uint16 bp;
@@ -59,9 +59,9 @@ public:
bool runScript(ScriptState *script);
protected:
- uint32 getFORMBlockSize(byte *&data) const;
- uint32 getIFFBlockSize(byte *start, byte *&data, uint32 maxSize, const uint32 chunk) const;
- bool loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const uint32 chunk, byte *loadTo, uint32 ptrSize) const;
+ uint32 getFORMBlockSize(const byte *&data) const;
+ uint32 getIFFBlockSize(const byte *start, const byte *&data, uint32 maxSize, const uint32 chunk) const;
+ bool loadIFFBlock(const byte *start, const byte *&data, uint32 maxSize, const uint32 chunk, void *loadTo, uint32 ptrSize) const;
KyraEngine *_vm;
int16 _parameter;
diff --git a/engines/kyra/script_v1.cpp b/engines/kyra/script_v1.cpp
index 2099b69a47..38ea303cb3 100644
--- a/engines/kyra/script_v1.cpp
+++ b/engines/kyra/script_v1.cpp
@@ -33,7 +33,7 @@
namespace Kyra {
#define stackPos(x) script->stack[script->sp+x]
-#define stackPosString(x) (char*)&script->dataPtr->text[READ_BE_UINT16(&((uint16 *)script->dataPtr->text)[stackPos(x)])]
+#define stackPosString(x) (const char*)&script->dataPtr->text[READ_BE_UINT16(&((uint16 *)script->dataPtr->text)[stackPos(x)])]
int KyraEngine::o1_magicInMouseItem(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o1_magicInMouseItem(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
@@ -437,7 +437,7 @@ int KyraEngine::o1_setScaleMode(ScriptState *script) {
int KyraEngine::o1_openWSAFile(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o1_openWSAFile(%p) ('%s', %d, %d, %d)", (const void *)script, stackPosString(0), stackPos(1), stackPos(2), stackPos(3));
- char *filename = stackPosString(0);
+ const char *filename = stackPosString(0);
int wsaIndex = stackPos(1);
_movieObjects[wsaIndex]->open(filename, (stackPos(3) != 0) ? 1 : 0, 0);