OSDN Git Service

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