summaryrefslogtreecommitdiff
blob: 02c3d578a69c66f4759fd8d53167c5afd4830f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
--- egoboo/code/egobootypedef.h.orig	2004-02-15 15:19:03.000000000 +0100
+++ egoboo/code/egobootypedef.h	2004-02-15 15:23:58.000000000 +0100
@@ -71,13 +71,49 @@
 typedef Sint32			LONG;
 typedef Uint32			DWORD;
 typedef struct lin_RECT { LONG left; LONG right; LONG top; LONG bottom; } RECT;
+
+#ifdef __powerpc__
+#define _BIG_ENDIAN
+
+/*
+ * __lwbrx - Load Word Byte-Reverse Indexed
+ *
+ *   int __lwbrx(void *, int);
+ */
+#define __lwbrx(base, index)    \
+	({ unsigned long lwbrxResult; \
+	__asm__ volatile ("lwbrx %0, %1, %2" : "=r" (lwbrxResult) : "b%" (index), "r" (base) : "memory"); \
+	/*return*/ lwbrxResult; })
+
+static float LoadFloatByteswapped( float *ptr );
+static inline float LoadFloatByteswapped( float *ptr )
+{
+	union {
+		float f;
+		long l;
+	} data;
+
+	/*Load byteswapped and store to the stack*/
+	data.l = __lwbrx( ptr, 0 ); 
+
+	/*Return the result*/
+	return data.f;
+}
+#elif __i386__
 #define _LITTLE_ENDIAN
+#else
+#define _BIG_ENDIAN
+#error You have to implement LoadFloatByteswapped on your architecture!
+#endif
+
 #define LE32bitToHost( pData, pNumByte ) pData
 #define BE32bitToHost( pData, pNumByte ) pData
 #define LE16bitToHost( pData, pNumByte ) pData
 #define BE16bitToHost( pData, pNumByte ) pData
 #define EndianChange32bit( pData, pNumByte ) pData
 #define EndianChange16bit( pData, pNumByte ) pData
+
+
 #endif
 
 
--- egoboo/code/game.c.orig	2004-02-15 15:19:07.000000000 +0100
+++ egoboo/code/game.c	2004-02-15 15:19:19.000000000 +0100
@@ -10,6 +10,7 @@
 #define TITLE "Boo"
 
 #define RELEASE(x) if (x) {x->Release(); x=NULL;}
+#include <SDL/SDL_endian.h>
 
 //---------------------------------------------------------------------------------------------
 char *os_cvrt_filename(char *name, char ch)
@@ -2203,7 +2204,7 @@
     #ifdef _LITTLE_ENDIAN
     iTmp = ipIntPointer[0];
     #else
-    iTmp = EndianS32_LtoB( ipIntPointer[0] );
+    iTmp = SDL_SwapLE32( ipIntPointer[0] );
     #endif
     if(iTmp != MD2START ) return FALSE;
     
@@ -2284,14 +2285,14 @@
     #ifdef _LITTLE_ENDIAN
     int iNumCommands = ipIntPointer[9];
     #else
-    int iNumCommands = EndianS32_LtoB( ipIntPointer[9] );
+    int iNumCommands = SDL_SwapLE32( ipIntPointer[9] );
     #endif
     
 	// Offset (in DWORDS) from the start of the file to the gl command list.
 	#ifdef _LITTLE_ENDIAN
 	int iCommandOffset = ipIntPointer[15]>>2;	
 	#else
-	int iCommandOffset = EndianS32_LtoB( ipIntPointer[15] )>>2;
+	int iCommandOffset = SDL_SwapLE32( ipIntPointer[15] )>>2;
 	#endif
 	
     // Read in each command
@@ -2306,7 +2307,7 @@
         #ifdef _LITTLE_ENDIAN
         iNumVertices = ipIntPointer[iCommandOffset]; iCommandOffset++; cnt++;
         #else
-        iNumVertices = EndianS32_LtoB( ipIntPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
+        iNumVertices = SDL_SwapLE32( ipIntPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
         #endif
         if(iNumVertices != 0)
         {
@@ -2337,7 +2338,7 @@
                 #else
                 fTmpu = LoadFloatByteswapped( &fpFloatPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
                 fTmpv = LoadFloatByteswapped( &fpFloatPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
-                iTmp = EndianS32_LtoB( ipIntPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
+                iTmp = SDL_SwapLE32( ipIntPointer[iCommandOffset] );  iCommandOffset++;  cnt++;
                 #endif
                 madcommandu[modelindex][entry] = fTmpu-(.5/64); // GL doesn't align correctly
                 madcommandv[modelindex][entry] = fTmpv-(.5/64); // with D3D
@@ -2373,9 +2374,9 @@
     iNumFrames = ipIntPointer[10];
     iFrameOffset = ipIntPointer[14]>>2;
     #else
-    iNumVertices = EndianS32_LtoB( ipIntPointer[6] );
-    iNumFrames = EndianS32_LtoB( ipIntPointer[10] );
-    iFrameOffset = EndianS32_LtoB( ipIntPointer[14] )>>2;
+    iNumVertices = SDL_SwapLE32( ipIntPointer[6] );
+    iNumFrames = SDL_SwapLE32( ipIntPointer[10] );
+    iFrameOffset = SDL_SwapLE32( ipIntPointer[14] )>>2;
     #endif
 
 
@@ -2433,9 +2434,9 @@
     iNumFrames = ipIntPointer[10];
     iFrameOffset = ipIntPointer[14]>>2;
     #else
-    iNumVertices = EndianS32_LtoB( ipIntPointer[6] );
-    iNumFrames = EndianS32_LtoB( ipIntPointer[10] );
-    iFrameOffset = EndianS32_LtoB( ipIntPointer[14] )>>2;
+    iNumVertices = SDL_SwapLE32( ipIntPointer[6] );
+    iNumFrames = SDL_SwapLE32( ipIntPointer[10] );
+    iFrameOffset = SDL_SwapLE32( ipIntPointer[14] )>>2;
     #endif
 
 
@@ -3270,10 +3271,10 @@
     fread(&itmp, 4, 1, fileread);  meshsizex = itmp;
     fread(&itmp, 4, 1, fileread);  meshsizey = itmp;
     #else
-    fread(&itmp, 4, 1, fileread);  if( ( int )EndianS32_LtoB( itmp ) != MAPID) return FALSE;
-    fread(&itmp, 4, 1, fileread);  numvert = ( int )EndianS32_LtoB( itmp );
-    fread(&itmp, 4, 1, fileread);  meshsizex = ( int )EndianS32_LtoB( itmp );
-    fread(&itmp, 4, 1, fileread);  meshsizey = ( int )EndianS32_LtoB( itmp );
+    fread(&itmp, 4, 1, fileread);  if( ( int )SDL_SwapLE32( itmp ) != MAPID) return FALSE;
+    fread(&itmp, 4, 1, fileread);  numvert = ( int )SDL_SwapLE32( itmp );
+    fread(&itmp, 4, 1, fileread);  meshsizex = ( int )SDL_SwapLE32( itmp );
+    fread(&itmp, 4, 1, fileread);  meshsizey = ( int )SDL_SwapLE32( itmp );
     #endif
     
     numfan = meshsizex*meshsizey;
@@ -3299,9 +3300,9 @@
       meshfx[fan] = itmp>>16;
       meshtile[fan] = itmp;
       #else
-      meshtype[fan] = EndianS32_LtoB( itmp )>>24;
-      meshfx[fan] = EndianS32_LtoB( itmp )>>16;
-      meshtile[fan] = EndianS32_LtoB( itmp );
+      meshtype[fan] = SDL_SwapLE32( itmp )>>24;
+      meshfx[fan] = SDL_SwapLE32( itmp )>>16;
+      meshtile[fan] = SDL_SwapLE32( itmp );
       #endif
       
       fan++;
@@ -3315,7 +3316,7 @@
       #ifdef _LITTLE_ENDIAN
       meshtwist[fan] = itmp;
       #else
-      meshtwist[fan] = EndianS32_LtoB( itmp );
+      meshtwist[fan] = SDL_SwapLE32( itmp );
       #endif
       
       fan++;
@@ -3387,7 +3388,7 @@
         #ifdef _LITTLE_ENDIAN
         meshvrta[cnt] = itmp;
         #else
-        meshvrta[cnt] = EndianS32_LtoB( itmp );
+        meshvrta[cnt] = SDL_SwapLE32( itmp );
         #endif
         meshvrtl[cnt] = 0;