OSDN Git Service

[VM][WIN32] config.cpp : Be type BOOL to bool with some config values.
[csp-qt/common_source_project-fm7.git] / source / src / config.cpp
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.18 -
6
7         [ config ]
8 */
9 #if defined(_USE_AGAR)
10 #include <SDL/SDL.h>
11 #include <agar/core.h>
12 #include <string>
13 #include <vector>
14 #include "fileio.h"
15 #include "agar_logger.h"
16 #endif
17
18 #ifdef _USE_QT
19 //# include <SDL/SDL.h>
20 #include <string>
21 #include <vector>
22 #include "fileio.h"
23 #include "agar_logger.h"
24 #include "qt_main.h"
25 #else
26 #include <windows.h>
27 #endif
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include "common.h"
32 #include "config.h"
33 #include "fileio.h"
34 #if defined(_USE_AGAR)
35 #include "agar_main.h"
36 #endif
37
38 config_t config;
39
40 #ifndef CONFIG_NAME
41 #define CONFIG_NAME "conf"
42 #endif
43
44 #if defined(_USE_AGAR) || defined(_USE_QT)
45 bool WritePrivateProfileString(char *lpAppName, char *lpKeyName, char *Value, FILEIO *lpFileName)
46 {
47    std::string s;
48   
49    s = lpAppName;
50    s = s + ".";
51    s = s + lpKeyName + "=";
52    s = s + Value + "\n";
53    
54    lpFileName->Fwrite((void *)s.c_str(), s.length(), 1);
55    return true;
56 }
57
58 bool WritePrivateProfileInt(char *lpAppName, char *lpKeyName, int Value, FILEIO *lpFileName)
59 {
60    std::string s;
61    int l;
62    char valuebuf[256];
63    memset(valuebuf, 0x00, 256);
64    
65    l = snprintf(valuebuf, 254, "%d", Value);
66    if((l <= 0) || (l >= 253)) return false;
67    s = lpAppName;
68    s = s + ".";
69    s = s + lpKeyName + "=";
70    s = s + valuebuf + "\n";
71    lpFileName->Fwrite((void *)s.c_str(), s.length(), 1);
72
73    return true;
74 }
75
76 BOOL WritePrivateProfileBool(char *lpAppName, char *lpKeyName, bool Value, FILEIO *lpFileName)
77 {
78    int v = 0;
79    if(Value) v = 1; 
80    return WritePrivateProfileInt(lpAppName, lpKeyName, v, lpFileName);
81 }
82  
83
84
85 std::string GetPrivateProfileStr(char *lpAppName, char *lpKeyName, FILEIO *lpFileName)
86 {
87    std::string key;
88    char ibuf[4096 + 102];
89    uint64_t i;
90    int l_len;
91    int c = '\0';
92    std::string::size_type  pos;
93    std::string key_str;
94    std::string got_str;
95   
96    key = lpAppName;
97    key = key + ".";
98    key = key + lpKeyName;
99    AGAR_DebugLog(AGAR_LOG_DEBUG, "Try App: %s Key: %s", lpAppName, lpKeyName);
100    lpFileName->Fseek(0, FILEIO_SEEK_SET);
101    do {
102       key_str = key;
103       ibuf[0] = '\0';
104       i = 0;
105       l_len = 0;
106       while(1) {
107         if(l_len > (4096 + 100)) { // Too long, read dummy.
108            c = (char)lpFileName->Fgetc();
109            if((c != EOF) && (c != '\n') && (c != '\0')) continue;
110            break;
111         }
112         c = (char)lpFileName->Fgetc();
113         if((c == EOF) || (c == '\n') || (c == '\0')) break;
114         ibuf[i] = (char)c;
115         i++;
116         l_len++;
117       }
118       l_len = 0;
119       ibuf[i] = '\0';
120       got_str = ibuf;
121       //AGAR_DebugLog(AGAR_LOG_DEBUG, "Got: %s %d chars.\n", got_str.c_str(), i);
122       key_str = key_str + "=";
123       pos = got_str.find(key_str);
124       if(pos != std::string::npos) break;
125       if(c == EOF) return "";
126    } while(c != EOF);
127
128    got_str.erase(0, pos + key_str.length());
129    //AGAR_DebugLog(AGAR_LOG_DEBUG, "Ok. Got %s = %s.\n", key, got_str.c_str());
130    return got_str;
131 }
132
133 void GetPrivateProfileString(char *section, char *key, char *defaultstr, char *str, int max_len, FILEIO *p)
134 {
135    std::string sp = GetPrivateProfileStr(section, key, p);
136 //   printf("Got: %s\n", sp.c_str());
137    
138    if((!sp.empty()) && (max_len > 1)){
139         strncpy(str, sp.c_str(), max_len);
140    } else {
141         strncpy(str, defaultstr, max_len);
142    }
143    printf("Got: %s\n", str);
144  
145 }
146
147 int GetPrivateProfileInt(char *lpAppName, char *lpKeyName, int nDefault, FILEIO *lpFileName)
148 {
149    int i;
150    std::string s = GetPrivateProfileStr(lpAppName,lpKeyName, lpFileName);
151
152    if(s.empty()) {
153       i = nDefault;
154    } else {
155       i = strtol(s.c_str(), NULL, 10);
156    }
157    printf("Got: %d\n", i);
158    return i;
159 }
160
161
162
163 bool GetPrivateProfileBool(char *lpAppName, char *lpKeyName, bool bDefault, FILEIO *lpFileName)
164 {
165    
166         return (GetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
167 }
168    
169 #else
170 extern _TCHAR* get_parent_dir(_TCHAR* file);
171 BOOL WritePrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, int Value, LPCTSTR lpFileName)
172 {
173         _TCHAR String[32];
174         _stprintf_s(String, 32, _T("%d"), Value);
175         return WritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
176 }
177
178 BOOL WritePrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool Value, LPCTSTR lpFileName)
179 {
180         _TCHAR String[32];
181         _stprintf_s(String, 32, _T("%d"), Value ? 1 : 0);
182         return WritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
183 }
184
185 BOOL GetPrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool bDefault, LPCTSTR lpFileName)
186 {
187         return (GetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
188 }
189
190 #endif
191 void init_config()
192 {
193         int i;
194         // initial settings
195         memset(&config, 0, sizeof(config_t));
196         
197         config.use_direct_input = true;
198         config.disable_dwm = false;
199         
200 #if !(defined(USE_BITMAP) || defined(USE_LED))
201         config.use_d3d9 = true;
202         config.stretch_type = 1;        // Stretch (Aspect)
203 #endif
204         config.sound_frequency = 6;     // 48KHz
205         config.sound_latency = 1;       // 100msec
206         
207 #if defined(USE_TAPE)
208         config.wave_shaper = true;
209         config.direct_load_mzt = true;
210         config.baud_high = true;
211 #endif
212 #if defined(USE_BOOT_MODE) && defined(BOOT_MODE_DEFAULT)
213         config.boot_mode = BOOT_MODE_DEFAULT;
214 #endif
215 #if defined(USE_CPU_TYPE) && defined(CPU_TYPE_DEFAULT)
216         config.cpu_type = CPU_TYPE_DEFAULT;
217 #endif
218 #if defined(USE_DIPSWITCH) && defined(DIPSWITCH_DEFAULT)
219         config.dipswitch = DIPSWITCH_DEFAULT;
220 #endif
221 #if defined(USE_DEVICE_TYPE) && defined(DEVICE_TYPE_DEFAULT)
222         config.device_type = DEVICE_TYPE_DEFAULT;
223 #endif
224 #if defined(USE_FD1)
225 # if defined(IGNORE_CRC_DEFAULT)
226         for(i = 0; i < 8; i++) config.ignore_crc[i] = IGNORE_CRC_DEFAULT;
227 # else
228         for(i = 0; i < 8; i++) config.ignore_crc[i] = false;
229 # endif 
230 #endif
231 #if defined(USE_SOUND_DEVICE_TYPE) && defined(SOUND_DEVICE_TYPE_DEFAULT)
232         config.sound_device_type = SOUND_DEVICE_TYPE_DEFAULT;
233 #endif
234         // FM7 Series:
235         // 0 = PSG or NONE
236         // 1 = OPN (+PSG)
237         // 2 = WHG (+PSG)
238         // 3 = WHG + OPN (+PSG)
239         // 4 = THG  (+PSG)
240         // 5 = THG + OPN (+PSG)
241         // 6 = THG + WHG (+PSG)
242         // 7 = THG + WHG + OPN (+PSG)
243 #if defined(_FM8)
244         config.sound_device_type = 0;   // WITHOUT PSG?
245 #elif  defined(_FM7) || defined(_FMNEW7) || defined(_FM77) || defined(_FM77L4) || defined(_FM77L2)
246         config.sound_device_type = 0;   // PSG ONLY      
247 #elif  defined(_FM77AV) || defined(_FM77AV20) || defined(_FM77AV40) || defined(_FM77AV40EX) || defined(_FM77AV40SX)
248         config.sound_device_type = 1;   // OPN      
249 #endif       
250 }
251
252 void load_config()
253 {
254         int drv, i;
255         // initial settings
256         init_config();
257         
258         // get config path
259
260 #if defined(_USE_AGAR) || defined(_USE_QT) 
261         char app_path2[_MAX_PATH], *ptr;
262         FILEIO *config_path = new FILEIO();
263    
264         memset(app_path2, 0x00, _MAX_PATH);
265         cpp_confdir.copy(app_path2, _MAX_PATH, 0);
266         
267         strncat(app_path2, CONFIG_NAME, _MAX_PATH);
268         strncat(app_path2, ".ini", _MAX_PATH);
269
270         AGAR_DebugLog(AGAR_LOG_INFO, "Try to read config: %s", app_path2);
271         if(!config_path->Fopen(app_path2, FILEIO_READ_ASCII)) return;
272 #else
273         _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
274         memset(config_path, 0x00, _MAX_PATH);
275         GetModuleFileName(NULL, config_path, _MAX_PATH);
276         GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
277         *ptr = _T('\0');
278         _stprintf_s(config_path, _MAX_PATH, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
279 #endif
280    
281         
282         // control
283         config.use_direct_input = GetPrivateProfileBool(_T("Control"), _T("UseDirectInput"), config.use_direct_input, config_path);
284         config.disable_dwm = GetPrivateProfileBool(_T("Control"), _T("DisableDwm"), config.disable_dwm, config_path);
285         
286 #ifdef USE_BOOT_MODE
287         config.boot_mode = GetPrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
288 #endif
289 #ifdef USE_CPU_TYPE
290         config.cpu_type = GetPrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
291 #endif
292 #ifdef USE_DIPSWITCH
293         config.dipswitch = GetPrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
294 #endif
295 #ifdef USE_DEVICE_TYPE
296         config.device_type = GetPrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
297 #endif
298 #ifdef USE_DRIVE_TYPE
299         config.drive_type = GetPrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
300 #endif
301 #ifdef USE_FD1
302         {
303                 _TCHAR _tag[128];
304                 for(drv = 0; drv < 8; drv++) {
305                         memset(_tag, 0x00, sizeof(_tag));
306                         _stprintf_s(_tag, 64, _T("IgnoreCRC_%d"), drv + 1);
307                         config.ignore_crc[drv] = GetPrivateProfileBool(_T("Control"), _tag, config.ignore_crc[drv], config_path);
308                 }
309         }
310 #endif
311 #ifdef USE_TAPE
312         config.tape_sound = GetPrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
313         config.wave_shaper = GetPrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
314         config.direct_load_mzt = GetPrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
315         config.baud_high = GetPrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
316 #endif
317         
318         // recent files
319 #ifdef USE_CART1
320         GetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
321         for(drv = 0; drv < MAX_CART; drv++) {
322                 for(i = 0; i < MAX_HISTORY; i++) {
323                         _TCHAR name[64];
324                         _stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
325 //                      sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
326                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_cart_path[drv][i], _MAX_PATH, config_path);
327                 }
328         }
329 #endif
330 #ifdef USE_FD1
331         GetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""), config.initial_disk_dir, _MAX_PATH, config_path);
332         get_parent_dir(config.initial_disk_dir);
333         for(drv = 0; drv < MAX_FD; drv++) {
334                 for(i = 0; i < MAX_HISTORY; i++) {
335                         _TCHAR name[64];
336 //                      sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
337                         _stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
338                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_disk_path[drv][i], _MAX_PATH, config_path);
339                 }
340         }
341 #endif
342 #ifdef USE_QD1
343         GetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), _T(""), config.initial_quickdisk_dir, _MAX_PATH, config_path);
344         for(drv = 0; drv < MAX_QD; drv++) {
345                 for(i = 0; i < MAX_HISTORY; i++) {
346                         _TCHAR name[64];
347 //                      sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
348                         _stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
349                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_quickdisk_path[drv][i], _MAX_PATH, config_path);
350                 }
351         }
352 #endif
353 #ifdef USE_TAPE
354         GetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""), config.initial_tape_dir, _MAX_PATH, config_path);
355         for(i = 0; i < MAX_HISTORY; i++) {
356                 _TCHAR name[64];
357 //              sprintf(name, _T("RecentTapePath1_%d"), i + 1);
358                 _stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
359                 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_tape_path[i], _MAX_PATH, config_path);
360         }
361 #endif
362 #ifdef USE_LASER_DISC
363         GetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""), config.initial_laser_disc_dir, _MAX_PATH, config_path);
364         for(int i = 0; i < MAX_HISTORY; i++) {
365                 _TCHAR name[64];
366 //              sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
367                 _stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
368                 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_laser_disc_path[i], _MAX_PATH, config_path);
369         }
370 #endif
371 #ifdef USE_BINARY_FILE1
372         GetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""), config.initial_binary_dir, _MAX_PATH, config_path);
373         for(drv = 0; drv < MAX_BINARY; drv++) {
374                 for(i = 0; i < MAX_HISTORY; i++) {
375                         _TCHAR name[64];
376 //                      sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
377                         _stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
378                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_binary_path[drv][i], _MAX_PATH, config_path);
379                 }
380         }
381 #endif
382         
383         // screen
384 #if !(defined(USE_BITMAP) || defined(USE_LED))
385         config.window_mode = GetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
386         config.use_d3d9 = GetPrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
387         config.wait_vsync = GetPrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
388         config.stretch_type = GetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
389 #else
390         config.window_mode = GetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
391 #endif
392 #ifdef USE_MONITOR_TYPE
393         config.monitor_type = GetPrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
394 #endif
395 #ifdef USE_CRT_FILTER
396         config.crt_filter = GetPrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
397 #endif
398 #ifdef USE_SCANLINE
399         config.scan_line = GetPrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
400 #endif
401
402 #ifdef USE_SCREEN_ROTATE
403         config.rotate_type = GetPrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
404 #endif
405         
406         // sound
407         config.sound_frequency = GetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
408         config.sound_latency = GetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
409 #ifdef USE_SOUND_DEVICE_TYPE
410         config.sound_device_type = GetPrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
411 #endif
412 #if defined(DATAREC_SOUND) && defined(USE_TAPE)
413 //      config.cmt_sound = GetPrivateProfileBool(_T("Sound"), _T("CMT"), false, config_path);
414 //      config.cmt_volume = GetPrivateProfileInt(_T("Sound"), _T("CMTVolume"), 0x1800, config_path);
415 #endif
416 //      GetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
417
418 #if defined(_USE_AGAR) || defined(_USE_QT)
419      config_path->Fclose();
420      delete config_path;
421      AGAR_DebugLog(AGAR_LOG_INFO, "Read Done.");
422 #endif
423 }
424
425 void save_config()
426 {
427         int drv, i;
428         // get config path
429 #if defined(_USE_AGAR) || defined(_USE_QT)
430         char app_path2[_MAX_PATH], *ptr;
431         FILEIO *config_path = new FILEIO();
432    
433         app_path2[0] = '\0';
434                 //GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
435         memset(app_path2, 0x00, _MAX_PATH);
436         cpp_confdir.copy(app_path2, _MAX_PATH, 0);
437         
438         strncat(app_path2, CONFIG_NAME, _MAX_PATH);
439         strncat(app_path2, ".ini", _MAX_PATH);
440
441         AGAR_DebugLog(AGAR_LOG_INFO, "Try to write config: %s", app_path2);
442         if(config_path->Fopen(app_path2, FILEIO_WRITE_ASCII) != true) return;
443 #else
444         _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
445         memset(config_path, 0x00, _MAX_PATH);
446         GetModuleFileName(NULL, config_path, _MAX_PATH);
447         GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
448         *ptr = _T('\0');
449         _stprintf_s(config_path, _MAX_PATH, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
450 #endif  
451         // control
452         WritePrivateProfileBool(_T("Control"), _T("UseDirectInput"), config.use_direct_input, config_path);
453         WritePrivateProfileBool(_T("Control"), _T("DisableDwm"), config.disable_dwm, config_path);
454
455 # ifdef USE_BOOT_MODE
456         WritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
457 #endif
458 #ifdef USE_CPU_TYPE
459         WritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
460 #endif
461 #ifdef USE_DIPSWITCH
462         WritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
463 #endif
464 #ifdef USE_DEVICE_TYPE
465         WritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
466 #endif
467 #ifdef USE_DRIVE_TYPE
468         WritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
469 #endif
470 #ifdef USE_FD1
471         {
472                 _TCHAR _tag[128];
473                 for(drv = 0; drv < 8; drv++) {
474                         memset(_tag, 0x00, sizeof(_tag));
475                         _stprintf_s(_tag, 64, _T("IgnoreCRC_%d"), drv + 1);
476                         WritePrivateProfileBool(_T("Control"), _tag, config.ignore_crc[drv], config_path);
477                 }
478         }
479         
480 #endif
481 #ifdef USE_TAPE
482         WritePrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
483         WritePrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
484         WritePrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
485         WritePrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
486 #endif
487         
488         // recent files
489 #ifdef USE_CART1
490         WritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
491         for(drv = 0; drv < MAX_CART; drv++) {
492                 for(i = 0; i < MAX_HISTORY; i++) {
493                         _TCHAR name[64];
494                         _stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
495 //                      sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
496                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_cart_path[drv][i], config_path);
497                 }
498         }
499 #endif
500 #ifdef USE_FD1
501         WritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
502         for(drv = 0; drv < MAX_FD; drv++) {
503                 for(i = 0; i < MAX_HISTORY; i++) {
504                         _TCHAR name[64];
505 //                      sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
506                         _stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
507                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_disk_path[drv][i], config_path);
508                 }
509         }
510 #endif
511 #ifdef USE_QD1
512         WritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quickdisk_dir, config_path);
513         for(drv = 0; drv < MAX_QD; drv++) {
514                 for(i = 0; i < MAX_HISTORY; i++) {
515                         _TCHAR name[64];
516                         _stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
517 //                      sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
518                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_quickdisk_path[drv][i], config_path);
519                 }
520         }
521 #endif
522 #ifdef USE_TAPE
523         WritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
524         for(i = 0; i < MAX_HISTORY; i++) {
525                 _TCHAR name[64];
526 //              sprintf(name, _T("RecentTapePath1_%d"), i + 1);
527                 _stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
528                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_tape_path[i], config_path);
529         }
530 #endif
531 #ifdef USE_LASER_DISC
532         WritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
533         for(int i = 0; i < MAX_HISTORY; i++) {
534                 _TCHAR name[64];
535 //              sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
536                 _stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
537                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_laser_disc_path[i], config_path);
538         }
539 #endif
540 #ifdef USE_BINARY_FILE1
541         WritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
542         for(drv = 0; drv < MAX_BINARY; drv++) {
543                 for(i = 0; i < MAX_HISTORY; i++) {
544                         _TCHAR name[64];
545 //                      sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
546                         _stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
547                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_binary_path[drv][i], config_path);
548                 }
549         }
550 #endif
551         
552         // screen
553 #if !(defined(USE_BITMAP) || defined(USE_LED))
554         WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
555         WritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
556         WritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
557         WritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
558 #else
559         WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
560 #endif
561 #ifdef USE_MONITOR_TYPE
562         WritePrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
563 #endif
564 #ifdef USE_CRT_FILTER
565         WritePrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
566 #endif
567 #ifdef USE_SCANLINE
568         WritePrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
569 #endif
570 #ifdef USE_SCREEN_ROTATE
571         WritePrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
572 #endif
573         
574         // sound
575         WritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
576         WritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
577 #ifdef USE_SOUND_DEVICE_TYPE
578         WritePrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
579 #endif
580 #if defined(DATAREC_SOUND) && defined(USE_TAPE)
581 //      WritePrivateProfileBool(_T("Sound"), _T("CMT"), config.cmt_sound, config_path);
582 //      WritePrivateProfileInt(_T("Sound"), _T("CMTVolume"), config.cmt_volume, config_path);
583 #endif
584 #if defined(_USE_AGAR) || defined(_USE_QT)
585         config_path->Fclose();
586         delete config_path;
587         AGAR_DebugLog(AGAR_LOG_INFO, "Write done.");
588 #endif
589
590 }
591
592 #define STATE_VERSION   1
593
594 void save_config_state(void *f)
595 {
596         FILEIO *state_fio = (FILEIO *)f;
597         int drv;
598         
599         state_fio->FputUint32(STATE_VERSION);
600         
601 #ifdef USE_BOOT_MODE
602         state_fio->FputInt32(config.boot_mode);
603 #endif
604 #ifdef USE_CPU_TYPE
605         state_fio->FputInt32(config.cpu_type);
606 #endif
607 #ifdef USE_DIPSWITCH
608         state_fio->FputUint32(config.dipswitch);
609 #endif
610 #ifdef USE_DEVICE_TYPE
611         state_fio->FputInt32(config.device_type);
612 #endif
613 #ifdef USE_DRIVE_TYPE
614         state_fio->FputInt32(config.drive_type);
615 #endif
616 #ifdef USE_FD1
617         for(drv = 0; drv < 8; drv++) state_fio->FputBool(config.ignore_crc[drv]);
618 #endif
619 #ifdef USE_MONITOR_TYPE
620         state_fio->FputInt32(config.monitor_type);
621 #endif
622 #ifdef USE_SOUND_DEVICE_TYPE
623         state_fio->FputInt32(config.sound_device_type);
624 #endif
625 }
626
627 bool load_config_state(void *f)
628 {
629         FILEIO *state_fio = (FILEIO *)f;
630         int drv;
631         
632         if(state_fio->FgetUint32() != STATE_VERSION) {
633                 return false;
634         }
635 #ifdef USE_BOOT_MODE
636         config.boot_mode = state_fio->FgetInt32();
637 #endif
638 #ifdef USE_CPU_TYPE
639         config.cpu_type = state_fio->FgetInt32();
640 #endif
641 #ifdef USE_DIPSWITCH
642         config.dipswitch = state_fio->FgetUint32();
643 #endif
644 #ifdef USE_DEVICE_TYPE
645         config.device_type = state_fio->FgetInt32();
646 #endif
647 #ifdef USE_DRIVE_TYPE
648         config.drive_type = state_fio->FgetInt32();
649 #endif
650 #ifdef USE_FD1
651         for(drv = 0; drv < 8; drv++) config.ignore_crc[drv] = state_fio->FgetBool();
652 #endif
653 #ifdef USE_MONITOR_TYPE
654         config.monitor_type = state_fio->FgetInt32();
655 #endif
656 #ifdef USE_SOUND_DEVICE_TYPE
657         config.sound_device_type = state_fio->FgetInt32();
658 #endif
659         return true;
660 }
661