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
31 #if defined(_USE_AGAR) || defined(_USE_SDL)
33 #include <agar/core.h>
35 #elif defined(_USE_QT)
38 # if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
41 # if defined(_USE_QT5)
46 # include <QtCore/QString>
47 # include <QtCore/QFile>
53 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
56 typedef uint8_t uint8;
62 typedef uint16_t uint16;
65 typedef int16_t int16;
68 typedef uint32_t uint32;
71 typedef int32_t int32;
74 typedef uint64_t uint64;
77 typedef int64_t int64;
82 # if !defined(Q_OS_WIN32) && !defined(Q_OS_WIN) && !defined(Q_OS_CYGWIN)
87 typedef uint16_t WORD;
90 typedef uint32_t DWORD;
93 typedef uint64_t QWORD;
97 typedef uint8_t UINT8;
100 typedef uint16_t UINT16;
103 typedef uint32_t UINT32;
106 typedef uint64_t UINT64;
113 typedef int16_t INT16;
116 typedef int32_t INT32;
119 typedef int64_t INT64;
122 //# ifndef Q_OS_WIN32
123 static inline void _stprintf(char *s, const char *fmt, ...) {
127 sprintf(s, fmt, args);
130 # define stricmp(a,b) strcmp(a,b)
131 # define strnicmp(a,b,n) strncmp(a,b,n)
136 //# define __T(x) L ## x
141 # define _T(x) __T(x)
142 # define _TEXT(x) __T(x)
145 // typedef wchar_t _TCHAR;
151 typedef _TCHAR* LPCTSTR;
155 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
156 return strncpy((char *)d, (char *)s, n);
159 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
160 return strncat((char *)d, (char *)s, n);
165 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
166 # if defined(Q_OS_CYGWIN)
167 # define stricmp(a,b) strcmp(a,b)
168 # define strnicmp(a,b,n) strncmp(a,b,n)
170 # if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
174 static int DeleteFile(_TCHAR *path)
177 QString fpath = (char *)path;
179 if(tfp.remove(fpath)) return (int)true;
182 return AG_FileDelete((const char *)path);
189 # include <libintl.h>
190 # define _N(x) gettext(x)
197 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
198 # if defined(Q_OS_WIN32) || defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
202 #undef __LITTLE_ENDIAN___
203 #undef __BIG_ENDIAN___
205 # if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
206 # define __LITTLE_ENDIAN__
207 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
212 static inline uint16_t EndianToLittle_WORD(uint16_t x)
217 # define __BIG_ENDIAN__
218 static inline uint32_t EndianToLittle_DWORD(uint32_t x)
221 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
222 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
226 static inline uint16_t EndianToLittle_WORD(uint16_t x)
229 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
233 #define ZeroMemory(p,s) memset(p,0x00,s)
234 #define CopyMemory(t,f,s) memcpy(t,f,s)
237 # if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
238 # if SDL_BYTEORDER == SDL_LIL_ENDIAN
239 # define __LITTLE_ENDIAN__
241 # define __BIG_ENDIAN__
249 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
251 #if defined(_MSC_VER) && (_MSC_VER == 1200)
252 #define for if(0);else for
255 // disable warnings for microsoft visual c++ 2005 or later
256 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
257 #pragma warning( disable : 4819 )
258 //#pragma warning( disable : 4995 )
259 #pragma warning( disable : 4996 )
263 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
264 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
265 #if __BYTE_ORDER == __LITTLE_ENDIAN
266 #define __LITTLE_ENDIAN__
267 #elif __BYTE_ORDER == __BIG_ENDIAN
268 #define __BIG_ENDIAN__
270 #elif defined(WORDS_LITTLEENDIAN)
271 #define __LITTLE_ENDIAN__
272 #elif defined(WORDS_BIGENDIAN)
273 #define __BIG_ENDIAN__
276 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
277 // Microsoft Visual C++
278 #define __LITTLE_ENDIAN__
284 typedef unsigned char uint8;
287 typedef unsigned short uint16;
290 typedef unsigned int uint32;
294 typedef unsigned __int64 uint64;
296 typedef unsigned long long uint64;
300 typedef signed char int8;
303 typedef signed short int16;
306 typedef signed int int32;
310 typedef signed __int64 int64;
312 typedef signed long long int64;
316 static inline DWORD EndianToLittle_DWORD(DWORD x)
321 static inline WORD EndianToLittle_WORD(WORD x)
331 #ifdef __BIG_ENDIAN__
338 #ifdef __BIG_ENDIAN__
345 #ifdef __BIG_ENDIAN__
352 #ifdef __BIG_ENDIAN__
360 inline void read_2bytes_le_from(uint8 *t)
362 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
364 inline void write_2bytes_le_to(uint8 *t)
366 t[0] = b.l; t[1] = b.h;
368 inline void read_2bytes_be_from(uint8 *t)
370 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
372 inline void write_2bytes_be_to(uint8 *t)
374 t[0] = b.h; t[1] = b.l;
376 inline void read_4bytes_le_from(uint8 *t)
378 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
380 inline void write_4bytes_le_to(uint8 *t)
382 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
384 inline void read_4bytes_be_from(uint8 *t)
386 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
388 inline void write_4bytes_be_to(uint8 *t)
390 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
395 // max/min from WinDef.h
397 //#define max(a,b) (((a) > (b)) ? (a) : (b))
400 //#define min(a,b) (((a) < (b)) ? (a) : (b))
404 #if !defined(_USE_QT)
410 #if defined(__BIG_ENDIAN__)
411 # if defined(_RGB555)
412 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
413 typedef uint16 scrntype;
414 # elif defined(_RGB565)
415 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
416 typedef uint16 scrntype;
417 # elif defined(_RGB888)
418 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
419 typedef uint32 scrntype;
420 # elif defined(_RGBA888)
421 //# if defined(USE_BITMAP)
422 //# define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)((r | g | b) == 0x00) ? 0x00 : 0xff)
424 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
426 typedef uint32 scrntype;
429 #else // LITTLE ENDIAN
431 # if defined(_RGB555)
432 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
433 typedef uint16 scrntype;
434 # elif defined(_RGB565)
435 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
436 typedef uint16 scrntype;
437 # elif defined(_RGB888)
438 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
439 typedef uint32 scrntype;
440 # elif defined(_RGBA888)
441 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
443 typedef uint32 scrntype;
450 #ifndef SUPPORT_TCHAR_TYPE
453 #define _tfopen fopen
454 #define _tcscmp strcmp
455 #define _tcscpy strcpy
456 # if !defined(_tcsicmp)
457 # define _tcsicmp stricmp
459 #define _tcslen strlen
460 #define _tcsncat strncat
461 #define _tcsncpy strncpy
462 # if !defined(_tcsncicmp)
463 #define _tcsncicmp strnicmp
465 #define _tcsstr strstr
466 #define _tcstok strtok
467 #define _tcstol strtol
468 #define _tcstoul strtoul
469 #define _stprintf sprintf
470 #define _vstprintf vsprintf
473 #if !defined(_MSC_VER)
478 #ifndef SUPPORT_SECURE_FUNCTIONS
482 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
483 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
484 # if !defined(Q_OS_WIN32) && !defined(Q_OS_WIN) //&& !defined(Q_OS_CYGWIN)
485 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
486 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
488 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
489 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
491 #define _strcpy_s strcpy_s
504 wav_chunk_t riff_chunk;
506 wav_chunk_t fmt_chunk;
517 //#if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
520 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
521 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
522 uint32 getcrc32(uint8 data[], int size);
525 #define array_length(array) (sizeof(array) / sizeof(array[0]))
527 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
528 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
529 #define TO_BCD_LO(v) ((v) % 10)
530 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
532 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
534 typedef struct cur_time_s {
535 int year, month, day, day_of_week, hour, minute, second;
543 void update_day_of_week();
544 void save_state(void *f);
545 bool load_state(void *f);