2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
13 // check environemnt/language
16 // Microsoft Visual C++
18 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
19 #define for if(0);else for
22 // Microsoft Visual C++ 6.0 or later
23 #define SUPPORT_TCHAR_TYPE
26 // Microsoft Visual C++ 8.0 (2005) or later
27 #define SUPPORT_SECURE_FUNCTIONS
28 #pragma warning( disable : 4819 )
29 //#pragma warning( disable : 4995 )
30 #pragma warning( disable : 4996 )
33 // Microsoft Visual C++ 12.0 (2013) or later
34 #define SUPPORT_CPLUSPLUS_11
37 // Win32, but not Microsoft Visual C++
38 #define SUPPORT_TCHAR_TYPE
39 // #define SUPPORT_SECURE_FUNCTIONS
43 #if defined(Q_OS_CYGWIN)
44 #define CSP_OS_GCC_CYGWIN
45 #define CSP_OS_WINDOWS
46 #elif defined(Q_OS_WIN) || defined(__WIN32) || defined(__WIN64)
47 #define CSP_OS_GCC_WINDOWS
48 #define CSP_OS_WINDOWS
49 #define DLL_PREFIX __declspec(dllexport)
50 #define DLL_PREFIX_I __declspec(dllimport)
52 #define CSP_OS_GCC_GENERIC
53 #define CSP_OS_GENERIC
57 #if defined(__clang__)
58 #define __CSP_COMPILER_CLANG
60 #define __CSP_COMPILER_GCC
62 #define SUPPORT_CPLUSPLUS_11
68 #ifndef SUPPORT_CPLUSPLUS_11
69 #if defined(__cplusplus) && (__cplusplus > 199711L)
70 #define SUPPORT_CPLUSPLUS_11
73 #ifndef SUPPORT_TCHAR_TYPE
74 // secure functions need tchar type
75 #undef SUPPORT_SECURE_FUNCTIONS
78 // include common header files
79 #ifdef SUPPORT_TCHAR_TYPE
82 #ifdef SUPPORT_CPLUSPLUS_11
90 // include environment/language dependent header files
106 #if defined(__MINGW32__) || (__MINGW64__)
111 #include <QtCore/QString>
112 #include <QtCore/QFile>
114 #include <sys/param.h>
117 #define _MAX_PATH 2048
121 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
122 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
123 #if __BYTE_ORDER == __LITTLE_ENDIAN
124 #define __LITTLE_ENDIAN__
125 #elif __BYTE_ORDER == __BIG_ENDIAN
126 #define __BIG_ENDIAN__
128 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
129 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
130 #define __LITTLE_ENDIAN__
131 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
132 #define __BIG_ENDIAN__
134 #elif defined(WORDS_LITTLEENDIAN)
135 #define __LITTLE_ENDIAN__
136 #elif defined(WORDS_BIGENDIAN)
137 #define __BIG_ENDIAN__
140 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
141 // may be Microsoft Visual C++
142 #define __LITTLE_ENDIAN__
146 #ifndef SUPPORT_TCHAR_TYPE
152 #ifndef SUPPORT_CPLUSPLUS_11
154 typedef signed char int8_t;
157 typedef signed short int16_t;
160 typedef signed int int32_t;
163 typedef signed long long int64_t;
166 typedef unsigned char uint8_t;
169 typedef unsigned short uint16_t;
172 typedef unsigned int uint32_t;
175 typedef unsigned long long uint64_t;
181 typedef _TCHAR* LPTSTR;
184 typedef const _TCHAR* LPCTSTR;
196 typedef uint8_t BYTE;
199 typedef uint16_t WORD;
202 typedef uint32_t DWORD;
205 typedef uint64_t QWORD;
211 typedef int16_t INT16;
214 typedef int32_t INT32;
217 typedef int64_t INT64;
220 typedef uint8_t UINT8;
223 typedef uint16_t UINT16;
226 typedef uint32_t UINT32;
229 typedef uint64_t UINT64;
235 typedef unsigned int UINT;
241 #ifdef __BIG_ENDIAN__
242 uint8_t h3, h2, h, l;
244 uint8_t l, h, h2, h3;
248 #ifdef __BIG_ENDIAN__
255 #ifdef __BIG_ENDIAN__
262 #ifdef __BIG_ENDIAN__
270 inline void read_2bytes_le_from(uint8_t *t)
272 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
274 inline void write_2bytes_le_to(uint8_t *t)
276 t[0] = b.l; t[1] = b.h;
278 inline void read_2bytes_be_from(uint8_t *t)
280 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
282 inline void write_2bytes_be_to(uint8_t *t)
284 t[0] = b.h; t[1] = b.l;
286 inline void read_4bytes_le_from(uint8_t *t)
288 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
290 inline void write_4bytes_le_to(uint8_t *t)
292 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
294 inline void read_4bytes_be_from(uint8_t *t)
296 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
298 inline void write_4bytes_be_to(uint8_t *t)
300 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
304 uint32_t EndianToLittle_DWORD(uint32_t x);
305 uint16_t EndianToLittle_WORD(uint16_t x);
311 int max(int a, int b);
312 unsigned int max(unsigned int a, unsigned int b);
313 int min(int a, int b);
314 unsigned int min(unsigned int a, unsigned int b);
318 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
319 #define stricmp(a,b) strcasecmp(a,b)
320 #define strnicmp(a,b,n) strncasecmp(a,b,n)
323 #ifndef SUPPORT_TCHAR_TYPE
325 #define _tfopen fopen
328 #define _tcscmp strcmp
331 #define _tcscpy strcpy
334 #define _tcsicmp stricmp
337 #define _tcslen strlen
340 #define _tcsncat strncat
343 #define _tcsncpy strncpy
346 #define _tcsncicmp strnicmp
349 #define _tcschr strchr
352 #define _tcsrchr strrchr
355 #define _tcsstr strstr
358 #define _tcstok strtok
364 #define _tcstol strtol
367 #define _tcstoul strtoul
370 #define _stprintf sprintf
373 #define _vstprintf vsprintf
376 #define _taccess access
379 #define _tremove remove
382 #define _trename rename
386 #define _TEXT(x) __T(x)
389 #ifndef SUPPORT_SECURE_FUNCTIONS
393 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
394 errno_t DLL_PREFIX my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
395 errno_t DLL_PREFIX my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
396 errno_t DLL_PREFIX my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
397 errno_t DLL_PREFIX my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
398 char * DLL_PREFIX my_strtok_s(char *strToken, const char *strDelimit, char **context);
399 _TCHAR * DLL_PREFIX my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
400 #define my_fprintf_s fprintf
401 int DLL_PREFIX my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
402 int DLL_PREFIX my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
403 int DLL_PREFIX my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
404 int DLL_PREFIX my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
406 // #define my_tfopen_s _tfopen_s
407 #define my_strcpy_s strcpy_s
408 #define my_tcscpy_s _tcscpy_s
409 #define my_strncpy_s strncpy_s
410 #define my_tcsncpy_s _tcsncpy_s
411 #define my_strtok_s strtok_s
412 #define my_tcstok_s _tcstok_s
413 #define my_fprintf_s fprintf_s
414 #define my_sprintf_s sprintf_s
415 #define my_stprintf_s _stprintf_s
416 #define my_vsprintf_s vsprintf_s
417 #define my_vstprintf_s _vstprintf_s
422 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
423 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
424 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
425 // used only in winmain and win32 osd class
426 // #define ZeroMemory(p,s) memset(p,0x00,s)
427 // #define CopyMemory(t,f,s) memcpy(t,f,s)
429 #define MyWritePrivateProfileString WritePrivateProfileString
430 #define MyGetPrivateProfileString GetPrivateProfileString
431 #define MyGetPrivateProfileInt GetPrivateProfileInt
435 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
439 #if defined(_RGB555) || defined(_RGB565)
440 typedef uint16_t scrntype_t;
441 scrntype_t RGB_COLOR(uint32_t r, uint32_t g, uint32_t b);
442 scrntype_t RGBA_COLOR(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
443 uint8_t R_OF_COLOR(scrntype_t c);
444 uint8_t G_OF_COLOR(scrntype_t c);
445 uint8_t B_OF_COLOR(scrntype_t c);
446 uint8_t A_OF_COLOR(scrntype_t c);
447 #elif defined(_RGB888)
448 typedef uint32_t scrntype_t;
449 #define RGB_COLOR(r, g, b) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0))
450 #define RGBA_COLOR(r, g, b, a) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0) | ((uint32_t)(a) << 24))
451 #define R_OF_COLOR(c) (((c) >> 16) & 0xff)
452 #define G_OF_COLOR(c) (((c) >> 8) & 0xff)
453 #define B_OF_COLOR(c) (((c) ) & 0xff)
454 #define A_OF_COLOR(c) (((c) >> 24) & 0xff)
467 wav_chunk_t riff_chunk;
469 wav_chunk_t fmt_chunk;
472 uint32_t sample_rate;
475 uint16_t sample_bits;
480 const _TCHAR * DLL_PREFIX get_application_path();
481 const _TCHAR * DLL_PREFIX create_local_path(const _TCHAR *format, ...);
482 void DLL_PREFIX create_local_path(_TCHAR *file_path, int length, const _TCHAR *format, ...);
483 const _TCHAR * DLL_PREFIX create_date_file_path(const _TCHAR *extension);
484 void DLL_PREFIX create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
485 bool DLL_PREFIX check_file_extension(const _TCHAR *file_path, const _TCHAR *ext);
486 const _TCHAR * DLL_PREFIX get_file_path_without_extensiton(const _TCHAR *file_path);
487 void DLL_PREFIX get_long_full_path_name(const _TCHAR* src, _TCHAR* dst, size_t dst_len);
488 const _TCHAR* DLL_PREFIX get_parent_dir(const _TCHAR* file);
491 const _TCHAR * DLL_PREFIX create_string(const _TCHAR* format, ...);
492 uint32_t DLL_PREFIX get_crc32(uint8_t data[], int size);
493 uint16_t DLL_PREFIX jis_to_sjis(uint16_t jis);
495 int DLL_PREFIX decibel_to_volume(int decibel);
496 int32_t DLL_PREFIX apply_volume(int32_t sample, int volume);
498 #define array_length(array) (sizeof(array) / sizeof(array[0]))
500 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
501 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
502 #define TO_BCD_LO(v) ((v) % 10)
503 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
505 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
507 typedef struct cur_time_s {
508 int year, month, day, day_of_week, hour, minute, second;
516 void update_day_of_week();
517 void save_state(void *f);
518 bool load_state(void *f);
521 void DLL_PREFIX get_host_time(cur_time_t* cur_time);