1 #ifndef JBUS_COMMON_HPP 2 #define JBUS_COMMON_HPP 20 #ifndef DOXYGEN_SHOULD_SKIP_THIS 28 static inline T bswap16(T val)
31 return __builtin_bswap16(val);
33 return _byteswap_ushort(val);
35 return (val = (val << 8) | ((val >> 8) & 0xFF));
40 static inline T bswap32(T val)
43 return __builtin_bswap32(val);
45 return _byteswap_ulong(val);
47 val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
48 val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
54 static inline T bswap64(T val)
57 return __builtin_bswap64(val);
59 return _byteswap_uint64(val);
61 return ((val & 0xFF00000000000000ULL) >> 56) |
62 ((val & 0x00FF000000000000ULL) >> 40) |
63 ((val & 0x0000FF0000000000ULL) >> 24) |
64 ((val & 0x000000FF00000000ULL) >> 8) |
65 ((val & 0x00000000FF000000ULL) << 8) |
66 ((val & 0x0000000000FF0000ULL) << 24) |
67 ((val & 0x000000000000FF00ULL) << 40) |
68 ((val & 0x00000000000000FFULL) << 56);
73 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 74 static inline int16_t SBig(int16_t val) {
return bswap16(val);}
75 static inline uint16_t SBig(uint16_t val) {
return bswap16(val);}
76 static inline int32_t SBig(int32_t val) {
return bswap32(val);}
77 static inline uint32_t SBig(uint32_t val) {
return bswap32(val);}
78 static inline int64_t SBig(int64_t val) {
return bswap64(val);}
79 static inline uint64_t SBig(uint64_t val) {
return bswap64(val);}
80 static inline float SBig(
float val)
82 int32_t ival = bswap32(*((int32_t*)(&val)));
83 return *((
float*)(&ival));
85 static inline double SBig(
double val)
87 int64_t ival = bswap64(*((int64_t*)(&val)));
88 return *((
double*)(&ival));
91 #define SBIG(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ 92 | ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 ) 95 static inline int16_t SLittle(int16_t val) {
return val;}
96 static inline uint16_t SLittle(uint16_t val) {
return val;}
97 static inline int32_t SLittle(int32_t val) {
return val;}
98 static inline uint32_t SLittle(uint32_t val) {
return val;}
99 static inline int64_t SLittle(int64_t val) {
return val;}
100 static inline uint64_t SLittle(uint64_t val) {
return val;}
101 static inline float SLittle(
float val) {
return val;}
102 static inline double SLittle(
double val) {
return val;}
104 #define SLITTLE(q) (q) 107 static inline int16_t SLittle(int16_t val) {
return bswap16(val);}
108 static inline uint16_t SLittle(uint16_t val) {
return bswap16(val);}
109 static inline int32_t SLittle(int32_t val) {
return bswap32(val);}
110 static inline uint32_t SLittle(uint32_t val) {
return bswap32(val);}
111 static inline int64_t SLittle(int64_t val) {
return bswap64(val);}
112 static inline uint64_t SLittle(uint64_t val) {
return bswap64(val);}
113 static inline float SLittle(
float val)
115 int32_t ival = bswap32(*((int32_t*)(&val)));
116 return *((
float*)(&ival));
118 static inline double SLittle(
double val)
120 int64_t ival = bswap64(*((int64_t*)(&val)));
121 return *((
double*)(&ival));
124 #define SLITTLE(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ 125 | ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 ) 128 static inline int16_t SBig(int16_t val) {
return val;}
129 static inline uint16_t SBig(uint16_t val) {
return val;}
130 static inline int32_t SBig(int32_t val) {
return val;}
131 static inline uint32_t SBig(uint32_t val) {
return val;}
132 static inline int64_t SBig(int64_t val) {
return val;}
133 static inline uint64_t SBig(uint64_t val) {
return val;}
134 static inline float SBig(
float val) {
return val;}
135 static inline double SBig(
double val) {
return val;}
169 using FGBACallback = std::function<void(ThreadLocalEndpoint& endpoint, EJoyReturn status)>;
181 static constexpr
u64 GetGCTicksPerSec() {
return 486000000ull; }
188 #endif // JBUS_COMMON_HPP uint16_t u16
Definition: Common.hpp:14
int8_t s8
Definition: Common.hpp:11
Definition: Common.hpp:149
int64_t s64
Definition: Common.hpp:17
std::function< void(ThreadLocalEndpoint &endpoint, EJoyReturn status)> FGBACallback
Standard callback for asynchronous jbus::Endpoint APIs.
Definition: Common.hpp:169
Definition: Common.hpp:148
Definition: Common.hpp:160
void WaitGCTicks(u64 ticks)
Wait an approximate Dolphin tick duration (avoid using, it's rather inaccurate).
Definition: Common.hpp:154
Definition: Common.hpp:159
Definition: Common.hpp:153
uint8_t u8
Definition: Common.hpp:12
Definition: Common.hpp:152
EJStatFlags
Definition: Common.hpp:146
uint64_t u64
Definition: Common.hpp:18
int16_t s16
Definition: Common.hpp:13
int32_t s32
Definition: Common.hpp:15
u64 GetGCTicks()
Get host system's timebase scaled into Dolphin ticks.
EJoyReturn
Definition: Common.hpp:157
Definition: Common.hpp:163
Definition: Endpoint.hpp:16
uint32_t u32
Definition: Common.hpp:16
Definition: Common.hpp:161
void Initialize()
Initialize platform specifics of JBus library.
Definition: Common.hpp:151
Definition: Common.hpp:162
Definition: Common.hpp:150
Definition: Endpoint.hpp:272