OSDN Git Service

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