Files @ r10673:d53513e30781
Branch filter:

Location: cpp/openttd-patchpack/source/src/core/endian_func.hpp

translators
(svn r14977) -Update: WebTranslator2 update to 2009-01-10 18:44:17
arabic_egypt - 4 fixed by khaloofah (4)
brazilian_portuguese - 26 fixed by tucalipe (26)
bulgarian - 3 fixed by Ar4i (3)
catalan - 3 fixed by arnaullv (3)
croatian - 35 fixed by tifached (35)
czech - 52 fixed, 10 changed by Hadez (62)
danish - 4 fixed by ThomasA (4)
dutch - 6 fixed by Excel20 (4), habell (2)
finnish - 15 fixed by UltimateSephiroth (15)
french - 15 fixed by glx (15)
hungarian - 6 fixed by alyr (6)
indonesian - 6 fixed, 64 changed by fanioz (70)
italian - 3 fixed, 1 changed by lorenzodv (4)
portuguese - 6 fixed by rmrebelo (6)
romanian - 6 fixed by kkmic (6)
/* $Id$ */

/** @file endian_func.hpp Function to handling different endian machines. */

#ifndef ENDIAN_FUNC_H
#define ENDIAN_FUNC_H

#include "endian_type.hpp"
#include "bitmath_func.hpp"

/* Setup alignment and conversion macros */
#if TTD_ENDIAN == TTD_BIG_ENDIAN
	#define FROM_BE16(x) (x)
	#define FROM_BE32(x) (x)
	#define TO_BE16(x)   (x)
	#define TO_BE32(x)   (x)
	#define TO_BE32X(x)  (x)
	#define FROM_LE16(x) BSWAP16(x)
	#define FROM_LE32(x) BSWAP32(x)
	#define TO_LE16(x)   BSWAP16(x)
	#define TO_LE32(x)   BSWAP32(x)
	#define TO_LE32X(x)  BSWAP32(x)
#else
	#define FROM_BE16(x) BSWAP16(x)
	#define FROM_BE32(x) BSWAP32(x)
	#define TO_BE16(x)   BSWAP16(x)
	#define TO_BE32(x)   BSWAP32(x)
	#define TO_BE32X(x)  BSWAP32(x)
	#define FROM_LE16(x) (x)
	#define FROM_LE32(x) (x)
	#define TO_LE16(x)   (x)
	#define TO_LE32(x)   (x)
	#define TO_LE32X(x)  (x)
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */

static FORCEINLINE uint16 ReadLE16Aligned(const void *x)
{
	return FROM_LE16(*(const uint16*)x);
}

static FORCEINLINE uint16 ReadLE16Unaligned(const void *x)
{
#if OTTD_ALIGNMENT == 1
	return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
#else
	return FROM_LE16(*(const uint16*)x);
#endif /* OTTD_ALIGNMENT == 1 */
}

#endif /* ENDIAN_FUNC_HPP */