1 /* Copyright (C) 2010-2017 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_H 25 26 #include <stdint.h> 27 28 #if defined(_WIN32) && !defined(_XBOX) 29 #ifndef WIN32_LEAN_AND_MEAN 30 #define WIN32_LEAN_AND_MEAN 31 #endif 32 #include <windows.h> 33 #elif defined(_WIN32) && defined(_XBOX) 34 #include <Xtl.h> 35 #endif 36 37 #include <limits.h> 38 39 #ifdef _MSC_VER 40 #include <compat/msvc.h> 41 #endif 42 43 #ifndef PATH_MAX_LENGTH 44 #if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(GEKKO)|| defined(WIIU) 45 #define PATH_MAX_LENGTH 512 46 #else 47 #define PATH_MAX_LENGTH 4096 48 #endif 49 #endif 50 51 #ifndef MAX 52 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 53 #endif 54 55 #ifndef MIN 56 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 57 #endif 58 59 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 60 61 #define BIT_SET(a, bit) ((a)[(bit) >> 3] |= (1 << ((bit) & 7))) 62 #define BIT_CLEAR(a, bit) ((a)[(bit) >> 3] &= ~(1 << ((bit) & 7))) 63 #define BIT_GET(a, bit) ((a)[(bit) >> 3] & (1 << ((bit) & 7))) 64 65 #define BIT16_SET(a, bit) ((a) |= (1 << ((bit) & 15))) 66 #define BIT16_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 15))) 67 #define BIT16_GET(a, bit) (!!((a) & (1 << ((bit) & 15)))) 68 #define BIT16_CLEAR_ALL(a) ((a) = 0) 69 70 #define BIT32_SET(a, bit) ((a) |= (1 << ((bit) & 31))) 71 #define BIT32_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 31))) 72 #define BIT32_GET(a, bit) (!!((a) & (1 << ((bit) & 31)))) 73 #define BIT32_CLEAR_ALL(a) ((a) = 0) 74 75 #define BIT64_SET(a, bit) ((a) |= (UINT64_C(1) << ((bit) & 63))) 76 #define BIT64_CLEAR(a, bit) ((a) &= ~(UINT64_C(1) << ((bit) & 63))) 77 #define BIT64_GET(a, bit) (!!((a) & (UINT64_C(1) << ((bit) & 63)))) 78 #define BIT64_CLEAR_ALL(a) ((a) = 0) 79 80 #define BIT128_SET(a, bit) ((a).data[(bit) >> 5] |= (1 << ((bit) & 31))) 81 #define BIT128_CLEAR(a, bit) ((a).data[(bit) >> 5] &= ~(1 << ((bit) & 31))) 82 #define BIT128_GET(a, bit) ((a).data[(bit) >> 5] & (1 << ((bit) & 31))) 83 #define BIT128_CLEAR_ALL(a) memset(&(a), 0, sizeof(a)); 84 85 /* Helper macros and struct to keep track of many booleans. 86 * To check for multiple bits, use &&, not &. 87 * For OR, | can be used. */ 88 typedef struct 89 { 90 uint32_t data[8]; 91 } retro_bits_t; 92 93 #endif 94