diff options
-rw-r--r-- | engines/cruise/cruise_main.cpp | 12 | ||||
-rw-r--r-- | engines/cruise/ctp.cpp | 21 | ||||
-rw-r--r-- | engines/cruise/dataLoader.cpp | 17 | ||||
-rw-r--r-- | engines/cruise/decompiler.cpp | 12 | ||||
-rw-r--r-- | engines/cruise/font.cpp | 32 | ||||
-rw-r--r-- | engines/cruise/font.h | 6 | ||||
-rw-r--r-- | engines/cruise/function.cpp | 2 | ||||
-rw-r--r-- | engines/cruise/gfxModule.cpp | 2 | ||||
-rw-r--r-- | engines/cruise/linker.cpp | 6 | ||||
-rw-r--r-- | engines/cruise/mainDraw.cpp | 21 | ||||
-rw-r--r-- | engines/cruise/various.cpp | 9 | ||||
-rw-r--r-- | engines/cruise/various.h | 2 | ||||
-rw-r--r-- | engines/cruise/volume.cpp | 20 |
13 files changed, 60 insertions, 102 deletions
diff --git a/engines/cruise/cruise_main.cpp b/engines/cruise/cruise_main.cpp index a5cec48e2d..bdbf257b32 100644 --- a/engines/cruise/cruise_main.cpp +++ b/engines/cruise/cruise_main.cpp @@ -613,14 +613,14 @@ int findObject(int mouseX, int mouseY, int *outObjOvl, int *outObjIdx) { dataPtr ++; - offset = *(dataPtr++); - flipShort(&offset); + offset = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; - newX = *(dataPtr++); - flipShort(&newX); + newX = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; - newY = *(dataPtr++); - flipShort(&newY); + newY = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; offset += j; diff --git a/engines/cruise/ctp.cpp b/engines/cruise/ctp.cpp index 4c566f57cf..be4639af4d 100644 --- a/engines/cruise/ctp.cpp +++ b/engines/cruise/ctp.cpp @@ -24,6 +24,7 @@ */ #include "cruise/cruise_main.h" +#include "common/endian.h" #include "common/util.h" namespace Cruise { @@ -242,20 +243,20 @@ int initCt(const char *ctpName) { return (0); } - ctp_routeCoordCount = readB16(dataPointer); // get the number of nods + ctp_routeCoordCount = (int16)READ_BE_UINT16(dataPointer); // get the number of nods dataPointer += 2; for (int i = 0; i < 7; i++) { - segementSizeTable[i] = readB16(dataPointer); + segementSizeTable[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } // get the path-finding coordinates ASSERT((segementSizeTable[0] % 4) == 0); for (int i = 0; i < segementSizeTable[0] / 4; i++) { - ctp_routeCoords[i][0] = readB16(dataPointer); + ctp_routeCoords[i][0] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; - ctp_routeCoords[i][1] = readB16(dataPointer); + ctp_routeCoords[i][1] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } @@ -263,7 +264,7 @@ int initCt(const char *ctpName) { ASSERT((segementSizeTable[1] % 20) == 0); for (int i = 0; i < segementSizeTable[1] / 20; i++) { for (int j = 0; j < 10; j++) { - ctp_routes[i][j] = readB16(dataPointer); + ctp_routes[i][j] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } } @@ -272,7 +273,7 @@ int initCt(const char *ctpName) { ASSERT((segementSizeTable[2] % 80) == 0); for (int i = 0; i < segementSizeTable[2] / 80; i++) { for (int j = 0; j < 40; j++) { - ctp_walkboxTable[i][j] = readB16(dataPointer); + ctp_walkboxTable[i][j] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } } @@ -286,14 +287,14 @@ int initCt(const char *ctpName) { // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone ASSERT((segementSizeTable[3] % 2) == 0); for (int i = 0; i < segementSizeTable[3] / 2; i++) { - walkboxColor[i] = readB16(dataPointer); + walkboxColor[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01) ASSERT((segementSizeTable[4] % 2) == 0); for (int i = 0; i < segementSizeTable[4] / 2; i++) { - walkboxState[i] = readB16(dataPointer); + walkboxState[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } } @@ -301,14 +302,14 @@ int initCt(const char *ctpName) { // ASSERT((segementSizeTable[5] % 2) == 0); for (int i = 0; i < segementSizeTable[5] / 2; i++) { - walkboxColorIndex[i] = readB16(dataPointer); + walkboxColorIndex[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } // ASSERT((segementSizeTable[6] % 2) == 0); for (int i = 0; i < segementSizeTable[6] / 2; i++) { - walkboxZoom[i] = readB16(dataPointer); + walkboxZoom[i] = (int16)READ_BE_UINT16(dataPointer); dataPointer += 2; } free(ptr); diff --git a/engines/cruise/dataLoader.cpp b/engines/cruise/dataLoader.cpp index 07602f2fcd..d725e1bb89 100644 --- a/engines/cruise/dataLoader.cpp +++ b/engines/cruise/dataLoader.cpp @@ -229,9 +229,7 @@ fileTypeEnum getFileType(const char *name) { } int getNumMaxEntiresInSet(uint8 *ptr) { - uint16 numEntries = *(uint16 *)(ptr + 4); - flipShort(&numEntries); - + uint16 numEntries = READ_BE_UINT16(ptr + 4); return numEntries; } @@ -351,9 +349,7 @@ int loadFNTSub(uint8 *ptr, int destIdx) { uint32 fontSize; ptr2 += 4; - memcpy(&loadFileVar1, ptr2, 4); - - flipLong(&loadFileVar1); + loadFileVar1 = READ_BE_UINT32(ptr2); if (destIdx == -1) { fileIndex = createResFileEntry(loadFileVar1, 1, loadFileVar1, 1); @@ -365,8 +361,7 @@ int loadFNTSub(uint8 *ptr, int destIdx) { memcpy(destPtr, ptr2, loadFileVar1); - memcpy(&fontSize, ptr2, 4); - flipLong(&fontSize); + fontSize = READ_BE_UINT32(ptr2); if (destPtr != NULL) { int32 i; @@ -374,14 +369,14 @@ int loadFNTSub(uint8 *ptr, int destIdx) { destPtr = filesDatabase[fileIndex].subData.ptr; - flipLong((int32 *) destPtr); - flipLong((int32 *)(destPtr + 4)); + bigEndianLongToNative((int32 *) destPtr); + bigEndianLongToNative((int32 *)(destPtr + 4)); flipGen(destPtr + 8, 6); currentPtr = destPtr + 14; for (i = 0; i < *(int16 *)(destPtr + 8); i++) { - flipLong((int32 *) currentPtr); + bigEndianLongToNative((int32 *) currentPtr); currentPtr += 4; flipGen(currentPtr, 8); diff --git a/engines/cruise/decompiler.cpp b/engines/cruise/decompiler.cpp index 505ca0e4d6..a7244d3f8a 100644 --- a/engines/cruise/decompiler.cpp +++ b/engines/cruise/decompiler.cpp @@ -243,13 +243,10 @@ char getByteFromDecompScriptReal(void) { } void getShortFromDecompScript(char *buffer) { - short int var = - *(int16 *)(currentDecompScript + currentDecompScriptPtr->var4); + int16 var = (int16)READ_BE_UINT16(currentDecompScript + currentDecompScriptPtr->var4); currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 2; - flipShort(&var); - if (var == -1) { resolveDecompShort(buffer); @@ -260,14 +257,11 @@ void getShortFromDecompScript(char *buffer) { sprintf(buffer, "%d", var); } -short int getShortFromDecompScriptReal(void) { - short int var = - *(int16 *)(currentDecompScript + currentDecompScriptPtr->var4); +int16 getShortFromDecompScriptReal(void) { + int16 var = (int16)READ_BE_UINT16(currentDecompScript + currentDecompScriptPtr->var4); currentDecompScriptPtr->var4 = currentDecompScriptPtr->var4 + 2; - flipShort(&var); - return var; } diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp index 79994aebad..1b3f840807 100644 --- a/engines/cruise/font.cpp +++ b/engines/cruise/font.cpp @@ -121,14 +121,14 @@ void loadFNT(const char *fileName) { // Flip structure values from BE to LE for font files - this is for consistency // with font resources, which are in LE formatt FontInfo *f = (FontInfo *)_systemFNT; - flipLong(&f->offset); - flipLong(&f->size); + bigEndianLongToNative(&f->offset); + bigEndianLongToNative(&f->size); flipGen(&f->numChars, 6); // numChars, hSpacing, and vSpacing FontEntry *fe = (FontEntry *)(_systemFNT + sizeof(FontInfo)); for (int i = 0; i < FROM_LE_16(f->numChars); ++i, ++fe) { - flipLong(&fe->offset); // Flip 32-bit offset field + bigEndianLongToNative(&fe->offset); // Flip 32-bit offset field flipGen(&fe->v1, 8); // Flip remaining 16-bit fields } } @@ -170,28 +170,12 @@ void freeSystem(void) { free(_systemFNT); } -void flipShort(int16 *var) { - uint8 *varPtr = (uint8 *) var; - SWAP(varPtr[0], varPtr[1]); +void bigEndianShortToNative(void *var) { + WRITE_UINT16(var, READ_BE_UINT16(var)); } -void flipShort(uint16 *var) { - uint8 *varPtr = (uint8 *) var; - SWAP(varPtr[0], varPtr[1]); -} - -void flipLong(int32 *var) { - uint8 *varPtr = (uint8 *)var; - - SWAP(varPtr[0], varPtr[3]); - SWAP(varPtr[1], varPtr[2]); -} - -void flipLong(uint32 *var) { - uint8 *varPtr = (uint8 *)var; - - SWAP(varPtr[0], varPtr[3]); - SWAP(varPtr[1], varPtr[2]); +void bigEndianLongToNative(void *var) { + WRITE_UINT32(var, READ_BE_UINT32(var)); } void flipGen(void *var, int32 length) { @@ -199,7 +183,7 @@ void flipGen(void *var, int32 length) { short int *varPtr = (int16 *) var; for (i = 0; i < (length / 2); i++) { - flipShort(&varPtr[i]); + bigEndianShortToNative(&varPtr[i]); } } diff --git a/engines/cruise/font.h b/engines/cruise/font.h index 6404c91230..e3f34837af 100644 --- a/engines/cruise/font.h +++ b/engines/cruise/font.h @@ -55,10 +55,8 @@ void initSystem(void); void freeSystem(void); ////////////////////////////////////////////////// -void flipShort(int16 * var); -void flipShort(uint16 * var); -void flipLong(int32 * var); // TODO: move away -void flipLong(uint32 * var); // TODO: move away +void bigEndianShortToNative(void *var); +void bigEndianLongToNative(void *var); // TODO: move away void flipGen(void *var, int32 length); int32 getLineHeight(int16 charCount, const FontEntry *fontPtr, const uint8 *fontPrt_Desc); // fontProc1 diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp index 113e0c6b81..7789cb6fb1 100644 --- a/engines/cruise/function.cpp +++ b/engines/cruise/function.cpp @@ -143,7 +143,7 @@ int16 Op_AddProc(void) { for (long int i = 0; i < pop1; i++) { int16* ptr = (int16*)(procBss + i * 2); *ptr = param[i]; - flipShort(ptr); + bigEndianShortToNative(ptr); } } diff --git a/engines/cruise/gfxModule.cpp b/engines/cruise/gfxModule.cpp index 490e208c1e..47d3f49204 100644 --- a/engines/cruise/gfxModule.cpp +++ b/engines/cruise/gfxModule.cpp @@ -147,7 +147,7 @@ void gfxModuleData_setPal256(const byte *ptr) { for (i = 0; i < 256; i++) { #define convertRatio 36.571428571428571428571428571429 uint16 atariColor = *ptr; - //flipShort(&atariColor); + //bigEndianShortToNative(&atariColor); ptr ++; R = (int)(convertRatio * ((atariColor & 0x700) >> 8)); diff --git a/engines/cruise/linker.cpp b/engines/cruise/linker.cpp index d7268c2f02..bb6f682e1e 100644 --- a/engines/cruise/linker.cpp +++ b/engines/cruise/linker.cpp @@ -184,7 +184,7 @@ int updateScriptImport(int ovlIdx) { *(ptr + 1) = out2; *(int16 *)(ptr + 2) = ptrDest2->idx; - flipShort((int16 *)(ptr + 2)); + bigEndianShortToNative((int16 *)(ptr + 2)); } else { if (param2 == 20 || param2 == 30 || param2 == 40 || param2 == 50) { // this patch a double push uint8 *ptr = ptrData + temp; @@ -194,7 +194,7 @@ int updateScriptImport(int ovlIdx) { *(int16 *)(ptr + 4) = ptrDest2->idx; - flipShort((int16 *)(ptr + 4)); + bigEndianShortToNative((int16 *)(ptr + 4)); } else { int var_4 = ptrDest2->var4; @@ -215,7 +215,7 @@ int updateScriptImport(int ovlIdx) { *(int16 *)(ptrData + temp + 2) = ptrDest2->idx; - flipShort + bigEndianShortToNative ( (int16 *) diff --git a/engines/cruise/mainDraw.cpp b/engines/cruise/mainDraw.cpp index be128a3ffb..2932e6dc7d 100644 --- a/engines/cruise/mainDraw.cpp +++ b/engines/cruise/mainDraw.cpp @@ -25,6 +25,7 @@ #include "cruise/cruise_main.h" #include "cruise/polys.h" +#include "common/endian.h" #include "common/util.h" namespace Cruise { @@ -163,14 +164,14 @@ void flipPoly(int fileId, int16 *dataPtr, int scale, char** newFrame, int X, int dataPtr ++; - offset = *(dataPtr++); - flipShort(&offset); + offset = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; - newX = *(dataPtr++); - flipShort(&newX); + newX = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; - newY = *(dataPtr++); - flipShort(&newY); + newY = (int16)READ_BE_UINT16(dataPtr); + dataPtr++; offset += fileId; @@ -828,11 +829,9 @@ void buildPolyModel(int positionX, int positionY, int scale, char *pMask, char * m_color = *dataPointer; // color dataPointer += 2; - minimumScale = *(uint16 *)(dataPointer); + minimumScale = READ_BE_UINT16(dataPointer); dataPointer += 2; - flipShort(&minimumScale); - if ((minimumScale <= scale)) { if (m_flipLeftRight) { drawPolyMode1((unsigned char *)dataPointer, linesToDraw); @@ -989,11 +988,9 @@ bool findPoly(char* dataPtr, int positionX, int positionY, int scale, int mouseX m_color = *dataPointer; // color dataPointer += 2; - minimumScale = *(uint16 *)(dataPointer); + minimumScale = READ_BE_UINT16(dataPointer); dataPointer += 2; - flipShort(&minimumScale); - if ((minimumScale <= scale)) { if (m_flipLeftRight) { drawPolyMode1((unsigned char *)dataPointer, linesToDraw); diff --git a/engines/cruise/various.cpp b/engines/cruise/various.cpp index 60f04be485..599da22de3 100644 --- a/engines/cruise/various.cpp +++ b/engines/cruise/various.cpp @@ -30,15 +30,6 @@ namespace Cruise { uint16 remdo = 0; uint16 PCFadeFlag; -int16 readB16(void *ptr) { - int16 temp; - - temp = *(int16 *) ptr; - flipShort(&temp); - - return temp; -} - char *getText(int textIndex, int overlayIndex) { if (!overlayTable[overlayIndex].ovlData) { return NULL; diff --git a/engines/cruise/various.h b/engines/cruise/various.h index 0bdaab305c..9471464b32 100644 --- a/engines/cruise/various.h +++ b/engines/cruise/various.h @@ -33,8 +33,6 @@ namespace Cruise { extern uint16 remdo; extern uint16 PCFadeFlag; -int16 readB16(void *ptr); - int16 objInit(int ovlIdx, int param1, int param2); char *getText(int textIndex, int overlayIndex); } // End of namespace Cruise diff --git a/engines/cruise/volume.cpp b/engines/cruise/volume.cpp index 6bda10b704..fda3b6bc1f 100644 --- a/engines/cruise/volume.cpp +++ b/engines/cruise/volume.cpp @@ -110,8 +110,8 @@ int getVolumeDataEntry(volumeDataStruct *entry) { currentVolumeFile.read(&volumeNumberOfEntry, 2); currentVolumeFile.read(&volumeSizeOfEntry, 2); - flipShort(&volumeNumberOfEntry); - flipShort(&volumeSizeOfEntry); + bigEndianShortToNative(&volumeNumberOfEntry); + bigEndianShortToNative(&volumeSizeOfEntry); volumeNumEntry = volumeNumberOfEntry; @@ -136,9 +136,9 @@ int getVolumeDataEntry(volumeDataStruct *entry) { } for (i = 0; i < volumeNumEntry; i++) { - flipLong(&volumePtrToFileDescriptor[i].offset); - flipLong(&volumePtrToFileDescriptor[i].size); - flipLong(&volumePtrToFileDescriptor[i].extSize); + bigEndianLongToNative(&volumePtrToFileDescriptor[i].offset); + bigEndianLongToNative(&volumePtrToFileDescriptor[i].size); + bigEndianLongToNative(&volumePtrToFileDescriptor[i].extSize); } strcpy(currentBaseName, entry->ident); @@ -356,10 +356,10 @@ int16 readVolCnf(void) { } fileHandle.read(&numOfDisks, 2); - flipShort(&numOfDisks); + bigEndianShortToNative(&numOfDisks); fileHandle.read(&sizeHEntry, 2); - flipShort(&sizeHEntry); // size of one header entry - 20 bytes + bigEndianShortToNative(&sizeHEntry); // size of one header entry - 20 bytes for (i = 0; i < numOfDisks; i++) { // fread(&volumeData[i],20,1,fileHandle); @@ -368,16 +368,16 @@ int16 readVolCnf(void) { fileHandle.read(&volumeData[i].diskNumber, 2); fileHandle.read(&volumeData[i].size, 4); - flipShort(&volumeData[i].diskNumber); + bigEndianShortToNative(&volumeData[i].diskNumber); debug(1, "Disk number: %d", volumeData[i].diskNumber); - flipLong(&volumeData[i].size); + bigEndianLongToNative(&volumeData[i].size); } for (i = 0; i < numOfDisks; i++) { dataFileName *ptr; fileHandle.read(&volumeData[i].size, 4); - flipLong(&volumeData[i].size); + bigEndianLongToNative(&volumeData[i].size); ptr = (dataFileName *) mallocAndZero(volumeData[i].size); |