OSDN Git Service

[VM][General] Merge Upstream 20180530.
[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                         MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("LastHardDiskPath%d"), drv + 1), _T(""), config.last_hard_disk_path[drv], _MAX_PATH, config_path);
316                 }
317         #endif
318         #ifdef USE_TAPE
319                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""), config.initial_tape_dir, _MAX_PATH, config_path);
320                 for(int drv = 0; drv < USE_TAPE; drv++) {
321                         for(int i = 0; i < MAX_HISTORY; i++) {
322                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath%d_%d"), drv + 1, i + 1), _T(""), config.recent_tape_path[drv][i], _MAX_PATH, config_path);
323                         }
324                 }
325         #endif
326         #ifdef USE_COMPACT_DISC
327                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialCompactDiscDir"), _T(""), config.initial_compact_disc_dir, _MAX_PATH, config_path);
328                 for(int drv = 0; drv < USE_COMPACT_DISC; drv++) {
329                         for(int i = 0; i < MAX_HISTORY; i++) {
330                                 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);
331                         }
332                 }
333         #endif
334         #ifdef USE_LASER_DISC
335                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""), config.initial_laser_disc_dir, _MAX_PATH, config_path);
336                 for(int drv = 0; drv < USE_LASER_DISC; drv++) {
337                         for(int i = 0; i < MAX_HISTORY; i++) {
338                                 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);
339                         }
340                 }
341         #endif
342         #ifdef USE_BINARY_FILE
343                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), _T(""), config.initial_binary_dir, _MAX_PATH, config_path);
344                 for(int drv = 0; drv < USE_BINARY_FILE; drv++) {
345                         for(int i = 0; i < MAX_HISTORY; i++) {
346                                 MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBinaryPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_binary_path[drv][i], _MAX_PATH, config_path);
347                         }
348                 }
349         #endif
350         #ifdef USE_BUBBLE
351                 MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), _T(""), config.initial_bubble_casette_dir, _MAX_PATH, config_path);
352                 for(int drv = 0; drv < USE_BUBBLE; drv++) {
353                         for(int i = 0; i < MAX_HISTORY; i++) {
354                                 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);
355                         }
356                 }
357         #endif
358         
359         // screen
360         #ifndef ONE_BOARD_MICRO_COMPUTER
361                 config.window_mode = MyGetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
362                 config.window_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
363                 config.fullscreen_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
364 //              #ifdef USE_SCREEN_ROTATE
365                         config.rotate_type = MyGetPrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
366 //              #endif
367         #endif
368
369         
370         // filter
371         #ifdef USE_SCREEN_FILTER
372                 config.filter_type = MyGetPrivateProfileInt(_T("Screen"), _T("FilterType"), config.filter_type, config_path);
373         #endif
374
375         // sound
376         config.sound_frequency = MyGetPrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
377         config.sound_latency = MyGetPrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
378         config.sound_strict_rendering = MyGetPrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
379         #ifdef USE_FLOPPY_DISK
380                 config.sound_noise_fdd = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);;
381         #endif
382         #ifdef USE_TAPE
383                 config.sound_noise_cmt = MyGetPrivateProfileBool(_T("Sound"), _T("NoiseCMT"), config.sound_noise_cmt, config_path);;
384                 config.sound_play_tape = MyGetPrivateProfileBool(_T("Sound"), _T("PlayTape"), config.sound_play_tape, config_path);
385         #endif
386         #ifdef USE_SOUND_VOLUME
387                 for(int i = 0; i < USE_SOUND_VOLUME; i++) {
388                         int tmp_l = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
389                         int tmp_r = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
390                         #ifdef _USE_QT
391                                 // Note: when using balance , levels are -40±20db to 0±20db.
392                                 config.sound_volume_l[i] = max(-60, min(20, tmp_l));
393                                 config.sound_volume_r[i] = max(-60, min(20, tmp_r));
394                         #else
395                                 config.sound_volume_l[i] = max(-40, min(0, tmp_l));
396                                 config.sound_volume_r[i] = max(-40, min(0, tmp_r));
397                         #endif
398                 }
399         #endif
400         #if defined(_WIN32) && !defined(_USE_QT)
401                 MyGetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
402         #endif
403         
404         // input
405         #ifdef USE_JOYSTICK
406                 for(int i = 0; i < 4; i++) {
407                         for(int j = 0; j < 16; j++) {
408                                 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);
409                         }
410                 }
411         #endif
412         // debug
413         #ifdef USE_FLOPPY_DISK
414                 config.special_debug_fdc =      MyGetPrivateProfileInt(_T("Debug"), _T("SpecialDebugFDC"), config.special_debug_fdc, config_path);
415         #endif
416                 config.print_statistics = MyGetPrivateProfileBool(_T("Debug"), _T("PrintCPUStatistics"), config.print_statistics, config_path);
417         // printer
418         #ifdef USE_PRINTER
419                 MyGetPrivateProfileString(_T("Printer"), _T("PrinterDll"), _T("printer.dll"), config.printer_dll_path, _MAX_PATH, config_path);
420         #endif
421
422         // win32
423         #if defined(_WIN32) && !defined(_USE_QT)
424                 #ifndef ONE_BOARD_MICRO_COMPUTER
425                         config.use_d3d9 = MyGetPrivateProfileBool(_T("Win32"), _T("UseDirect3D9"), config.use_d3d9, config_path);
426                         config.wait_vsync = MyGetPrivateProfileBool(_T("Win32"), _T("WaitVSync"), config.wait_vsync, config_path);
427                 #endif
428                 config.use_dinput = MyGetPrivateProfileBool(_T("Win32"), _T("UseDirectInput"), config.use_dinput, config_path);
429                 config.disable_dwm = MyGetPrivateProfileBool(_T("Win32"), _T("DisableDwm"), config.disable_dwm, config_path);
430                 config.show_status_bar = MyGetPrivateProfileBool(_T("Win32"), _T("ShowStatusBar"), config.show_status_bar, config_path);
431         #endif
432
433         // qt
434         #ifdef _USE_QT
435                 config.use_separate_thread_draw = MyGetPrivateProfileBool(_T("Qt"), _T("UseSeparateThreadDraw"), config.use_separate_thread_draw, config_path);
436                 config.use_osd_virtual_media = MyGetPrivateProfileBool(_T("Qt"), _T("UseOSDVirtualMedia"), config.use_osd_virtual_media, config_path); 
437                 config.use_opengl_scanline = MyGetPrivateProfileBool(_T("Qt"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
438                 config.opengl_scanline_vert = MyGetPrivateProfileBool(_T("Qt"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
439                 config.opengl_scanline_horiz = MyGetPrivateProfileBool(_T("Qt"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
440                 config.use_opengl_filters = MyGetPrivateProfileBool(_T("Qt"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
441                 config.opengl_filter_num = MyGetPrivateProfileInt(_T("Qt"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
442                 config.render_platform = MyGetPrivateProfileInt(_T("Qt"), _T("RenderPlatform"), config.render_platform, config_path);
443                 config.render_major_version = MyGetPrivateProfileInt(_T("Qt"), _T("RenderMajorVersion"), config.render_major_version, config_path);
444                 config.render_minor_version = MyGetPrivateProfileInt(_T("Qt"), _T("RenderMinorVersion"), config.render_minor_version, config_path);
445                 config.rendering_type = MyGetPrivateProfileInt(_T("Qt"), _T("RenderType"), config.rendering_type, config_path);
446
447                 config.general_sound_level = MyGetPrivateProfileInt(_T("Qt"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
448                 config.focus_with_click = MyGetPrivateProfileBool(_T("Qt"), _T("FocusWithClick"), config.focus_with_click, config_path);
449                 
450                 if(config.rendering_type < 0) config.rendering_type = 0;
451                 if(config.rendering_type >= CONFIG_RENDER_TYPE_END) config.rendering_type = CONFIG_RENDER_TYPE_END - 1;
452                 // Assigning joysticks.
453                 for(i = 0; i < 16; i++) {
454                         _TCHAR name[256];
455                         my_stprintf_s(name, 256, _T("AssignedJoystick"), i + 1);
456                         MyGetPrivateProfileString(_T("Qt"), (const _TCHAR *)name, _T(""),
457                                                                           config.assigned_joystick_name[i], 256, config_path);
458                 }
459
460                 // Extra UI
461                 config.swap_kanji_pause = MyGetPrivateProfileBool(_T("Qt"), _T("SwapKanjiPause"), config.swap_kanji_pause, config_path);
462                 config.cursor_as_ten_key = MyGetPrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
463                 config.numpad_enter_as_fullkey = MyGetPrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
464                 config.host_keyboard_type = MyGetPrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
465
466                 
467                 // Movie load/save.
468                 config.video_width   = MyGetPrivateProfileInt(_T("Qt"), _T("VideoWidth"), config.video_width, config_path);
469                 if(config.video_width < 128) config.video_width = 128;
470                 config.video_height  = MyGetPrivateProfileInt(_T("Qt"), _T("VideoHeight"), config.video_height, config_path);
471                 if(config.video_height < 80) config.video_height = 80;
472                 
473                 config.video_codec_type = MyGetPrivateProfileInt(_T("Qt"), _T("VideoCodecType"), config.video_codec_type, config_path);
474                 if(config.video_codec_type > 1) config.video_codec_type = 1;
475                 if(config.video_codec_type < 0) config.video_codec_type = 0;
476                 
477                 config.audio_codec_type = MyGetPrivateProfileInt(_T("Qt"), _T("AudioCodecType"), config.audio_codec_type, config_path);
478                 if(config.video_codec_type > 2) config.audio_codec_type = 2;
479                 if(config.video_codec_type < 0) config.audio_codec_type = 0;
480                 
481                 config.video_h264_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
482                 if(config.video_h264_bitrate < 64) config.video_h264_bitrate = 64;
483                 
484                 config.video_h264_bframes = MyGetPrivateProfileInt(_T("Qt"), _T("H264BFrames"), config.video_h264_bframes, config_path);
485                 if(config.video_h264_bframes < 0) config.video_h264_bframes = 0;
486                 if(config.video_h264_bframes > 10) config.video_h264_bframes = 10;
487                 
488                 config.video_h264_b_adapt = MyGetPrivateProfileInt(_T("Qt"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
489                 if(config.video_h264_b_adapt < 0) config.video_h264_b_adapt = 0;
490                 if(config.video_h264_b_adapt > 2) config.video_h264_b_adapt = 2;
491                 
492                 config.video_h264_subme   = MyGetPrivateProfileInt(_T("Qt"), _T("H264Subme"), config.video_h264_subme, config_path);
493                 if(config.video_h264_subme < 0) config.video_h264_subme = 0;
494                 if(config.video_h264_subme > 11) config.video_h264_subme = 11;
495                 
496                 config.video_h264_minq   = MyGetPrivateProfileInt(_T("Qt"), _T("H264MinQ"), config.video_h264_minq, config_path);
497                 if(config.video_h264_minq < 0) config.video_h264_minq = 0;
498                 if(config.video_h264_minq > 63) config.video_h264_minq = 63;
499                 
500                 config.video_h264_maxq   = MyGetPrivateProfileInt(_T("Qt"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
501                 if(config.video_h264_maxq < 0) config.video_h264_maxq = 0;
502                 if(config.video_h264_maxq > 63) config.video_h264_maxq = 63;
503                 
504                 config.video_mpeg4_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
505                 if(config.video_mpeg4_bitrate < 64) config.video_mpeg4_bitrate = 64;
506                 
507                 config.video_mpeg4_bframes = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
508                 if(config.video_mpeg4_bframes < 0) config.video_mpeg4_bframes = 0;
509                 if(config.video_mpeg4_bframes > 10) config.video_mpeg4_bframes = 10;
510                 
511                 config.video_mpeg4_minq   = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
512                 if(config.video_mpeg4_minq < 1) config.video_mpeg4_minq = 1;
513                 if(config.video_mpeg4_minq > 31) config.video_mpeg4_minq = 31;
514                 
515                 config.video_mpeg4_maxq   = MyGetPrivateProfileInt(_T("Qt"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
516                 if(config.video_mpeg4_maxq < 1) config.video_mpeg4_maxq = 1;
517                 if(config.video_mpeg4_maxq > 31) config.video_mpeg4_maxq = 31;
518                 if(config.video_mpeg4_maxq < config.video_mpeg4_minq) {
519                         int n;
520                         n = config.video_mpeg4_maxq;
521                         config.video_mpeg4_maxq  = config.video_mpeg4_minq;
522                         config.video_mpeg4_minq = n;
523                 }
524                 
525                 config.video_threads = MyGetPrivateProfileInt(_T("Qt"), _T("VideoThreads"), config.video_threads, config_path);
526                 if(config.video_threads < 0) config.video_threads = 0;
527                 if(config.video_threads > 16) config.video_threads = 16;
528                 
529                 config.audio_bitrate = MyGetPrivateProfileInt(_T("Qt"), _T("AudioBitrate"), config.audio_bitrate, config_path);
530                 if(config.audio_bitrate < 16) config.audio_bitrate = 16;
531                 if(config.audio_bitrate > 448) config.audio_bitrate = 448;
532                 
533                 config.video_frame_rate = MyGetPrivateProfileInt(_T("Qt"), _T("VideoFramerate"), config.video_frame_rate, config_path);
534                 if(config.video_frame_rate < 15) config.video_frame_rate = 15;
535                 if(config.video_frame_rate > 75) config.video_frame_rate = 75;
536                 // Logging
537                 config.log_to_syslog = MyGetPrivateProfileBool(_T("Qt"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
538                 config.log_to_console = MyGetPrivateProfileBool(_T("Qt"), _T("WriteToConsole"), config.log_to_console, config_path);
539                 
540                 for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; ii++) {
541                         uint32_t flags = 0;
542                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("SyslogEnabled%d"), ii), 0xffff, config_path);
543                         for(int jj = 0; jj < 8; jj++) {
544                                 config.dev_log_to_syslog[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
545                                 flags >>= 1;
546                         }
547                         flags = 0;
548                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("ConsoleLogEnabled%d"), ii), 0xffff, config_path);
549                         for(int jj = 0; jj < 8; jj++) {
550                                 config.dev_log_to_console[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
551                                 flags >>= 1;
552                         }
553                         flags = MyGetPrivateProfileInt(_T("Qt"), create_string(_T("RecordLogEnabled%d"), ii), 0xffff, config_path);
554                         for(int jj = 0; jj < 8; jj++) {
555                                 config.dev_log_recording[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
556                         flags >>= 1;
557                         }
558                 }
559                 config.state_log_to_console = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToConsole"), config.state_log_to_console, config_path);;
560                 config.state_log_to_syslog = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToSyslog"), config.state_log_to_syslog, config_path);;
561                 config.state_log_to_recording = MyGetPrivateProfileBool(_T("Qt"), _T("StateLogToRecording"), config.state_log_to_recording, config_path);;
562
563                 config.virtual_media_position = MyGetPrivateProfileInt(_T("Qt"), _T("UiVirtualMediaPosition"), config.virtual_media_position, config_path);
564                 //csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Read config done.");
565         #endif
566 }
567                 
568 void save_config(const _TCHAR *config_path)
569 {
570         int drv, i;
571 #if !defined(_MSC_VER)
572         {
573                 FILEIO *pt = new FILEIO;
574                 if(pt->Fopen(config_path, FILEIO_WRITE_ASCII) != true) {
575                         delete pt;
576                         return;
577                 }
578                 pt->Fclose();
579                 delete pt;
580         }
581         
582 #endif  
583         // control
584         #ifdef USE_BOOT_MODE
585                 MyWritePrivateProfileInt(_T("Control"), _T("BootMode"), config.boot_mode, config_path);
586         #endif
587         #ifdef USE_CPU_TYPE
588                 MyWritePrivateProfileInt(_T("Control"), _T("CPUType"), config.cpu_type, config_path);
589         #endif
590         #ifdef USE_DIPSWITCH
591                 MyWritePrivateProfileInt(_T("Control"), _T("DipSwitch"), config.dipswitch, config_path);
592         #endif
593         #ifdef USE_DEVICE_TYPE
594                 MyWritePrivateProfileInt(_T("Control"), _T("DeviceType"), config.device_type, config_path);
595         #endif
596         #ifdef USE_DRIVE_TYPE
597                 MyWritePrivateProfileInt(_T("Control"), _T("DriveType"), config.drive_type, config_path);
598         #endif
599         #ifdef USE_KEYBOARD_TYPE
600                 MyWritePrivateProfileInt(_T("Control"), _T("KeyboardType"), config.keyboard_type, config_path);
601         #endif
602         #ifdef USE_MOUSE_TYPE
603                 MyWritePrivateProfileInt(_T("Control"), _T("MouseType"), config.mouse_type, config_path);
604         #endif
605         #ifdef USE_JOYSTICK_TYPE
606                 MyWritePrivateProfileInt(_T("Control"), _T("JoystickType"), config.joystick_type, config_path);
607         #endif
608         #ifdef USE_SOUND_TYPE
609                 MyWritePrivateProfileInt(_T("Control"), _T("SoundType"), config.sound_type, config_path);
610         #endif
611         #ifdef USE_MONITOR_TYPE
612                 MyWritePrivateProfileInt(_T("Control"), _T("MonitorType"), config.monitor_type, config_path);
613         #endif
614         #ifdef USE_SCANLINE
615                 MyWritePrivateProfileBool(_T("Control"), _T("ScanLine"), config.scan_line, config_path);
616         #endif
617         #ifdef USE_PRINTER
618                 MyWritePrivateProfileInt(_T("Control"), _T("PrinterType"), config.printer_type, config_path);
619         #endif
620         #ifdef USE_FLOPPY_DISK
621                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
622                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("CorrectDiskTiming%d"), drv + 1), config.correct_disk_timing[drv], config_path);
623                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("IgnoreDiskCRC%d"), drv + 1), config.ignore_disk_crc[drv], config_path);
624                 #ifdef _USE_QT
625                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("DiskIncrementImmediate%d"), drv + 1), config.disk_count_immediate[drv], config_path);
626                 #endif
627                 }
628         #endif
629         #ifdef USE_TAPE
630                 for(int drv = 0; drv < USE_TAPE; drv++) {
631                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("WaveShaper%d"), drv + 1), config.wave_shaper[drv], config_path);
632                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("DirectLoadMZT%d"), drv + 1), config.direct_load_mzt[drv], config_path);
633                         MyWritePrivateProfileBool(_T("Control"), create_string(_T("BaudHigh%d"), drv + 1), config.baud_high[drv], config_path);
634                 }
635         #endif
636         MyWritePrivateProfileBool(_T("Control"), _T("CompressState"), config.compress_state, config_path);
637         
638         // recent files
639         
640         // recent files
641         #ifdef USE_CART
642                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
643                 for(int drv = 0; drv < USE_CART; drv++) {
644                         for(int i = 0; i < MAX_HISTORY; i++) {
645                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCartPath%d_%d"), drv + 1, i + 1), config.recent_cart_path[drv][i], config_path);
646                         }
647                 }
648         #endif
649         #ifdef USE_FLOPPY_DISK
650                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_floppy_disk_dir, config_path);
651                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
652                         for(int i = 0; i < MAX_HISTORY; i++) {
653                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentDiskPath%d_%d"), drv + 1, i + 1), config.recent_floppy_disk_path[drv][i], config_path);
654                         }
655                 }
656         #endif
657         #ifdef USE_QUICK_DISK
658                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quick_disk_dir, config_path);
659                 for(int drv = 0; drv < USE_QUICK_DISK; drv++) {
660                         for(int i = 0; i < MAX_HISTORY; i++) {
661                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1), config.recent_quick_disk_path[drv][i], config_path);
662                         }
663                 }
664         #endif
665         #ifdef USE_HARD_DISK
666                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialHardDiskDir"), config.initial_hard_disk_dir, config_path);
667                 for(int drv = 0; drv < USE_HARD_DISK; drv++) {
668                         for(int i = 0; i < MAX_HISTORY; i++) {
669                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentHardDiskPath%d_%d"), drv + 1, i + 1), config.recent_hard_disk_path[drv][i], config_path);
670                         }
671                         MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("LastHardDiskPath%d"), drv + 1), config.last_hard_disk_path[drv], config_path);
672                 }
673         #endif
674         #ifdef USE_TAPE
675                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
676                 for(int drv = 0; drv < USE_TAPE; drv++) {
677                         for(int i = 0; i < MAX_HISTORY; i++) {
678                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath%d_%d"), drv + 1, i + 1), config.recent_tape_path[drv][i], config_path);
679                         }
680                 }
681         #endif
682         #ifdef USE_COMPACT_DISC
683                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCompactDiscDir"), config.initial_compact_disc_dir, config_path);
684                 for(int drv = 0; drv < USE_COMPACT_DISC; drv++) {
685                         for(int i = 0; i < MAX_HISTORY; i++) {
686                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCompactDiscPath%d_%d"), drv + 1, i + 1), config.recent_compact_disc_path[drv][i], config_path);
687                         }
688                 }
689         #endif
690         #ifdef USE_LASER_DISC
691                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
692                 for(int drv = 0; drv < USE_LASER_DISC; drv++) {
693                         for(int i = 0; i < MAX_HISTORY; i++) {
694                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentLaserDiscPath%d_%d"), drv + 1, i + 1), config.recent_laser_disc_path[drv][i], config_path);
695                         }
696                 }
697         #endif
698         #ifdef USE_BINARY_FILE
699                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
700                 for(int drv = 0; drv < USE_BINARY_FILE; drv++) {
701                         for(int i = 0; i < MAX_HISTORY; i++) {
702                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBinaryPath%d_%d"), drv + 1, i + 1), config.recent_binary_path[drv][i], config_path);
703                         }
704                 }
705         #endif
706         #ifdef USE_BUBBLE
707                 MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), config.initial_bubble_casette_dir, config_path);
708                 for(int drv = 0; drv < USE_BUBBLE; drv++) {
709                         for(int i = 0; i < MAX_HISTORY; i++) {
710                                 MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBubblePath%d_%d"), drv + 1, i + 1), config.recent_bubble_casette_path[drv][i], config_path);
711                         }
712                 }
713         #endif
714         
715         // screen
716         #ifndef ONE_BOARD_MICRO_COMPUTER
717                 MyWritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
718                 MyWritePrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
719                 MyWritePrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
720 //              #ifdef USE_SCREEN_ROTATE
721                         MyWritePrivateProfileInt(_T("Screen"), _T("RotateType"), config.rotate_type, config_path);
722 //              #endif
723         #endif
724
725         // filter
726         #ifdef USE_SCREEN_FILTER
727                 MyWritePrivateProfileInt(_T("Screen"), _T("FilterType"), config.filter_type, config_path);
728         #endif
729                 
730         // sound
731                 MyWritePrivateProfileInt(_T("Sound"), _T("Frequency"), config.sound_frequency, config_path);
732                 MyWritePrivateProfileInt(_T("Sound"), _T("Latency"), config.sound_latency, config_path);
733                 MyWritePrivateProfileBool(_T("Sound"), _T("StrictRendering"), config.sound_strict_rendering, config_path);
734         #ifdef USE_FLOPPY_DISK
735                 MyWritePrivateProfileBool(_T("Sound"), _T("NoiseFDD"), config.sound_noise_fdd, config_path);
736         #endif
737         #ifdef USE_TAPE
738                 MyWritePrivateProfileBool(_T("Sound"), _T("NoiseCMT"), config.sound_noise_cmt, config_path);
739                 MyWritePrivateProfileBool(_T("Sound"), _T("PlayTape"), config.sound_play_tape, config_path);
740         #endif
741         #ifdef USE_SOUND_VOLUME
742                 for(int i = 0; i < USE_SOUND_VOLUME; i++) {
743                         MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
744                         MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
745                 }
746         #endif
747         #if defined(_WIN32) && !defined(_USE_QT)
748                 MyWritePrivateProfileString(_T("Sound"), _T("FMGenDll"), config.fmgen_dll_path, config_path);
749         #endif
750         
751         // input
752         #ifdef USE_JOYSTICK
753                 for(int i = 0; i < 4; i++) {
754                         for(int j = 0; j < 16; j++) {
755                                 MyWritePrivateProfileInt(_T("Input"), create_string(_T("JoyButtons%d_%d"), i + 1, j + 1), config.joy_buttons[i][j], config_path);
756                         }
757                 }
758         #endif
759
760         // debug
761         #ifdef USE_FLOPPY_DISK
762                 MyWritePrivateProfileInt(_T("Debug"), _T("SpecialDebugFDC"), config.special_debug_fdc, config_path);
763         #endif
764                 MyWritePrivateProfileBool(_T("Debug"), _T("PrintCPUStatistics"), config.print_statistics, config_path);
765         // printer
766         #ifdef USE_PRINTER
767                 MyWritePrivateProfileString(_T("Printer"), _T("PrinterDll"), config.printer_dll_path, config_path);
768         #endif
769
770         
771         // win32
772         #if defined(_WIN32) && !defined(_USE_QT)
773                 #ifndef ONE_BOARD_MICRO_COMPUTER
774                         MyWritePrivateProfileBool(_T("Win32"), _T("UseDirect3D9"), config.use_d3d9, config_path);
775                         MyWritePrivateProfileBool(_T("Win32"), _T("WaitVSync"), config.wait_vsync, config_path);
776                 #endif
777                 MyWritePrivateProfileBool(_T("Win32"), _T("UseDirectInput"), config.use_dinput, config_path);
778                 MyWritePrivateProfileBool(_T("Win32"), _T("DisableDwm"), config.disable_dwm, config_path);
779                 MyWritePrivateProfileBool(_T("Win32"), _T("ShowStatusBar"), config.show_status_bar, config_path);
780         #endif
781         #ifdef _USE_QT
782                 MyWritePrivateProfileBool(_T("Qt"), _T("UseSeparateThreadDraw"), config.use_separate_thread_draw, config_path);
783                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOSDVirtualMedia"), config.use_osd_virtual_media, config_path); 
784                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
785                 MyWritePrivateProfileBool(_T("Qt"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
786                 MyWritePrivateProfileBool(_T("Qt"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
787                 MyWritePrivateProfileBool(_T("Qt"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
788                 MyWritePrivateProfileInt(_T("Qt"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
789                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderType"), config.rendering_type, config_path);
790                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderPlatform"), config.render_platform, config_path);
791                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderMajorVersion"), config.render_major_version, config_path);
792                 MyWritePrivateProfileInt(_T("Qt"), _T("RenderMinorVersion"), config.render_minor_version, config_path);
793
794                 MyWritePrivateProfileInt(_T("Qt"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
795                 MyWritePrivateProfileBool(_T("Qt"), _T("FocusWithClick"), config.focus_with_click, config_path);
796
797                 // Extra UI
798                 MyWritePrivateProfileBool(_T("Qt"), _T("SwapKanjiPause"), config.swap_kanji_pause, config_path);
799                 MyWritePrivateProfileInt(_T("Qt"), _T("CursorAsTenKey"), config.cursor_as_ten_key, config_path);
800                 MyWritePrivateProfileBool(_T("Qt"), _T("NumpadEnterAsFullKey"), config.numpad_enter_as_fullkey, config_path);
801                 MyWritePrivateProfileInt(_T("Qt"), _T("HostKeyboardType"), config.host_keyboard_type, config_path);
802
803                 for(i = 0; i < 16; i++) {
804                         _TCHAR name[256];
805                         my_stprintf_s(name, 256, _T("AssignedJoystick%d"), i + 1);
806                         MyWritePrivateProfileString(_T("Qt"), (const _TCHAR *)name, 
807                                                                                 config.assigned_joystick_name[i], config_path);
808                 }
809                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoWidth"), config.video_width, config_path);
810                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoHeight"), config.video_height, config_path);
811                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoCodecType"), config.video_codec_type, config_path);
812                 MyWritePrivateProfileInt(_T("Qt"), _T("AudioCodecType"), config.audio_codec_type, config_path);
813                 
814                 MyWritePrivateProfileInt(_T("Qt"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
815                 MyWritePrivateProfileInt(_T("Qt"), _T("H264BFrames"), config.video_h264_bframes, config_path);
816                 MyWritePrivateProfileInt(_T("Qt"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
817                 MyWritePrivateProfileInt(_T("Qt"), _T("H264MinQ"), config.video_h264_minq, config_path);
818                 MyWritePrivateProfileInt(_T("Qt"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
819                 MyWritePrivateProfileInt(_T("Qt"), _T("H264Subme"), config.video_h264_subme, config_path);
820                 
821                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
822                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
823                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
824                 MyWritePrivateProfileInt(_T("Qt"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
825                 
826                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoThreads"), config.video_threads, config_path);
827                 MyWritePrivateProfileInt(_T("Qt"), _T("AudioBitrate"), config.audio_bitrate, config_path);
828                 MyWritePrivateProfileInt(_T("Qt"), _T("VideoFramerate"), config.video_frame_rate, config_path);
829                 
830                 MyWritePrivateProfileBool(_T("Qt"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
831                 MyWritePrivateProfileBool(_T("Qt"), _T("WriteToConsole"), config.log_to_console, config_path);
832                 
833                 for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; ii++) {
834                         uint32_t flags = 0;
835                         flags = 0;
836                         for(int jj = 0; jj < 8; jj++) {
837                                 flags <<= 1;
838                                 if(config.dev_log_to_syslog[ii][jj]) flags |= 0x0001;
839                         }
840                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("SyslogEnabled%d"), ii), flags, config_path);
841                         
842                         flags = 0;
843                         for(int jj = 0; jj < 8; jj++) {
844                                 flags <<= 1;
845                                 if(config.dev_log_to_console[ii][jj]) flags |= 0x0001;
846                         }
847                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("ConsoleLogEnabled%d"), ii), flags, config_path);
848                         
849                         flags = 0;
850                         for(int jj = 0; jj < 8; jj++) {
851                                 flags <<= 1;
852                                 if(config.dev_log_recording[ii][jj]) flags |= 0x0001;
853                         }
854                         MyWritePrivateProfileInt(_T("Qt"), create_string(_T("RecordLogEnabled%d"), ii), flags, config_path);
855                 }
856                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToConsole"), config.state_log_to_console, config_path);
857                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToSyslog"), config.state_log_to_syslog, config_path);
858                 MyWritePrivateProfileBool(_T("Qt"), _T("StateLogToRecording"), config.state_log_to_recording, config_path);
859                 
860                 MyWritePrivateProfileInt(_T("Qt"), _T("UiVirtualMediaPosition"), config.virtual_media_position, config_path);
861                 //csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Write config done.");
862         #endif  
863 }
864
865 #define STATE_VERSION   6
866
867 void save_config_state(void *f)
868 {
869         FILEIO *state_fio = (FILEIO *)f;
870         
871         state_fio->FputUint32(STATE_VERSION);
872         
873         #ifdef USE_BOOT_MODE
874                 state_fio->FputInt32(config.boot_mode);
875         #endif
876         #ifdef USE_CPU_TYPE
877                 state_fio->FputInt32(config.cpu_type);
878         #endif
879         #ifdef USE_DIPSWITCH
880                 state_fio->FputUint32(config.dipswitch);
881         #endif
882         #ifdef USE_DEVICE_TYPE
883                 state_fio->FputInt32(config.device_type);
884         #endif
885         #ifdef USE_DRIVE_TYPE
886                 state_fio->FputInt32(config.drive_type);
887         #endif
888         #ifdef USE_KEYBOARD_TYPE
889                 state_fio->FputInt32(config.keyboard_type);
890         #endif
891         #ifdef USE_MOUSE_TYPE
892                 state_fio->FputInt32(config.mouse_type);
893         #endif
894         #ifdef USE_JOYSTICK_TYPE
895                 state_fio->FputInt32(config.joystick_type);
896         #endif
897         #ifdef USE_SOUND_TYPE
898                 state_fio->FputInt32(config.sound_type);
899         #endif
900         #ifdef USE_MONITOR_TYPE
901                 state_fio->FputInt32(config.monitor_type);
902         #endif
903         #ifdef USE_PRINTER_TYPE
904                 state_fio->FputInt32(config.printer_type);
905         #endif
906         #ifdef USE_FLOPPY_DISK
907                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
908                         state_fio->FputBool(config.correct_disk_timing[drv]);
909                         state_fio->FputBool(config.ignore_disk_crc[drv]);
910                 }
911         #endif
912         state_fio->FputInt32(config.sound_frequency);
913         state_fio->FputInt32(config.sound_latency);
914 }
915
916 bool load_config_state(void *f)
917 {
918         FILEIO *state_fio = (FILEIO *)f;
919         
920         if(state_fio->FgetUint32() != STATE_VERSION) {
921                 return false;
922         }
923         #ifdef USE_BOOT_MODE
924                 config.boot_mode = state_fio->FgetInt32();
925         #endif
926         #ifdef USE_CPU_TYPE
927                 config.cpu_type = state_fio->FgetInt32();
928         #endif
929         #ifdef USE_DIPSWITCH
930                 config.dipswitch = state_fio->FgetUint32();
931         #endif
932         #ifdef USE_DEVICE_TYPE
933                 config.device_type = state_fio->FgetInt32();
934         #endif
935         #ifdef USE_DRIVE_TYPE
936                 config.drive_type = state_fio->FgetInt32();
937         #endif
938         #ifdef USE_KEYBOARD_TYPE
939                 config.keyboard_type = state_fio->FgetInt32();
940         #endif
941         #ifdef USE_MOUSE_TYPE
942                 config.mouse_type = state_fio->FgetInt32();
943         #endif
944         #ifdef USE_JOYSTICK_TYPE
945                 config.joystick_type = state_fio->FgetInt32();
946         #endif
947         #ifdef USE_SOUND_TYPE
948                 config.sound_type = state_fio->FgetInt32();
949         #endif
950         #ifdef USE_MONITOR_TYPE
951                 config.monitor_type = state_fio->FgetInt32();
952         #endif
953         #ifdef USE_PRINTER_TYPE
954                 config.printer_type = state_fio->FgetInt32();
955         #endif
956         #ifdef USE_FLOPPY_DISK
957                 for(int drv = 0; drv < USE_FLOPPY_DISK; drv++) {
958                         config.correct_disk_timing[drv] = state_fio->FgetBool();
959                         config.ignore_disk_crc[drv] = state_fio->FgetBool();
960                 }
961         #endif
962         config.sound_frequency = state_fio->FgetInt32();
963         config.sound_latency = state_fio->FgetInt32();
964         return true;
965 }
966