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
29 # define __CSP_COMPILER_MS_C
33 # if defined(_USE_QT5)
38 # include <QtCore/QString>
39 # include <QtCore/QFile>
45 #include "common_gcc.h"
48 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
49 #if defined(_MSC_VER) && (_MSC_VER == 1200)
50 #define for if(0);else for
53 // disable warnings for microsoft visual c++ 2005 or later
54 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
55 #pragma warning( disable : 4819 )
56 //#pragma warning( disable : 4995 )
57 #pragma warning( disable : 4996 )
61 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
62 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
63 #if __BYTE_ORDER == __LITTLE_ENDIAN
64 #define __LITTLE_ENDIAN__
65 #elif __BYTE_ORDER == __BIG_ENDIAN
66 #define __BIG_ENDIAN__
68 #elif defined(WORDS_LITTLEENDIAN)
69 #define __LITTLE_ENDIAN__
70 #elif defined(WORDS_BIGENDIAN)
71 #define __BIG_ENDIAN__
74 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
75 // Microsoft Visual C++
76 #define __LITTLE_ENDIAN__
82 typedef unsigned char uint8;
85 typedef unsigned short uint16;
88 typedef unsigned int uint32;
92 typedef unsigned __int64 uint64;
94 typedef unsigned long long uint64;
98 typedef signed char int8;
101 typedef signed short int16;
104 typedef signed int int32;
108 typedef signed __int64 int64;
110 typedef signed long long int64;
114 static inline DWORD EndianToLittle_DWORD(DWORD x)
119 static inline WORD EndianToLittle_WORD(WORD x)
129 #ifdef __BIG_ENDIAN__
136 #ifdef __BIG_ENDIAN__
143 #ifdef __BIG_ENDIAN__
150 #ifdef __BIG_ENDIAN__
158 inline void read_2bytes_le_from(uint8 *t)
160 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
162 inline void write_2bytes_le_to(uint8 *t)
164 t[0] = b.l; t[1] = b.h;
166 inline void read_2bytes_be_from(uint8 *t)
168 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
170 inline void write_2bytes_be_to(uint8 *t)
172 t[0] = b.h; t[1] = b.l;
174 inline void read_4bytes_le_from(uint8 *t)
176 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
178 inline void write_4bytes_le_to(uint8 *t)
180 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
182 inline void read_4bytes_be_from(uint8 *t)
184 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
186 inline void write_4bytes_be_to(uint8 *t)
188 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
193 // max/min from WinDef.h
195 #if !defined(_USE_QT)
201 #if defined(__BIG_ENDIAN__)
202 # if defined(_RGB555)
203 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>4) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
204 typedef uint16 scrntype;
205 # elif defined(_RGB565)
206 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) >>3) | (uint16)(((uint16)(g) & 0xfc) << 2) | (uint16)(((uint16)(r) & 0xf8) << 8))
207 typedef uint16 scrntype;
208 # elif defined(_RGB888)
209 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
210 typedef uint32 scrntype;
211 # elif defined(_RGBA888)
212 # define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
213 //# define RGB_COLOR(r, g, b) (((uint32)(b) << 24) | ((uint32)(g) << 16) | ((uint32)(r) << 8)) | ((uint32)0xff << 0)
214 typedef uint32 scrntype;
217 #else // LITTLE ENDIAN
219 # if defined(_RGB555)
220 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 7) | (uint16)(((uint16)(g) & 0xf8) << 2) | (uint16)(((uint16)(r) & 0xf8) >> 3))
221 typedef uint16 scrntype;
222 # elif defined(_RGB565)
223 # define RGB_COLOR(r, g, b) ((uint16)(((uint16)(b) & 0xf8) << 8) | (uint16)(((uint16)(g) & 0xfc) << 3) | (uint16)(((uint16)(r) & 0xf8) >> 3))
224 typedef uint16 scrntype;
225 # elif defined(_RGB888)
226 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
227 typedef uint32 scrntype;
228 # elif defined(_RGBA888)
229 # define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
230 //# define RGB_COLOR(r, g, b) (((uint32)(b) << 16) | ((uint32)(g) << 8) | ((uint32)(r) << 0)) | ((uint32)0xff << 24)
231 typedef uint32 scrntype;
238 #ifndef SUPPORT_TCHAR_TYPE
241 #define _tfopen fopen
242 #define _tcscmp strcmp
243 #define _tcscpy strcpy
244 # if !defined(_tcsicmp)
245 # define _tcsicmp stricmp
247 #define _tcslen strlen
248 #define _tcsncat strncat
249 #define _tcsncpy strncpy
250 # if !defined(_tcsncicmp)
251 #define _tcsncicmp strnicmp
253 #define _tcsstr strstr
254 #define _tcstok strtok
255 #define _tcstol strtol
256 #define _tcstoul strtoul
257 #define _stprintf sprintf
258 #define _vstprintf vsprintf
261 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
265 # define _strcpy_s _tcscpy_s
266 # if defined(CSP_OS_GCC_WINDOWS) || defined(CSP_OS_GCC_CYGWIN)
267 # define strcpy_s _tcscpy_s
268 # define tcscpy_s _tcscpy_s
269 # define tcstok_s _tcstok_s
270 # define stprintf_s _stprintf_s
271 # define vstprintf_s _vstprintf_s
272 # define vsprintf_s _vsprintf_s
274 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
275 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
276 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
277 static inline int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
280 va_start(ap, format);
281 int result = vsprintf(buffer, format, ap);
285 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
287 # define _strcpy_s _tcscpy_s
288 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
303 wav_chunk_t riff_chunk;
305 wav_chunk_t fmt_chunk;
318 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
319 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path);
320 uint32 getcrc32(uint8 data[], int size);
323 #define array_length(array) (sizeof(array) / sizeof(array[0]))
325 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
326 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
327 #define TO_BCD_LO(v) ((v) % 10)
328 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
330 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
332 typedef struct cur_time_s {
333 int year, month, day, day_of_week, hour, minute, second;
341 void update_day_of_week();
342 void save_state(void *f);
343 bool load_state(void *f);