aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/gob/game.cpp28
-rw-r--r--engines/gob/game.h6
-rw-r--r--engines/gob/game_v1.cpp3
-rw-r--r--engines/gob/game_v2.cpp3
-rw-r--r--engines/gob/global.h16
-rw-r--r--engines/gob/init.cpp3
-rw-r--r--engines/gob/inter_v1.cpp3
-rw-r--r--engines/gob/inter_v2.cpp14
-rw-r--r--engines/gob/sound.h2
9 files changed, 51 insertions, 27 deletions
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp
index e73c544edf..09c922f921 100644
--- a/engines/gob/game.cpp
+++ b/engines/gob/game.cpp
@@ -150,11 +150,12 @@ Game::~Game() {
delete[] _word_2FC80;
}
-char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
+char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize) {
int16 commonHandle;
int16 itemsCount;
int32 offset;
uint32 size;
+ uint32 realSize;
ExtItem *item;
char isPacked;
int16 handle;
@@ -206,6 +207,7 @@ char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
debugC(7, DEBUG_FILEIO, "off: %d size: %d", offset, tableSize);
_vm->_dataio->seekData(handle, offset + tableSize, SEEK_SET);
+ realSize = size;
// CHECKME: is the below correct?
if (isPacked)
dataBuf = new char[size];
@@ -227,13 +229,15 @@ char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) {
if (isPacked != 0) {
packedBuf = dataBuf;
- dataBuf = new char[READ_LE_UINT32(packedBuf)];
+ realSize = READ_LE_UINT32(packedBuf);
+ dataBuf = new char[realSize];
_vm->_pack->unpackData(packedBuf, dataBuf);
delete[] packedBuf;
}
+ if (dataSize)
+ *dataSize = realSize;
return dataBuf;
-
}
void Game::freeCollision(int16 id) {
@@ -302,12 +306,14 @@ void Game::capturePop(char doDraw) {
_vm->_draw->_spritesArray[30 + _captureCount] = 0;
}
-char *Game::loadTotResource(int16 id) {
+char *Game::loadTotResource(int16 id, int16 *dataSize) {
TotResItem *itemPtr;
int32 offset;
itemPtr = &_totResourceTable->items[id];
offset = itemPtr->offset;
+ if (dataSize)
+ *dataSize = itemPtr->size;
if (offset >= 0) {
return _totResourceTable->dataPtr + szGame_TotResTable +
szGame_TotResItem * _totResourceTable->itemsCount + offset;
@@ -316,20 +322,22 @@ char *Game::loadTotResource(int16 id) {
}
}
-void Game::loadSound(int16 slot, char *dataPtr) {
+void Game::loadSound(int16 slot, char *dataPtr, uint32 dataSize) {
Snd::SoundDesc *soundDesc;
+ byte *data = (byte *) dataPtr;
soundDesc = new Snd::SoundDesc;
_soundSamples[slot] = soundDesc;
- soundDesc->frequency = (dataPtr[4] << 8) + dataPtr[5];
- soundDesc->size = (dataPtr[1] << 16) + (dataPtr[2] << 8) + dataPtr[3];
+ soundDesc->frequency = (data[4] << 8) + data[5];
+ // Somehow, one sound in one CD version has a wrong size, leading to statics and crashes
+ soundDesc->size = MIN((uint32) ((data[1] << 16) + (data[2] << 8) + data[3]), dataSize - 6);
soundDesc->data = dataPtr + 6;
soundDesc->timerTicks = (int32)1193180 / (int32)soundDesc->frequency;
-
soundDesc->inClocks = (soundDesc->frequency * 10) / 182;
soundDesc->flag = 0;
+
}
void Game::freeSoundSlot(int16 slot) {
@@ -350,13 +358,13 @@ void Game::freeSoundSlot(int16 slot) {
char* data = _soundSamples[slot]->data;
_vm->_snd->freeSoundDesc(_soundSamples[slot], false);
- _soundSamples[slot] = 0;
if (_soundFromExt[slot] == 1) {
delete[] (data - 6);
_soundFromExt[slot] = 0;
}
}
+ _soundSamples[slot] = 0;
}
int16 Game::adjustKey(int16 key) {
@@ -748,7 +756,7 @@ void Game::collAreaSub(int16 index, int8 enter) {
Snd::SoundDesc *Game::loadSND(const char *path, int8 arg_4) {
Snd::SoundDesc *soundDesc;
- int32 dsize;
+ uint32 dsize;
char *data;
char *dataPtr;
diff --git a/engines/gob/game.h b/engines/gob/game.h
index f0c78d692e..9bdd15049f 100644
--- a/engines/gob/game.h
+++ b/engines/gob/game.h
@@ -186,8 +186,8 @@ public:
Game(GobEngine *vm);
virtual ~Game();
- char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight);
- char *loadTotResource(int16 id);
+ char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight, uint32 *dataSize = 0);
+ char *loadTotResource(int16 id, int16 *dataSize = 0);
void capturePush(int16 left, int16 top, int16 width, int16 height);
@@ -195,7 +195,7 @@ public:
void freeSoundSlot(int16 slot);
void freeCollision(int16 id);
- void loadSound(int16 slot, char *dataPtr);
+ void loadSound(int16 slot, char *dataPtr, uint32 dataSize = 4294967295U);
int16 adjustKey(int16 key);
int32 loadTotFile(char *path);
void loadExtTable(void);
diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp
index 590ecfa2a7..b539a63fd2 100644
--- a/engines/gob/game_v1.cpp
+++ b/engines/gob/game_v1.cpp
@@ -173,8 +173,7 @@ void Game_v1::playTot(int16 skipPlay) {
variablesCount = READ_LE_UINT32((char *)_totFileData + 0x2c);
_vm->_global->_inter_variables = new char[variablesCount * 4];
_vm->_global->_inter_variablesSizes = new byte[variablesCount * 4];
- for (i = 0; i < variablesCount; i++)
- WRITE_VAR(i, 0);
+ _vm->_global->clearVars(variablesCount);
}
_vm->_global->_inter_execPtr = (char *)_totFileData;
diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp
index 22a4953656..30166269a5 100644
--- a/engines/gob/game_v2.cpp
+++ b/engines/gob/game_v2.cpp
@@ -201,8 +201,7 @@ void Game_v2::playTot(int16 skipPlay) {
variablesCount = READ_LE_UINT32((char *)_totFileData + 0x2c);
_vm->_global->_inter_variables = new char[variablesCount * 4];
_vm->_global->_inter_variablesSizes = new byte[variablesCount * 4];
- for (i = 0; i < variablesCount; i++)
- WRITE_VAR(i, 0);
+ _vm->_global->clearVars(variablesCount);
}
_vm->_global->_inter_execPtr = (char *)_totFileData;
diff --git a/engines/gob/global.h b/engines/gob/global.h
index 3dc1876090..242c05578f 100644
--- a/engines/gob/global.h
+++ b/engines/gob/global.h
@@ -163,6 +163,22 @@ public:
int16 _inter_mouseX;
int16 _inter_mouseY;
+ inline void clearVars(uint32 count)
+ {
+ uint32 i;
+
+ for (i = 0; i < count; i++) {
+ _inter_variablesSizes[i * 4] = 3;
+ _inter_variablesSizes[i * 4 + 1] = 0;
+ _inter_variablesSizes[i * 4 + 2] = 0;
+ _inter_variablesSizes[i * 4 + 3] = 0;
+ _inter_variables[i * 4] = 0;
+ _inter_variables[i * 4 + 1] = 0;
+ _inter_variables[i * 4 + 2] = 0;
+ _inter_variables[i * 4 + 3] = 0;
+ }
+ }
+
inline void writeVarSizeStr(uint32 offset, uint32 len) {
uint32 i;
uint32 inVar;
diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp
index 89149a1112..7263fe9658 100644
--- a/engines/gob/init.cpp
+++ b/engines/gob/init.cpp
@@ -206,8 +206,7 @@ memBlocks = word ptr -2*/
_vm->_global->_inter_variables = new char[varsCount * 4];
_vm->_global->_inter_variablesSizes = new byte[varsCount * 4];
- for (i = 0; i < varsCount; i++)
- WRITE_VAR(i, 0);
+ _vm->_global->clearVars(varsCount);
WRITE_VAR(58, 1);
strcpy(_vm->_game->_curTotFile, buffer);
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index a58c526512..7fa7ef8738 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -1339,9 +1339,8 @@ bool Inter_v1::o1_keyFunc(char &cmdCount, int16 &counter, int16 &retFlag) {
animPalette();
_vm->_draw->blitInvalidated();
- _vm->_video->waitRetrace(_vm->_global->_videoMode);
// Gob2 busy-waits here, so add a delay
- _vm->_util->delay(1);
+ _vm->_util->longDelay(1);
if (flag != 0) {
diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp
index 47b3b77ffa..7fce867982 100644
--- a/engines/gob/inter_v2.cpp
+++ b/engines/gob/inter_v2.cpp
@@ -933,7 +933,7 @@ void Inter_v2::o2_stub0x85(void) {
int16 Inter_v2::loadSound(int16 search) {
int16 id; // si
int16 slot; // di
- int32 i;
+ uint32 i;
bool isADL;
char sndfile[14];
char *extData;
@@ -1003,21 +1003,25 @@ int16 Inter_v2::loadSound(int16 search) {
_vm->_game->_soundSamples[slot] = soundDesc;
_vm->_game->_soundFromExt[slot] = 1;
} else { // loc_99BC
- extData = _vm->_game->loadExtData(id, 0, 0);
+ uint32 dataSize;
+
+ extData = _vm->_game->loadExtData(id, 0, 0, &dataSize);
if (extData == 0)
return slot;
_vm->_game->_soundTypes[slot] = 1;
if (!isADL)
- _vm->_game->loadSound(slot, extData);
+ _vm->_game->loadSound(slot, extData, dataSize);
else
// TODO: This is very ugly
_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;
_vm->_game->_soundFromExt[slot] = 1;
}
} else { // loc_9A13
- extData = _vm->_game->loadTotResource(id);
+ int16 dataSize;
+
+ extData = _vm->_game->loadTotResource(id, &dataSize);
if (!isADL)
- _vm->_game->loadSound(slot, extData);
+ _vm->_game->loadSound(slot, extData, dataSize);
else
// TODO: This is very ugly
_vm->_game->_soundSamples[slot] = (Snd::SoundDesc *) extData;
diff --git a/engines/gob/sound.h b/engines/gob/sound.h
index 5c989a7a38..5b32569ac1 100644
--- a/engines/gob/sound.h
+++ b/engines/gob/sound.h
@@ -33,7 +33,7 @@ public:
struct SoundDesc {
Audio::SoundHandle handle;
char *data;
- int32 size;
+ uint32 size;
int16 repCount;
int16 timerTicks;
int16 inClocks;