|
20 | 20 | #ifndef __I_SWAP__
|
21 | 21 | #define __I_SWAP__
|
22 | 22 |
|
23 |
| -#ifdef FEATURE_SOUND |
24 |
| - |
25 |
| - |
26 | 23 | #ifdef __DJGPP__
|
27 | 24 |
|
28 | 25 |
|
|
35 | 32 | #else // __DJGPP__
|
36 | 33 |
|
37 | 34 |
|
38 |
| -#include <SDL_endian.h> |
39 |
| - |
40 |
| -// Endianess handling. |
41 |
| -// WAD files are stored little endian. |
42 |
| - |
43 |
| -// Just use SDL's endianness swapping functions. |
44 |
| - |
45 |
| -// These are deliberately cast to signed values; this is the behaviour |
46 |
| -// of the macros in the original source and some code relies on it. |
| 35 | +#if ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) |
| 36 | +#define SYS_LITTLE_ENDIAN |
| 37 | +#define SHORT(x) ((signed short) (x)) |
| 38 | +#define LONG(x) ((signed int) (x)) |
| 39 | +#elif ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ) |
| 40 | +#define SYS_BIG_ENDIAN |
47 | 41 |
|
48 |
| -#define SHORT(x) ((signed short) SDL_SwapLE16(x)) |
49 |
| -#define LONG(x) ((signed int) SDL_SwapLE32(x)) |
| 42 | +static inline unsigned short swapLE16(unsigned short val) { |
| 43 | + return ((val << 8) | (val >> 8)); |
| 44 | +} |
50 | 45 |
|
51 |
| -// Defines for checking the endianness of the system. |
| 46 | +static inline unsigned long swapLE32(unsigned long val) { |
| 47 | + return ((val << 24) | ((val << 8) & 0x00FF0000) | ((val >> 8) & 0x0000FF00) | (val >> 24)); |
| 48 | +} |
52 | 49 |
|
53 |
| -#if SDL_BYTEORDER == SYS_LIL_ENDIAN |
54 |
| -#define SYS_LITTLE_ENDIAN |
55 |
| -#elif SDL_BYTEORDER == SYS_BIG_ENDIAN |
56 |
| -#define SYS_BIG_ENDIAN |
| 50 | +#define SHORT(x) ((signed short) swapLE16(x)) |
| 51 | +#define LONG(x) ((signed int) swapLE32(x)) |
| 52 | +#else |
| 53 | +#error "Unknown byte order" |
57 | 54 | #endif
|
58 | 55 |
|
| 56 | + |
59 | 57 | // cosmito from lsdldoom
|
60 | 58 | #define doom_swap_s(x) \
|
61 | 59 | ((short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
|
62 | 60 | (((unsigned short int)(x) & 0xff00) >> 8)))
|
63 | 61 |
|
64 |
| - |
65 |
| -#if ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) |
| 62 | +#if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ) |
66 | 63 | #define doom_wtohs(x) doom_swap_s(x)
|
67 | 64 | #else
|
68 | 65 | #define doom_wtohs(x) (short int)(x)
|
|
72 | 69 | #endif // __DJGPP__
|
73 | 70 |
|
74 | 71 |
|
75 |
| -#else // FEATURE_SOUND |
76 |
| - |
77 |
| -#define SHORT(x) ((signed short) (x)) |
78 |
| -#define LONG(x) ((signed int) (x)) |
79 |
| - |
80 |
| -#define SYS_LITTLE_ENDIAN |
81 |
| - |
82 |
| -#endif /* FEATURE_SOUND */ |
83 |
| - |
84 | 72 | #endif
|
85 | 73 |
|
0 commit comments