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 #ifdef SUPPORT_TCHAR_TYPE
32 # define __CSP_COMPILER_MS_C
36 # if defined(_USE_QT5)
41 # include <QtCore/QString>
42 # include <QtCore/QFile>
48 #include "common_gcc.h"
49 #elif defined(_MSC_VER)
50 #include "common_msc.h"
52 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
53 #if defined(_MSC_VER) && (_MSC_VER == 1200)
54 #define for if(0);else for
57 // disable warnings for microsoft visual c++ 2005 or later
58 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
59 #pragma warning( disable : 4819 )
60 //#pragma warning( disable : 4995 )
61 #pragma warning( disable : 4996 )
65 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
66 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
67 #if __BYTE_ORDER == __LITTLE_ENDIAN
68 #define __LITTLE_ENDIAN__
69 #elif __BYTE_ORDER == __BIG_ENDIAN
70 #define __BIG_ENDIAN__
72 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
73 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
74 #define __LITTLE_ENDIAN__
75 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
76 #define __BIG_ENDIAN__
78 #elif defined(WORDS_LITTLEENDIAN)
79 #define __LITTLE_ENDIAN__
80 #elif defined(WORDS_BIGENDIAN)
81 #define __BIG_ENDIAN__
84 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
85 // Microsoft Visual C++
86 #define __LITTLE_ENDIAN__
92 typedef unsigned char uint8;
95 typedef unsigned short uint16;
98 typedef unsigned int uint32;
102 typedef unsigned __int64 uint64;
104 //typedef unsigned long long uint64;
108 typedef signed char int8;
111 typedef signed short int16;
114 typedef signed int int32;
118 typedef signed __int64 int64;
120 //typedef signed long long int64;
124 #if defined(__LITTLE_ENDIAN__)
125 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
130 static inline uint16_t EndianToLittle_WORD(uint16_t x)
135 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
138 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
139 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
143 static inline uint16_t EndianToLittle_WORD(uint16_t x)
146 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
153 #ifdef __BIG_ENDIAN__
160 #ifdef __BIG_ENDIAN__
167 #ifdef __BIG_ENDIAN__
174 #ifdef __BIG_ENDIAN__
182 inline void read_2bytes_le_from(uint8 *t)
184 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
186 inline void write_2bytes_le_to(uint8 *t)
188 t[0] = b.l; t[1] = b.h;
190 inline void read_2bytes_be_from(uint8 *t)
192 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
194 inline void write_2bytes_be_to(uint8 *t)
196 t[0] = b.h; t[1] = b.l;
198 inline void read_4bytes_le_from(uint8 *t)
200 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
202 inline void write_4bytes_le_to(uint8 *t)
204 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
206 inline void read_4bytes_be_from(uint8 *t)
208 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
210 inline void write_4bytes_be_to(uint8 *t)
212 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
217 // max/min from WinDef.h
221 #define MAX_MACRO_NOT_DEFINED
222 int max(int a, int b);
223 unsigned int max(unsigned int a, unsigned int b);
224 #define MIN_MACRO_NOT_DEFINED
225 int min(int a, int b);
226 unsigned int min(unsigned int a, unsigned int b);
229 //#if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
230 // #define stricmp(a,b) strcasecmp(a,b)
231 // #define strnicmp(a,b,n) strncasecmp(a,b,n)
235 #ifndef SUPPORT_TCHAR_TYPE
237 #define _tfopen fopen
240 #define _tcscmp strcmp
243 #define _tcscpy strcpy
246 #define _tcsicmp stricmp
249 #define _tcslen strlen
252 #define _tcsncat strncat
255 #define _tcsncpy strncpy
258 #define _tcsncicmp strnicmp
261 #define _tcsstr strstr
264 #define _tcstok strtok
267 #define _tcstol strtol
270 #define _tcstoul strtoul
273 #define _stprintf sprintf
276 #define _vstprintf vsprintf
279 #define _taccess access
282 #define _tremove remove
285 #define _trename rename
289 #define _TEXT(x) __T(x)
292 #ifndef SUPPORT_SECURE_FUNCTIONS
296 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
297 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
298 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
299 char *my_strtok_s(char *strToken, const char *strDelimit, char **context);
300 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
301 #define my_fprintf_s fprintf
302 int my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
303 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
304 int my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
305 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
307 // #define my_tfopen_s _tfopen_s
308 #define my_strcpy_s strcpy_s
309 #define my_tcscpy_s _tcscpy_s
310 #define my_strtok_s strtok_s
311 #define my_tcstok_s _tcstok_s
312 #define my_fprintf_s fprintf_s
313 #define my_sprintf_s sprintf_s
314 #define my_stprintf_s _stprintf_s
315 #define my_vsprintf_s vsprintf_s
316 #define my_vstprintf_s _vstprintf_s
320 #if!defined(_MSC_VER) && !defined(CSP_OS_WINDOWS)
321 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
322 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPCTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
323 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
325 #define MyWritePrivateProfileString WritePrivateProfileString
326 #define MyGetPrivateProfileString GetPrivateProfileString
327 #define MyGetPrivateProfileInt GetPrivateProfileInt
332 #define ZeroMemory(p,s) memset(p,0x00,s)
333 #define CopyMemory(t,f,s) memcpy(t,f,s)
339 #if defined(_RGB555) || defined(_RGB565)
340 typedef uint16 scrntype;
341 scrntype RGB_COLOR(uint r, uint g, uint b);
342 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
343 uint8 R_OF_COLOR(scrntype c);
344 uint8 G_OF_COLOR(scrntype c);
345 uint8 B_OF_COLOR(scrntype c);
346 uint8 A_OF_COLOR(scrntype c);
347 #elif defined(__BIG_ENDIAN__)
348 # if defined(_RGB888)
349 typedef uint32 scrntype;
350 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
351 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
352 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
353 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
354 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
355 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
358 #else // LITTLE ENDIAN
360 # if defined(_RGB888)
361 typedef uint32 scrntype;
362 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
363 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
364 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
365 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
366 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
367 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
374 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
375 #define stricmp(a,b) strcasecmp(a,b)
376 #define strnicmp(a,b,n) strncasecmp(a,b,n)
380 #ifndef SUPPORT_TCHAR_TYPE
383 #define _tfopen fopen
384 #define _tcscmp strcmp
385 #define _tcscpy strcpy
386 #define _tcsicmp stricmp
387 #define _tcslen strlen
388 #define _tcsncat strncat
389 #define _tcsncpy strncpy
390 #define _tcsncicmp strnicmp
391 #define _tcsstr strstr
392 #define _tcstok strtok
393 #define _tcstol strtol
394 #define _tcstoul strtoul
395 #define _stprintf sprintf
396 #define _vstprintf vsprintf
399 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
403 # define _strcpy_s _tcscpy_s
404 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
405 # define strcpy_s _tcscpy_s
406 # define tcscpy_s _tcscpy_s
407 # define tcstok_s _tcstok_s
408 # define stprintf_s _stprintf_s
409 # define vstprintf_s _vstprintf_s
410 # define vsprintf_s _vsprintf_s
412 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
413 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
414 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
415 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
418 va_start(ap, format);
419 int result = vsprintf(buffer, format, ap);
423 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
425 # define _strcpy_s _tcscpy_s
426 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
441 wav_chunk_t riff_chunk;
443 wav_chunk_t fmt_chunk;
455 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
456 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
457 uint32 getcrc32(uint8 data[], int size);
460 #define array_length(array) (sizeof(array) / sizeof(array[0]))
462 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
463 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
464 #define TO_BCD_LO(v) ((v) % 10)
465 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
467 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
469 typedef struct cur_time_s {
470 int year, month, day, day_of_week, hour, minute, second;
478 void update_day_of_week();
479 void save_state(void *f);
480 bool load_state(void *f);