OSDN Git Service

[VM][EMU][CONFIG] OOPS: I forgot config.ignore_crc as array when not defined default...
[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 #endif
390 #ifdef USE_MONITOR_TYPE
391         config.monitor_type = GetPrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
392 #endif
393 #ifdef USE_CRT_FILTER
394         config.crt_filter = GetPrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
395 #endif
396 #ifdef USE_SCANLINE
397         config.scan_line = GetPrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
398 #endif
399
400 #ifdef USE_SCREEN_ROTATE
401         config.rotate_type = GetPrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
402 #endif
403         
404         // sound
405         config.sound_frequency = GetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
406         config.sound_latency = GetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
407 #ifdef USE_SOUND_DEVICE_TYPE
408         config.sound_device_type = GetPrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
409 #endif
410 #if defined(DATAREC_SOUND) && defined(USE_TAPE)
411 //      config.cmt_sound = GetPrivateProfileBool(_T("Sound"), _T("CMT"), false, config_path);
412 //      config.cmt_volume = GetPrivateProfileInt(_T("Sound"), _T("CMTVolume"), 0x1800, config_path);
413 #endif
414 //      GetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
415
416 #if defined(_USE_AGAR) || defined(_USE_QT)
417      config_path->Fclose();
418      delete config_path;
419      AGAR_DebugLog(AGAR_LOG_INFO, "Read Done.");
420 #endif
421 }
422
423 void save_config()
424 {
425         int drv, i;
426         // get config path
427 #if defined(_USE_AGAR) || defined(_USE_QT)
428         char app_path2[_MAX_PATH], *ptr;
429         FILEIO *config_path = new FILEIO();
430    
431         app_path2[0] = '\0';
432                 //GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
433         memset(app_path2, 0x00, _MAX_PATH);
434         cpp_confdir.copy(app_path2, _MAX_PATH, 0);
435         
436         strncat(app_path2, CONFIG_NAME, _MAX_PATH);
437         strncat(app_path2, ".ini", _MAX_PATH);
438
439         AGAR_DebugLog(AGAR_LOG_INFO, "Try to write config: %s", app_path2);
440         if(config_path->Fopen(app_path2, FILEIO_WRITE_ASCII) != true) return;
441 #else
442         _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
443         memset(config_path, 0x00, _MAX_PATH);
444         GetModuleFileName(NULL, config_path, _MAX_PATH);
445         GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
446         *ptr = _T('\0');
447         _stprintf_s(config_path, _MAX_PATH, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
448 #endif  
449         // control
450         WritePrivateProfileBool(_T("Control"), _T("UseDirectInput"), config.use_direct_input, config_path);
451         WritePrivateProfileBool(_T("Control"), _T("DisableDwm"), config.disable_dwm, config_path);
452
453 # ifdef USE_BOOT_MODE
454         WritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
455 #endif
456 #ifdef USE_CPU_TYPE
457         WritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
458 #endif
459 #ifdef USE_DIPSWITCH
460         WritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
461 #endif
462 #ifdef USE_DEVICE_TYPE
463         WritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
464 #endif
465 #ifdef USE_DRIVE_TYPE
466         WritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
467 #endif
468 #ifdef USE_FD1
469         {
470                 _TCHAR _tag[128];
471                 for(drv = 0; drv < 8; drv++) {
472                         memset(_tag, 0x00, sizeof(_tag));
473                         _stprintf_s(_tag, 64, _T("IgnoreCRC_%d"), drv + 1);
474                         WritePrivateProfileBool(_T("Control"), _tag, config.ignore_crc[drv], config_path);
475                 }
476         }
477         
478 #endif
479 #ifdef USE_TAPE
480         WritePrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
481         WritePrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
482         WritePrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
483         WritePrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
484 #endif
485         
486         // recent files
487 #ifdef USE_CART1
488         WritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
489         for(drv = 0; drv < MAX_CART; drv++) {
490                 for(i = 0; i < MAX_HISTORY; i++) {
491                         _TCHAR name[64];
492                         _stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
493 //                      sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
494                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_cart_path[drv][i], config_path);
495                 }
496         }
497 #endif
498 #ifdef USE_FD1
499         WritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
500         for(drv = 0; drv < MAX_FD; drv++) {
501                 for(i = 0; i < MAX_HISTORY; i++) {
502                         _TCHAR name[64];
503 //                      sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
504                         _stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
505                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_disk_path[drv][i], config_path);
506                 }
507         }
508 #endif
509 #ifdef USE_QD1
510         WritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quickdisk_dir, config_path);
511         for(drv = 0; drv < MAX_QD; drv++) {
512                 for(i = 0; i < MAX_HISTORY; i++) {
513                         _TCHAR name[64];
514                         _stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
515 //                      sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
516                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_quickdisk_path[drv][i], config_path);
517                 }
518         }
519 #endif
520 #ifdef USE_TAPE
521         WritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
522         for(i = 0; i < MAX_HISTORY; i++) {
523                 _TCHAR name[64];
524 //              sprintf(name, _T("RecentTapePath1_%d"), i + 1);
525                 _stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
526                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_tape_path[i], config_path);
527         }
528 #endif
529 #ifdef USE_LASER_DISC
530         WritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
531         for(int i = 0; i < MAX_HISTORY; i++) {
532                 _TCHAR name[64];
533 //              sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
534                 _stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
535                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_laser_disc_path[i], config_path);
536         }
537 #endif
538 #ifdef USE_BINARY_FILE1
539         WritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
540         for(drv = 0; drv < MAX_BINARY; drv++) {
541                 for(i = 0; i < MAX_HISTORY; i++) {
542                         _TCHAR name[64];
543 //                      sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
544                         _stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
545                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_binary_path[drv][i], config_path);
546                 }
547         }
548 #endif
549         
550         // screen
551 #if !(defined(USE_BITMAP) || defined(USE_LED))
552         WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
553         WritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
554         WritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
555         WritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
556 #endif
557 #ifdef USE_MONITOR_TYPE
558         WritePrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
559 #endif
560 #ifdef USE_CRT_FILTER
561         WritePrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
562 #endif
563 #ifdef USE_SCANLINE
564         WritePrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
565 #endif
566 #ifdef USE_SCREEN_ROTATE
567         WritePrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
568 #endif
569         
570         // sound
571         WritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
572         WritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
573 #ifdef USE_SOUND_DEVICE_TYPE
574         WritePrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
575 #endif
576 #if defined(DATAREC_SOUND) && defined(USE_TAPE)
577 //      WritePrivateProfileBool(_T("Sound"), _T("CMT"), config.cmt_sound, config_path);
578 //      WritePrivateProfileInt(_T("Sound"), _T("CMTVolume"), config.cmt_volume, config_path);
579 #endif
580 #if defined(_USE_AGAR) || defined(_USE_QT)
581         config_path->Fclose();
582         delete config_path;
583         AGAR_DebugLog(AGAR_LOG_INFO, "Write done.");
584 #endif
585
586 }
587
588 #define STATE_VERSION   1
589
590 void save_config_state(void *f)
591 {
592         FILEIO *state_fio = (FILEIO *)f;
593         int drv;
594         
595         state_fio->FputUint32(STATE_VERSION);
596         
597 #ifdef USE_BOOT_MODE
598         state_fio->FputInt32(config.boot_mode);
599 #endif
600 #ifdef USE_CPU_TYPE
601         state_fio->FputInt32(config.cpu_type);
602 #endif
603 #ifdef USE_DIPSWITCH
604         state_fio->FputUint32(config.dipswitch);
605 #endif
606 #ifdef USE_DEVICE_TYPE
607         state_fio->FputInt32(config.device_type);
608 #endif
609 #ifdef USE_DRIVE_TYPE
610         state_fio->FputInt32(config.drive_type);
611 #endif
612 #ifdef USE_FD1
613         for(drv = 0; drv < 8; drv++) state_fio->FputBool(config.ignore_crc[drv]);
614 #endif
615 #ifdef USE_MONITOR_TYPE
616         state_fio->FputInt32(config.monitor_type);
617 #endif
618 #ifdef USE_SOUND_DEVICE_TYPE
619         state_fio->FputInt32(config.sound_device_type);
620 #endif
621 }
622
623 bool load_config_state(void *f)
624 {
625         FILEIO *state_fio = (FILEIO *)f;
626         int drv;
627         
628         if(state_fio->FgetUint32() != STATE_VERSION) {
629                 return false;
630         }
631 #ifdef USE_BOOT_MODE
632         config.boot_mode = state_fio->FgetInt32();
633 #endif
634 #ifdef USE_CPU_TYPE
635         config.cpu_type = state_fio->FgetInt32();
636 #endif
637 #ifdef USE_DIPSWITCH
638         config.dipswitch = state_fio->FgetUint32();
639 #endif
640 #ifdef USE_DEVICE_TYPE
641         config.device_type = state_fio->FgetInt32();
642 #endif
643 #ifdef USE_DRIVE_TYPE
644         config.drive_type = state_fio->FgetInt32();
645 #endif
646 #ifdef USE_FD1
647         for(drv = 0; drv < 8; drv++) config.ignore_crc[drv] = state_fio->FgetBool();
648 #endif
649 #ifdef USE_MONITOR_TYPE
650         config.monitor_type = state_fio->FgetInt32();
651 #endif
652 #ifdef USE_SOUND_DEVICE_TYPE
653         config.sound_device_type = state_fio->FgetInt32();
654 #endif
655         return true;
656 }
657