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
38 # define __CSP_COMPILER_MS_C
42 # if defined(_USE_QT5)
50 #include "common_gcc.h"
51 #elif defined(_MSC_VER)
52 //#include "common_msc.h"
57 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
58 #define for if(0);else for
61 #define SUPPORT_TCHAR_TYPE
64 #define SUPPORT_SECURE_FUNCTIONS
65 // disable warnings for Microsoft Visual C++ 2005 or later
66 #pragma warning( disable : 4819 )
67 //#pragma warning( disable : 4995 )
68 #pragma warning( disable : 4996 )
71 // Windows, but not VC++
72 #define SUPPORT_TCHAR_TYPE
73 // #define SUPPORT_SECURE_FUNCTIONS
77 // disable warnings for microsoft visual c++ 2005 or later
78 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
79 #pragma warning( disable : 4819 )
80 //#pragma warning( disable : 4995 )
81 #pragma warning( disable : 4996 )
85 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
86 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
87 #if __BYTE_ORDER == __LITTLE_ENDIAN
88 #define __LITTLE_ENDIAN__
89 #elif __BYTE_ORDER == __BIG_ENDIAN
90 #define __BIG_ENDIAN__
92 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
93 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
94 #define __LITTLE_ENDIAN__
95 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
96 #define __BIG_ENDIAN__
98 #elif defined(WORDS_LITTLEENDIAN)
99 #define __LITTLE_ENDIAN__
100 #elif defined(WORDS_BIGENDIAN)
101 #define __BIG_ENDIAN__
104 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
105 // may be Microsoft Visual C++
106 #define __LITTLE_ENDIAN__
113 typedef bool boolean;
116 typedef unsigned char byte;
120 typedef unsigned char uchar;
123 typedef unsigned char uint8;
126 typedef unsigned short uint16;
129 typedef unsigned int uint32;
133 typedef unsigned __int64 uint64;
135 //typedef unsigned long long uint64;
139 typedef signed char int8;
142 typedef signed short int16;
145 typedef signed int int32;
149 typedef signed __int64 int64;
151 //typedef signed long long int64;
154 #ifndef SUPPORT_TCHAR_TYPE
159 #if defined(_MSC_VER)
160 # define CSP_OS_VISUALC
161 # define CSP_OS_WINDOWS
163 typedef uint8_t uint8;
165 typedef uint16_t uint16;
166 typedef int16_t int16;
167 typedef uint32_t uint32;
168 typedef int32_t int32;
169 typedef uint64_t uint64;
170 typedef int64_t int64;
173 typedef uint8_t BYTE;
174 typedef uint16_t WORD;
175 typedef uint32_t DWORD;
176 typedef uint64_t QWORD;
177 //# if !defined(Q_OS_CYGWIN)
178 typedef uint8_t UINT8;
179 typedef uint16_t UINT16;
180 typedef uint32_t UINT32;
181 typedef uint64_t UINT64;
183 typedef int16_t INT16;
184 typedef int32_t INT32;
185 typedef int64_t INT64;
190 typedef _TCHAR* LPTSTR;
193 typedef const _TCHAR* LPCTSTR;
197 #if defined(__LITTLE_ENDIAN__)
198 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
203 static inline uint16_t EndianToLittle_WORD(uint16_t x)
208 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
211 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
212 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
216 static inline uint16_t EndianToLittle_WORD(uint16_t x)
219 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
226 #ifdef __BIG_ENDIAN__
233 #ifdef __BIG_ENDIAN__
240 #ifdef __BIG_ENDIAN__
247 #ifdef __BIG_ENDIAN__
255 inline void read_2bytes_le_from(uint8 *t)
257 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
259 inline void write_2bytes_le_to(uint8 *t)
261 t[0] = b.l; t[1] = b.h;
263 inline void read_2bytes_be_from(uint8 *t)
265 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
267 inline void write_2bytes_be_to(uint8 *t)
269 t[0] = b.h; t[1] = b.l;
271 inline void read_4bytes_le_from(uint8 *t)
273 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
275 inline void write_4bytes_le_to(uint8 *t)
277 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
279 inline void read_4bytes_be_from(uint8 *t)
281 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
283 inline void write_4bytes_be_to(uint8 *t)
285 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
290 // max/min from WinDef.h
294 #define MAX_MACRO_NOT_DEFINED
295 int max(int a, int b);
296 unsigned int max(unsigned int a, unsigned int b);
297 #define MIN_MACRO_NOT_DEFINED
298 int min(int a, int b);
299 unsigned int min(unsigned int a, unsigned int b);
302 //#if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
303 // #define stricmp(a,b) strcasecmp(a,b)
304 // #define strnicmp(a,b,n) strncasecmp(a,b,n)
308 #ifndef SUPPORT_TCHAR_TYPE
310 #define _tfopen fopen
313 #define _tcscmp strcmp
316 #define _tcscpy strcpy
319 #define _tcsicmp stricmp
322 #define _tcslen strlen
325 #define _tcsncat strncat
328 #define _tcsncpy strncpy
331 #define _tcsncicmp strnicmp
334 #define _tcschr strchr
337 #define _tcsrchr strrchr
340 #define _tcsstr strstr
343 #define _tcstok strtok
346 #define _tcstol strtol
349 #define _tcstoul strtoul
352 #define _stprintf sprintf
355 #define _vstprintf vsprintf
358 #define _taccess access
361 #define _tremove remove
364 #define _trename rename
368 #define _TEXT(x) __T(x)
371 #ifndef SUPPORT_SECURE_FUNCTIONS
375 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
376 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
377 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
378 errno_t my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
379 errno_t my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
380 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
381 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
382 #define my_fprintf_s fprintf
383 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
384 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
385 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
386 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
388 // #define my_tfopen_s _tfopen_s
389 #define my_strcpy_s strcpy_s
390 #define my_tcscpy_s _tcscpy_s
391 #define my_strncpy_s strncpy_s
392 #define my_tcsncpy_s _tcsncpy_s
393 #define my_strtok_s strtok_s
394 #define my_tcstok_s _tcstok_s
395 #define my_fprintf_s fprintf_s
396 #define my_sprintf_s sprintf_s
397 #define my_stprintf_s _stprintf_s
398 #define my_vsprintf_s vsprintf_s
399 #define my_vstprintf_s _vstprintf_s
404 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
405 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPCTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
406 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
407 // used only in winmain and win32 osd class
408 // #define ZeroMemory(p,s) memset(p,0x00,s)
409 // #define CopyMemory(t,f,s) memcpy(t,f,s)
411 #define MyWritePrivateProfileString WritePrivateProfileString
412 #define MyGetPrivateProfileString GetPrivateProfileString
413 #define MyGetPrivateProfileInt GetPrivateProfileInt
420 #if defined(_RGB555) || defined(_RGB565)
421 typedef uint16 scrntype;
422 scrntype RGB_COLOR(uint r, uint g, uint b);
423 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
424 uint8 R_OF_COLOR(scrntype c);
425 uint8 G_OF_COLOR(scrntype c);
426 uint8 B_OF_COLOR(scrntype c);
427 uint8 A_OF_COLOR(scrntype c);
428 #elif defined(__BIG_ENDIAN__)
429 # if defined(_RGB888)
430 typedef uint32 scrntype;
431 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
432 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
433 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
434 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
435 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
436 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
439 #else // LITTLE ENDIAN
441 # if defined(_RGB888)
442 typedef uint32 scrntype;
443 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
444 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
445 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
446 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
447 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
448 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
455 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
456 #define stricmp(a,b) strcasecmp(a,b)
457 #define strnicmp(a,b,n) strncasecmp(a,b,n)
458 #define _strnicmp(a,b,n) strnicmp(a,b,n)
462 #ifndef SUPPORT_TCHAR_TYPE
465 #define _tfopen fopen
466 #define _tcscmp strcmp
467 #define _tcscpy strcpy
468 #define _tcsicmp stricmp
469 #define _tcslen strlen
470 #define _tcsncat strncat
471 #define _tcsncpy strncpy
472 #define _tcsncicmp strnicmp
473 #define _tcsstr strstr
474 #define _tcstok strtok
475 #define _tcstol strtol
476 #define _tcstoul strtoul
477 #define _stprintf sprintf
478 #define _vstprintf vsprintf
481 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
485 # define _strcpy_s _tcscpy_s
486 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
487 # define strcpy_s _tcscpy_s
488 # define tcscpy_s _tcscpy_s
489 # define tcstok_s _tcstok_s
490 # define stprintf_s _stprintf_s
491 # define vstprintf_s _vstprintf_s
492 # define vsprintf_s _vsprintf_s
494 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
495 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
496 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
497 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
500 va_start(ap, format);
501 int result = vsprintf(buffer, format, ap);
505 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
507 # define _strcpy_s _tcscpy_s
508 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
523 wav_chunk_t riff_chunk;
525 wav_chunk_t fmt_chunk;
536 const _TCHAR *application_path();
537 const _TCHAR *create_local_path(const _TCHAR* format, ...);
538 void create_local_path(_TCHAR *file_path, int length, const _TCHAR* format, ...);
539 const _TCHAR *create_date_file_path(const _TCHAR *extension);
540 void create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
541 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
542 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
544 uint32 getcrc32(uint8 data[], int size);
547 #define array_length(array) (sizeof(array) / sizeof(array[0]))
549 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
550 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
551 #define TO_BCD_LO(v) ((v) % 10)
552 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
554 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
556 typedef struct cur_time_s {
557 int year, month, day, day_of_week, hour, minute, second;
565 void update_day_of_week();
566 void save_state(void *f);
567 bool load_state(void *f);
570 void get_host_time(cur_time_t* cur_time);