OSDN Git Service

[VM][DATAREC][FDD] Add sounds of SEEK/CMT, excepts either pseudo devices / bios.
[csp-qt/common_source_project-fm7.git] / source / src / config.cpp
index 9b53ee2..6dd9efd 100644 (file)
@@ -6,20 +6,11 @@
 
        [ config ]
 */
-#if defined(_USE_AGAR)
-#include <SDL/SDL.h>
-#include <agar/core.h>
-#include <string>
-#include <vector>
-#include "fileio.h"
-#include "agar_logger.h"
-#endif
-
 #if defined(_USE_QT)
 #include <string>
 #include <vector>
 #include "fileio.h"
-#include "agar_logger.h"
+#include "csp_logger.h"
 #include "qt_main.h"
 # if defined(Q_OS_WIN)
 # include <windows.h>
@@ -45,15 +36,12 @@ config_t config;
 BOOL MyWritePrivateProfileInt(LPCTSTR lpAppName, LPCTSTR lpKeyName, int Value, LPCTSTR lpFileName)
 {
        _TCHAR String[32];
-       my_stprintf_s(String, 32, _T("%d"), Value);
-       return MyWritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
+       return MyWritePrivateProfileString(lpAppName, lpKeyName, create_string(_T("%d"), Value), lpFileName);
 }
  
 BOOL MyWritePrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool Value, LPCTSTR lpFileName)
 {
-       _TCHAR String[32];
-       my_stprintf_s(String, 32, _T("%d"), Value ? 1 : 0);
-       return MyWritePrivateProfileString(lpAppName, lpKeyName, String, lpFileName);
+       return MyWritePrivateProfileString(lpAppName, lpKeyName, create_string(_T("%d"), Value ? 1 : 0), lpFileName);
 }
  
 bool MyGetPrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool bDefault, LPCTSTR lpFileName)
@@ -61,7 +49,7 @@ bool MyGetPrivateProfileBool(LPCTSTR lpAppName, LPCTSTR lpKeyName, bool bDefault
        return (MyGetPrivateProfileInt(lpAppName, lpKeyName, bDefault ? 1 : 0, lpFileName) != 0);
 }
 
-void init_config()
+void initialize_config()
 {
        int i;
        // initial settings
@@ -106,7 +94,11 @@ void init_config()
 #endif
 
        // sound
+#if defined(SOUND_RATE_DEFAULT)
+       config.sound_frequency = SOUND_RATE_DEFAULT;
+#else
        config.sound_frequency = 6;     // 48KHz
+#endif
        config.sound_latency = 1;       // 100msec
        config.general_sound_level = 0;
 #if defined(USE_SOUND_DEVICE_TYPE) && defined(SOUND_DEVICE_TYPE_DEFAULT)
@@ -121,25 +113,47 @@ void init_config()
        config.disable_dwm = false;
 #endif
        config.keyboard_type = 0;
+#ifdef USE_JOYSTICK
        for(int i = 0; i < 4; i++) {
                for(int j = 0; j < 16; j++) {
                        config.joy_buttons[i][j] = (i << 4) | j;
                }
        }
-       
+#endif 
        // printer
 #if defined(USE_PRINTER) && defined(PRINTER_DEVICE_TYPE_DEFAULT)
        config.printer_device_type = PRINTER_DEVICE_TYPE_DEFAULT;
 #elif defined(USE_PRINTER)
        config.printer_device_type = 0;
 #endif
+#if defined(USE_QT)
+       config.video_width = 640;
+       config.video_height = 480;
+       config.video_codec_type = 0; // MPEG4
+       
+       config.video_h264_bitrate = 512;
+       config.video_h264_bframes = 4;
+       config.video_h264_b_adapt = 2;
+       config.video_h264_minq = 14;
+       config.video_h264_maxq = 25;
+       config.video_h264_subme = 8;
        
+       config.video_mpeg4_bitrate = 512;
+       config.video_mpeg4_bframes = 4;
+       config.video_mpeg4_minq = 1;
+       config.video_mpeg4_maxq = 20;
+       
+       config.audio_codec_type = 0;
+       config.video_threads = 0;
+       config.audio_bitrate = 160;
+       config.video_frame_rate = 30;
+#endif
        // screen
 #ifndef ONE_BOARD_MICRO_COMPUTER
 #ifdef _WIN32
        config.use_d3d9 = true;
 #endif
-       config.stretch_type = 1;        // Stretch (Aspect)
+       config.fullscreen_stretch_type = 1;     // Stretch (Aspect)
 #endif
        
 #if defined(_USE_QT)
@@ -148,6 +162,9 @@ void init_config()
        config.opengl_scanline_horiz = false;
        config.use_opengl_filters = false;
        config.opengl_filter_num = 0;
+
+       config.log_to_syslog = false;
+       config.log_to_console = true;
 #endif 
 }
 
@@ -155,7 +172,7 @@ void load_config(const _TCHAR *config_path)
 {
        int drv, i;
        // initial settings
-       init_config();
+       initialize_config();
 
        // control
 #ifdef USE_BOOT_MODE
@@ -175,15 +192,9 @@ void load_config(const _TCHAR *config_path)
 #endif
 #ifdef USE_FD1
        {
-               _TCHAR name[64];
                for(drv = 0; drv < MAX_FD; drv++) {
-                       memset(name, 0x00, sizeof(name));
-                       my_stprintf_s(name, 64, _T("CorrectDiskTiming%d"), drv + 1);
-                       config.correct_disk_timing[drv] = MyGetPrivateProfileBool(_T("Control"), (const _TCHAR *)name,
-                                                                                                                                       config.correct_disk_timing[drv], config_path);
-                       my_stprintf_s(name, 64, _T("IgnoreDiskCRC%d"), drv + 1);
-                       config.ignore_disk_crc[drv] = MyGetPrivateProfileBool(_T("Control"), (const _TCHAR *)name,
-                                                                                                                               config.ignore_disk_crc[drv], config_path);
+               config.correct_disk_timing[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("CorrectDiskTiming%d"), drv + 1), config.correct_disk_timing[drv], config_path);
+               config.ignore_disk_crc[drv] = MyGetPrivateProfileBool(_T("Control"), create_string(_T("IgnoreDiskCRC%d"), drv + 1), config.ignore_disk_crc[drv], config_path);
                }
        }
 #endif
@@ -200,35 +211,24 @@ void load_config(const _TCHAR *config_path)
        MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), _T(""), config.initial_cart_dir, _MAX_PATH, config_path);
        for(drv = 0; drv < MAX_CART; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
-                       MyGetPrivateProfileString(_T("RecentFiles"), name, _T(""),
-                                                                       config.recent_cart_path[drv][i], _MAX_PATH, config_path);
+                       MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCartPath%d_%d"), drv + 1, i + 1), _T(""), config.recent_cart_path[drv][i], _MAX_PATH, config_path);
                }
        }
 #endif
 #ifdef USE_FD1
-       MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""),
-                                                       config.initial_disk_dir, _MAX_PATH, config_path);
+       MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), _T(""), config.initial_floppy_disk_dir, _MAX_PATH, config_path);
     //    get_parent_dir(config.initial_disk_dir);
        for(drv = 0; drv < MAX_FD; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
-                       MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                       _T(""), config.recent_disk_path[drv][i], _MAX_PATH, config_path);
+                       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);
                }
        }
 #endif
 #ifdef USE_QD1
-       MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"),
-                                                       _T(""), config.initial_quickdisk_dir, _MAX_PATH, config_path);
+       MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), _T(""), config.initial_quick_disk_dir, _MAX_PATH, config_path);
        for(drv = 0; drv < MAX_QD; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
-                       MyGetPrivateProfileString(_T("RecentFiles"), name, _T(""),
-                                                                       config.recent_quickdisk_path[drv][i], _MAX_PATH, config_path);
+                       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);
                }
        }
 #endif
@@ -237,10 +237,7 @@ void load_config(const _TCHAR *config_path)
        MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), _T(""),
                                                        config.initial_tape_dir, _MAX_PATH, config_path);
        for(i = 0; i < MAX_HISTORY; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
-               MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
-                                                               config.recent_tape_path[i], _MAX_PATH, config_path);
+               MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath1_%d"), i + 1), _T(""), config.recent_tape_path[i], _MAX_PATH, config_path);
        }
 #endif
 
@@ -248,10 +245,7 @@ void load_config(const _TCHAR *config_path)
        MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), _T(""),
                                                        config.initial_laser_disc_dir, _MAX_PATH, config_path);
        for(int i = 0; i < MAX_HISTORY; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
-               MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
-                                                               config.recent_laser_disc_path[i], _MAX_PATH, config_path);
+               MyGetPrivateProfileString(_T("RecentFiles"), create_string(_T("RecentLaserDiscPath1_%d"), i + 1), _T(""), config.recent_laser_disc_path[i], _MAX_PATH, config_path);
        }
 #endif
 #ifdef USE_BINARY_FILE1
@@ -266,6 +260,18 @@ void load_config(const _TCHAR *config_path)
                }
        }
 #endif
+#if defined(USE_BUBBLE1)
+       MyGetPrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), _T(""),
+                                                       config.initial_bubble_casette_dir, _MAX_PATH, config_path);
+       for(drv = 0; drv < MAX_BUBBLE; drv++) {
+               for(i = 0; i < MAX_HISTORY; i++) {
+                       _TCHAR name[64];
+                       my_stprintf_s(name, 64, _T("RecentBubblePath%d_%d"), drv + 1, i + 1);
+                       MyGetPrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, _T(""),
+                                                                       config.recent_bubble_casette_path[drv][i], _MAX_PATH, config_path);
+               }
+       }
+#endif
        
        // screen
 #ifndef ONE_BOARD_MICRO_COMPUTER
@@ -274,7 +280,10 @@ void load_config(const _TCHAR *config_path)
        config.use_d3d9 = MyGetPrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
        config.wait_vsync = MyGetPrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
 #endif
-       config.stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
+//-    config.stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
+       config.window_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
+       config.fullscreen_stretch_type = MyGetPrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
+
 #else
        config.window_mode = MyGetPrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
 #endif
@@ -311,33 +320,33 @@ void load_config(const _TCHAR *config_path)
 #endif
 #ifdef USE_SOUND_VOLUME
        for(int i = 0; i < USE_SOUND_VOLUME; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("VolumeLeft%d"), i + 1);
-               int tmp_l = MyGetPrivateProfileInt(_T("Sound"), name, config.sound_volume_l[i], config_path);
-               my_stprintf_s(name, 64, _T("VolumeRight%d"), i + 1);
-               int tmp_r = MyGetPrivateProfileInt(_T("Sound"), name, config.sound_volume_r[i], config_path);
+               int tmp_l = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
+               int tmp_r = MyGetPrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
+#ifdef _USE_QT
+               // Note: when using balance , levels are -40±20db to 0±20db.
+               config.sound_volume_l[i] = max(-60, min(20, tmp_l));
+               config.sound_volume_r[i] = max(-60, min(20, tmp_r));
+#else
                config.sound_volume_l[i] = max(-40, min(0, tmp_l));
                config.sound_volume_r[i] = max(-40, min(0, tmp_r));
+#endif
        }
 #endif
-#if !defined(_USE_QT)
        MyGetPrivateProfileString(_T("Sound"), _T("FMGenDll"), _T("mamefm.dll"), config.fmgen_dll_path, _MAX_PATH, config_path);
-#endif 
+       config.general_sound_level = MyGetPrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
        // input
-       config.general_sound_level = MyGetPrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
-                                                                                                         config.general_sound_level, config_path);
 #ifdef _WIN32
        config.use_direct_input = MyGetPrivateProfileBool(_T("Input"), _T("UseDirectInput"), config.use_direct_input, config_path);
        config.disable_dwm = MyGetPrivateProfileBool(_T("Input"), _T("DisableDwm"), config.disable_dwm, config_path);
 #endif
        config.keyboard_type = MyGetPrivateProfileInt(_T("Input"), _T("KeyboardType"), config.keyboard_type, config_path);
+#ifdef USE_JOYSTICK
        for(int i = 0; i < 4; i++) {
                for(int j = 0; j < 16; j++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("JoyButtons%d_%d"), i + 1, j + 1);
-                       config.joy_buttons[i][j] = MyGetPrivateProfileInt(_T("Input"), name, config.joy_buttons[i][j], config_path);
+                       config.joy_buttons[i][j] = MyGetPrivateProfileInt(_T("Input"), create_string(_T("JoyButtons%d_%d"), i + 1, j + 1), config.joy_buttons[i][j], config_path);
                }
        }
+#endif   
 #if defined(_USE_QT)
        for(i = 0; i < 16; i++) {
                _TCHAR name[256];
@@ -351,8 +360,105 @@ void load_config(const _TCHAR *config_path)
        config.printer_device_type = MyGetPrivateProfileInt(_T("Printer"), _T("DeviceType"), config.printer_device_type, config_path);
        MyGetPrivateProfileString(_T("Printer"), _T("PrinterDll"), _T("printer.dll"), config.printer_dll_path, _MAX_PATH, config_path);
 #endif
-#if defined(_USE_QT) && !defined(Q_OS_WIN)
-       AGAR_DebugLog(AGAR_LOG_INFO, "Read Done.");
+#if defined(_USE_QT)
+       config.video_width   = MyGetPrivateProfileInt(_T("Video"), _T("VideoWidth"), config.video_width, config_path);
+       if(config.video_width < 128) config.video_width = 128;
+       config.video_height  = MyGetPrivateProfileInt(_T("Video"), _T("VideoHeight"), config.video_height, config_path);
+       if(config.video_height < 80) config.video_height = 80;
+       
+       config.video_codec_type = MyGetPrivateProfileInt(_T("Video"), _T("VideoCodecType"), config.video_codec_type, config_path);
+       if(config.video_codec_type > 1) config.video_codec_type = 1;
+       if(config.video_codec_type < 0) config.video_codec_type = 0;
+       
+       config.audio_codec_type = MyGetPrivateProfileInt(_T("Video"), _T("AudioCodecType"), config.audio_codec_type, config_path);
+       if(config.video_codec_type > 2) config.audio_codec_type = 2;
+       if(config.video_codec_type < 0) config.audio_codec_type = 0;
+       
+       config.video_h264_bitrate = MyGetPrivateProfileInt(_T("Video"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
+       if(config.video_h264_bitrate < 64) config.video_h264_bitrate = 64;
+
+       config.video_h264_bframes = MyGetPrivateProfileInt(_T("Video"), _T("H264BFrames"), config.video_h264_bframes, config_path);
+       if(config.video_h264_bframes < 0) config.video_h264_bframes = 0;
+       if(config.video_h264_bframes > 10) config.video_h264_bframes = 10;
+
+       config.video_h264_b_adapt = MyGetPrivateProfileInt(_T("Video"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
+       if(config.video_h264_b_adapt < 0) config.video_h264_b_adapt = 0;
+       if(config.video_h264_b_adapt > 2) config.video_h264_b_adapt = 2;
+       
+       config.video_h264_subme   = MyGetPrivateProfileInt(_T("Video"), _T("H264Subme"), config.video_h264_subme, config_path);
+       if(config.video_h264_subme < 0) config.video_h264_subme = 0;
+       if(config.video_h264_subme > 11) config.video_h264_subme = 11;
+
+       config.video_h264_minq   = MyGetPrivateProfileInt(_T("Video"), _T("H264MinQ"), config.video_h264_minq, config_path);
+       if(config.video_h264_minq < 0) config.video_h264_minq = 0;
+       if(config.video_h264_minq > 63) config.video_h264_minq = 63;
+
+       config.video_h264_maxq   = MyGetPrivateProfileInt(_T("Video"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
+       if(config.video_h264_maxq < 0) config.video_h264_maxq = 0;
+       if(config.video_h264_maxq > 63) config.video_h264_maxq = 63;
+       
+       config.video_mpeg4_bitrate = MyGetPrivateProfileInt(_T("Video"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
+       if(config.video_mpeg4_bitrate < 64) config.video_mpeg4_bitrate = 64;
+
+       config.video_mpeg4_bframes = MyGetPrivateProfileInt(_T("Video"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
+       if(config.video_mpeg4_bframes < 0) config.video_mpeg4_bframes = 0;
+       if(config.video_mpeg4_bframes > 10) config.video_mpeg4_bframes = 10;
+
+       config.video_mpeg4_minq   = MyGetPrivateProfileInt(_T("Video"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
+       if(config.video_mpeg4_minq < 1) config.video_mpeg4_minq = 1;
+       if(config.video_mpeg4_minq > 31) config.video_mpeg4_minq = 31;
+
+       config.video_mpeg4_maxq   = MyGetPrivateProfileInt(_T("Video"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
+       if(config.video_mpeg4_maxq < 1) config.video_mpeg4_maxq = 1;
+       if(config.video_mpeg4_maxq > 31) config.video_mpeg4_maxq = 31;
+       if(config.video_mpeg4_maxq < config.video_mpeg4_minq) {
+               int n;
+               n = config.video_mpeg4_maxq;
+               config.video_mpeg4_maxq  = config.video_mpeg4_minq;
+               config.video_mpeg4_minq = n;
+       }
+
+       config.video_threads = MyGetPrivateProfileInt(_T("Video"), _T("VideoThreads"), config.video_threads, config_path);
+       if(config.video_threads < 0) config.video_threads = 0;
+       if(config.video_threads > 16) config.video_threads = 16;
+       
+       config.audio_bitrate = MyGetPrivateProfileInt(_T("Video"), _T("AudioBitrate"), config.audio_bitrate, config_path);
+       if(config.audio_bitrate < 16) config.audio_bitrate = 16;
+       if(config.audio_bitrate > 448) config.audio_bitrate = 448;
+       
+       config.video_frame_rate = MyGetPrivateProfileInt(_T("Video"), _T("VideoFramerate"), config.video_frame_rate, config_path);
+       if(config.video_frame_rate < 15) config.video_frame_rate = 15;
+       if(config.video_frame_rate > 75) config.video_frame_rate = 75;
+
+#endif 
+#if defined(_USE_QT)
+       config.log_to_syslog = MyGetPrivateProfileBool(_T("Emulator"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
+       config.log_to_console = MyGetPrivateProfileBool(_T("Emulator"), _T("WriteToConsole"), config.log_to_console, config_path);
+       for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); ii++) {
+               uint32_t flags = 0;
+               flags = MyGetPrivateProfileInt(_T("Emulator"), create_string(_T("SyslogEnabled%d"), ii), 0x0000, config_path);
+               for(int jj = 0; jj < 8; jj++) {
+                       config.dev_log_to_syslog[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
+                       csp_logger->set_device_node_log(ii, 1, jj, config.dev_log_to_syslog[ii][jj]);
+                       flags >>= 1;
+               }
+               flags = 0;
+               flags = MyGetPrivateProfileInt(_T("Emulator"), create_string(_T("ConsoleLogEnabled%d"), ii), 0xffff, config_path);
+               for(int jj = 0; jj < 8; jj++) {
+                       config.dev_log_to_console[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
+                       csp_logger->set_device_node_log(ii, 2, jj, config.dev_log_to_console[ii][jj]);
+                       flags >>= 1;
+               }
+               flags = MyGetPrivateProfileInt(_T("Emulator"), create_string(_T("RecordLogEnabled%d"), ii), 0xffff, config_path);
+               for(int jj = 0; jj < 8; jj++) {
+                       config.dev_log_recording[ii][jj] = ((flags & 0x0001) != 0) ? true : false;
+                       csp_logger->set_device_node_log(ii, 0, jj, config.dev_log_recording[ii][jj]);
+                       flags >>= 1;
+               }
+       }
+#endif
+#if defined(_USE_QT)
+       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Read config done.");
 #endif
 }
 
@@ -389,13 +495,9 @@ void save_config(const _TCHAR *config_path)
 #endif
 #ifdef USE_FD1
        {
-               _TCHAR name[64];
                for(drv = 0; drv < MAX_FD; drv++) {
-                       memset(name, 0x00, sizeof(name));
-                       my_stprintf_s(name, 64, _T("CorrectDiskTiming%d"), drv + 1);
-                       MyWritePrivateProfileBool(_T("Control"), (const _TCHAR *)name, config.correct_disk_timing[drv], config_path);
-                       my_stprintf_s(name, 64, _T("IgnoreDiskCRC%d"), drv + 1);
-                       MyWritePrivateProfileBool(_T("Control"), (const _TCHAR *)name, config.ignore_disk_crc[drv], config_path);
+               MyWritePrivateProfileBool(_T("Control"), create_string(_T("CorrectDiskTiming%d"), drv + 1), config.correct_disk_timing[drv], config_path);
+               MyWritePrivateProfileBool(_T("Control"), create_string(_T("IgnoreDiskCRC%d"), drv + 1), config.ignore_disk_crc[drv], config_path);
                }
        }
 
@@ -412,64 +514,67 @@ void save_config(const _TCHAR *config_path)
        MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCartDir"), config.initial_cart_dir, config_path);
        for(drv = 0; drv < MAX_CART; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentCartPath%d_%d"), drv + 1, i + 1);
-                       MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name, config.recent_cart_path[drv][i], config_path);
+                       MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCartPath%d_%d"), drv + 1, i + 1), config.recent_cart_path[drv][i], config_path);
                }
        }
 #endif
 #ifdef USE_FD1
-       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_disk_dir, config_path);
+       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialDiskDir"), config.initial_floppy_disk_dir, config_path);
        for(drv = 0; drv < MAX_FD; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentDiskPath%d_%d"), drv + 1, i + 1);
-                       MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                         config.recent_disk_path[drv][i], config_path);
+                       MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentDiskPath%d_%d"), drv + 1, i + 1), config.recent_floppy_disk_path[drv][i], config_path);
                }
        }
 #endif
 #ifdef USE_QD1
-       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"),
-                                                         config.initial_quickdisk_dir, config_path);
+       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialQuickDiskDir"), config.initial_quick_disk_dir, config_path);
        for(drv = 0; drv < MAX_QD; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1);
-                       MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                         config.recent_quickdisk_path[drv][i], config_path);
+                       MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentQuickDiskPath%d_%d"), drv + 1, i + 1), config.recent_quick_disk_path[drv][i], config_path);
                }
        }
 #endif
 #ifdef USE_TAPE
        MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialTapeDir"), config.initial_tape_dir, config_path);
        for(i = 0; i < MAX_HISTORY; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("RecentTapePath1_%d"), i + 1);
-               MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                 config.recent_tape_path[i], config_path);
+               MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentTapePath1_%d"), i + 1), config.recent_tape_path[i], config_path);
+       }
+#endif
+#ifdef USE_COMPACT_DISC
+       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialCompactDiscDir"), config.initial_compact_disc_dir, config_path);
+       for(int i = 0; i < MAX_HISTORY; i++) {
+               MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentCompactDiscPath1_%d"), i + 1), config.recent_compact_disc_path[i], config_path);
        }
 #endif
 #ifdef USE_LASER_DISC
        MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialLaserDiscDir"), config.initial_laser_disc_dir, config_path);
        for(int i = 0; i < MAX_HISTORY; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("RecentLaserDiscPath1_%d"), i + 1);
-               MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                 config.recent_laser_disc_path[i], config_path);
+               MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentLaserDiscPath1_%d"), i + 1), config.recent_laser_disc_path[i], config_path);
        }
 #endif
 #ifdef USE_BINARY_FILE1
        MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBinaryDir"), config.initial_binary_dir, config_path);
        for(drv = 0; drv < MAX_BINARY; drv++) {
                for(i = 0; i < MAX_HISTORY; i++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("RecentBinaryPath%d_%d"), drv + 1, i + 1);
-                       MyWritePrivateProfileString(_T("RecentFiles"), (const _TCHAR *)name,
-                                                                         config.recent_binary_path[drv][i], config_path);
+                       MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBinaryPath%d_%d"), drv + 1, i + 1), config.recent_binary_path[drv][i], config_path);
+               }
+       }
+#endif
+#if defined(USE_BUBBLE1)
+       MyWritePrivateProfileString(_T("RecentFiles"), _T("InitialBubbleDir"), config.initial_bubble_casette_dir, config_path);
+       for(drv = 0; drv < MAX_BUBBLE; drv++) {
+               for(i = 0; i < MAX_HISTORY; i++) {
+                       MyWritePrivateProfileString(_T("RecentFiles"), create_string(_T("RecentBubblePath%d_%d"), drv + 1, i + 1), config.recent_bubble_casette_path[drv][i], config_path);                     
                }
        }
 #endif
+#if defined(_USE_QT)
+       config.use_opengl_scanline = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLScanLine"), config.use_opengl_scanline, config_path);
+       config.opengl_scanline_vert = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineVert"), config.opengl_scanline_vert, config_path);;
+       config.opengl_scanline_horiz = MyGetPrivateProfileBool(_T("Screen"), _T("OpenGLScanLineHoriz"), config.opengl_scanline_horiz, config_path);;
+       config.use_opengl_filters = MyGetPrivateProfileBool(_T("Screen"), _T("UseOpenGLFilters"), config.use_opengl_filters, config_path);
+       config.opengl_filter_num = MyGetPrivateProfileInt(_T("Screen"), _T("OpenGLFilterNum"), config.opengl_filter_num, config_path);
+#endif
        
        // screen
 #ifndef ONE_BOARD_MICRO_COMPUTER
@@ -478,7 +583,10 @@ void save_config(const _TCHAR *config_path)
        MyWritePrivateProfileBool(_T("Screen"), _T("UseD3D9"), config.use_d3d9, config_path);
        MyWritePrivateProfileBool(_T("Screen"), _T("WaitVSync"), config.wait_vsync, config_path);
 #endif
-       MyWritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
+       //MyWritePrivateProfileInt(_T("Screen"), _T("StretchType"), config.stretch_type, config_path);
+       MyWritePrivateProfileInt(_T("Screen"), _T("WindowStretchType"), config.window_stretch_type, config_path);
+       MyWritePrivateProfileInt(_T("Screen"), _T("FullScreenStretchType"), config.fullscreen_stretch_type, config_path);
+
 #else
        MyWritePrivateProfileInt(_T("Screen"), _T("WindowMode"), config.window_mode, config_path);
 #endif
@@ -515,31 +623,26 @@ void save_config(const _TCHAR *config_path)
 #endif
 #ifdef USE_SOUND_VOLUME
        for(int i = 0; i < USE_SOUND_VOLUME; i++) {
-               _TCHAR name[64];
-               my_stprintf_s(name, 64, _T("VolumeLeft%d"), i + 1);
-               MyWritePrivateProfileInt(_T("Sound"), name, config.sound_volume_l[i], config_path);
-               my_stprintf_s(name, 64, _T("VolumeRight%d"), i + 1);
-               MyWritePrivateProfileInt(_T("Sound"), name, config.sound_volume_r[i], config_path);
+               MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeLeft%d"), i + 1), config.sound_volume_l[i], config_path);
+               MyWritePrivateProfileInt(_T("Sound"), create_string(_T("VolumeRight%d"), i + 1), config.sound_volume_r[i], config_path);
        }
 #endif
-#if !defined(_USE_QT)
+
        MyWritePrivateProfileString(_T("Sound"), _T("FMGenDll"), config.fmgen_dll_path, config_path);
-#endif 
-       MyWritePrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"),
-                                                  config.general_sound_level, config_path);
+       MyWritePrivateProfileInt(_T("Sound"), _T("GeneralSoundLevel"), config.general_sound_level, config_path);
        // input
 #ifdef _WIN32
        MyWritePrivateProfileBool(_T("Input"), _T("UseDirectInput"), config.use_direct_input, config_path);
        MyWritePrivateProfileBool(_T("Input"), _T("DisableDwm"), config.disable_dwm, config_path);
 #endif
        MyWritePrivateProfileInt(_T("Input"), _T("KeyboardType"), config.keyboard_type, config_path);
+#ifdef USE_JOYSTICK   
        for(int i = 0; i < 4; i++) {
                for(int j = 0; j < 16; j++) {
-                       _TCHAR name[64];
-                       my_stprintf_s(name, 64, _T("JoyButtons%d_%d"), i + 1, j + 1);
-                       MyWritePrivateProfileInt(_T("Input"), name, config.joy_buttons[i][j], config_path);
+                       MyWritePrivateProfileInt(_T("Input"), create_string(_T("JoyButtons%d_%d"), i + 1, j + 1), config.joy_buttons[i][j], config_path);
                }
        }
+#endif   
 #if defined(_USE_QT)
        for(i = 0; i < 16; i++) {
                _TCHAR name[256];
@@ -553,9 +656,61 @@ void save_config(const _TCHAR *config_path)
 #ifdef USE_PRINTER
        MyWritePrivateProfileInt(_T("Printer"), _T("DeviceType"), config.printer_device_type, config_path);
 #endif
+#if defined(_USE_QT)
+       MyWritePrivateProfileInt(_T("Video"), _T("VideoWidth"), config.video_width, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("VideoHeight"), config.video_height, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("VideoCodecType"), config.video_codec_type, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("AudioCodecType"), config.audio_codec_type, config_path);
+       
+       MyWritePrivateProfileInt(_T("Video"), _T("H264Bitrate"), config.video_h264_bitrate, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("H264BFrames"), config.video_h264_bframes, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("H264BAdapt"), config.video_h264_b_adapt, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("H264MinQ"), config.video_h264_minq, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("H264MaxQ"), config.video_h264_maxq, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("H264Subme"), config.video_h264_subme, config_path);
+       
+       MyWritePrivateProfileInt(_T("Video"), _T("MPEG4Bitrate"), config.video_mpeg4_bitrate, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("MPEG4BFrames"), config.video_mpeg4_bframes, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("MPEG4MinQ"), config.video_mpeg4_minq, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("MPEG4MaxQ"), config.video_mpeg4_maxq, config_path);
+       
+       MyWritePrivateProfileInt(_T("Video"), _T("VideoThreads"), config.video_threads, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("AudioBitrate"), config.audio_bitrate, config_path);
+       MyWritePrivateProfileInt(_T("Video"), _T("VideoFramerate"), config.video_frame_rate, config_path);
+#endif 
+#if defined(_USE_QT)
+       MyWritePrivateProfileBool(_T("Emulator"), _T("WriteToSyslog"), config.log_to_syslog, config_path);
+       MyWritePrivateProfileBool(_T("Emulator"), _T("WriteToConsole"), config.log_to_console, config_path);
+       
+       for(int ii = 0; ii < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); ii++) {
+               uint32_t flags = 0;
+               flags = 0;
+               for(int jj = 0; jj < 8; jj++) {
+                       flags <<= 1;
+                       if(config.dev_log_to_syslog[ii][jj]) flags |= 0x0001;
+               }
+               flags = MyWritePrivateProfileInt(_T("Emulator"), create_string(_T("SyslogEnabled%d"), ii), flags, config_path);
+
+               flags = 0;
+               for(int jj = 0; jj < 8; jj++) {
+                       flags <<= 1;
+                       if(config.dev_log_to_console[ii][jj]) flags |= 0x0001;
+               }
+               flags = MyWritePrivateProfileInt(_T("Emulator"), create_string(_T("ConsoleLogEnabled%d"), ii), flags, config_path);
+
+               flags = 0;
+               for(int jj = 0; jj < 8; jj++) {
+                       flags <<= 1;
+                       if(config.dev_log_recording[ii][jj]) flags |= 0x0001;
+               }
+               flags = MyWritePrivateProfileInt(_T("Emulator"), create_string(_T("RecordLogEnabled%d"), ii), flags, config_path);
+       }
+#endif
 #if defined(_USE_QT) && !defined(Q_OS_WIN)
-       AGAR_DebugLog(AGAR_LOG_INFO, "Write done.");
+       csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Write config done.");
 #endif
+
+       
 }
 
 #define STATE_VERSION  5