2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
13 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
14 #define SUPPORT_TCHAR_TYPE
16 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
17 #define SUPPORT_SECURE_FUNCTIONS
20 // secure functions need tchar type
21 #ifndef SUPPORT_TCHAR_TYPE
22 #undef SUPPORT_SECURE_FUNCTIONS
25 #ifdef SUPPORT_TCHAR_TYPE
34 #define EMU_LOG_CPU1 0x00000001
35 #define EMU_LOG_CPU2 0x00000002
36 #define EMU_LOG_CPU3 0x00000004
37 #define EMU_LOG_CPU4 0x00000008
38 #define EMU_LOG_FLOPPY 0x00000010
39 #define EMU_LOG_CMT 0x00000020
40 #define EMU_LOG_QD 0x00000040
41 #define EMU_LOG_CART 0x00000080
42 #define EMU_LOG_BINARY 0x00000100
43 #define EMU_LOG_LASERDISC 0x00000200
44 #define EMU_LOG_DISPLAY 0x00001000
45 #define EMU_LOG_SOUND 0x00002000
46 #define EMU_LOG_KEYBOARD 0x00004000
47 #define EMU_LOG_IO 0x00008000
48 #define EMU_LOG_MEMORY 0x00010000
49 #define EMU_LOG_USR1 0x00020000
50 #define EMU_LOG_USR2 0x00040000
51 #define EMU_LOG_USR3 0x00080000
52 #define EMU_LOG_USR4 0x00100000
53 #define EMU_LOG_USR5 0x00200000
54 #define EMU_LOG_USR6 0x00400000
55 #define EMU_LOG_USR7 0x00800000
56 #define EMU_LOG_USR8 0x01000000
57 #define EMU_LOG_USR9 0x02000000
58 #define EMU_LOG_USR10 0x04000000
59 #define EMU_LOG_GUI 0x08000000
60 #define EMU_LOG_DEBUG 0x10000000
61 #define EMU_LOG_INFO 0x20000000
62 #define EMU_LOG_WARNING 0x40000000
63 #define EMU_LOG_GENERAL 0x80000000
70 # define __CSP_COMPILER_MS_C
74 # if defined(_USE_QT5)
77 # include <sys/param.h>
79 # define _MAX_PATH 2048
85 #include "common_gcc.h"
86 #elif defined(_MSC_VER)
87 //#include "common_msc.h"
92 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
93 #define for if(0);else for
96 #define SUPPORT_TCHAR_TYPE
99 #define SUPPORT_SECURE_FUNCTIONS
100 // disable warnings for Microsoft Visual C++ 2005 or later
101 #pragma warning( disable : 4819 )
102 //#pragma warning( disable : 4995 )
103 #pragma warning( disable : 4996 )
106 // Windows, but not VC++
107 #define SUPPORT_TCHAR_TYPE
108 // #define SUPPORT_SECURE_FUNCTIONS
112 // disable warnings for microsoft visual c++ 2005 or later
113 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
114 #pragma warning( disable : 4819 )
115 //#pragma warning( disable : 4995 )
116 #pragma warning( disable : 4996 )
120 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
121 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
122 #if __BYTE_ORDER == __LITTLE_ENDIAN
123 #define __LITTLE_ENDIAN__
124 #elif __BYTE_ORDER == __BIG_ENDIAN
125 #define __BIG_ENDIAN__
127 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
128 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
129 #define __LITTLE_ENDIAN__
130 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
131 #define __BIG_ENDIAN__
133 #elif defined(WORDS_LITTLEENDIAN)
134 #define __LITTLE_ENDIAN__
135 #elif defined(WORDS_BIGENDIAN)
136 #define __BIG_ENDIAN__
139 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
140 // may be Microsoft Visual C++
141 #define __LITTLE_ENDIAN__
146 #if !defined(_MSC_VER) && !defined(CSP_OS_GCC_WINDOWS) && !defined(CSP_OS_GCC_CYGWIN)
148 typedef bool boolean;
151 typedef unsigned char byte;
155 typedef unsigned char uchar;
158 typedef unsigned char uint8;
161 typedef unsigned short uint16;
164 typedef unsigned int uint32;
168 typedef unsigned __int64 uint64;
170 //typedef unsigned long long uint64;
174 typedef signed char int8;
177 typedef signed short int16;
180 typedef signed int int32;
184 typedef signed __int64 int64;
186 //typedef signed long long int64;
189 #ifndef SUPPORT_TCHAR_TYPE
194 #if defined(_MSC_VER)
195 # define CSP_OS_VISUALC
196 # define CSP_OS_WINDOWS
198 typedef uint8_t uint8;
200 typedef uint16_t uint16;
201 typedef int16_t int16;
202 typedef uint32_t uint32;
203 typedef int32_t int32;
204 typedef uint64_t uint64;
205 typedef int64_t int64;
208 typedef uint8_t BYTE;
209 typedef uint16_t WORD;
210 typedef uint32_t DWORD;
211 typedef uint64_t QWORD;
212 //# if !defined(Q_OS_CYGWIN)
213 typedef uint8_t UINT8;
214 typedef uint16_t UINT16;
215 typedef uint32_t UINT32;
216 typedef uint64_t UINT64;
218 typedef int16_t INT16;
219 typedef int32_t INT32;
220 typedef int64_t INT64;
225 typedef _TCHAR* LPTSTR;
227 #ifndef LPCTSTR // This with const causes FTBFS with GCC/LLVM .
228 typedef _TCHAR* LPCTSTR;
232 #if defined(__LITTLE_ENDIAN__)
233 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
238 static inline uint16_t EndianToLittle_WORD(uint16_t x)
243 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
246 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
247 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
251 static inline uint16_t EndianToLittle_WORD(uint16_t x)
254 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
261 #ifdef __BIG_ENDIAN__
268 #ifdef __BIG_ENDIAN__
275 #ifdef __BIG_ENDIAN__
282 #ifdef __BIG_ENDIAN__
290 inline void read_2bytes_le_from(uint8 *t)
292 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
294 inline void write_2bytes_le_to(uint8 *t)
296 t[0] = b.l; t[1] = b.h;
298 inline void read_2bytes_be_from(uint8 *t)
300 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
302 inline void write_2bytes_be_to(uint8 *t)
304 t[0] = b.h; t[1] = b.l;
306 inline void read_4bytes_le_from(uint8 *t)
308 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
310 inline void write_4bytes_le_to(uint8 *t)
312 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
314 inline void read_4bytes_be_from(uint8 *t)
316 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
318 inline void write_4bytes_be_to(uint8 *t)
320 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
325 // max/min from WinDef.h
329 #define MAX_MACRO_NOT_DEFINED
330 int max(int a, int b);
331 unsigned int max(unsigned int a, unsigned int b);
332 #define MIN_MACRO_NOT_DEFINED
333 int min(int a, int b);
334 unsigned int min(unsigned int a, unsigned int b);
337 //#if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
338 // #define stricmp(a,b) strcasecmp(a,b)
339 // #define strnicmp(a,b,n) strncasecmp(a,b,n)
343 #ifndef SUPPORT_TCHAR_TYPE
345 #define _tfopen fopen
348 #define _tcscmp strcmp
351 #define _tcscpy strcpy
354 #define _tcsicmp stricmp
357 #define _tcslen strlen
360 #define _tcsncat strncat
363 #define _tcsncpy strncpy
366 #define _tcsncicmp strnicmp
369 #define _tcschr strchr
372 #define _tcsrchr strrchr
375 #define _tcsstr strstr
378 #define _tcstok strtok
381 #define _tcstol strtol
384 #define _tcstoul strtoul
387 #define _stprintf sprintf
390 #define _vstprintf vsprintf
393 #define _taccess access
396 #define _tremove remove
399 #define _trename rename
403 #define _TEXT(x) __T(x)
406 #ifndef SUPPORT_SECURE_FUNCTIONS
410 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
411 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
412 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
413 errno_t my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
414 errno_t my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
415 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
416 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
417 #define my_fprintf_s fprintf
418 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
419 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
420 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
421 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
423 // #define my_tfopen_s _tfopen_s
424 #define my_strcpy_s strcpy_s
425 #define my_tcscpy_s _tcscpy_s
426 #define my_strncpy_s strncpy_s
427 #define my_tcsncpy_s _tcsncpy_s
428 #define my_strtok_s strtok_s
429 #define my_tcstok_s _tcstok_s
430 #define my_fprintf_s fprintf_s
431 #define my_sprintf_s sprintf_s
432 #define my_stprintf_s _stprintf_s
433 #define my_vsprintf_s vsprintf_s
434 #define my_vstprintf_s _vstprintf_s
439 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
440 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPCTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
441 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
442 // used only in winmain and win32 osd class
443 // #define ZeroMemory(p,s) memset(p,0x00,s)
444 // #define CopyMemory(t,f,s) memcpy(t,f,s)
446 #define MyWritePrivateProfileString WritePrivateProfileString
447 #define MyGetPrivateProfileString GetPrivateProfileString
448 #define MyGetPrivateProfileInt GetPrivateProfileInt
455 #if defined(_RGB555) || defined(_RGB565)
456 typedef uint16 scrntype;
457 scrntype RGB_COLOR(uint r, uint g, uint b);
458 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
459 uint8 R_OF_COLOR(scrntype c);
460 uint8 G_OF_COLOR(scrntype c);
461 uint8 B_OF_COLOR(scrntype c);
462 uint8 A_OF_COLOR(scrntype c);
463 #elif defined(__BIG_ENDIAN__)
464 # if defined(_RGB888)
465 typedef uint32 scrntype;
466 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
467 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
468 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
469 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
470 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
471 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
474 #else // LITTLE ENDIAN
476 # if defined(_RGB888)
477 typedef uint32 scrntype;
478 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
479 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
480 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
481 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
482 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
483 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
490 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
491 #define stricmp(a,b) strcasecmp(a,b)
492 #define strnicmp(a,b,n) strncasecmp(a,b,n)
493 #define _strnicmp(a,b,n) strnicmp(a,b,n)
497 #ifndef SUPPORT_TCHAR_TYPE
500 #define _tfopen fopen
501 #define _tcscmp strcmp
502 #define _tcscpy strcpy
503 #define _tcsicmp stricmp
504 #define _tcslen strlen
505 #define _tcsncat strncat
506 #define _tcsncpy strncpy
507 #define _tcsncicmp strnicmp
508 #define _tcsstr strstr
509 #define _tcstok strtok
510 #define _tcstol strtol
511 #define _tcstoul strtoul
512 #define _stprintf sprintf
513 #define _vstprintf vsprintf
516 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
520 # define _strcpy_s _tcscpy_s
521 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
522 # define strcpy_s _tcscpy_s
523 # define tcscpy_s _tcscpy_s
524 # define tcstok_s _tcstok_s
525 # define stprintf_s _stprintf_s
526 # define vstprintf_s _vstprintf_s
527 # define vsprintf_s _vsprintf_s
529 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
530 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
531 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
532 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
535 va_start(ap, format);
536 int result = vsprintf(buffer, format, ap);
540 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
542 # define _strcpy_s _tcscpy_s
543 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
558 wav_chunk_t riff_chunk;
560 wav_chunk_t fmt_chunk;
571 const _TCHAR *application_path();
572 const _TCHAR *create_local_path(const _TCHAR* format, ...);
573 void create_local_path(_TCHAR *file_path, int length, const _TCHAR* format, ...);
574 const _TCHAR *create_date_file_path(const _TCHAR *extension);
575 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
576 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
577 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
579 uint32 getcrc32(uint8 data[], int size);
582 #define array_length(array) (sizeof(array) / sizeof(array[0]))
584 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
585 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
586 #define TO_BCD_LO(v) ((v) % 10)
587 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
589 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
591 typedef struct cur_time_s {
592 int year, month, day, day_of_week, hour, minute, second;
600 void update_day_of_week();
601 void save_state(void *f);
602 bool load_state(void *f);
605 void get_host_time(cur_time_t* cur_time);