OSDN Git Service

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