|
Xemu [doxygen]
hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
|
Go to the documentation of this file.
21 #ifndef XEMU_COMMON_EMUTOOLS_BASICDEFS_H_INCLUDED
22 #define XEMU_COMMON_EMUTOOLS_BASICDEFS_H_INCLUDED
24 #define COPYRIGHT_YEARS "2016-2022"
35 #ifdef XEMU_RELEASE_BUILD
39 #ifndef XEMU_DISABLE_SDL
41 #error "We require SDL2, but XEMU_HAS_SDL2 was not defined: SDL2 cannot be detected?"
43 #include <SDL_types.h>
44 #include <SDL_endian.h>
47 #error "This build does not want SDL2, but XEMU_HAS_SDL2 was specified?"
51 typedef uint8_t
Uint8;
52 typedef int16_t Sint16;
54 typedef int32_t Sint32;
56 typedef int64_t Sint64;
57 typedef uint64_t Uint64;
59 #define SDL_LIL_ENDIAN 1234
60 #define SDL_BIG_ENDIAN 4321
63 #define SDL_BYTEORDER __BYTE_ORDER
64 #elif defined(__OpenBSD__)
66 #define SDL_BYTEORDER BYTE_ORDER
67 #elif defined(__FreeBSD__)
68 #include <sys/endian.h>
69 #define SDL_BYTEORDER BYTE_ORDER
71 #if defined(__hppa__) || \
72 defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
73 (defined(__MIPS__) && defined(__MISPEB__)) || \
74 defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
76 #define SDL_BYTEORDER SDL_BIG_ENDIAN
78 #define SDL_BYTEORDER SDL_LIL_ENDIAN
83 #if UINTPTR_MAX == 0xffffffffU
86 # define ARCH_BITS_AS_TEXT "32"
90 # define ARCH_BITS_AS_TEXT "64"
93 #if defined(__EMSCRIPTEN__)
94 # define CC_TYPE "clang-emscripten"
95 #elif defined(__clang__)
96 # define CC_TYPE "clang"
97 #elif defined(__MINGW64__)
98 # define CC_TYPE "gcc-mingw64"
99 #elif defined(__MINGW32__)
100 # define CC_TYPE "gcc-mingw32"
101 #elif defined(__GNUC__)
102 # define CC_TYPE "gcc-compatible"
104 # define CC_TYPE "UNKNOWN-COMPILER"
105 # warning "Unrecognizable C compiler"
108 #define XEMU_UNREACHABLE_FATAL_ERROR() do { fprintf(stderr, "*** Unreachable code point hit in function %s\n", __func__); exit(1); } while(0)
111 # define XEMU_LIKELY(__x__) __builtin_expect(!!(__x__), 1)
112 # define XEMU_UNLIKELY(__x__) __builtin_expect(!!(__x__), 0)
113 # ifdef DO_NOT_FORCE_UNREACHABLE
114 # define XEMU_UNREACHABLE() XEMU_UNREACHABLE_FATAL_ERROR()
116 # define XEMU_UNREACHABLE() __builtin_unreachable()
118 # ifdef DO_NOT_FORCE_INLINE
119 # define XEMU_INLINE inline
121 # define XEMU_INLINE __attribute__ ((__always_inline__)) inline
124 # define XEMU_LIKELY(__x__) (__x__)
125 # define XEMU_UNLIKELY(__x__) (__x__)
126 # define XEMU_INLINE inline
127 # define XEMU_UNREACHABLE() XEMU_UNREACHABLE_FATAL_ERROR()
130 #if defined(USE_REGPARM) && defined(__GNUC__) && !defined(__EMSCRIPTEN__)
131 #define REGPARM(__n__) __attribute__ ((__regparm__ (__n__)))
133 #define REGPARM(__n__)
139 #ifndef XEMU_ARCH_WIN
141 # define DIRSEP_STR "/"
142 # define DIRSEP_CHR '/'
145 # define PRINTF_LLD "%lld"
146 # define PRINTF_LLU "%llu"
147 # define MKDIR(__n) mkdir((__n), 0777)
148 # define NULL_DEVICE "/dev/null"
150 # define DIRSEP_STR "\\"
151 # define DIRSEP_CHR '\\'
154 # define PRINTF_LLD "%I64d"
155 # define PRINTF_LLU "%I64u"
156 # define MKDIR(__n) mkdir(__n)
157 # define NULL_DEVICE "NUL:"
165 #define DEBUGPRINT(...) printf(__VA_ARGS__)
167 #define DEBUG(...) do { \
168 if (XEMU_UNLIKELY(debug_fp)) \
169 fprintf(debug_fp, __VA_ARGS__); \
171 #define DEBUGPRINT(...) do { \
173 printf(__VA_ARGS__); \
174 DEBUG(__VA_ARGS__); \
178 #ifndef __BIGGEST_ALIGNMENT__
179 # define __BIGGEST_ALIGNMENT__ 16
180 # define XEMU_MISSING_BIGGEST_ALIGNMENT_WORKAROUND
181 #elif __BIGGEST_ALIGNMENT__ > 256
182 # undef __BIGGEST_ALIGNMENT__
183 # define __BIGGEST_ALIGNMENT__ 256
184 # define XEMU_OVERSIZED_BIGGEST_ALIGNMENT_WORKAROUND
187 #define ALIGNED(n) __attribute__ ((aligned (n)))
188 #define MAXALIGNED ALIGNED(__BIGGEST_ALIGNMENT__)
192 #ifndef SDL_BYTEORDER
193 # error "SDL_BYTEORDER is not defined!"
195 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
196 # ifdef Z80EX_WORDS_BIG_ENDIAN
197 # undef Z80EX_WORDS_BIG_ENDIAN
199 # define ENDIAN_NAME "LE"
201 # define ENDIAN_CHECKER_BYTE_L 0x01
202 # define ENDIAN_CHECKER_BYTE_H 0x23
203 # define ENDIAN_CHECKER_WORD 0x2301
204 # define ENDIAN_CHECKER_DWORD 0x67452301
211 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
212 # ifndef Z80EX_WORDS_BIG_ENDIAN
213 # define Z80EX_WORDS_BIG_ENDIAN
215 # define ENDIAN_NAME "BE"
217 # define ENDIAN_CHECKER_BYTE_L 0x67
218 # define ENDIAN_CHECKER_BYTE_H 0x45
219 # define ENDIAN_CHECKER_WORD 0x4567
220 # define ENDIAN_CHECKER_DWORD 0x01234567
223 struct {
Uint8 _un1,_un2,h,l; } b;
224 struct {
Uint16 _unw,w; } w;
228 # error "SDL_BYTEORDER is not SDL_LIL_ENDIAN neither SDL_BIG_ENDIAN"
230 static inline int xemu_byte_order_test (
void )
241 #ifdef __EMSCRIPTEN__
242 #include <emscripten.h>
243 #define XEMUEXIT(n) do { emscripten_cancel_main_loop(); emscripten_force_exit(n); exit(n); } while (0)
246 #define XEMUEXIT(n) exit(n)
249 #define BOOLEAN_VALUE(n) (!!(n))
256 static XEMU_INLINE unsigned char XEMU_BYTE_TO_BCD (
unsigned char b ) {
257 return ((b / 10) << 4) + (b % 10);
263 static inline void *xemu_strcpy_special (
void *target,
const void *source )
265 while (*(
char *)source)
266 *(
char *)target++ = *(
char *)source++;
270 #define VOIDPTR_TO_INT(x) ((int)(intptr_t)(void*)(x))
271 #define VOIDPTR_TO_UINT(x) ((unsigned int)(uintptr_t)(void*)(x))
274 #define TO_STR_LEVEL1_(x) #x // stringification argument
275 #define STRINGIFY(x) TO_STR_LEVEL1_(x) // level of indirection to be able to expand argument given as macros