2 Skelton for retropc emulator
\r
4 Author : Takeda.Toshiya
\r
9 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
10 #include <SDL/SDL.h>
\r
11 #include <agar/core.h>
\r
15 #include "agar_logger.h"
\r
17 #include <windows.h>
\r
25 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
26 #include "agar_main.h"
\r
32 #define CONFIG_NAME "conf"
\r
35 #if defined(_USE_AGAR)
\r
39 bool WritePrivateProfileString(char *lpAppName, char *lpKeyName, char *Value, FILEIO *lpFileName)
\r
42 snprintf(s, 128, "%s.%s=%s\n", lpAppName, lpKeyName, Value);
\r
43 //AG_WriteString(lpFileName, s);
\r
44 lpFileName->Fwrite(s, strlen(s), 1);
\r
48 bool WritePrivateProfileInt(char *lpAppName, char *lpKeyName, int Value, FILEIO *lpFileName)
\r
51 snprintf(s, 128, "%s.%s=%d\n", lpAppName, lpKeyName, Value);
\r
52 //AG_WriteString(lpFileName, s);
\r
53 lpFileName->Fwrite(s, strlen(s), 1);
\r
57 BOOL WritePrivateProfileBool(char *lpAppName, char *lpKeyName, bool Value, FILEIO *lpFileName)
\r
60 snprintf(String, 128, "%s.%s=%d\n", lpAppName, lpKeyName, Value ? 1 : 0);
\r
61 lpFileName->Fwrite(String, strlen(String), 1);
\r
62 //AG_WriteString(lpFileName, String);
\r
68 std::string GetPrivateProfileStr(char *lpAppName, char *lpKeyName, FILEIO *lpFileName)
\r
71 char ibuf[AG_PATHNAME_MAX + 102];
\r
74 std::string::size_type pos;
\r
75 std::string key_str;
\r
76 std::string got_str;
\r
78 snprintf(key, 255, "%s.%s", lpAppName, lpKeyName);
\r
79 AGAR_DebugLog(AGAR_LOG_DEBUG, "Try App: %s Key: %s", lpAppName, lpKeyName);
\r
80 lpFileName->Fseek(0, FILEIO_SEEK_SET);
\r
86 if(i > (AG_PATHNAME_MAX + 100)) break;
\r
87 c = (char)lpFileName->Fgetc();
\r
89 if(c == '\n') break;
\r
95 //AGAR_DebugLog(AGAR_LOG_DEBUG, "Got: %s %d chars.\n", got_str.c_str(), i);
\r
96 key_str = key_str + "=";
\r
97 pos = got_str.find(key_str);
\r
98 if(pos != std::string::npos) break;
\r
99 if(c == EOF) return "";
\r
102 got_str.erase(0, pos + key_str.length());
\r
103 //AGAR_DebugLog(AGAR_LOG_DEBUG, "Ok. Got %s = %s.\n", key, got_str.c_str());
\r
107 void GetPrivateProfileString(char *section, char *key, char *defaultstr, char *str, int max_len, FILEIO *p)
\r
109 std::string sp = GetPrivateProfileStr(section, key, p);
\r
110 // printf("Got: %s\n", sp.c_str());
\r
112 if((!sp.empty()) && (max_len > 1)){
\r
113 strncpy(str, sp.c_str(), max_len);
\r
115 strncpy(str, defaultstr, max_len);
\r
117 printf("Got: %s\n", str);
\r
121 int GetPrivateProfileInt(char *lpAppName, char *lpKeyName, int nDefault, FILEIO *lpFileName)
\r
124 std::string s = GetPrivateProfileStr(lpAppName,lpKeyName, lpFileName);
\r
129 i = strtol(s.c_str(), NULL, 10);
\r
131 printf("Got: %d\n", i);
\r
137 bool GetPrivateProfileBool(char *lpAppName, char *lpKeyName, bool bDefault, FILEIO *lpFileName)
\r
140 return (GetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
\r
144 BOOL WritePrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, int Value, LPCTSTR lpFileName)
\r
147 _stprintf(String, _T("%d"), Value);
\r
148 return WritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
\r
151 BOOL WritePrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool Value, LPCTSTR lpFileName)
\r
154 _stprintf(String, _T("%d"), Value ? 1 : 0);
\r
155 return WritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
\r
158 bool GetPrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool bDefault, LPCTSTR lpFileName)
\r
160 return (GetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
\r
166 // initial settings
\r
167 memset(&config, 0, sizeof(config_t));
\r
169 #if !(defined(USE_BITMAP) || defined(USE_LED))
\r
170 config.use_d3d9 = true;
\r
171 config.stretch_type = 1; // Stretch (Aspect)
\r
173 config.sound_frequency = 6; // 48KHz
\r
174 config.sound_latency = 1; // 100msec
\r
176 #if defined(USE_TAPE)
\r
177 config.wave_shaper = true;
\r
178 config.direct_load_mzt = true;
\r
180 #if defined(USE_DIPSWITCH) && defined(DIPSWITCH_DEFAULT)
\r
181 config.dipswitch = DIPSWITCH_DEFAULT;
\r
184 config.device_type = 2; // Nonintelligent ram disk
\r
186 #if defined(_PC8801MA)
\r
187 config.boot_mode = 2; // V2 mode, 4MHz
\r
188 config.cpu_type = 1;
\r
190 #if defined(_X1TURBO) || defined(_X1TURBOZ)
\r
191 config.device_type = 1; // Keyboard mode B
\r
193 #if defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
\r
194 config.sound_device_type = 1; // CZ-8BS1
\r
201 // initial settings
\r
206 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
207 char app_path2[_MAX_PATH], *ptr;
\r
208 char cfgpath[_MAX_PATH];
\r
209 FILEIO *config_path = new FILEIO();
\r
211 app_path2[0] = '\0';
\r
213 //GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
\r
214 cpp_confdir.copy(app_path2, _MAX_PATH, 0);
\r
215 strncat(app_path2, CONFIG_NAME, _MAX_PATH);
\r
216 strncat(app_path2, ".ini", _MAX_PATH);
\r
218 AGAR_DebugLog(AGAR_LOG_INFO, "Try to read config: %s", app_path2);
\r
219 if(!config_path->Fopen(app_path2, FILEIO_READ_ASCII)) return;
\r
220 AGAR_DebugLog(AGAR_LOG_INFO, "OK.");
\r
222 _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
\r
223 GetModuleFileName(NULL, config_path, _MAX_PATH);
\r
224 GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
\r
226 _stprintf(config_path, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
\r
231 #ifdef USE_BOOT_MODE
\r
232 config.boot_mode = GetPrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
\r
234 #ifdef USE_CPU_TYPE
\r
235 config.cpu_type = GetPrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
\r
237 #ifdef USE_DIPSWITCH
\r
238 config.dipswitch = GetPrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
\r
240 #ifdef USE_DEVICE_TYPE
\r
241 config.device_type = GetPrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
\r
244 config.ignore_crc = GetPrivateProfileBool(_T("Control"), _T("IgnoreCRC"), config.ignore_crc, config_path);
\r
247 config.wave_shaper = GetPrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
\r
248 config.direct_load_mzt = GetPrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
\r
253 GetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
\r
254 for(drv = 0; drv < MAX_CART; drv++) {
\r
255 for(i = 0; i < MAX_HISTORY; i++) {
\r
257 sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
\r
258 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_cart_path[drv][i], _MAX_PATH, config_path);
\r
263 GetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""), config.initial_disk_dir, _MAX_PATH, config_path);
\r
264 get_parent_dir(config.initial_disk_dir);
\r
265 for(drv = 0; drv < MAX_FD; drv++) {
\r
266 for(i = 0; i < MAX_HISTORY; i++) {
\r
268 sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
\r
269 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_disk_path[drv][i], _MAX_PATH, config_path);
\r
274 GetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), _T(""), config.initial_quickdisk_dir, _MAX_PATH, config_path);
\r
275 for(drv = 0; drv < MAX_QD; drv++) {
\r
276 for(i = 0; i < MAX_HISTORY; i++) {
\r
278 sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
\r
279 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_quickdisk_path[drv][i], _MAX_PATH, config_path);
\r
284 GetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""), config.initial_tape_dir, _MAX_PATH, config_path);
\r
285 for(i = 0; i < MAX_HISTORY; i++) {
\r
287 sprintf(name, _T("RecentTapePath1_%d"), i + 1);
\r
288 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_tape_path[i], _MAX_PATH, config_path);
\r
291 #ifdef USE_LASER_DISC
\r
292 GetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""), config.initial_laser_disc_dir, _MAX_PATH, config_path);
\r
293 for(int i = 0; i < MAX_HISTORY; i++) {
\r
295 sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
\r
296 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_laser_disc_path[i], _MAX_PATH, config_path);
\r
299 #ifdef USE_BINARY_FILE1
\r
300 GetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""), config.initial_binary_dir, _MAX_PATH, config_path);
\r
301 for(drv = 0; drv < MAX_BINARY; drv++) {
\r
302 for(i = 0; i < MAX_HISTORY; i++) {
\r
304 sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
\r
305 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_binary_path[drv][i], _MAX_PATH, config_path);
\r
311 #if !(defined(USE_BITMAP) || defined(USE_LED))
\r
312 config.window_mode = GetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
\r
313 config.use_d3d9 = GetPrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
\r
314 config.wait_vsync = GetPrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
\r
315 config.stretch_type = GetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
\r
317 #ifdef USE_MONITOR_TYPE
\r
318 config.monitor_type = GetPrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
\r
320 #ifdef USE_CRT_FILTER
\r
321 config.crt_filter = GetPrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
\r
323 #ifdef USE_SCANLINE
\r
324 config.scan_line = GetPrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
\r
328 config.sound_frequency = GetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
\r
329 config.sound_latency = GetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
\r
330 #ifdef USE_SOUND_DEVICE_TYPE
\r
331 config.sound_device_type = GetPrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
\r
333 GetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
\r
335 #if defined(_USE_AGAR) || (_USE_SDL)
\r
336 config_path->Fclose();
\r
337 delete config_path;
\r
346 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
347 char app_path2[_MAX_PATH], *ptr;
\r
348 char cfgpath[_MAX_PATH];
\r
349 FILEIO *config_path = new FILEIO();
\r
351 app_path2[0] = '\0';
\r
353 //GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
\r
354 cpp_confdir.copy(app_path2, _MAX_PATH, 0);
\r
356 strncat(app_path2, CONFIG_NAME, _MAX_PATH);
\r
357 strncat(app_path2, ".ini", _MAX_PATH);
\r
359 #if defined(_USE_AGAR) || defined(_USE_SDL)
\r
360 AGAR_DebugLog(AGAR_LOG_INFO, "Try to write config: %s", app_path2);
\r
362 printf("Try to write config: %s\n", app_path2);
\r
365 if(config_path->Fopen(app_path2, FILEIO_WRITE_ASCII) != true) return;
\r
366 AGAR_DebugLog(AGAR_LOG_INFO, "OK.");
\r
369 _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
\r
370 GetModuleFileName(NULL, config_path, _MAX_PATH);
\r
371 GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
\r
373 _stprintf(config_path, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
\r
377 # ifdef USE_BOOT_MODE
\r
378 WritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
\r
380 #ifdef USE_CPU_TYPE
\r
381 WritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
\r
383 #ifdef USE_DIPSWITCH
\r
384 WritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
\r
386 #ifdef USE_DEVICE_TYPE
\r
387 WritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
\r
390 WritePrivateProfileBool(_T("Control"), _T("IgnoreCRC"), config.ignore_crc, config_path);
\r
393 WritePrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
\r
394 WritePrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
\r
399 WritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
\r
400 for(drv = 0; drv < MAX_CART; drv++) {
\r
401 for(i = 0; i < MAX_HISTORY; i++) {
\r
403 sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
\r
404 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_cart_path[drv][i], config_path);
\r
409 WritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
\r
410 for(drv = 0; drv < MAX_FD; drv++) {
\r
411 for(i = 0; i < MAX_HISTORY; i++) {
\r
413 sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
\r
414 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_disk_path[drv][i], config_path);
\r
419 WritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quickdisk_dir, config_path);
\r
420 for(drv = 0; drv < MAX_QD; drv++) {
\r
421 for(i = 0; i < MAX_HISTORY; i++) {
\r
423 sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
\r
424 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_quickdisk_path[drv][i], config_path);
\r
429 WritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
\r
430 for(i = 0; i < MAX_HISTORY; i++) {
\r
432 sprintf(name, _T("RecentTapePath1_%d"), i + 1);
\r
433 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_tape_path[i], config_path);
\r
436 #ifdef USE_LASER_DISC
\r
437 WritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
\r
438 for(int i = 0; i < MAX_HISTORY; i++) {
\r
440 sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
\r
441 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_laser_disc_path[i], config_path);
\r
444 #ifdef USE_BINARY_FILE1
\r
445 WritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
\r
446 for(drv = 0; drv < MAX_BINARY; drv++) {
\r
447 for(i = 0; i < MAX_HISTORY; i++) {
\r
449 sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
\r
450 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_binary_path[drv][i], config_path);
\r
456 #if !(defined(USE_BITMAP) || defined(USE_LED))
\r
457 WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
\r
458 WritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
\r
459 WritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
\r
460 WritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
\r
462 #ifdef USE_MONITOR_TYPE
\r
463 WritePrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
\r
465 #ifdef USE_CRT_FILTER
\r
466 WritePrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
\r
468 #ifdef USE_SCANLINE
\r
469 WritePrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
\r
473 WritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
\r
474 WritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
\r
475 #ifdef USE_SOUND_DEVICE_TYPE
\r
476 WritePrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
\r
478 #if defined(_USE_AGAR) || (_USE_SDL)
\r
479 config_path->Fclose();
\r
480 delete config_path;
\r
485 #define STATE_VERSION 1
\r
487 void save_config_state(void *f)
\r
489 FILEIO *state_fio = (FILEIO *)f;
\r
491 state_fio->FputUint32(STATE_VERSION);
\r
493 #ifdef USE_BOOT_MODE
\r
494 state_fio->FputInt32(config.boot_mode);
\r
496 #ifdef USE_CPU_TYPE
\r
497 state_fio->FputInt32(config.cpu_type);
\r
499 #ifdef USE_DIPSWITCH
\r
500 state_fio->FputUint32(config.dipswitch);
\r
502 #ifdef USE_DEVICE_TYPE
\r
503 state_fio->FputInt32(config.device_type);
\r
506 state_fio->FputBool(config.ignore_crc);
\r
508 #ifdef USE_MONITOR_TYPE
\r
509 state_fio->FputInt32(config.monitor_type);
\r
511 #ifdef USE_SOUND_DEVICE_TYPE
\r
512 state_fio->FputInt32(config.sound_device_type);
\r
516 bool load_config_state(void *f)
\r
518 FILEIO *state_fio = (FILEIO *)f;
\r
520 if(state_fio->FgetUint32() != STATE_VERSION) {
\r
523 #ifdef USE_BOOT_MODE
\r
524 config.boot_mode = state_fio->FgetInt32();
\r
526 #ifdef USE_CPU_TYPE
\r
527 config.cpu_type = state_fio->FgetInt32();
\r
529 #ifdef USE_DIPSWITCH
\r
530 config.dipswitch = state_fio->FgetUint32();
\r
532 #ifdef USE_DEVICE_TYPE
\r
533 config.device_type = state_fio->FgetInt32();
\r
536 config.ignore_crc = state_fio->FgetBool();
\r
538 #ifdef USE_MONITOR_TYPE
\r
539 config.monitor_type = state_fio->FgetInt32();
\r
541 #ifdef USE_SOUND_DEVICE_TYPE
\r
542 config.sound_device_type = state_fio->FgetInt32();
\r