OSDN Git Service

[VM][Qt][UI] Add volumes setting future.
[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         config.multiple_speakers = false;
251         config.general_sound_level = 0;
252
253 #if defined(USE_QT)
254         config.use_opengl_scanline = false;
255         config.opengl_scanline_vert = false;
256         config.opengl_scanline_horiz = false;
257         config.use_opengl_filters = false;
258         config.opengl_filter_num = 0;
259 #endif  
260 #ifdef USE_MULTIPLE_SOUNDCARDS
261         {
262                 int ii;
263                 for(ii = 0; ii < USE_MULTIPLE_SOUNDCARDS; ii++) {
264                         config.sound_device_level[ii] = 0;
265                 }
266         }
267 #endif
268 }
269
270 void load_config()
271 {
272         int drv, i;
273         // initial settings
274         init_config();
275         
276         // get config path
277
278 #if defined(_USE_AGAR) || defined(_USE_QT) 
279         char app_path2[_MAX_PATH], *ptr;
280         FILEIO *config_path = new FILEIO();
281    
282         memset(app_path2, 0x00, _MAX_PATH);
283         cpp_confdir.copy(app_path2, _MAX_PATH, 0);
284         
285         strncat(app_path2, CONFIG_NAME, _MAX_PATH);
286         strncat(app_path2, ".ini", _MAX_PATH);
287
288         AGAR_DebugLog(AGAR_LOG_INFO, "Try to read config: %s", app_path2);
289         if(!config_path->Fopen(app_path2, FILEIO_READ_ASCII)) return;
290 #else
291         _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
292         memset(config_path, 0x00, _MAX_PATH);
293         GetModuleFileName(NULL, config_path, _MAX_PATH);
294         GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
295         *ptr = _T('\0');
296         _stprintf_s(config_path, _MAX_PATH, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
297 #endif
298    
299         
300         // control
301         config.use_direct_input = GetPrivateProfileBool(_T("Control"), _T("UseDirectInput"), config.use_direct_input, config_path);
302         config.disable_dwm = GetPrivateProfileBool(_T("Control"), _T("DisableDwm"), config.disable_dwm, config_path);
303         
304 #ifdef USE_BOOT_MODE
305         config.boot_mode = GetPrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
306 #endif
307 #ifdef USE_CPU_TYPE
308         config.cpu_type = GetPrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
309 #endif
310 #ifdef USE_DIPSWITCH
311         config.dipswitch = GetPrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
312 #endif
313 #ifdef USE_DEVICE_TYPE
314         config.device_type = GetPrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
315 #endif
316 #ifdef USE_DRIVE_TYPE
317         config.drive_type = GetPrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
318 #endif
319 #ifdef USE_FD1
320         {
321                 _TCHAR _tag[128];
322                 for(drv = 0; drv < 8; drv++) {
323                         memset(_tag, 0x00, sizeof(_tag));
324                         _stprintf_s(_tag, 64, _T("IgnoreCRC_%d"), drv + 1);
325                         config.ignore_crc[drv] = GetPrivateProfileBool(_T("Control"), _tag, config.ignore_crc[drv], config_path);
326                 }
327         }
328 #endif
329 #ifdef USE_TAPE
330         config.tape_sound = GetPrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
331         config.wave_shaper = GetPrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
332         config.direct_load_mzt = GetPrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
333         config.baud_high = GetPrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
334 #endif
335         
336         // recent files
337 #ifdef USE_CART1
338         GetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
339         for(drv = 0; drv < MAX_CART; drv++) {
340                 for(i = 0; i < MAX_HISTORY; i++) {
341                         _TCHAR name[64];
342                         _stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
343 //                      sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
344                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_cart_path[drv][i], _MAX_PATH, config_path);
345                 }
346         }
347 #endif
348 #ifdef USE_FD1
349         GetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""), config.initial_disk_dir, _MAX_PATH, config_path);
350         get_parent_dir(config.initial_disk_dir);
351         for(drv = 0; drv < MAX_FD; drv++) {
352                 for(i = 0; i < MAX_HISTORY; i++) {
353                         _TCHAR name[64];
354 //                      sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
355                         _stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
356                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_disk_path[drv][i], _MAX_PATH, config_path);
357                 }
358         }
359 #endif
360 #ifdef USE_QD1
361         GetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), _T(""), config.initial_quickdisk_dir, _MAX_PATH, config_path);
362         for(drv = 0; drv < MAX_QD; drv++) {
363                 for(i = 0; i < MAX_HISTORY; i++) {
364                         _TCHAR name[64];
365 //                      sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
366                         _stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
367                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_quickdisk_path[drv][i], _MAX_PATH, config_path);
368                 }
369         }
370 #endif
371 #ifdef USE_TAPE
372         GetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""), config.initial_tape_dir, _MAX_PATH, config_path);
373         for(i = 0; i < MAX_HISTORY; i++) {
374                 _TCHAR name[64];
375 //              sprintf(name, _T("RecentTapePath1_%d"), i + 1);
376                 _stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
377                 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_tape_path[i], _MAX_PATH, config_path);
378         }
379 #endif
380 #ifdef USE_LASER_DISC
381         GetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""), config.initial_laser_disc_dir, _MAX_PATH, config_path);
382         for(int i = 0; i < MAX_HISTORY; i++) {
383                 _TCHAR name[64];
384 //              sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
385                 _stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
386                 GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_laser_disc_path[i], _MAX_PATH, config_path);
387         }
388 #endif
389 #ifdef USE_BINARY_FILE1
390         GetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""), config.initial_binary_dir, _MAX_PATH, config_path);
391         for(drv = 0; drv < MAX_BINARY; drv++) {
392                 for(i = 0; i < MAX_HISTORY; i++) {
393                         _TCHAR name[64];
394 //                      sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
395                         _stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
396                         GetPrivateProfileString(_T("RecentFiles"), name, _T(""), config.recent_binary_path[drv][i], _MAX_PATH, config_path);
397                 }
398         }
399 #endif
400         
401         // screen
402 #if !(defined(USE_BITMAP) || defined(USE_LED))
403         config.window_mode = GetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
404         config.use_d3d9 = GetPrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
405         config.wait_vsync = GetPrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
406         config.stretch_type = GetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
407 #else
408         config.window_mode = GetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
409 #endif
410 #ifdef USE_MONITOR_TYPE
411         config.monitor_type = GetPrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
412 #endif
413 #ifdef USE_CRT_FILTER
414         config.crt_filter = GetPrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
415 #endif
416 #ifdef USE_SCANLINE
417         config.scan_line = GetPrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
418 #endif
419
420 #ifdef USE_SCREEN_ROTATE
421         config.rotate_type = GetPrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
422 #endif
423 #if defined(USE_QT)
424         config.use_opengl_scanline = GetPrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"),
425                                                                                                            config.use_opengl_scanline, config_path);
426         config.opengl_scanline_vert = GetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"),
427                                                                                                            config.opengl_scanline_vert, config_path);;
428         config.opengl_scanline_horiz = GetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"),
429                                                                                                            config.opengl_scanline_horiz, config_path);;
430         config.use_opengl_filters = GetPrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"),
431                                                                                                            config.use_opengl_filters, config_path);
432         config.opengl_filter_num =      GetPrivateProfileInt(_T("Screen"), _T("OpenGlFilterNum"),
433                                                                                                          config.opengl_filter_num, config_path);
434 #endif  
435         // sound
436         config.sound_frequency = GetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
437         config.sound_latency = GetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
438 #ifdef USE_SOUND_DEVICE_TYPE
439         config.sound_device_type = GetPrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
440 #endif
441         config.multiple_speakers = GetPrivateProfileBool(_T("Sound"), _T("MultipleSpeakers"),
442                                                                                                          config.multiple_speakers, config_path);
443         config.general_sound_level = GetPrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
444                                                                                                           config.general_sound_level, config_path);
445 #ifdef USE_MULTIPLE_SOUNDCARDS
446         {
447                 _TCHAR _tag[128];
448                 int ii;
449                 for(ii = 0; ii < USE_MULTIPLE_SOUNDCARDS; ii++) {
450                         memset(_tag, 0x00, sizeof(_tag));
451                         _stprintf_s(_tag, 64, _T("DeviceVolumeLevel_%d"), ii + 1);
452                         config.sound_device_level[ii] = GetPrivateProfileBool(_T("Sound"), _tag, config.sound_device_level[ii], config_path);
453                 }
454         }
455 #endif
456 #if defined(_USE_AGAR) || defined(_USE_QT)
457      config_path->Fclose();
458      delete config_path;
459      AGAR_DebugLog(AGAR_LOG_INFO, "Read Done.");
460 #endif
461 }
462
463 void save_config()
464 {
465         int drv, i;
466         // get config path
467 #if defined(_USE_AGAR) || defined(_USE_QT)
468         char app_path2[_MAX_PATH], *ptr;
469         FILEIO *config_path = new FILEIO();
470    
471         app_path2[0] = '\0';
472                 //GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
473         memset(app_path2, 0x00, _MAX_PATH);
474         cpp_confdir.copy(app_path2, _MAX_PATH, 0);
475         
476         strncat(app_path2, CONFIG_NAME, _MAX_PATH);
477         strncat(app_path2, ".ini", _MAX_PATH);
478
479         AGAR_DebugLog(AGAR_LOG_INFO, "Try to write config: %s", app_path2);
480         if(config_path->Fopen(app_path2, FILEIO_WRITE_ASCII) != true) return;
481 #else
482         _TCHAR app_path[_MAX_PATH], config_path[_MAX_PATH], *ptr;
483         memset(config_path, 0x00, _MAX_PATH);
484         GetModuleFileName(NULL, config_path, _MAX_PATH);
485         GetFullPathName(config_path, _MAX_PATH, app_path, &ptr);
486         *ptr = _T('\0');
487         _stprintf_s(config_path, _MAX_PATH, _T("%s%s.ini"), app_path, _T(CONFIG_NAME));
488 #endif  
489         // control
490         WritePrivateProfileBool(_T("Control"), _T("UseDirectInput"), config.use_direct_input, config_path);
491         WritePrivateProfileBool(_T("Control"), _T("DisableDwm"), config.disable_dwm, config_path);
492
493 # ifdef USE_BOOT_MODE
494         WritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
495 #endif
496 #ifdef USE_CPU_TYPE
497         WritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
498 #endif
499 #ifdef USE_DIPSWITCH
500         WritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
501 #endif
502 #ifdef USE_DEVICE_TYPE
503         WritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
504 #endif
505 #ifdef USE_DRIVE_TYPE
506         WritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
507 #endif
508 #ifdef USE_FD1
509         {
510                 _TCHAR _tag[128];
511                 for(drv = 0; drv < 8; drv++) {
512                         memset(_tag, 0x00, sizeof(_tag));
513                         _stprintf_s(_tag, 64, _T("IgnoreCRC_%d"), drv + 1);
514                         WritePrivateProfileBool(_T("Control"), _tag, config.ignore_crc[drv], config_path);
515                 }
516         }
517         
518 #endif
519 #ifdef USE_TAPE
520         WritePrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
521         WritePrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
522         WritePrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
523         WritePrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
524 #endif
525         
526         // recent files
527 #ifdef USE_CART1
528         WritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
529         for(drv = 0; drv < MAX_CART; drv++) {
530                 for(i = 0; i < MAX_HISTORY; i++) {
531                         _TCHAR name[64];
532                         _stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
533 //                      sprintf(name, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
534                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_cart_path[drv][i], config_path);
535                 }
536         }
537 #endif
538 #ifdef USE_FD1
539         WritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
540         for(drv = 0; drv < MAX_FD; drv++) {
541                 for(i = 0; i < MAX_HISTORY; i++) {
542                         _TCHAR name[64];
543 //                      sprintf(name, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
544                         _stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
545                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_disk_path[drv][i], config_path);
546                 }
547         }
548 #endif
549 #ifdef USE_QD1
550         WritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quickdisk_dir, config_path);
551         for(drv = 0; drv < MAX_QD; drv++) {
552                 for(i = 0; i < MAX_HISTORY; i++) {
553                         _TCHAR name[64];
554                         _stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
555 //                      sprintf(name, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
556                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_quickdisk_path[drv][i], config_path);
557                 }
558         }
559 #endif
560 #ifdef USE_TAPE
561         WritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
562         for(i = 0; i < MAX_HISTORY; i++) {
563                 _TCHAR name[64];
564 //              sprintf(name, _T("RecentTapePath1_%d"), i + 1);
565                 _stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
566                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_tape_path[i], config_path);
567         }
568 #endif
569 #ifdef USE_LASER_DISC
570         WritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
571         for(int i = 0; i < MAX_HISTORY; i++) {
572                 _TCHAR name[64];
573 //              sprintf(name, _T("RecentLaserDiscPath1_%d"), i + 1);
574                 _stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
575                 WritePrivateProfileString(_T("RecentFiles"), name, config.recent_laser_disc_path[i], config_path);
576         }
577 #endif
578 #ifdef USE_BINARY_FILE1
579         WritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
580         for(drv = 0; drv < MAX_BINARY; drv++) {
581                 for(i = 0; i < MAX_HISTORY; i++) {
582                         _TCHAR name[64];
583 //                      sprintf(name, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
584                         _stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
585                         WritePrivateProfileString(_T("RecentFiles"), name, config.recent_binary_path[drv][i], config_path);
586                 }
587         }
588 #endif
589         
590         // screen
591 #if !(defined(USE_BITMAP) || defined(USE_LED))
592         WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
593         WritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
594         WritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
595         WritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
596 #else
597         WritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
598 #endif
599 #ifdef USE_MONITOR_TYPE
600         WritePrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
601 #endif
602 #ifdef USE_CRT_FILTER
603         WritePrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
604 #endif
605 #ifdef USE_SCANLINE
606         WritePrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
607 #endif
608 #ifdef USE_SCREEN_ROTATE
609         WritePrivateProfileBool(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
610 #endif
611 #if defined(USE_QT)
612         WritePrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"),
613                                                         config.use_opengl_scanline, config_path);
614         WritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"),
615                                                         config.opengl_scanline_vert, config_path);;
616         WritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"),
617                                                         config.opengl_scanline_horiz, config_path);;
618         WritePrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"),
619                                                         config.use_opengl_filters, config_path);
620         WritePrivateProfileInt(_T("Screen"), _T("OpenGlFilterNum"),
621                                                    config.opengl_filter_num, config_path);
622 #endif  
623         
624         // sound
625         WritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
626         WritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
627 #ifdef USE_SOUND_DEVICE_TYPE
628         WritePrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
629 #endif
630         WritePrivateProfileBool(_T("Sound"), _T("MultipleSpeakers"),
631                                                         config.multiple_speakers, config_path);
632         WritePrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
633                                                    config.general_sound_level, config_path);
634 #ifdef USE_MULTIPLE_SOUNDCARDS
635         {
636                 _TCHAR _tag[128];
637                 int ii;
638                 for(ii = 0; ii < USE_MULTIPLE_SOUNDCARDS; ii++) {
639                         memset(_tag, 0x00, sizeof(_tag));
640                         _stprintf_s(_tag, 64, _T("DeviceVolumeLevel_%d"), ii + 1);
641                         WritePrivateProfileBool(_T("Sound"), _tag, config.sound_device_level[ii], config_path);
642                 }
643         }
644 #endif
645 #if defined(_USE_AGAR) || defined(_USE_QT)
646         config_path->Fclose();
647         delete config_path;
648         AGAR_DebugLog(AGAR_LOG_INFO, "Write done.");
649 #endif
650
651 }
652
653 #define STATE_VERSION   1
654
655 void save_config_state(void *f)
656 {
657         FILEIO *state_fio = (FILEIO *)f;
658         int drv;
659         
660         state_fio->FputUint32(STATE_VERSION);
661         
662 #ifdef USE_BOOT_MODE
663         state_fio->FputInt32(config.boot_mode);
664 #endif
665 #ifdef USE_CPU_TYPE
666         state_fio->FputInt32(config.cpu_type);
667 #endif
668 #ifdef USE_DIPSWITCH
669         state_fio->FputUint32(config.dipswitch);
670 #endif
671 #ifdef USE_DEVICE_TYPE
672         state_fio->FputInt32(config.device_type);
673 #endif
674 #ifdef USE_DRIVE_TYPE
675         state_fio->FputInt32(config.drive_type);
676 #endif
677 #ifdef USE_FD1
678         for(drv = 0; drv < 8; drv++) state_fio->FputBool(config.ignore_crc[drv]);
679 #endif
680 #ifdef USE_MONITOR_TYPE
681         state_fio->FputInt32(config.monitor_type);
682 #endif
683 #ifdef USE_SOUND_DEVICE_TYPE
684         state_fio->FputInt32(config.sound_device_type);
685 #endif
686 }
687
688 bool load_config_state(void *f)
689 {
690         FILEIO *state_fio = (FILEIO *)f;
691         int drv;
692         
693         if(state_fio->FgetUint32() != STATE_VERSION) {
694                 return false;
695         }
696 #ifdef USE_BOOT_MODE
697         config.boot_mode = state_fio->FgetInt32();
698 #endif
699 #ifdef USE_CPU_TYPE
700         config.cpu_type = state_fio->FgetInt32();
701 #endif
702 #ifdef USE_DIPSWITCH
703         config.dipswitch = state_fio->FgetUint32();
704 #endif
705 #ifdef USE_DEVICE_TYPE
706         config.device_type = state_fio->FgetInt32();
707 #endif
708 #ifdef USE_DRIVE_TYPE
709         config.drive_type = state_fio->FgetInt32();
710 #endif
711 #ifdef USE_FD1
712         for(drv = 0; drv < 8; drv++) config.ignore_crc[drv] = state_fio->FgetBool();
713 #endif
714 #ifdef USE_MONITOR_TYPE
715         config.monitor_type = state_fio->FgetInt32();
716 #endif
717 #ifdef USE_SOUND_DEVICE_TYPE
718         config.sound_device_type = state_fio->FgetInt32();
719 #endif
720         return true;
721 }
722