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"
49 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
50 #if defined(_MSC_VER) && (_MSC_VER == 1200)
51 #define for if(0);else for
54 // disable warnings for microsoft visual c++ 2005 or later
55 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
56 #pragma warning( disable : 4819 )
57 //#pragma warning( disable : 4995 )
58 #pragma warning( disable : 4996 )
62 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
63 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
64 #if __BYTE_ORDER == __LITTLE_ENDIAN
65 #define __LITTLE_ENDIAN__
66 #elif __BYTE_ORDER == __BIG_ENDIAN
67 #define __BIG_ENDIAN__
69 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
70 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
71 #define __LITTLE_ENDIAN__
72 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
73 #define __BIG_ENDIAN__
75 #elif defined(WORDS_LITTLEENDIAN)
76 #define __LITTLE_ENDIAN__
77 #elif defined(WORDS_BIGENDIAN)
78 #define __BIG_ENDIAN__
81 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
82 // Microsoft Visual C++
83 #define __LITTLE_ENDIAN__
89 typedef unsigned char uint8;
92 typedef unsigned short uint16;
95 typedef unsigned int uint32;
99 typedef unsigned __int64 uint64;
101 typedef unsigned long long uint64;
105 typedef signed char int8;
108 typedef signed short int16;
111 typedef signed int int32;
115 typedef signed __int64 int64;
117 typedef signed long long int64;
121 #if defined(__LITTLE_ENDIAN__)
122 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
127 static inline uint16_t EndianToLittle_WORD(uint16_t x)
132 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
135 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
136 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
140 static inline uint16_t EndianToLittle_WORD(uint16_t x)
143 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
150 #ifdef __BIG_ENDIAN__
157 #ifdef __BIG_ENDIAN__
164 #ifdef __BIG_ENDIAN__
171 #ifdef __BIG_ENDIAN__
179 inline void read_2bytes_le_from(uint8 *t)
181 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
183 inline void write_2bytes_le_to(uint8 *t)
185 t[0] = b.l; t[1] = b.h;
187 inline void read_2bytes_be_from(uint8 *t)
189 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
191 inline void write_2bytes_be_to(uint8 *t)
193 t[0] = b.h; t[1] = b.l;
195 inline void read_4bytes_le_from(uint8 *t)
197 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
199 inline void write_4bytes_le_to(uint8 *t)
201 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
203 inline void read_4bytes_be_from(uint8 *t)
205 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
207 inline void write_4bytes_be_to(uint8 *t)
209 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
214 // max/min from WinDef.h
216 #define MAX_MACRO_NOT_DEFINED
217 inline int max(int a, int b);
218 inline unsigned int max(unsigned int a, unsigned int b);
221 #define MIN_MACRO_NOT_DEFINED
222 inline int min(int a, int b);
223 inline unsigned int min(unsigned int a, unsigned int b);
227 #ifndef SUPPORT_TCHAR_TYPE
229 #define _tfopen fopen
232 #define _tcscmp strcmp
235 #define _tcscpy strcpy
238 #define _tcsicmp stricmp
241 #define _tcslen strlen
244 #define _tcsncat strncat
247 #define _tcsncpy strncpy
250 #define _tcsncicmp strnicmp
253 #define _tcsstr strstr
256 #define _tcstok strtok
259 #define _tcstol strtol
262 #define _tcstoul strtoul
265 #define _stprintf sprintf
268 #define _vstprintf vsprintf
271 #define _taccess access
274 #define _tremove remove
278 #define _TEXT(x) __T(x)
282 #ifndef SUPPORT_SECURE_FUNCTIONS
286 // errno_t my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
287 errno_t my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
288 errno_t my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
289 _TCHAR *my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
290 int my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
291 int my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
293 // #define my_tfopen_s _tfopen_s
294 #define my_strcpy_s strcpy_s
295 #define my_tcscpy_s _tcscpy_s
296 #define my_tcstok_s _tcstok_s
297 #define my_stprintf_s _stprintf_s
298 #define my_vstprintf_s _vstprintf_s
302 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
303 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
304 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
306 #define MyWritePrivateProfileString WritePrivateProfileString
307 #define MyGetPrivateProfileString GetPrivateProfileString
308 #define MyGetPrivateProfileInt GetPrivateProfileInt
314 #if defined(_RGB555) || defined(_RGB565)
315 typedef uint16 scrntype;
316 scrntype RGB_COLOR(uint r, uint g, uint b);
317 scrntype RGBA_COLOR(uint r, uint g, uint b, uint a);
318 uint8 R_OF_COLOR(scrntype c);
319 uint8 G_OF_COLOR(scrntype c);
320 uint8 B_OF_COLOR(scrntype c);
321 uint8 A_OF_COLOR(scrntype c);
322 #elif defined(__BIG_ENDIAN__)
323 # if defined(_RGB888)
324 typedef uint32 scrntype;
325 #define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
326 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8) | ((uint32)(a) << 0))
327 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
328 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
329 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
330 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
333 #else // LITTLE ENDIAN
335 # if defined(_RGB888)
336 typedef uint32 scrntype;
337 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (uint32)0xff << 24)
338 #define RGBA_COLOR(r, g, b, a) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | ((uint32)(a) << 24))
339 #define R_OF_COLOR(c) (((c) >> 24) & 0xff)
340 #define G_OF_COLOR(c) (((c) >> 16) & 0xff)
341 #define B_OF_COLOR(c) (((c) >> 8 ) & 0xff)
342 #define A_OF_COLOR(c) (((c) >> 0 ) & 0xff)
349 #ifndef SUPPORT_TCHAR_TYPE
352 #define _tfopen fopen
353 #define _tcscmp strcmp
354 #define _tcscpy strcpy
355 #define _tcsicmp stricmp
356 #define _tcslen strlen
357 #define _tcsncat strncat
358 #define _tcsncpy strncpy
359 #define _tcsncicmp strnicmp
360 #define _tcsstr strstr
361 #define _tcstok strtok
362 #define _tcstol strtol
363 #define _tcstoul strtoul
364 #define _stprintf sprintf
365 #define _vstprintf vsprintf
368 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
372 # define _strcpy_s _tcscpy_s
373 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
374 # define strcpy_s _tcscpy_s
375 # define tcscpy_s _tcscpy_s
376 # define tcstok_s _tcstok_s
377 # define stprintf_s _stprintf_s
378 # define vstprintf_s _vstprintf_s
379 # define vsprintf_s _vsprintf_s
381 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
382 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
383 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
384 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
387 va_start(ap, format);
388 int result = vsprintf(buffer, format, ap);
392 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
394 # define _strcpy_s _tcscpy_s
395 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
410 wav_chunk_t riff_chunk;
412 wav_chunk_t fmt_chunk;
424 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
425 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
426 uint32 getcrc32(uint8 data[], int size);
429 #define array_length(array) (sizeof(array) / sizeof(array[0]))
431 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
432 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
433 #define TO_BCD_LO(v) ((v) % 10)
434 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
436 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
438 typedef struct cur_time_s {
439 int year, month, day, day_of_week, hour, minute, second;
447 void update_day_of_week();
448 void save_state(void *f);
449 bool load_state(void *f);