Rearrange storage of reserved tracks for railway tiles
[openttd/fttd.git] / src / core / endian_func.hpp
blobab5b181500b77edfb4e4dbcc07a064299ed6c545
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file endian_func.hpp Function to handling different endian machines. */
12 #ifndef ENDIAN_FUNC_HPP
13 #define ENDIAN_FUNC_HPP
15 #include "endian_type.hpp"
16 #include "bitmath_func.hpp"
18 /* Setup alignment and conversion macros */
19 #if TTD_ENDIAN == TTD_BIG_ENDIAN
20 #define FROM_BE16(x) (x)
21 #define FROM_BE32(x) (x)
22 #define TO_BE16(x) (x)
23 #define TO_BE32(x) (x)
24 #define TO_BE32X(x) (x)
25 #define FROM_LE16(x) BSWAP16(x)
26 #define FROM_LE32(x) BSWAP32(x)
27 #define TO_LE16(x) BSWAP16(x)
28 #define TO_LE32(x) BSWAP32(x)
29 #define TO_LE32X(x) BSWAP32(x)
30 #else
31 #define FROM_BE16(x) BSWAP16(x)
32 #define FROM_BE32(x) BSWAP32(x)
33 #define TO_BE16(x) BSWAP16(x)
34 #define TO_BE32(x) BSWAP32(x)
35 #define TO_BE32X(x) BSWAP32(x)
36 #define FROM_LE16(x) (x)
37 #define FROM_LE32(x) (x)
38 #define TO_LE16(x) (x)
39 #define TO_LE32(x) (x)
40 #define TO_LE32X(x) (x)
41 #endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
43 static inline uint16 ReadLE16Aligned(const void *x)
45 return FROM_LE16(*(const uint16*)x);
48 static inline uint16 ReadLE16Unaligned(const void *x)
50 #if OTTD_ALIGNMENT == 1
51 return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
52 #else
53 return FROM_LE16(*(const uint16*)x);
54 #endif /* OTTD_ALIGNMENT == 1 */
57 #endif /* ENDIAN_FUNC_HPP */