2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
13 // move shared codes to DLL???
15 #define USE_SHARED_DLL
18 // use zlib to decompress gzip file???
20 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
25 // check environemnt/language
28 // Microsoft Visual C++
30 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
31 #define for if(0);else for
34 // Microsoft Visual C++ 6.0 or later
35 #define SUPPORT_TCHAR_TYPE
38 // Microsoft Visual C++ 8.0 (2005) or later
39 #define SUPPORT_SECURE_FUNCTIONS
40 #pragma warning( disable : 4819 )
41 //#pragma warning( disable : 4995 )
42 #pragma warning( disable : 4996 )
45 // Microsoft Visual C++ 12.0 (2013) or later
46 #define SUPPORT_CPLUSPLUS_11
49 // Win32, but not Microsoft Visual C++
50 #define SUPPORT_TCHAR_TYPE
51 // #define SUPPORT_SECURE_FUNCTIONS
55 #if defined(Q_OS_CYGWIN)
56 #define CSP_OS_GCC_CYGWIN
57 #define CSP_OS_WINDOWS
58 #elif defined(Q_OS_WIN) || defined(__WIN32) || defined(__WIN64)
59 #define CSP_OS_GCC_WINDOWS
60 #define CSP_OS_WINDOWS
62 #define DLL_PREFIX __declspec(dllexport)
63 #define DLL_PREFIX_I __declspec(dllimport)
66 #define CSP_OS_GCC_GENERIC
67 #define CSP_OS_GENERIC
71 #if defined(__clang__)
72 #define __CSP_COMPILER_CLANG
74 #define __CSP_COMPILER_GCC
76 #define SUPPORT_CPLUSPLUS_11
82 #ifndef SUPPORT_CPLUSPLUS_11
83 #if defined(__cplusplus) && (__cplusplus > 199711L)
84 #define SUPPORT_CPLUSPLUS_11
87 #ifndef SUPPORT_TCHAR_TYPE
88 // secure functions need tchar type
89 #undef SUPPORT_SECURE_FUNCTIONS
98 // include common header files
99 #ifdef SUPPORT_TCHAR_TYPE
102 #ifdef SUPPORT_CPLUSPLUS_11
111 // include environment/language dependent header files
114 #include <windowsx.h>
116 #include <mmsystem.h>
127 #if defined(__MINGW32__) || (__MINGW64__)
132 #include <QtCore/QString>
133 #include <QtCore/QFile>
135 #include <sys/param.h>
138 #define _MAX_PATH 2048
142 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
143 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
144 #if __BYTE_ORDER == __LITTLE_ENDIAN
145 #define __LITTLE_ENDIAN__
146 #elif __BYTE_ORDER == __BIG_ENDIAN
147 #define __BIG_ENDIAN__
149 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
150 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
151 #define __LITTLE_ENDIAN__
152 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
153 #define __BIG_ENDIAN__
155 #elif defined(WORDS_LITTLEENDIAN)
156 #define __LITTLE_ENDIAN__
157 #elif defined(WORDS_BIGENDIAN)
158 #define __BIG_ENDIAN__
161 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
162 // may be Microsoft Visual C++
163 #define __LITTLE_ENDIAN__
167 #ifndef SUPPORT_TCHAR_TYPE
173 #ifndef SUPPORT_CPLUSPLUS_11
175 typedef signed char int8_t;
178 typedef signed short int16_t;
181 typedef signed int int32_t;
184 typedef signed long long int64_t;
187 typedef unsigned char uint8_t;
190 typedef unsigned short uint16_t;
193 typedef unsigned int uint32_t;
196 typedef unsigned long long uint64_t;
202 typedef _TCHAR* LPTSTR;
205 typedef const _TCHAR* LPCTSTR;
217 typedef uint8_t BYTE;
220 typedef uint16_t WORD;
223 typedef uint32_t DWORD;
226 typedef uint64_t QWORD;
232 typedef int16_t INT16;
235 typedef int32_t INT32;
238 typedef int64_t INT64;
241 typedef uint8_t UINT8;
244 typedef uint16_t UINT16;
247 typedef uint32_t UINT32;
250 typedef uint64_t UINT64;
256 typedef unsigned int UINT;
262 #ifdef __BIG_ENDIAN__
263 uint8_t h3, h2, h, l;
265 uint8_t l, h, h2, h3;
269 #ifdef __BIG_ENDIAN__
276 #ifdef __BIG_ENDIAN__
283 #ifdef __BIG_ENDIAN__
291 inline void read_2bytes_le_from(uint8_t *t)
293 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
295 inline void write_2bytes_le_to(uint8_t *t)
297 t[0] = b.l; t[1] = b.h;
299 inline void read_2bytes_be_from(uint8_t *t)
301 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
303 inline void write_2bytes_be_to(uint8_t *t)
305 t[0] = b.h; t[1] = b.l;
307 inline void read_4bytes_le_from(uint8_t *t)
309 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
311 inline void write_4bytes_le_to(uint8_t *t)
313 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
315 inline void read_4bytes_be_from(uint8_t *t)
317 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
319 inline void write_4bytes_be_to(uint8_t *t)
321 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
325 uint32_t DLL_PREFIX EndianToLittle_DWORD(uint32_t x);
326 uint16_t DLL_PREFIX EndianToLittle_WORD(uint16_t x);
332 int max(int a, int b);
333 unsigned int max(unsigned int a, unsigned int b);
334 int min(int a, int b);
335 unsigned int min(unsigned int a, unsigned int b);
339 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
340 #define stricmp(a,b) strcasecmp(a,b)
341 #define strnicmp(a,b,n) strncasecmp(a,b,n)
344 #ifndef SUPPORT_TCHAR_TYPE
346 #define _tfopen fopen
349 #define _tcscmp strcmp
352 #define _tcscpy strcpy
355 #define _tcsicmp stricmp
358 #define _tcslen strlen
361 #define _tcsncat strncat
364 #define _tcsncpy strncpy
367 #define _tcsncicmp strnicmp
370 #define _tcschr strchr
373 #define _tcsrchr strrchr
376 #define _tcsstr strstr
379 #define _tcstok strtok
385 #define _tcstol strtol
388 #define _tcstoul strtoul
391 #define _stprintf sprintf
394 #define _vstprintf vsprintf
397 #define _taccess access
400 #define _tremove remove
403 #define _trename rename
407 #define _TEXT(x) __T(x)
410 #ifndef SUPPORT_SECURE_FUNCTIONS
414 // errno_t DLL_PREFIX my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
415 errno_t DLL_PREFIX my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
416 errno_t DLL_PREFIX my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
417 errno_t DLL_PREFIX my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
418 errno_t DLL_PREFIX my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
419 char * DLL_PREFIX my_strtok_s(char *strToken, const char *strDelimit, char **context);
420 _TCHAR * DLL_PREFIX my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
421 #define my_fprintf_s fprintf
422 int DLL_PREFIX my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
423 int DLL_PREFIX my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
424 int DLL_PREFIX my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
425 int DLL_PREFIX my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
427 // #define my_tfopen_s _tfopen_s
428 #define my_strcpy_s strcpy_s
429 #define my_tcscpy_s _tcscpy_s
430 #define my_strncpy_s strncpy_s
431 #define my_tcsncpy_s _tcsncpy_s
432 #define my_strtok_s strtok_s
433 #define my_tcstok_s _tcstok_s
434 #define my_fprintf_s fprintf_s
435 #define my_sprintf_s sprintf_s
436 #define my_stprintf_s _stprintf_s
437 #define my_vsprintf_s vsprintf_s
438 #define my_vstprintf_s _vstprintf_s
443 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
444 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
445 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
446 // used only in winmain and win32 osd class
447 // #define ZeroMemory(p,s) memset(p,0x00,s)
448 // #define CopyMemory(t,f,s) memcpy(t,f,s)
450 #define MyWritePrivateProfileString WritePrivateProfileString
451 #define MyGetPrivateProfileString GetPrivateProfileString
452 #define MyGetPrivateProfileInt GetPrivateProfileInt
456 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
460 #if defined(_RGB555) || defined(_RGB565)
461 typedef uint16_t scrntype_t;
462 scrntype_t RGB_COLOR(uint32_t r, uint32_t g, uint32_t b);
463 scrntype_t RGBA_COLOR(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
464 uint8_t R_OF_COLOR(scrntype_t c);
465 uint8_t G_OF_COLOR(scrntype_t c);
466 uint8_t B_OF_COLOR(scrntype_t c);
467 uint8_t A_OF_COLOR(scrntype_t c);
468 #elif defined(_RGB888)
469 typedef uint32_t scrntype_t;
470 #define RGB_COLOR(r, g, b) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0))
471 #define RGBA_COLOR(r, g, b, a) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0) | ((uint32_t)(a) << 24))
472 #define R_OF_COLOR(c) (((c) >> 16) & 0xff)
473 #define G_OF_COLOR(c) (((c) >> 8) & 0xff)
474 #define B_OF_COLOR(c) (((c) ) & 0xff)
475 #define A_OF_COLOR(c) (((c) >> 24) & 0xff)
488 wav_chunk_t riff_chunk;
490 wav_chunk_t fmt_chunk;
493 uint32_t sample_rate;
496 uint16_t sample_bits;
501 const _TCHAR *get_application_path();
502 const _TCHAR *create_local_path(const _TCHAR *format, ...);
503 void create_local_path(_TCHAR *file_path, int length, const _TCHAR *format, ...);
504 const _TCHAR *create_date_file_path(const _TCHAR *extension);
505 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
506 bool check_file_extension(const _TCHAR *file_path, const _TCHAR *ext);
507 const _TCHAR *get_file_path_without_extensiton(const _TCHAR *file_path);
508 void get_long_full_path_name(const _TCHAR* src, _TCHAR* dst, size_t dst_len);
509 const _TCHAR* get_parent_dir(const _TCHAR* file);
512 const _TCHAR * DLL_PREFIX create_string(const _TCHAR* format, ...);
513 uint32_t DLL_PREFIX get_crc32(uint8_t data[], int size);
514 uint16_t DLL_PREFIX jis_to_sjis(uint16_t jis);
516 int DLL_PREFIX decibel_to_volume(int decibel);
517 int32_t DLL_PREFIX apply_volume(int32_t sample, int volume);
519 #define array_length(array) (sizeof(array) / sizeof(array[0]))
521 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
522 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
523 #define TO_BCD_LO(v) ((v) % 10)
524 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
526 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
528 #define dll_cur_time_t DLL_PREFIX_I struct cur_time_s
530 typedef DLL_PREFIX struct cur_time_s {
531 int year, month, day, day_of_week, hour, minute, second;
539 void update_day_of_week();
540 void save_state(void *f);
541 bool load_state(void *f);
544 void DLL_PREFIX get_host_time(cur_time_t* cur_time);