OSDN Git Service

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