OSDN Git Service

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