2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
15 // Microsoft Visual C++
17 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
18 #define for if(0);else for
21 // Microsoft Visual C++ 6.0 or later
22 #define SUPPORT_TCHAR_TYPE
25 // Microsoft Visual C++ 8.0 (2005) or later
26 #define SUPPORT_SECURE_FUNCTIONS
27 #pragma warning( disable : 4819 )
28 //#pragma warning( disable : 4995 )
29 #pragma warning( disable : 4996 )
32 // Microsoft Visual C++ 12.0 (2013) or later
33 #define SUPPORT_CPLUSPLUS_11
36 // Win32, but not Microsoft Visual C++
37 #define SUPPORT_TCHAR_TYPE
38 // #define SUPPORT_SECURE_FUNCTIONS
41 #ifndef SUPPORT_CPLUSPLUS_11
42 #if defined(__cplusplus) && (__cplusplus > 199711L)
43 #define SUPPORT_CPLUSPLUS_11
46 #ifndef SUPPORT_TCHAR_TYPE
47 // secure functions need tchar type
48 #undef SUPPORT_SECURE_FUNCTIONS
51 #ifdef SUPPORT_TCHAR_TYPE
54 #ifdef SUPPORT_CPLUSPLUS_11
64 #if defined(Q_OS_CYGWIN)
65 #define CSP_OS_GCC_CYGWIN
66 #define CSP_OS_WINDOWS
67 #elif defined(Q_OS_WIN) || defined(__WIN32) || defined(__WIN64)
68 #define CSP_OS_GCC_WINDOWS
69 #define CSP_OS_WINDOWS
71 #define CSP_OS_GCC_GENERIC
72 #define CSP_OS_GENERIC
74 #if defined(__clang__)
75 #define __CSP_COMPILER_CLANG
77 #define __CSP_COMPILER_GCC
80 //#include "common_gcc.h"
86 #include <sys/param.h>
88 #define _MAX_PATH 2048
105 #if defined(__MINGW32__) || (__MINGW64__)
110 #include <QtCore/QString>
111 #include <QtCore/QFile>
116 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
117 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
118 #if __BYTE_ORDER == __LITTLE_ENDIAN
119 #define __LITTLE_ENDIAN__
120 #elif __BYTE_ORDER == __BIG_ENDIAN
121 #define __BIG_ENDIAN__
123 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
124 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
125 #define __LITTLE_ENDIAN__
126 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
127 #define __BIG_ENDIAN__
129 #elif defined(WORDS_LITTLEENDIAN)
130 #define __LITTLE_ENDIAN__
131 #elif defined(WORDS_BIGENDIAN)
132 #define __BIG_ENDIAN__
135 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
136 // may be Microsoft Visual C++
137 #define __LITTLE_ENDIAN__
141 #ifndef SUPPORT_TCHAR_TYPE
147 #if defined(__GNUC__)
149 #if !defined(SUPPORT_CPLUSPLUS_11)
150 #define SUPPORT_CPLUSPLUS_11
154 #if !defined(SUPPORT_CPLUSPLUS_11)
156 typedef signed char int8_t;
159 typedef signed short int16_t;
162 typedef signed int int32_t;
165 typedef signed long long int64_t;
168 typedef unsigned char uint8_t;
171 typedef unsigned short uint16_t;
174 typedef unsigned int uint32_t;
177 typedef unsigned long long uint64_t;
183 typedef _TCHAR* LPTSTR;
186 typedef const _TCHAR* LPCTSTR;
198 typedef uint8_t BYTE;
201 typedef uint16_t WORD;
204 typedef uint32_t DWORD;
207 typedef uint64_t QWORD;
213 typedef int16_t INT16;
216 typedef int32_t INT32;
219 typedef int64_t INT64;
225 typedef uint8_t UINT8;
228 typedef uint16_t UINT16;
231 typedef uint32_t UINT32;
234 typedef uint64_t UINT64;
237 typedef unsigned int UINT;
243 #ifdef __BIG_ENDIAN__
244 uint8_t h3, h2, h, l;
246 uint8_t l, h, h2, h3;
250 #ifdef __BIG_ENDIAN__
257 #ifdef __BIG_ENDIAN__
264 #ifdef __BIG_ENDIAN__
272 inline void read_2bytes_le_from(uint8_t *t)
274 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
276 inline void write_2bytes_le_to(uint8_t *t)
278 t[0] = b.l; t[1] = b.h;
280 inline void read_2bytes_be_from(uint8_t *t)
282 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
284 inline void write_2bytes_be_to(uint8_t *t)
286 t[0] = b.h; t[1] = b.l;
288 inline void read_4bytes_le_from(uint8_t *t)
290 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
292 inline void write_4bytes_le_to(uint8_t *t)
294 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
296 inline void read_4bytes_be_from(uint8_t *t)
298 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
300 inline void write_4bytes_be_to(uint8_t *t)
302 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
306 uint32_t EndianToLittle_DWORD(uint32_t x);
307 uint16_t EndianToLittle_WORD(uint16_t x);
313 int max(int a, int b);
314 unsigned int max(unsigned int a, unsigned int b);
315 int min(int a, int b);
316 unsigned int min(unsigned int a, unsigned int b);
320 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
321 #define stricmp(a,b) strcasecmp(a,b)
322 #define strnicmp(a,b,n) strncasecmp(a,b,n)
325 #ifndef SUPPORT_TCHAR_TYPE
327 #define _tfopen fopen
330 #define _tcscmp strcmp
333 #define _tcscpy strcpy
336 #define _tcsicmp stricmp
339 #define _tcslen strlen
342 #define _tcsncat strncat
345 #define _tcsncpy strncpy
348 #define _tcsncicmp strnicmp
351 #define _tcschr strchr
354 #define _tcsrchr strrchr
357 #define _tcsstr strstr
360 #define _tcstok strtok
366 #define _tcstol strtol
369 #define _tcstoul strtoul
372 #define _stprintf sprintf
375 #define _vstprintf vsprintf
378 #define _taccess access
381 #define _tremove remove
384 #define _trename rename
388 #define _TEXT(x) __T(x)
391 #ifndef SUPPORT_SECURE_FUNCTIONS
395 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
396 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
397 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
398 errno_t my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
399 errno_t my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
400 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
401 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
402 #define my_fprintf_s fprintf
403 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
404 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
405 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
406 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
408 // #define my_tfopen_s _tfopen_s
409 #define my_strcpy_s strcpy_s
410 #define my_tcscpy_s _tcscpy_s
411 #define my_strncpy_s strncpy_s
412 #define my_tcsncpy_s _tcsncpy_s
413 #define my_strtok_s strtok_s
414 #define my_tcstok_s _tcstok_s
415 #define my_fprintf_s fprintf_s
416 #define my_sprintf_s sprintf_s
417 #define my_stprintf_s _stprintf_s
418 #define my_vsprintf_s vsprintf_s
419 #define my_vstprintf_s _vstprintf_s
424 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
425 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
426 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
427 // used only in winmain and win32 osd class
428 // #define ZeroMemory(p,s) memset(p,0x00,s)
429 // #define CopyMemory(t,f,s) memcpy(t,f,s)
431 #define MyWritePrivateProfileString WritePrivateProfileString
432 #define MyGetPrivateProfileString GetPrivateProfileString
433 #define MyGetPrivateProfileInt GetPrivateProfileInt
437 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
441 #if defined(_RGB555) || defined(_RGB565)
442 typedef uint16_t scrntype_t;
443 scrntype_t RGB_COLOR(uint32_t r, uint32_t g, uint32_t b);
444 scrntype_t RGBA_COLOR(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
445 uint8_t R_OF_COLOR(scrntype_t c);
446 uint8_t G_OF_COLOR(scrntype_t c);
447 uint8_t B_OF_COLOR(scrntype_t c);
448 uint8_t A_OF_COLOR(scrntype_t c);
449 #elif defined(_RGB888)
450 typedef uint32_t scrntype_t;
451 #define RGB_COLOR(r, g, b) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0))
452 #define RGBA_COLOR(r, g, b, a) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0) | ((uint32_t)(a) << 24))
453 #define R_OF_COLOR(c) (((c) >> 16) & 0xff)
454 #define G_OF_COLOR(c) (((c) >> 8) & 0xff)
455 #define B_OF_COLOR(c) (((c) ) & 0xff)
456 #define A_OF_COLOR(c) (((c) >> 24) & 0xff)
469 wav_chunk_t riff_chunk;
471 wav_chunk_t fmt_chunk;
474 uint32_t sample_rate;
477 uint16_t sample_bits;
482 const _TCHAR *get_application_path();
483 const _TCHAR *create_local_path(const _TCHAR *format, ...);
484 void create_local_path(_TCHAR *file_path, int length, const _TCHAR *format, ...);
485 const _TCHAR *create_date_file_path(const _TCHAR *extension);
486 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
487 bool check_file_extension(const _TCHAR *file_path, const _TCHAR *ext);
488 const _TCHAR *get_file_path_without_extensiton(const _TCHAR *file_path);
489 void get_long_full_path_name(const _TCHAR* src, _TCHAR* dst, size_t dst_len);
490 const _TCHAR* get_parent_dir(const _TCHAR* file);
493 const _TCHAR *create_string(const _TCHAR* format, ...);
494 uint32_t get_crc32(uint8_t data[], int size);
495 uint16_t jis_to_sjis(uint16_t jis);
497 int decibel_to_volume(int decibel);
498 int32_t apply_volume(int32_t sample, int volume);
500 #define array_length(array) (sizeof(array) / sizeof(array[0]))
502 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
503 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
504 #define TO_BCD_LO(v) ((v) % 10)
505 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
507 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
509 typedef struct cur_time_s {
510 int year, month, day, day_of_week, hour, minute, second;
518 void update_day_of_week();
519 void save_state(void *f);
520 bool load_state(void *f);
523 void get_host_time(cur_time_t* cur_time);
526 #define EMU_LOG_CPU1 0x00000001
527 #define EMU_LOG_CPU2 0x00000002
528 #define EMU_LOG_CPU3 0x00000004
529 #define EMU_LOG_CPU4 0x00000008
530 #define EMU_LOG_FLOPPY 0x00000010
531 #define EMU_LOG_CMT 0x00000020
532 #define EMU_LOG_QD 0x00000040
533 #define EMU_LOG_CART 0x00000080
534 #define EMU_LOG_BINARY 0x00000100
535 #define EMU_LOG_LASERDISC 0x00000200
536 #define EMU_LOG_DISPLAY 0x00001000
537 #define EMU_LOG_SOUND 0x00002000
538 #define EMU_LOG_KEYBOARD 0x00004000
539 #define EMU_LOG_IO 0x00008000
540 #define EMU_LOG_MEMORY 0x00010000
541 #define EMU_LOG_USR1 0x00020000
542 #define EMU_LOG_USR2 0x00040000
543 #define EMU_LOG_USR3 0x00080000
544 #define EMU_LOG_USR4 0x00100000
545 #define EMU_LOG_USR5 0x00200000
546 #define EMU_LOG_USR6 0x00400000
547 #define EMU_LOG_USR7 0x00800000
548 #define EMU_LOG_USR8 0x01000000
549 #define EMU_LOG_USR9 0x02000000
550 #define EMU_LOG_USR10 0x04000000
551 #define EMU_LOG_GUI 0x08000000
552 #define EMU_LOG_DEBUG 0x10000000
553 #define EMU_LOG_INFO 0x20000000
554 #define EMU_LOG_WARNING 0x40000000
555 #define EMU_LOG_GENERAL 0x80000000