OSDN Git Service

9b53ee2afaad037145159ca554d756d2e57d450a
[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.general_sound_level = 0;
112 #if defined(USE_SOUND_DEVICE_TYPE) && defined(SOUND_DEVICE_TYPE_DEFAULT)
113         config.sound_device_type = SOUND_DEVICE_TYPE_DEFAULT;
114 #elif defined(USE_SOUND_DEVICE_TYPE)
115         config.sound_device_type = 0;
116 #endif
117         
118         // input
119 #ifdef _WIN32
120         config.use_direct_input = true;
121         config.disable_dwm = false;
122 #endif
123         config.keyboard_type = 0;
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 }
153
154 void load_config(const _TCHAR *config_path)
155 {
156         int drv, i;
157         // initial settings
158         init_config();
159
160         // control
161 #ifdef USE_BOOT_MODE
162         config.boot_mode = MyGetPrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
163 #endif
164 #ifdef USE_CPU_TYPE
165         config.cpu_type = MyGetPrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
166 #endif
167 #ifdef USE_DIPSWITCH
168         config.dipswitch = MyGetPrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
169 #endif
170 #ifdef USE_DEVICE_TYPE
171         config.device_type = MyGetPrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
172 #endif
173 #ifdef USE_DRIVE_TYPE
174         config.drive_type = MyGetPrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
175 #endif
176 #ifdef USE_FD1
177         {
178                 _TCHAR name[64];
179                 for(drv = 0; drv < MAX_FD; drv++) {
180                         memset(name, 0x00, sizeof(name));
181                         my_stprintf_s(name, 64, _T("CorrectDiskTiming%d"), drv + 1);
182                         config.correct_disk_timing[drv] = MyGetPrivateProfileBool(_T("Control"), (const _TCHAR *)name,
183                                                                                                                                         config.correct_disk_timing[drv], config_path);
184                         my_stprintf_s(name, 64, _T("IgnoreDiskCRC%d"), drv + 1);
185                         config.ignore_disk_crc[drv] = MyGetPrivateProfileBool(_T("Control"), (const _TCHAR *)name,
186                                                                                                                                 config.ignore_disk_crc[drv], config_path);
187                 }
188         }
189 #endif
190
191 #ifdef USE_TAPE
192         config.tape_sound = MyGetPrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
193         config.wave_shaper = MyGetPrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
194         config.direct_load_mzt = MyGetPrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
195         config.baud_high = MyGetPrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
196 #endif
197         
198         // recent files
199 #ifdef USE_CART1
200         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
201         for(drv = 0; drv < MAX_CART; drv++) {
202                 for(i = 0; i < MAX_HISTORY; i++) {
203                         _TCHAR name[64];
204                         my_stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
205                         MyGetPrivateProfileString(_T("RecentFiles"), name, _T(""),
206                                                                         config.recent_cart_path[drv][i], _MAX_PATH, config_path);
207                 }
208         }
209 #endif
210 #ifdef USE_FD1
211         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""),
212                                                         config.initial_disk_dir, _MAX_PATH, config_path);
213     //    get_parent_dir(config.initial_disk_dir);
214         for(drv = 0; drv < MAX_FD; drv++) {
215                 for(i = 0; i < MAX_HISTORY; i++) {
216                         _TCHAR name[64];
217                         my_stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
218                         MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
219                                                                         _T(""), config.recent_disk_path[drv][i], _MAX_PATH, config_path);
220                 }
221         }
222 #endif
223 #ifdef USE_QD1
224         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"),
225                                                         _T(""), config.initial_quickdisk_dir, _MAX_PATH, config_path);
226         for(drv = 0; drv < MAX_QD; drv++) {
227                 for(i = 0; i < MAX_HISTORY; i++) {
228                         _TCHAR name[64];
229                         my_stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
230                         MyGetPrivateProfileString(_T("RecentFiles"), name, _T(""),
231                                                                         config.recent_quickdisk_path[drv][i], _MAX_PATH, config_path);
232                 }
233         }
234 #endif
235
236 #ifdef USE_TAPE
237         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""),
238                                                         config.initial_tape_dir, _MAX_PATH, config_path);
239         for(i = 0; i < MAX_HISTORY; i++) {
240                 _TCHAR name[64];
241                 my_stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
242                 MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
243                                                                 config.recent_tape_path[i], _MAX_PATH, config_path);
244         }
245 #endif
246
247 #ifdef USE_LASER_DISC
248         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""),
249                                                         config.initial_laser_disc_dir, _MAX_PATH, config_path);
250         for(int i = 0; i < MAX_HISTORY; i++) {
251                 _TCHAR name[64];
252                 my_stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
253                 MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
254                                                                 config.recent_laser_disc_path[i], _MAX_PATH, config_path);
255         }
256 #endif
257 #ifdef USE_BINARY_FILE1
258         MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""),
259                                                         config.initial_binary_dir, _MAX_PATH, config_path);
260         for(drv = 0; drv < MAX_BINARY; drv++) {
261                 for(i = 0; i < MAX_HISTORY; i++) {
262                         _TCHAR name[64];
263                         my_stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
264                         MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
265                                                                         config.recent_binary_path[drv][i], _MAX_PATH, config_path);
266                 }
267         }
268 #endif
269         
270         // screen
271 #ifndef ONE_BOARD_MICRO_COMPUTER
272         config.window_mode = MyGetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
273 #ifdef _WIN32
274         config.use_d3d9 = MyGetPrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
275         config.wait_vsync = MyGetPrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
276 #endif
277         config.stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
278 #else
279         config.window_mode = MyGetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
280 #endif
281 #ifdef USE_MONITOR_TYPE
282         config.monitor_type = MyGetPrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
283 #endif
284 #ifdef USE_CRT_FILTER
285         config.crt_filter = MyGetPrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
286 #endif
287 #ifdef USE_SCANLINE
288         config.scan_line = MyGetPrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
289 #endif
290
291 #ifdef USE_SCREEN_ROTATE
292         config.rotate_type = MyGetPrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
293 #endif
294 #if defined(_USE_QT)
295         config.use_opengl_scanline = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"),
296                                                                                                            config.use_opengl_scanline, config_path);
297         config.opengl_scanline_vert = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"),
298                                                                                                            config.opengl_scanline_vert, config_path);;
299         config.opengl_scanline_horiz = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"),
300                                                                                                            config.opengl_scanline_horiz, config_path);;
301         config.use_opengl_filters = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"),
302                                                                                                            config.use_opengl_filters, config_path);
303         config.opengl_filter_num =      MyGetPrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"),
304                                                                                                          config.opengl_filter_num, config_path);
305 #endif  
306         // sound
307         config.sound_frequency = MyGetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
308         config.sound_latency = MyGetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
309 #ifdef USE_SOUND_DEVICE_TYPE
310         config.sound_device_type = MyGetPrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
311 #endif
312 #ifdef USE_SOUND_VOLUME
313         for(int i = 0; i < USE_SOUND_VOLUME; i++) {
314                 _TCHAR name[64];
315                 my_stprintf_s(name, 64, _T("VolumeLeft%d"), i + 1);
316                 int tmp_l = MyGetPrivateProfileInt(_T("Sound"), name, config.sound_volume_l[i], config_path);
317                 my_stprintf_s(name, 64, _T("VolumeRight%d"), i + 1);
318                 int tmp_r = MyGetPrivateProfileInt(_T("Sound"), name, config.sound_volume_r[i], config_path);
319                 config.sound_volume_l[i] = max(-40, min(0, tmp_l));
320                 config.sound_volume_r[i] = max(-40, min(0, tmp_r));
321         }
322 #endif
323 #if !defined(_USE_QT)
324         MyGetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
325 #endif  
326         // input
327         config.general_sound_level = MyGetPrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
328                                                                                                           config.general_sound_level, config_path);
329 #ifdef _WIN32
330         config.use_direct_input = MyGetPrivateProfileBool(_T("Input"), _T("UseDirectInput"), config.use_direct_input, config_path);
331         config.disable_dwm = MyGetPrivateProfileBool(_T("Input"), _T("DisableDwm"), config.disable_dwm, config_path);
332 #endif
333         config.keyboard_type = MyGetPrivateProfileInt(_T("Input"), _T("KeyboardType"), config.keyboard_type, config_path);
334         for(int i = 0; i < 4; i++) {
335                 for(int j = 0; j < 16; j++) {
336                         _TCHAR name[64];
337                         my_stprintf_s(name, 64, _T("JoyButtons%d_%d"), i + 1, j + 1);
338                         config.joy_buttons[i][j] = MyGetPrivateProfileInt(_T("Input"), name, config.joy_buttons[i][j], config_path);
339                 }
340         }
341 #if defined(_USE_QT)
342         for(i = 0; i < 16; i++) {
343                 _TCHAR name[256];
344                 my_stprintf_s(name, 256, _T("AssignedJoystick"), i + 1);
345                 MyGetPrivateProfileString(_T("Input"), (const _TCHAR *)name, _T(""),
346                                                                   config.assigned_joystick_name[i], 256, config_path);
347         }
348 #endif  
349         // printer
350 #ifdef USE_PRINTER
351         config.printer_device_type = MyGetPrivateProfileInt(_T("Printer"), _T("DeviceType"), config.printer_device_type, config_path);
352         MyGetPrivateProfileString(_T("Printer"), _T("PrinterDll"), _T("printer.dll"), config.printer_dll_path, _MAX_PATH, config_path);
353 #endif
354 #if defined(_USE_QT) && !defined(Q_OS_WIN)
355         AGAR_DebugLog(AGAR_LOG_INFO, "Read Done.");
356 #endif
357 }
358
359 void save_config(const _TCHAR *config_path)
360 {
361         int drv, i;
362 #if !defined(_MSC_VER)
363         {
364                 FILEIO *pt = new FILEIO;
365                 if(pt->Fopen(config_path, FILEIO_WRITE_ASCII) != true) {
366                         delete pt;
367                         return;
368                 }
369                 pt->Fclose();
370                 delete pt;
371         }
372         
373 #endif  
374         // control
375 # ifdef USE_BOOT_MODE
376         MyWritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
377 #endif
378 #ifdef USE_CPU_TYPE
379         MyWritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
380 #endif
381 #ifdef USE_DIPSWITCH
382         MyWritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
383 #endif
384 #ifdef USE_DEVICE_TYPE
385         MyWritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
386 #endif
387 #ifdef USE_DRIVE_TYPE
388         MyWritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
389 #endif
390 #ifdef USE_FD1
391         {
392                 _TCHAR name[64];
393                 for(drv = 0; drv < MAX_FD; drv++) {
394                         memset(name, 0x00, sizeof(name));
395                         my_stprintf_s(name, 64, _T("CorrectDiskTiming%d"), drv + 1);
396                         MyWritePrivateProfileBool(_T("Control"), (const _TCHAR *)name, config.correct_disk_timing[drv], config_path);
397                         my_stprintf_s(name, 64, _T("IgnoreDiskCRC%d"), drv + 1);
398                         MyWritePrivateProfileBool(_T("Control"), (const _TCHAR *)name, config.ignore_disk_crc[drv], config_path);
399                 }
400         }
401
402 #endif
403 #ifdef USE_TAPE
404         MyWritePrivateProfileBool(_T("Control"), _T("TapeSound"), config.tape_sound, config_path);
405         MyWritePrivateProfileBool(_T("Control"), _T("WaveShaper"), config.wave_shaper, config_path);
406         MyWritePrivateProfileBool(_T("Control"), _T("DirectLoadMZT"), config.direct_load_mzt, config_path);
407         MyWritePrivateProfileBool(_T("Control"), _T("BaudHigh"), config.baud_high, config_path);
408 #endif
409         
410         // recent files
411 #ifdef USE_CART1
412         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
413         for(drv = 0; drv < MAX_CART; drv++) {
414                 for(i = 0; i < MAX_HISTORY; i++) {
415                         _TCHAR name[64];
416                         my_stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
417                         MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, config.recent_cart_path[drv][i], config_path);
418                 }
419         }
420 #endif
421 #ifdef USE_FD1
422         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
423         for(drv = 0; drv < MAX_FD; drv++) {
424                 for(i = 0; i < MAX_HISTORY; i++) {
425                         _TCHAR name[64];
426                         my_stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
427                         MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
428                                                                           config.recent_disk_path[drv][i], config_path);
429                 }
430         }
431 #endif
432 #ifdef USE_QD1
433         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"),
434                                                           config.initial_quickdisk_dir, config_path);
435         for(drv = 0; drv < MAX_QD; drv++) {
436                 for(i = 0; i < MAX_HISTORY; i++) {
437                         _TCHAR name[64];
438                         my_stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
439                         MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
440                                                                           config.recent_quickdisk_path[drv][i], config_path);
441                 }
442         }
443 #endif
444 #ifdef USE_TAPE
445         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
446         for(i = 0; i < MAX_HISTORY; i++) {
447                 _TCHAR name[64];
448                 my_stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
449                 MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
450                                                                   config.recent_tape_path[i], config_path);
451         }
452 #endif
453 #ifdef USE_LASER_DISC
454         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
455         for(int i = 0; i < MAX_HISTORY; i++) {
456                 _TCHAR name[64];
457                 my_stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
458                 MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
459                                                                   config.recent_laser_disc_path[i], config_path);
460         }
461 #endif
462 #ifdef USE_BINARY_FILE1
463         MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
464         for(drv = 0; drv < MAX_BINARY; drv++) {
465                 for(i = 0; i < MAX_HISTORY; i++) {
466                         _TCHAR name[64];
467                         my_stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
468                         MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
469                                                                           config.recent_binary_path[drv][i], config_path);
470                 }
471         }
472 #endif
473         
474         // screen
475 #ifndef ONE_BOARD_MICRO_COMPUTER
476         MyWritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
477 #ifdef _WIN32
478         MyWritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
479         MyWritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
480 #endif
481         MyWritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
482 #else
483         MyWritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
484 #endif
485 #ifdef USE_MONITOR_TYPE
486         MyWritePrivateProfileInt(_T("Screen"), _T("MonitorType"), config.monitor_type, config_path);
487 #endif
488 #ifdef USE_CRT_FILTER
489         MyWritePrivateProfileBool(_T("Screen"), _T("CRTFilter"), config.crt_filter, config_path);
490 #endif
491 #ifdef USE_SCANLINE
492         MyWritePrivateProfileBool(_T("Screen"), _T("ScanLine"), config.scan_line, config_path);
493 #endif
494 #ifdef USE_SCREEN_ROTATE
495         MyWritePrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
496 #endif
497 #if defined(_USE_QT)
498         MyWritePrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"),
499                                                         config.use_opengl_scanline, config_path);
500         MyWritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"),
501                                                         config.opengl_scanline_vert, config_path);;
502         MyWritePrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"),
503                                                         config.opengl_scanline_horiz, config_path);;
504         MyWritePrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"),
505                                                         config.use_opengl_filters, config_path);
506         MyWritePrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"),
507                                                    config.opengl_filter_num, config_path);
508 #endif  
509         
510         // sound
511         MyWritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
512         MyWritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
513 #ifdef USE_SOUND_DEVICE_TYPE
514         MyWritePrivateProfileInt(_T("Sound"), _T("DeviceType"), config.sound_device_type, config_path);
515 #endif
516 #ifdef USE_SOUND_VOLUME
517         for(int i = 0; i < USE_SOUND_VOLUME; i++) {
518                 _TCHAR name[64];
519                 my_stprintf_s(name, 64, _T("VolumeLeft%d"), i + 1);
520                 MyWritePrivateProfileInt(_T("Sound"), name, config.sound_volume_l[i], config_path);
521                 my_stprintf_s(name, 64, _T("VolumeRight%d"), i + 1);
522                 MyWritePrivateProfileInt(_T("Sound"), name, config.sound_volume_r[i], config_path);
523         }
524 #endif
525 #if !defined(_USE_QT)
526         MyWritePrivateProfileString(_T("Sound"), _T("FMGenDll"), config.fmgen_dll_path, config_path);
527 #endif  
528         MyWritePrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
529                                                    config.general_sound_level, config_path);
530         // input
531 #ifdef _WIN32
532         MyWritePrivateProfileBool(_T("Input"), _T("UseDirectInput"), config.use_direct_input, config_path);
533         MyWritePrivateProfileBool(_T("Input"), _T("DisableDwm"), config.disable_dwm, config_path);
534 #endif
535         MyWritePrivateProfileInt(_T("Input"), _T("KeyboardType"), config.keyboard_type, config_path);
536         for(int i = 0; i < 4; i++) {
537                 for(int j = 0; j < 16; j++) {
538                         _TCHAR name[64];
539                         my_stprintf_s(name, 64, _T("JoyButtons%d_%d"), i + 1, j + 1);
540                         MyWritePrivateProfileInt(_T("Input"), name, config.joy_buttons[i][j], config_path);
541                 }
542         }
543 #if defined(_USE_QT)
544         for(i = 0; i < 16; i++) {
545                 _TCHAR name[256];
546                 my_stprintf_s(name, 256, _T("AssignedJoystick%d"), i + 1);
547                 MyWritePrivateProfileString(_T("Input"), (const _TCHAR *)name, 
548                                                                         config.assigned_joystick_name[i], config_path);
549         }
550 #endif  
551         
552         // printer
553 #ifdef USE_PRINTER
554         MyWritePrivateProfileInt(_T("Printer"), _T("DeviceType"), config.printer_device_type, config_path);
555 #endif
556 #if defined(_USE_QT) && !defined(Q_OS_WIN)
557         AGAR_DebugLog(AGAR_LOG_INFO, "Write done.");
558 #endif
559 }
560
561 #define STATE_VERSION   5
562
563 void save_config_state(void *f)
564 {
565         FILEIO *state_fio = (FILEIO *)f;
566         int drv;
567         
568         state_fio->FputUint32(STATE_VERSION);
569         
570 #ifdef USE_BOOT_MODE
571         state_fio->FputInt32(config.boot_mode);
572 #endif
573 #ifdef USE_CPU_TYPE
574         state_fio->FputInt32(config.cpu_type);
575 #endif
576 #ifdef USE_DIPSWITCH
577         state_fio->FputUint32(config.dipswitch);
578 #endif
579 #ifdef USE_DEVICE_TYPE
580         state_fio->FputInt32(config.device_type);
581 #endif
582 #ifdef USE_DRIVE_TYPE
583         state_fio->FputInt32(config.drive_type);
584 #endif
585 #ifdef USE_FD1
586         for(int drv = 0; drv < MAX_FD; drv++) {
587                 state_fio->FputBool(config.correct_disk_timing[drv]);
588                 state_fio->FputBool(config.ignore_disk_crc[drv]);
589         }
590 //      for(int drv = 0; drv < MAX_FD; drv++) {
591 //              state_fio->FputBool(config.fdd_hack_fast_transfer[drv]);
592 //      }
593 #endif
594 #ifdef USE_MONITOR_TYPE
595         state_fio->FputInt32(config.monitor_type);
596 #endif
597 #ifdef USE_SOUND_DEVICE_TYPE
598         state_fio->FputInt32(config.sound_device_type);
599 #endif
600 #ifdef USE_PRINTER
601         state_fio->FputInt32(config.printer_device_type);
602 #endif
603         state_fio->FputInt32(config.keyboard_type);
604 }
605
606 bool load_config_state(void *f)
607 {
608         FILEIO *state_fio = (FILEIO *)f;
609         
610         if(state_fio->FgetUint32() != STATE_VERSION) {
611                 return false;
612         }
613 #ifdef USE_BOOT_MODE
614         config.boot_mode = state_fio->FgetInt32();
615 #endif
616 #ifdef USE_CPU_TYPE
617         config.cpu_type = state_fio->FgetInt32();
618 #endif
619 #ifdef USE_DIPSWITCH
620         config.dipswitch = state_fio->FgetUint32();
621 #endif
622 #ifdef USE_DEVICE_TYPE
623         config.device_type = state_fio->FgetInt32();
624 #endif
625 #ifdef USE_DRIVE_TYPE
626         config.drive_type = state_fio->FgetInt32();
627 #endif
628 #ifdef USE_FD1
629         for(int drv = 0; drv < MAX_FD; drv++) {
630                 config.correct_disk_timing[drv] = state_fio->FgetBool();
631                 config.ignore_disk_crc[drv] = state_fio->FgetBool();
632         }
633 //      for(int drv = 0; drv < MAX_FD; drv++) {
634 //              config.fdd_hack_fast_transfer[drv] = state_fio->FgetBool();
635 //      }
636 #endif
637 #ifdef USE_MONITOR_TYPE
638         config.monitor_type = state_fio->FgetInt32();
639 #endif
640 #ifdef USE_SOUND_DEVICE_TYPE
641         config.sound_device_type = state_fio->FgetInt32();
642 #endif
643 #ifdef USE_PRINTER
644         config.printer_device_type = state_fio->FgetInt32();
645 #endif
646         config.keyboard_type = state_fio->FgetInt32();
647         return true;
648 }
649