author | peter1138 |
Tue, 22 Jan 2008 07:27:06 +0000 | |
changeset 8374 | 7a1b6c89cb89 |
parent 8135 | 2373c1e0e9bc |
child 9111 | 48ce04029fe4 |
permissions | -rw-r--r-- |
8113
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
2 |
|
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
3 |
/** @file endian_func.hpp */ |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
4 |
|
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
5 |
#ifndef ENDIAN_FUNC_H |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
6 |
#define ENDIAN_FUNC_H |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
7 |
|
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
8 |
#include "bitmath_func.hpp" |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
9 |
|
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
10 |
#if defined(ARM) || defined(__arm__) || defined(__alpha__) |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
11 |
#define OTTD_ALIGNMENT |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
12 |
#endif |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
13 |
|
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
14 |
/* Windows has always LITTLE_ENDIAN */ |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
15 |
#if defined(WIN32) || defined(__OS2__) || defined(WIN64) |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
16 |
#define TTD_LITTLE_ENDIAN |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
17 |
#elif !defined(TESTING) |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
18 |
/* Else include endian[target/host].h, which has the endian-type, autodetected by the Makefile */ |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
19 |
#if defined(STRGEN) |
8135
2373c1e0e9bc
(svn r11697) -Fix [FS#1585]: strgen did not (always) compile properly.
rubidium
parents:
8133
diff
changeset
|
20 |
#include "endian_host.h" |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
21 |
#else |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
22 |
#include "endian_target.h" |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
23 |
#endif |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
24 |
#endif /* WIN32 || __OS2__ || WIN64 */ |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
25 |
|
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
26 |
/* Setup alignment and conversion macros */ |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
27 |
#if defined(TTD_BIG_ENDIAN) |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
28 |
#define FROM_BE16(x) (x) |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
29 |
#define FROM_BE32(x) (x) |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
30 |
#define TO_BE16(x) (x) |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
31 |
#define TO_BE32(x) (x) |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
32 |
#define TO_BE32X(x) (x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
33 |
#define FROM_LE16(x) BSWAP16(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
34 |
#define FROM_LE32(x) BSWAP32(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
35 |
#define TO_LE16(x) BSWAP16(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
36 |
#define TO_LE32(x) BSWAP32(x) |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
37 |
#define TO_LE32X(x) BSWAP32(x) |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
38 |
#else |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
39 |
#define FROM_BE16(x) BSWAP16(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
40 |
#define FROM_BE32(x) BSWAP32(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
41 |
#define TO_BE16(x) BSWAP16(x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
42 |
#define TO_BE32(x) BSWAP32(x) |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
43 |
#define TO_BE32X(x) BSWAP32(x) |
8133
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
44 |
#define FROM_LE16(x) (x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
45 |
#define FROM_LE32(x) (x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
46 |
#define TO_LE16(x) (x) |
3ab8eaf85ca0
(svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents:
8132
diff
changeset
|
47 |
#define TO_LE32(x) (x) |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
48 |
#define TO_LE32X(x) (x) |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
49 |
#endif /* TTD_BIG_ENDIAN */ |
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
50 |
|
8113
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
51 |
static inline uint16 ReadLE16Aligned(const void *x) |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
52 |
{ |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
53 |
return FROM_LE16(*(const uint16*)x); |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
54 |
} |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
55 |
|
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
56 |
static inline uint16 ReadLE16Unaligned(const void *x) |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
57 |
{ |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
58 |
#ifdef OTTD_ALIGNMENT |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
59 |
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8; |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
60 |
#else |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
61 |
return FROM_LE16(*(const uint16*)x); |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
62 |
#endif |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
63 |
} |
31b7784db761
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
diff
changeset
|
64 |
|
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8113
diff
changeset
|
65 |
#endif /* ENDIAN_FUNC_HPP */ |