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
19 #ifdef SUPPORT_TCHAR_TYPE
30 # define __CSP_COMPILER_MS_C
34 # if defined(_USE_QT5)
39 # include <QtCore/QString>
40 # include <QtCore/QFile>
46 #include "common_gcc.h"
47 #elif defined(_MSC_VER)
48 #include "common_msc.h"
50 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
51 #if defined(_MSC_VER) && (_MSC_VER == 1200)
52 #define for if(0);else for
55 // disable warnings for microsoft visual c++ 2005 or later
56 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
57 #pragma warning( disable : 4819 )
58 //#pragma warning( disable : 4995 )
59 #pragma warning( disable : 4996 )
63 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
64 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
65 #if __BYTE_ORDER == __LITTLE_ENDIAN
66 #define __LITTLE_ENDIAN__
67 #elif __BYTE_ORDER == __BIG_ENDIAN
68 #define __BIG_ENDIAN__
70 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
71 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
72 #define __LITTLE_ENDIAN__
73 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
74 #define __BIG_ENDIAN__
76 #elif defined(WORDS_LITTLEENDIAN)
77 #define __LITTLE_ENDIAN__
78 #elif defined(WORDS_BIGENDIAN)
79 #define __BIG_ENDIAN__
82 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
83 // Microsoft Visual C++
84 #define __LITTLE_ENDIAN__
90 typedef unsigned char uint8;
93 typedef unsigned short uint16;
96 typedef unsigned int uint32;
100 typedef unsigned __int64 uint64;
102 //typedef unsigned long long uint64;
106 typedef signed char int8;
109 typedef signed short int16;
112 typedef signed int int32;
116 typedef signed __int64 int64;
118 //typedef signed long long int64;
122 #if defined(__LITTLE_ENDIAN__)
123 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
128 static inline uint16_t EndianToLittle_WORD(uint16_t x)
133 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
136 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
137 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
141 static inline uint16_t EndianToLittle_WORD(uint16_t x)
144 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
151 #ifdef __BIG_ENDIAN__
158 #ifdef __BIG_ENDIAN__
165 #ifdef __BIG_ENDIAN__
172 #ifdef __BIG_ENDIAN__
180 inline void read_2bytes_le_from(uint8 *t)
182 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
184 inline void write_2bytes_le_to(uint8 *t)
186 t[0] = b.l; t[1] = b.h;
188 inline void read_2bytes_be_from(uint8 *t)
190 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
192 inline void write_2bytes_be_to(uint8 *t)
194 t[0] = b.h; t[1] = b.l;
196 inline void read_4bytes_le_from(uint8 *t)
198 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
200 inline void write_4bytes_le_to(uint8 *t)
202 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
204 inline void read_4bytes_be_from(uint8 *t)
206 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
208 inline void write_4bytes_be_to(uint8 *t)
210 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
215 // max/min from WinDef.h
217 #define MAX_MACRO_NOT_DEFINED
218 int max(int a, int b);
219 unsigned int max(unsigned int a, unsigned int b);
222 #define MIN_MACRO_NOT_DEFINED
223 int min(int a, int b);
224 unsigned int min(unsigned int a, unsigned int b);
228 #ifndef SUPPORT_TCHAR_TYPE
230 #define _tfopen fopen
233 #define _tcscmp strcmp
236 #define _tcscpy strcpy
239 #define _tcsicmp stricmp
242 #define _tcslen strlen
245 #define _tcsncat strncat
248 #define _tcsncpy strncpy
251 #define _tcsncicmp strnicmp
254 #define _tcsstr strstr
257 #define _tcstok strtok
260 #define _tcstol strtol
263 #define _tcstoul strtoul
266 #define _stprintf sprintf
269 #define _vstprintf vsprintf
272 #define _taccess access
275 #define _tremove remove
279 #define _TEXT(x) __T(x)
283 #ifndef SUPPORT_SECURE_FUNCTIONS
287 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
288 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
289 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
290 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
291 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
292 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
294 // #define my_tfopen_s _tfopen_s
295 #define my_strcpy_s strcpy_s
296 #define my_tcscpy_s _tcscpy_s
297 #define my_tcstok_s _tcstok_s
298 #define my_stprintf_s _stprintf_s
299 #define my_vstprintf_s _vstprintf_s
302 #if!defined(_MSC_VER) && !defined(CSP_OS_WINDOWS)
303 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
304 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPCTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
305 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
307 #define MyWritePrivateProfileString WritePrivateProfileString
308 #define MyGetPrivateProfileString GetPrivateProfileString
309 #define MyGetPrivateProfileInt GetPrivateProfileInt
315 #if defined(_RGB555) || defined(_RGB565)
316 typedef uint16 scrntype;
317 scrntype RGB_COLOR(uint r, uint g, uint b);
318 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
319 uint8 R_OF_COLOR(scrntype c);
320 uint8 G_OF_COLOR(scrntype c);
321 uint8 B_OF_COLOR(scrntype c);
322 uint8 A_OF_COLOR(scrntype c);
323 #elif defined(__BIG_ENDIAN__)
324 # if defined(_RGB888)
325 typedef uint32 scrntype;
326 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
327 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
328 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
329 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
330 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
331 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
334 #else // LITTLE ENDIAN
336 # if defined(_RGB888)
337 typedef uint32 scrntype;
338 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
339 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
340 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
341 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
342 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
343 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
350 #ifndef SUPPORT_TCHAR_TYPE
353 #define _tfopen fopen
354 #define _tcscmp strcmp
355 #define _tcscpy strcpy
356 #define _tcsicmp stricmp
357 #define _tcslen strlen
358 #define _tcsncat strncat
359 #define _tcsncpy strncpy
360 #define _tcsncicmp strnicmp
361 #define _tcsstr strstr
362 #define _tcstok strtok
363 #define _tcstol strtol
364 #define _tcstoul strtoul
365 #define _stprintf sprintf
366 #define _vstprintf vsprintf
369 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
373 # define _strcpy_s _tcscpy_s
374 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
375 # define strcpy_s _tcscpy_s
376 # define tcscpy_s _tcscpy_s
377 # define tcstok_s _tcstok_s
378 # define stprintf_s _stprintf_s
379 # define vstprintf_s _vstprintf_s
380 # define vsprintf_s _vsprintf_s
382 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
383 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
384 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
385 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
388 va_start(ap, format);
389 int result = vsprintf(buffer, format, ap);
393 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
395 # define _strcpy_s _tcscpy_s
396 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
411 wav_chunk_t riff_chunk;
413 wav_chunk_t fmt_chunk;
425 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
426 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
427 uint32 getcrc32(uint8 data[], int size);
430 #define array_length(array) (sizeof(array) / sizeof(array[0]))
432 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
433 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
434 #define TO_BCD_LO(v) ((v) % 10)
435 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
437 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
439 typedef struct cur_time_s {
440 int year, month, day, day_of_week, hour, minute, second;
448 void update_day_of_week();
449 void save_state(void *f);
450 bool load_state(void *f);