From 07a05f0e52d55768ddda27fc78a30b36c14afbbe Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Tue, 7 Aug 2018 02:30:07 -0500 Subject: [PATCH] Use settings ini file method (#1370) * Import SimpleIni module * Rename XBController to DInputController Since it's only about configure DirectInput support. * Append to previous 2 commits * Initialize Settings class * Append to previous commit * Properly use EmuXTL header instead of EmuShared * Move audio variables into setting class * Move video variables into Settings class * Append to previous commit * Move hack variables into Settings class * Append previous commit * Append to third previous commit * Move xbox controller port map to Settings class * Append to second previous commit * Move DirectInput Controller map to Settings class * Remove old XInput member variable * Append to second previous commit * Tiny Fixup * Remove Load/Save from EmuShared class * Move both GUI and emulate/core to Settings class * Oops, append to DirectInput controller's commit(s) * Fix spaces to tab plus remove useless extra spaces * Code format fixes * Fix EmuShared's Set____ function to include const type. Then "set" functions are supportive for both const and non-const variables. * Add Sync and GetDataLocation functions to Settings class * Move include filesystem into root header file. * Introduce Verify function in Settings class * Fix old bug for console remains open * Making some adjustments... * Append * Another fix for any output prints crash. * Add Delete function to Settings class Plus keep save's file path if has given one. * Fix LLE_USB to set into Settings class' member variable. * No longer rely on GUI's end to reset LLE flags for multi-xbe titles. * Simulate what GUI will do except in standalone kernel mode support. * Move m_StorageLocation into Settings class as central. Plus optimization for GetDataLocation function. * Update sentence... * Remove m_XbePath from EmuShared class. Since kernel process is launching by on its own without rely on GUI process. * Update copyright * Fix DirectInput config not responding message * Implement new feature: Bypass running as admin warning message * Rename Emulate Settings to Core Settings Plus move AllowAdminPrivilage option to core. * Add reserve space for Settings' structure to integrate into EmuShared * Ensure all reserves are set to 0 by default. * Append to "Rename Emulate Settings to Core Settings" commit * Fix rebase loss. * Fix kernel mode process's window screen * Correction: use bool for allowAdminPrivilege and add a save data * Few fixes for allowAdminPrivilege * Implement support to prevent tamper shared memory between GUI processes. NOTE: Kernel process will be using same shared memory since guiProcessID will remain as 0. * Various improvement * Use std library functions * Use single column spaces for align support on different tab size * Include failsafe if custom and file path string values are bad format Apparently ARRAYSIZE isn't define on other compilers. * Last ARRAYSIZE replacement plus buffer overflow protection * Replace WinAPI to std library's filesystem * Revert support for 2+ emulation process at same time. Emulation's graphic screen has corruption between both windows. Not even a wrapper to D3D9 will fix it. --- .gitmodules | 3 + build/win32/Cxbx.vcxproj | 23 +- build/win32/Cxbx.vcxproj.filters | 37 +- import/simpleini | 1 + resource/Cxbx.rc | 1 + src/Common/Settings.cpp | 715 ++++++++++++++++++ src/Common/Settings.hpp | 225 ++++++ ...{XBController.cpp => DInputController.cpp} | 294 ++----- .../{XBController.h => DInputController.h} | 40 +- src/Common/Win32/EmuShared.cpp | 34 +- src/Common/Win32/XBAudio.cpp | 117 --- src/Common/Win32/XBAudio.h | 93 --- src/Common/Win32/XBPortMapping.cpp | 136 +--- src/Common/Win32/XBPortMapping.h | 10 +- src/Common/Win32/XBVideo.cpp | 127 ---- src/Common/Win32/XBVideo.h | 107 --- src/Common/Xbe.cpp | 2 +- src/Cxbx.h | 9 + src/Cxbx/DlgAudioConfig.cpp | 32 +- src/Cxbx/DlgControllerConfig.cpp | 29 +- src/Cxbx/DlgVideoConfig.cpp | 47 +- src/Cxbx/DlgXboxControllerPortMapping.cpp | 12 +- src/Cxbx/ResCxbx.h | 3 +- src/Cxbx/WinMain.cpp | 90 ++- src/Cxbx/WndMain.cpp | 645 +++++----------- src/Cxbx/WndMain.h | 52 +- src/CxbxKrnl/CxbxKrnl.cpp | 58 +- src/CxbxKrnl/CxbxKrnl.h | 1 + src/CxbxKrnl/EmuD3D8.cpp | 66 +- src/CxbxKrnl/EmuDInput.cpp | 17 +- src/CxbxKrnl/EmuDSound.cpp | 7 +- src/CxbxKrnl/EmuDSoundInline.hpp | 6 +- src/CxbxKrnl/EmuKrnlHal.cpp | 7 +- src/CxbxKrnl/EmuShared.h | 158 ++-- src/CxbxKrnl/EmuXapi.cpp | 9 +- src/CxbxKrnl/HLEIntercept.cpp | 8 +- 36 files changed, 1602 insertions(+), 1619 deletions(-) create mode 160000 import/simpleini create mode 100644 src/Common/Settings.cpp create mode 100644 src/Common/Settings.hpp rename src/Common/Win32/{XBController.cpp => DInputController.cpp} (77%) rename src/Common/Win32/{XBController.h => DInputController.h} (89%) delete mode 100644 src/Common/Win32/XBAudio.cpp delete mode 100644 src/Common/Win32/XBAudio.h delete mode 100644 src/Common/Win32/XBVideo.cpp delete mode 100644 src/Common/Win32/XBVideo.h diff --git a/.gitmodules b/.gitmodules index bfb466842..4ac3615ce 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "import/XbSymbolDatabase"] path = import/XbSymbolDatabase url = https://github.com/Cxbx-Reloaded/XbSymbolDatabase.git +[submodule "import/simpleini"] + path = import/simpleini + url = https://github.com/brofield/simpleini diff --git a/build/win32/Cxbx.vcxproj b/build/win32/Cxbx.vcxproj index b507409c6..c13f5345f 100644 --- a/build/win32/Cxbx.vcxproj +++ b/build/win32/Cxbx.vcxproj @@ -102,7 +102,7 @@ Disabled - ..\..\src\Common;..\..\src;..\..\src\Common\Win32;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\import\subhook\ + ..\..\src\Common;..\..\src;..\..\src\Common\Win32;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\import\subhook\;..\..\import\simpleini NOMINMAX;_WIN32_WINNT=0x0601;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -162,7 +162,7 @@ Disabled - ..\..\src\Common;..\..\src;..\..\src\Common\Win32;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\import\subhook\ + ..\..\src\Common;..\..\src;..\..\src\Common\Win32;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\import\subhook\;..\..\import\simpleini CXBX_USE_D3D9;NOMINMAX;_WIN32_WINNT=0x0601;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -223,7 +223,7 @@ MaxSpeed AnySuitable - ..\..\src;..\..\src\Common;..\..\src\Common\Win32\;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\src\Common\Win32;..\..\import\subhook\ + ..\..\src;..\..\src\Common;..\..\src\Common\Win32\;%(AdditionalIncludeDirectories);..\..\import\OpenXDK\include;..\..\import\distorm\include;..\..\import\glew-2.0.0\include;..\..\src\Common\Win32;..\..\import\subhook\;..\..\import\simpleini NOMINMAX;_WIN32_WINNT=0x0601;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -284,9 +284,9 @@ + - @@ -352,9 +352,8 @@ - + - @@ -427,10 +426,10 @@ + - @@ -709,7 +708,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - + %(AdditionalIncludeDirectories) %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) @@ -725,14 +724,6 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - diff --git a/build/win32/Cxbx.vcxproj.filters b/build/win32/Cxbx.vcxproj.filters index 87dbdff57..d4d32750d 100644 --- a/build/win32/Cxbx.vcxproj.filters +++ b/build/win32/Cxbx.vcxproj.filters @@ -94,15 +94,9 @@ Shared - - Shared - Shared - - Shared - Emulator @@ -184,9 +178,6 @@ GUI - - Shared - Emulator @@ -317,6 +308,12 @@ Cross Platform + + Cross Platform + + + Shared + @@ -352,6 +349,9 @@ Kernel + + Shared + Shared @@ -367,15 +367,9 @@ Shared - - Shared - Shared - - Shared - Emulator @@ -472,9 +466,6 @@ GUI - - Shared - Emulator @@ -616,12 +607,16 @@ Shared\Input - - Shared - Cross Platform + + + Cross Platform + + + Shared + diff --git a/import/simpleini b/import/simpleini new file mode 160000 index 000000000..2af65fcc5 --- /dev/null +++ b/import/simpleini @@ -0,0 +1 @@ +Subproject commit 2af65fcc504f8242752755e836709762ef7ce062 diff --git a/resource/Cxbx.rc b/resource/Cxbx.rc index cefc315d6..aa4ee302c 100644 --- a/resource/Cxbx.rc +++ b/resource/Cxbx.rc @@ -499,6 +499,7 @@ BEGIN MENUITEM "Skip rdtsc patching", ID_HACKS_SKIPRDTSCPATCHING,MFT_STRING,MFS_ENABLED MENUITEM "Scale Xbox viewport to host (and back)", ID_HACKS_SCALEVIEWPORT,MFT_STRING,MFS_ENABLED END + MENUITEM "Allow Admin Privilege", ID_SETTINGS_ALLOWADMINPRIVILEGE,MFT_STRING,MFS_ENABLED MENUITEM MFT_SEPARATOR MENUITEM "Reset To Defaults", ID_SETTINGS_INITIALIZE,MFT_STRING,MFS_ENABLED END diff --git a/src/Common/Settings.cpp b/src/Common/Settings.cpp new file mode 100644 index 000000000..308c9ed89 --- /dev/null +++ b/src/Common/Settings.cpp @@ -0,0 +1,715 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Common->Settings.cpp +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2018 wutno (#/g/punk - Rizon) +// * (c) 2018 RadWolfie +// * +// * All rights reserved +// * +// ****************************************************************** + +#include "Settings.hpp" +#include "CxbxKrnl/Emu.h" +#include "CxbxKrnl/EmuShared.h" + +// TODO: Implement Qt support when real CPU emulation is available. +#ifndef QT_VERSION // NOTE: Non-Qt will be using current directory for data +#include // For SHGetSpecialFolderPath and CSIDL_APPDATA +#else +static_assert(false, "Please implement support for cross-platform's user profile data."); + +#include // for create directory +#include // for check file existance +#include // for cross-platform's user profile support +#endif + +// NOTE: Update settings_version when add/edit/delete setting's structure. +const uint settings_version = 2; + +Settings* g_Settings = nullptr; + +#define szSettings_setup_error "ERROR: Either setup have a problem or do not have write permission to directory." +#define szSettings_init_error "ERROR: Unable to initialize Settings class." +#define szSettings_save_user_option_message "If you want to save your settings in current/portable directory,\nclick 'Yes'." \ + "\n\nIf you want to store your settings in user profile directory,\nclick 'No'." \ + "\n\nClicking cancel will abort Cxbx-Reloaded." + +#define szSettings_settings_file "/settings.ini" +#define szSettings_cxbx_reloaded_directory "/Cxbx-Reloaded" + +static const char* section_gui = "gui"; +static struct { + const char* CxbxDebugMode = "CxbxDebugMode"; + const char* CxbxDebugLogFile = "CxbxDebugLogFile"; + const char* RecentXbeFiles = "RecentXbeFiles"; + const char* DataStorageToggle = "DataStorageToggle"; + const char* DataCustomLocation = "DataCustomLocation"; +} sect_gui_keys; + +static const char* section_core = "core"; +static struct { + const char* FlagsLLE = "FlagsLLE"; + const char* KrnlDebugMode = "KrnlDebugMode"; + const char* KrnlDebugLogFile = "KrnlDebugLogFile"; + const char* AllowAdminPrivilege = "AllowAdminPrivilege"; +} sect_core_keys; + +static const char* section_video = "video"; +static struct { + const char* VideoResolution = "VideoResolution"; + const char* adapter = "adapter"; + const char* Direct3DDevice = "Direct3DDevice"; + const char* VSync = "VSync"; + const char* FullScreen = "FullScreen"; + const char* HardwareYUV = "HardwareYUV"; +} sect_video_keys; + +static const char* section_audio = "audio"; +static struct { + const char* adapter = "adapter"; + const char* adapter_value = "%08X %04X %04X %02X%02X %02X%02X%02X%02X%02X%02X"; + const char* codec_pcm = "PCM"; + const char* codec_xadpcm = "XADPCM"; + const char* codec_unknown = "UnknownCodec"; +} sect_audio_keys; + +static const char* section_controller_dinput = "controller-dinput"; +// All keys so far are dynamic +static struct { + const char* device_name = "DeviceName 0x%.02X"; + const char* object_name = "Object : \"%s\""; + const char* object_name_value = "%08X %08X %08X"; +} sect_controller_dinput_keys; + +static const char* section_controller_port = "controller-port"; +// All keys so far are dynamic +static struct { + const char* xbox_port_x_host_type = "XboxPort%dHostType"; + const char* xbox_port_x_host_port = "XboxPort%dHostPort"; +} sect_controller_port_keys; + +static const char* section_hack = "hack"; +static struct { + const char* DisablePixelShaders = "DisablePixelShaders"; + const char* UncapFramerate = "UncapFramerate"; + const char* UseAllCores = "UseAllCores"; + const char* SkipRdtscPatching = "SkipRdtscPatching"; + const char* ScaleViewPort = "ScaleViewPort"; + const char* DirectHostBackBufferAccess = "DirectHostBackBufferAccess"; +} sect_hack_keys; + +std::string GenerateCurrentDirectoryStr() +{ + // NOTE: There is no cross-platform support for getting file's current directory. + return std::filesystem::current_path().generic_string(); +} + +// NOTE: This function will be only have Qt support, std::filesystem doesn't have generic support. +// Plus appending support for each OSes are not worthy to work on. +std::string GenerateUserProfileDirectoryStr() +{ + // ======================================================== + // TODO: Use QT's QDir and QFile classes for cross-platform + // with QStandardPaths::GenericDataLocation for generic User Profile location. + // NOTE: LibRetro compile build will not have user profile option support. + // ======================================================== + char folderOption[MAX_PATH]; + std::string genDirectory; + // TODO: Use QDir and QStandardPaths::GenericDataLocation for get user profile directory to support cross-platform + BOOL bRet = SHGetSpecialFolderPathA(NULL, folderOption, CSIDL_APPDATA, TRUE); // NOTE: Windows only support + if (!bRet) { + return ""; + } + genDirectory = folderOption; + genDirectory.append(szSettings_cxbx_reloaded_directory); + + return genDirectory; +} + +bool Settings::Init() +{ + m_si.SetMultiKey(true); + + bool bRet = LoadUserConfig(); + + // Enter setup installer process + if (!bRet) { + + std::string saveFile; +#ifdef RETRO_API_VERSION // TODO: Change me to #ifndef QT_VERSION + // Can only have one option without Qt. + saveFile = GenerateCurrentDirectoryStr(); + saveFile.append(szSettings_settings_file); + +#else // Only support for Qt compile build. + int iRet = MessageBox(nullptr, szSettings_save_user_option_message, "Cxbx-Reloaded", MB_YESNOCANCEL | MB_ICONQUESTION); + + if (iRet == IDYES) { + saveFile = GenerateCurrentDirectoryStr(); + saveFile.append(szSettings_settings_file); + } + else if (iRet == IDNO){ + saveFile = GenerateUserProfileDirectoryStr(); + if (saveFile.size() == 0) { + return false; + } + + // Check if data directory exist. + bRet = std::filesystem::exists(saveFile); + if (!bRet) { + // Then try create data directory. + bRet = std::filesystem::create_directory(saveFile); + if (!bRet) { + // Unable to create a data directory + return false; + } + } + + saveFile.append(szSettings_settings_file); + } + else { + return false; + } +#endif + + bRet = Save(saveFile); + + // Check if saving a file is a success. + if (!bRet) { + MessageBox(nullptr, szSettings_setup_error, "Cxbx-Reloaded", MB_OK); + return false; + } + + // Final check if able to auto load settings file. + bRet = LoadUserConfig(); + } + return bRet; +} + +bool Settings::LoadUserConfig() +{ + std::string fileSearch = GenerateCurrentDirectoryStr(); + + fileSearch.append(szSettings_settings_file); + + // Check and see if file exist from portable, current, directory. + if (std::filesystem::exists(fileSearch) == false) { + + fileSearch = GenerateUserProfileDirectoryStr(); + if (fileSearch.size() == 0) { + return false; + } + fileSearch.append(szSettings_settings_file); + + // Check if user profile directory settings file exist + if (std::filesystem::exists(fileSearch) == false) { + return false; + } + } + + return LoadFile(fileSearch); +} + +bool Settings::LoadFile(std::string file_path) +{ + bool bRet; + const char* si_data; + int iStatus; + std::list si_list; + std::list::iterator si_list_iterator; + + SI_Error siError = m_si.LoadFile(file_path.c_str()); + + if (siError != SI_OK) { + return false; + } + m_file_path = file_path; + + // ==== GUI Begin =========== + + m_gui.CxbxDebugMode = (DebugMode)m_si.GetLongValue(section_gui, sect_gui_keys.CxbxDebugMode, /*Default=*/DM_NONE); + si_data = m_si.GetValue(section_gui, sect_gui_keys.CxbxDebugLogFile, /*Default=*/nullptr); + // Fallback to null string if value is empty or contain bigger string. + if (si_data == nullptr || std::strlen(si_data) >= MAX_PATH) { + m_gui.szCxbxDebugFile = ""; + } + else { + m_gui.szCxbxDebugFile = si_data; + } + + m_gui.DataStorageToggle = m_si.GetLongValue(section_gui, sect_gui_keys.DataStorageToggle, /*Default=*/CXBX_DATA_APPDATA); + si_data = m_si.GetValue(section_gui, sect_gui_keys.DataCustomLocation, /*Default=*/nullptr); + // Fallback to null string if value is empty or contain bigger string. + if (si_data == nullptr || std::strlen(si_data) >= MAX_PATH) { + m_gui.szCustomLocation = ""; + } + else { + m_gui.szCustomLocation = si_data; + } + + // GUI - Recent xbe file paths + uint index = 0; + uint list_max = std::size(m_gui.szRecentXbeFiles); + bRet = m_si.GetAllValues(section_gui, sect_gui_keys.RecentXbeFiles, si_list);/*Default=empty list*/ + if (bRet) { + si_list_iterator = si_list.begin(); + for (si_list_iterator; si_list_iterator != si_list.end(); si_list_iterator++) { + // Exit loop when list has reach the limit. + if (index == list_max) { + break; + } + // Do not accept any file path greater or equal to MAX_PATH + if (std::strlen(si_list_iterator->pItem) >= MAX_PATH) { + continue; + } + m_gui.szRecentXbeFiles[index] = si_list_iterator->pItem; + index++; + } + } + // Set all or remaining recent xbe file paths to null string + while (index < list_max) { + m_gui.szRecentXbeFiles[index] = ""; + index++; + } + + // ==== GUI End ============= + + // ==== Core Begin ========== + + m_core.FlagsLLE = m_si.GetLongValue(section_core, sect_core_keys.FlagsLLE, /*Default=*/LLE_NONE); + m_core.KrnlDebugMode = (DebugMode)m_si.GetLongValue(section_core, sect_core_keys.KrnlDebugMode, /*Default=*/DM_NONE); + si_data = m_si.GetValue(section_core, sect_core_keys.KrnlDebugLogFile, /*Default=*/nullptr); + // Fallback to null string if value is empty or contain bigger string. + if (si_data == nullptr || std::strlen(si_data) >= MAX_PATH) { + m_core.szKrnlDebug[0] = '\0'; + } + else { + std::strncpy(m_core.szKrnlDebug, si_data, MAX_PATH); + } + + m_core.allowAdminPrivilege = m_si.GetBoolValue(section_core, sect_core_keys.AllowAdminPrivilege, /*Default=*/false); + + // ==== Core End ============ + + // ==== Hack Begin ========== + + m_hacks.DisablePixelShaders = m_si.GetBoolValue(section_hack, sect_hack_keys.DisablePixelShaders, /*Default=*/false); + m_hacks.UncapFramerate = m_si.GetBoolValue(section_hack, sect_hack_keys.UncapFramerate, /*Default=*/false); + m_hacks.UseAllCores = m_si.GetBoolValue(section_hack, sect_hack_keys.UseAllCores, /*Default=*/false); + m_hacks.SkipRdtscPatching = m_si.GetBoolValue(section_hack, sect_hack_keys.SkipRdtscPatching, /*Default=*/false); + m_hacks.ScaleViewport = m_si.GetBoolValue(section_hack, sect_hack_keys.ScaleViewPort, /*Default=*/false); + m_hacks.DirectHostBackBufferAccess = m_si.GetBoolValue(section_hack, sect_hack_keys.DirectHostBackBufferAccess, /*Default=*/true); + + // ==== Hack End ============ + + // ==== Video Begin ========= + + // Video - Resolution config + si_data = m_si.GetValue(section_video, sect_video_keys.VideoResolution, /*Default=*/nullptr); + // Fallback to null string if value is empty or contain bigger string. + if (si_data == nullptr || std::strlen(si_data) >= std::size(m_video.szVideoResolution)) { + m_video.szVideoResolution[0] = '\0'; + } + else { + std::strncpy(m_video.szVideoResolution, si_data, std::size(m_video.szVideoResolution)); + } + + m_video.adapter = m_si.GetLongValue(section_video, sect_video_keys.adapter, /*Default=*/0); + m_video.direct3DDevice = m_si.GetLongValue(section_video, sect_video_keys.Direct3DDevice, /*Default=*/0); + m_video.bVSync = m_si.GetBoolValue(section_video, sect_video_keys.VSync, /*Default=*/false); + m_video.bFullScreen = m_si.GetBoolValue(section_video, sect_video_keys.FullScreen, /*Default=*/false); + m_video.bHardwareYUV = m_si.GetBoolValue(section_video, sect_video_keys.HardwareYUV, /*Default=*/false); + + // ==== Video End =========== + + // ==== Audio Begin ========= + + // Audio - Adapter config + si_data = m_si.GetValue(section_audio, sect_audio_keys.adapter, /*Default=*/nullptr); + if (si_data == nullptr) { + // Default to primary audio device + m_audio.adapterGUID = { 0 }; + } + else { + iStatus = std::sscanf(si_data, sect_audio_keys.adapter_value, + &m_audio.adapterGUID.Data1, &m_audio.adapterGUID.Data2, &m_audio.adapterGUID.Data3, + &m_audio.adapterGUID.Data4[0], &m_audio.adapterGUID.Data4[1], &m_audio.adapterGUID.Data4[2], &m_audio.adapterGUID.Data4[3], + &m_audio.adapterGUID.Data4[4], &m_audio.adapterGUID.Data4[5], &m_audio.adapterGUID.Data4[6], &m_audio.adapterGUID.Data4[7]); + + // Fallback to primary audio device if file contain invalid value. + if (iStatus != 11 /*= total arguments*/) { + m_audio.adapterGUID = { 0 }; + } + } + + m_audio.codec_pcm = m_si.GetBoolValue(section_audio, sect_audio_keys.codec_pcm, /*Default=*/true, nullptr); + m_audio.codec_xadpcm = m_si.GetBoolValue(section_audio, sect_audio_keys.codec_xadpcm, /*Default=*/true, nullptr); + m_audio.codec_unknown = m_si.GetBoolValue(section_audio, sect_audio_keys.codec_unknown, /*Default=*/true, nullptr); + + // ==== Audio End =========== + + // ==== Controller Begin ==== + + int v = 0; + char szKeyName[64]; + + // ****************************************************************** + // * Load Device Names + // ****************************************************************** + for (v = 0; v < XBCTRL_MAX_DEVICES; v++) { + std::sprintf(szKeyName, sect_controller_dinput_keys.device_name, v); + si_data = m_si.GetValue(section_controller_dinput, szKeyName, /*Default=*/nullptr); + + // Fallback to null string if value is empty or contain bigger string. + if (si_data == nullptr || std::strlen(si_data) >= MAX_PATH) { + // default is a null string + m_controller_dinput.DeviceName[v][0] = '\0'; + } + else { + std::strncpy(m_controller_dinput.DeviceName[v], si_data, MAX_PATH); + } + } + + // ****************************************************************** + // * Load Object Configuration + // ****************************************************************** + for (v = 0; vSetCoreSettings(&m_core); + + // register Video settings + g_EmuShared->SetVideoSettings(&m_video); + + // register Audio settings + g_EmuShared->SetAudioSettings(&m_audio); + + // register Controller settings + g_EmuShared->SetControllerDInputSettings(&m_controller_dinput); + g_EmuShared->SetControllerPortSettings(&m_controller_port); + + // register Hacks settings + g_EmuShared->SetHackSettings(&m_hacks); + + // register data location setting + g_EmuShared->SetStorageLocation(GetDataLocation().c_str()); +} + +void Settings::Verify() +{ + // Prevent using an incorrect path from the registry if the debug folders have been moved + char szDebugPath[MAX_PATH]; + char szDebugName[MAX_PATH]; + + if (m_gui.CxbxDebugMode == DM_FILE) { + + if(m_gui.szCxbxDebugFile.size() == 0) { + m_gui.CxbxDebugMode = DM_NONE; + } + else { + std::strcpy(szDebugName, strrchr(m_gui.szCxbxDebugFile.c_str(), '\\')); + + if(m_gui.szCxbxDebugFile.size() < std::strlen(szDebugName)) { + m_gui.szCxbxDebugFile = ""; + m_gui.CxbxDebugMode = DM_NONE; + } + else { + std::strncpy(szDebugPath, m_gui.szCxbxDebugFile.c_str(), m_gui.szCxbxDebugFile.size() - std::strlen(szDebugName)); + + if(std::filesystem::exists(szDebugPath) == false) { + m_gui.szCxbxDebugFile = ""; + m_gui.CxbxDebugMode = DM_NONE; + } + } + } + } + + if (m_core.KrnlDebugMode == DM_FILE) { + + if(std::strlen(m_core.szKrnlDebug) == 0) { + m_core.KrnlDebugMode = DM_NONE; + } + else { + std::strcpy(szDebugName, strrchr(m_core.szKrnlDebug, '\\')); + + if(std::strlen(m_core.szKrnlDebug) < std::strlen(szDebugName)) { + memset(m_core.szKrnlDebug, '\0', MAX_PATH); + m_core.KrnlDebugMode = DM_NONE; + } + else { + std::strncpy(szDebugPath, m_core.szKrnlDebug, std::strlen(m_core.szKrnlDebug) - std::strlen(szDebugName)); + + if(std::filesystem::exists(szDebugPath) == false) { + memset(m_core.szKrnlDebug, '\0', MAX_PATH); + m_core.KrnlDebugMode = DM_NONE; + } + } + } + } +} + +std::string Settings::GetDataLocation() +{ + + // Optimization purpose for not require to re-process when toggle state has not changed. + if (m_current_DataStorageToggle == m_gui.DataStorageToggle) { + return m_current_data_location; + } + + switch (m_gui.DataStorageToggle) { + default: +#ifdef RETRO_API_VERSION // TODO: Change me to #ifndef QT_VERSION + + m_gui.DataStorageToggle = CXBX_DATA_CURDIR; + +#else // Only support for Qt compile build. + + m_gui.DataStorageToggle = CXBX_DATA_APPDATA; + // If unknown value, default to CXBX_DATA_APPDATA (below, don't use break) + + case CXBX_DATA_APPDATA: + m_current_data_location = GenerateUserProfileDirectoryStr(); + break; +#endif + + case CXBX_DATA_CURDIR: + m_current_data_location = GenerateCurrentDirectoryStr(); + break; + + case CXBX_DATA_CUSTOM: + m_current_data_location = m_gui.szCustomLocation; + break; + } + m_current_DataStorageToggle = m_gui.DataStorageToggle; + + return m_current_data_location; +} + +// ****************************************************************** +// * Input Device Name Lookup Table +// ****************************************************************** +const char *Settings::s_controller_dinput::XboxControllerObjectNameLookup[XBCTRL_OBJECT_COUNT] = +{ + // ****************************************************************** + // * Analog Axis + // ****************************************************************** + "LThumbPosX", "LThumbNegX", "LThumbPosY", "LThumbNegY", + "RThumbPosX", "RThumbNegX", "RThumbPosY", "RThumbNegY", + + // ****************************************************************** + // * Analog Buttons + // ****************************************************************** + "A", "B", "X", "Y", "Black", "White", "LTrigger", "RTrigger", + + // ****************************************************************** + // * Digital Buttons + // ****************************************************************** + "DPadUp", "DPadDown", "DPadLeft", "DPadRight", + "Back", "Start", "LThumb", "RThumb" +}; diff --git a/src/Common/Settings.hpp b/src/Common/Settings.hpp new file mode 100644 index 000000000..20b22327d --- /dev/null +++ b/src/Common/Settings.hpp @@ -0,0 +1,225 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Common->Settings.hpp +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * (c) 2017-2018 RadWolfie +// * +// * All rights reserved +// * +// ****************************************************************** +#ifndef SETTINGS_HPP +#define SETTINGS_HPP +#include "Cxbx.h" + +#include "SimpleIni.h" +#include + +#define szSettings_alloc_error "ERROR: Unable to allocate Settings class." + +// Cxbx-Reloaded's data storage location. +typedef enum _CXBX_DATA { + CXBX_DATA_APPDATA = 0, + CXBX_DATA_CURDIR = 1, + CXBX_DATA_CUSTOM = 2, +} CXBX_DATA; + +// ****************************************************************** +// * Xbox Controller Object IDs +// ****************************************************************** +enum XBCtrlObject +{ + // ****************************************************************** + // * Analog Axis + // ****************************************************************** + XBCTRL_OBJECT_LTHUMBPOSX = 0, + XBCTRL_OBJECT_LTHUMBNEGX, + XBCTRL_OBJECT_LTHUMBPOSY, + XBCTRL_OBJECT_LTHUMBNEGY, + XBCTRL_OBJECT_RTHUMBPOSX, + XBCTRL_OBJECT_RTHUMBNEGX, + XBCTRL_OBJECT_RTHUMBPOSY, + XBCTRL_OBJECT_RTHUMBNEGY, + // ****************************************************************** + // * Analog Buttons + // ****************************************************************** + XBCTRL_OBJECT_A, + XBCTRL_OBJECT_B, + XBCTRL_OBJECT_X, + XBCTRL_OBJECT_Y, + XBCTRL_OBJECT_BLACK, + XBCTRL_OBJECT_WHITE, + XBCTRL_OBJECT_LTRIGGER, + XBCTRL_OBJECT_RTRIGGER, + // ****************************************************************** + // * Digital Buttons + // ****************************************************************** + XBCTRL_OBJECT_DPADUP, + XBCTRL_OBJECT_DPADDOWN, + XBCTRL_OBJECT_DPADLEFT, + XBCTRL_OBJECT_DPADRIGHT, + XBCTRL_OBJECT_BACK, + XBCTRL_OBJECT_START, + XBCTRL_OBJECT_LTHUMB, + XBCTRL_OBJECT_RTHUMB, + // ****************************************************************** + // * Total number of components + // ****************************************************************** + XBCTRL_OBJECT_COUNT +}; + +// ****************************************************************** +// * Maximum number of devices allowed +// ****************************************************************** +#define XBCTRL_MAX_DEVICES XBCTRL_OBJECT_COUNT + +#define XBCTRL_MAX_GAMEPAD_PORTS 4 + +// ****************************************************************** +// * Xbox Controller Object Config +// ****************************************************************** +struct XBCtrlObjectCfg +{ + int dwDevice; // offset into m_InputDevice + int dwInfo; // extended information, depending on dwFlags + int dwFlags; // flags explaining the data format +}; + +enum { + LLE_NONE = 0, + LLE_APU = 1 << 0, + LLE_GPU = 1 << 1, + LLE_JIT = 1 << 2, + LLE_USB = 1 << 3, +}; + +class Settings +{ +public: + bool Init(); + bool LoadUserConfig(); + bool LoadFile(std::string file_path); + bool Save(std::string file_path = ""); + void Delete(); + void SyncToEmulator(); + void Verify(); + std::string GetDataLocation(); + + // GUI settings + struct s_gui { + DebugMode CxbxDebugMode; + std::string szCxbxDebugFile; + std::string szRecentXbeFiles[10]; + uint DataStorageToggle; + std::string szCustomLocation = ""; + } m_gui; + + // Core settings + struct s_core { + uint FlagsLLE; + DebugMode KrnlDebugMode; + char szKrnlDebug[MAX_PATH] = ""; + char szStorageLocation[MAX_PATH] = ""; + bool allowAdminPrivilege; + bool Reserved2 = 0; + bool Reserved3 = 0; + bool Reserved4 = 0; + int Reserved99[10] = { 0 }; + } m_core; + + // Video settings + struct s_video { + char szVideoResolution[100] = ""; + uint adapter; + uint direct3DDevice; + bool bVSync; + bool bFullScreen; + bool bHardwareYUV; + bool Reserved4 = 0; + int Reserved99[10] = { 0 }; + } m_video; + + // Audio settings + struct s_audio { + GUID adapterGUID; + bool codec_pcm ; + bool codec_xadpcm; + bool codec_unknown; + bool Reserved4 = 0; + int Reserved99[14] = { 0 }; + } m_audio; + + // Controller settings + struct s_controller_dinput { + + // ****************************************************************** + // * Input Device Name Lookup Table + // ****************************************************************** + static const char *XboxControllerObjectNameLookup[XBCTRL_OBJECT_COUNT]; + + // ****************************************************************** + // * Device Names + // ****************************************************************** + char DeviceName[XBCTRL_MAX_DEVICES][MAX_PATH]; + + // ****************************************************************** + // * Object Configuration + // ****************************************************************** + XBCtrlObjectCfg ObjectConfig[XBCTRL_OBJECT_COUNT]; + + } m_controller_dinput; + + struct s_controller_port { + uint XboxPortMapHostType[XBCTRL_MAX_GAMEPAD_PORTS] = { 1, 1, 1, 1 }; + uint XboxPortMapHostPort[XBCTRL_MAX_GAMEPAD_PORTS] = { 0, 1, 2, 3 }; + } m_controller_port; + + // Hack settings + struct s_hack { + bool DisablePixelShaders; + bool UncapFramerate; + bool UseAllCores; + bool SkipRdtscPatching; + bool ScaleViewport; + bool DirectHostBackBufferAccess; + bool Reserved7 = 0; + bool Reserved8 = 0; + int Reserved99[8] = { 0 }; + } m_hacks; + +private: + std::string m_file_path = ""; + CSimpleIniA m_si; + std::string m_current_data_location; + uint m_current_DataStorageToggle = -1; +}; + +// Settings manager +extern Settings* g_Settings; +extern const uint settings_version; + +#endif diff --git a/src/Common/Win32/XBController.cpp b/src/Common/Win32/DInputController.cpp similarity index 77% rename from src/Common/Win32/XBController.cpp rename to src/Common/Win32/DInputController.cpp index 402ae7639..0cd0e11f5 100644 --- a/src/Common/Win32/XBController.cpp +++ b/src/Common/Win32/DInputController.cpp @@ -9,7 +9,7 @@ // * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, // * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, // * -// * Cxbx->Win32->XBController.cpp +// * Cxbx->Win32->DInputController.cpp // * // * This file is part of the Cxbx project. // * @@ -33,7 +33,7 @@ // * All rights reserved // * // ****************************************************************** -#include "XBController.h" +#include "DInputController.h" #include "CxbxKrnl/EmuShared.h" #include "CxbxKrnl/EmuXTL.h" @@ -42,28 +42,29 @@ #define FIELD_OFFSET(type,field) ((ULONG)&(((type *)0)->field)) // ****************************************************************** -// * func: XBController::XBController +// * func: DInputController::DInputController // ****************************************************************** -XBController::XBController() +DInputController::DInputController() { m_CurrentState = XBCTRL_STATE_NONE; int v=0; - for(v=0;v=m_dwInputDeviceCount;v--) - m_DeviceName[v][0] = '\0'; + m_settings.DeviceName[v][0] = '\0'; for(v=0;v= m_dwInputDeviceCount) + if(m_settings.ObjectConfig[v].dwDevice >= m_dwInputDeviceCount) { - printf("Warning: Device Mapped to %s was not found!\n", m_DeviceNameLookup[v]); - m_ObjectConfig[v].dwDevice = -1; + printf("Warning: Device Mapped to %s was not found!\n", Settings::s_controller_dinput::XboxControllerObjectNameLookup[v]); + m_settings.ObjectConfig[v].dwDevice = -1; } } @@ -474,9 +347,9 @@ void XBController::ListenBegin(HWND hwnd) } // ****************************************************************** -// * func: XBController::ListenPoll +// * func: DInputController::ListenPoll // ****************************************************************** -void XBController::ListenPoll(XTL::X_XINPUT_STATE *Controller) +void DInputController::ListenPoll(XTL::X_XINPUT_STATE *Controller) { if(Controller == NULL) return; @@ -504,9 +377,9 @@ void XBController::ListenPoll(XTL::X_XINPUT_STATE *Controller) // ****************************************************************** for(int v=0;v=0;v--) { @@ -921,14 +794,14 @@ void XBController::DInputCleanup() } // ****************************************************************** -// * func: XBController::Map +// * func: DInputController::Map // ****************************************************************** -void XBController::Map(XBCtrlObject object, const char *szDeviceName, int dwInfo, int dwFlags) +void DInputController::Map(XBCtrlObject object, const char *szDeviceName, int dwInfo, int dwFlags) { // Initialize InputMapping instance - m_ObjectConfig[object].dwDevice = Insert(szDeviceName); - m_ObjectConfig[object].dwInfo = dwInfo; - m_ObjectConfig[object].dwFlags = dwFlags; + m_settings.ObjectConfig[object].dwDevice = Insert(szDeviceName); + m_settings.ObjectConfig[object].dwInfo = dwInfo; + m_settings.ObjectConfig[object].dwFlags = dwFlags; // Purge unused device slots for(int v=0;vtszInstanceName)) return DIENUM_CONTINUE; @@ -1040,9 +913,9 @@ BOOL XBController::EnumGameCtrlCallback(XTL::LPCDIDEVICEINSTANCE lpddi) } // ****************************************************************** -// * func: XBController::EnumObjectsCallback +// * func: DInputController::EnumObjectsCallback // ****************************************************************** -BOOL XBController::EnumObjectsCallback(XTL::LPCDIDEVICEOBJECTINSTANCE lpddoi) +BOOL DInputController::EnumObjectsCallback(XTL::LPCDIDEVICEOBJECTINSTANCE lpddoi) { if(lpddoi->dwType & DIDFT_AXIS) { @@ -1095,7 +968,7 @@ BOOL XBController::EnumObjectsCallback(XTL::LPCDIDEVICEOBJECTINSTANCE lpddoi) // ****************************************************************** BOOL CALLBACK WrapEnumGameCtrlCallback(XTL::LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { - XBController *context = (XBController*)pvRef; + DInputController *context = (DInputController*)pvRef; return context->EnumGameCtrlCallback(lpddi); } @@ -1105,30 +978,7 @@ BOOL CALLBACK WrapEnumGameCtrlCallback(XTL::LPCDIDEVICEINSTANCE lpddi, LPVOID pv // ****************************************************************** BOOL CALLBACK WrapEnumObjectsCallback(XTL::LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) { - XBController *context = (XBController*)pvRef; + DInputController *context = (DInputController*)pvRef; return context->EnumObjectsCallback(lpddoi); } - -// ****************************************************************** -// * Input Device Name Lookup Table -// ****************************************************************** -const char *XBController::m_DeviceNameLookup[XBCTRL_OBJECT_COUNT] = -{ - // ****************************************************************** - // * Analog Axis - // ****************************************************************** - "LThumbPosX", "LThumbNegX", "LThumbPosY", "LThumbNegY", - "RThumbPosX", "RThumbNegX", "RThumbPosY", "RThumbNegY", - - // ****************************************************************** - // * Analog Buttons - // ****************************************************************** - "A", "B", "X", "Y", "Black", "White", "LTrigger", "RTrigger", - - // ****************************************************************** - // * Digital Buttons - // ****************************************************************** - "DPadUp", "DPadDown", "DPadLeft", "DPadRight", - "Back", "Start", "LThumb", "RThumb", -}; diff --git a/src/Common/Win32/XBController.h b/src/Common/Win32/DInputController.h similarity index 89% rename from src/Common/Win32/XBController.h rename to src/Common/Win32/DInputController.h index 1758effd4..2ea794ae4 100644 --- a/src/Common/Win32/XBController.h +++ b/src/Common/Win32/DInputController.h @@ -7,7 +7,7 @@ // * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, // * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, // * -// * Cxbx->Win32->Cxbx->XBController.h +// * Cxbx->Win32->Cxbx->DInputController.h // * // * This file is part of the Cxbx project. // * @@ -31,8 +31,8 @@ // * All rights reserved // * // ****************************************************************** -#ifndef XBCONTROLLER_H -#define XBCONTROLLER_H +#ifndef DINPUTCONTROLLER_H +#define DINPUTCONTROLLER_H #include "Cxbx.h" #include "Common/Error.h" @@ -43,7 +43,8 @@ #include #include "CxbxKrnl/EmuXTL.h" - +#include "Common/Settings.hpp" +/* // ****************************************************************** // * Xbox Controller Object IDs // ****************************************************************** @@ -101,25 +102,19 @@ struct XBCtrlObjectCfg int dwDevice; // offset into m_InputDevice int dwInfo; // extended information, depending on dwFlags int dwFlags; // flags explaining the data format -}; +};*/ // ****************************************************************** -// * class: XBController +// * class: DInputController // ****************************************************************** -class XBController : public Error +class DInputController : public Error { public: // ****************************************************************** // * Initialization // ****************************************************************** - XBController(); - ~XBController(); - - // ****************************************************************** - // * Registry Load/Save - // ****************************************************************** - void Load(const char *szRegistryKey); - void Save(const char *szRegistryKey); + DInputController(); + ~DInputController(); // ****************************************************************** // * Configuration @@ -147,9 +142,9 @@ class XBController : public Error bool DeviceIsUsed(const char *szDeviceName); // ****************************************************************** - // * Input Device Name Lookup Table + // * Settings for DirectInput Device(s) // ****************************************************************** - static const char *m_DeviceNameLookup[XBCTRL_OBJECT_COUNT]; + Settings::s_controller_dinput m_settings; private: // ****************************************************************** @@ -179,16 +174,6 @@ class XBController : public Error friend BOOL CALLBACK WrapEnumGameCtrlCallback(XTL::LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef); friend BOOL CALLBACK WrapEnumObjectsCallback(XTL::LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); - // ****************************************************************** - // * Device Names - // ****************************************************************** - char m_DeviceName[XBCTRL_MAX_DEVICES][260]; - - // ****************************************************************** - // * Object Configuration - // ****************************************************************** - XBCtrlObjectCfg m_ObjectConfig[XBCTRL_OBJECT_COUNT]; - // ****************************************************************** // * DirectInput // ****************************************************************** @@ -220,7 +205,6 @@ class XBController : public Error // ****************************************************************** int m_dwInputDeviceCount; int m_dwCurObject; - }; // ****************************************************************** diff --git a/src/Common/Win32/EmuShared.cpp b/src/Common/Win32/EmuShared.cpp index 6868de5a3..d28c1a3bb 100644 --- a/src/Common/Win32/EmuShared.cpp +++ b/src/Common/Win32/EmuShared.cpp @@ -56,7 +56,7 @@ HANDLE hMapObject = NULL; // ****************************************************************** // * func: EmuShared::EmuSharedInit // ****************************************************************** -void EmuShared::Init() +void EmuShared::Init(DWORD guiProcessID) { // ****************************************************************** // * Ensure initialization only occurs once @@ -73,6 +73,8 @@ void EmuShared::Init() // * Create the shared memory "file" // ****************************************************************** { + // NOTE: guiProcessID support is not available due to 2+ emulation is causing problem with graphic screen. + std::string emuSharedStr = "Local\\EmuShared-s" + std::to_string(settings_version);// +"-p" + std::to_string(guiProcessID); hMapObject = CreateFileMapping ( INVALID_HANDLE_VALUE, // Paging file @@ -80,7 +82,7 @@ void EmuShared::Init() PAGE_READWRITE, // read/write access 0, // size: high 32 bits sizeof(EmuShared), // size: low 32 bits - "Local\\EmuShared" // name of map object + emuSharedStr.c_str() // name of map object ); if(hMapObject == NULL) @@ -110,8 +112,9 @@ void EmuShared::Init() // ****************************************************************** // * Executed only on first initialization of shared memory // ****************************************************************** - if(bRequireConstruction) + if (bRequireConstruction) { g_EmuShared->EmuShared::EmuShared(); + } g_EmuShared->m_RefCount++; } @@ -135,10 +138,16 @@ void EmuShared::Cleanup() // ****************************************************************** EmuShared::EmuShared() { - Load(); m_bDebugging = false; - m_bEmulating = false; + m_bEmulating_status = false; m_bFirstLaunch = false; + + // Reserve space (default to 0) + m_bReserved1 = false; + m_bReserved2 = false; + m_bReserved3 = false; + m_bReserved4 = false; + memset(m_Reserved99, 0, sizeof(m_Reserved99)); } // ****************************************************************** @@ -146,19 +155,4 @@ EmuShared::EmuShared() // ****************************************************************** EmuShared::~EmuShared() { - Save(); -} - -void EmuShared::Load() -{ - m_XBController.Load("Software\\Cxbx-Reloaded\\XBController"); - m_XBVideo.Load("Software\\Cxbx-Reloaded\\XBVideo"); - m_XBAudio.Load("Software\\Cxbx-Reloaded\\XBAudio"); -} - -void EmuShared::Save() -{ - m_XBController.Save("Software\\Cxbx-Reloaded\\XBController"); - m_XBVideo.Save("Software\\Cxbx-Reloaded\\XBVideo"); - m_XBAudio.Save("Software\\Cxbx-Reloaded\\XBAudio"); } diff --git a/src/Common/Win32/XBAudio.cpp b/src/Common/Win32/XBAudio.cpp deleted file mode 100644 index 31b2df565..000000000 --- a/src/Common/Win32/XBAudio.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -// ****************************************************************** -// * -// * .,-::::: .,:: .::::::::. .,:: .: -// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; -// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' -// * $$$ Y$$$P $$""""Y$$ Y$$$P -// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, -// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, -// * -// * Cxbx->Common->Win32->XBAudio.cpp -// * -// * This file is part of the Cxbx project. -// * -// * Cxbx and Cxbe are free software; you can redistribute them -// * and/or modify them under the terms of the GNU General Public -// * License as published by the Free Software Foundation; either -// * version 2 of the license, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have recieved a copy of the GNU General Public License -// * along with this program; see the file COPYING. -// * If not, write to the Free Software Foundation, Inc., -// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. -// * -// * (c) 2017 RadWolfie -// * -// * All rights reserved -// * -// ****************************************************************** -#include "XBAudio.h" - -#include - -// ****************************************************************** -// * func: XBAudio::XBAudio -// ****************************************************************** -XBAudio::XBAudio() : m_bPCM(true), m_bXADPCM(true), m_bUnknownCodec(true) -{ - m_binAudioAdapter = { 0 }; -} - -// ****************************************************************** -// * func: XBAudio::~XBAudio -// ****************************************************************** -XBAudio::~XBAudio() -{ -} - -// ****************************************************************** -// * func: XBAudio::Load -// ****************************************************************** -void XBAudio::Load(const char *szRegistryKey) -{ - // ****************************************************************** - // * Load Configuration from Registry - // ****************************************************************** - { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - - dwType = REG_DWORD; dwSize = sizeof(m_binAudioAdapter); - RegQueryValueEx(hKey, "AudioAdapter", NULL, &dwType, (PBYTE)&m_binAudioAdapter, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bPCM); - RegQueryValueEx(hKey, "PCM", NULL, &dwType, (PBYTE)&m_bPCM, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bXADPCM); - RegQueryValueEx(hKey, "XADPCM", NULL, &dwType, (PBYTE)&m_bXADPCM, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bUnknownCodec); - RegQueryValueEx(hKey, "UnknownCodec", NULL, &dwType, (PBYTE)&m_bUnknownCodec, &dwSize); - - RegCloseKey(hKey); - } - } -} - -// ****************************************************************** -// * func: XBAudio::Save -// ****************************************************************** -void XBAudio::Save(const char *szRegistryKey) -{ - // ****************************************************************** - // * Save Configuration to Registry - // ****************************************************************** - if (g_SaveOnExit) { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - - dwType = REG_BINARY; dwSize = sizeof(m_binAudioAdapter); - RegSetValueEx(hKey, "AudioAdapter", 0, dwType, (PBYTE)&m_binAudioAdapter, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bPCM); - RegSetValueEx(hKey, "PCM", 0, dwType, (PBYTE)&m_bPCM, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bXADPCM); - RegSetValueEx(hKey, "XADPCM", 0, dwType, (PBYTE)&m_bXADPCM, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bUnknownCodec); - RegSetValueEx(hKey, "UnknownCodec", 0, dwType, (PBYTE)&m_bUnknownCodec, dwSize); - - RegCloseKey(hKey); - } - } -} diff --git a/src/Common/Win32/XBAudio.h b/src/Common/Win32/XBAudio.h deleted file mode 100644 index d4d28436c..000000000 --- a/src/Common/Win32/XBAudio.h +++ /dev/null @@ -1,93 +0,0 @@ -// ****************************************************************** -// * -// * .,-::::: .,:: .::::::::. .,:: .: -// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; -// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' -// * $$$ Y$$$P $$""""Y$$ Y$$$P -// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, -// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, -// * -// * Cxbx->Common->Win32->Cxbx->XBAudio.h -// * -// * This file is part of the Cxbx project. -// * -// * Cxbx and Cxbe are free software; you can redistribute them -// * and/or modify them under the terms of the GNU General Public -// * License as published by the Free Software Foundation; either -// * version 2 of the license, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have recieved a copy of the GNU General Public License -// * along with this program; see the file COPYING. -// * If not, write to the Free Software Foundation, Inc., -// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. -// * -// * (c) 2017 RadWolfie -// * -// * All rights reserved -// * -// ****************************************************************** -#ifndef XBAUDIO_H -#define XBAUDIO_H - -#include "Cxbx.h" -#include "Common/Error.h" -#include "Mutex.h" - -// ****************************************************************** -// * class: XBAudio -// ****************************************************************** -class XBAudio : public Error -{ - public: - // ****************************************************************** - // * Initialization - // ****************************************************************** - XBAudio(); - ~XBAudio(); - - // ****************************************************************** - // * Registry Load/Save - // ****************************************************************** - void Load(const char *szRegistryKey); - void Save(const char *szRegistryKey); - - // ****************************************************************** - // * SetAudioAdapter - // ****************************************************************** - void SetAudioAdapter(GUID binAudioAdapter) { m_binAudioAdapter = binAudioAdapter; } - GUID GetAudioAdapter() const { return m_binAudioAdapter; } - - // ****************************************************************** - // * PCM Toggling - // ****************************************************************** - void SetPCM(BOOL bPCM) { m_bPCM = bPCM; } - BOOL GetPCM() const { return m_bPCM; } - - // ****************************************************************** - // * XADPCM Toggling - // ****************************************************************** - void SetXADPCM(BOOL bXADPCM) { m_bXADPCM = bXADPCM; } - BOOL GetXADPCM() const { return m_bXADPCM; } - - // ****************************************************************** - // * Unknown Codec Toggling - // ****************************************************************** - void SetUnknownCodec(BOOL bUnknownCodec) { m_bUnknownCodec = bUnknownCodec; } - BOOL GetUnknownCodec() const { return m_bUnknownCodec; } - - private: - // ****************************************************************** - // * Configuration - // ****************************************************************** - GUID m_binAudioAdapter; - BOOL m_bPCM; - BOOL m_bXADPCM; - BOOL m_bUnknownCodec; -}; - -#endif diff --git a/src/Common/Win32/XBPortMapping.cpp b/src/Common/Win32/XBPortMapping.cpp index 27106ac77..282409dc1 100644 --- a/src/Common/Win32/XBPortMapping.cpp +++ b/src/Common/Win32/XBPortMapping.cpp @@ -45,132 +45,22 @@ namespace xboxkrnl }; #include -//#include "CxbxKrnl.h" -//#include "Logging.h" -//#include "Emu.h" -//#include "EmuKrnl.h" // For DefaultLaunchDataPage -//#include "EmuFile.h" -//#include "EmuFS.h" -//#include "EmuShared.h" -//#include "HLEIntercept.h" -//#include "CxbxVSBC/CxbxVSBC.h" -//#include "Windef.h" -//#include +#include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" +static Settings::s_controller_port g_ControllerPortMap; -DWORD g_XboxPortMapHostType[] = { 1,1,1,1 }; -DWORD g_XboxPortMapHostPort[] = { 0,1,2,3 }; - -// XInputSetState status waiters - -void XBPortMappingLoad(const char *szRegistryKey) +void XBPortMappingSet(Settings::s_controller_port &controller_port_settings) { - { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if (RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - dwType = REG_DWORD; dwSize = sizeof(DWORD); - LSTATUS result; - result = RegQueryValueEx(hKey, "XboxPort0HostType", NULL, &dwType, (PBYTE)&g_XboxPortMapHostType[0], &dwSize); - if (result != ERROR_SUCCESS) { - //default to use XInput - g_XboxPortMapHostType[0] = 1; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort0HostPort", NULL, &dwType, (PBYTE)&g_XboxPortMapHostPort[0], &dwSize); - if (result != ERROR_SUCCESS) { - g_XboxPortMapHostPort[0] = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort1HostType", NULL, &dwType, (PBYTE)&g_XboxPortMapHostType[1], &dwSize); - if (result != ERROR_SUCCESS) { - //default to use XInput - g_XboxPortMapHostType[1] = 1; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort1HostPort", NULL, &dwType, (PBYTE)&g_XboxPortMapHostPort[1], &dwSize); - if (result != ERROR_SUCCESS) { - g_XboxPortMapHostPort[1] = 1; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort2HostType", NULL, &dwType, (PBYTE)&g_XboxPortMapHostType[2], &dwSize); - if (result != ERROR_SUCCESS) { - //default to use XInput - g_XboxPortMapHostType[2] = 1; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort2HostPort", NULL, &dwType, (PBYTE)&g_XboxPortMapHostPort[2], &dwSize); - if (result != ERROR_SUCCESS) { - g_XboxPortMapHostPort[2] = 2; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort3HostType", NULL, &dwType, (PBYTE)&g_XboxPortMapHostType[3], &dwSize); - if (result != ERROR_SUCCESS) { - //default to use XInput - g_XboxPortMapHostType[3] = 1; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "XboxPort3HostPort", NULL, &dwType, (PBYTE)&g_XboxPortMapHostPort[3], &dwSize); - if (result != ERROR_SUCCESS) { - g_XboxPortMapHostPort[3] = 3; - } - - RegCloseKey(hKey); - } - } + g_ControllerPortMap = controller_port_settings; } // ****************************************************************** // * func: Save // ****************************************************************** -void XBPortMappingSave(const char *szRegistryKey) +void XBPortMappingGet(Settings::s_controller_port &controller_port_settings) { - // ****************************************************************** - // * Save Configuration to Registry - // ****************************************************************** - //if (g_SaveOnExit) { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if (RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort0HostType", 0, dwType, (PBYTE)&g_XboxPortMapHostType[0], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort0HostPort", 0, dwType, (PBYTE)&g_XboxPortMapHostPort[0], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort1HostType", 0, dwType, (PBYTE)&g_XboxPortMapHostType[1], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort1HostPort", 0, dwType, (PBYTE)&g_XboxPortMapHostPort[1], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort2HostType", 0, dwType, (PBYTE)&g_XboxPortMapHostType[2], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort2HostPort", 0, dwType, (PBYTE)&g_XboxPortMapHostPort[2], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort3HostType", 0, dwType, (PBYTE)&g_XboxPortMapHostType[3], dwSize); - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - RegSetValueEx(hKey, "XboxPort3HostPort", 0, dwType, (PBYTE)&g_XboxPortMapHostPort[3], dwSize); - - - RegCloseKey(hKey); - } - //} + controller_port_settings = g_ControllerPortMap; } //Set HostType and HostPort setting from global array per xbox port. The setted value will take effect from next time xbe loading. @@ -178,23 +68,23 @@ void SetXboxPortToHostPort(DWORD dwXboxPort, DWORD dwHostType, DWORD dwHostPort) { //set host type and host port in global array per xbox port, will be used when xbe get reloaded. //only host type and host port can be set in this time. because the xbox DeviceType can only be determined when loading the xbe. - g_XboxPortMapHostType[dwXboxPort] = dwHostType; - g_XboxPortMapHostPort[dwXboxPort] = dwHostPort; + g_ControllerPortMap.XboxPortMapHostType[dwXboxPort] = dwHostType; + g_ControllerPortMap.XboxPortMapHostPort[dwXboxPort] = dwHostPort; } //retrieve HostType and HostPort setting from global array per xbox port. void GetXboxPortToHostPort(DWORD dwXboxPort, DWORD &dwHostType, DWORD &dwHostPort) { //get Host Type and Host Port per xbox port - dwHostType = g_XboxPortMapHostType[dwXboxPort]; - dwHostPort = g_XboxPortMapHostPort[dwXboxPort]; + dwHostType = g_ControllerPortMap.XboxPortMapHostType[dwXboxPort]; + dwHostPort = g_ControllerPortMap.XboxPortMapHostPort[dwXboxPort]; } DWORD GetXboxPortMapHostType(DWORD dwXboxPort) { - return g_XboxPortMapHostType[dwXboxPort]; + return g_ControllerPortMap.XboxPortMapHostType[dwXboxPort]; } DWORD GetXboxPortMapHostPort(DWORD dwXboxPort) { - return g_XboxPortMapHostPort[dwXboxPort]; + return g_ControllerPortMap.XboxPortMapHostPort[dwXboxPort]; } diff --git a/src/Common/Win32/XBPortMapping.h b/src/Common/Win32/XBPortMapping.h index ab2e8c059..d3ae9f6f4 100644 --- a/src/Common/Win32/XBPortMapping.h +++ b/src/Common/Win32/XBPortMapping.h @@ -34,8 +34,6 @@ #ifndef XBPORTMAPPING_H #define XBPORTMAPPING_H -#include "../CxbxKrnl/EmuXapi.h" - extern void SetXboxPortToHostPort(DWORD dwXboxPort, DWORD dwHostType, DWORD dwHostPort); extern void GetXboxPortToHostPort(DWORD dwXboxPort, DWORD &dwHostType, DWORD &dwHostPort); @@ -44,12 +42,12 @@ extern DWORD GetXboxPortMapHostType(DWORD dwXboxPort); extern DWORD GetXboxPortMapHostPort(DWORD dwXboxPort); // ****************************************************************** -// * Load Configuration from Registry +// * Set configuration // ****************************************************************** -extern void XBPortMappingLoad(const char *szRegistryKey); +extern void XBPortMappingSet(Settings::s_controller_port &controller_port_settings); // ****************************************************************** -// * Save Configuration from Registry +// * Get configuration // ****************************************************************** -extern void XBPortMappingSave(const char *szRegistryKey); +extern void XBPortMappingGet(Settings::s_controller_port &controller_port_settings); #endif diff --git a/src/Common/Win32/XBVideo.cpp b/src/Common/Win32/XBVideo.cpp deleted file mode 100644 index aa5dbcc85..000000000 --- a/src/Common/Win32/XBVideo.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check it. -// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -// ****************************************************************** -// * -// * .,-::::: .,:: .::::::::. .,:: .: -// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; -// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' -// * $$$ Y$$$P $$""""Y$$ Y$$$P -// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, -// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, -// * -// * Cxbx->Win32->XBVideo.cpp -// * -// * This file is part of the Cxbx project. -// * -// * Cxbx and Cxbe are free software; you can redistribute them -// * and/or modify them under the terms of the GNU General Public -// * License as published by the Free Software Foundation; either -// * version 2 of the license, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have recieved a copy of the GNU General Public License -// * along with this program; see the file COPYING. -// * If not, write to the Free Software Foundation, Inc., -// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. -// * -// * (c) 2002-2003 Aaron Robinson -// * -// * All rights reserved -// * -// ****************************************************************** -#include "XBVideo.h" - -#include - -// ****************************************************************** -// * func: XBVideo::XBVideo -// ****************************************************************** -XBVideo::XBVideo() : m_bVSync(false), m_bFullscreen(false), m_bHardwareYUV(false) -{ - strcpy(m_szVideoResolution, "Automatic (Default)"); -} - -// ****************************************************************** -// * func: XBVideo::~XBVideo -// ****************************************************************** -XBVideo::~XBVideo() -{ -} - -// ****************************************************************** -// * func: XBVideo::Load -// ****************************************************************** -void XBVideo::Load(const char *szRegistryKey) -{ - // ****************************************************************** - // * Load Configuration from Registry - // ****************************************************************** - { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - dwType = REG_SZ; dwSize = sizeof(m_szVideoResolution); - RegQueryValueEx(hKey, "VideoResolution", NULL, &dwType, (PBYTE)m_szVideoResolution, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_dwDisplayAdapter); - RegQueryValueEx(hKey, "DisplayAdapter", NULL, &dwType, (PBYTE)&m_dwDisplayAdapter, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_dwDirect3DDevice); - RegQueryValueEx(hKey, "Direct3DDevice", NULL, &dwType, (PBYTE)&m_dwDirect3DDevice, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bFullscreen); - RegQueryValueEx(hKey, "Fullscreen", NULL, &dwType, (PBYTE)&m_bFullscreen, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bVSync); - RegQueryValueEx(hKey, "VSync", NULL, &dwType, (PBYTE)&m_bVSync, &dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bHardwareYUV); - RegQueryValueEx(hKey, "HardwareYUV", NULL, &dwType, (PBYTE)&m_bHardwareYUV, &dwSize); - - RegCloseKey(hKey); - } - } -} - -// ****************************************************************** -// * func: XBVideo::Save -// ****************************************************************** -void XBVideo::Save(const char *szRegistryKey) -{ - // ****************************************************************** - // * Save Configuration to Registry - // ****************************************************************** - if (g_SaveOnExit) { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, szRegistryKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - dwType = REG_SZ; dwSize = sizeof(m_szVideoResolution); - RegSetValueEx(hKey, "VideoResolution", 0, dwType, (PBYTE)m_szVideoResolution, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_dwDisplayAdapter); - RegSetValueEx(hKey, "DisplayAdapter", 0, dwType, (PBYTE)&m_dwDisplayAdapter, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_dwDirect3DDevice); - RegSetValueEx(hKey, "Direct3DDevice", 0, dwType, (PBYTE)&m_dwDirect3DDevice, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bFullscreen); - RegSetValueEx(hKey, "Fullscreen", 0, dwType, (PBYTE)&m_bFullscreen, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bVSync); - RegSetValueEx(hKey, "VSync", 0, dwType, (PBYTE)&m_bVSync, dwSize); - - dwType = REG_DWORD; dwSize = sizeof(m_bHardwareYUV); - RegSetValueEx(hKey, "HardwareYUV", 0, dwType, (PBYTE)&m_bHardwareYUV, dwSize); - - RegCloseKey(hKey); - } - } -} diff --git a/src/Common/Win32/XBVideo.h b/src/Common/Win32/XBVideo.h deleted file mode 100644 index 43630e44d..000000000 --- a/src/Common/Win32/XBVideo.h +++ /dev/null @@ -1,107 +0,0 @@ -// ****************************************************************** -// * -// * .,-::::: .,:: .::::::::. .,:: .: -// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; -// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' -// * $$$ Y$$$P $$""""Y$$ Y$$$P -// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, -// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, -// * -// * Cxbx->Win32->Cxbx->XBVideo.h -// * -// * This file is part of the Cxbx project. -// * -// * Cxbx and Cxbe are free software; you can redistribute them -// * and/or modify them under the terms of the GNU General Public -// * License as published by the Free Software Foundation; either -// * version 2 of the license, or (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have recieved a copy of the GNU General Public License -// * along with this program; see the file COPYING. -// * If not, write to the Free Software Foundation, Inc., -// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. -// * -// * (c) 2002-2003 Aaron Robinson -// * -// * All rights reserved -// * -// ****************************************************************** -#ifndef XBVIDEO_H -#define XBVIDEO_H - -#include "Cxbx.h" -#include "Common/Error.h" -#include "Mutex.h" - -// ****************************************************************** -// * class: XBVideo -// ****************************************************************** -class XBVideo : public Error -{ - public: - // ****************************************************************** - // * Initialization - // ****************************************************************** - XBVideo(); - ~XBVideo(); - - // ****************************************************************** - // * Registry Load/Save - // ****************************************************************** - void Load(const char *szRegistryKey); - void Save(const char *szRegistryKey); - - // ****************************************************************** - // * SetDirect3DDevice - // ****************************************************************** - void SetDirect3DDevice(DWORD dwDirect3DDevice) { m_dwDirect3DDevice = dwDirect3DDevice; } - DWORD GetDirect3DDevice() const { return m_dwDirect3DDevice; } - - // ****************************************************************** - // * SetDisplayAdapter - // ****************************************************************** - void SetDisplayAdapter(DWORD dwDisplayAdapter) { m_dwDisplayAdapter = dwDisplayAdapter; } - DWORD GetDisplayAdapter() const { return m_dwDisplayAdapter; } - - // ****************************************************************** - // * SetVideoResolution - // ****************************************************************** - void SetVideoResolution(const char *szBuffer) { strcpy(m_szVideoResolution, szBuffer); } - const char *GetVideoResolution(){ return m_szVideoResolution; } - - // ****************************************************************** - // * Fullscreen Toggling - // ****************************************************************** - void SetFullscreen(BOOL bFullscreen) { m_bFullscreen = bFullscreen; } - BOOL GetFullscreen() const { return m_bFullscreen; } - - // ****************************************************************** - // * VSync Toggling - // ****************************************************************** - void SetVSync(BOOL bVSync) { m_bVSync = bVSync; } - BOOL GetVSync() const { return m_bVSync; } - - // ****************************************************************** - // * Hardware YUV Toggling - // ****************************************************************** - void SetHardwareYUV(BOOL bHardwareYUV) { m_bHardwareYUV = bHardwareYUV; } - BOOL GetHardwareYUV() const { return m_bHardwareYUV; } - - private: - // ****************************************************************** - // * Configuration - // ****************************************************************** - char m_szVideoResolution[100]; - DWORD m_dwDisplayAdapter; - DWORD m_dwDirect3DDevice; - BOOL m_bVSync; - BOOL m_bFullscreen; - BOOL m_bHardwareYUV; -}; - -#endif diff --git a/src/Common/Xbe.cpp b/src/Common/Xbe.cpp index f430b290a..4962908ed 100644 --- a/src/Common/Xbe.cpp +++ b/src/Common/Xbe.cpp @@ -47,9 +47,9 @@ namespace xboxkrnl #include // For ctime #include "devices\LED.h" // For LED::Sequence #include "CxbxKrnl/CxbxKrnl.h" // For CxbxKrnlPrintUEM -#include "CxbxKrnl/EmuShared.h" // Include this to avoid including EmuXapi.h and EmuD3D8.h #include "CxbxKrnl\EmuSha.h" // For the SHA functions #include "CxbxKrnl\EmuRsa.h" // For the RSA functions +#include "CxbxKrnl/EmuXTL.h" // For LDT_FROM_DASHBOARD and CxbxInitWindow namespace fs = std::experimental::filesystem; diff --git a/src/Cxbx.h b/src/Cxbx.h index 56b9ad612..b77ef4c11 100644 --- a/src/Cxbx.h +++ b/src/Cxbx.h @@ -157,4 +157,13 @@ extern volatile bool g_bPrintfOn; #define CxbxSetThreadName(Name) #endif +// NOTE: The reason filesystem is here is for force compress "experimental" namespace +// to work with same old and new filesystem's functions. Untested, yet should work fine. +#include +#ifdef _EXPERIMENTAL_FILESYSTEM_ +namespace std { + namespace filesystem = std::experimental::filesystem; +} +#endif + #endif diff --git a/src/Cxbx/DlgAudioConfig.cpp b/src/Cxbx/DlgAudioConfig.cpp index 0509ef627..ba266d88a 100644 --- a/src/Cxbx/DlgAudioConfig.cpp +++ b/src/Cxbx/DlgAudioConfig.cpp @@ -34,7 +34,7 @@ // * // ****************************************************************** -#include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" // for g_Settings #include "DlgAudioConfig.h" #include "ResCxbx.h" @@ -49,7 +49,7 @@ static BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrv static VOID RefreshAudioAdapter(); /*! audio configuration */ -static XBAudio g_XBAudio; +static Settings::s_audio g_XBAudio; /*! changes flag */ static BOOL g_bHasChanges = FALSE; /*! handle to audio adapter list window */ @@ -61,7 +61,7 @@ VOID ShowAudioConfig(HWND hwnd) g_bHasChanges = FALSE; /*! retrieve audio configuration */ - g_EmuShared->GetXBAudio(&g_XBAudio); + g_XBAudio = g_Settings->m_audio; /*! show dialog box */ DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AUDIO_CFG), hwnd, DlgAudioConfigProc); @@ -82,7 +82,7 @@ BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, L binGUID = { 0 }; } - GUID curGUID = g_XBAudio.GetAudioAdapter(); + GUID curGUID = g_XBAudio.adapterGUID; /*! activate configured audio adapter */ if (curGUID == binGUID) { @@ -108,7 +108,7 @@ INT_PTR CALLBACK DlgAudioConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR SendMessage(g_hAudioAdapter, CB_RESETCONTENT, 0, 0); - XTL::DirectSoundEnumerate(&DSEnumProc, NULL); + DirectSoundEnumerate(&DSEnumProc, NULL); } /*! refresh UI based on currently selected audio adapter */ @@ -116,11 +116,11 @@ INT_PTR CALLBACK DlgAudioConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR /*! check appropriate options */ { - SendMessage(GetDlgItem(hWndDlg, IDC_AC_PCM), BM_SETCHECK, (WPARAM)g_XBAudio.GetPCM(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_AC_PCM), BM_SETCHECK, (WPARAM)g_XBAudio.codec_pcm, 0); - SendMessage(GetDlgItem(hWndDlg, IDC_AC_XADPCM), BM_SETCHECK, (WPARAM)g_XBAudio.GetXADPCM(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_AC_XADPCM), BM_SETCHECK, (WPARAM)g_XBAudio.codec_xadpcm, 0); - SendMessage(GetDlgItem(hWndDlg, IDC_AC_UNKNOWN_CODEC), BM_SETCHECK, (WPARAM)g_XBAudio.GetUnknownCodec(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_AC_UNKNOWN_CODEC), BM_SETCHECK, (WPARAM)g_XBAudio.codec_unknown, 0); } } break; @@ -163,21 +163,21 @@ INT_PTR CALLBACK DlgAudioConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR /*! save PCM/XADPCM/UnknownCodec options */ { - LRESULT lRet = SendMessage(GetDlgItem(hWndDlg, IDC_AC_PCM), BM_GETCHECK, 0, 0); + LRESULT lRet = SendMessage(GetDlgItem(hWndDlg, IDC_AC_PCM), BM_GETCHECK, 0, 0); - g_XBAudio.SetPCM(lRet == BST_CHECKED); + g_XBAudio.codec_pcm = (lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_AC_XADPCM), BM_GETCHECK, 0, 0); - g_XBAudio.SetXADPCM(lRet == BST_CHECKED); + g_XBAudio.codec_xadpcm = (lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_AC_UNKNOWN_CODEC), BM_GETCHECK, 0, 0); - g_XBAudio.SetUnknownCodec(lRet == BST_CHECKED); + g_XBAudio.codec_unknown = (lRet == BST_CHECKED); } /*! save audio configuration */ - g_EmuShared->SetXBAudio(&g_XBAudio); + g_Settings->m_audio = g_XBAudio; EndDialog(hWndDlg, wParam); } @@ -203,7 +203,7 @@ VOID RefreshAudioAdapter() { /*! save configured audio adapter */ { - GUID oldGUID = g_XBAudio.GetAudioAdapter(); + GUID oldGUID = g_XBAudio.adapterGUID; DWORD dwAudioAdapter = (DWORD)SendMessage(g_hAudioAdapter, CB_GETCURSEL, 0, 0); @@ -222,13 +222,13 @@ VOID RefreshAudioAdapter() if(binGUID != oldGUID) { g_bHasChanges = TRUE; - g_XBAudio.SetAudioAdapter(binGUID); + g_XBAudio.adapterGUID = binGUID; } // Force save default audio device if selected audio device is invalid. if (pGUID == (LPGUID)CB_ERR) { SendMessage(g_hAudioAdapter, CB_SETCURSEL, 0, 0); - g_EmuShared->SetXBAudio(&g_XBAudio); + g_Settings->m_audio = g_XBAudio; MessageBox(nullptr, "Your selected audio adapter is invalid,\n" "reverting to default audio adapter.", "Cxbx-Reloaded", MB_OK | MB_ICONEXCLAMATION); } diff --git a/src/Cxbx/DlgControllerConfig.cpp b/src/Cxbx/DlgControllerConfig.cpp index c697873b6..3df2ea548 100644 --- a/src/Cxbx/DlgControllerConfig.cpp +++ b/src/Cxbx/DlgControllerConfig.cpp @@ -34,11 +34,13 @@ // * // ****************************************************************** -#include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" // for g_Settings #include "DlgControllerConfig.h" #include "ResCxbx.h" +#include "Common/Win32/DInputController.h" +#define DIRECTINPUT_VERSION 0x0800 #include #include @@ -50,7 +52,7 @@ static VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object); static VOID EnableButtonWindows(HWND hWndDlg, HWND hExclude, BOOL bEnable); /*! controller configuration */ -static XBController g_XBController; +static DInputController g_DInputController; /*! changes flag */ static BOOL g_bHasChanges = FALSE; @@ -60,7 +62,7 @@ VOID ShowControllerConfig(HWND hwnd) g_bHasChanges = FALSE; /*! retrieve controller configuration */ - g_EmuShared->GetXBController(&g_XBController); + g_DInputController.m_settings = g_Settings->m_controller_dinput; /*! show dialog box */ DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CONTROLLER_CFG), hwnd, DlgControllerConfigProc); @@ -114,7 +116,7 @@ INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, break; case IDC_INPUT_CONFIG_ACCEPT: - g_EmuShared->SetXBController(&g_XBController); + g_Settings->m_controller_dinput = g_DInputController.m_settings; EndDialog(hWndDlg, wParam); break; @@ -286,7 +288,7 @@ VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object) SetWindowText(GetDlgItem(hWndDlg, IDC_CONFIG_STATUS), "Waiting for your input..."); GetWindowText(hWndButton, szOrgText, 32); - g_XBController.ConfigBegin(hWndDlg, object); + g_DInputController.ConfigBegin(hWndDlg, object); // wait for input, or 5 second timeout for(int v=100;v>0;v--) @@ -299,14 +301,19 @@ VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object) sprintf(szBuffer, "%d", (v+19)/20); SetWindowText(hWndButton, szBuffer); + + // NOTE: This fix false positive of non-responding message when inputting all keys at once. + // Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633526%28v=vs.85%29.aspx + MSG Msg; + PeekMessage(&Msg, hWndDlg, 0, 0, PM_NOREMOVE); } - if(g_XBController.HasError()) + if(g_DInputController.HasError()) { goto cleanup; } - if(g_XBController.ConfigPoll(szNewText)) + if(g_DInputController.ConfigPoll(szNewText)) { break; } @@ -314,13 +321,13 @@ VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object) Sleep(50); } - if(g_XBController.HasError()) + if(g_DInputController.HasError()) { goto cleanup; } else { - g_XBController.ConfigEnd(); + g_DInputController.ConfigEnd(); } cleanup: @@ -330,9 +337,9 @@ cleanup: /*! update window with status */ { - if(g_XBController.HasError()) + if(g_DInputController.HasError()) { - sprintf(szNewText, "%s", g_XBController.GetError().c_str()); + sprintf(szNewText, "%s", g_DInputController.GetError().c_str()); } SetWindowText(hWndButton, szOrgText); diff --git a/src/Cxbx/DlgVideoConfig.cpp b/src/Cxbx/DlgVideoConfig.cpp index 8cb7d8093..738974079 100644 --- a/src/Cxbx/DlgVideoConfig.cpp +++ b/src/Cxbx/DlgVideoConfig.cpp @@ -34,12 +34,12 @@ // * // ****************************************************************** -#include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" // for g_Settings #include "DlgVideoConfig.h" #include "ResCxbx.h" -#include "CxbxKrnl/EmuD3D8Types.h" +#include "CxbxKrnl/EmuXTL.h" /*! windows dialog procedure */ static INT_PTR CALLBACK DlgVideoConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -51,7 +51,7 @@ static VOID RefreshDirect3DDevice(); /*! direct3d instance */ static XTL::IDirect3D *g_pDirect3D = 0; /*! video configuration */ -static XBVideo g_XBVideo; +static Settings::s_video g_XBVideo; /*! changes flag */ static BOOL g_bHasChanges = FALSE; /*! number of adapters */ @@ -69,7 +69,7 @@ VOID ShowVideoConfig(HWND hwnd) g_bHasChanges = FALSE; /*! retrieve video configuration */ - g_EmuShared->GetXBVideo(&g_XBVideo); + g_XBVideo = g_Settings->m_video; /*! initialize direct3d */ { @@ -122,18 +122,18 @@ INT_PTR CALLBACK DlgVideoConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR } /*! activate configured display adapter */ - SendMessage(g_hDisplayAdapter, CB_SETCURSEL, g_XBVideo.GetDisplayAdapter(), 0); + SendMessage(g_hDisplayAdapter, CB_SETCURSEL, g_XBVideo.adapter, 0); /*! refresh UI based on currently selected display adapter */ RefreshDisplayAdapter(); /*! check appropriate options */ { - SendMessage(GetDlgItem(hWndDlg, IDC_CV_FULLSCREEN), BM_SETCHECK, (WPARAM)g_XBVideo.GetFullscreen(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_CV_FULLSCREEN), BM_SETCHECK, (WPARAM)g_XBVideo.bFullScreen, 0); - SendMessage(GetDlgItem(hWndDlg, IDC_CV_VSYNC), BM_SETCHECK, (WPARAM)g_XBVideo.GetVSync(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_CV_VSYNC), BM_SETCHECK, (WPARAM)g_XBVideo.bVSync, 0); - SendMessage(GetDlgItem(hWndDlg, IDC_CV_HARDWAREYUV), BM_SETCHECK, (WPARAM)g_XBVideo.GetHardwareYUV(), 0); + SendMessage(GetDlgItem(hWndDlg, IDC_CV_HARDWAREYUV), BM_SETCHECK, (WPARAM)g_XBVideo.bHardwareYUV, 0); } } break; @@ -183,26 +183,29 @@ INT_PTR CALLBACK DlgVideoConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR lRet = SendMessage(hVideoResolution, CB_GETLBTEXT, (WPARAM)lRet, (LPARAM)szBuffer); - g_XBVideo.SetVideoResolution(szBuffer); + strncpy(g_XBVideo.szVideoResolution, szBuffer, std::size(g_XBVideo.szVideoResolution)); + + // For prevent buffer overflow whenever copy string from another location. + g_XBVideo.szVideoResolution[std::size(g_XBVideo.szVideoResolution)-1] = '\0'; } /*! save fullscreen/vsync/YUV options */ { LRESULT lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_FULLSCREEN), BM_GETCHECK, 0, 0); - g_XBVideo.SetFullscreen(lRet == BST_CHECKED); + g_XBVideo.bFullScreen = (lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_VSYNC), BM_GETCHECK, 0, 0); - g_XBVideo.SetVSync(lRet == BST_CHECKED); + g_XBVideo.bVSync = (lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_HARDWAREYUV), BM_GETCHECK, 0, 0); - g_XBVideo.SetHardwareYUV(lRet == BST_CHECKED); + g_XBVideo.bHardwareYUV = (lRet == BST_CHECKED); } /*! save video configuration */ - g_EmuShared->SetXBVideo(&g_XBVideo); + g_Settings->m_video = g_XBVideo; EndDialog(hWndDlg, wParam); } @@ -238,7 +241,7 @@ VOID RefreshDisplayAdapter() { /*! save configured display adapter */ { - DWORD dwOld = g_XBVideo.GetDisplayAdapter(); + DWORD dwOld = g_XBVideo.adapter; DWORD dwDisplayAdapter = (DWORD)SendMessage(g_hDisplayAdapter, CB_GETCURSEL, 0, 0); @@ -246,7 +249,7 @@ VOID RefreshDisplayAdapter() { g_bHasChanges = TRUE; - g_XBVideo.SetDisplayAdapter(dwDisplayAdapter); + g_XBVideo.adapter = dwDisplayAdapter; } } @@ -267,7 +270,7 @@ VOID RefreshDisplayAdapter() XTL::D3DCAPS Caps; /*! verify device is available */ - if(g_pDirect3D->GetDeviceCaps(g_XBVideo.GetDisplayAdapter(), devType[d], &Caps) == D3D_OK) + if(g_pDirect3D->GetDeviceCaps(g_XBVideo.adapter, devType[d], &Caps) == D3D_OK) { /*! add device to list */ SendMessage(g_hDirect3DDevice, CB_ADDSTRING, 0, (LPARAM)szDevType[d]); @@ -276,7 +279,7 @@ VOID RefreshDisplayAdapter() } /*! activate configured device */ - SendMessage(g_hDirect3DDevice, CB_SETCURSEL, g_XBVideo.GetDirect3DDevice(), 0); + SendMessage(g_hDirect3DDevice, CB_SETCURSEL, g_XBVideo.direct3DDevice, 0); /*! refresh based on new device selection */ RefreshDirect3DDevice(); @@ -290,7 +293,7 @@ VOID RefreshDirect3DDevice() /*! save configured device */ { - DWORD dwOld = g_XBVideo.GetDirect3DDevice(); + DWORD dwOld = g_XBVideo.direct3DDevice; DWORD dwDirect3DDevice = SendMessage(g_hDirect3DDevice, CB_GETCURSEL, 0, 0); @@ -298,7 +301,7 @@ VOID RefreshDirect3DDevice() { g_bHasChanges = TRUE; - g_XBVideo.SetDirect3DDevice(dwDirect3DDevice); + g_XBVideo.direct3DDevice = dwDirect3DDevice; } } @@ -310,7 +313,7 @@ VOID RefreshDirect3DDevice() /*! enumerate display modes */ { uint32 dwAdapterModeCount = g_pDirect3D->GetAdapterModeCount( - g_XBVideo.GetDisplayAdapter() + g_XBVideo.adapter #ifdef CXBX_USE_D3D9 , XTL::D3DFMT_X8R8G8B8 #endif @@ -326,7 +329,7 @@ VOID RefreshDirect3DDevice() XTL::D3DDISPLAYMODE displayMode; g_pDirect3D->EnumAdapterModes( - g_XBVideo.GetDisplayAdapter(), + g_XBVideo.adapter, #ifdef CXBX_USE_D3D9 XTL::D3DFMT_X8R8G8B8, #endif @@ -367,7 +370,7 @@ VOID RefreshDirect3DDevice() } /*! if current mode is the configured video resolution, activate it in the list */ - if(strcmp(szBuffer, g_XBVideo.GetVideoResolution()) == 0) + if(strcmp(szBuffer, g_XBVideo.szVideoResolution) == 0) { dwVideoResolution = v+1; } diff --git a/src/Cxbx/DlgXboxControllerPortMapping.cpp b/src/Cxbx/DlgXboxControllerPortMapping.cpp index b69af3a5e..9357c52fc 100644 --- a/src/Cxbx/DlgXboxControllerPortMapping.cpp +++ b/src/Cxbx/DlgXboxControllerPortMapping.cpp @@ -34,11 +34,13 @@ // * // ****************************************************************** -#include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" // for g_Settings + #include "DlgXboxControllerPortMapping.h" #include "../Common/Win32/XBPortMapping.h" #include "Windowsx.h" #include "ResCxbx.h" +#include "CxbxKrnl/EmuXTL.h" #include @@ -70,8 +72,8 @@ INT_PTR CALLBACK DlgXboxControllerPortMappingProc(HWND hWndDlg, UINT uMsg, WPARA { /*! set window icon */ SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX))); - //Load saved configuration from registry. - XBPortMappingLoad("Software\\Cxbx-Reloaded\\XboxPortHostMapping");//"Software\\Cxbx-Reloaded\\XboxPortHostMapping" + // Load configuration from settings. + XBPortMappingSet(g_Settings->m_controller_port); //Init dialog selections per global array contenst. XTL::DWORD port = 0; int index = 0; @@ -140,8 +142,8 @@ INT_PTR CALLBACK DlgXboxControllerPortMappingProc(HWND hWndDlg, UINT uMsg, WPARA EndDialog(hWndDlg, wParam); break; case IDC_HOST_APPLY: - //save configuration to registry. - XBPortMappingSave("Software\\Cxbx-Reloaded\\XboxPortHostMapping"); + // Save configuration to settings. + XBPortMappingGet(g_Settings->m_controller_port); EndDialog(hWndDlg, wParam); break; //set host type and host port in global array xbox to host bridge for xbox port 0 diff --git a/src/Cxbx/ResCxbx.h b/src/Cxbx/ResCxbx.h index 7b5f220aa..87e2c2367 100644 --- a/src/Cxbx/ResCxbx.h +++ b/src/Cxbx/ResCxbx.h @@ -281,6 +281,7 @@ #define ID_SETTINGS_CONFIG_DLOCCUSTOM 40104 #define ID_SETTINGS_CONFIG_DLOCAPPDATA 40105 #define ID_SETTINGS_CONFIG_DLOCCURDIR 40106 +#define ID_SETTINGS_ALLOWADMINPRIVILEGE 40107 #define IDC_STATIC -1 // Next default values for new objects @@ -288,7 +289,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 135 -#define _APS_NEXT_COMMAND_VALUE 40107 +#define _APS_NEXT_COMMAND_VALUE 40108 #define _APS_NEXT_CONTROL_VALUE 1256 #define _APS_NEXT_SYMED_VALUE 104 #endif diff --git a/src/Cxbx/WinMain.cpp b/src/Cxbx/WinMain.cpp index 8c976e7a7..80c907cbf 100644 --- a/src/Cxbx/WinMain.cpp +++ b/src/Cxbx/WinMain.cpp @@ -39,6 +39,7 @@ #include "CxbxKrnl/CxbxKrnl.h" #include "CxbxKrnl/Emu.h" #include "CxbxKrnl/EmuShared.h" +#include "Common/Settings.hpp" #include // Enable Visual Styles @@ -68,26 +69,65 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine if ((UINT_PTR)GetModuleHandle(nullptr) != CXBX_BASE_ADDR) { /*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of - the Cxbx.exe host executable. + the Cxbx.exe host executable. Set in Cxbx Project options, Linker, Advanced, Base Address */ MessageBox(NULL, "Cxbx.exe is not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", MB_OK | MB_ICONERROR); return EXIT_FAILURE; } + bool bRet, bKernel; + HWND hWnd = nullptr; + DWORD guiProcessID = 0; + + if (__argc >= 2 && std::strcmp(__argv[1], "/load") == 0 && std::strlen(__argv[2]) > 0) { + bKernel = true; + + // Perform check if command line contain gui's hWnd value. + if (__argc > 2) { + hWnd = (HWND)std::stoi(__argv[3], nullptr, 10); + + hWnd = IsWindow(hWnd) ? hWnd : nullptr; + if (hWnd != nullptr) { + // We don't need thread ID from window handle. + GetWindowThreadProcessId(hWnd, &guiProcessID); + } + } + } + else { + bKernel = false; + guiProcessID = GetCurrentProcessId(); + } + /*! initialize shared memory */ - EmuShared::Init(); + EmuShared::Init(guiProcessID); bool bFirstLaunch; g_EmuShared->GetIsFirstLaunch(&bFirstLaunch); /* check if process is launch with elevated access then prompt for continue on or not. */ if (!bFirstLaunch) { + + g_Settings = new Settings(); + + if (g_Settings == nullptr) { + MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK); + EmuShared::Cleanup(); + return EXIT_FAILURE; + } + + bRet = g_Settings->Init(); + if (!bRet) { + EmuShared::Cleanup(); + return EXIT_FAILURE; + } + bool bElevated = CxbxIsElevated(); - if (bElevated && !bFirstLaunch) { + + if (bElevated && !g_Settings->m_core.allowAdminPrivilege) { int ret = MessageBox(NULL, "Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n" - "\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n" - "\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING); + "\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n" + "\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING); if (ret != IDYES) { EmuShared::Cleanup(); return EXIT_FAILURE; @@ -96,7 +136,28 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine g_EmuShared->SetIsFirstLaunch(true); } - if (__argc >= 2 && strcmp(__argv[1], "/load") == 0 && strlen(__argv[2]) > 0) { + if (bKernel) { + + // NOTE: This is designated for standalone kernel mode launch without GUI + if (g_Settings != nullptr) { + + // Reset to default + g_EmuShared->Reset(); + + g_Settings->Verify(); + g_Settings->SyncToEmulator(); + + // We don't need to keep Settings open plus allow emulator to use unused memory. + delete g_Settings; + g_Settings = nullptr; + + // Perform identical to what GUI will do to certain EmuShared's variable before launch. + g_EmuShared->SetIsEmulating(true); + + // NOTE: This setting the ready status is optional. Internal kernel process is checking if GUI is running. + // Except if enforce check, then we need to re-set ready status every time for non-GUI. + //g_EmuShared->SetIsReady(true); + } /* Initialize Cxbx File Paths */ CxbxInitFilePaths(); @@ -105,6 +166,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine return EXIT_SUCCESS; } + // If 2nd GUI executable is launched, load settings file for GUI for editable support. + if (g_Settings == nullptr) { + g_Settings = new Settings(); + + if (g_Settings == nullptr) { + MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK); + EmuShared::Cleanup(); + return EXIT_FAILURE; + } + + bRet = g_Settings->Init(); + if (!bRet) { + EmuShared::Cleanup(); + return EXIT_FAILURE; + } + } + INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES; diff --git a/src/Cxbx/WndMain.cpp b/src/Cxbx/WndMain.cpp index 9de358cd1..0c6d03aed 100644 --- a/src/Cxbx/WndMain.cpp +++ b/src/Cxbx/WndMain.cpp @@ -29,6 +29,8 @@ // * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. // * // * (c) 2002-2003 Aaron Robinson +// * (c) 2017-2018 RadWolfie +// * (c) 2018 wutno (#/g/punk - Rizon) // * // * All rights reserved // * @@ -42,6 +44,9 @@ #include "DlgXboxControllerPortMapping.h" #include "Common/XbePrinter.h" // For DumpInformation #include "CxbxKrnl/EmuShared.h" +#include "CxbxKrnl/EmuXTL.h" +#include "Common/Settings.hpp" + #include "..\CxbxKrnl\CxbxKrnl.h" // For CxbxConvertArgToString and CxbxExec #include "ResCxbx.h" #include "CxbxVersion.h" @@ -65,7 +70,7 @@ static int splashLogoWidth, splashLogoHeight; bool g_SaveOnExit = true; -void ClearHLECache(char sStorageLocation[MAX_PATH]) +void ClearHLECache(const char sStorageLocation[MAX_PATH]) { std::string cacheDir = std::string(sStorageLocation) + "\\HLECache\\"; std::string fullpath = cacheDir + "*.ini"; @@ -93,14 +98,10 @@ void ClearHLECache(char sStorageLocation[MAX_PATH]) printf("Cleared HLE Cache\n"); } -void WndMain::InitializeSettings() { - HKEY hKey; - if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cxbx-Reloaded", 0, KEY_ENUMERATE_SUB_KEYS | DELETE | KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { - RegDeleteTree(hKey, NULL); - RegCloseKey(hKey); - - g_SaveOnExit = false; - } +void WndMain::InitializeSettings() +{ + g_Settings->Delete(); + g_SaveOnExit = false; } #define TIMERID_FPS 0 @@ -116,10 +117,10 @@ void WndMain::ResizeWindow(HWND hwnd, bool bForGUI) m_h = 480; if (!bForGUI) { // For emulation, get the configured window dimensions - XBVideo XBVideoConf; - g_EmuShared->GetXBVideo(&XBVideoConf); + Settings::s_video XBVideoConf; + g_EmuShared->GetVideoSettings(&XBVideoConf); - const char* resolution = XBVideoConf.GetVideoResolution(); + const char* resolution = XBVideoConf.szVideoResolution; if (2 != sscanf(resolution, "%d x %d", &m_w, &m_h)) { DbgPrintf("Couldn't parse resolution : %s.\n", resolution); } @@ -166,301 +167,42 @@ WndMain::WndMain(HINSTANCE x_hInstance) : m_bXbeChanged(false), m_bIsStarted(false), m_hwndChild(nullptr), - m_KrnlDebug(DM_NONE), - m_CxbxDebug(DM_NONE), - m_FlagsLLE(0), - m_StorageToggle(CXBX_DATA_APPDATA), - m_StorageLocation(""), - m_dwRecentXbe(0), m_hDebuggerProc(nullptr), m_hDebuggerMonitorThread(), m_prevWindowLoc({ -1, -1 }) { - // initialize members - { - m_classname = "WndMain"; - m_wndname = "Cxbx-Reloaded " _CXBX_VERSION; + // initialize members + { + m_classname = "WndMain"; + m_wndname = "Cxbx-Reloaded " _CXBX_VERSION; + } - m_XbeFilename = (char*)calloc(1, MAX_PATH); + // load configuration from settings file + { + // NOTE: Settings has already been initalized/load from file before WndMain constructed. - m_CxbxDebugFilename = (char*)calloc(1, MAX_PATH); - m_KrnlDebugFilename = (char*)calloc(1, MAX_PATH); + g_Settings->Verify(); - for(int v=0;vSetStorageLocation(g_Settings->GetDataLocation().c_str()); - // load configuration from registry - { - DWORD dwDisposition, dwType, dwSize; - HKEY hKey; - - if(RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Cxbx-Reloaded", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) - { - LONG result = ERROR_SUCCESS; - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "LLEFLAGS", NULL, &dwType, (PBYTE)&m_FlagsLLE, &dwSize); - if (result != ERROR_SUCCESS) { - m_FlagsLLE = 0; + unsigned int i = 0; + do { + if (g_Settings->m_gui.szRecentXbeFiles[i].size() == 0) { + break; } + i++; + } while (i < RECENT_XBE_LIST_MAX); - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackDisablePixelShaders", NULL, &dwType, (PBYTE)&m_DisablePixelShaders, &dwSize); - if (result != ERROR_SUCCESS) { - m_DisablePixelShaders = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackUncapFrameRate", NULL, &dwType, (PBYTE)&m_UncapFramerate, &dwSize); - if (result != ERROR_SUCCESS) { - m_UncapFramerate = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackUseAllCores", NULL, &dwType, (PBYTE)&m_UseAllCores, &dwSize); - if (result != ERROR_SUCCESS) { - m_UseAllCores = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackSkipRdtscPatching", NULL, &dwType, (PBYTE)&m_SkipRdtscPatching, &dwSize); - if (result != ERROR_SUCCESS) { - m_SkipRdtscPatching = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackScaleViewport", NULL, &dwType, (PBYTE)&m_ScaleViewport, &dwSize); - if (result != ERROR_SUCCESS) { - m_ScaleViewport = 0; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "HackDirectBackBufferAccess", NULL, &dwType, (PBYTE)&m_DirectHostBackBufferAccess, &dwSize); - if (result != ERROR_SUCCESS) { - m_DirectHostBackBufferAccess = 1; - } - - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "CxbxDebug", NULL, &dwType, (PBYTE)&m_CxbxDebug, &dwSize); - if (result != ERROR_SUCCESS) { - m_CxbxDebug = DebugMode::DM_NONE; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "KrnlDebug", NULL, &dwType, (PBYTE)&m_KrnlDebug, &dwSize); - if (result != ERROR_SUCCESS) { - m_KrnlDebug = DebugMode::DM_NONE; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "RecentXbe", NULL, &dwType, (PBYTE)&m_dwRecentXbe, &dwSize); - if (result != ERROR_SUCCESS) { - m_dwRecentXbe = 0; - } - - dwType = REG_SZ; dwSize = MAX_PATH; ULONG lErrCodeCxbxDebugFilename; - lErrCodeCxbxDebugFilename = RegQueryValueEx(hKey, "CxbxDebugFilename", NULL, &dwType, (PBYTE)m_CxbxDebugFilename, &dwSize); - if (lErrCodeCxbxDebugFilename != ERROR_SUCCESS) { - m_CxbxDebugFilename[0] = '\0'; - } - - dwType = REG_SZ; dwSize = MAX_PATH; LONG lErrCodeKrnlDebugFilename; - lErrCodeKrnlDebugFilename = RegQueryValueEx(hKey, "KrnlDebugFilename", NULL, &dwType, (PBYTE)m_KrnlDebugFilename, &dwSize); - if (lErrCodeKrnlDebugFilename != ERROR_SUCCESS) { - m_KrnlDebugFilename[0] = '\0'; - } - - dwType = REG_DWORD; dwSize = sizeof(DWORD); - result = RegQueryValueEx(hKey, "DataStorageToggle", NULL, &dwType, (PBYTE)&m_StorageToggle, &dwSize); - if (result != ERROR_SUCCESS) { - m_StorageToggle = CXBX_DATA_APPDATA; - } - - switch (m_StorageToggle) { - case CXBX_DATA_APPDATA: - default: - SHGetSpecialFolderPath(NULL, m_StorageLocation, CSIDL_APPDATA, TRUE); - m_StorageToggle = CXBX_DATA_APPDATA; - strncat(m_StorageLocation, "\\Cxbx-Reloaded", MAX_PATH); - break; - - case CXBX_DATA_CURDIR: - GetCurrentDirectory(MAX_PATH, m_StorageLocation); - break; - - case CXBX_DATA_CUSTOM: - dwType = REG_SZ; dwSize = MAX_PATH; - result = RegQueryValueEx(hKey, "DataStorageLocation", NULL, &dwType, (PBYTE)&m_StorageLocation, &dwSize); - if (result != ERROR_SUCCESS) { - SHGetSpecialFolderPath(NULL, m_StorageLocation, CSIDL_APPDATA, TRUE); - strncat(m_StorageLocation, "\\Cxbx-Reloaded", MAX_PATH); - } - break; - } - // NOTE: This is a requirement for pre-verification from GUI. Used in CxbxInitFilePaths function. - g_EmuShared->SetStorageLocation(m_StorageLocation); - - // Prevent using an incorrect path from the registry if the debug folders have been moved - if (m_CxbxDebug == DM_FILE) - { - if(lErrCodeCxbxDebugFilename == ERROR_FILE_NOT_FOUND || strlen(m_CxbxDebugFilename) == 0) - { - m_CxbxDebug = DM_NONE; - } - else - { - char *CxbxDebugPath = (char*)calloc(1, MAX_PATH); - char *CxbxDebugName = (char*)calloc(1, MAX_PATH); - - strcpy(CxbxDebugName, strrchr(m_CxbxDebugFilename, '\\')); - - if(strlen(m_CxbxDebugFilename) < strlen(CxbxDebugName)) - { - memset((char*)m_CxbxDebugFilename, '\0', MAX_PATH); - m_CxbxDebug = DM_NONE; - } - else - { - strncpy(CxbxDebugPath, m_CxbxDebugFilename, strlen(m_CxbxDebugFilename) - strlen(CxbxDebugName)); - if(PathFileExists((LPCSTR)CxbxDebugPath) == FALSE) - { - memset((char*)m_CxbxDebugFilename, '\0', MAX_PATH); - m_CxbxDebug = DM_NONE; - } - } - free(CxbxDebugPath); - free(CxbxDebugName); - } - } - - if (m_KrnlDebug == DM_FILE) - { - if(lErrCodeKrnlDebugFilename == ERROR_FILE_NOT_FOUND || strlen(m_KrnlDebugFilename) == 0) - { - m_KrnlDebug = DM_NONE; - } - else - { - char *KrnlDebugPath = (char*)calloc(1, MAX_PATH); - char *KrnlDebugName = (char*)calloc(1, MAX_PATH); - - strcpy(KrnlDebugName, strrchr(m_KrnlDebugFilename, '\\')); - - if(strlen(m_KrnlDebugFilename) < strlen(KrnlDebugName)) - { - memset((char*)m_KrnlDebugFilename, '\0', MAX_PATH); - m_KrnlDebug = DM_NONE; - } - else - { - strncpy(KrnlDebugPath, m_KrnlDebugFilename, strlen(m_KrnlDebugFilename) - strlen(KrnlDebugName)); - if(PathFileExists((LPCSTR)KrnlDebugPath) == FALSE) - { - memset((char*)m_KrnlDebugFilename, '\0', MAX_PATH); - m_KrnlDebug = DM_NONE; - } - } - free(KrnlDebugPath); - free(KrnlDebugName); - } - } - - int v=0; - - for(v=0;vSave(); } // Close opened debugger monitor if there is one @@ -469,11 +211,7 @@ WndMain::~WndMain() // cleanup allocations { delete m_Xbe; - - free(m_XbeFilename); - - free(m_CxbxDebugFilename); - free(m_KrnlDebugFilename); + delete g_Settings; } } @@ -525,7 +263,7 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP m_SplashDC = CreateCompatibleDC(hDC); m_LogoDC = CreateCompatibleDC(hDC); - + m_OrigBmp = (HBITMAP)SelectObject(m_SplashDC, m_SplashBmp); m_OrigLogo = (HBITMAP)SelectObject(m_LogoDC, m_LogoBmp); @@ -596,7 +334,6 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP pCMD->dwChildProcID = lParam; // lParam is process ID. std::thread(CrashMonitorWrapper, pCMD).detach(); - g_EmuShared->SetFlagsLLE(&m_FlagsLLE); g_EmuShared->SetIsEmulating(true); // NOTE: Putting in here raise to low or medium risk due to debugger will launch itself. (Current workaround) g_EmuShared->SetIsReady(true); break; @@ -1264,8 +1001,8 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP break; } - m_StorageToggle = CXBX_DATA_CUSTOM; - strncpy(m_StorageLocation, szDirTemp.c_str(), MAX_PATH); + g_Settings->m_gui.DataStorageToggle = CXBX_DATA_CUSTOM; + g_Settings->m_gui.szCustomLocation = szDirTemp; RefreshMenus(); } } @@ -1273,35 +1010,28 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_SETTINGS_CONFIG_DLOCAPPDATA: { - char szDir[MAX_PATH]; - - SHGetSpecialFolderPath(NULL, szDir, CSIDL_APPDATA, TRUE); - m_StorageToggle = CXBX_DATA_APPDATA; - strncpy(m_StorageLocation, szDir, MAX_PATH); - strncat(m_StorageLocation, "\\Cxbx-Reloaded", MAX_PATH); + g_Settings->m_gui.DataStorageToggle = CXBX_DATA_APPDATA; RefreshMenus(); } break; case ID_SETTINGS_CONFIG_DLOCCURDIR: { - - GetCurrentDirectory(MAX_PATH, m_StorageLocation); - m_StorageToggle = CXBX_DATA_CURDIR; + g_Settings->m_gui.DataStorageToggle = CXBX_DATA_CURDIR; RefreshMenus(); } break; case ID_CACHE_CLEARHLECACHE_ALL: { - ClearHLECache(m_StorageLocation); + ClearHLECache(g_Settings->GetDataLocation().c_str()); MessageBox(m_hwnd, "The entire HLE Cache has been cleared.", "Cxbx-Reloaded", MB_OK); } break; case ID_CACHE_CLEARHLECACHE_CURRENT: { - std::string cacheDir = std::string(m_StorageLocation) + "\\HLECache\\"; + std::string cacheDir = g_Settings->GetDataLocation() + "\\HLECache\\"; // Hash the loaded XBE's header, use it as a filename uint32_t uiHash = XXHash32::hash((void*)&m_Xbe->m_Header, sizeof(Xbe::Header), 0); @@ -1332,11 +1062,12 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE: { - if (m_KrnlDebug == DM_NONE || m_KrnlDebug == DM_FILE) - m_KrnlDebug = DM_CONSOLE; - else - m_KrnlDebug = DM_NONE; - + if (g_Settings->m_core.KrnlDebugMode == DM_NONE || g_Settings->m_core.KrnlDebugMode == DM_FILE) { + g_Settings->m_core.KrnlDebugMode = DM_CONSOLE; + } + else { + g_Settings->m_core.KrnlDebugMode = DM_NONE; + } MessageBox(m_hwnd, "This will not take effect until the next time emulation is started.\n", "Cxbx-Reloaded", MB_OK); RefreshMenus(); @@ -1347,9 +1078,8 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_EMULATION_DEBUGOUTPUTKERNEL_FILE: { - if (m_KrnlDebug == DM_FILE) - { - m_KrnlDebug = DM_NONE; + if (g_Settings->m_core.KrnlDebugMode == DM_FILE) { + g_Settings->m_core.KrnlDebugMode = DM_NONE; RefreshMenus(); @@ -1377,9 +1107,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP { MessageBox(m_hwnd, "This will not take effect until emulation is (re)started.\n", "Cxbx-Reloaded", MB_OK); - strncpy(m_KrnlDebugFilename, ofn.lpstrFile, MAX_PATH - 1); + strncpy(g_Settings->m_core.szKrnlDebug, ofn.lpstrFile, MAX_PATH - 1); - m_KrnlDebug = DM_FILE; + g_Settings->m_core.KrnlDebugMode = DM_FILE; RefreshMenus(); @@ -1391,11 +1121,12 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE: { - if (m_CxbxDebug == DM_NONE || m_CxbxDebug == DM_FILE) - m_CxbxDebug = DM_CONSOLE; - else - m_CxbxDebug = DM_NONE; - + if (g_Settings->m_gui.CxbxDebugMode == DM_NONE || g_Settings->m_gui.CxbxDebugMode == DM_FILE) { + g_Settings->m_gui.CxbxDebugMode = DM_CONSOLE; + } + else { + g_Settings->m_gui.CxbxDebugMode = DM_NONE; + } RefreshMenus(); UpdateDebugConsoles(); @@ -1404,9 +1135,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_EMULATION_DEBUGOUTPUTGUI_FILE: { - if (m_CxbxDebug == DM_FILE) + if (g_Settings->m_gui.CxbxDebugMode == DM_FILE) { - m_CxbxDebug = DM_NONE; + g_Settings->m_gui.CxbxDebugMode = DM_NONE; RefreshMenus(); @@ -1432,9 +1163,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP if (GetSaveFileName(&ofn) != FALSE) { - strncpy(m_CxbxDebugFilename, ofn.lpstrFile, MAX_PATH - 1); + g_Settings->m_gui.szCxbxDebugFile = ofn.lpstrFile; - m_CxbxDebug = DM_FILE; + g_Settings->m_gui.CxbxDebugMode = DM_FILE; RefreshMenus(); @@ -1447,28 +1178,28 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP case ID_EMULATION_LLE_JIT: { - m_FlagsLLE = m_FlagsLLE ^ LLE_JIT; + g_Settings->m_core.FlagsLLE = g_Settings->m_core.FlagsLLE ^ LLE_JIT; RefreshMenus(); } break; case ID_EMULATION_LLE_APU: { - m_FlagsLLE = m_FlagsLLE ^ LLE_APU; + g_Settings->m_core.FlagsLLE = g_Settings->m_core.FlagsLLE ^ LLE_APU; RefreshMenus(); } break; case ID_EMULATION_LLE_GPU: { - m_FlagsLLE = m_FlagsLLE ^ LLE_GPU; + g_Settings->m_core.FlagsLLE = g_Settings->m_core.FlagsLLE ^ LLE_GPU; RefreshMenus(); } break; #if 0 // Reenable this when LLE USB actually works case ID_EMULATION_LLE_USB: { - m_FlagsLLE = m_FlagsLLE ^ LLE_USB; + g_Settings->m_core.FlagsLLE = g_Settings->m_core.FlagsLLE ^ LLE_USB; RefreshMenus(); } break; @@ -1492,32 +1223,37 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP break; case ID_HACKS_DISABLEPIXELSHADERS: - m_DisablePixelShaders = !m_DisablePixelShaders; + g_Settings->m_hacks.DisablePixelShaders = !g_Settings->m_hacks.DisablePixelShaders; RefreshMenus(); break; case ID_HACKS_UNCAPFRAMERATE: - m_UncapFramerate = !m_UncapFramerate; + g_Settings->m_hacks.UncapFramerate = !g_Settings->m_hacks.UncapFramerate; RefreshMenus(); break; case ID_HACKS_RUNXBOXTHREADSONALLCORES: - m_UseAllCores = !m_UseAllCores; + g_Settings->m_hacks.UseAllCores = !g_Settings->m_hacks.UseAllCores; RefreshMenus(); break; case ID_HACKS_SKIPRDTSCPATCHING: - m_SkipRdtscPatching = !m_SkipRdtscPatching; + g_Settings->m_hacks.SkipRdtscPatching = !g_Settings->m_hacks.SkipRdtscPatching; RefreshMenus(); break; case ID_HACKS_SCALEVIEWPORT: - m_ScaleViewport = !m_ScaleViewport; + g_Settings->m_hacks.ScaleViewport = !g_Settings->m_hacks.ScaleViewport; RefreshMenus(); break; case ID_HACKS_RENDERDIRECTLYTOHOSTBACKBUFFER: - m_DirectHostBackBufferAccess = !m_DirectHostBackBufferAccess; + g_Settings->m_hacks.DirectHostBackBufferAccess = !g_Settings->m_hacks.DirectHostBackBufferAccess; + RefreshMenus(); + break; + + case ID_SETTINGS_ALLOWADMINPRIVILEGE: + g_Settings->m_core.allowAdminPrivilege = !g_Settings->m_core.allowAdminPrivilege; RefreshMenus(); break; @@ -1713,7 +1449,7 @@ void WndMain::LoadGameLogo() } gameLogoWidth = 0; - gameLogoHeight = 0; + gameLogoHeight = 0; uint8 *ImageData = NULL; XTL::X_D3DPixelContainer XboxPixelContainer = {}; @@ -1740,7 +1476,7 @@ void WndMain::LoadGameLogo() ImageData = (uint8 *)(pSection + sizeof(DWORD) + pDDSHeader->dwSize); //gameLogoHeight = pDDSHeader->dwHeight; //gameLogoWidth = pDDSHeader->dwWidth; - + // TODO : Use PixelCopy code here to decode. For now, fake it : XTL::CxbxSetPixelContainerHeader(&XboxPixelContainer, 0, // Common - could be X_D3DCOMMON_TYPE_TEXTURE @@ -1888,36 +1624,38 @@ void WndMain::RefreshMenus() HMENU emul_debg = GetSubMenu(view_menu, 0); HMENU emul_krnl = GetSubMenu(view_menu, 1); - if (m_KrnlDebug == DM_CONSOLE) - { - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_CHECKED); - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_UNCHECKED); - } - else if (m_KrnlDebug == DM_FILE) - { - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_UNCHECKED); - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_CHECKED); - } - else - { - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_UNCHECKED); - CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_UNCHECKED); + switch (g_Settings->m_core.KrnlDebugMode) { + case DM_CONSOLE: + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_CHECKED); + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_UNCHECKED); + break; + + case DM_FILE: + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_UNCHECKED); + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_CHECKED); + break; + + default: + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_CONSOLE, MF_UNCHECKED); + CheckMenuItem(emul_krnl, ID_EMULATION_DEBUGOUTPUTKERNEL_FILE, MF_UNCHECKED); + break; } - if (m_CxbxDebug == DM_CONSOLE) - { - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_CHECKED); - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_UNCHECKED); - } - else if (m_CxbxDebug == DM_FILE) - { - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_UNCHECKED); - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_CHECKED); - } - else - { - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_UNCHECKED); - CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_UNCHECKED); + switch (g_Settings->m_gui.CxbxDebugMode) { + case DM_CONSOLE: + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_CHECKED); + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_UNCHECKED); + break; + + case DM_FILE: + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_UNCHECKED); + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_CHECKED); + break; + + default: + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_CONSOLE, MF_UNCHECKED); + CheckMenuItem(emul_debg, ID_EMULATION_DEBUGOUTPUTGUI_FILE, MF_UNCHECKED); + break; } } @@ -1928,55 +1666,58 @@ void WndMain::RefreshMenus() // enable/disable clear current hle cache EnableMenuItem(settings_menu, ID_CACHE_CLEARHLECACHE_CURRENT, MF_BYCOMMAND | MF_WhenXbeLoadedNotRunning); - UINT chk_flag = (m_FlagsLLE & LLE_JIT) ? MF_CHECKED : MF_UNCHECKED; + UINT chk_flag = (g_Settings->m_core.FlagsLLE & LLE_JIT) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_EMULATION_LLE_JIT, chk_flag); - chk_flag = (m_FlagsLLE & LLE_APU) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_core.FlagsLLE & LLE_APU) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_EMULATION_LLE_APU, chk_flag); - chk_flag = (m_FlagsLLE & LLE_GPU) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_core.FlagsLLE & LLE_GPU) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_EMULATION_LLE_GPU, chk_flag); - //chk_flag = (m_FlagsLLE & LLE_USB) ? MF_CHECKED : MF_UNCHECKED; // Reenable this when LLE USB actually works + //chk_flag = (g_Settings->m_core.FlagsLLE & LLE_USB) ? MF_CHECKED : MF_UNCHECKED; // Reenable this when LLE USB actually works //CheckMenuItem(settings_menu, ID_EMULATION_LLE_USB, chk_flag); - chk_flag = (m_DisablePixelShaders) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_hacks.DisablePixelShaders) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_DISABLEPIXELSHADERS, chk_flag); - chk_flag = (m_UncapFramerate) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_hacks.UncapFramerate) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_UNCAPFRAMERATE, chk_flag); - chk_flag = (m_UseAllCores) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_hacks.UseAllCores) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_RUNXBOXTHREADSONALLCORES, chk_flag); - chk_flag = (m_SkipRdtscPatching) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_hacks.SkipRdtscPatching) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_SKIPRDTSCPATCHING, chk_flag); - - chk_flag = (m_ScaleViewport) ? MF_CHECKED : MF_UNCHECKED; + + chk_flag = (g_Settings->m_hacks.ScaleViewport) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_SCALEVIEWPORT, chk_flag); - chk_flag = (m_DirectHostBackBufferAccess) ? MF_CHECKED : MF_UNCHECKED; + chk_flag = (g_Settings->m_hacks.DirectHostBackBufferAccess) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_RENDERDIRECTLYTOHOSTBACKBUFFER, chk_flag); - //bad - switch (m_StorageToggle) - { + switch (g_Settings->m_gui.DataStorageToggle) { case CXBX_DATA_APPDATA: CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_CHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_UNCHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_UNCHECKED); break; + case CXBX_DATA_CURDIR: CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_UNCHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_CHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_UNCHECKED); break; + case CXBX_DATA_CUSTOM: CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCAPPDATA, MF_UNCHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCURDIR, MF_UNCHECKED); CheckMenuItem(settings_menu, ID_SETTINGS_CONFIG_DLOCCUSTOM, MF_CHECKED); break; } + + chk_flag = (g_Settings->m_core.allowAdminPrivilege) ? MF_CHECKED : MF_UNCHECKED; + CheckMenuItem(settings_menu, ID_SETTINGS_ALLOWADMINPRIVILEGE, chk_flag); } // emulation menu @@ -1998,37 +1739,38 @@ void WndMain::RefreshMenus() // update debug consoles void WndMain::UpdateDebugConsoles() { - if(m_CxbxDebug == DM_CONSOLE) - { - if(AllocConsole()) - { - freopen("CONOUT$", "wt", stdout); + switch (g_Settings->m_gui.CxbxDebugMode) { + case DM_CONSOLE: + if (AllocConsole()) { + freopen("CONOUT$", "wt", stdout); - SetConsoleTitle("Cxbx-Reloaded : Debug Console"); + SetConsoleTitle("Cxbx-Reloaded : Debug Console"); - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED); + + printf("%s", "WndMain: Debug console allocated.\n"); + + SetForegroundWindow(m_hwnd); + } + break; + + case DM_FILE: + + freopen(g_Settings->m_gui.szCxbxDebugFile.c_str(), "wt", stdout); + FreeConsole(); printf("%s", "WndMain: Debug console allocated.\n"); + break; - SetForegroundWindow(m_hwnd); - } - } - else if(m_CxbxDebug == DM_FILE) - { - FreeConsole(); + default: - freopen(m_CxbxDebugFilename, "wt", stdout); - - printf("%s", "WndMain: Debug console allocated.\n"); - } - else - { - FreeConsole(); - - char buffer[16]; - - if(GetConsoleTitle(buffer, 16) != NULL) + if (GetConsoleWindow() != NULL) { + fclose(stdout); + FreeConsole(); + } freopen("nul", "w", stdout); + + break; } } @@ -2063,7 +1805,7 @@ void WndMain::UpdateRecentFiles() // NOTE: Resource defines ID_FILE_RXBE_0 through ID_FILE_RXBE_9 must be in order for(int v=0;vm_gui.szRecentXbeFiles[v]); AppendMenu(RXbeMenu, MF_STRING, ID_FILE_RXBE_0 + v, szBuffer); } } @@ -2147,62 +1889,47 @@ void WndMain::OpenXbe(const char *x_filename) } // save this xbe to the list of recent xbe files - if(m_XbeFilename[0] != '\0') - { + if(m_XbeFilename[0] != '\0') { bool found = false; // if this filename already exists, temporarily remove it - for(int c=0, r=0;cm_gui.szRecentXbeFiles[c].c_str(), m_XbeFilename) == 0) { found = true; r++; } - if(r != c) - { - if(m_szRecentXbe[r] == 0 || r > m_dwRecentXbe - 1) - { - free(m_szRecentXbe[c]); - m_szRecentXbe[c] = 0; + if(r != c) { + if(g_Settings->m_gui.szRecentXbeFiles[r].c_str() == 0 || r > m_dwRecentXbe - 1) { + g_Settings->m_gui.szRecentXbeFiles[c] = ""; } - else - { - strncpy(m_szRecentXbe[c], m_szRecentXbe[r], MAX_PATH-1); + else { + g_Settings->m_gui.szRecentXbeFiles[c] = g_Settings->m_gui.szRecentXbeFiles[r]; } } } - if(found) + if (found) { m_dwRecentXbe--; + } // move all items down one, removing the last one if necessary - for(int v=RECENT_XBE_SIZE-1;v>0;v--) - { - if(m_szRecentXbe[v-1] == 0) - { - free(m_szRecentXbe[v]); - m_szRecentXbe[v] = 0; + for (int v = RECENT_XBE_LIST_MAX - 1;v > 0; v--) { + + if(g_Settings->m_gui.szRecentXbeFiles[v-1].size() == 0) { + g_Settings->m_gui.szRecentXbeFiles[v] = ""; } - else - { - if(m_szRecentXbe[v] == 0) - m_szRecentXbe[v] = (char*)calloc(1, MAX_PATH); - strncpy(m_szRecentXbe[v], m_szRecentXbe[v-1], MAX_PATH-1); + else { + g_Settings->m_gui.szRecentXbeFiles[v] = g_Settings->m_gui.szRecentXbeFiles[v - 1]; } } // add new item as first index - { - if(m_szRecentXbe[0] == 0) - m_szRecentXbe[0] = (char*)calloc(1, MAX_PATH); + g_Settings->m_gui.szRecentXbeFiles[0] = m_XbeFilename; - strcpy(m_szRecentXbe[0], m_XbeFilename); - } - - if(m_dwRecentXbe < RECENT_XBE_SIZE) + if (m_dwRecentXbe < RECENT_XBE_LIST_MAX) { m_dwRecentXbe++; + } } UpdateRecentFiles(); @@ -2276,7 +2003,7 @@ void WndMain::OpenMRU(int mru) // Open the dashboard xbe if found void WndMain::OpenDashboard() { - std::string DashboardPath = std::string(m_StorageLocation) + std::string("\\EmuDisk\\Partition2\\xboxdash.xbe"); + std::string DashboardPath = g_Settings->GetDataLocation() + std::string("\\EmuDisk\\Partition2\\xboxdash.xbe"); OpenXbe(DashboardPath.c_str()); } @@ -2349,25 +2076,11 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState / return; } - // Reset to default - g_EmuShared->Reset(); + // Reset to default + g_EmuShared->Reset(); - // register xbe path with emulator process - g_EmuShared->SetXbePath(m_Xbe->m_szPath); - - // register LLE flags with emulator process - g_EmuShared->SetFlagsLLE(&m_FlagsLLE); - - // register Hacks with emulator process - g_EmuShared->SetDisablePixelShaders(&m_DisablePixelShaders); - g_EmuShared->SetUncapFramerate(&m_UncapFramerate); - g_EmuShared->SetUseAllCores(&m_UseAllCores); - g_EmuShared->SetSkipRdtscPatching(&m_SkipRdtscPatching); - g_EmuShared->SetScaleViewport(&m_ScaleViewport); - g_EmuShared->SetDirectHostBackBufferAccess(&m_DirectHostBackBufferAccess); - - // register storage location with emulator process - g_EmuShared->SetStorageLocation(m_StorageLocation); + // register all emulator settings to kernel process + g_Settings->SyncToEmulator(); // Preserve previous GUI window location. HWND hOwner = GetParent(m_hwnd); @@ -2379,7 +2092,7 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState / m_prevWindowLoc.x = curWindowPos.left - m_prevWindowLoc.x; m_prevWindowLoc.y = curWindowPos.top - m_prevWindowLoc.y; - if (m_ScaleViewport) { + if (g_Settings->m_hacks.ScaleViewport) { // Set the window size to emulation dimensions // Note : Doing this here assures the emulation process will use // the configured dimensions (because if done inside the emulation @@ -2400,7 +2113,7 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState / g_EmuShared->SetDebuggingFlag(&AttachLocalDebugger); std::string szProcArgsBuffer; - XTL::CxbxConvertArgToString(szProcArgsBuffer, szExeFileName, m_XbeFilename, hwndParent, m_KrnlDebug, m_KrnlDebugFilename); + XTL::CxbxConvertArgToString(szProcArgsBuffer, szExeFileName, m_XbeFilename, hwndParent, g_Settings->m_core.KrnlDebugMode, g_Settings->m_core.szKrnlDebug); if (AttachLocalDebugger) { @@ -2584,7 +2297,7 @@ void WndMain::DrawLedBitmap(HWND hwnd, bool bdefault) else { // draw colored bitmap int LedSequence[4] = { XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF }; static int LedSequenceOffset = 0; - int FlagsLLE = 0; + uint FlagsLLE = 0; g_EmuShared->GetLedSequence(LedSequence); @@ -2592,7 +2305,7 @@ void WndMain::DrawLedBitmap(HWND hwnd, bool bdefault) ActiveLEDColor = LedSequence[LedSequenceOffset & 3]; ++LedSequenceOffset; - g_EmuShared->GetFlagsLLE(&FlagsLLE); + g_EmuShared->GetFlagsLLEStatus(&FlagsLLE); // Set LLE flags string based on selected LLE flags if (FlagsLLE & LLE_APU) { strcat(flagString, "A"); diff --git a/src/Cxbx/WndMain.h b/src/Cxbx/WndMain.h index 2b3522d6e..52ef6dc3e 100644 --- a/src/Cxbx/WndMain.h +++ b/src/Cxbx/WndMain.h @@ -42,14 +42,7 @@ // ****************************************************************** // * constants // ****************************************************************** -#define RECENT_XBE_SIZE 10 - -// Cxbx-Reloaded's data storage location. -typedef enum _CXBX_DATA { - CXBX_DATA_APPDATA = 0, - CXBX_DATA_CURDIR = 1, - CXBX_DATA_CUSTOM = 2, -} CXBX_DATA; +#define RECENT_XBE_LIST_MAX 10 typedef struct _Crash_Manager_Data { LPVOID pWndMain; @@ -205,7 +198,7 @@ class WndMain : public Wnd // ****************************************************************** // * cached filenames // ****************************************************************** - char *m_XbeFilename; + char m_XbeFilename[MAX_PATH]; // ****************************************************************** // * cached window, process, and thread handle @@ -218,50 +211,11 @@ class WndMain : public Wnd // * Recent Xbe files // ****************************************************************** int m_dwRecentXbe; - char *m_szRecentXbe[RECENT_XBE_SIZE]; // ****************************************************************** // * is this window fully initialized? // ****************************************************************** - bool m_bCreated; - - // ****************************************************************** - // * current debug mode type - // ****************************************************************** - DebugMode m_CxbxDebug; - DebugMode m_KrnlDebug; - - // ****************************************************************** - // * LLE flags - // ****************************************************************** - int m_FlagsLLE; - - // ****************************************************************** - // * XInput Enabled Flag - // ****************************************************************** - int m_XInputEnabled; - - // ****************************************************************** - // * Hack Flags - // ****************************************************************** - int m_DisablePixelShaders; - int m_UncapFramerate; - int m_UseAllCores; - int m_SkipRdtscPatching; - int m_ScaleViewport; - int m_DirectHostBackBufferAccess; - - // ****************************************************************** - // * debug output filenames - // ****************************************************************** - char *m_CxbxDebugFilename; - char *m_KrnlDebugFilename; - - // ****************************************************************** - // * Storage location - // ****************************************************************** - CXBX_DATA m_StorageToggle; - char m_StorageLocation[MAX_PATH]; + bool m_bCreated; // ****************************************************************** // * Previous GUI window location (before start emulation) diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index 9b14e696c..3d2ea6067 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -53,16 +53,15 @@ namespace xboxkrnl #include "EmuEEPROM.h" // For CxbxRestoreEEPROM, EEPROM, XboxFactoryGameRegion #include "EmuKrnl.h" #include "EmuShared.h" +#include "EmuXTL.h" #include "HLEIntercept.h" #include "ReservedMemory.h" // For virtual_memory_placeholder #include "VMManager.h" #include "CxbxDebugger.h" #include "EmuX86.h" -#include #include #include -#include #include // For time() #include // For std::ostringstream @@ -97,6 +96,7 @@ char szFolder_CxbxReloadedData[MAX_PATH] = { 0 }; char szFilePath_EEPROM_bin[MAX_PATH] = { 0 }; char szFilePath_memory_bin[MAX_PATH] = { 0 }; char szFilePath_page_tables[MAX_PATH] = { 0 }; +char szFilePath_Xbe[MAX_PATH] = { 0 }; std::string CxbxBasePath; HANDLE CxbxBasePathHandle; @@ -577,27 +577,27 @@ void PrintCurrentConfigurationLog() // Print current video configuration (DirectX/HLE) if (!bLLE_GPU) { - XBVideo XBVideoConf; - g_EmuShared->GetXBVideo(&XBVideoConf); + Settings::s_video XBVideoConf; + g_EmuShared->GetVideoSettings(&XBVideoConf); printf("--------------------------- VIDEO CONFIG ---------------------------\n"); - printf("Direct3D Device: %s\n", XBVideoConf.GetDirect3DDevice() == 0 ? "Direct3D HAL (Hardware Accelerated)" : "Direct3D REF (Software)"); - printf("Video Resolution: %s\n", XBVideoConf.GetVideoResolution()); - printf("Force VSync is %s\n", XBVideoConf.GetVSync() ? "enabled" : "disabled"); - printf("Fullscreen is %s\n", XBVideoConf.GetFullscreen() ? "enabled" : "disabled"); - printf("Hardware YUV is %s\n", XBVideoConf.GetHardwareYUV() ? "enabled" : "disabled"); + printf("Direct3D Device: %s\n", XBVideoConf.direct3DDevice == 0 ? "Direct3D HAL (Hardware Accelerated)" : "Direct3D REF (Software)"); + printf("Video Resolution: %s\n", XBVideoConf.szVideoResolution); + printf("Force VSync is %s\n", XBVideoConf.bVSync ? "enabled" : "disabled"); + printf("Fullscreen is %s\n", XBVideoConf.bFullScreen ? "enabled" : "disabled"); + printf("Hardware YUV is %s\n", XBVideoConf.bHardwareYUV ? "enabled" : "disabled"); } // Print current audio configuration { - XBAudio XBAudioConf; - g_EmuShared->GetXBAudio(&XBAudioConf); + Settings::s_audio XBAudioConf; + g_EmuShared->GetAudioSettings(&XBAudioConf); printf("--------------------------- AUDIO CONFIG ---------------------------\n"); - printf("Audio Adapter: %s\n", XBAudioConf.GetAudioAdapter().Data1 == 0 ? "Primary Audio Device" : "Secondary Audio Device"); - printf("PCM is %s\n", XBAudioConf.GetPCM() ? "enabled" : "disabled"); - printf("XADPCM is %s\n", XBAudioConf.GetXADPCM() ? "enabled" : "disabled"); - printf("Unknown Codec is %s\n", XBAudioConf.GetUnknownCodec() ? "enabled" : "disabled"); + printf("Audio Adapter: %s\n", XBAudioConf.adapterGUID.Data1 == 0 ? "Primary Audio Device" : "Secondary Audio Device"); + printf("PCM is %s\n", XBAudioConf.codec_pcm ? "enabled" : "disabled"); + printf("XADPCM is %s\n", XBAudioConf.codec_xadpcm ? "enabled" : "disabled"); + printf("Unknown Codec is %s\n", XBAudioConf.codec_unknown ? "enabled" : "disabled"); } // Print Enabled Hacks @@ -868,13 +868,13 @@ void CxbxKrnlMain(int argc, char* argv[]) // Get DCHandle : HWND hWnd = 0; if (argc > 2) { - hWnd = (HWND)StrToInt(argv[3]); + hWnd = (HWND)std::atoi(argv[3]); } // Get KernelDebugMode : DebugMode DbgMode = DebugMode::DM_NONE; if (argc > 3) { - DbgMode = (DebugMode)StrToInt(argv[4]); + DbgMode = (DebugMode)std::atoi(argv[4]); } // Get KernelDebugFileName : @@ -1077,9 +1077,9 @@ void CxbxKrnlMain(int argc, char* argv[]) // Now we can load and run the XBE : // MapAndRunXBE(XbePath, DCHandle); { - // Load Xbe (this one will reside above WinMain's virtual_memory_placeholder) - g_EmuShared->SetXbePath(xbePath.c_str()); - CxbxKrnl_Xbe = new Xbe(xbePath.c_str(), false); // TODO : Instead of using the Xbe class, port Dxbx _ReadXbeBlock() + strncpy(szFilePath_Xbe, xbePath.c_str(), MAX_PATH - 1); + // Load Xbe (this one will reside above WinMain's virtual_memory_placeholder) + CxbxKrnl_Xbe = new Xbe(szFilePath_Xbe, false); // TODO : Instead of using the Xbe class, port Dxbx _ReadXbeBlock() if (CxbxKrnl_Xbe->HasFatalError()) { CxbxKrnlCleanup(CxbxKrnl_Xbe->GetError().c_str()); @@ -1303,8 +1303,8 @@ __declspec(noreturn) void CxbxKrnlInit // Read which components need to be LLE'ed : { - int CxbxLLE_Flags; - g_EmuShared->GetFlagsLLE(&CxbxLLE_Flags); + uint CxbxLLE_Flags; + g_EmuShared->GetFlagsLLEStatus(&CxbxLLE_Flags); bLLE_APU = (CxbxLLE_Flags & LLE_APU) > 0; bLLE_GPU = (CxbxLLE_Flags & LLE_GPU) > 0; //bLLE_USB = (CxbxLLE_Flags & LLE_USB) > 0; // Reenable this when LLE USB actually works @@ -1340,10 +1340,10 @@ __declspec(noreturn) void CxbxKrnlInit // Determine XBE Path memset(szBuffer, 0, MAX_PATH); - g_EmuShared->GetXbePath(szBuffer); + strncpy(szBuffer, szFilePath_Xbe, MAX_PATH); std::string xbePath(szBuffer); - PathRemoveFileSpec(szBuffer); std::string xbeDirectory(szBuffer); + xbeDirectory = xbeDirectory.substr(0, xbeDirectory.find_last_of("\\/")); CxbxBasePathHandle = CreateFile(CxbxBasePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); memset(szBuffer, 0, MAX_PATH); // Games may assume they are running from CdRom : @@ -1538,15 +1538,15 @@ void CxbxInitFilePaths() g_EmuShared->GetStorageLocation(szFolder_CxbxReloadedData); // Make sure our data folder exists : - int result = SHCreateDirectoryEx(nullptr, szFolder_CxbxReloadedData, nullptr); - if ((result != ERROR_SUCCESS) && (result != ERROR_ALREADY_EXISTS)) { - CxbxKrnlCleanup("CxbxInitFilePaths : Couldn't create Cxbx-Reloaded AppData folder!"); + bool result = std::filesystem::exists(szFolder_CxbxReloadedData); + if (!result && !std::filesystem::create_directory(szFolder_CxbxReloadedData)) { + CxbxKrnlCleanup("CxbxInitFilePaths : Couldn't create Cxbx-Reloaded's data folder!"); } // Make sure the EmuDisk folder exists std::string emuDisk = std::string(szFolder_CxbxReloadedData) + std::string("\\EmuDisk"); - result = SHCreateDirectoryEx(nullptr, emuDisk.c_str(), nullptr); - if ((result != ERROR_SUCCESS) && (result != ERROR_ALREADY_EXISTS)) { + result = std::filesystem::exists(emuDisk); + if (!result && !std::filesystem::create_directory(emuDisk)) { CxbxKrnlCleanup("CxbxInitFilePaths : Couldn't create Cxbx-Reloaded EmuDisk folder!"); } diff --git a/src/CxbxKrnl/CxbxKrnl.h b/src/CxbxKrnl/CxbxKrnl.h index 9bf123098..0fd6810a8 100644 --- a/src/CxbxKrnl/CxbxKrnl.h +++ b/src/CxbxKrnl/CxbxKrnl.h @@ -308,6 +308,7 @@ extern std::string CxbxKrnl_DebugFileName; extern char szFilePath_CxbxReloaded_Exe[MAX_PATH]; extern char szFolder_CxbxReloadedData[MAX_PATH]; extern char szFilePath_EEPROM_bin[MAX_PATH]; +extern char szFilePath_Xbe[MAX_PATH]; #ifdef __cplusplus } diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index 1ea04cd95..23e323ab3 100644 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -58,7 +58,7 @@ namespace xboxkrnl #include "Logging.h" #include "EmuD3D8Logging.h" #include "HLEIntercept.h" // for bLLE_GPU -#include "Cxbx\\ResCxbx.h" +#include "Cxbx/ResCxbx.h" #include #include @@ -102,7 +102,7 @@ static XTL::LPDIRECTDRAW7 g_pDD7 = NULL; // DirectDraw7 static XTL::DDCAPS g_DriverCaps = { 0 }; static HBRUSH g_hBgBrush = NULL; // Background Brush static volatile bool g_bRenderWindowActive = false; -static XBVideo g_XBVideo; +static Settings::s_video g_XBVideo; static XTL::D3DVBLANKCALLBACK g_pVBCallback = NULL; // Vertical-Blank callback routine static std::condition_variable g_VBConditionVariable; // Used in BlockUntilVerticalBlank static std::mutex g_VBConditionMutex; // Used in BlockUntilVerticalBlank @@ -485,9 +485,9 @@ const char *D3DErrorString(HRESULT hResult) VOID XTL::CxbxInitWindow(bool bFullInit) { - g_EmuShared->GetXBVideo(&g_XBVideo); + g_EmuShared->GetVideoSettings(&g_XBVideo); - if(g_XBVideo.GetFullscreen()) + if(g_XBVideo.bFullScreen) CxbxKrnl_hEmuParent = NULL; // create timing thread @@ -1342,8 +1342,8 @@ VOID XTL::EmuD3DInit() // Initialise CreateDevice Proxy Data struct { g_EmuCDPD = {0}; - g_EmuCDPD.Adapter = g_XBVideo.GetDisplayAdapter(); - g_EmuCDPD.DeviceType = (g_XBVideo.GetDirect3DDevice() == 0) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + g_EmuCDPD.Adapter = g_XBVideo.adapter; + g_EmuCDPD.DeviceType = (g_XBVideo.direct3DDevice == 0) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; g_EmuCDPD.hFocusWindow = g_hEmuWindow; } @@ -1422,15 +1422,31 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid) // create the window { - HWND hwndParent = GetDesktopWindow(); - DWORD dwStyle = WS_POPUP; + // Peform selection if running in GUI or kernel mode first. + HWND hwndParent = (!CxbxKrnl_hEmuParent ? GetDesktopWindow() : CxbxKrnl_hEmuParent); + DWORD dwStyle = WS_POPUP; RECT windowRect = { 0 }; - if (!g_XBVideo.GetFullscreen()) { - hwndParent = CxbxKrnl_hEmuParent; - GetWindowRect(hwndParent, &windowRect); - dwStyle = (CxbxKrnl_hEmuParent == 0) ? WS_OVERLAPPEDWINDOW : WS_CHILD; - } + // Obtain the selected resolution from GUI or full desktop screen in kernel mode. + if (!GetWindowRect(hwndParent, &windowRect)) { + // Fall back resolution if failed + windowRect = { 0, 0, 640, 480 }; + } + + // Then perform additional checks if not running in full screen. + if (!g_XBVideo.bFullScreen) { + + // If running as kernel mode, force use the xbox's default resolution. + if (!CxbxKrnl_hEmuParent) { + // Xbox default resolution (standalone window is resizable by the way) + windowRect.right = 640; + windowRect.bottom = 480; + dwStyle = WS_OVERLAPPEDWINDOW; + } + else { + dwStyle = WS_CHILD; + } + } g_hEmuWindow = CreateWindow ( @@ -1444,10 +1460,10 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid) ); } - ShowWindow(g_hEmuWindow, ((CxbxKrnl_hEmuParent == 0) || g_XBVideo.GetFullscreen()) ? SW_SHOWDEFAULT : SW_SHOWMAXIMIZED); + ShowWindow(g_hEmuWindow, ((CxbxKrnl_hEmuParent == 0) || g_XBVideo.bFullScreen) ? SW_SHOWDEFAULT : SW_SHOWMAXIMIZED); UpdateWindow(g_hEmuWindow); - if(!g_XBVideo.GetFullscreen() && (CxbxKrnl_hEmuParent != NULL)) + if(!g_XBVideo.bFullScreen && (CxbxKrnl_hEmuParent != NULL)) { SetFocus(CxbxKrnl_hEmuParent); } @@ -1511,7 +1527,7 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid) // simple helper function void ToggleFauxFullscreen(HWND hWnd) { - if(g_XBVideo.GetFullscreen()) + if(g_XBVideo.bFullScreen) return; static LONG lRestore = 0, lRestoreEx = 0; @@ -1599,7 +1615,7 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar /*! disable fullscreen if we are set to faux mode, and faux fullscreen is active */ if(wParam == VK_ESCAPE) { - if(g_XBVideo.GetFullscreen()) + if(g_XBVideo.bFullScreen) { SendMessage(hWnd, WM_CLOSE, 0, 0); } @@ -1647,7 +1663,7 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar case SIZE_MINIMIZED: { - if(g_XBVideo.GetFullscreen()) + if(g_XBVideo.bFullScreen) CxbxKrnlCleanup(NULL); if(!g_bEmuSuspended) @@ -1676,7 +1692,7 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar case WM_SETCURSOR: { - if(g_XBVideo.GetFullscreen() || g_bIsFauxFullscreen) + if(g_XBVideo.bFullScreen || g_bIsFauxFullscreen) { SetCursor(NULL); return D3D_OK; // = 0 @@ -1939,9 +1955,9 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // make adjustments to parameters to make sense with windows Direct3D { - g_EmuCDPD.HostPresentationParameters.Windowed = !g_XBVideo.GetFullscreen(); + g_EmuCDPD.HostPresentationParameters.Windowed = !g_XBVideo.bFullScreen; - if(g_XBVideo.GetVSync()) + if(g_XBVideo.bVSync) #ifdef CXBX_USE_D3D9 g_EmuCDPD.HostPresentationParameters.SwapEffect = XTL::D3DSWAPEFFECT_COPY; #else @@ -1951,11 +1967,11 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) g_EmuCDPD.HostPresentationParameters.BackBufferFormat = XTL::EmuXB2PC_D3DFormat(g_EmuCDPD.XboxPresentationParameters.BackBufferFormat); g_EmuCDPD.HostPresentationParameters.AutoDepthStencilFormat = XTL::EmuXB2PC_D3DFormat(g_EmuCDPD.XboxPresentationParameters.AutoDepthStencilFormat); - if(!g_XBVideo.GetVSync() && (g_D3DCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) && g_XBVideo.GetFullscreen()) + if(!g_XBVideo.bVSync && (g_D3DCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) && g_XBVideo.bFullScreen) g_EmuCDPD.HostPresentationParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; else { - if(g_D3DCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE && g_XBVideo.GetFullscreen()) + if(g_D3DCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE && g_XBVideo.bFullScreen) g_EmuCDPD.HostPresentationParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; else g_EmuCDPD.HostPresentationParameters.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; @@ -1996,7 +2012,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // retrieve resolution from configuration if(g_EmuCDPD.HostPresentationParameters.Windowed) { - const char* resolution = g_XBVideo.GetVideoResolution(); + const char* resolution = g_XBVideo.szVideoResolution; if (2 != sscanf(resolution, "%u x %u", &g_EmuCDPD.HostPresentationParameters.BackBufferWidth, &g_EmuCDPD.HostPresentationParameters.BackBufferHeight)) { DbgPrintf("EmuCreateDeviceProxy: Couldn't parse resolution : %s.\n", resolution); } @@ -2018,7 +2034,7 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) { char szBackBufferFormat[16] = {}; - const char* resolution = g_XBVideo.GetVideoResolution(); + const char* resolution = g_XBVideo.szVideoResolution; if (4 != sscanf(resolution, "%u x %u %*dbit %s (%u hz)", &g_EmuCDPD.HostPresentationParameters.BackBufferWidth, &g_EmuCDPD.HostPresentationParameters.BackBufferHeight, diff --git a/src/CxbxKrnl/EmuDInput.cpp b/src/CxbxKrnl/EmuDInput.cpp index c470ef56f..7edb39053 100644 --- a/src/CxbxKrnl/EmuDInput.cpp +++ b/src/CxbxKrnl/EmuDInput.cpp @@ -40,22 +40,23 @@ #include "Emu.h" #include "EmuXTL.h" #include "EmuShared.h" +#include "Common/Win32/DInputController.h" // ****************************************************************** // * Static Variable(s) // ****************************************************************** -static XBController g_XBController; +static DInputController g_DInputController; // ****************************************************************** // * XTL::EmuDInputInit // ****************************************************************** bool XTL::EmuDInputInit() { - g_EmuShared->GetXBController(&g_XBController); + g_EmuShared->GetControllerDInputSettings(&g_DInputController.m_settings); - g_XBController.ListenBegin(g_hEmuWindow); + g_DInputController.ListenBegin(g_hEmuWindow); - if(g_XBController.HasError()) + if(g_DInputController.HasError()) return false; return true; @@ -66,7 +67,7 @@ bool XTL::EmuDInputInit() // ****************************************************************** void XTL::EmuDInputCleanup() { - g_XBController.ListenEnd(); + g_DInputController.ListenEnd(); } //emulated dwPacketNumber for DirectInput controller @@ -77,13 +78,13 @@ DWORD dwPacketNumber_DirectInput = 0; // ****************************************************************** void XTL::EmuDInputPoll(XTL::PX_XINPUT_STATE pXboxController) { - g_XBController.ListenPoll(pXboxController); + g_DInputController.ListenPoll(pXboxController); //increment of emulated PacketNumber and report back to Controller. dwPacketNumber_DirectInput++; pXboxController->dwPacketNumber = dwPacketNumber_DirectInput; - if(g_XBController.HasError()) - MessageBox(NULL, g_XBController.GetError().c_str(), "Cxbx-Reloaded [*UNHANDLED!*]", MB_OK); // TODO: Handle this! + if(g_DInputController.HasError()) + MessageBox(NULL, g_DInputController.GetError().c_str(), "Cxbx-Reloaded [*UNHANDLED!*]", MB_OK); // TODO: Handle this! return; } diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 1837ad5c0..40f2d5167 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -51,6 +51,7 @@ namespace xboxkrnl { #include "EmuFS.h" #include "EmuShared.h" #include "EmuXTL.h" +#include "Common/Settings.hpp" #ifndef _DEBUG_TRACE @@ -194,7 +195,7 @@ XTL::X_XFileMediaObject::_vtbl XTL::X_XFileMediaObject::vtbl = #define vector_ds_stream std::vector // Static Variable(s) -XBAudio g_XBAudio = XBAudio(); +static Settings::s_audio g_XBAudio = { 0 }; extern LPDIRECTSOUND8 g_pDSound8 = nullptr; //This is necessary in order to allow share with EmuDSoundInline.hpp static LPDIRECTSOUNDBUFFER g_pDSoundPrimaryBuffer = nullptr; //TODO: RadWolfie - How to implement support if primary does not permit it for DSP usage? @@ -228,7 +229,7 @@ extern "C" { void CxbxInitAudio() { - g_EmuShared->GetXBAudio(&g_XBAudio); + g_EmuShared->GetAudioSettings(&g_XBAudio); } #ifdef __cplusplus @@ -269,7 +270,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) g_bDSoundCreateCalled = TRUE; if (!initialized || g_pDSound8 == nullptr) { - hRet = DirectSoundCreate8(&g_XBAudio.GetAudioAdapter(), &g_pDSound8, NULL); + hRet = DirectSoundCreate8(&g_XBAudio.adapterGUID, &g_pDSound8, NULL); LPCSTR dsErrorMsg = nullptr; diff --git a/src/CxbxKrnl/EmuDSoundInline.hpp b/src/CxbxKrnl/EmuDSoundInline.hpp index 7bcb9c4b5..b680091bb 100644 --- a/src/CxbxKrnl/EmuDSoundInline.hpp +++ b/src/CxbxKrnl/EmuDSoundInline.hpp @@ -1714,15 +1714,15 @@ inline HRESULT HybridDirectSoundBuffer_SetVolume( lVolume += Xb_volumeMixbin - Xb_dwHeadroom; if ((dwEmuFlags & DSE_FLAG_PCM) > 0) { - if (!g_XBAudio.GetPCM()) { + if (!g_XBAudio.codec_pcm) { lVolume = DSBVOLUME_MIN; } } else if ((dwEmuFlags & DSE_FLAG_XADPCM) > 0) { - if (!g_XBAudio.GetXADPCM()) { + if (!g_XBAudio.codec_xadpcm) { lVolume = DSBVOLUME_MIN; } } else if ((dwEmuFlags & DSE_FLAG_PCM_UNKNOWN) > 0) { - if (!g_XBAudio.GetUnknownCodec()) { + if (!g_XBAudio.codec_unknown) { lVolume = DSBVOLUME_MIN; } } diff --git a/src/CxbxKrnl/EmuKrnlHal.cpp b/src/CxbxKrnl/EmuKrnlHal.cpp index e4d5628ed..e76625b43 100644 --- a/src/CxbxKrnl/EmuKrnlHal.cpp +++ b/src/CxbxKrnl/EmuKrnlHal.cpp @@ -601,14 +601,11 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur xboxkrnl::HalWriteSMBusValue(SMBUS_ADDRESS_SYSTEM_MICRO_CONTROLLER, SMC_COMMAND_SCRATCH, 0, SMC_SCRATCH_DISPLAY_FATAL_ERROR); - char szWorkingDirectoy[MAX_PATH]; - g_EmuShared->GetXbePath(szWorkingDirectoy); - std::string szProcArgsBuffer; - CxbxConvertArgToString(szProcArgsBuffer, szFilePath_CxbxReloaded_Exe, szWorkingDirectoy, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName.c_str()); + CxbxConvertArgToString(szProcArgsBuffer, szFilePath_CxbxReloaded_Exe, szFilePath_Xbe, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName.c_str()); if (!CxbxExec(szProcArgsBuffer, nullptr, false)) { - CxbxKrnlCleanup("Could not launch %s", szWorkingDirectoy); + CxbxKrnlCleanup("Could not launch %s", szFilePath_Xbe); } break; } diff --git a/src/CxbxKrnl/EmuShared.h b/src/CxbxKrnl/EmuShared.h index 3c78f8b40..e4a035af5 100644 --- a/src/CxbxKrnl/EmuShared.h +++ b/src/CxbxKrnl/EmuShared.h @@ -34,10 +34,9 @@ #ifndef EMUSHARED_H #define EMUSHARED_H -#include "Cxbx.h" -#include "Common/Win32/XBController.h" -#include "Common/Win32/XBVideo.h" -#include "Common/Win32/XBAudio.h" +#include "Cxbx.h" +#include "Common/Settings.hpp" +#include "Mutex.h" #include @@ -46,13 +45,6 @@ enum { XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_RED, XBOX_LED_COLOUR_ORANGE, -}; - -enum { - LLE_APU = 1 << 0, - LLE_GPU = 1 << 1, - LLE_JIT = 1 << 2, - LLE_USB = 1 << 3, }; // Kernel boot flags @@ -76,10 +68,7 @@ class EmuShared : public Mutex // ****************************************************************** // * Each process needs to call this to initialize shared memory // ****************************************************************** - static void Init(); - - void Load(); - void Save(); + static void Init(DWORD guiProcessID); // ****************************************************************** // * Each process needs to call this to cleanup shared memory @@ -90,95 +79,102 @@ class EmuShared : public Mutex // * Check if shared memory is used on launch // ****************************************************************** void GetIsFirstLaunch(bool *isFirstLaunch) { Lock(); *isFirstLaunch = m_bFirstLaunch; Unlock(); } - void SetIsFirstLaunch(bool isFirstLaunch) { Lock(); m_bFirstLaunch = isFirstLaunch; Unlock(); } + void SetIsFirstLaunch(const bool isFirstLaunch) { Lock(); m_bFirstLaunch = isFirstLaunch; Unlock(); } // ****************************************************************** // * Check if parent process is emulating title // ****************************************************************** - void GetIsEmulating(bool *isEmulating) { Lock(); *isEmulating = m_bEmulating; Unlock(); } - void SetIsEmulating(bool isEmulating) { Lock(); m_bEmulating = isEmulating; Unlock(); } + void GetIsEmulating(bool *isEmulating) { Lock(); *isEmulating = m_bEmulating_status; Unlock(); } + void SetIsEmulating(const bool isEmulating) { Lock(); m_bEmulating_status = isEmulating; Unlock(); } // ****************************************************************** // * Each child process need to wait until parent process is ready // ****************************************************************** - void GetIsReady(bool *isReady) { Lock(); *isReady = m_bReady; Unlock(); } - void SetIsReady(bool isReady) { Lock(); m_bReady = isReady; Unlock(); } + void GetIsReady(bool *isReady) { Lock(); *isReady = m_bReady_status; Unlock(); } + void SetIsReady(const bool isReady) { Lock(); m_bReady_status = isReady; Unlock(); } // ****************************************************************** // * Check if previous kernel mode process is running. // ****************************************************************** void GetKrnlProcID(unsigned int *krnlProcID) { Lock(); *krnlProcID = m_dwKrnlProcID; Unlock(); } - void SetKrnlProcID(unsigned int krnlProcID) { Lock(); m_dwKrnlProcID = krnlProcID; Unlock(); } + void SetKrnlProcID(const unsigned int krnlProcID) { Lock(); m_dwKrnlProcID = krnlProcID; Unlock(); } + + // ****************************************************************** + // * Xbox Core Accessors + // ****************************************************************** + void GetCoreSettings( Settings::s_core *emulate) { Lock(); *emulate = m_core; Unlock(); } + void SetCoreSettings(const Settings::s_core *emulate) { Lock(); m_core = *emulate; Unlock(); } // ****************************************************************** // * Xbox Video Accessors // ****************************************************************** - void GetXBVideo( XBVideo *video) { Lock(); *video = XBVideo(m_XBVideo); Unlock(); } - void SetXBVideo(const XBVideo *video) { Lock(); m_XBVideo = XBVideo(*video); Unlock(); } + void GetVideoSettings( Settings::s_video *video) { Lock(); *video = m_video; Unlock(); } + void SetVideoSettings(const Settings::s_video *video) { Lock(); m_video = *video; Unlock(); } // ****************************************************************** // * Xbox Audio Accessors // ****************************************************************** - void GetXBAudio( XBAudio *audio) { Lock(); *audio = XBAudio(m_XBAudio); Unlock(); } - void SetXBAudio(const XBAudio *audio) { Lock(); m_XBAudio = XBAudio(*audio); Unlock(); } + void GetAudioSettings( Settings::s_audio *audio) { Lock(); *audio = m_audio; Unlock(); } + void SetAudioSettings(const Settings::s_audio *audio) { Lock(); m_audio = *audio; Unlock(); } // ****************************************************************** // * Xbox Controller Accessors // ****************************************************************** - void GetXBController( XBController *ctrl) { Lock(); *ctrl = XBController(m_XBController); Unlock(); } - void SetXBController(const XBController *ctrl) { Lock(); m_XBController = XBController(*ctrl); Unlock(); } - - // ****************************************************************** - // * Xbe Path Accessors - // ****************************************************************** - void GetXbePath( char *path) { Lock(); strcpy(path, m_XbePath); Unlock(); } - void SetXbePath(const char *path) { Lock(); strcpy(m_XbePath, path); Unlock(); } + void GetControllerDInputSettings( Settings::s_controller_dinput *ctrl) { Lock(); *ctrl = m_controller_dinput; Unlock(); } + void SetControllerDInputSettings(const Settings::s_controller_dinput *ctrl) { Lock(); m_controller_dinput = *ctrl; Unlock(); } + void GetControllerPortSettings( Settings::s_controller_port *ctrl) { Lock(); *ctrl = m_controller_port; Unlock(); } + void SetControllerPortSettings(const Settings::s_controller_port *ctrl) { Lock(); m_controller_port = *ctrl; Unlock(); } // ****************************************************************** // * LLE Flags Accessors // ****************************************************************** - void GetFlagsLLE( int *flags) { Lock(); *flags = m_FlagsLLE; Unlock(); } - void SetFlagsLLE(const int *flags) { Lock(); m_FlagsLLE = *flags; Unlock(); } + void GetFlagsLLE( uint *flags) { Lock(); *flags = m_core.FlagsLLE; Unlock(); } + void SetFlagsLLE(const uint *flags) { Lock(); m_core.FlagsLLE = *flags; Unlock(); } + void GetFlagsLLEStatus( uint *flags) { Lock(); *flags = m_FlagsLLE_status; Unlock(); } + void SetFlagsLLEStatus(const uint flags) { Lock(); m_FlagsLLE_status = flags; Unlock(); } // ****************************************************************** // * Boot flag Accessors // ****************************************************************** - void GetBootFlags(int *value) { Lock(); *value = m_BootFlags; Unlock(); } - void SetBootFlags(int *value) { Lock(); m_BootFlags = *value; Unlock(); } + void GetBootFlags(int *value) { Lock(); *value = m_BootFlags_status; Unlock(); } + void SetBootFlags(const int *value) { Lock(); m_BootFlags_status = *value; Unlock(); } // ****************************************************************** // * Hack Flag Accessors - // ****************************************************************** - void GetDisablePixelShaders(int* value) { Lock(); *value = m_DisablePixelShaders; Unlock(); } - void SetDisablePixelShaders(int* value) { Lock(); m_DisablePixelShaders = *value; Unlock(); } - void GetUncapFramerate(int* value) { Lock(); *value = m_UncapFramerate; Unlock(); } - void SetUncapFramerate(int* value) { Lock(); m_UncapFramerate = *value; Unlock(); } - void GetUseAllCores(int* value) { Lock(); *value = m_UseAllCores; Unlock(); } - void SetUseAllCores(int* value) { Lock(); m_UseAllCores = *value; Unlock(); } - void GetSkipRdtscPatching(int* value) { Lock(); *value = m_SkipRdtscPatching; Unlock(); } - void SetSkipRdtscPatching(int* value) { Lock(); m_SkipRdtscPatching = *value; Unlock(); } - void GetScaleViewport(int* value) { Lock(); *value = m_ScaleViewport; Unlock(); } - void SetScaleViewport(int* value) { Lock(); m_ScaleViewport = *value; Unlock(); } - void GetDirectHostBackBufferAccess(int* value) { Lock(); *value = m_DirectHostBackBufferAccess; Unlock(); } - void SetDirectHostBackBufferAccess(int* value) { Lock(); m_DirectHostBackBufferAccess = *value; Unlock(); } + // ****************************************************************** + void GetHackSettings(Settings::s_hack *hacks) { Lock(); *hacks = m_hacks; Unlock(); } + void SetHackSettings(Settings::s_hack *hacks) { Lock(); m_hacks = *hacks; Unlock(); } + + void GetDisablePixelShaders(int* value) { Lock(); *value = m_hacks.DisablePixelShaders; Unlock(); } + void SetDisablePixelShaders(const int* value) { Lock(); m_hacks.DisablePixelShaders = *value; Unlock(); } + void GetUncapFramerate(int* value) { Lock(); *value = m_hacks.UncapFramerate; Unlock(); } + void SetUncapFramerate(const int* value) { Lock(); m_hacks.UncapFramerate = *value; Unlock(); } + void GetUseAllCores(int* value) { Lock(); *value = m_hacks.UseAllCores; Unlock(); } + void SetUseAllCores(const int* value) { Lock(); m_hacks.UseAllCores = *value; Unlock(); } + void GetSkipRdtscPatching(int* value) { Lock(); *value = m_hacks.SkipRdtscPatching; Unlock(); } + void SetSkipRdtscPatching(const int* value) { Lock(); m_hacks.SkipRdtscPatching = *value; Unlock(); } + void GetScaleViewport(int* value) { Lock(); *value = m_hacks.ScaleViewport; Unlock(); } + void SetScaleViewport(const int* value) { Lock(); m_hacks.ScaleViewport = *value; Unlock(); } + void GetDirectHostBackBufferAccess(int* value) { Lock(); *value = m_hacks.DirectHostBackBufferAccess; Unlock(); } + void SetDirectHostBackBufferAccess(const int* value) { Lock(); m_hacks.DirectHostBackBufferAccess = *value; Unlock(); } // ****************************************************************** // * MSpF/Benchmark values Accessors // ****************************************************************** - void GetCurrentMSpF(float *value) { Lock(); *value = m_MSpF; Unlock(); } - void SetCurrentMSpF(float *value) { Lock(); m_MSpF = *value; Unlock(); } + void GetCurrentMSpF(float *value) { Lock(); *value = m_MSpF_status; Unlock(); } + void SetCurrentMSpF(const float *value) { Lock(); m_MSpF_status = *value; Unlock(); } // ****************************************************************** // * FPS/Benchmark values Accessors // ****************************************************************** - void GetCurrentFPS(float *value) { Lock(); *value = m_FPS; Unlock(); } - void SetCurrentFPS(float *value) { Lock(); m_FPS = *value; Unlock(); } + void GetCurrentFPS(float *value) { Lock(); *value = m_FPS_status; Unlock(); } + void SetCurrentFPS(const float *value) { Lock(); m_FPS_status = *value; Unlock(); } // ****************************************************************** // * Debugging flag Accessors // ****************************************************************** void GetDebuggingFlag(bool *value) { Lock(); *value = m_bDebugging; Unlock(); } - void SetDebuggingFlag(bool *value) { Lock(); m_bDebugging = *value; Unlock(); } + void SetDebuggingFlag(const bool *value) { Lock(); m_bDebugging = *value; Unlock(); } // ****************************************************************** // * Xbox LED values Accessors @@ -188,7 +184,7 @@ class EmuShared : public Mutex Lock(); for (int i = 0; i < 4; ++i) { - value[i] = m_LedSequence[i]; + value[i] = m_LedSequence_status[i]; } Unlock(); } @@ -197,7 +193,7 @@ class EmuShared : public Mutex Lock(); for (int i = 0; i < 4; ++i) { - m_LedSequence[i] = value[i]; + m_LedSequence_status[i] = value[i]; } Unlock(); } @@ -205,8 +201,8 @@ class EmuShared : public Mutex // ****************************************************************** // * File storage location // ****************************************************************** - void GetStorageLocation(char *path) { Lock(); strcpy(path, m_StorageLocation); Unlock(); } - void SetStorageLocation(char *path) { Lock(); strcpy(m_StorageLocation, path); Unlock(); } + void GetStorageLocation(char *path) { Lock(); strncpy(path, m_core.szStorageLocation, MAX_PATH); Unlock(); } + void SetStorageLocation(const char *path) { Lock(); strncpy(m_core.szStorageLocation, path, MAX_PATH); Unlock(); } // ****************************************************************** // * Reset specific variables to default for kernel mode. @@ -214,9 +210,10 @@ class EmuShared : public Mutex void ResetKrnl() { Lock(); - m_BootFlags = 0; - m_MSpF = 0.0f; - m_FPS = 0.0f; + m_BootFlags_status = 0; + m_MSpF_status = 0.0f; + m_FPS_status = 0.0f; + m_FlagsLLE_status = m_core.FlagsLLE; Unlock(); } @@ -227,6 +224,7 @@ class EmuShared : public Mutex { Lock(); ResetKrnl(); + m_bEmulating_status = 0; m_dwKrnlProcID = 0; Unlock(); } @@ -241,32 +239,30 @@ class EmuShared : public Mutex // ****************************************************************** // * Shared configuration // ****************************************************************** - XBController m_XBController; - XBVideo m_XBVideo; - XBAudio m_XBAudio; - char m_XbePath[MAX_PATH]; - int m_BootFlags; - int m_FlagsLLE; - int m_Reserved1; - int m_DisablePixelShaders; - int m_UncapFramerate; - int m_UseAllCores; - int m_SkipRdtscPatching; - float m_MSpF; - float m_FPS; + int m_BootFlags_status; + unsigned int m_FlagsLLE_status; + float m_MSpF_status; + float m_FPS_status; bool m_bReserved1; bool m_bDebugging; - bool m_bReady; - bool m_bEmulating; - int m_LedSequence[4]; - int m_ScaleViewport; - int m_DirectHostBackBufferAccess; - char m_StorageLocation[MAX_PATH]; + bool m_bReady_status; + bool m_bEmulating_status; + int m_LedSequence_status[4]; bool m_bFirstLaunch; bool m_bReserved2; bool m_bReserved3; bool m_bReserved4; unsigned int m_dwKrnlProcID; // Only used for kernel mode level. + int m_Reserved99[32]; // Reserve space + + // Settings class in memory should not be tampered by third-party. + // Third-party program should only be allow to edit settings.ini file. + Settings::s_controller_dinput m_controller_dinput; + Settings::s_controller_port m_controller_port; + Settings::s_core m_core; + Settings::s_video m_video; + Settings::s_audio m_audio; + Settings::s_hack m_hacks; }; // ****************************************************************** diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index 71d2f1cad..cb29abe5c 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -51,6 +51,7 @@ namespace xboxkrnl #include "EmuKrnl.h" // For DefaultLaunchDataPage #include "EmuFile.h" #include "EmuFS.h" +#include "EmuXTL.h" #include "EmuShared.h" #include "../Common/Win32/XBPortMapping.h" #include "HLEIntercept.h" @@ -81,8 +82,6 @@ PFARPROC1 fnCxbxVSBCOpen; //typedef DWORD(*fnCxbxVSBCGetState)(UCHAR *); XTL::PXPP_DEVICE_TYPE gDeviceType_Gamepad = nullptr; -#include "EmuXTL.h" - XTL::X_POLLING_PARAMETERS_HANDLE g_pph[4]; XTL::X_XINPUT_POLLING_PARAMETERS g_pp[4]; @@ -123,8 +122,10 @@ int FindDeviceInfoIndexByDeviceType(XTL::PXPP_DEVICE_TYPE DeviceType) //this is called in the end of SetupXboxDeviceTypes(), later we'll move this code to accept user configuration. void InitXboxControllerHostBridge(void) { - //load host type and port configuration from registry. - XBPortMappingLoad("Software\\Cxbx-Reloaded\\XboxPortHostMapping"); + //load host type and port configuration from settings. + Settings::s_controller_port ControllerPortMap; + g_EmuShared->GetControllerPortSettings(&ControllerPortMap); + XBPortMappingSet(ControllerPortMap); total_xinput_gamepad = XTL::XInputGamepad_Connected(); int port; diff --git a/src/CxbxKrnl/HLEIntercept.cpp b/src/CxbxKrnl/HLEIntercept.cpp index 6cfb73d1c..1bf2fb529 100644 --- a/src/CxbxKrnl/HLEIntercept.cpp +++ b/src/CxbxKrnl/HLEIntercept.cpp @@ -333,7 +333,7 @@ void EmuD3D_Init_DeferredStates() // Update shared structure with GUI process void EmuUpdateLLEStatus(uint32_t XbLibScan) { - int FlagsLLE; + uint FlagsLLE; g_EmuShared->GetFlagsLLE(&FlagsLLE); if ((FlagsLLE & LLE_GPU) == false @@ -358,7 +358,7 @@ void EmuUpdateLLEStatus(uint32_t XbLibScan) EmuOutputMessage(XB_OUTPUT_MESSAGE_INFO, "Fallback to LLE USB."); } #endif - g_EmuShared->SetFlagsLLE(&FlagsLLE); + g_EmuShared->SetFlagsLLEStatus(FlagsLLE); } // NOTE: EmuHLEIntercept do not get to be in XbSymbolDatabase, do the intecept in Cxbx project only. @@ -400,8 +400,8 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader) } EmuUpdateLLEStatus(XbLibScan); - int gFlagsLLE; - g_EmuShared->GetFlagsLLE(&gFlagsLLE); + uint gFlagsLLE; + g_EmuShared->GetFlagsLLEStatus(&gFlagsLLE); printf("\n"); printf("*******************************************************************************\n");