2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
13 // move shared codes to DLL???
15 #define USE_SHARED_DLL
18 // use zlib to decompress gzip file???
20 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
25 // check environemnt/language
28 // Microsoft Visual C++
30 // variable scope of 'for' loop for Microsoft Visual C++ 6.0
31 #define for if(0);else for
34 // Microsoft Visual C++ 6.0 or later
35 #define SUPPORT_TCHAR_TYPE
38 // Microsoft Visual C++ 8.0 (2005) or later
39 #define SUPPORT_SECURE_FUNCTIONS
40 #pragma warning( disable : 4819 )
41 //#pragma warning( disable : 4995 )
42 #pragma warning( disable : 4996 )
45 // Microsoft Visual C++ 12.0 (2013) or later
46 #define SUPPORT_CPLUSPLUS_11
49 // Win32, but not Microsoft Visual C++
50 #define SUPPORT_TCHAR_TYPE
51 // #define SUPPORT_SECURE_FUNCTIONS
55 #if defined(Q_OS_CYGWIN)
56 #define CSP_OS_GCC_CYGWIN
57 #define CSP_OS_WINDOWS
58 #elif defined(Q_OS_WIN) || defined(__WIN32) || defined(__WIN64)
59 #define CSP_OS_GCC_WINDOWS
60 #define CSP_OS_WINDOWS
62 #define DLL_PREFIX __declspec(dllexport)
63 #define DLL_PREFIX_I __declspec(dllimport)
66 #define CSP_OS_GCC_GENERIC
67 #define CSP_OS_GENERIC
71 #if defined(__clang__)
72 #define __CSP_COMPILER_CLANG
74 #define __CSP_COMPILER_GCC
76 #define SUPPORT_CPLUSPLUS_11
82 #ifndef SUPPORT_CPLUSPLUS_11
83 #if defined(__cplusplus) && (__cplusplus > 199711L)
84 #define SUPPORT_CPLUSPLUS_11
87 #ifndef SUPPORT_TCHAR_TYPE
88 // secure functions need tchar type
89 #undef SUPPORT_SECURE_FUNCTIONS
98 // include common header files
99 #ifdef SUPPORT_TCHAR_TYPE
102 #ifdef SUPPORT_CPLUSPLUS_11
111 // include environment/language dependent header files
114 #include <windowsx.h>
116 #include <mmsystem.h>
127 #if defined(__MINGW32__) || (__MINGW64__)
132 #include <QtCore/QString>
133 #include <QtCore/QFile>
135 #include <sys/param.h>
138 #define _MAX_PATH 2048
142 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
143 #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
144 #if __BYTE_ORDER == __LITTLE_ENDIAN
145 #define __LITTLE_ENDIAN__
146 #elif __BYTE_ORDER == __BIG_ENDIAN
147 #define __BIG_ENDIAN__
149 #elif defined(SDL_BYTEORDER) && (defined(SDL_LIL_ENDIAN) || defined(SDL_BIG_ENDIAN))
150 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
151 #define __LITTLE_ENDIAN__
152 #elif SDL_BYTEORDER == SDL_BIG_ENDIAN
153 #define __BIG_ENDIAN__
155 #elif defined(WORDS_LITTLEENDIAN)
156 #define __LITTLE_ENDIAN__
157 #elif defined(WORDS_BIGENDIAN)
158 #define __BIG_ENDIAN__
161 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
162 // may be Microsoft Visual C++
163 #define __LITTLE_ENDIAN__
167 #ifndef SUPPORT_TCHAR_TYPE
173 #ifndef SUPPORT_CPLUSPLUS_11
175 typedef signed char int8_t;
178 typedef signed short int16_t;
181 typedef signed int int32_t;
184 typedef signed long long int64_t;
187 typedef unsigned char uint8_t;
190 typedef unsigned short uint16_t;
193 typedef unsigned int uint32_t;
196 typedef unsigned long long uint64_t;
202 typedef _TCHAR* LPTSTR;
205 typedef const _TCHAR* LPCTSTR;
217 typedef uint8_t BYTE;
220 typedef uint16_t WORD;
223 typedef uint32_t DWORD;
226 typedef uint64_t QWORD;
232 typedef int16_t INT16;
235 typedef int32_t INT32;
238 typedef int64_t INT64;
241 typedef uint8_t UINT8;
244 typedef uint16_t UINT16;
247 typedef uint32_t UINT32;
250 typedef uint64_t UINT64;
256 typedef unsigned int UINT;
262 #ifdef __BIG_ENDIAN__
263 uint8_t h3, h2, h, l;
265 uint8_t l, h, h2, h3;
269 #ifdef __BIG_ENDIAN__
276 #ifdef __BIG_ENDIAN__
283 #ifdef __BIG_ENDIAN__
291 inline void read_2bytes_le_from(uint8_t *t)
293 b.l = t[0]; b.h = t[1]; b.h2 = b.h3 = 0;
295 inline void write_2bytes_le_to(uint8_t *t)
297 t[0] = b.l; t[1] = b.h;
299 inline void read_2bytes_be_from(uint8_t *t)
301 b.h3 = b.h2 = 0; b.h = t[0]; b.l = t[1];
303 inline void write_2bytes_be_to(uint8_t *t)
305 t[0] = b.h; t[1] = b.l;
307 inline void read_4bytes_le_from(uint8_t *t)
309 b.l = t[0]; b.h = t[1]; b.h2 = t[2]; b.h3 = t[3];
311 inline void write_4bytes_le_to(uint8_t *t)
313 t[0] = b.l; t[1] = b.h; t[2] = b.h2; t[3] = b.h3;
315 inline void read_4bytes_be_from(uint8_t *t)
317 b.h3 = t[0]; b.h2 = t[1]; b.h = t[2]; b.l = t[3];
319 inline void write_4bytes_be_to(uint8_t *t)
321 t[0] = b.h3; t[1] = b.h2; t[2] = b.h; t[3] = b.l;
325 uint32_t DLL_PREFIX EndianToLittle_DWORD(uint32_t x);
326 uint16_t DLL_PREFIX EndianToLittle_WORD(uint16_t x);
332 int DLL_PREFIX max(int a, int b);
333 unsigned int DLL_PREFIX max(unsigned int a, unsigned int b);
334 int DLL_PREFIX min(int a, int b);
335 unsigned int DLL_PREFIX min(unsigned int a, unsigned int b);
339 #if defined(__GNUC__) || defined(__CYGWIN__) || defined(Q_OS_CYGWIN)
340 #define stricmp(a,b) strcasecmp(a,b)
341 #define strnicmp(a,b,n) strncasecmp(a,b,n)
344 #ifndef SUPPORT_TCHAR_TYPE
346 #define _fgetts fgets
349 #define _ftprintf printf
352 #define _tfopen fopen
355 #define _tcscmp strcmp
358 #define _tcscpy strcpy
361 #define _tcsicmp stricmp
364 #define _tcslen strlen
367 #define _tcscat strcat
370 #define _tcsncat strncat
373 #define _tcsncpy strncpy
376 #define _tcsncicmp strnicmp
379 #define _tcschr strchr
382 #define _tcsrchr strrchr
385 #define _tcsstr strstr
388 #define _tcstok strtok
394 #define _tcstol strtol
397 #define _tcstoul strtoul
400 #define _stprintf sprintf
403 #define _vstprintf vsprintf
406 #define _taccess access
409 #define _tremove remove
412 #define _trename rename
416 #define _TEXT(x) __T(x)
419 #ifndef SUPPORT_SECURE_FUNCTIONS
423 // errno_t DLL_PREFIX my_tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
424 errno_t DLL_PREFIX my_tcscat_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
425 errno_t DLL_PREFIX my_strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
426 errno_t DLL_PREFIX my_tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
427 errno_t DLL_PREFIX my_strncpy_s(char *strDestination, size_t numberOfElements, const char *strSource, size_t count);
428 errno_t DLL_PREFIX my_tcsncpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource, size_t count);
429 char * DLL_PREFIX my_strtok_s(char *strToken, const char *strDelimit, char **context);
430 _TCHAR * DLL_PREFIX my_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
431 #define my_fprintf_s fprintf
432 #define my_ftprintf_s fprintf
433 int DLL_PREFIX my_sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...);
434 int DLL_PREFIX my_swprintf_s(wchar_t *buffer, size_t sizeOfBuffer, const wchar_t *format, ...);
435 int DLL_PREFIX my_stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
436 int DLL_PREFIX my_vsprintf_s(char *buffer, size_t numberOfElements, const char *format, va_list argptr);
437 int DLL_PREFIX my_vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
439 // #define my_tfopen_s _tfopen_s
440 #define my_tcscat_s _tcscat_s
441 #define my_strcpy_s strcpy_s
442 #define my_tcscpy_s _tcscpy_s
443 #define my_strncpy_s strncpy_s
444 #define my_tcsncpy_s _tcsncpy_s
445 #define my_strtok_s strtok_s
446 #define my_tcstok_s _tcstok_s
447 #define my_fprintf_s fprintf_s
448 #define my_ftprintf_s _ftprintf_s
449 #define my_sprintf_s sprintf_s
450 #define my_swprintf_s swprintf_s
451 #define my_stprintf_s _stprintf_s
452 #define my_vsprintf_s vsprintf_s
453 #define my_vstprintf_s _vstprintf_s
456 // C99 math functions
458 #define my_isfinite _finite
459 #define my_log2(v) (log((double)(v)) / log(2.0))
461 #define my_isfinite isfinite
467 BOOL MyWritePrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpString, LPCTSTR lpFileName);
468 DWORD MyGetPrivateProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize, LPCTSTR lpFileName);
469 UINT MyGetPrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, INT nDefault, LPCTSTR lpFileName);
470 // used only in winmain and win32 osd class
471 // #define ZeroMemory(p,s) memset(p,0x00,s)
472 // #define CopyMemory(t,f,s) memcpy(t,f,s)
474 #define MyWritePrivateProfileString WritePrivateProfileString
475 #define MyGetPrivateProfileString GetPrivateProfileString
476 #define MyGetPrivateProfileInt GetPrivateProfileInt
480 #if !defined(_RGB555) && !defined(_RGB565) && !defined(_RGB888)
484 #if defined(_RGB555) || defined(_RGB565)
485 typedef uint16_t scrntype_t;
486 scrntype_t DLL_PREFIX RGB_COLOR(uint32_t r, uint32_t g, uint32_t b);
487 scrntype_t DLL_PREFIX RGBA_COLOR(uint32_t r, uint32_t g, uint32_t b, uint32_t a);
488 uint8_t DLL_PREFIX R_OF_COLOR(scrntype_t c);
489 uint8_t DLL_PREFIX G_OF_COLOR(scrntype_t c);
490 uint8_t DLL_PREFIX B_OF_COLOR(scrntype_t c);
491 uint8_t DLL_PREFIX A_OF_COLOR(scrntype_t c);
492 #elif defined(_RGB888)
493 typedef uint32_t scrntype_t;
494 #define RGB_COLOR(r, g, b) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0))
495 #define RGBA_COLOR(r, g, b, a) (((uint32_t)(r) << 16) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 0) | ((uint32_t)(a) << 24))
496 #define R_OF_COLOR(c) (((c) >> 16) & 0xff)
497 #define G_OF_COLOR(c) (((c) >> 8) & 0xff)
498 #define B_OF_COLOR(c) (((c) ) & 0xff)
499 #define A_OF_COLOR(c) (((c) >> 24) & 0xff)
512 wav_chunk_t riff_chunk;
514 wav_chunk_t fmt_chunk;
517 uint32_t sample_rate;
520 uint16_t sample_bits;
525 const _TCHAR *DLL_PREFIX get_application_path();
526 const _TCHAR *DLL_PREFIX create_local_path(const _TCHAR *format, ...);
527 void DLL_PREFIX create_local_path(_TCHAR *file_path, int length, const _TCHAR *format, ...);
528 const _TCHAR *DLL_PREFIX create_date_file_path(const _TCHAR *extension);
529 void DLL_PREFIX create_date_file_path(_TCHAR *file_path, int length, const _TCHAR *extension);
530 bool DLL_PREFIX check_file_extension(const _TCHAR *file_path, const _TCHAR *ext);
531 const _TCHAR *DLL_PREFIX get_file_path_without_extensiton(const _TCHAR *file_path);
532 void DLL_PREFIX get_long_full_path_name(const _TCHAR* src, _TCHAR* dst, size_t dst_len);
533 const _TCHAR* DLL_PREFIX get_parent_dir(const _TCHAR* file);
536 const _TCHAR *DLL_PREFIX create_string(const _TCHAR* format, ...);
537 const wchar_t *DLL_PREFIX char_to_wchar(const char *cs);
538 const char *DLL_PREFIX wchar_to_char(const wchar_t *ws);
539 const _TCHAR *DLL_PREFIX char_to_tchar(const char *cs);
540 const char *DLL_PREFIX tchar_to_char(const _TCHAR *ts);
541 const _TCHAR *DLL_PREFIX wchar_to_tchar(const wchar_t *ws);
542 const wchar_t *DLL_PREFIX tchar_to_wchar(const _TCHAR *ts);
545 int32_t DLL_PREFIX muldiv_s32(int32_t nNumber, int32_t nNumerator, int32_t nDenominator);
546 uint32_t DLL_PREFIX muldiv_u32(uint32_t nNumber, uint32_t nNumerator, uint32_t nDenominator);
548 uint32_t DLL_PREFIX get_crc32(uint8_t data[], int size);
549 uint16_t DLL_PREFIX jis_to_sjis(uint16_t jis);
551 int DLL_PREFIX decibel_to_volume(int decibel);
552 int32_t DLL_PREFIX apply_volume(int32_t sample, int volume);
554 #define array_length(array) (sizeof(array) / sizeof(array[0]))
556 #define FROM_BCD(v) (((v) & 0x0f) + (((v) >> 4) & 0x0f) * 10)
557 #define TO_BCD(v) ((int)(((v) % 100) / 10) << 4) | ((v) % 10)
558 #define TO_BCD_LO(v) ((v) % 10)
559 #define TO_BCD_HI(v) (int)(((v) % 100) / 10)
562 #define LEAP_YEAR(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
564 #define dll_cur_time_t DLL_PREFIX_I struct cur_time_s
566 typedef DLL_PREFIX struct cur_time_s {
567 int year, month, day, day_of_week, hour, minute, second;
575 void update_day_of_week();
576 void save_state(void *f);
577 bool load_state(void *f);
580 void DLL_PREFIX get_host_time(cur_time_t* cur_time);
583 typedef struct symbol_s {
586 struct symbol_s *next_symbol;
589 const _TCHAR* DLL_PREFIX get_symbol(symbol_t *first_symbol, uint32_t addr);
590 const _TCHAR* DLL_PREFIX get_value_or_symbol(symbol_t *first_symbol, const _TCHAR *format, uint32_t addr);
591 const _TCHAR* DLL_PREFIX get_value_and_symbol(symbol_t *first_symbol, const _TCHAR *format, uint32_t addr);