Skip to content

Commit 44b4b1f

Browse files
authored
Merge pull request #21 from techflashYT/fix-byteswapping
[FIX] support byteswapping no matter what
2 parents 8706f5e + 1782268 commit 44b4b1f

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

doomgeneric/i_swap.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#ifndef __I_SWAP__
2121
#define __I_SWAP__
2222

23-
#ifdef FEATURE_SOUND
24-
25-
2623
#ifdef __DJGPP__
2724

2825

@@ -35,34 +32,34 @@
3532
#else // __DJGPP__
3633

3734

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
4741

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+
}
5045

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+
}
5249

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"
5754
#endif
5855

56+
5957
// cosmito from lsdldoom
6058
#define doom_swap_s(x) \
6159
((short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
6260
(((unsigned short int)(x) & 0xff00) >> 8)))
6361

64-
65-
#if ( SDL_BYTEORDER == SDL_BIG_ENDIAN )
62+
#if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
6663
#define doom_wtohs(x) doom_swap_s(x)
6764
#else
6865
#define doom_wtohs(x) (short int)(x)
@@ -72,14 +69,5 @@
7269
#endif // __DJGPP__
7370

7471

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-
8472
#endif
8573

0 commit comments

Comments
 (0)