[Scummvm-cvs-logs] SF.net SVN: scummvm:[41107] scummvm/trunk/engines/cruise

joostp at users.sourceforge.net joostp at users.sourceforge.net
Mon Jun 1 21:29:05 CEST 2009


Revision: 41107
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41107&view=rev
Author:   joostp
Date:     2009-06-01 19:29:04 +0000 (Mon, 01 Jun 2009)

Log Message:
-----------
Change flip[Short|Long] functions to bigEndian[Short|Long]ToNative to clarify that flipping only occurs on LE systems + some related cleanup.

Modified Paths:
--------------
    scummvm/trunk/engines/cruise/cruise_main.cpp
    scummvm/trunk/engines/cruise/ctp.cpp
    scummvm/trunk/engines/cruise/dataLoader.cpp
    scummvm/trunk/engines/cruise/decompiler.cpp
    scummvm/trunk/engines/cruise/font.cpp
    scummvm/trunk/engines/cruise/font.h
    scummvm/trunk/engines/cruise/function.cpp
    scummvm/trunk/engines/cruise/gfxModule.cpp
    scummvm/trunk/engines/cruise/linker.cpp
    scummvm/trunk/engines/cruise/mainDraw.cpp
    scummvm/trunk/engines/cruise/various.cpp
    scummvm/trunk/engines/cruise/various.h
    scummvm/trunk/engines/cruise/volume.cpp

Modified: scummvm/trunk/engines/cruise/cruise_main.cpp
===================================================================
--- scummvm/trunk/engines/cruise/cruise_main.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/cruise_main.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -613,14 +613,14 @@
 
 								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;
 

Modified: scummvm/trunk/engines/cruise/ctp.cpp
===================================================================
--- scummvm/trunk/engines/cruise/ctp.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/ctp.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -24,6 +24,7 @@
  */
 
 #include "cruise/cruise_main.h"
+#include "common/endian.h"
 #include "common/util.h"
 
 namespace Cruise {
@@ -242,20 +243,20 @@
 		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 @@
 	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 @@
 	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 @@
 		// 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 @@
 	//
 	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);

Modified: scummvm/trunk/engines/cruise/dataLoader.cpp
===================================================================
--- scummvm/trunk/engines/cruise/dataLoader.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/dataLoader.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -229,9 +229,7 @@
 }
 
 int getNumMaxEntiresInSet(uint8 *ptr) {
-	uint16 numEntries = *(uint16 *)(ptr + 4);
-	flipShort(&numEntries);
-
+	uint16 numEntries = READ_BE_UINT16(ptr + 4);
 	return numEntries;
 }
 
@@ -351,10 +349,8 @@
 	uint32 fontSize;
 
 	ptr2 += 4;
-	memcpy(&loadFileVar1, ptr2, 4);
+	loadFileVar1 = READ_BE_UINT32(ptr2);
 
-	flipLong(&loadFileVar1);
-
 	if (destIdx == -1) {
 		fileIndex = createResFileEntry(loadFileVar1, 1, loadFileVar1, 1);
 	} else {
@@ -365,8 +361,7 @@
 
 	memcpy(destPtr, ptr2, loadFileVar1);
 
-	memcpy(&fontSize, ptr2, 4);
-	flipLong(&fontSize);
+	fontSize = READ_BE_UINT32(ptr2);
 
 	if (destPtr != NULL) {
 		int32 i;
@@ -374,14 +369,14 @@
 
 		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);

Modified: scummvm/trunk/engines/cruise/decompiler.cpp
===================================================================
--- scummvm/trunk/engines/cruise/decompiler.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/decompiler.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -243,13 +243,10 @@
 }
 
 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 @@
 	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;
 }
 

Modified: scummvm/trunk/engines/cruise/font.cpp
===================================================================
--- scummvm/trunk/engines/cruise/font.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/font.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -121,14 +121,14 @@
 			// 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,36 +170,20 @@
 	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 bigEndianLongToNative(void *var) {
+	WRITE_UINT32(var, READ_BE_UINT32(var));
 }
 
-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 flipGen(void *var, int32 length) {
 	int i;
 	short int *varPtr = (int16 *) var;
 
 	for (i = 0; i < (length / 2); i++) {
-		flipShort(&varPtr[i]);
+		bigEndianShortToNative(&varPtr[i]);
 	}
 }
 

Modified: scummvm/trunk/engines/cruise/font.h
===================================================================
--- scummvm/trunk/engines/cruise/font.h	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/font.h	2009-06-01 19:29:04 UTC (rev 41107)
@@ -55,10 +55,8 @@
 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

Modified: scummvm/trunk/engines/cruise/function.cpp
===================================================================
--- scummvm/trunk/engines/cruise/function.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/function.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -143,7 +143,7 @@
 		for (long int i = 0; i < pop1; i++) {
 			int16* ptr = (int16*)(procBss + i * 2);
 			*ptr = param[i];
-			flipShort(ptr);
+			bigEndianShortToNative(ptr);
 		}
 	}
 

Modified: scummvm/trunk/engines/cruise/gfxModule.cpp
===================================================================
--- scummvm/trunk/engines/cruise/gfxModule.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/gfxModule.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -147,7 +147,7 @@
 	for (i = 0; i < 256; i++) {
 #define convertRatio 36.571428571428571428571428571429
 		uint16 atariColor = *ptr;
-		//flipShort(&atariColor);
+		//bigEndianShortToNative(&atariColor);
 		ptr ++;
 
 		R = (int)(convertRatio * ((atariColor & 0x700) >> 8));

Modified: scummvm/trunk/engines/cruise/linker.cpp
===================================================================
--- scummvm/trunk/engines/cruise/linker.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/linker.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -184,7 +184,7 @@
 									*(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 @@
 
 										*(int16 *)(ptr + 4) = ptrDest2->idx;
 
-										flipShort((int16 *)(ptr + 4));
+										bigEndianShortToNative((int16 *)(ptr + 4));
 									} else {
 										int var_4 = ptrDest2->var4;
 
@@ -215,7 +215,7 @@
 
 										*(int16 *)(ptrData + temp + 2) = ptrDest2->idx;
 
-										flipShort
+										bigEndianShortToNative
 										(
 										    (int16
 										     *)

Modified: scummvm/trunk/engines/cruise/mainDraw.cpp
===================================================================
--- scummvm/trunk/engines/cruise/mainDraw.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/mainDraw.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -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 @@
 
 		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 @@
 			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 @@
 			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);

Modified: scummvm/trunk/engines/cruise/various.cpp
===================================================================
--- scummvm/trunk/engines/cruise/various.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/various.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -30,15 +30,6 @@
 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;

Modified: scummvm/trunk/engines/cruise/various.h
===================================================================
--- scummvm/trunk/engines/cruise/various.h	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/various.h	2009-06-01 19:29:04 UTC (rev 41107)
@@ -33,8 +33,6 @@
 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

Modified: scummvm/trunk/engines/cruise/volume.cpp
===================================================================
--- scummvm/trunk/engines/cruise/volume.cpp	2009-06-01 19:11:56 UTC (rev 41106)
+++ scummvm/trunk/engines/cruise/volume.cpp	2009-06-01 19:29:04 UTC (rev 41107)
@@ -110,8 +110,8 @@
 	currentVolumeFile.read(&volumeNumberOfEntry, 2);
 	currentVolumeFile.read(&volumeSizeOfEntry, 2);
 
-	flipShort(&volumeNumberOfEntry);
-	flipShort(&volumeSizeOfEntry);
+	bigEndianShortToNative(&volumeNumberOfEntry);
+	bigEndianShortToNative(&volumeSizeOfEntry);
 
 	volumeNumEntry = volumeNumberOfEntry;
 
@@ -136,9 +136,9 @@
 	}
 
 	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 @@
 	}
 
 	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 @@
 		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);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list