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
111 // secure functions need tchar type
112 #ifndef SUPPORT_TCHAR_TYPE
113 #undef SUPPORT_SECURE_FUNCTIONS
118 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
119 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
120 #if __BYTE_ORDER == __LITTLE_ENDIAN
121 #define __LITTLE_ENDIAN__
122 #elif __BYTE_ORDER == __BIG_ENDIAN
123 #define __BIG_ENDIAN__
125 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
126 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
127 #define __LITTLE_ENDIAN__
128 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
129 #define __BIG_ENDIAN__
131 #elif defined(WORDS_LITTLEENDIAN)
132 #define __LITTLE_ENDIAN__
133 #elif defined(WORDS_BIGENDIAN)
134 #define __BIG_ENDIAN__
137 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
138 // may be Microsoft Visual C++
139 #define __LITTLE_ENDIAN__
144 #if !defined(_MSC_VER) && !defined(CSP_OS_GCC_WINDOWS) && !defined(CSP_OS_GCC_CYGWIN)
146 typedef bool boolean;
149 typedef unsigned char byte;
153 typedef unsigned char uchar;
156 typedef unsigned char uint8;
159 typedef unsigned short uint16;
162 typedef unsigned int uint32;
166 typedef unsigned __int64 uint64;
168 //typedef unsigned long long uint64;
172 typedef signed char int8;
175 typedef signed short int16;
178 typedef signed int int32;
182 typedef signed __int64 int64;
184 //typedef signed long long int64;
187 #ifndef SUPPORT_TCHAR_TYPE
192 #if defined(_MSC_VER)
193 # define CSP_OS_VISUALC
194 # define CSP_OS_WINDOWS
196 typedef uint8_t uint8;
198 typedef uint16_t uint16;
199 typedef int16_t int16;
200 typedef uint32_t uint32;
201 typedef int32_t int32;
202 typedef uint64_t uint64;
203 typedef int64_t int64;
206 typedef uint8_t BYTE;
207 typedef uint16_t WORD;
208 typedef uint32_t DWORD;
209 typedef uint64_t QWORD;
210 //# if !defined(Q_OS_CYGWIN)
211 typedef uint8_t UINT8;
212 typedef uint16_t UINT16;
213 typedef uint32_t UINT32;
214 typedef uint64_t UINT64;
216 typedef int16_t INT16;
217 typedef int32_t INT32;
218 typedef int64_t INT64;
223 typedef _TCHAR* LPTSTR;
225 #ifndef LPCTSTR // This with const causes FTBFS with GCC/LLVM .
226 typedef _TCHAR* LPCTSTR;
230 #if defined(__LITTLE_ENDIAN__)
231 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
236 static inline uint16_t EndianToLittle_WORD(uint16_t x)
241 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
244 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
245 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
249 static inline uint16_t EndianToLittle_WORD(uint16_t x)
252 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
259 #ifdef __BIG_ENDIAN__
266 #ifdef __BIG_ENDIAN__
273 #ifdef __BIG_ENDIAN__
280 #ifdef __BIG_ENDIAN__
288 inline void read_2bytes_le_from(uint8 *t)
290 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
292 inline void write_2bytes_le_to(uint8 *t)
294 t[0] = b.l; t[1] = b.h;
296 inline void read_2bytes_be_from(uint8 *t)
298 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
300 inline void write_2bytes_be_to(uint8 *t)
302 t[0] = b.h; t[1] = b.l;
304 inline void read_4bytes_le_from(uint8 *t)
306 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
308 inline void write_4bytes_le_to(uint8 *t)
310 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
312 inline void read_4bytes_be_from(uint8 *t)
314 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
316 inline void write_4bytes_be_to(uint8 *t)
318 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
323 // max/min from WinDef.h
327 #define MAX_MACRO_NOT_DEFINED
328 int max(int a, int b);
329 unsigned int max(unsigned int a, unsigned int b);
330 #define MIN_MACRO_NOT_DEFINED
331 int min(int a, int b);
332 unsigned int min(unsigned int a, unsigned int b);
335 //#if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
336 // #define stricmp(a,b) strcasecmp(a,b)
337 // #define strnicmp(a,b,n) strncasecmp(a,b,n)
341 #ifndef SUPPORT_TCHAR_TYPE
343 #define _tfopen fopen
346 #define _tcscmp strcmp
349 #define _tcscpy strcpy
352 #define _tcsicmp stricmp
355 #define _tcslen strlen
358 #define _tcsncat strncat
361 #define _tcsncpy strncpy
364 #define _tcsncicmp strnicmp
367 #define _tcschr strchr
370 #define _tcsrchr strrchr
373 #define _tcsstr strstr
376 #define _tcstok strtok
382 #define _tcstol strtol
385 #define _tcstoul strtoul
388 #define _stprintf sprintf
391 #define _vstprintf vsprintf
394 #define _taccess access
397 #define _tremove remove
400 #define _trename rename
404 #define _TEXT(x) __T(x)
407 #ifndef SUPPORT_SECURE_FUNCTIONS
411 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
412 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
413 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
414 errno_t my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
415 errno_t my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
416 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
417 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
418 #define my_fprintf_s fprintf
419 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
420 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
421 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
422 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
424 // #define my_tfopen_s _tfopen_s
425 #define my_strcpy_s strcpy_s
426 #define my_tcscpy_s _tcscpy_s
427 #define my_strncpy_s strncpy_s
428 #define my_tcsncpy_s _tcsncpy_s
429 #define my_strtok_s strtok_s
430 #define my_tcstok_s _tcstok_s
431 #define my_fprintf_s fprintf_s
432 #define my_sprintf_s sprintf_s
433 #define my_stprintf_s _stprintf_s
434 #define my_vsprintf_s vsprintf_s
435 #define my_vstprintf_s _vstprintf_s
440 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
441 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPCTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
442 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
443 // used only in winmain and win32 osd class
444 // #define ZeroMemory(p,s) memset(p,0x00,s)
445 // #define CopyMemory(t,f,s) memcpy(t,f,s)
447 #define MyWritePrivateProfileString WritePrivateProfileString
448 #define MyGetPrivateProfileString GetPrivateProfileString
449 #define MyGetPrivateProfileInt GetPrivateProfileInt
454 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
458 #if defined(_RGB555) || defined(_RGB565)
459 typedef uint16 scrntype;
460 scrntype RGB_COLOR(uint r, uint g, uint b);
461 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
462 uint8 R_OF_COLOR(scrntype c);
463 uint8 G_OF_COLOR(scrntype c);
464 uint8 B_OF_COLOR(scrntype c);
465 uint8 A_OF_COLOR(scrntype c);
466 #elif defined(__BIG_ENDIAN__)
467 # if defined(_RGB888)
468 typedef uint32 scrntype;
469 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
470 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
471 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
472 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
473 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
474 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
477 #else // LITTLE ENDIAN
479 # if defined(_RGB888)
480 typedef uint32 scrntype;
481 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
482 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
483 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
484 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
485 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
486 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
493 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
494 #define stricmp(a,b) strcasecmp(a,b)
495 #define strnicmp(a,b,n) strncasecmp(a,b,n)
496 #define _strnicmp(a,b,n) strnicmp(a,b,n)
500 #ifndef SUPPORT_TCHAR_TYPE
503 #define _tfopen fopen
504 #define _tcscmp strcmp
505 #define _tcscpy strcpy
506 #define _tcsicmp stricmp
507 #define _tcslen strlen
508 #define _tcsncat strncat
509 #define _tcsncpy strncpy
510 #define _tcsncicmp strnicmp
511 #define _tcsstr strstr
512 #define _tcstok strtok
513 #define _tcstol strtol
514 #define _tcstoul strtoul
515 #define _stprintf sprintf
516 #define _vstprintf vsprintf
519 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
523 # define _strcpy_s _tcscpy_s
524 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
525 # define strcpy_s _tcscpy_s
526 # define tcscpy_s _tcscpy_s
527 # define tcstok_s _tcstok_s
528 # define stprintf_s _stprintf_s
529 # define vstprintf_s _vstprintf_s
530 # define vsprintf_s _vsprintf_s
532 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
533 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
534 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
535 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
538 va_start(ap, format);
539 int result = vsprintf(buffer, format, ap);
543 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
545 # define _strcpy_s _tcscpy_s
546 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
561 wav_chunk_t riff_chunk;
563 wav_chunk_t fmt_chunk;
574 const _TCHAR *application_path();
575 const _TCHAR *create_local_path(const _TCHAR* format, ...);
576 void create_local_path(_TCHAR *file_path, int length, const _TCHAR* format, ...);
577 const _TCHAR *create_date_file_path(const _TCHAR *extension);
578 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
580 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
581 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
583 uint32 getcrc32(uint8 data[], int size);
586 #define array_length(array) (sizeof(array) / sizeof(array[0]))
588 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
589 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
590 #define TO_BCD_LO(v) ((v) % 10)
591 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
593 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
595 typedef struct cur_time_s {
596 int year, month, day, day_of_week, hour, minute, second;
604 void update_day_of_week();
605 void save_state(void *f);
606 bool load_state(void *f);
609 void get_host_time(cur_time_t* cur_time);