| 1 | /* Copyright (C) 2010-2016 The RetroArch team |
| 2 | * |
| 3 | * --------------------------------------------------------------------------------------- |
| 4 | * The following license statement only applies to this file (retro_miscellaneous.h). |
| 5 | * --------------------------------------------------------------------------------------- |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, |
| 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation the rights to |
| 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
| 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __RARCH_MISCELLANEOUS_H |
| 24 | #define __RARCH_MISCELLANEOUS_Hcxx . . $ `libretro-common/include/retro_miscellaneous.h:24:9`! |
| 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>cxx . . $ `<file>/libretro-common/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_LENGTHcxx . . $ `libretro-common/include/retro_miscellaneous.h:63:9`! 4096 |
| 64 | #endif |
| 65 | #endif |
| 66 | |
| 67 | #ifndef M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! |
| 68 | #define M_PI 3.14159265358979323846264338327 |
| 69 | #endif |
| 70 | |
| 71 | #ifndef MAX |
| 72 | #define MAXcxx . . $ `libretro-common/include/retro_miscellaneous.h:72:9`!(a, b) ((a) > (b) ? (a) : (b)) |
| 73 | #endif |
| 74 | |
| 75 | #ifndef MIN |
| 76 | #define MINcxx . . $ `libretro-common/include/retro_miscellaneous.h:76:9`!(a, b) ((a) < (b) ? (a) : (b)) |
| 77 | #endif |
| 78 | |
| 79 | #define ARRAY_SIZEcxx . . $ `libretro-common/include/retro_miscellaneous.h:79:9`!(a) (sizeof(a) / sizeof((a)[0])) |
| 80 | #define RARCH_SCALE_BASEcxx . . $ `libretro-common/include/retro_miscellaneous.h:80:9`! 256 |
| 81 | |
| 82 | /** |
| 83 | * retro_sleep: |
| 84 | * @msec : amount in milliseconds to sleep |
| 85 | * |
| 86 | * Sleeps for a specified amount of milliseconds (@msec). |
| 87 | **/ |
| 88 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! void retro_sleepcxx . . $ retro_sleep(cb2f890c2fdad230).(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 timespeccxx . . $ timespec# tv = {0}; |
| 104 | tv.tv_seccxx . . $ timespec#tv_sec. = msec / 1000; |
| 105 | tv.tv_nseccxx . . $ timespec#tv_nsec. = (msec % 1000) * 1000000; |
| 106 | nanosleepcxx . . $ nanosleep(645c6fc2576d4126).(&tv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 107 | #endif |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * next_pow2: |
| 112 | * @v : initial value |
| 113 | * |
| 114 | * Get next power of 2 value based on initial value. |
| 115 | * |
| 116 | * Returns: next power of 2 value (derived from @v). |
| 117 | **/ |
| 118 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32_tcxx . . $ uint32_t# next_pow2cxx . . $ next_pow2(2141b656ce2cc063).(uint32_tcxx . . $ 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 | * prev_pow2: |
| 132 | * @v : initial value |
| 133 | * |
| 134 | * Get previous power of 2 value based on initial value. |
| 135 | * |
| 136 | * Returns: previous power of 2 value (derived from @v). |
| 137 | **/ |
| 138 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! uint32_tcxx . . $ uint32_t# prev_pow2cxx . . $ prev_pow2(2141b656ce2cc063).(uint32_tcxx . . $ 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 | * db_to_gain: |
| 150 | * @db : Decibels. |
| 151 | * |
| 152 | * Converts decibels to voltage gain. |
| 153 | * |
| 154 | * Returns: voltage gain value. |
| 155 | **/ |
| 156 | static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! float db_to_gaincxx . . $ db_to_gain(fbcf3211dfe1bfd1).(float db) |
| 157 | { |
| 158 | return powfcxx . . $ powf(d59a45cd3bfd2eda).(10.0f, db / 20.0f); |
| 159 | } |
| 160 | |
| 161 | /* Helper macros and struct to keep track of many booleans. |
| 162 | * To check for multiple bits, use &&, not &. |
| 163 | * For OR, | can be used. */ |
| 164 | typedef structcxx . . $ $anonymous_type_9f6930dedf550348_0# |
| 165 | { |
| 166 | uint32_tcxx . . $ uint32_t# datacxx . . $ $anonymous_type_9f6930dedf550348_0#data.[8]; |
| 167 | } retro_bits_tcxx . . $ retro_bits_t#; |
| 168 | |
| 169 | #define BIT_SETcxx . . $ `libretro-common/include/retro_miscellaneous.h:169:9`!(a, bit) ((a)[(bit) >> 3] |= (1 << ((bit) & 7))) |
| 170 | #define BIT_CLEARcxx . . $ `libretro-common/include/retro_miscellaneous.h:170:9`!(a, bit) ((a)[(bit) >> 3] &= ~(1 << ((bit) & 7))) |
| 171 | #define BIT_GETcxx . . $ `libretro-common/include/retro_miscellaneous.h:171:9`!(a, bit) ((a)[(bit) >> 3] & (1 << ((bit) & 7))) |
| 172 | |
| 173 | #define BIT16_SETcxx . . $ `libretro-common/include/retro_miscellaneous.h:173:9`!(a, bit) ((a) |= (1 << ((bit) & 15))) |
| 174 | #define BIT16_CLEARcxx . . $ `libretro-common/include/retro_miscellaneous.h:174:9`!(a, bit) ((a) &= ~(1 << ((bit) & 15))) |
| 175 | #define BIT16_GETcxx . . $ `libretro-common/include/retro_miscellaneous.h:175:9`!(a, bit) (!!((a) & (1 << ((bit) & 15)))) |
| 176 | #define BIT16_CLEAR_ALLcxx . . $ `libretro-common/include/retro_miscellaneous.h:176:9`!(a) ((a) = 0) |
| 177 | |
| 178 | #define BIT32_SETcxx . . $ `libretro-common/include/retro_miscellaneous.h:178:9`!(a, bit) ((a) |= (1 << ((bit) & 31))) |
| 179 | #define BIT32_CLEARcxx . . $ `libretro-common/include/retro_miscellaneous.h:179:9`!(a, bit) ((a) &= ~(1 << ((bit) & 31))) |
| 180 | #define BIT32_GETcxx . . $ `libretro-common/include/retro_miscellaneous.h:180:9`!(a, bit) (!!((a) & (1 << ((bit) & 31)))) |
| 181 | #define BIT32_CLEAR_ALLcxx . . $ `libretro-common/include/retro_miscellaneous.h:181:9`!(a) ((a) = 0) |
| 182 | |
| 183 | #define BIT64_SETcxx . . $ `libretro-common/include/retro_miscellaneous.h:183:9`!(a, bit) ((a) |= (UINT64_C(1) << ((bit) & 63))) |
| 184 | #define BIT64_CLEARcxx . . $ `libretro-common/include/retro_miscellaneous.h:184:9`!(a, bit) ((a) &= ~(UINT64_C(1) << ((bit) & 63))) |
| 185 | #define BIT64_GETcxx . . $ `libretro-common/include/retro_miscellaneous.h:185:9`!(a, bit) (!!((a) & (UINT64_C(1) << ((bit) & 63)))) |
| 186 | #define BIT64_CLEAR_ALLcxx . . $ `libretro-common/include/retro_miscellaneous.h:186:9`!(a) ((a) = 0) |
| 187 | |
| 188 | #define BIT128_SETcxx . . $ `libretro-common/include/retro_miscellaneous.h:188:9`!(a, bit) ((a).data[(bit) >> 5] |= (1 << ((bit) & 31)) |
| 189 | #define BIT128_CLEARcxx . . $ `libretro-common/include/retro_miscellaneous.h:189:9`!(a, bit) ((a).data[(bit) >> 5] &= ~(1 << ((bit) & 31))) |
| 190 | #define BIT128_GETcxx . . $ `libretro-common/include/retro_miscellaneous.h:190:9`!(a, bit) ((a).data[(bit) >> 5] & (1 << ((bit) & 31))) |
| 191 | #define BIT128_CLEAR_ALLcxx . . $ `libretro-common/include/retro_miscellaneous.h:191:9`!(a) memset(&(a), 0, sizeof(a)); |
| 192 | |
| 193 | #endif |