OSDN Git Service

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