28 #ifndef AGS_SHARED_UTIL_BBOP_H 29 #define AGS_SHARED_UTIL_BBOP_H 31 #include "ags/shared/core/platform.h" 32 #include "ags/shared/core/types.h" 36 #if AGS_PLATFORM_ENDIAN_BIG || defined (TEST_BIGENDIAN) 37 #define BITBYTE_BIG_ENDIAN 46 #if defined (BITBYTE_BIG_ENDIAN) 47 kDefaultSystemEndianess = kBigEndian
49 kDefaultSystemEndianess = kLittleEndian
60 inline int FlagToFlag(
int value,
int flag1,
int flag2) {
61 return ((value & flag1) != 0) * flag2;
64 inline int FlagToNoFlag(
int value,
int flag1,
int flag2) {
65 return ((value & flag1) == 0) * flag2;
69 namespace BitByteOperations {
81 inline int16_t SwapBytesInt16(
const int16_t val) {
82 return ((val >> 8) & 0xFF) | ((val << 8) & 0xFF00);
85 inline int32_t SwapBytesInt32(
const int32_t val) {
86 return ((val >> 24) & 0xFF) | ((val >> 8) & 0xFF00) | ((val << 8) & 0xFF0000) | ((val << 24) & 0xFF000000);
89 inline int64_t SwapBytesInt64(
const int64_t val) {
90 return ((val >> 56) & 0xFF) | ((val >> 40) & 0xFF00) | ((val >> 24) & 0xFF0000) |
91 ((val >> 8) & 0xFF000000) | ((val << 8) & 0xFF00000000LL) |
92 ((val << 24) & 0xFF0000000000LL) | ((val << 40) & 0xFF000000000000LL) | ((val << 56) & 0xFF00000000000000LL);
95 inline float SwapBytesFloat(
const float val) {
97 swap.val.i32 = SwapBytesInt32(swap.val.i32);
101 inline int16_t Int16FromLE(
const int16_t val) {
102 #if defined (BITBYTE_BIG_ENDIAN) 103 return SwapBytesInt16(val);
109 inline int32_t Int32FromLE(
const int32_t val) {
110 #if defined (BITBYTE_BIG_ENDIAN) 111 return SwapBytesInt32(val);
117 inline int64_t Int64FromLE(
const int64_t val) {
118 #if defined (BITBYTE_BIG_ENDIAN) 119 return SwapBytesInt64(val);
125 inline float FloatFromLE(
const float val) {
126 #if defined (BITBYTE_BIG_ENDIAN) 127 return SwapBytesFloat(val);
133 inline int16_t Int16FromBE(
const int16_t val) {
134 #if defined (BITBYTE_BIG_ENDIAN) 137 return SwapBytesInt16(val);
141 inline int32_t Int32FromBE(
const int32_t val) {
142 #if defined (BITBYTE_BIG_ENDIAN) 145 return SwapBytesInt32(val);
149 inline int64_t Int64FromBE(
const int64_t val) {
150 #if defined (BITBYTE_BIG_ENDIAN) 153 return SwapBytesInt64(val);
157 inline float FloatFromBE(
const float val) {
158 #if defined (BITBYTE_BIG_ENDIAN) 161 return SwapBytesFloat(val);
169 namespace BBOp = BitByteOperations;
Definition: achievements_tables.h:27