r1197 - in trunk: . code/tools/asm

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Oct 13 08:03:48 EDT 2007


Author: tma
Date: 2007-10-13 08:03:47 -0400 (Sat, 13 Oct 2007)
New Revision: 1197

Modified:
   trunk/Makefile
   trunk/code/tools/asm/cmdlib.c
   trunk/code/tools/asm/cmdlib.h
   trunk/code/tools/asm/q3asm.c
Log:
* Fix to qvm compilation on big endian architectures


Modified: trunk/Makefile
===================================================================
--- trunk/Makefile	2007-10-12 23:27:47 UTC (rev 1196)
+++ trunk/Makefile	2007-10-13 12:03:47 UTC (rev 1197)
@@ -44,13 +44,13 @@
 endif
 export PLATFORM
 
+ifeq ($(COMPILE_ARCH),powerpc)
+  COMPILE_ARCH=ppc
+endif
+
 ifndef ARCH
 ARCH=$(COMPILE_ARCH)
 endif
-
-ifeq ($(ARCH),powerpc)
-  ARCH=ppc
-endif
 export ARCH
 
 ifneq ($(PLATFORM),$(COMPILE_PLATFORM))

Modified: trunk/code/tools/asm/cmdlib.c
===================================================================
--- trunk/code/tools/asm/cmdlib.c	2007-10-12 23:27:47 UTC (rev 1196)
+++ trunk/code/tools/asm/cmdlib.c	2007-10-13 12:03:47 UTC (rev 1197)
@@ -975,13 +975,7 @@
 ============================================================================
 */
 
-#ifdef _SGI_SOURCE
-#define	__BIG_ENDIAN__
-#endif
-
-#ifdef __BIG_ENDIAN__
-
-short   LittleShort (short l)
+short   ShortSwap (short l)
 {
 	byte    b1,b2;
 
@@ -991,14 +985,8 @@
 	return (b1<<8) + b2;
 }
 
-short   BigShort (short l)
+int    LongSwap (int l)
 {
-	return l;
-}
-
-
-int    LittleLong (int l)
-{
 	byte    b1,b2,b3,b4;
 
 	b1 = l&255;
@@ -1009,89 +997,20 @@
 	return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
 }
 
-int    BigLong (int l)
-{
-	return l;
-}
+typedef union {
+    float	f;
+    unsigned int i;
+} _FloatByteUnion;
 
+float FloatSwap (const float *f) {
+	_FloatByteUnion out;
 
-float	LittleFloat (float l)
-{
-	union {byte b[4]; float f;} in, out;
-	
-	in.f = l;
-	out.b[0] = in.b[3];
-	out.b[1] = in.b[2];
-	out.b[2] = in.b[1];
-	out.b[3] = in.b[0];
-	
-	return out.f;
-}
+	out.f = *f;
+	out.i = LongSwap(out.i);
 
-float	BigFloat (float l)
-{
-	return l;
-}
-
-
-#else
-
-
-short   BigShort (short l)
-{
-	byte    b1,b2;
-
-	b1 = l&255;
-	b2 = (l>>8)&255;
-
-	return (b1<<8) + b2;
-}
-
-short   LittleShort (short l)
-{
-	return l;
-}
-
-
-int    BigLong (int l)
-{
-	byte    b1,b2,b3,b4;
-
-	b1 = l&255;
-	b2 = (l>>8)&255;
-	b3 = (l>>16)&255;
-	b4 = (l>>24)&255;
-
-	return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
-}
-
-int    LittleLong (int l)
-{
-	return l;
-}
-
-float	BigFloat (float l)
-{
-	union {byte b[4]; float f;} in, out;
-	
-	in.f = l;
-	out.b[0] = in.b[3];
-	out.b[1] = in.b[2];
-	out.b[2] = in.b[1];
-	out.b[3] = in.b[0];
-	
 	return out.f;
 }
 
-float	LittleFloat (float l)
-{
-	return l;
-}
-
-
-#endif
-
-
 //=======================================================
 
 

Modified: trunk/code/tools/asm/cmdlib.h
===================================================================
--- trunk/code/tools/asm/cmdlib.h	2007-10-12 23:27:47 UTC (rev 1196)
+++ trunk/code/tools/asm/cmdlib.h	2007-10-13 12:03:47 UTC (rev 1197)
@@ -115,14 +115,6 @@
 
 int 	ParseNum (const char *str);
 
-short	BigShort (short l);
-short	LittleShort (short l);
-int		BigLong (int l);
-int		LittleLong (int l);
-float	BigFloat (float l);
-float	LittleFloat (float l);
-
-
 char *COM_Parse (char *data);
 
 extern	char		com_token[1024];

Modified: trunk/code/tools/asm/q3asm.c
===================================================================
--- trunk/code/tools/asm/q3asm.c	2007-10-12 23:27:47 UTC (rev 1196)
+++ trunk/code/tools/asm/q3asm.c	2007-10-13 12:03:47 UTC (rev 1197)
@@ -20,6 +20,7 @@
 ===========================================================================
 */
 
+#include "../../qcommon/q_platform.h"
 #include "cmdlib.h"
 #include "mathlib.h"
 #include "../../qcommon/qfiles.h"
@@ -1356,6 +1357,7 @@
 	vmHeader_t	header;
 	FILE	*f;
 	int		headerSize;
+	int i;
 
 	report( "%i total errors\n", errorCount );
 
@@ -1400,6 +1402,13 @@
 
 	report( "Writing to %s\n", imageName );
 
+#ifdef Q3_BIG_ENDIAN
+	// byte swap the header
+	for ( i = 0 ; i < sizeof( vmHeader_t ) / 4 ; i++ ) {
+		((int *)&header)[i] = LittleLong( ((int *)&header)[i] );
+	}
+#endif
+
 	CreatePath( imageName );
 	f = SafeOpenWrite( imageName );
 	SafeWrite( f, &header, headerSize );




More information about the quake3-commits mailing list