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)
291 #ifdef __BIG_ENDIAN__
326 #if defined(_USE_AGAR)
328 # if AG_BYTEORDER == AG_BIG_ENDIAN
329 # if defined(_RGB555)
330 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
331 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
332 typedef uint16 scrntype;
333 # elif defined(_RGB565)
334 //#define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
335 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
336 typedef uint16 scrntype;
337 # elif defined(_RGB888)
338 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
339 typedef uint32 scrntype;
340 # elif defined(_RGBA888)
341 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
342 typedef uint32 scrntype;
345 #else // LITTLE ENDIAN
347 # if defined(_RGB555)
348 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
349 typedef uint16 scrntype;
350 # elif defined(_RGB565)
351 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
352 typedef uint16 scrntype;
353 # elif defined(_RGB888)
354 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16))
355 typedef uint32 scrntype;
356 # elif defined(_RGBA888)
357 # define RGB_COLOR(r, g, b) (((uint32)(r) << 0) | ((uint32)(g) << 8) | ((uint32)(b) << 16)) | ((uint32)0xff << 24)
358 typedef uint32 scrntype;
363 #else // NOT USE AGAR
365 # if defined(_RGB555)
366 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(b) & 0xf8) >> 3))
367 typedef uint16 scrntype;
368 #elif defined(_RGB565)
369 #define RGB_COLOR(r, g, b) ((uint16)(((uint16)(r) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(b) & 0xf8) >> 3))
370 typedef uint16 scrntype;
371 #elif defined(_RGB888)
372 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
373 typedef uint32 scrntype;
374 #elif defined(_RGBA888)
375 #define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
376 typedef uint32 scrntype;
382 #ifndef SUPPORT_TCHAR_TYPE
385 #define _tfopen fopen
386 #define _tcscmp strcmp
387 #define _tcscpy strcpy
388 #define _tcsicmp stricmp
389 #define _tcslen strlen
390 #define _tcsncat strncat
391 #define _tcsncpy strncpy
392 #define _tcsncicmp strnicmp
393 #define _tcsstr strstr
394 #define _tcstok strtok
395 #define _tcstol strtol
396 #define _stprintf sprintf
397 #define _vstprintf vsprintf
400 #if !defined(_MSC_VER)
405 #ifndef SUPPORT_SECURE_FUNCTIONS
406 errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
407 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
408 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
409 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
410 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
411 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
413 #define _strcpy_s strcpy_s
417 #if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
420 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext);
421 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path);
422 uint32 getcrc32(uint8 data[], int size);
425 #define array_length(array) (sizeof(array) / sizeof(array[0]))
427 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
428 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
429 #define TO_BCD_LO(v) ((v) % 10)
430 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
432 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
434 typedef struct cur_time_t {
435 int year, month, day, day_of_week, hour, minute, second;
443 void update_day_of_week();
444 void save_state(void *f);
445 bool load_state(void *f);