[Scummvm-cvs-logs] SF.net SVN: scummvm: [21035] tools/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Mar 3 06:36:03 CET 2006


Revision: 21035
Author:   fingolfin
Date:     2006-03-03 06:35:18 -0800 (Fri, 03 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm?rev=21035&view=rev

Log Message:
-----------
- Removed the TO_* macros by using the READ_ functions instead
- Removed SCUMM_BIG_ENDIAN, as it was only needed for the TO_* macros
  -> no more problems on big endian systems because somebody forgot to
     manually specify that flag

Modified Paths:
--------------
    tools/trunk/Makefile
    tools/trunk/compress_scumm_san.cpp
    tools/trunk/compress_sword1.c
    tools/trunk/dekyra.cpp
    tools/trunk/descumm-common.cpp
    tools/trunk/descumm-tool.cpp
    tools/trunk/extract_kyra.cpp
    tools/trunk/util.h
Modified: tools/trunk/Makefile
===================================================================
--- tools/trunk/Makefile	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/Makefile	2006-03-03 14:35:18 UTC (rev 21035)
@@ -15,9 +15,6 @@
 # -Wconversion
 CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings 
 
-# Uncomment this if you are on a big endian system
-# CFLAGS += -DSCUMM_BIG_ENDIAN
-
 TARGETS := \
 	compress_kyra$(EXEEXT) \
 	compress_queen$(EXEEXT) \

Modified: tools/trunk/compress_scumm_san.cpp
===================================================================
--- tools/trunk/compress_scumm_san.cpp	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/compress_scumm_san.cpp	2006-03-03 14:35:18 UTC (rev 21035)
@@ -191,8 +191,7 @@
 
 	while (bsize > 0) {
 		if (_IACTpos >= 2) {
-			int32 len = *(uint16 *)(_IACToutput);
-			len = TO_BE_16(len) + 2;
+			int32 len = READ_BE_UINT16(_IACToutput) + 2;
 			len -= _IACTpos;
 			if (len > bsize) {
 				memcpy(_IACToutput + _IACTpos, d_src, bsize);

Modified: tools/trunk/compress_sword1.c
===================================================================
--- tools/trunk/compress_sword1.c	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/compress_sword1.c	2006-03-03 14:35:18 UTC (rev 21035)
@@ -350,20 +350,20 @@
 	int16 *srcData, *dstData, *dstPos;
 	uint32 headerPos = 0;
 	int16 length, cnt;
-	uint8 *fBuf = (uint8*)malloc(cSize);
+	uint8 *fBuf = (uint8 *)malloc(cSize);
 	fseek(clu, idx, SEEK_SET);
 	assert(fread(fBuf, 1, cSize, clu) == cSize);
 	while ((READ_BE_UINT32(fBuf + headerPos) != 'data') && (headerPos < 100))
 		headerPos++;
 	if (headerPos < 100) {
-		resSize = TO_LE_32(*(uint32*)(fBuf + headerPos + 4)) >> 1;
-		srcData = (int16*)(fBuf + headerPos + 8);
-		dstData = (int16*)malloc(resSize * 2);
+		resSize = READ_LE_UINT32(fBuf + headerPos + 4) >> 1;
+		srcData = (int16 *)(fBuf + headerPos + 8);
+		dstData = (int16 *)malloc(resSize * 2);
 		srcPos = 0;
 		dstPos = dstData;
 		cSize = (cSize - (headerPos + 8)) / 2;
 		while (srcPos < cSize) {
-			length = (int16)TO_LE_16(*(int16*)(srcData + srcPos));
+			length = (int16)READ_LE_UINT16(srcData + srcPos);
 			srcPos++;
 			if (length < 0) {
 				length = -length;

Modified: tools/trunk/dekyra.cpp
===================================================================
--- tools/trunk/dekyra.cpp	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/dekyra.cpp	2006-03-03 14:35:18 UTC (rev 21035)
@@ -123,7 +123,7 @@
 			text_size += text_size % 2 != 0 ? 1 : 0;
 			
 			_chunks[kText]._data = _scriptFile + ftell(script);
-			_chunks[kText]._size = TO_BE_16(*((uint16*)_chunks[kText]._data)) >> 1;
+			_chunks[kText]._size = READ_BE_UINT16(_chunks[kText]._data) >> 1;
 			_chunks[kText]._additional = _chunks[kText]._data + (_chunks[kText]._size << 1);				
 			fseek(script, text_size, SEEK_CUR);
 		} else if (!strcmp((char*)chunkName, "DATA")) {
@@ -153,10 +153,10 @@
 	printf("TEXT chunk:\n");
 	// first is size
 	for (uint32 pos = 1; pos < (_chunks[kText]._size << 1); ++pos) {
-		if (TO_BE_16(((uint16*)_chunks[kText]._data)[pos]) >= _scriptSize) {
+		if (READ_BE_UINT16(_chunks[kText]._data + 2*pos) >= _scriptSize) {
 			break;
 		}
-		uint32 startoffset = TO_BE_16(((uint16*)_chunks[kText]._data)[pos]);
+		uint32 startoffset = READ_BE_UINT16(_chunks[kText]._data + 2*pos);
 		printf("%d(at %d) : %s\n", pos, startoffset, (char*)(_chunks[kText]._data + startoffset));
 	}
 }
@@ -406,7 +406,7 @@
 	memset(_registers, 0, sizeof(_registers));
 	
 	_stackPos = 0;
-	_instructionPos = (TO_BE_16(((uint16*)_chunks[kEmc2Ordr]._data)[script]) << 1);	
+	_instructionPos = (READ_BE_UINT16(_chunks[kEmc2Ordr]._data + 2*script) << 1);	
 	uint8* script_start = _chunks[kData]._data;
 	bool gotArgument = true;
 	
@@ -431,11 +431,13 @@
 			_argument = *(script_start + _instructionPos++);
 		} else if (_currentCommand & 0x20) {
 			_instructionPos++;
-				
-			uint16 tmp = *(uint16*)(script_start + _instructionPos);
+			
+			// FIXME: I am not 100% sure if this code is correct (after my
+			// 'endian macro' changes), somebody please double check.
+			uint16 tmp = READ_BE_UINT16(script_start + _instructionPos);
 			tmp &= 0xFF7F;
 			
-			_argument = TO_BE_16(tmp);
+			_argument = tmp;
 			_instructionPos += 2;
 		} else {
 			gotArgument = false;
@@ -496,9 +498,10 @@
 	uint32 pos = 0xFFFFFFFE;
 	
 	for (uint32 tmp = 0; tmp < _chunks[kEmc2Ordr]._size; ++tmp) {
-		if ((uint32)((TO_BE_16(_chunks[kEmc2Ordr]._data[tmp]) << 1) + 2) > current_start &&
-			(uint32)((TO_BE_16(_chunks[kEmc2Ordr]._data[tmp]) << 1) + 2) < pos) {
-			pos = ((TO_BE_16(_chunks[kEmc2Ordr]._data[tmp]) << 1) + 2);
+		uint32 tmp2 = READ_BE_UINT16(_chunks[kEmc2Ordr]._data + tmp);
+		tmp2 = (tmp2 << 1) + 2;
+		if (tmp2 > current_start && tmp2 < pos) {
+			pos = tmp2;
 		}
 	}
 	
@@ -519,7 +522,7 @@
 	if (index < 0 || (uint32)index >= _chunks[kText]._size)
 		return 0;
 	
-	uint16 offset = TO_BE_16(((uint16*)_chunks[kText]._data)[index]);
+	uint16 offset = READ_BE_UINT16(_chunks[kText]._data + 2*index);
 	return (const char *)(_chunks[kText]._data + offset);
 }
 

Modified: tools/trunk/descumm-common.cpp
===================================================================
--- tools/trunk/descumm-common.cpp	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/descumm-common.cpp	2006-03-03 14:35:18 UTC (rev 21035)
@@ -77,10 +77,10 @@
 	int i;
 
 	if (scriptVersion == 8) {
-		i = (int32)TO_LE_32(*((uint32 *)cur_pos));
+		i = (int32)READ_LE_UINT32(cur_pos);
 		cur_pos += 4;
 	} else {
-		i = (int16)TO_LE_16(*((uint16 *)cur_pos));
+		i = (int16)READ_LE_UINT16(cur_pos);
 		cur_pos += 2;
 	}
 	return i;
@@ -189,10 +189,10 @@
 	// jump right behind a regular jump, then whether that jump is targeting us.
 	if (scriptVersion == 8) {
 		p->isWhile = (*(byte*)(org_pos+to-5) == g_jump_opcode);
-		i = (int32)TO_LE_32(*(int32*)(org_pos+to-4));
+		i = (int32)READ_LE_UINT32(org_pos+to-4);
 	} else {
 		p->isWhile = (*(byte*)(org_pos+to-3) == g_jump_opcode);
-		i = (int16)TO_LE_16(*(int16*)(org_pos+to-2));
+		i = (int16)READ_LE_UINT16(org_pos+to-2);
 	}
 	
 	p->isWhile = p->isWhile && (offs_of_line == (int)to + i);
@@ -261,9 +261,9 @@
 			return false;							/* Invalid jump */
 	
 		if (scriptVersion == 8)
-			k = to + TO_LE_32(*(int32*)(org_pos + k + 1));
+			k = to + READ_LE_UINT32(org_pos + k + 1);
 		else
-			k = to + TO_LE_16(*(int16*)(org_pos + k + 1));
+			k = to + READ_LE_UINT16(org_pos + k + 1);
 	
 		if (k != elseto)
 			return false;							/* Not an ifelse */

Modified: tools/trunk/descumm-tool.cpp
===================================================================
--- tools/trunk/descumm-tool.cpp	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/descumm-tool.cpp	2006-03-03 14:35:18 UTC (rev 21035)
@@ -85,7 +85,7 @@
 	printf("Events:\n");
 
 	while ((code = *p++) != 0) {
-		offset = TO_LE_16(*(uint16 *)p);
+		offset = READ_LE_UINT16(p);
 		p += 2;
 		printf("  %2X - %.4X\n", code, offset);
 		if (minOffset > offset)
@@ -104,7 +104,7 @@
 	printf("Events:\n");
 
 	while ((code = *p++) != 0) {
-		offset = TO_LE_16(*(uint16 *)p);
+		offset = READ_LE_UINT16(p);
 		p += 2;
 		printf("  %2X - %.4X\n", code, offset);
 		if (minOffset > offset)
@@ -121,8 +121,8 @@
 	int minOffset = 255;
 	
 	ptr = (uint32 *)p;
-	while ((code = TO_LE_32(*ptr++)) != 0) {
-		offset = TO_LE_32(*ptr++);
+	while ((code = READ_LE_UINT32(ptr++)) != 0) {
+		offset = READ_LE_UINT16(ptr++);
 		printf("  %2d - %.4X\n", code, offset);
 		if (minOffset > offset)
 			minOffset = offset;
@@ -278,7 +278,7 @@
 			return 1;
 		}
 		// Hack to detect verb script: first 4 bytes should be file length
-		if (TO_LE_32(*((uint32 *)mem)) == size_of_code) {
+		if (READ_LE_UINT32(mem) == size_of_code) {
 			if (scriptVersion <= 2)
 				offs_of_line = skipVerbHeader_V12(mem);
 			else
@@ -292,12 +292,12 @@
 			return 1;
 		}
 	
-		switch (TO_BE_32(*((uint32 *)mem))) {
+		switch (READ_BE_UINT32(mem)) {
 		case 'LSC2':
 			if (size_of_code < 13) {
 				printf("File too small to be a local script\n");
 			}
-			printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));
+			printf("Script# %d\n", READ_LE_UINT32(mem+8));
 			mem += 12;
 			break;											/* Local script */
 		case 'LSCR':
@@ -305,13 +305,13 @@
 				if (size_of_code < 13) {
 					printf("File too small to be a local script\n");
 				}
-				printf("Script# %d\n", TO_LE_32(*((int32 *)(mem+8))));
+				printf("Script# %d\n", READ_LE_UINT32(mem+8));
 				mem += 12;
 			} else if (scriptVersion == 7) {
 				if (size_of_code < 11) {
 					printf("File too small to be a local script\n");
 				}
-				printf("Script# %d\n", TO_LE_16(*((int16 *)(mem+8))));
+				printf("Script# %d\n", READ_LE_UINT16(mem+8));
 				mem += 10;
 			} else {
 				if (size_of_code < 10) {
@@ -346,7 +346,7 @@
 			printf("File too small to be a script\n");
 			return 1;
 		}
-		switch (TO_BE_16(*((uint16 *)mem + 2))) {
+		switch (READ_BE_UINT16(mem + 2)) {
 		case 'LS':
 			printf("Script# %d\n", (byte)mem[6]);
 			mem += 7;

Modified: tools/trunk/extract_kyra.cpp
===================================================================
--- tools/trunk/extract_kyra.cpp	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/extract_kyra.cpp	2006-03-03 14:35:18 UTC (rev 21035)
@@ -90,7 +90,7 @@
 void PAKFile::drawFilelist(void) {
 	const char* currentName = 0;
 	
-	uint32 startoffset = TO_LE_32(*(uint32 *)_buffer);
+	uint32 startoffset = READ_LE_UINT32(_buffer);
 	uint32 endoffset = 0;
 	uint8* position = _buffer + 4;
 	
@@ -103,7 +103,7 @@
 
 		position += strlgt + 1;
 		// scip offset
-		endoffset = TO_LE_32(*(uint32 *)position);
+		endoffset = READ_LE_UINT32(position);
 		if (endoffset > _filesize) {
 			endoffset = _filesize;
 		} else if (endoffset == 0) {
@@ -124,7 +124,7 @@
 void PAKFile::outputFile(const char* file) {
 	const char* currentName = 0;
 	
-	uint32 startoffset = TO_LE_32(*(uint32 *)_buffer);
+	uint32 startoffset = READ_LE_UINT32(_buffer);
 	uint32 endoffset = 0;
 	uint8* position = _buffer + 4;
 	
@@ -137,7 +137,7 @@
 
 		position += strlgt + 1;
 		// scip offset
-		endoffset = TO_LE_32(*(uint32 *)position);
+		endoffset = READ_LE_UINT32(position);
 		if (endoffset > _filesize) {
 			endoffset = _filesize;
 		} else if (endoffset == 0) {
@@ -167,7 +167,7 @@
 void PAKFile::outputAllFiles(void) {
 	const char* currentName = 0;
 	
-	uint32 startoffset = TO_LE_32(*(uint32 *)_buffer);
+	uint32 startoffset = READ_LE_UINT32(_buffer);
 	uint32 endoffset = 0;
 	uint8* position = _buffer + 4;
 	
@@ -180,7 +180,7 @@
 
 		position += strlgt + 1;
 		// scip offset
-		endoffset = TO_LE_32(*(uint32 *)position);
+		endoffset = READ_LE_UINT32(position);
 		if (endoffset > _filesize) {
 			endoffset = _filesize;
 		} else if (endoffset == 0) {

Modified: tools/trunk/util.h
===================================================================
--- tools/trunk/util.h	2006-03-03 14:29:28 UTC (rev 21034)
+++ tools/trunk/util.h	2006-03-03 14:35:18 UTC (rev 21035)
@@ -78,18 +78,6 @@
 	return ((a >> 8) & 0xFF) | ((a << 8) & 0xFF00);
 }
 
-#if defined(SCUMM_BIG_ENDIAN)
-#define TO_BE_32(a) (a)
-#define TO_BE_16(a) (a)
-#define TO_LE_32(a) SWAP_32(a)
-#define TO_LE_16(a) SWAP_16(a)
-#else
-#define TO_BE_32(a) SWAP_32(a)
-#define TO_BE_16(a) SWAP_16(a)
-#define TO_LE_32(a) (a)
-#define TO_LE_16(a) (a)
-#endif
-
 #define FORCEINLINE static inline
 
 FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) {







More information about the Scummvm-git-logs mailing list