OSDN Git Service

c9e44d8f4fa4433052aa306d137f842bc168a7fe
[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_QT)
10 #include <string>
11 #include <vector>
12 #include "fileio.h"
13 #include "csp_logger.h"
14 #include "qt_main.h"
15 # if defined(Q_OS_WIN)
16 # include <windows.h>
17 # endif
18
19 extern CSP_Logger *csp_logger;
20 #endif
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include "common.h"
25 #include "config.h"
26 #include "fileio.h"
27 #if defined(_USE_AGAR)
28 #include "agar_main.h"
29 #endif
30
31 config_t config;
32
33 #ifndef CONFIG_NAME
34 #define CONFIG_NAME "conf"
35 #endif
36
37 BOOL MyWritePrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, int Value, LPCTSTR lpFileName)
38 {
39         return MyWritePrivateProfileString(lpAppName, lpKeyName, create_string(_T("%d"), Value), lpFileName);
40 }
41  
42 BOOL MyWritePrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool Value, LPCTSTR lpFileName)
43 {
44         return MyWritePrivateProfileString(lpAppName, lpKeyName, create_string(_T("%d"), Value ? 1 : 0), lpFileName);
45 }
46  
47 bool MyGetPrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool bDefault, LPCTSTR lpFileName)
48 {
49         return (MyGetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
50 }
51
52 void initialize_config()
53 {
54         // initial settings
55         memset(&config, 0, sizeof(config_t));
56         config.window_mode = 1; 
57         // memo: set only non zero value
58         config.full_speed = false;      
59         
60         // control
61         #if defined(USE_BOOT_MODE) && defined(BOOT_MODE_DEFAULT)
62                 config.boot_mode = BOOT_MODE_DEFAULT;
63         #endif
64         #if defined(USE_CPU_TYPE) && defined(CPU_TYPE_DEFAULT)
65                 config.cpu_type = CPU_TYPE_DEFAULT;
66         #endif
67         #if defined(USE_DIPSWITCH) && defined(DIPSWITCH_DEFAULT)
68                 config.dipswitch = DIPSWITCH_DEFAULT;
69         #endif
70         #if defined(USE_DEVICE_TYPE) && defined(DEVICE_TYPE_DEFAULT)
71                 config.device_type = DEVICE_TYPE_DEFAULT;
72         #endif
73         #if defined(USE_DRIVE_TYPE) && defined(DRIVE_TYPE_DEFAULT)
74                 config.drive_type = DRIVE_TYPE_DEFAULT;
75         #endif
76         #if defined(USE_KEYBOARD_TYPE) && defined(KEYBOARD_TYPE_DEFAULT)
77                 config.keyboard_type = KEYBOARD_TYPE_DEFAULT;
78         #endif
79         #if defined(USE_MOUSE_TYPE) && defined(MOUSE_TYPE_DEFAULT)
80                 config.mouse_type = MOUSE_TYPE_DEFAULT;
81         #endif
82         #if defined(USE_JOYSTICK_TYPE) && defined(JOYSTICK_TYPE_DEFAULT)
83                 config.joystick_type = JOYSTICK_TYPE_DEFAULT;
84         #endif
85         #if defined(USE_SOUND_TYPE) && defined(SOUND_TYPE_DEFAULT)
86                 config.sound_type = SOUND_TYPE_DEFAULT;
87         #endif
88         #if defined(USE_MONITOR_TYPE) && defined(MONITOR_TYPE_DEFAULT)
89                 config.monitor_type = MONITOR_TYPE_DEFAULT;
90         #endif
91         #if defined(USE_PRINTER_TYPE) && defined(PRINTER_TYPE_DEFAULT)
92                 config.printer_type = PRINTER_TYPE_DEFAULT;
93         #endif
94         #if defined(USE_FLOPPY_DISK)
95                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
96                         #if defined(CORRECT_DISK_TIMING_DEFAULT)
97                                 config.correct_disk_timing[drv] = CORRECT_DISK_TIMING_DEFAULT;
98                         #else
99                                 config.correct_disk_timing[drv] = false;
100                         #endif
101                         #if defined(IGNORE_DISK_CRC_DEFAULT)
102                                 config.ignore_disk_crc[drv] = IGNORE_DISK_CRC_DEFAULT;
103                         #else
104                                 config.ignore_disk_crc[drv] = false;
105                         #endif
106                 }
107         #endif
108         #if defined(USE_TAPE)
109                 for(int drv = 0; drv < USE_TAPE; drv++) {
110                         config.wave_shaper[drv] = true;
111                         config.direct_load_mzt[drv] = true;
112                         config.baud_high[drv] = true;
113                 }
114         #endif
115         config.compress_state = true;
116         
117         // screen
118         #ifndef ONE_BOARD_MICRO_COMPUTER
119                 config.fullscreen_stretch_type = 1;     // Stretch (Aspect)
120         #endif
121
122         // sound
123         #ifdef SOUND_RATE_DEFAULT
124                 config.sound_frequency = SOUND_RATE_DEFAULT;
125         #else
126                 config.sound_frequency = 6;     // 48KHz
127         #endif
128                 config.sound_latency = 1;       // 100msec
129                 config.sound_strict_rendering = true;
130         #ifdef USE_FLOPPY_DISK
131                 config.sound_noise_fdd = true;
132         #endif
133         #ifdef USE_TAPE
134                 config.sound_noise_cmt = true;
135                 config.sound_play_tape = true;
136         #endif
137         // input
138         #ifdef USE_JOYSTICK
139                 for(int i = 0; i < 4; i++) {
140                         for(int j = 0; j < 16; j++) {
141                                 config.joy_buttons[i][j] = (i << 4) | j;
142                         }
143                 }
144         #endif
145         // debug
146         config.special_debug_fdc = false;
147         config.print_statistics = false;
148         
149         // win32
150         #if defined(_WIN32) && !defined(_USE_QT)
151                 #ifndef ONE_BOARD_MICRO_COMPUTER
152                         config.use_d3d9 = true;
153                 #endif
154                 config.use_dinput = true;
155                 config.show_status_bar = true;
156         #endif
157         
158         // qt
159         #ifdef _USE_QT
160                 config.use_separate_thread_draw = true;
161                 config.use_osd_virtual_media = true;            
162                 config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_ES;
163                 config.render_major_version = 2; // For crash with some devices.
164                 config.render_minor_version = 0;
165                 config.rendering_type = CONFIG_RENDER_TYPE_STD;
166                 
167                 config.use_opengl_scanline = false;
168                 config.opengl_scanline_vert = false;
169                 config.opengl_scanline_horiz = false;
170                 config.use_opengl_filters = false;
171                 config.opengl_filter_num = 0;
172                 config.focus_with_click = false;
173                 
174                 config.video_width = 640;
175                 config.video_height = 480;
176                 config.video_codec_type = 0; // MPEG4
177         
178                 config.video_h264_bitrate = 512;
179                 config.video_h264_bframes = 4;
180                 config.video_h264_b_adapt = 2;
181                 config.video_h264_minq = 14;
182                 config.video_h264_maxq = 25;
183                 config.video_h264_subme = 8;
184                 
185                 config.video_mpeg4_bitrate = 512;
186                 config.video_mpeg4_bframes = 4;
187                 config.video_mpeg4_minq = 1;
188                 config.video_mpeg4_maxq = 20;
189                 
190                 config.audio_codec_type = 0;
191                 config.video_threads = 0;
192                 config.audio_bitrate = 160;
193                 config.video_frame_rate = 30;
194                 config.log_to_syslog = false;
195                 config.log_to_console = true;
196                 for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; ii++) {
197                         for(int jj = 0; jj < 8; jj++) {
198                                 config.dev_log_to_syslog[ii][jj] = true;
199                                 config.dev_log_to_console[ii][jj] = true;
200                                 config.dev_log_recording[ii][jj] = true;
201                         }
202                 }
203                 config.state_log_to_console = false;
204                 config.state_log_to_syslog = false;
205                 config.state_log_to_recording = false; 
206                 
207                 config.rendering_type = CONFIG_RENDER_TYPE_STD;
208                 config.virtual_media_position = 2; // Down.
209                 for(int drv = 0; drv < 16; drv++) {
210                         config.disk_count_immediate[drv] = false;
211                 }
212                 // Extra UI
213                 config.cursor_as_ten_key = CONFIG_CURSOR_AS_CURSOR;
214         #if defined(_FM7) || defined(_FMNEW7) || defined(_FM8) \
215             || defined(_FM77_VARIANTS) || defined(_FM77AV_VARIANTS)             
216                 config.numpad_enter_as_fullkey = false;
217         #else
218                 config.numpad_enter_as_fullkey = true;
219         #endif
220                 config.host_keyboard_type = CONFIG_HOST_KEYBOARD_AT_109JP;
221 #endif  
222 }
223
224 void load_config(const _TCHAR *config_path)
225 {
226         int drv, i;
227         // initial settings
228         initialize_config();
229         
230         // control
231         #ifdef USE_BOOT_MODE
232                 config.boot_mode = MyGetPrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
233         #endif
234         #ifdef USE_CPU_TYPE
235                 config.cpu_type = MyGetPrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
236         #endif
237         #ifdef USE_DIPSWITCH
238                 config.dipswitch = MyGetPrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
239         #endif
240         #ifdef USE_DEVICE_TYPE
241                 config.device_type = MyGetPrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
242         #endif
243         #ifdef USE_DRIVE_TYPE
244                 config.drive_type = MyGetPrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
245         #endif
246         #ifdef USE_KEYBOARD_TYPE
247                 config.keyboard_type = MyGetPrivateProfileInt(_T("Control"), _T("KeyboardType"), config.keyboard_type, config_path);
248         #endif
249         #ifdef USE_MOUSE_TYPE
250                 config.mouse_type = MyGetPrivateProfileInt(_T("Control"), _T("MouseType"), config.mouse_type, config_path);
251         #endif
252         #ifdef USE_JOYSTICK_TYPE
253                 config.joystick_type = MyGetPrivateProfileInt(_T("Control"), _T("JoystickType"), config.joystick_type, config_path);
254         #endif
255         #ifdef USE_SOUND_TYPE
256                 config.sound_type = MyGetPrivateProfileInt(_T("Control"), _T("SoundType"), config.sound_type, config_path);
257         #endif
258         #ifdef USE_MONITOR_TYPE
259                 config.monitor_type = MyGetPrivateProfileInt(_T("Control"), _T("MonitorType"), config.monitor_type, config_path);
260         #endif
261         #ifdef USE_SCANLINE
262                 config.scan_line = MyGetPrivateProfileBool(_T("Control"), _T("ScanLine"), config.scan_line, config_path);
263         #endif
264         #ifdef USE_PRINTER
265                 config.printer_type = MyGetPrivateProfileInt(_T("Control"), _T("PrinterType"), config.printer_type, config_path);
266         #endif
267         #ifdef USE_FLOPPY_DISK
268                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
269                         config.correct_disk_timing[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("CorrectDiskTiming%d"), drv + 1), config.correct_disk_timing[drv], config_path);
270                         config.ignore_disk_crc[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("IgnoreDiskCRC%d"), drv + 1), config.ignore_disk_crc[drv], config_path);
271                 #ifdef _USE_QT
272                         config.disk_count_immediate[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("DiskIncrementImmediate%d"), drv + 1), config.disk_count_immediate[drv], config_path);
273                 #endif
274                 }
275         #endif
276         #ifdef USE_TAPE
277                 for(int drv = 0; drv < USE_TAPE; drv++) {
278                         config.wave_shaper[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("WaveShaper%d"), drv + 1), config.wave_shaper[drv], config_path);
279                         config.direct_load_mzt[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("DirectLoadMZT%d"), drv + 1), config.direct_load_mzt[drv], config_path);
280                         config.baud_high[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("BaudHigh%d"), drv + 1), config.baud_high[drv], config_path);
281                 }
282         #endif
283         config.compress_state = MyGetPrivateProfileBool(_T("Control"), _T("CompressState"), config.compress_state, config_path);                
284                 // recent files
285         #ifdef USE_CART
286                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
287                 for(int drv = 0; drv < USE_CART; drv++) {
288                         for(int i = 0; i < MAX_HISTORY; i++) {
289                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCartPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_cart_path[drv][i], _MAX_PATH, config_path);
290                         }
291                 }
292         #endif
293         #ifdef USE_FLOPPY_DISK
294                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""), config.initial_floppy_disk_dir, _MAX_PATH, config_path);
295                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
296                         for(int i = 0; i < MAX_HISTORY; i++) {
297                                 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);
298                         }
299                 }
300         #endif
301         #ifdef USE_QUICK_DISK
302                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), _T(""), config.initial_quick_disk_dir, _MAX_PATH, config_path);
303                 for(int drv = 0; drv < USE_QUICK_DISK; drv++) {
304                         for(int i = 0; i < MAX_HISTORY; i++) {
305                                 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);
306                         }
307                 }
308         #endif
309         #ifdef USE_HARD_DISK
310                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialHardDiskDir"), _T(""), config.initial_hard_disk_dir, _MAX_PATH, config_path);
311                 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
312                         for(int i = 0; i < MAX_HISTORY; i++) {
313                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentHardDiskPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_hard_disk_path[drv][i], _MAX_PATH, config_path);
314                         }
315                 }
316         #endif
317         #ifdef USE_TAPE
318                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""), config.initial_tape_dir, _MAX_PATH, config_path);
319                 for(int drv = 0; drv < USE_TAPE; drv++) {
320                         for(int i = 0; i < MAX_HISTORY; i++) {
321                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath%d_%d"), drv + 1, i + 1), _T(""), config.recent_tape_path[drv][i], _MAX_PATH, config_path);
322                         }
323                 }
324         #endif
325         #ifdef USE_COMPACT_DISC
326                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialCompactDiscDir"), _T(""), config.initial_compact_disc_dir, _MAX_PATH, config_path);
327                 for(int drv = 0; drv < USE_COMPACT_DISC; drv++) {
328                         for(int i = 0; i < MAX_HISTORY; i++) {
329                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCompactDiscPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_compact_disc_path[drv][i], _MAX_PATH, config_path);
330                         }
331                 }
332         #endif
333         #ifdef USE_LASER_DISC
334                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""), config.initial_laser_disc_dir, _MAX_PATH, config_path);
335                 for(int drv = 0; drv < USE_LASER_DISC; drv++) {
336                         for(int i = 0; i < MAX_HISTORY; i++) {
337                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentLaserDiscPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_laser_disc_path[drv][i], _MAX_PATH, config_path);
338                         }
339                 }
340         #endif
341         #ifdef USE_BINARY_FILE
342                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""), config.initial_binary_dir, _MAX_PATH, config_path);
343                 for(int drv = 0; drv < USE_BINARY_FILE; drv++) {
344                         for(int i = 0; i < MAX_HISTORY; i++) {
345                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBinaryPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_binary_path[drv][i], _MAX_PATH, config_path);
346                         }
347                 }
348         #endif
349         #ifdef USE_BUBBLE
350                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), _T(""), config.initial_bubble_casette_dir, _MAX_PATH, config_path);
351                 for(int drv = 0; drv < USE_BUBBLE; drv++) {
352                         for(int i = 0; i < MAX_HISTORY; i++) {
353                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBubblePath%d_%d"), drv + 1, i + 1), _T(""), config.recent_bubble_casette_path[drv][i], _MAX_PATH, config_path);
354                         }
355                 }
356         #endif
357         
358         // screen
359         #ifndef ONE_BOARD_MICRO_COMPUTER
360                 config.window_mode = MyGetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
361                 config.window_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
362                 config.fullscreen_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
363 //              #ifdef USE_SCREEN_ROTATE
364                         config.rotate_type = MyGetPrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
365 //              #endif
366         #endif
367
368         
369         // filter
370         #ifdef USE_SCREEN_FILTER
371                 config.filter_type = MyGetPrivateProfileInt(_T("Screen"), _T("FilterType"), config.filter_type, config_path);
372         #endif
373
374         // sound
375         config.sound_frequency = MyGetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
376         config.sound_latency = MyGetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
377         config.sound_strict_rendering = MyGetPrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
378         #ifdef USE_FLOPPY_DISK
379                 config.sound_noise_fdd = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);;
380         #endif
381         #ifdef USE_TAPE
382                 config.sound_noise_cmt = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseCMT"), config.sound_noise_cmt, config_path);;
383                 config.sound_play_tape = MyGetPrivateProfileBool(_T("Sound"), _T("PlayTape"), config.sound_play_tape, config_path);
384         #endif
385         #ifdef USE_SOUND_VOLUME
386                 for(int i = 0; i < USE_SOUND_VOLUME; i++) {
387                         int tmp_l = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
388                         int tmp_r = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
389                         #ifdef _USE_QT
390                                 // Note: when using balance , levels are -40±20db to 0±20db.
391                                 config.sound_volume_l[i] = max(-60, min(20, tmp_l));
392                                 config.sound_volume_r[i] = max(-60, min(20, tmp_r));
393                         #else
394                                 config.sound_volume_l[i] = max(-40, min(0, tmp_l));
395                                 config.sound_volume_r[i] = max(-40, min(0, tmp_r));
396                         #endif
397                 }
398         #endif
399         #if defined(_WIN32) && !defined(_USE_QT)
400                 MyGetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
401         #endif
402         
403         // input
404         #ifdef USE_JOYSTICK
405                 for(int i = 0; i < 4; i++) {
406                         for(int j = 0; j < 16; j++) {
407                                 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);
408                         }
409                 }
410         #endif
411         // debug
412         #ifdef USE_FLOPPY_DISK
413                 config.special_debug_fdc =      MyGetPrivateProfileInt(_T("Debug"), _T("SpecialDebugFDC"), config.special_debug_fdc, config_path);
414         #endif
415                 config.print_statistics = MyGetPrivateProfileBool(_T("Debug"), _T("PrintCPUStatistics"), config.print_statistics, config_path);
416         // printer
417         #ifdef USE_PRINTER
418                 MyGetPrivateProfileString(_T("Printer"), _T("PrinterDll"), _T("printer.dll"), config.printer_dll_path, _MAX_PATH, config_path);
419         #endif
420
421         // win32
422         #if defined(_WIN32) && !defined(_USE_QT)
423                 #ifndef ONE_BOARD_MICRO_COMPUTER
424                         config.use_d3d9 = MyGetPrivateProfileBool(_T("Win32"), _T("UseDirect3D9"), config.use_d3d9, config_path);
425                         config.wait_vsync = MyGetPrivateProfileBool(_T("Win32"), _T("WaitVSync"), config.wait_vsync, config_path);
426                 #endif
427                 config.use_dinput = MyGetPrivateProfileBool(_T("Win32"), _T("UseDirectInput"), config.use_dinput, config_path);
428                 config.disable_dwm = MyGetPrivateProfileBool(_T("Win32"), _T("DisableDwm"), config.disable_dwm, config_path);
429                 config.show_status_bar = MyGetPrivateProfileBool(_T("Win32"), _T("ShowStatusBar"), config.show_status_bar, config_path);
430         #endif
431
432         // qt
433         #ifdef _USE_QT
434                 config.use_separate_thread_draw = MyGetPrivateProfileBool(_T("Qt"), _T("UseSeparateThreadDraw"), config.use_separate_thread_draw, config_path);
435                 config.use_osd_virtual_media = MyGetPrivateProfileBool(_T("Qt"), _T("UseOSDVirtualMedia"), config.use_osd_virtual_media, config_path); 
436                 config.use_opengl_scanline = MyGetPrivateProfileBool(_T("Qt"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
437                 config.opengl_scanline_vert = MyGetPrivateProfileBool(_T("Qt"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
438                 config.opengl_scanline_horiz = MyGetPrivateProfileBool(_T("Qt"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
439                 config.use_opengl_filters = MyGetPrivateProfileBool(_T("Qt"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
440                 config.opengl_filter_num = MyGetPrivateProfileInt(_T("Qt"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
441                 config.render_platform = MyGetPrivateProfileInt(_T("Qt"), _T("RenderPlatform"), config.render_platform, config_path);
442                 config.render_major_version = MyGetPrivateProfileInt(_T("Qt"), _T("RenderMajorVersion"), config.render_major_version, config_path);
443                 config.render_minor_version = MyGetPrivateProfileInt(_T("Qt"), _T("RenderMinorVersion"), config.render_minor_version, config_path);
444                 config.rendering_type = MyGetPrivateProfileInt(_T("Qt"), _T("RenderType"), config.rendering_type, config_path);
445
446                 config.general_sound_level = MyGetPrivateProfileInt(_T("Qt"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
447                 config.focus_with_click = MyGetPrivateProfileBool(_T("Qt"), _T("FocusWithClick"), config.focus_with_click, config_path);
448                 
449                 if(config.rendering_type < 0) config.rendering_type = 0;
450                 if(config.rendering_type >= CONFIG_RENDER_TYPE_END) config.rendering_type = CONFIG_RENDER_TYPE_END - 1;
451                 // Assigning joysticks.
452                 for(i = 0; i < 16; i++) {
453                         _TCHAR name[256];
454                         my_stprintf_s(name, 256, _T("AssignedJoystick"), i + 1);
455                         MyGetPrivateProfileString(_T("Qt"), (const _TCHAR *)name, _T(""),
456                                                                           config.assigned_joystick_name[i], 256, config_path);
457                 }
458
459                 // Extra UI
460                 config.swap_kanji_pause = MyGetPrivateProfileBool(_T("Qt"), _T("SwapKanjiPause"), config.swap_kanji_pause, config_path);
461                 config.cursor_as_ten_key = MyGetPrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
462                 config.numpad_enter_as_fullkey = MyGetPrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
463                 config.host_keyboard_type = MyGetPrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
464
465                 
466                 // Movie load/save.
467                 config.video_width   = MyGetPrivateProfileInt(_T("Qt"), _T("VideoWidth"), config.video_width, config_path);
468                 if(config.video_width < 128) config.video_width = 128;
469                 config.video_height  = MyGetPrivateProfileInt(_T("Qt"), _T("VideoHeight"), config.video_height, config_path);
470                 if(config.video_height < 80) config.video_height = 80;
471                 
472                 config.video_codec_type = MyGetPrivateProfileInt(_T("Qt"), _T("VideoCodecType"), config.video_codec_type, config_path);
473                 if(config.video_codec_type > 1) config.video_codec_type = 1;
474                 if(config.video_codec_type < 0) config.video_codec_type = 0;
475                 
476                 config.audio_codec_type = MyGetPrivateProfileInt(_T("Qt"), _T("AudioCodecType"), config.audio_codec_type, config_path);
477                 if(config.video_codec_type > 2) config.audio_codec_type = 2;
478                 if(config.video_codec_type < 0) config.audio_codec_type = 0;
479                 
480                 config.video_h264_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
481                 if(config.video_h264_bitrate < 64) config.video_h264_bitrate = 64;
482                 
483                 config.video_h264_bframes = MyGetPrivateProfileInt(_T("Qt"), _T("H264BFrames"), config.video_h264_bframes, config_path);
484                 if(config.video_h264_bframes < 0) config.video_h264_bframes = 0;
485                 if(config.video_h264_bframes > 10) config.video_h264_bframes = 10;
486                 
487                 config.video_h264_b_adapt = MyGetPrivateProfileInt(_T("Qt"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
488                 if(config.video_h264_b_adapt < 0) config.video_h264_b_adapt = 0;
489                 if(config.video_h264_b_adapt > 2) config.video_h264_b_adapt = 2;
490                 
491                 config.video_h264_subme   = MyGetPrivateProfileInt(_T("Qt"), _T("H264Subme"), config.video_h264_subme, config_path);
492                 if(config.video_h264_subme < 0) config.video_h264_subme = 0;
493                 if(config.video_h264_subme > 11) config.video_h264_subme = 11;
494                 
495                 config.video_h264_minq   = MyGetPrivateProfileInt(_T("Qt"), _T("H264MinQ"), config.video_h264_minq, config_path);
496                 if(config.video_h264_minq < 0) config.video_h264_minq = 0;
497                 if(config.video_h264_minq > 63) config.video_h264_minq = 63;
498                 
499                 config.video_h264_maxq   = MyGetPrivateProfileInt(_T("Qt"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
500                 if(config.video_h264_maxq < 0) config.video_h264_maxq = 0;
501                 if(config.video_h264_maxq > 63) config.video_h264_maxq = 63;
502                 
503                 config.video_mpeg4_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
504                 if(config.video_mpeg4_bitrate < 64) config.video_mpeg4_bitrate = 64;
505                 
506                 config.video_mpeg4_bframes = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
507                 if(config.video_mpeg4_bframes < 0) config.video_mpeg4_bframes = 0;
508                 if(config.video_mpeg4_bframes > 10) config.video_mpeg4_bframes = 10;
509                 
510                 config.video_mpeg4_minq   = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
511                 if(config.video_mpeg4_minq < 1) config.video_mpeg4_minq = 1;
512                 if(config.video_mpeg4_minq > 31) config.video_mpeg4_minq = 31;
513                 
514                 config.video_mpeg4_maxq   = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
515                 if(config.video_mpeg4_maxq < 1) config.video_mpeg4_maxq = 1;
516                 if(config.video_mpeg4_maxq > 31) config.video_mpeg4_maxq = 31;
517                 if(config.video_mpeg4_maxq < config.video_mpeg4_minq) {
518                         int n;
519                         n = config.video_mpeg4_maxq;
520                         config.video_mpeg4_maxq  = config.video_mpeg4_minq;
521                         config.video_mpeg4_minq = n;
522                 }
523                 
524                 config.video_threads = MyGetPrivateProfileInt(_T("Qt"), _T("VideoThreads"), config.video_threads, config_path);
525                 if(config.video_threads < 0) config.video_threads = 0;
526                 if(config.video_threads > 16) config.video_threads = 16;
527                 
528                 config.audio_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("AudioBitrate"), config.audio_bitrate, config_path);
529                 if(config.audio_bitrate < 16) config.audio_bitrate = 16;
530                 if(config.audio_bitrate > 448) config.audio_bitrate = 448;
531                 
532                 config.video_frame_rate = MyGetPrivateProfileInt(_T("Qt"), _T("VideoFramerate"), config.video_frame_rate, config_path);
533                 if(config.video_frame_rate < 15) config.video_frame_rate = 15;
534                 if(config.video_frame_rate > 75) config.video_frame_rate = 75;
535                 // Logging
536                 config.log_to_syslog = MyGetPrivateProfileBool(_T("Qt"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
537                 config.log_to_console = MyGetPrivateProfileBool(_T("Qt"), _T("WriteToConsole"), config.log_to_console, config_path);
538                 
539                 for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; ii++) {
540                         uint32_t flags = 0;
541                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("SyslogEnabled%d"), ii), 0xffff, config_path);
542                         for(int jj = 0; jj < 8; jj++) {
543                                 config.dev_log_to_syslog[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
544                                 flags >>= 1;
545                         }
546                         flags = 0;
547                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("ConsoleLogEnabled%d"), ii), 0xffff, config_path);
548                         for(int jj = 0; jj < 8; jj++) {
549                                 config.dev_log_to_console[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
550                                 flags >>= 1;
551                         }
552                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("RecordLogEnabled%d"), ii), 0xffff, config_path);
553                         for(int jj = 0; jj < 8; jj++) {
554                                 config.dev_log_recording[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
555                         flags >>= 1;
556                         }
557                 }
558                 config.state_log_to_console = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToConsole"), config.state_log_to_console, config_path);;
559                 config.state_log_to_syslog = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToSyslog"), config.state_log_to_syslog, config_path);;
560                 config.state_log_to_recording = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToRecording"), config.state_log_to_recording, config_path);;
561
562                 config.virtual_media_position = MyGetPrivateProfileInt(_T("Qt"), _T("UiVirtualMediaPosition"), config.virtual_media_position, config_path);
563                 //csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Read config done.");
564         #endif
565 }
566                 
567 void save_config(const _TCHAR *config_path)
568 {
569         int drv, i;
570 #if !defined(_MSC_VER)
571         {
572                 FILEIO *pt = new FILEIO;
573                 if(pt->Fopen(config_path, FILEIO_WRITE_ASCII) != true) {
574                         delete pt;
575                         return;
576                 }
577                 pt->Fclose();
578                 delete pt;
579         }
580         
581 #endif  
582         // control
583         #ifdef USE_BOOT_MODE
584                 MyWritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
585         #endif
586         #ifdef USE_CPU_TYPE
587                 MyWritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
588         #endif
589         #ifdef USE_DIPSWITCH
590                 MyWritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
591         #endif
592         #ifdef USE_DEVICE_TYPE
593                 MyWritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
594         #endif
595         #ifdef USE_DRIVE_TYPE
596                 MyWritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
597         #endif
598         #ifdef USE_KEYBOARD_TYPE
599                 MyWritePrivateProfileInt(_T("Control"), _T("KeyboardType"), config.keyboard_type, config_path);
600         #endif
601         #ifdef USE_MOUSE_TYPE
602                 MyWritePrivateProfileInt(_T("Control"), _T("MouseType"), config.mouse_type, config_path);
603         #endif
604         #ifdef USE_JOYSTICK_TYPE
605                 MyWritePrivateProfileInt(_T("Control"), _T("JoystickType"), config.joystick_type, config_path);
606         #endif
607         #ifdef USE_SOUND_TYPE
608                 MyWritePrivateProfileInt(_T("Control"), _T("SoundType"), config.sound_type, config_path);
609         #endif
610         #ifdef USE_MONITOR_TYPE
611                 MyWritePrivateProfileInt(_T("Control"), _T("MonitorType"), config.monitor_type, config_path);
612         #endif
613         #ifdef USE_SCANLINE
614                 MyWritePrivateProfileBool(_T("Control"), _T("ScanLine"), config.scan_line, config_path);
615         #endif
616         #ifdef USE_PRINTER
617                 MyWritePrivateProfileInt(_T("Control"), _T("PrinterType"), config.printer_type, config_path);
618         #endif
619         #ifdef USE_FLOPPY_DISK
620                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
621                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("CorrectDiskTiming%d"), drv + 1), config.correct_disk_timing[drv], config_path);
622                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("IgnoreDiskCRC%d"), drv + 1), config.ignore_disk_crc[drv], config_path);
623                 #ifdef _USE_QT
624                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("DiskIncrementImmediate%d"), drv + 1), config.disk_count_immediate[drv], config_path);
625                 #endif
626                 }
627         #endif
628         #ifdef USE_TAPE
629                 for(int drv = 0; drv < USE_TAPE; drv++) {
630                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("WaveShaper%d"), drv + 1), config.wave_shaper[drv], config_path);
631                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("DirectLoadMZT%d"), drv + 1), config.direct_load_mzt[drv], config_path);
632                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("BaudHigh%d"), drv + 1), config.baud_high[drv], config_path);
633                 }
634         #endif
635         MyWritePrivateProfileBool(_T("Control"), _T("CompressState"), config.compress_state, config_path);
636         
637         // recent files
638         
639         // recent files
640         #ifdef USE_CART
641                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
642                 for(int drv = 0; drv < USE_CART; drv++) {
643                         for(int i = 0; i < MAX_HISTORY; i++) {
644                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCartPath%d_%d"), drv + 1, i + 1), config.recent_cart_path[drv][i], config_path);
645                         }
646                 }
647         #endif
648         #ifdef USE_FLOPPY_DISK
649                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_floppy_disk_dir, config_path);
650                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
651                         for(int i = 0; i < MAX_HISTORY; i++) {
652                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentDiskPath%d_%d"), drv + 1, i + 1), config.recent_floppy_disk_path[drv][i], config_path);
653                         }
654                 }
655         #endif
656         #ifdef USE_QUICK_DISK
657                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quick_disk_dir, config_path);
658                 for(int drv = 0; drv < USE_QUICK_DISK; drv++) {
659                         for(int i = 0; i < MAX_HISTORY; i++) {
660                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1), config.recent_quick_disk_path[drv][i], config_path);
661                         }
662                 }
663         #endif
664         #ifdef USE_HARD_DISK
665                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialHardDiskDir"), config.initial_hard_disk_dir, config_path);
666                 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
667                         for(int i = 0; i < MAX_HISTORY; i++) {
668                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentHardDiskPath%d_%d"), drv + 1, i + 1), config.recent_hard_disk_path[drv][i], config_path);
669                         }
670                 }
671         #endif
672         #ifdef USE_TAPE
673                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
674                 for(int drv = 0; drv < USE_TAPE; drv++) {
675                         for(int i = 0; i < MAX_HISTORY; i++) {
676                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath%d_%d"), drv + 1, i + 1), config.recent_tape_path[drv][i], config_path);
677                         }
678                 }
679         #endif
680         #ifdef USE_COMPACT_DISC
681                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCompactDiscDir"), config.initial_compact_disc_dir, config_path);
682                 for(int drv = 0; drv < USE_COMPACT_DISC; drv++) {
683                         for(int i = 0; i < MAX_HISTORY; i++) {
684                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCompactDiscPath%d_%d"), drv + 1, i + 1), config.recent_compact_disc_path[drv][i], config_path);
685                         }
686                 }
687         #endif
688         #ifdef USE_LASER_DISC
689                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
690                 for(int drv = 0; drv < USE_LASER_DISC; drv++) {
691                         for(int i = 0; i < MAX_HISTORY; i++) {
692                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentLaserDiscPath%d_%d"), drv + 1, i + 1), config.recent_laser_disc_path[drv][i], config_path);
693                         }
694                 }
695         #endif
696         #ifdef USE_BINARY_FILE
697                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
698                 for(int drv = 0; drv < USE_BINARY_FILE; drv++) {
699                         for(int i = 0; i < MAX_HISTORY; i++) {
700                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBinaryPath%d_%d"), drv + 1, i + 1), config.recent_binary_path[drv][i], config_path);
701                         }
702                 }
703         #endif
704         #ifdef USE_BUBBLE
705                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), config.initial_bubble_casette_dir, config_path);
706                 for(int drv = 0; drv < USE_BUBBLE; drv++) {
707                         for(int i = 0; i < MAX_HISTORY; i++) {
708                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBubblePath%d_%d"), drv + 1, i + 1), config.recent_bubble_casette_path[drv][i], config_path);
709                         }
710                 }
711         #endif
712         
713         // screen
714         #ifndef ONE_BOARD_MICRO_COMPUTER
715                 MyWritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
716                 MyWritePrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
717                 MyWritePrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
718 //              #ifdef USE_SCREEN_ROTATE
719                         MyWritePrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
720 //              #endif
721         #endif
722
723         // filter
724         #ifdef USE_SCREEN_FILTER
725                 MyWritePrivateProfileInt(_T("Screen"), _T("FilterType"), config.filter_type, config_path);
726         #endif
727                 
728         // sound
729                 MyWritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
730                 MyWritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
731                 MyWritePrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
732         #ifdef USE_FLOPPY_DISK
733                 MyWritePrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);
734         #endif
735         #ifdef USE_TAPE
736                 MyWritePrivateProfileBool(_T("Sound"), _T("NoiseCMT"), config.sound_noise_cmt, config_path);
737                 MyWritePrivateProfileBool(_T("Sound"), _T("PlayTape"), config.sound_play_tape, config_path);
738         #endif
739         #ifdef USE_SOUND_VOLUME
740                 for(int i = 0; i < USE_SOUND_VOLUME; i++) {
741                         MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
742                         MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
743                 }
744         #endif
745         #if defined(_WIN32) && !defined(_USE_QT)
746                 MyWritePrivateProfileString(_T("Sound"), _T("FMGenDll"), config.fmgen_dll_path, config_path);
747         #endif
748         
749         // input
750         #ifdef USE_JOYSTICK
751                 for(int i = 0; i < 4; i++) {
752                         for(int j = 0; j < 16; j++) {
753                                 MyWritePrivateProfileInt(_T("Input"), create_string(_T("JoyButtons%d_%d"), i + 1, j + 1), config.joy_buttons[i][j], config_path);
754                         }
755                 }
756         #endif
757
758         // debug
759         #ifdef USE_FLOPPY_DISK
760                 MyWritePrivateProfileInt(_T("Debug"), _T("SpecialDebugFDC"), config.special_debug_fdc, config_path);
761         #endif
762                 MyWritePrivateProfileBool(_T("Debug"), _T("PrintCPUStatistics"), config.print_statistics, config_path);
763         // printer
764         #ifdef USE_PRINTER
765                 MyWritePrivateProfileString(_T("Printer"), _T("PrinterDll"), config.printer_dll_path, config_path);
766         #endif
767
768         
769         // win32
770         #if defined(_WIN32) && !defined(_USE_QT)
771                 #ifndef ONE_BOARD_MICRO_COMPUTER
772                         MyWritePrivateProfileBool(_T("Win32"), _T("UseDirect3D9"), config.use_d3d9, config_path);
773                         MyWritePrivateProfileBool(_T("Win32"), _T("WaitVSync"), config.wait_vsync, config_path);
774                 #endif
775                 MyWritePrivateProfileBool(_T("Win32"), _T("UseDirectInput"), config.use_dinput, config_path);
776                 MyWritePrivateProfileBool(_T("Win32"), _T("DisableDwm"), config.disable_dwm, config_path);
777                 MyWritePrivateProfileBool(_T("Win32"), _T("ShowStatusBar"), config.show_status_bar, config_path);
778         #endif
779         #ifdef _USE_QT
780                 MyWritePrivateProfileBool(_T("Qt"), _T("UseSeparateThreadDraw"), config.use_separate_thread_draw, config_path);
781                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOSDVirtualMedia"), config.use_osd_virtual_media, config_path); 
782                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
783                 MyWritePrivateProfileBool(_T("Qt"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
784                 MyWritePrivateProfileBool(_T("Qt"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
785                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
786                 MyWritePrivateProfileInt(_T("Qt"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
787                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderType"), config.rendering_type, config_path);
788                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderPlatform"), config.render_platform, config_path);
789                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderMajorVersion"), config.render_major_version, config_path);
790                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderMinorVersion"), config.render_minor_version, config_path);
791
792                 MyWritePrivateProfileInt(_T("Qt"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
793                 MyWritePrivateProfileBool(_T("Qt"), _T("FocusWithClick"), config.focus_with_click, config_path);
794
795                 // Extra UI
796                 MyWritePrivateProfileBool(_T("Qt"), _T("SwapKanjiPause"), config.swap_kanji_pause, config_path);
797                 MyWritePrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
798                 MyWritePrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
799                 MyWritePrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
800
801                 for(i = 0; i < 16; i++) {
802                         _TCHAR name[256];
803                         my_stprintf_s(name, 256, _T("AssignedJoystick%d"), i + 1);
804                         MyWritePrivateProfileString(_T("Qt"), (const _TCHAR *)name, 
805                                                                                 config.assigned_joystick_name[i], config_path);
806                 }
807                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoWidth"), config.video_width, config_path);
808                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoHeight"), config.video_height, config_path);
809                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoCodecType"), config.video_codec_type, config_path);
810                 MyWritePrivateProfileInt(_T("Qt"), _T("AudioCodecType"), config.audio_codec_type, config_path);
811                 
812                 MyWritePrivateProfileInt(_T("Qt"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
813                 MyWritePrivateProfileInt(_T("Qt"), _T("H264BFrames"), config.video_h264_bframes, config_path);
814                 MyWritePrivateProfileInt(_T("Qt"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
815                 MyWritePrivateProfileInt(_T("Qt"), _T("H264MinQ"), config.video_h264_minq, config_path);
816                 MyWritePrivateProfileInt(_T("Qt"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
817                 MyWritePrivateProfileInt(_T("Qt"), _T("H264Subme"), config.video_h264_subme, config_path);
818                 
819                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
820                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
821                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
822                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
823                 
824                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoThreads"), config.video_threads, config_path);
825                 MyWritePrivateProfileInt(_T("Qt"), _T("AudioBitrate"), config.audio_bitrate, config_path);
826                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoFramerate"), config.video_frame_rate, config_path);
827                 
828                 MyWritePrivateProfileBool(_T("Qt"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
829                 MyWritePrivateProfileBool(_T("Qt"), _T("WriteToConsole"), config.log_to_console, config_path);
830                 
831                 for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; ii++) {
832                         uint32_t flags = 0;
833                         flags = 0;
834                         for(int jj = 0; jj < 8; jj++) {
835                                 flags <<= 1;
836                                 if(config.dev_log_to_syslog[ii][jj]) flags |= 0x0001;
837                         }
838                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("SyslogEnabled%d"), ii), flags, config_path);
839                         
840                         flags = 0;
841                         for(int jj = 0; jj < 8; jj++) {
842                                 flags <<= 1;
843                                 if(config.dev_log_to_console[ii][jj]) flags |= 0x0001;
844                         }
845                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("ConsoleLogEnabled%d"), ii), flags, config_path);
846                         
847                         flags = 0;
848                         for(int jj = 0; jj < 8; jj++) {
849                                 flags <<= 1;
850                                 if(config.dev_log_recording[ii][jj]) flags |= 0x0001;
851                         }
852                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("RecordLogEnabled%d"), ii), flags, config_path);
853                 }
854                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToConsole"), config.state_log_to_console, config_path);
855                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToSyslog"), config.state_log_to_syslog, config_path);
856                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToRecording"), config.state_log_to_recording, config_path);
857                 
858                 MyWritePrivateProfileInt(_T("Qt"), _T("UiVirtualMediaPosition"), config.virtual_media_position, config_path);
859                 //csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Write config done.");
860         #endif  
861 }
862
863 #define STATE_VERSION   6
864
865 void save_config_state(void *f)
866 {
867         FILEIO *state_fio = (FILEIO *)f;
868         
869         state_fio->FputUint32(STATE_VERSION);
870         
871         #ifdef USE_BOOT_MODE
872                 state_fio->FputInt32(config.boot_mode);
873         #endif
874         #ifdef USE_CPU_TYPE
875                 state_fio->FputInt32(config.cpu_type);
876         #endif
877         #ifdef USE_DIPSWITCH
878                 state_fio->FputUint32(config.dipswitch);
879         #endif
880         #ifdef USE_DEVICE_TYPE
881                 state_fio->FputInt32(config.device_type);
882         #endif
883         #ifdef USE_DRIVE_TYPE
884                 state_fio->FputInt32(config.drive_type);
885         #endif
886         #ifdef USE_KEYBOARD_TYPE
887                 state_fio->FputInt32(config.keyboard_type);
888         #endif
889         #ifdef USE_MOUSE_TYPE
890                 state_fio->FputInt32(config.mouse_type);
891         #endif
892         #ifdef USE_JOYSTICK_TYPE
893                 state_fio->FputInt32(config.joystick_type);
894         #endif
895         #ifdef USE_SOUND_TYPE
896                 state_fio->FputInt32(config.sound_type);
897         #endif
898         #ifdef USE_MONITOR_TYPE
899                 state_fio->FputInt32(config.monitor_type);
900         #endif
901         #ifdef USE_PRINTER_TYPE
902                 state_fio->FputInt32(config.printer_type);
903         #endif
904         #ifdef USE_FLOPPY_DISK
905                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
906                         state_fio->FputBool(config.correct_disk_timing[drv]);
907                         state_fio->FputBool(config.ignore_disk_crc[drv]);
908                 }
909         #endif
910         state_fio->FputInt32(config.sound_frequency);
911         state_fio->FputInt32(config.sound_latency);
912 }
913
914 bool load_config_state(void *f)
915 {
916         FILEIO *state_fio = (FILEIO *)f;
917         
918         if(state_fio->FgetUint32() != STATE_VERSION) {
919                 return false;
920         }
921         #ifdef USE_BOOT_MODE
922                 config.boot_mode = state_fio->FgetInt32();
923         #endif
924         #ifdef USE_CPU_TYPE
925                 config.cpu_type = state_fio->FgetInt32();
926         #endif
927         #ifdef USE_DIPSWITCH
928                 config.dipswitch = state_fio->FgetUint32();
929         #endif
930         #ifdef USE_DEVICE_TYPE
931                 config.device_type = state_fio->FgetInt32();
932         #endif
933         #ifdef USE_DRIVE_TYPE
934                 config.drive_type = state_fio->FgetInt32();
935         #endif
936         #ifdef USE_KEYBOARD_TYPE
937                 config.keyboard_type = state_fio->FgetInt32();
938         #endif
939         #ifdef USE_MOUSE_TYPE
940                 config.mouse_type = state_fio->FgetInt32();
941         #endif
942         #ifdef USE_JOYSTICK_TYPE
943                 config.joystick_type = state_fio->FgetInt32();
944         #endif
945         #ifdef USE_SOUND_TYPE
946                 config.sound_type = state_fio->FgetInt32();
947         #endif
948         #ifdef USE_MONITOR_TYPE
949                 config.monitor_type = state_fio->FgetInt32();
950         #endif
951         #ifdef USE_PRINTER_TYPE
952                 config.printer_type = state_fio->FgetInt32();
953         #endif
954         #ifdef USE_FLOPPY_DISK
955                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
956                         config.correct_disk_timing[drv] = state_fio->FgetBool();
957                         config.ignore_disk_crc[drv] = state_fio->FgetBool();
958                 }
959         #endif
960         config.sound_frequency = state_fio->FgetInt32();
961         config.sound_latency = state_fio->FgetInt32();
962         return true;
963 }
964