summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/asm/cmdlib.c101
-rw-r--r--src/tools/asm/cmdlib.h8
-rw-r--r--src/tools/asm/q3asm.c12
3 files changed, 22 insertions, 99 deletions
diff --git a/src/tools/asm/cmdlib.c b/src/tools/asm/cmdlib.c
index 69ce3ffd..ac088675 100644
--- a/src/tools/asm/cmdlib.c
+++ b/src/tools/asm/cmdlib.c
@@ -976,13 +976,7 @@ int ParseNum (const char *str)
============================================================================
*/
-#ifdef _SGI_SOURCE
-#define __BIG_ENDIAN__
-#endif
-
-#ifdef __BIG_ENDIAN__
-
-short LittleShort (short l)
+short ShortSwap (short l)
{
byte b1,b2;
@@ -992,13 +986,7 @@ short LittleShort (short l)
return (b1<<8) + b2;
}
-short BigShort (short l)
-{
- return l;
-}
-
-
-int LittleLong (int l)
+int LongSwap (int l)
{
byte b1,b2,b3,b4;
@@ -1010,89 +998,20 @@ int LittleLong (int l)
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
-int BigLong (int l)
-{
- return l;
-}
-
-
-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;
-}
-
-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;
-}
+typedef union {
+ float f;
+ unsigned int i;
+} _FloatByteUnion;
+float FloatSwap (const float *f) {
+ _FloatByteUnion out;
-int BigLong (int l)
-{
- byte b1,b2,b3,b4;
+ out.f = *f;
+ out.i = LongSwap(out.i);
- 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
-
-
//=======================================================
diff --git a/src/tools/asm/cmdlib.h b/src/tools/asm/cmdlib.h
index 36a5dfc0..3b2f2db4 100644
--- a/src/tools/asm/cmdlib.h
+++ b/src/tools/asm/cmdlib.h
@@ -116,14 +116,6 @@ void ExtractFileExtension( const char *path, char *dest );
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];
diff --git a/src/tools/asm/q3asm.c b/src/tools/asm/q3asm.c
index 4f4c9a37..1ac2939e 100644
--- a/src/tools/asm/q3asm.c
+++ b/src/tools/asm/q3asm.c
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
+#include "../../qcommon/q_platform.h"
#include "cmdlib.h"
#include "mathlib.h"
#include "../../qcommon/qfiles.h"
@@ -1401,6 +1402,17 @@ void WriteVmFile( void ) {
report( "Writing to %s\n", imageName );
+#ifdef Q3_BIG_ENDIAN
+ {
+ int i;
+
+ // 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 );