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)
39 # if defined(_USE_QT5)
43 # include <QtCore/QString>
44 # include <QtCore/QFile>
48 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
51 typedef uint8_t uint8;
57 typedef uint16_t uint16;
60 typedef int16_t int16;
63 typedef uint32_t uint32;
66 typedef int32_t int32;
69 typedef uint64_t uint64;
72 typedef int64_t int64;
81 typedef uint16_t WORD;
84 typedef uint32_t DWORD;
87 typedef uint64_t QWORD;
91 typedef uint8_t UINT8;
94 typedef uint16_t UINT16;
97 typedef uint32_t UINT32;
100 typedef uint64_t UINT64;
107 typedef int16_t INT16;
110 typedef int32_t INT32;
113 typedef int64_t INT64;
116 static inline void _stprintf(char *s, const char *fmt, ...) {
120 sprintf(s, fmt, args);
123 #define stricmp(a,b) strcmp(a,b)
124 #define strnicmp(a,b,n) strncmp(a,b,n)
129 //# define __T(x) L ## x
134 # define _T(x) __T(x)
135 # define _TEXT(x) __T(x)
138 // typedef wchar_t _TCHAR;
144 typedef _TCHAR* LPCTSTR;
148 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
149 return strncpy((char *)d, (char *)s, n);
152 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
153 return strncat((char *)d, (char *)s, n);
157 static inline int DeleteFile(_TCHAR *path)
160 QString fpath = (char *)path;
162 if(tfp.remove(fpath)) return (int)true;
165 return AG_FileDelete((const char *)path);
171 # include <libintl.h>
172 # define _N(x) gettext(x)
177 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
178 static inline DWORD EndianToLittle_DWORD(DWORD x)
183 static inline WORD EndianToLittle_WORD(WORD x)
188 static inline DWORD EndianToLittle_DWORD(DWORD x)
191 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
192 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
196 static inline WORD EndianToLittle_WORD(WORD x)
199 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
203 #define ZeroMemory(p,s) memset(p,0x00,s)
204 #define CopyMemory(t,f,s) memcpy(t,f,s)
210 //extern void Sleep(uint32_t tick);
211 //extern uint32_t timeGetTime(void);
219 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
221 #if defined(_MSC_VER) && (_MSC_VER == 1200)
222 #define for if(0);else for
225 // disable warnings for microsoft visual c++ 2005 or later
226 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
227 #pragma warning( disable : 4819 )
228 //#pragma warning( disable : 4995 )
229 #pragma warning( disable : 4996 )
233 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
234 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
235 #if __BYTE_ORDER == __LITTLE_ENDIAN
236 #define __LITTLE_ENDIAN__
237 #elif __BYTE_ORDER == __BIG_ENDIAN
238 #define __BIG_ENDIAN__
240 #elif defined(WORDS_LITTLEENDIAN)
241 #define __LITTLE_ENDIAN__
242 #elif defined(WORDS_BIGENDIAN)
243 #define __BIG_ENDIAN__
246 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
247 // Microsoft Visual C++
248 #define __LITTLE_ENDIAN__
254 typedef unsigned char uint8;
257 typedef unsigned short uint16;
260 typedef unsigned int uint32;
264 typedef unsigned __int64 uint64;
266 typedef unsigned long long uint64;
271 typedef signed char int8;
274 typedef signed short int16;
277 typedef signed int int32;
281 typedef signed __int64 int64;
283 typedef signed long long int64;
287 static inline DWORD EndianToLittle_DWORD(DWORD x)
292 static inline WORD EndianToLittle_WORD(WORD x)
303 #ifdef __BIG_ENDIAN__
310 #ifdef __BIG_ENDIAN__
317 #ifdef __BIG_ENDIAN__
324 #ifdef __BIG_ENDIAN__
332 inline void read_2bytes_le_from(uint8 *t)
334 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
336 inline void write_2bytes_le_to(uint8 *t)
338 t[0] = b.l; t[1] = b.h;
340 inline void read_2bytes_be_from(uint8 *t)
342 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
344 inline void write_2bytes_be_to(uint8 *t)
346 t[0] = b.h; t[1] = b.l;
348 inline void read_4bytes_le_from(uint8 *t)
350 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
352 inline void write_4bytes_le_to(uint8 *t)
354 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
356 inline void read_4bytes_be_from(uint8 *t)
358 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
360 inline void write_4bytes_be_to(uint8 *t)
362 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
367 // max/min from WinDef.h
369 //#define max(a,b) (((a) > (b)) ? (a) : (b))
372 //#define min(a,b) (((a) < (b)) ? (a) : (b))
376 #if !defined(_USE_QT)
382 #if defined(_USE_AGAR)
384 # if AG_BYTEORDER == AG_BIG_ENDIAN
385 # if defined(_RGB555)
386 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
387 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
388 typedef uint16 scrntype;
389 # elif defined(_RGB565)
390 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
391 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
392 typedef uint16 scrntype;
393 # elif defined(_RGB888)
394 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
395 typedef uint32 scrntype;
396 # elif defined(_RGBA888)
397 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
398 typedef uint32 scrntype;
401 #else // LITTLE ENDIAN
403 # if defined(_RGB555)
404 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
405 typedef uint16 scrntype;
406 # elif defined(_RGB565)
407 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
408 typedef uint16 scrntype;
409 # elif defined(_RGB888)
410 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16))
411 typedef uint32 scrntype;
412 # elif defined(_RGBA888)
413 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16)) | ((uint32)0xff << 24)
414 typedef uint32 scrntype;
419 #else // NOT USE AGAR
421 # if defined(_RGB555)
422 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(b) & 0xf8) >> 3))
423 typedef uint16 scrntype;
424 #elif defined(_RGB565)
425 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(b) & 0xf8) >> 3))
426 typedef uint16 scrntype;
427 #elif defined(_RGB888)
428 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
429 typedef uint32 scrntype;
430 #elif defined(_RGBA888)
431 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
432 typedef uint32 scrntype;
438 #ifndef SUPPORT_TCHAR_TYPE
441 #define _tfopen fopen
442 #define _tcscmp strcmp
443 #define _tcscpy strcpy
444 #define _tcsicmp stricmp
445 #define _tcslen strlen
446 #define _tcsncat strncat
447 #define _tcsncpy strncpy
448 #define _tcsncicmp strnicmp
449 #define _tcsstr strstr
450 #define _tcstok strtok
451 #define _tcstol strtol
452 #define _tcstoul strtoul
453 #define _stprintf sprintf
454 #define _vstprintf vsprintf
457 #if !defined(_MSC_VER)
462 #ifndef SUPPORT_SECURE_FUNCTIONS
466 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
467 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
468 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
469 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
470 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
471 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
473 #define _strcpy_s strcpy_s
486 wav_chunk_t riff_chunk;
488 wav_chunk_t fmt_chunk;
499 //#if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
502 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
503 _TCHAR *get_file_path_without_extensiton(_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);