XenevaOS
Loading...
Searching...
No Matches
XenevaOS
Process
Doomgeneric
i_swap.h
Go to the documentation of this file.
1
//
2
// Copyright(C) 1993-1996 Id Software, Inc.
3
// Copyright(C) 2005-2014 Simon Howard
4
//
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License
7
// as published by the Free Software Foundation; either version 2
8
// of the License, or (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// DESCRIPTION:
16
// Endianess handling, swapping 16bit and 32bit.
17
//
18
19
20
#ifndef __I_SWAP__
21
#define __I_SWAP__
22
23
#ifdef __DJGPP__
24
25
26
#define SHORT(x) ((signed short) (x))
27
#define LONG(x) ((signed int) (x))
28
29
#define SYS_LITTLE_ENDIAN
30
31
32
#else
// __DJGPP__
33
34
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
41
42
static
inline
unsigned
short
swapLE16(
unsigned
short
val) {
43
return
((val << 8) | (val >> 8));
44
}
45
46
static
inline
unsigned
long
swapLE32(
unsigned
long
val) {
47
return
((val << 24) | ((val << 8) & 0x00FF0000) | ((val >> 8) & 0x0000FF00) | (val >> 24));
48
}
49
50
#define SHORT(x) ((signed short) swapLE16(x))
51
#define LONG(x) ((signed int) swapLE32(x))
52
#else
53
#error "Unknown byte order"
54
#endif
55
56
57
// cosmito from lsdldoom
58
#define doom_swap_s(x) \
59
((short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
60
(((unsigned short int)(x) & 0xff00) >> 8)))
61
62
#if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
63
#define doom_wtohs(x) doom_swap_s(x)
64
#else
65
#define doom_wtohs(x) (short int)(x)
66
#endif
67
68
69
#endif
// __DJGPP__
70
71
72
#endif
73
Generated by
1.9.8