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
26 #if defined(_USE_AGAR) || defined(_USE_SDL)
28 #include <agar/core.h>
30 #elif defined(_USE_QT)
33 #include <QtCore/QString>
34 #include <QtCore/QFile>
37 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
40 typedef uint8_t uint8;
46 typedef uint16_t uint16;
49 typedef int16_t int16;
52 typedef uint32_t uint32;
55 typedef int32_t int32;
58 typedef uint64_t uint64;
61 typedef int64_t int64;
70 typedef uint16_t WORD;
73 typedef uint32_t DWORD;
76 typedef uint64_t QWORD;
80 typedef uint8_t UINT8;
83 typedef uint16_t UINT16;
86 typedef uint32_t UINT32;
89 typedef uint64_t UINT64;
96 typedef int16_t INT16;
99 typedef int32_t INT32;
102 typedef int64_t INT64;
105 static inline void _stprintf(char *s, const char *fmt, ...) {
109 sprintf(s, fmt, args);
112 #define stricmp(a,b) strcmp(a,b)
113 #define strnicmp(a,b,n) strncmp(a,b,n)
118 //# define __T(x) L ## x
123 # define _T(x) __T(x)
124 # define _TEXT(x) __T(x)
127 // typedef wchar_t _TCHAR;
133 typedef _TCHAR* LPCTSTR;
137 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
138 return strncpy((char *)d, (char *)s, n);
141 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
142 return strncat((char *)d, (char *)s, n);
146 static inline int DeleteFile(_TCHAR *path)
149 QString fpath = (char *)path;
151 if(tfp.remove(fpath)) return (int)true;
154 return AG_FileDelete((const char *)path);
160 # include <libintl.h>
161 # define _N(x) gettext(x)
166 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
167 static inline DWORD EndianToLittle_DWORD(DWORD x)
172 static inline WORD EndianToLittle_WORD(WORD x)
177 static inline DWORD EndianToLittle_DWORD(DWORD x)
180 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
181 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
185 static inline WORD EndianToLittle_WORD(WORD x)
188 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
192 #define ZeroMemory(p,s) memset(p,0x00,s)
193 #define CopyMemory(t,f,s) memcpy(t,f,s)
199 //extern void Sleep(uint32_t tick);
200 //extern uint32_t timeGetTime(void);
208 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
210 #if defined(_MSC_VER) && (_MSC_VER == 1200)
211 #define for if(0);else for
214 // disable warnings for microsoft visual c++ 2005 or later
215 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
216 #pragma warning( disable : 4819 )
217 //#pragma warning( disable : 4995 )
218 #pragma warning( disable : 4996 )
222 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
223 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
224 #if __BYTE_ORDER == __LITTLE_ENDIAN
225 #define __LITTLE_ENDIAN__
226 #elif __BYTE_ORDER == __BIG_ENDIAN
227 #define __BIG_ENDIAN__
229 #elif defined(WORDS_LITTLEENDIAN)
230 #define __LITTLE_ENDIAN__
231 #elif defined(WORDS_BIGENDIAN)
232 #define __BIG_ENDIAN__
235 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
236 // Microsoft Visual C++
237 #define __LITTLE_ENDIAN__
243 typedef unsigned char uint8;
246 typedef unsigned short uint16;
249 typedef unsigned int uint32;
253 typedef unsigned __int64 uint64;
255 typedef unsigned long long uint64;
260 typedef signed char int8;
263 typedef signed short int16;
266 typedef signed int int32;
270 typedef signed __int64 int64;
272 typedef signed long long int64;
276 static inline DWORD EndianToLittle_DWORD(DWORD x)
281 static inline WORD EndianToLittle_WORD(WORD x)
292 #ifdef __BIG_ENDIAN__
299 #ifdef __BIG_ENDIAN__
306 #ifdef __BIG_ENDIAN__
313 #ifdef __BIG_ENDIAN__
321 inline void read_2bytes_le_from(uint8 *t)
323 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
325 inline void write_2bytes_le_to(uint8 *t)
327 t[0] = b.l; t[1] = b.h;
329 inline void read_2bytes_be_from(uint8 *t)
331 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
333 inline void write_2bytes_be_to(uint8 *t)
335 t[0] = b.h; t[1] = b.l;
337 inline void read_4bytes_le_from(uint8 *t)
339 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
341 inline void write_4bytes_le_to(uint8 *t)
343 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
345 inline void read_4bytes_be_from(uint8 *t)
347 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
349 inline void write_4bytes_be_to(uint8 *t)
351 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
360 #if defined(_USE_AGAR)
362 # if AG_BYTEORDER == AG_BIG_ENDIAN
363 # if defined(_RGB555)
364 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
365 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
366 typedef uint16 scrntype;
367 # elif defined(_RGB565)
368 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
369 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
370 typedef uint16 scrntype;
371 # elif defined(_RGB888)
372 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
373 typedef uint32 scrntype;
374 # elif defined(_RGBA888)
375 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
376 typedef uint32 scrntype;
379 #else // LITTLE ENDIAN
381 # if defined(_RGB555)
382 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
383 typedef uint16 scrntype;
384 # elif defined(_RGB565)
385 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
386 typedef uint16 scrntype;
387 # elif defined(_RGB888)
388 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16))
389 typedef uint32 scrntype;
390 # elif defined(_RGBA888)
391 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16)) | ((uint32)0xff << 24)
392 typedef uint32 scrntype;
397 #else // NOT USE AGAR
399 # if defined(_RGB555)
400 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(b) & 0xf8) >> 3))
401 typedef uint16 scrntype;
402 #elif defined(_RGB565)
403 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(b) & 0xf8) >> 3))
404 typedef uint16 scrntype;
405 #elif defined(_RGB888)
406 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
407 typedef uint32 scrntype;
408 #elif defined(_RGBA888)
409 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
410 typedef uint32 scrntype;
416 #ifndef SUPPORT_TCHAR_TYPE
419 #define _tfopen fopen
420 #define _tcscmp strcmp
421 #define _tcscpy strcpy
422 #define _tcsicmp stricmp
423 #define _tcslen strlen
424 #define _tcsncat strncat
425 #define _tcsncpy strncpy
426 #define _tcsncicmp strnicmp
427 #define _tcsstr strstr
428 #define _tcstok strtok
429 #define _tcstol strtol
430 #define _stprintf sprintf
431 #define _vstprintf vsprintf
434 #if !defined(_MSC_VER)
439 #ifndef SUPPORT_SECURE_FUNCTIONS
443 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
444 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
445 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
446 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
447 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
448 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
450 #define _strcpy_s strcpy_s
463 wav_chunk_t riff_chunk;
465 wav_chunk_t fmt_chunk;
476 #if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
479 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
480 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path);
481 uint32 getcrc32(uint8 data[], int size);
484 #define array_length(array) (sizeof(array) / sizeof(array[0]))
486 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
487 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
488 #define TO_BCD_LO(v) ((v) % 10)
489 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
491 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
493 typedef struct cur_time_s {
494 int year, month, day, day_of_week, hour, minute, second;
502 void update_day_of_week();
503 void save_state(void *f);
504 bool load_state(void *f);