2 Skelton for retropc emulator
\r
4 Author : Takeda.Toshiya
\r
13 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
\r
14 #define SUPPORT_TCHAR_TYPE
\r
16 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
\r
17 #define SUPPORT_SECURE_FUNCTIONS
\r
19 #ifdef SUPPORT_TCHAR_TYPE
\r
26 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
27 #include <SDL/SDL.h>
\r
28 #include <agar/core.h>
\r
30 #elif defined(_USE_QT)
\r
31 #include <SDL2/SDL.h>
\r
33 #include <QtCore/QString>
\r
34 #include <QtCore/QFile>
\r
37 #if defined(_USE_AGAR) || defined(_USE_SDL) || defined(_USE_QT)
\r
40 typedef uint8_t uint8;
\r
43 typedef int8_t int8;
\r
46 typedef uint16_t uint16;
\r
49 typedef int16_t int16;
\r
52 typedef uint32_t uint32;
\r
55 typedef int32_t int32;
\r
58 typedef uint64_t uint64;
\r
61 typedef int64_t int64;
\r
67 typedef uint8_t BYTE;
\r
70 typedef uint16_t WORD;
\r
73 typedef uint32_t DWORD;
\r
76 typedef uint64_t QWORD;
\r
80 typedef uint8_t UINT8;
\r
83 typedef uint16_t UINT16;
\r
86 typedef uint32_t UINT32;
\r
89 typedef uint64_t UINT64;
\r
93 typedef int8_t INT8;
\r
96 typedef int16_t INT16;
\r
99 typedef int32_t INT32;
\r
102 typedef int64_t INT64;
\r
105 static inline void _stprintf(char *s, const char *fmt, ...) {
\r
108 va_start(args, fmt);
\r
109 sprintf(s, fmt, args);
\r
112 #define stricmp(a,b) strcmp(a,b)
\r
113 #define strnicmp(a,b,n) strncmp(a,b,n)
\r
118 //# define __T(x) L ## x
\r
123 # define _T(x) __T(x)
\r
124 # define _TEXT(x) __T(x)
\r
127 // typedef wchar_t _TCHAR;
\r
129 typedef char _TCHAR;
\r
133 typedef _TCHAR* LPCTSTR;
\r
137 static inline char *_tcsncpy(_TCHAR *d, _TCHAR *s, int n) {
\r
138 return strncpy((char *)d, (char *)s, n);
\r
141 static inline char *_tcsncat(_TCHAR *d, _TCHAR *s, int n) {
\r
142 return strncat((char *)d, (char *)s, n);
\r
146 static inline int DeleteFile(_TCHAR *path)
\r
149 QString fpath = (char *)path;
\r
151 if(tfp.remove(fpath)) return (int)true;
\r
154 return AG_FileDelete((const char *)path);
\r
157 #include <algorithm>
\r
159 # ifdef USE_GETTEXT
\r
160 # include <libintl.h>
\r
161 # define _N(x) gettext(x)
\r
163 # define _N(x) _T(x)
\r
166 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
\r
167 static inline DWORD EndianToLittle_DWORD(DWORD x)
\r
172 static inline WORD EndianToLittle_WORD(WORD x)
\r
176 #else // BIG_ENDIAN
\r
177 static inline DWORD EndianToLittle_DWORD(DWORD x)
\r
180 y = ((x & 0x000000ff) << 24) | ((x & 0x0000ff00) << 8) |
\r
181 ((x & 0x00ff0000) >> 8) | ((x & 0xff000000) >> 24);
\r
185 static inline WORD EndianToLittle_WORD(WORD x)
\r
188 y = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
\r
192 #define ZeroMemory(p,s) memset(p,0x00,s)
\r
193 #define CopyMemory(t,f,s) memcpy(t,f,s)
\r
199 //extern void Sleep(uint32_t tick);
\r
200 //extern uint32_t timeGetTime(void);
\r
208 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
\r
210 #if defined(_MSC_VER) && (_MSC_VER == 1200)
\r
211 #define for if(0);else for
\r
214 // disable warnings for microsoft visual c++ 2005 or later
\r
215 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
\r
216 #pragma warning( disable : 4819 )
\r
217 //#pragma warning( disable : 4995 )
\r
218 //#pragma warning( disable : 4996 )
\r
222 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
\r
223 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
\r
224 #if __BYTE_ORDER == __LITTLE_ENDIAN
\r
225 #define __LITTLE_ENDIAN__
\r
226 #elif __BYTE_ORDER == __BIG_ENDIAN
\r
227 #define __BIG_ENDIAN__
\r
229 #elif defined(WORDS_LITTLEENDIAN)
\r
230 #define __LITTLE_ENDIAN__
\r
231 #elif defined(WORDS_BIGENDIAN)
\r
232 #define __BIG_ENDIAN__
\r
235 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
\r
236 // Microsoft Visual C++
\r
237 #define __LITTLE_ENDIAN__
\r
243 typedef unsigned char uint8;
\r
246 typedef unsigned short uint16;
\r
249 typedef unsigned int uint32;
\r
253 typedef unsigned __int64 uint64;
\r
255 typedef unsigned long long uint64;
\r
260 typedef signed char int8;
\r
263 typedef signed short int16;
\r
266 typedef signed int int32;
\r
270 typedef signed __int64 int64;
\r
272 typedef signed long long int64;
\r
276 static inline DWORD EndianToLittle_DWORD(DWORD x)
\r
281 static inline WORD EndianToLittle_WORD(WORD x)
\r
291 #ifdef __BIG_ENDIAN__
\r
293 uint8 h3, h2, h, l;
\r
306 uint8 l, h, h2, h3;
\r
326 #if defined(_USE_AGAR)
\r
328 # if AG_BYTEORDER == AG_BIG_ENDIAN
\r
329 # if defined(_RGB555)
\r
330 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
\r
331 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
\r
332 typedef uint16 scrntype;
\r
333 # elif defined(_RGB565)
\r
334 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
\r
335 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
\r
336 typedef uint16 scrntype;
\r
337 # elif defined(_RGB888)
\r
338 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
\r
339 typedef uint32 scrntype;
\r
340 # elif defined(_RGBA888)
\r
341 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
\r
342 typedef uint32 scrntype;
\r
345 #else // LITTLE ENDIAN
\r
347 # if defined(_RGB555)
\r
348 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
\r
349 typedef uint16 scrntype;
\r
350 # elif defined(_RGB565)
\r
351 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
\r
352 typedef uint16 scrntype;
\r
353 # elif defined(_RGB888)
\r
354 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16))
\r
355 typedef uint32 scrntype;
\r
356 # elif defined(_RGBA888)
\r
357 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16)) | ((uint32)0xff << 24)
\r
358 typedef uint32 scrntype;
\r
363 #else // NOT USE AGAR
\r
365 # if defined(_RGB555)
\r
366 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(b) & 0xf8) >> 3))
\r
367 typedef uint16 scrntype;
\r
368 #elif defined(_RGB565)
\r
369 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(b) & 0xf8) >> 3))
\r
370 typedef uint16 scrntype;
\r
371 #elif defined(_RGB888)
\r
372 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
\r
373 typedef uint32 scrntype;
\r
374 #elif defined(_RGBA888)
\r
375 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
\r
376 typedef uint32 scrntype;
\r
382 #ifndef SUPPORT_TCHAR_TYPE
\r
383 typedef char _TCHAR;
\r
384 //#define _T(s) (s)
\r
385 #define _tfopen fopen
\r
386 #define _tcscmp strcmp
\r
387 #define _tcscpy strcpy
\r
388 #define _tcsicmp stricmp
\r
389 #define _tcslen strlen
\r
390 #define _tcsncat strncat
\r
391 #define _tcsncpy strncpy
\r
392 #define _tcsncicmp strnicmp
\r
393 #define _tcsstr strstr
\r
394 #define _tcstok strtok
\r
395 #define _tcstol strtol
\r
396 #define _stprintf sprintf
\r
397 #define _vstprintf vsprintf
\r
400 #if !defined(_MSC_VER)
\r
402 typedef int errno_t;
\r
404 // secture functions
\r
405 #ifndef SUPPORT_SECURE_FUNCTIONS
\r
406 errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
\r
407 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
\r
408 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
\r
409 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
\r
410 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
\r
411 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
\r
413 #define _strcpy_s strcpy_s
\r
417 #if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
\r
420 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
\r
421 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path);
\r
422 uint32 getcrc32(uint8 data[], int size);
\r
425 #define array_length(array) (sizeof(array) / sizeof(array[0]))
\r
427 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
\r
428 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
\r
429 #define TO_BCD_LO(v) ((v) % 10)
\r
430 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
\r
432 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
\r
434 typedef struct cur_time_t {
\r
435 int year, month, day, day_of_week, hour, minute, second;
\r
439 initialized = false;
\r
442 void update_year();
\r
443 void update_day_of_week();
\r
444 void save_state(void *f);
\r
445 bool load_state(void *f);
\r