diff options
author | Nicolas Bacca | 2004-03-23 20:34:19 +0000 |
---|---|---|
committer | Nicolas Bacca | 2004-03-23 20:34:19 +0000 |
commit | 52642e41234d703c4fa8ffcb459ed72403fa327b (patch) | |
tree | 0adcef84345bc11a71d7e4c830eec28afdd6c589 | |
parent | e1a1f291aaab2632dc12f9a72024d22c38de6779 (diff) | |
download | scummvm-rg350-52642e41234d703c4fa8ffcb459ed72403fa327b.tar.gz scummvm-rg350-52642e41234d703c4fa8ffcb459ed72403fa327b.tar.bz2 scummvm-rg350-52642e41234d703c4fa8ffcb459ed72403fa327b.zip |
Fix #922003 - FOTAQ crash on PocketPC
svn-id: r13372
-rw-r--r-- | queen/cutaway.cpp | 102 | ||||
-rw-r--r-- | queen/grid.cpp | 4 | ||||
-rw-r--r-- | queen/logic.cpp | 8 | ||||
-rw-r--r-- | queen/queen.h | 16 | ||||
-rw-r--r-- | queen/sound.cpp | 2 | ||||
-rw-r--r-- | queen/talk.cpp | 30 |
6 files changed, 89 insertions, 73 deletions
diff --git a/queen/cutaway.cpp b/queen/cutaway.cpp index e0d26e992c..5aaef473e8 100644 --- a/queen/cutaway.cpp +++ b/queen/cutaway.cpp @@ -74,9 +74,9 @@ void Cutaway::load(const char *filename) { _comPanel = READ_BE_UINT16(ptr); ptr += 2; debug(6, "_comPanel = %i", _comPanel); - - _cutawayObjectCount = (int16)READ_BE_UINT16(ptr); + _cutawayObjectCount = (int16)READ_BE_INT16(ptr); ptr += 2; + debug(6, "_cutawayObjectCount = %i", _cutawayObjectCount); if (_cutawayObjectCount < 0) { @@ -86,7 +86,7 @@ void Cutaway::load(const char *filename) { else _vm->input()->canQuit(true); - int16 flags1 = (int16)READ_BE_UINT16(ptr); + int16 flags1 = (int16)READ_BE_INT16(ptr); ptr += 2; debug(6, "flags1 = %i", flags1); @@ -179,7 +179,7 @@ void Cutaway::loadStrings(byte *ptr) { ptr = Talk::getString(ptr, _talkFile, MAX_FILENAME_LENGTH); debug(6, "Talk file = '%s'", _talkFile); - _talkTo = (int16)READ_BE_UINT16(ptr); + _talkTo = (int16)READ_BE_INT16(ptr); ptr += 2; debug(6, "_talkTo = %i", _talkTo); } @@ -188,23 +188,23 @@ byte *Cutaway::getCutawayObject(byte *ptr, CutawayObject &object) { byte *oldPtr = ptr; - object.objectNumber = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.moveToX = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.moveToY = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.bank = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.animList = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.execute = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.limitBobX1 = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.limitBobY1 = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.limitBobX2 = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.limitBobY2 = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.specialMove = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.animType = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.fromObject = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.bobStartX = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.bobStartY = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.room = (int16)READ_BE_UINT16(ptr); ptr += 2; - object.scale = (int16)READ_BE_UINT16(ptr); ptr += 2; + object.objectNumber = (int16)READ_BE_INT16(ptr); ptr += 2; + object.moveToX = (int16)READ_BE_INT16(ptr); ptr += 2; + object.moveToY = (int16)READ_BE_INT16(ptr); ptr += 2; + object.bank = (int16)READ_BE_INT16(ptr); ptr += 2; + object.animList = (int16)READ_BE_INT16(ptr); ptr += 2; + object.execute = (int16)READ_BE_INT16(ptr); ptr += 2; + object.limitBobX1 = (int16)READ_BE_INT16(ptr); ptr += 2; + object.limitBobY1 = (int16)READ_BE_INT16(ptr); ptr += 2; + object.limitBobX2 = (int16)READ_BE_INT16(ptr); ptr += 2; + object.limitBobY2 = (int16)READ_BE_INT16(ptr); ptr += 2; + object.specialMove = (int16)READ_BE_INT16(ptr); ptr += 2; + object.animType = (int16)READ_BE_INT16(ptr); ptr += 2; + object.fromObject = (int16)READ_BE_INT16(ptr); ptr += 2; + object.bobStartX = (int16)READ_BE_INT16(ptr); ptr += 2; + object.bobStartY = (int16)READ_BE_INT16(ptr); ptr += 2; + object.room = (int16)READ_BE_INT16(ptr); ptr += 2; + object.scale = (int16)READ_BE_INT16(ptr); ptr += 2; if ((ptr - oldPtr) != 17*sizeof(int16)) error("Wrong number of values read"); @@ -263,14 +263,14 @@ void Cutaway::dumpCutawayObject(int index, CutawayObject &object) byte *Cutaway::turnOnPeople(byte *ptr, CutawayObject &object) { // Lines 1248-1259 in cutaway.c - object.personCount = (int16)READ_BE_UINT16(ptr); + object.personCount = (int16)READ_BE_INT16(ptr); ptr += 2; if (object.personCount > MAX_PERSON_COUNT) error("[Cutaway::turnOnPeople] object.personCount > MAX_PERSON_COUNT"); for (int i = 0; i < object.personCount; i++) { - object.person[i] = (int16)READ_BE_UINT16(ptr); + object.person[i] = (int16)READ_BE_INT16(ptr); ptr += 2; //debug(6, "[%i] Turn on person %i", i, object.person[i]); } @@ -491,13 +491,13 @@ byte *Cutaway::getCutawayAnim(byte *ptr, int header, CutawayAnim &anim) { anim.originalFrame = _vm->logic()->findFrame(header); } - anim.unpackFrame = (int16)READ_BE_UINT16(ptr); + anim.unpackFrame = (int16)READ_BE_INT16(ptr); ptr += 2; - anim.speed = ((int16)READ_BE_UINT16(ptr)) / 3 + 1; + anim.speed = ((int16)READ_BE_INT16(ptr)) / 3 + 1; ptr += 2; - anim.bank = (int16)READ_BE_UINT16(ptr); + anim.bank = (int16)READ_BE_INT16(ptr); ptr += 2; if (anim.bank == 0) { @@ -514,26 +514,26 @@ byte *Cutaway::getCutawayAnim(byte *ptr, int header, CutawayAnim &anim) { } } - anim.mx = (int16)READ_BE_UINT16(ptr); + anim.mx = (int16)READ_BE_INT16(ptr); ptr += 2; - anim.my = (int16)READ_BE_UINT16(ptr); + anim.my = (int16)READ_BE_INT16(ptr); ptr += 2; - anim.cx = (int16)READ_BE_UINT16(ptr); + anim.cx = (int16)READ_BE_INT16(ptr); ptr += 2; - anim.cy = (int16)READ_BE_UINT16(ptr); + anim.cy = (int16)READ_BE_INT16(ptr); ptr += 2; - anim.scale = (int16)READ_BE_UINT16(ptr); + anim.scale = (int16)READ_BE_INT16(ptr); ptr += 2; if (_vm->resource()->isDemo()) { anim.song = 0; } else { - anim.song = (int16)READ_BE_UINT16(ptr); + anim.song = (int16)READ_BE_INT16(ptr); ptr += 2; } @@ -575,7 +575,7 @@ byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) { // Read animation frames for (;;) { - header = (int16)READ_BE_UINT16(ptr); + header = (int16)READ_BE_INT16(ptr); ptr += 2; if (-2 == header) @@ -1007,7 +1007,7 @@ void Cutaway::stop() { byte *ptr = _gameStatePtr; // Skipping GAMESTATE data - int gameStateCount = (int16)READ_BE_UINT16(ptr); ptr += 2; + int gameStateCount = (int16)READ_BE_INT16(ptr); ptr += 2; if (gameStateCount > 0) ptr += (gameStateCount * 12); @@ -1051,16 +1051,16 @@ void Cutaway::stop() { } } - int quitObjectCount = (int16)READ_BE_UINT16(ptr); ptr += 2; + int quitObjectCount = (int16)READ_BE_INT16(ptr); ptr += 2; for (i = 0; i < quitObjectCount; i++) { - int16 objectIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 fromIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 x = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 y = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 room = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 frame = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 bank = (int16)READ_BE_UINT16(ptr); ptr += 2; + int16 objectIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 fromIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 x = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 y = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 room = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 frame = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 bank = (int16)READ_BE_INT16(ptr); ptr += 2; int bobIndex = _vm->logic()->findBob(objectIndex); ObjectData *object = _vm->logic()->objectData(objectIndex); @@ -1116,11 +1116,11 @@ void Cutaway::stop() { } } // for() - int16 specialMove = (int16)READ_BE_UINT16(ptr); ptr += 2; + int16 specialMove = (int16)READ_BE_INT16(ptr); ptr += 2; if (specialMove > 0) _vm->logic()->executeSpecialMove(specialMove); - _lastSong = (int16)READ_BE_UINT16(ptr); ptr += 2; + _lastSong = (int16)READ_BE_INT16(ptr); ptr += 2; } if (joeRoom == _temporaryRoom && @@ -1141,15 +1141,15 @@ void Cutaway::updateGameState() { // Lines 2047-2115 in cutaway.c byte *ptr = _gameStatePtr; - int gameStateCount = (int16)READ_BE_UINT16(ptr); ptr += 2; + int gameStateCount = (int16)READ_BE_INT16(ptr); ptr += 2; for (int i = 0; i < gameStateCount; i++) { - int16 stateIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 stateValue = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 objectIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 areaIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 areaSubIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 fromObject = (int16)READ_BE_UINT16(ptr); ptr += 2; + int16 stateIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 stateValue = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 objectIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 areaIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 areaSubIndex = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 fromObject = (int16)READ_BE_INT16(ptr); ptr += 2; bool update = false; diff --git a/queen/grid.cpp b/queen/grid.cpp index 07e317b5c1..f015589a97 100644 --- a/queen/grid.cpp +++ b/queen/grid.cpp @@ -46,8 +46,8 @@ void Grid::readDataFrom(uint16 numObjects, uint16 numRooms, byte *&ptr) { _areaMax[0] = 0; memset(&_area[0], 0, sizeof(Area) * MAX_AREAS_NUMBER); for (i = 1; i <= _numRoomAreas; i++) { - _objMax[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; - _areaMax[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; + _objMax[i] = (int16)READ_BE_INT16(ptr); ptr += 2; + _areaMax[i] = (int16)READ_BE_INT16(ptr); ptr += 2; memset(&_area[i][0], 0, sizeof(Area)); for (j = 1; j <= _areaMax[i]; j++) { assert(j < MAX_AREAS_NUMBER); diff --git a/queen/logic.cpp b/queen/logic.cpp index 0b533d8c45..5e8eeb0be7 100644 --- a/queen/logic.cpp +++ b/queen/logic.cpp @@ -1298,11 +1298,11 @@ void Logic::saveState(byte *&ptr) { void Logic::loadState(uint32 ver, byte *&ptr) { uint16 i; for (i = 0; i < 4; i++) { - _inventoryItem[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; + _inventoryItem[i] = (int16)READ_BE_INT16(ptr); ptr += 2; } - _joe.x = (int16)READ_BE_UINT16(ptr); ptr += 2; - _joe.y = (int16)READ_BE_UINT16(ptr); ptr += 2; + _joe.x = (int16)READ_BE_INT16(ptr); ptr += 2; + _joe.y = (int16)READ_BE_INT16(ptr); ptr += 2; _currentRoom = READ_BE_UINT16(ptr); ptr += 2; @@ -1313,7 +1313,7 @@ void Logic::loadState(uint32 ver, byte *&ptr) { _itemData[i].readFromBE(ptr); for (i = 0; i < GAME_STATE_COUNT; i++) { - _gameState[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; + _gameState[i] = (int16)READ_BE_INT16(ptr); ptr += 2; } for (i = 0; i < TALK_SELECTED_COUNT; i++) diff --git a/queen/queen.h b/queen/queen.h index b7e9da5dbb..b3793bb229 100644 --- a/queen/queen.h +++ b/queen/queen.h @@ -26,6 +26,22 @@ class GameDetector; +#if defined(_WIN32_WCE) && (_WIN32_WCE <= 300) + +FORCEINLINE int16 READ_BE_INT16(const void *ptr) { + uint16 result; + char dummy[2]; + result = READ_BE_UINT16(ptr); + strcpy(dummy, "x"); // Hello, I'm a drunk optimizer. Thanks for helping me. + return result; +} + +#else + +#define READ_BE_INT16 READ_BE_UINT16 + +#endif + namespace Queen { struct GameStateHeader { diff --git a/queen/sound.cpp b/queen/sound.cpp index 26c75af9a1..f560573045 100644 --- a/queen/sound.cpp +++ b/queen/sound.cpp @@ -167,7 +167,7 @@ void Sound::saveState(byte *&ptr) { } void Sound::loadState(uint32 ver, byte *&ptr) { - _lastOverride = (int16)READ_BE_UINT16(ptr); ptr += 2; + _lastOverride = (int16)READ_BE_INT16(ptr); ptr += 2; } void SBSound::playSound(byte *sound, uint32 size, bool isSpeech) { diff --git a/queen/talk.cpp b/queen/talk.cpp index 41ebbdf09c..8bc748ef25 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -300,8 +300,8 @@ void Talk::talk(const char *filename, int personInRoom, char *cutawayFilename) { uint8 *ptr = _cutawayPtr; - int16 cutawayGameState = (int16)READ_BE_UINT16(ptr); ptr += 2; - int16 cutawayTestValue = (int16)READ_BE_UINT16(ptr); ptr += 2; + int16 cutawayGameState = (int16)READ_BE_INT16(ptr); ptr += 2; + int16 cutawayTestValue = (int16)READ_BE_INT16(ptr); ptr += 2; if (_vm->logic()->gameState(cutawayGameState) == cutawayTestValue) { getString(ptr, cutawayFilename, 20); @@ -360,7 +360,7 @@ void Talk::findDialogueString(byte *ptr, int16 id, int16 max, char *str) { for (int i = 1; i <= max; i++) { ptr += 2; - int16 currentId = (int16)READ_BE_UINT16(ptr); ptr += 2; + int16 currentId = (int16)READ_BE_INT16(ptr); ptr += 2; if (id == currentId) { ptr = getString(ptr, str, MAX_STRING_LENGTH, 4); //debug(6, "Found string with ID %i: '%s'", id, str); @@ -409,7 +409,7 @@ void Talk::load(const char *filename) { // Load talk header // - _levelMax = (int16)READ_BE_UINT16(ptr); ptr += 2; + _levelMax = (int16)READ_BE_INT16(ptr); ptr += 2; //debug(6, "levelMax = %i", _levelMax); @@ -420,15 +420,15 @@ void Talk::load(const char *filename) { else canQuit = true; - _uniqueKey = (int16)READ_BE_UINT16(ptr); ptr += 2; - _talkKey = (int16)READ_BE_UINT16(ptr); ptr += 2; - _jMax = (int16)READ_BE_UINT16(ptr); ptr += 2; - _pMax = (int16)READ_BE_UINT16(ptr); ptr += 2; + _uniqueKey = (int16)READ_BE_INT16(ptr); ptr += 2; + _talkKey = (int16)READ_BE_INT16(ptr); ptr += 2; + _jMax = (int16)READ_BE_INT16(ptr); ptr += 2; + _pMax = (int16)READ_BE_INT16(ptr); ptr += 2; for (i = 0; i < 2; i++) { - _gameState [i] = (int16)READ_BE_UINT16(ptr); ptr += 2; - _testValue [i] = (int16)READ_BE_UINT16(ptr); ptr += 2; - _itemNumber[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; + _gameState [i] = (int16)READ_BE_INT16(ptr); ptr += 2; + _testValue [i] = (int16)READ_BE_INT16(ptr); ptr += 2; + _itemNumber[i] = (int16)READ_BE_INT16(ptr); ptr += 2; } //debug(6, "uniqueKey = %i", _uniqueKey); @@ -454,13 +454,13 @@ void Talk::load(const char *filename) { for (i = 1; i <= _levelMax; i++) for (int j = 0; j <= 5; j++) { ptr += 2; - _dialogueTree[i][j].head = (int16)READ_BE_UINT16(ptr); ptr += 2; + _dialogueTree[i][j].head = (int16)READ_BE_INT16(ptr); ptr += 2; ptr += 2; - _dialogueTree[i][j].dialogueNodeValue1 = (int16)READ_BE_UINT16(ptr); ptr += 2; + _dialogueTree[i][j].dialogueNodeValue1 = (int16)READ_BE_INT16(ptr); ptr += 2; ptr += 2; - _dialogueTree[i][j].gameStateIndex = (int16)READ_BE_UINT16(ptr); ptr += 2; + _dialogueTree[i][j].gameStateIndex = (int16)READ_BE_INT16(ptr); ptr += 2; ptr += 2; - _dialogueTree[i][j].gameStateValue = (int16)READ_BE_UINT16(ptr); ptr += 2; + _dialogueTree[i][j].gameStateValue = (int16)READ_BE_INT16(ptr); ptr += 2; } } |