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)
44 # include <QtCore/QString>
45 # include <QtCore/QFile>
49 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
52 typedef uint8_t uint8;
58 typedef uint16_t uint16;
61 typedef int16_t int16;
64 typedef uint32_t uint32;
67 typedef int32_t int32;
70 typedef uint64_t uint64;
73 typedef int64_t int64;
82 typedef uint16_t WORD;
85 typedef uint32_t DWORD;
88 typedef uint64_t QWORD;
92 typedef uint8_t UINT8;
95 typedef uint16_t UINT16;
98 typedef uint32_t UINT32;
101 typedef uint64_t UINT64;
108 typedef int16_t INT16;
111 typedef int32_t INT32;
114 typedef int64_t INT64;
117 static inline void _stprintf(char *s, const char *fmt, ...) {
121 sprintf(s, fmt, args);
124 #define stricmp(a,b) strcmp(a,b)
125 #define strnicmp(a,b,n) strncmp(a,b,n)
130 //# define __T(x) L ## x
135 # define _T(x) __T(x)
136 # define _TEXT(x) __T(x)
139 // typedef wchar_t _TCHAR;
145 typedef _TCHAR* LPCTSTR;
149 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
150 return strncpy((char *)d, (char *)s, n);
153 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
154 return strncat((char *)d, (char *)s, n);
158 static inline int DeleteFile(_TCHAR *path)
161 QString fpath = (char *)path;
163 if(tfp.remove(fpath)) return (int)true;
166 return AG_FileDelete((const char *)path);
172 # include <libintl.h>
173 # define _N(x) gettext(x)
178 #undef __LITTLE_ENDIAN___
179 #undef __BIG_ENDIAN___
181 # if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
182 # define __LITTLE_ENDIAN__
183 static inline DWORD EndianToLittle_DWORD(DWORD x)
188 static inline WORD EndianToLittle_WORD(WORD x)
193 # define __BIG_ENDIAN__
194 static inline DWORD EndianToLittle_DWORD(DWORD x)
197 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
198 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
202 static inline WORD EndianToLittle_WORD(WORD x)
205 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
209 #define ZeroMemory(p,s) memset(p,0x00,s)
210 #define CopyMemory(t,f,s) memcpy(t,f,s)
213 # if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
214 # if SDL_BYTEORDER == SDL_LIL_ENDIAN
215 # define __LITTLE_ENDIAN__
217 # define __BIG_ENDIAN__
225 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
227 #if defined(_MSC_VER) && (_MSC_VER == 1200)
228 #define for if(0);else for
231 // disable warnings for microsoft visual c++ 2005 or later
232 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
233 #pragma warning( disable : 4819 )
234 //#pragma warning( disable : 4995 )
235 #pragma warning( disable : 4996 )
239 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
240 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
241 #if __BYTE_ORDER == __LITTLE_ENDIAN
242 #define __LITTLE_ENDIAN__
243 #elif __BYTE_ORDER == __BIG_ENDIAN
244 #define __BIG_ENDIAN__
246 #elif defined(WORDS_LITTLEENDIAN)
247 #define __LITTLE_ENDIAN__
248 #elif defined(WORDS_BIGENDIAN)
249 #define __BIG_ENDIAN__
252 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
253 // Microsoft Visual C++
254 #define __LITTLE_ENDIAN__
260 typedef unsigned char uint8;
263 typedef unsigned short uint16;
266 typedef unsigned int uint32;
270 typedef unsigned __int64 uint64;
272 typedef unsigned long long uint64;
276 typedef signed char int8;
279 typedef signed short int16;
282 typedef signed int int32;
286 typedef signed __int64 int64;
288 typedef signed long long int64;
292 static inline DWORD EndianToLittle_DWORD(DWORD x)
297 static inline WORD EndianToLittle_WORD(WORD x)
308 #ifdef __BIG_ENDIAN__
315 #ifdef __BIG_ENDIAN__
322 #ifdef __BIG_ENDIAN__
329 #ifdef __BIG_ENDIAN__
337 inline void read_2bytes_le_from(uint8 *t)
339 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
341 inline void write_2bytes_le_to(uint8 *t)
343 t[0] = b.l; t[1] = b.h;
345 inline void read_2bytes_be_from(uint8 *t)
347 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
349 inline void write_2bytes_be_to(uint8 *t)
351 t[0] = b.h; t[1] = b.l;
353 inline void read_4bytes_le_from(uint8 *t)
355 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
357 inline void write_4bytes_le_to(uint8 *t)
359 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
361 inline void read_4bytes_be_from(uint8 *t)
363 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
365 inline void write_4bytes_be_to(uint8 *t)
367 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
372 // max/min from WinDef.h
374 //#define max(a,b) (((a) > (b)) ? (a) : (b))
377 //#define min(a,b) (((a) < (b)) ? (a) : (b))
381 #if !defined(_USE_QT)
387 #if defined(__BIG_ENDIAN__)
388 # if defined(_RGB555)
389 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
390 typedef uint16 scrntype;
391 # elif defined(_RGB565)
392 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
393 typedef uint16 scrntype;
394 # elif defined(_RGB888)
395 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
396 typedef uint32 scrntype;
397 # elif defined(_RGBA888)
398 //# if defined(USE_BITMAP)
399 //# define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)((r | g | b) == 0x00) ? 0x00 : 0xff)
401 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
403 typedef uint32 scrntype;
406 #else // LITTLE ENDIAN
408 # if defined(_RGB555)
409 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
410 typedef uint16 scrntype;
411 # elif defined(_RGB565)
412 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
413 typedef uint16 scrntype;
414 # elif defined(_RGB888)
415 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
416 typedef uint32 scrntype;
417 # elif defined(_RGBA888)
418 //# if defined(USE_BITMAP)
419 //# define RGB_COLOR(r, g, b) (((r | g | b) == 0x00) ? \
420 // (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) : \
421 // (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0) | (0x000000ff << 24)))
423 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
425 typedef uint32 scrntype;
432 #ifndef SUPPORT_TCHAR_TYPE
435 #define _tfopen fopen
436 #define _tcscmp strcmp
437 #define _tcscpy strcpy
438 #define _tcsicmp stricmp
439 #define _tcslen strlen
440 #define _tcsncat strncat
441 #define _tcsncpy strncpy
442 #define _tcsncicmp strnicmp
443 #define _tcsstr strstr
444 #define _tcstok strtok
445 #define _tcstol strtol
446 #define _tcstoul strtoul
447 #define _stprintf sprintf
448 #define _vstprintf vsprintf
451 #if !defined(_MSC_VER)
456 #ifndef SUPPORT_SECURE_FUNCTIONS
460 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
461 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
462 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
463 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
464 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
465 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
467 #define _strcpy_s strcpy_s
480 wav_chunk_t riff_chunk;
482 wav_chunk_t fmt_chunk;
493 //#if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
496 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
497 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path);
498 uint32 getcrc32(uint8 data[], int size);
501 #define array_length(array) (sizeof(array) / sizeof(array[0]))
503 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
504 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
505 #define TO_BCD_LO(v) ((v) % 10)
506 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
508 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
510 typedef struct cur_time_s {
511 int year, month, day, day_of_week, hour, minute, second;
519 void update_day_of_week();
520 void save_state(void *f);
521 bool load_state(void *f);