2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
9 #if defined(_USE_AGAR) || defined(_USE_QT)
16 #pragma comment(lib, "shlwapi.lib")
24 #ifndef SUPPORT_SECURE_FUNCTIONS
25 //errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode)
27 // if((*pFile = _tfopen(filename, mode)) != NULL) {
34 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource)
36 strcpy(strDestination, strSource);
40 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource)
42 _tcscpy(strDestination, strSource);
46 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context)
48 return _tcstok(strToken, strDelimit);
51 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
55 int result = _vstprintf(buffer, format, ap);
60 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr)
62 return _vstprintf(buffer, format, argptr);
66 bool check_file_extension(_TCHAR* file_path, _TCHAR* ext)
68 #if defined(_USE_AGAR)
69 int nam_len = strlen(file_path);
70 int ext_len = strlen(ext);
72 return (nam_len >= ext_len && strncmp(&file_path[nam_len - ext_len], ext, ext_len) == 0);
73 #elif defined(_USE_QT)
74 QString s_fpath = file_path;
77 s_fpath = s_fpath.toUpper();
78 s_ext = s_ext.toUpper();
79 if(s_fpath.length() < s_ext.length()) return false;
80 s_fpath = s_fpath.right(s_ext.length());
81 if(s_fpath == s_ext) return true;
84 int nam_len = _tcslen(file_path);
85 int ext_len = _tcslen(ext);
87 return (nam_len >= ext_len && _tcsncicmp(&file_path[nam_len - ext_len], ext, ext_len) == 0);
91 _TCHAR *get_file_path_without_extensiton(_TCHAR* file_path)
93 static _TCHAR path[_MAX_PATH];
95 #if defined(_USE_AGAR) || defined(_USE_QT)
97 static _TCHAR p3[_MAX_PATH];
98 strcpy(path, file_path);
99 p1 = (_TCHAR *)strrchr(path, '/');
100 p2 = (_TCHAR *)strrchr(path, '.');
104 } else if(p1 == NULL) {
105 strncpy(p3, path, p2 - path);
110 strncpy(p3, path, p2 - path);
117 _tcscpy_s(path, _MAX_PATH, file_path);
118 PathRemoveExtension(path);
123 uint32 getcrc32(uint8 data[], int size)
125 static bool initialized = false;
126 static uint32 table[256];
129 for(int i = 0; i < 256; i++) {
131 for(int j = 0; j < 8; j++) {
133 c = (c >> 1) ^ 0xedb88320;
144 for(int i = 0; i < size; i++) {
145 c = table[(c ^ data[i]) & 0xff] ^ (c >> 8);
150 void cur_time_t::increment()
158 // days in this month
161 days = LEAP_YEAR(year) ? 29 : 28;
162 } else if(month == 4 || month == 6 || month == 9 || month == 11) {
172 if(++day_of_week >= 7) {
180 void cur_time_t::update_year()
185 } else if(year < 100) {
190 void cur_time_t::update_day_of_week()
192 static const int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
193 int y = year - (month < 3);
194 day_of_week = (y + y / 4 - y / 100 + y / 400 + t[month - 1] + day) % 7;
197 #define STATE_VERSION 1
199 void cur_time_t::save_state(void *f)
201 FILEIO *state_fio = (FILEIO *)f;
203 state_fio->FputUint32(STATE_VERSION);
205 state_fio->FputInt32(year);
206 state_fio->FputInt32(month);
207 state_fio->FputInt32(day);
208 state_fio->FputInt32(day_of_week);
209 state_fio->FputInt32(hour);
210 state_fio->FputInt32(minute);
211 state_fio->FputInt32(second);
212 state_fio->FputBool(initialized);
215 bool cur_time_t::load_state(void *f)
217 FILEIO *state_fio = (FILEIO *)f;
219 if(state_fio->FgetUint32() != STATE_VERSION) {
222 year = state_fio->FgetInt32();
223 month = state_fio->FgetInt32();
224 day = state_fio->FgetInt32();
225 day_of_week = state_fio->FgetInt32();
226 hour = state_fio->FgetInt32();
227 minute = state_fio->FgetInt32();
228 second = state_fio->FgetInt32();
229 initialized = state_fio->FgetBool();