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 #include <QtCore/QString>
39 #include <QtCore/QFile>
42 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
45 typedef uint8_t uint8;
51 typedef uint16_t uint16;
54 typedef int16_t int16;
57 typedef uint32_t uint32;
60 typedef int32_t int32;
63 typedef uint64_t uint64;
66 typedef int64_t int64;
75 typedef uint16_t WORD;
78 typedef uint32_t DWORD;
81 typedef uint64_t QWORD;
85 typedef uint8_t UINT8;
88 typedef uint16_t UINT16;
91 typedef uint32_t UINT32;
94 typedef uint64_t UINT64;
101 typedef int16_t INT16;
104 typedef int32_t INT32;
107 typedef int64_t INT64;
110 static inline void _stprintf(char *s, const char *fmt, ...) {
114 sprintf(s, fmt, args);
117 #define stricmp(a,b) strcmp(a,b)
118 #define strnicmp(a,b,n) strncmp(a,b,n)
123 //# define __T(x) L ## x
128 # define _T(x) __T(x)
129 # define _TEXT(x) __T(x)
132 // typedef wchar_t _TCHAR;
138 typedef _TCHAR* LPCTSTR;
142 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
143 return strncpy((char *)d, (char *)s, n);
146 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
147 return strncat((char *)d, (char *)s, n);
151 static inline int DeleteFile(_TCHAR *path)
154 QString fpath = (char *)path;
156 if(tfp.remove(fpath)) return (int)true;
159 return AG_FileDelete((const char *)path);
165 # include <libintl.h>
166 # define _N(x) gettext(x)
171 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
172 static inline DWORD EndianToLittle_DWORD(DWORD x)
177 static inline WORD EndianToLittle_WORD(WORD x)
182 static inline DWORD EndianToLittle_DWORD(DWORD x)
185 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
186 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
190 static inline WORD EndianToLittle_WORD(WORD x)
193 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
197 #define ZeroMemory(p,s) memset(p,0x00,s)
198 #define CopyMemory(t,f,s) memcpy(t,f,s)
204 //extern void Sleep(uint32_t tick);
205 //extern uint32_t timeGetTime(void);
213 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
215 #if defined(_MSC_VER) && (_MSC_VER == 1200)
216 #define for if(0);else for
219 // disable warnings for microsoft visual c++ 2005 or later
220 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
221 #pragma warning( disable : 4819 )
222 //#pragma warning( disable : 4995 )
223 #pragma warning( disable : 4996 )
227 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
228 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
229 #if __BYTE_ORDER == __LITTLE_ENDIAN
230 #define __LITTLE_ENDIAN__
231 #elif __BYTE_ORDER == __BIG_ENDIAN
232 #define __BIG_ENDIAN__
234 #elif defined(WORDS_LITTLEENDIAN)
235 #define __LITTLE_ENDIAN__
236 #elif defined(WORDS_BIGENDIAN)
237 #define __BIG_ENDIAN__
240 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
241 // Microsoft Visual C++
242 #define __LITTLE_ENDIAN__
248 typedef unsigned char uint8;
251 typedef unsigned short uint16;
254 typedef unsigned int uint32;
258 typedef unsigned __int64 uint64;
260 typedef unsigned long long uint64;
265 typedef signed char int8;
268 typedef signed short int16;
271 typedef signed int int32;
275 typedef signed __int64 int64;
277 typedef signed long long int64;
281 static inline DWORD EndianToLittle_DWORD(DWORD x)
286 static inline WORD EndianToLittle_WORD(WORD x)
297 #ifdef __BIG_ENDIAN__
304 #ifdef __BIG_ENDIAN__
311 #ifdef __BIG_ENDIAN__
318 #ifdef __BIG_ENDIAN__
326 inline void read_2bytes_le_from(uint8 *t)
328 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
330 inline void write_2bytes_le_to(uint8 *t)
332 t[0] = b.l; t[1] = b.h;
334 inline void read_2bytes_be_from(uint8 *t)
336 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
338 inline void write_2bytes_be_to(uint8 *t)
340 t[0] = b.h; t[1] = b.l;
342 inline void read_4bytes_le_from(uint8 *t)
344 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
346 inline void write_4bytes_le_to(uint8 *t)
348 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
350 inline void read_4bytes_be_from(uint8 *t)
352 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
354 inline void write_4bytes_be_to(uint8 *t)
356 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
361 // max/min from WinDef.h
363 //#define max(a,b) (((a) > (b)) ? (a) : (b))
366 //#define min(a,b) (((a) < (b)) ? (a) : (b))
373 #if defined(_USE_AGAR)
375 # if AG_BYTEORDER == AG_BIG_ENDIAN
376 # if defined(_RGB555)
377 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
378 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
379 typedef uint16 scrntype;
380 # elif defined(_RGB565)
381 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
382 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
383 typedef uint16 scrntype;
384 # elif defined(_RGB888)
385 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
386 typedef uint32 scrntype;
387 # elif defined(_RGBA888)
388 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
389 typedef uint32 scrntype;
392 #else // LITTLE ENDIAN
394 # if defined(_RGB555)
395 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
396 typedef uint16 scrntype;
397 # elif defined(_RGB565)
398 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
399 typedef uint16 scrntype;
400 # elif defined(_RGB888)
401 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16))
402 typedef uint32 scrntype;
403 # elif defined(_RGBA888)
404 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16)) | ((uint32)0xff << 24)
405 typedef uint32 scrntype;
410 #else // NOT USE AGAR
412 # if defined(_RGB555)
413 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(b) & 0xf8) >> 3))
414 typedef uint16 scrntype;
415 #elif defined(_RGB565)
416 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(b) & 0xf8) >> 3))
417 typedef uint16 scrntype;
418 #elif defined(_RGB888)
419 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
420 typedef uint32 scrntype;
421 #elif defined(_RGBA888)
422 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
423 typedef uint32 scrntype;
429 #ifndef SUPPORT_TCHAR_TYPE
432 #define _tfopen fopen
433 #define _tcscmp strcmp
434 #define _tcscpy strcpy
435 #define _tcsicmp stricmp
436 #define _tcslen strlen
437 #define _tcsncat strncat
438 #define _tcsncpy strncpy
439 #define _tcsncicmp strnicmp
440 #define _tcsstr strstr
441 #define _tcstok strtok
442 #define _tcstol strtol
443 #define _tcstoul strtoul
444 #define _stprintf sprintf
445 #define _vstprintf vsprintf
448 #if !defined(_MSC_VER)
453 #ifndef SUPPORT_SECURE_FUNCTIONS
457 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
458 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
459 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
460 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
461 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
462 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
464 #define _strcpy_s strcpy_s
477 wav_chunk_t riff_chunk;
479 wav_chunk_t fmt_chunk;
490 //#if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
493 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
494 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path);
495 uint32 getcrc32(uint8 data[], int size);
498 #define array_length(array) (sizeof(array) / sizeof(array[0]))
500 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
501 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
502 #define TO_BCD_LO(v) ((v) % 10)
503 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
505 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
507 typedef struct cur_time_s {
508 int year, month, day, day_of_week, hour, minute, second;
516 void update_day_of_week();
517 void save_state(void *f);
518 bool load_state(void *f);