OSDN Git Service

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