| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef __RARCH_MISCELLANEOUS_H |
| 24 |
#define __RARCH_MISCELLANEOUS_H |
| 25 |
|
| 26 |
#include <stdint.h> |
| 27 |
#include <math.h> |
| 28 |
|
| 29 |
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__) |
| 30 |
#include <sys/timer.h> |
| 31 |
#elif defined(XENON) |
| 32 |
#include <time/time.h> |
| 33 |
#elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__) |
| 34 |
#include <unistd.h> |
| 35 |
#elif defined(PSP) |
| 36 |
#include <pspthreadman.h> |
| 37 |
#elif defined(VITA) |
| 38 |
#include <psp2/kernel/threadmgr.h> |
| 39 |
#elif defined(_3DS) |
| 40 |
#include <3ds.h> |
| 41 |
#else |
| 42 |
#include <time.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
#if defined(_WIN32) && !defined(_XBOX) |
| 46 |
#define WIN32_LEAN_AND_MEAN |
| 47 |
#include <windows.h> |
| 48 |
#elif defined(_WIN32) && defined(_XBOX) |
| 49 |
#include <Xtl.h> |
| 50 |
#endif |
| 51 |
|
| 52 |
#include <limits.h> |
| 53 |
|
| 54 |
#ifdef _MSC_VER |
| 55 |
#include <compat/msvc.h> |
| 56 |
#endif |
| 57 |
#include <retro_inline.h> |
| 58 |
|
| 59 |
#ifndef PATH_MAX_LENGTH |
| 60 |
#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(GEKKO) |
| 61 |
#define PATH_MAX_LENGTH 512 |
| 62 |
#else |
| 63 |
#define PATH_MAX_LENGTH 4096 |
| 64 |
#endif |
| 65 |
#endif |
| 66 |
|
| 67 |
#ifndef M_PI |
| 68 |
#define M_PI 3.14159265358979323846264338327 |
| 69 |
#endif |
| 70 |
|
| 71 |
#ifndef MAX |
| 72 |
#define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifndef MIN |
| 76 |
#define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 77 |
#endif |
| 78 |
|
| 79 |
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 80 |
#define RARCH_SCALE_BASE 256 |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
static INLINE void retro_sleep(unsigned msec) |
| 89 |
{ |
| 90 |
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__) |
| 91 |
sys_timer_usleep(1000 * msec); |
| 92 |
#elif defined(PSP) || defined(VITA) |
| 93 |
sceKernelDelayThread(1000 * msec); |
| 94 |
#elif defined(_3DS) |
| 95 |
svcSleepThread(1000000 * (s64)msec); |
| 96 |
#elif defined(_WIN32) |
| 97 |
Sleep(msec); |
| 98 |
#elif defined(XENON) |
| 99 |
udelay(1000 * msec); |
| 100 |
#elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__) |
| 101 |
usleep(1000 * msec); |
| 102 |
#else |
| 103 |
struct timespec tv = {0}; |
| 104 |
tv.tv_sec = msec / 1000; |
| 105 |
tv.tv_nsec = (msec % 1000) * 1000000; |
| 106 |
nanosleep(&tv, NULL); |
| 107 |
#endif |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static INLINE uint32_t next_pow2(uint32_t v) |
| 119 |
{ |
| 120 |
v--; |
| 121 |
v |= v >> 1; |
| 122 |
v |= v >> 2; |
| 123 |
v |= v >> 4; |
| 124 |
v |= v >> 8; |
| 125 |
v |= v >> 16; |
| 126 |
v++; |
| 127 |
return v; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
static INLINE uint32_t prev_pow2(uint32_t v) |
| 139 |
{ |
| 140 |
v |= v >> 1; |
| 141 |
v |= v >> 2; |
| 142 |
v |= v >> 4; |
| 143 |
v |= v >> 8; |
| 144 |
v |= v >> 16; |
| 145 |
return v - (v >> 1); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
static INLINE float db_to_gain(float db) |
| 157 |
{ |
| 158 |
return powf(10.0f, db / 20.0f); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
typedef struct |
| 165 |
{ |
| 166 |
uint32_t data[8]; |
| 167 |
} retro_bits_t; |
| 168 |
|
| 169 |
#define BIT_SET(a, bit) ((a)[(bit) >> 3] |= (1 << ((bit) & 7))) |
| 170 |
#define BIT_CLEAR(a, bit) ((a)[(bit) >> 3] &= ~(1 << ((bit) & 7))) |
| 171 |
#define BIT_GET(a, bit) ((a)[(bit) >> 3] & (1 << ((bit) & 7))) |
| 172 |
|
| 173 |
#define BIT16_SET(a, bit) ((a) |= (1 << ((bit) & 15))) |
| 174 |
#define BIT16_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 15))) |
| 175 |
#define BIT16_GET(a, bit) (!!((a) & (1 << ((bit) & 15)))) |
| 176 |
#define BIT16_CLEAR_ALL(a) ((a) = 0) |
| 177 |
|
| 178 |
#define BIT32_SET(a, bit) ((a) |= (1 << ((bit) & 31))) |
| 179 |
#define BIT32_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 31))) |
| 180 |
#define BIT32_GET(a, bit) (!!((a) & (1 << ((bit) & 31)))) |
| 181 |
#define BIT32_CLEAR_ALL(a) ((a) = 0) |
| 182 |
|
| 183 |
#define BIT64_SET(a, bit) ((a) |= (UINT64_C(1) << ((bit) & 63))) |
| 184 |
#define BIT64_CLEAR(a, bit) ((a) &= ~(UINT64_C(1) << ((bit) & 63))) |
| 185 |
#define BIT64_GET(a, bit) (!!((a) & (UINT64_C(1) << ((bit) & 63)))) |
| 186 |
#define BIT64_CLEAR_ALL(a) ((a) = 0) |
| 187 |
|
| 188 |
#define BIT128_SET(a, bit) ((a).data[(bit) >> 5] |= (1 << ((bit) & 31)) |
| 189 |
#define BIT128_CLEAR(a, bit) ((a).data[(bit) >> 5] &= ~(1 << ((bit) & 31))) |
| 190 |
#define BIT128_GET(a, bit) ((a).data[(bit) >> 5] & (1 << ((bit) & 31))) |
| 191 |
#define BIT128_CLEAR_ALL(a) memset(&(a), 0, sizeof(a)); |
| 192 |
|
| 193 |
#endif |