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
35 # if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
38 # if defined(_USE_QT5)
43 # include <QtCore/QString>
44 # include <QtCore/QFile>
50 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
53 typedef uint8_t uint8;
59 typedef uint16_t uint16;
62 typedef int16_t int16;
65 typedef uint32_t uint32;
68 typedef int32_t int32;
71 typedef uint64_t uint64;
74 typedef int64_t int64;
79 # if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
84 typedef uint16_t WORD;
87 typedef uint32_t DWORD;
90 typedef uint64_t QWORD;
93 # if !defined(Q_OS_CYGWIN)
95 typedef uint8_t UINT8;
98 typedef uint16_t UINT16;
101 typedef uint32_t UINT32;
104 typedef uint64_t UINT64;
111 typedef int16_t INT16;
114 typedef int32_t INT32;
117 typedef int64_t INT64;
120 # if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
121 static inline void _stprintf(char *s, const char *fmt, ...) {
125 sprintf(s, fmt, args);
129 # define stricmp(a,b) strcmp(a,b)
130 # define strnicmp(a,b,n) strncmp(a,b,n)
135 # define _T(x) __T(x)
136 # define _TEXT(x) __T(x)
140 # if !defined(Q_OS_CYGWIN) && !defined(Q_OS_WIN)
142 typedef _TCHAR* LPCTSTR;
144 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
145 return strncpy((char *)d, (char *)s, n);
148 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
149 return strncat((char *)d, (char *)s, n);
157 # if defined(Q_OS_CYGWIN)
158 # define stricmp(a,b) strcmp(a,b)
159 # define strnicmp(a,b,n) strncmp(a,b,n)
161 # if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
165 static int DeleteFile(_TCHAR *path)
168 QString fpath = (char *)path;
170 if(tfp.remove(fpath)) return (int)true;
173 return AG_FileDelete((const char *)path);
184 # if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
188 #undef __LITTLE_ENDIAN___
189 #undef __BIG_ENDIAN___
191 # if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
192 # define __LITTLE_ENDIAN__
193 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
198 static inline uint16_t EndianToLittle_WORD(uint16_t x)
203 # define __BIG_ENDIAN__
204 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
207 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
208 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
212 static inline uint16_t EndianToLittle_WORD(uint16_t x)
215 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
219 #define ZeroMemory(p,s) memset(p,0x00,s)
220 #define CopyMemory(t,f,s) memcpy(t,f,s)
223 # if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
224 # if SDL_BYTEORDER == SDL_LIL_ENDIAN
225 # define __LITTLE_ENDIAN__
227 # define __BIG_ENDIAN__
235 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
237 #if defined(_MSC_VER) && (_MSC_VER == 1200)
238 #define for if(0);else for
241 // disable warnings for microsoft visual c++ 2005 or later
242 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
243 #pragma warning( disable : 4819 )
244 //#pragma warning( disable : 4995 )
245 #pragma warning( disable : 4996 )
249 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
250 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
251 #if __BYTE_ORDER == __LITTLE_ENDIAN
252 #define __LITTLE_ENDIAN__
253 #elif __BYTE_ORDER == __BIG_ENDIAN
254 #define __BIG_ENDIAN__
256 #elif defined(WORDS_LITTLEENDIAN)
257 #define __LITTLE_ENDIAN__
258 #elif defined(WORDS_BIGENDIAN)
259 #define __BIG_ENDIAN__
262 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
263 // Microsoft Visual C++
264 #define __LITTLE_ENDIAN__
270 typedef unsigned char uint8;
273 typedef unsigned short uint16;
276 typedef unsigned int uint32;
280 typedef unsigned __int64 uint64;
282 typedef unsigned long long uint64;
286 typedef signed char int8;
289 typedef signed short int16;
292 typedef signed int int32;
296 typedef signed __int64 int64;
298 typedef signed long long int64;
302 static inline DWORD EndianToLittle_DWORD(DWORD x)
307 static inline WORD EndianToLittle_WORD(WORD x)
317 #ifdef __BIG_ENDIAN__
324 #ifdef __BIG_ENDIAN__
331 #ifdef __BIG_ENDIAN__
338 #ifdef __BIG_ENDIAN__
346 inline void read_2bytes_le_from(uint8 *t)
348 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
350 inline void write_2bytes_le_to(uint8 *t)
352 t[0] = b.l; t[1] = b.h;
354 inline void read_2bytes_be_from(uint8 *t)
356 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
358 inline void write_2bytes_be_to(uint8 *t)
360 t[0] = b.h; t[1] = b.l;
362 inline void read_4bytes_le_from(uint8 *t)
364 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
366 inline void write_4bytes_le_to(uint8 *t)
368 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
370 inline void read_4bytes_be_from(uint8 *t)
372 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
374 inline void write_4bytes_be_to(uint8 *t)
376 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
381 // max/min from WinDef.h
383 #if !defined(_USE_QT)
389 #if defined(__BIG_ENDIAN__)
390 # if defined(_RGB555)
391 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
392 typedef uint16 scrntype;
393 # elif defined(_RGB565)
394 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
395 typedef uint16 scrntype;
396 # elif defined(_RGB888)
397 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
398 typedef uint32 scrntype;
399 # elif defined(_RGBA888)
400 //# define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
401 # define RGB_COLOR(r, g, b) (((uint32)(b) << 24) | ((uint32)(g) << 16) | ((uint32)(r) << 8)) | ((uint32)0xff << 0)
402 typedef uint32 scrntype;
405 #else // LITTLE ENDIAN
407 # if defined(_RGB555)
408 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
409 typedef uint16 scrntype;
410 # elif defined(_RGB565)
411 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
412 typedef uint16 scrntype;
413 # elif defined(_RGB888)
414 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
415 typedef uint32 scrntype;
416 # elif defined(_RGBA888)
417 //# define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
418 # define RGB_COLOR(r, g, b) (((uint32)(b) << 16) | ((uint32)(g) << 8) | ((uint32)(r) << 0)) | ((uint32)0xff << 24)
419 typedef uint32 scrntype;
426 #ifndef SUPPORT_TCHAR_TYPE
429 #define _tfopen fopen
430 #define _tcscmp strcmp
431 #define _tcscpy strcpy
432 # if !defined(_tcsicmp)
433 # define _tcsicmp stricmp
435 #define _tcslen strlen
436 #define _tcsncat strncat
437 #define _tcsncpy strncpy
438 # if !defined(_tcsncicmp)
439 #define _tcsncicmp strnicmp
441 #define _tcsstr strstr
442 #define _tcstok strtok
443 #define _tcstol strtol
444 #define _tcstoul strtoul
445 #define _stprintf sprintf
446 #define _vstprintf vsprintf
449 #if !defined(_MSC_VER)
454 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(Q_OS_WIN)
458 # if defined(Q_OS_WIN)
459 # define strcpy_s _strcpy_s
460 # define tcscpy_s _tcscpy_s
461 # define tcstok_s _tcstok_s
462 # define stprintf_s _stprintf_s
463 # define vstprintf_s _vstprintf_s
464 # define vsprintf_s _vsprintf_s
466 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
467 # if !defined(Q_OS_WIN) //&& !defined(Q_OS_CYGWIN)
468 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
469 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
471 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
472 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
474 # define _strcpy_s strcpy_s
487 wav_chunk_t riff_chunk;
489 wav_chunk_t fmt_chunk;
502 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
503 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
504 uint32 getcrc32(uint8 data[], int size);
507 #define array_length(array) (sizeof(array) / sizeof(array[0]))
509 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
510 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
511 #define TO_BCD_LO(v) ((v) % 10)
512 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
514 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
516 typedef struct cur_time_s {
517 int year, month, day, day_of_week, hour, minute, second;
525 void update_day_of_week();
526 void save_state(void *f);
527 bool load_state(void *f);