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 #include <QtCore/QString>
106 #include <QtCore/QFile>
111 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
112 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
113 #if __BYTE_ORDER == __LITTLE_ENDIAN
114 #define __LITTLE_ENDIAN__
115 #elif __BYTE_ORDER == __BIG_ENDIAN
116 #define __BIG_ENDIAN__
118 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
119 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
120 #define __LITTLE_ENDIAN__
121 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
122 #define __BIG_ENDIAN__
124 #elif defined(WORDS_LITTLEENDIAN)
125 #define __LITTLE_ENDIAN__
126 #elif defined(WORDS_BIGENDIAN)
127 #define __BIG_ENDIAN__
130 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
131 // may be Microsoft Visual C++
132 #define __LITTLE_ENDIAN__
136 #ifndef SUPPORT_TCHAR_TYPE
142 #if defined(__GNUC__)
144 #if !defined(SUPPORT_CPLUSPLUS_11)
145 #define SUPPORT_CPLUSPLUS_11
149 #if !defined(SUPPORT_CPLUSPLUS_11)
151 typedef signed char int8_t;
154 typedef signed short int16_t;
157 typedef signed int int32_t;
160 typedef signed long long int64_t;
163 typedef unsigned char uint8_t;
166 typedef unsigned short uint16_t;
169 typedef unsigned int uint32_t;
172 typedef unsigned long long uint64_t;
178 typedef _TCHAR* LPTSTR;
181 typedef const _TCHAR* LPCTSTR;
193 typedef uint8_t BYTE;
196 typedef uint16_t WORD;
199 typedef uint32_t DWORD;
202 typedef uint64_t QWORD;
208 typedef int16_t INT16;
211 typedef int32_t INT32;
214 typedef int64_t INT64;
220 typedef uint8_t UINT8;
223 typedef uint16_t UINT16;
226 typedef uint32_t UINT32;
229 typedef uint64_t UINT64;
232 typedef unsigned int UINT;
238 #ifdef __BIG_ENDIAN__
239 uint8_t h3, h2, h, l;
241 uint8_t l, h, h2, h3;
245 #ifdef __BIG_ENDIAN__
252 #ifdef __BIG_ENDIAN__
259 #ifdef __BIG_ENDIAN__
267 inline void read_2bytes_le_from(uint8_t *t)
269 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
271 inline void write_2bytes_le_to(uint8_t *t)
273 t[0] = b.l; t[1] = b.h;
275 inline void read_2bytes_be_from(uint8_t *t)
277 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
279 inline void write_2bytes_be_to(uint8_t *t)
281 t[0] = b.h; t[1] = b.l;
283 inline void read_4bytes_le_from(uint8_t *t)
285 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
287 inline void write_4bytes_le_to(uint8_t *t)
289 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
291 inline void read_4bytes_be_from(uint8_t *t)
293 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
295 inline void write_4bytes_be_to(uint8_t *t)
297 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
301 uint32_t EndianToLittle_DWORD(uint32_t x);
302 uint16_t EndianToLittle_WORD(uint16_t x);
308 int max(int a, int b);
309 unsigned int max(unsigned int a, unsigned int b);
310 int min(int a, int b);
311 unsigned int min(unsigned int a, unsigned int b);
315 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
316 #define stricmp(a,b) strcasecmp(a,b)
317 #define strnicmp(a,b,n) strncasecmp(a,b,n)
320 #ifndef SUPPORT_TCHAR_TYPE
322 #define _tfopen fopen
325 #define _tcscmp strcmp
328 #define _tcscpy strcpy
331 #define _tcsicmp stricmp
334 #define _tcslen strlen
337 #define _tcsncat strncat
340 #define _tcsncpy strncpy
343 #define _tcsncicmp strnicmp
346 #define _tcschr strchr
349 #define _tcsrchr strrchr
352 #define _tcsstr strstr
355 #define _tcstok strtok
361 #define _tcstol strtol
364 #define _tcstoul strtoul
367 #define _stprintf sprintf
370 #define _vstprintf vsprintf
373 #define _taccess access
376 #define _tremove remove
379 #define _trename rename
383 #define _TEXT(x) __T(x)
386 #ifndef SUPPORT_SECURE_FUNCTIONS
390 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
391 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
392 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
393 errno_t my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
394 errno_t my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
395 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
396 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
397 #define my_fprintf_s fprintf
398 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
399 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
400 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
401 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
403 // #define my_tfopen_s _tfopen_s
404 #define my_strcpy_s strcpy_s
405 #define my_tcscpy_s _tcscpy_s
406 #define my_strncpy_s strncpy_s
407 #define my_tcsncpy_s _tcsncpy_s
408 #define my_strtok_s strtok_s
409 #define my_tcstok_s _tcstok_s
410 #define my_fprintf_s fprintf_s
411 #define my_sprintf_s sprintf_s
412 #define my_stprintf_s _stprintf_s
413 #define my_vsprintf_s vsprintf_s
414 #define my_vstprintf_s _vstprintf_s
419 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
420 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
421 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
422 // used only in winmain and win32 osd class
423 // #define ZeroMemory(p,s) memset(p,0x00,s)
424 // #define CopyMemory(t,f,s) memcpy(t,f,s)
426 #define MyWritePrivateProfileString WritePrivateProfileString
427 #define MyGetPrivateProfileString GetPrivateProfileString
428 #define MyGetPrivateProfileInt GetPrivateProfileInt
432 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
436 #if defined(_RGB555) || defined(_RGB565)
437 typedef uint16_t scrntype_t;
438 scrntype_t RGB_COLOR(uint32_t r, uint32_t g, uint32_t b);
439 scrntype_t RGBA_COLOR(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
440 uint8_t R_OF_COLOR(scrntype_t c);
441 uint8_t G_OF_COLOR(scrntype_t c);
442 uint8_t B_OF_COLOR(scrntype_t c);
443 uint8_t A_OF_COLOR(scrntype_t c);
444 #elif defined(_RGB888)
445 typedef uint32_t scrntype_t;
446 #define RGB_COLOR(r, g, b) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0))
447 #define RGBA_COLOR(r, g, b, a) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0) | ((uint32_t)(a) << 24))
448 #define R_OF_COLOR(c) (((c) >> 16) & 0xff)
449 #define G_OF_COLOR(c) (((c) >> 8) & 0xff)
450 #define B_OF_COLOR(c) (((c) ) & 0xff)
451 #define A_OF_COLOR(c) (((c) >> 24) & 0xff)
464 wav_chunk_t riff_chunk;
466 wav_chunk_t fmt_chunk;
469 uint32_t sample_rate;
472 uint16_t sample_bits;
477 const _TCHAR *get_application_path();
478 const _TCHAR *create_local_path(const _TCHAR *format, ...);
479 void create_local_path(_TCHAR *file_path, int length, const _TCHAR *format, ...);
480 const _TCHAR *create_date_file_path(const _TCHAR *extension);
481 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
482 bool check_file_extension(const _TCHAR *file_path, const _TCHAR *ext);
483 const _TCHAR *get_file_path_without_extensiton(const _TCHAR *file_path);
484 void get_long_full_path_name(const _TCHAR* src, _TCHAR* dst, size_t dst_len);
485 const _TCHAR* get_parent_dir(const _TCHAR* file);
488 const _TCHAR *create_string(const _TCHAR* format, ...);
489 uint32_t get_crc32(uint8_t data[], int size);
490 uint16_t jis_to_sjis(uint16_t jis);
492 int decibel_to_volume(int decibel);
493 int32_t apply_volume(int32_t sample, int volume);
495 #define array_length(array) (sizeof(array) / sizeof(array[0]))
497 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
498 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
499 #define TO_BCD_LO(v) ((v) % 10)
500 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
502 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
504 typedef struct cur_time_s {
505 int year, month, day, day_of_week, hour, minute, second;
513 void update_day_of_week();
514 void save_state(void *f);
515 bool load_state(void *f);
518 void get_host_time(cur_time_t* cur_time);
521 #define EMU_LOG_CPU1 0x00000001
522 #define EMU_LOG_CPU2 0x00000002
523 #define EMU_LOG_CPU3 0x00000004
524 #define EMU_LOG_CPU4 0x00000008
525 #define EMU_LOG_FLOPPY 0x00000010
526 #define EMU_LOG_CMT 0x00000020
527 #define EMU_LOG_QD 0x00000040
528 #define EMU_LOG_CART 0x00000080
529 #define EMU_LOG_BINARY 0x00000100
530 #define EMU_LOG_LASERDISC 0x00000200
531 #define EMU_LOG_DISPLAY 0x00001000
532 #define EMU_LOG_SOUND 0x00002000
533 #define EMU_LOG_KEYBOARD 0x00004000
534 #define EMU_LOG_IO 0x00008000
535 #define EMU_LOG_MEMORY 0x00010000
536 #define EMU_LOG_USR1 0x00020000
537 #define EMU_LOG_USR2 0x00040000
538 #define EMU_LOG_USR3 0x00080000
539 #define EMU_LOG_USR4 0x00100000
540 #define EMU_LOG_USR5 0x00200000
541 #define EMU_LOG_USR6 0x00400000
542 #define EMU_LOG_USR7 0x00800000
543 #define EMU_LOG_USR8 0x01000000
544 #define EMU_LOG_USR9 0x02000000
545 #define EMU_LOG_USR10 0x04000000
546 #define EMU_LOG_GUI 0x08000000
547 #define EMU_LOG_DEBUG 0x10000000
548 #define EMU_LOG_INFO 0x20000000
549 #define EMU_LOG_WARNING 0x40000000
550 #define EMU_LOG_GENERAL 0x80000000