From 7fca148bc6f8561b07b3b8790cdb6f286618094c Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sun, 13 Oct 2019 13:01:54 -0500 Subject: [PATCH] implement toggle loader project in GUI --- projects/cxbxr-emu/CMakeLists.txt | 1 + src/common/ReservedMemory.h | 2 ++ src/common/Settings.cpp | 5 +++++ src/common/Settings.hpp | 2 +- src/common/win32/EmuShared.h | 4 ++-- src/core/kernel/init/CxbxKrnl.cpp | 4 ++-- src/core/kernel/init/CxbxKrnl.h | 2 +- src/core/kernel/memory-manager/VMManager.cpp | 4 ++-- src/gui/WinMain.cpp | 12 +++++------- src/gui/WndMain.cpp | 11 +++++++---- src/gui/resource/Cxbx.rc | 8 ++++++-- src/gui/resource/ResCxbx.h | 6 ++++-- 12 files changed, 38 insertions(+), 23 deletions(-) diff --git a/projects/cxbxr-emu/CMakeLists.txt b/projects/cxbxr-emu/CMakeLists.txt index 6e71867e6..e4df55fae 100644 --- a/projects/cxbxr-emu/CMakeLists.txt +++ b/projects/cxbxr-emu/CMakeLists.txt @@ -61,6 +61,7 @@ endif() add_compile_definitions( NOMINMAX + CXBXR_EMU CXBXR_EMU_EXPORTS ) diff --git a/src/common/ReservedMemory.h b/src/common/ReservedMemory.h index 4d5f0287b..fe3e10e23 100644 --- a/src/common/ReservedMemory.h +++ b/src/common/ReservedMemory.h @@ -25,6 +25,7 @@ #ifndef RESERVEDMEMORY_H #define RESERVEDMEMORY_H +#ifndef CXBXR_EMU #if defined(__cplusplus) extern "C" { @@ -49,5 +50,6 @@ unsigned char virtual_memory_placeholder[VM_PLACEHOLDER_SIZE]; // = { OPCODE_NOP #if defined(__cplusplus) } #endif +#endif #endif // RESERVEDMEMORY_H diff --git a/src/common/Settings.cpp b/src/common/Settings.cpp index 7ae1b4afb..61d381656 100644 --- a/src/common/Settings.cpp +++ b/src/common/Settings.cpp @@ -89,6 +89,7 @@ static struct { const char* AllowAdminPrivilege = "AllowAdminPrivilege"; const char* LoggedModules = "LoggedModules"; const char* LogLevel = "LogLevel"; + const char* LoaderExperiment = "LoaderExperiment"; } sect_core_keys; static const char* section_video = "video"; @@ -350,6 +351,8 @@ bool Settings::LoadConfig() index++; } + m_core.loaderExperiment = m_si.GetBoolValue(section_core, sect_core_keys.LoaderExperiment, /*Default=*/false); + // ==== Core End ============ // ==== Hack Begin ========== @@ -525,6 +528,8 @@ bool Settings::Save(std::string file_path) m_si.SetValue(section_core, sect_core_keys.LoggedModules, stream.str().c_str(), nullptr, false); } + m_si.SetBoolValue(section_core, sect_core_keys.LoaderExperiment, m_core.loaderExperiment, nullptr, true); + // ==== Core End ============ // ==== Video Begin ========= diff --git a/src/common/Settings.hpp b/src/common/Settings.hpp index 14bf70811..5df432b37 100644 --- a/src/common/Settings.hpp +++ b/src/common/Settings.hpp @@ -97,7 +97,7 @@ public: bool allowAdminPrivilege; unsigned int LoggedModules[NUM_INTEGERS_LOG]; int LogLevel = 1; - bool Reserved2 = 0; + bool loaderExperiment; bool Reserved3 = 0; bool Reserved4 = 0; int Reserved99[10] = { 0 }; diff --git a/src/common/win32/EmuShared.h b/src/common/win32/EmuShared.h index 9503e4c11..c5f3a81b9 100644 --- a/src/common/win32/EmuShared.h +++ b/src/common/win32/EmuShared.h @@ -191,7 +191,7 @@ class EmuShared : public Mutex // ****************************************************************** void GetDebuggingFlag(bool *value) { Lock(); *value = m_bDebugging; Unlock(); } void SetDebuggingFlag(const bool *value) { Lock(); m_bDebugging = *value; Unlock(); } -#ifndef CXBX_LOADER +#ifndef CXBX_LOADER // Temporary usage for cxbx.exe's emu // ****************************************************************** // * Previous Memory Layout value Accessors // ****************************************************************** @@ -271,7 +271,7 @@ class EmuShared : public Mutex bool m_bDebugging; bool m_bReady_status; bool m_bEmulating_status; -#ifndef CXBX_LOADER +#ifndef CXBX_LOADER // Temporary usage for cxbx.exe's emu int m_PreviousMmLayout; int m_Reserved7[3]; #else diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index 718bc192f..824cdd346 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -938,7 +938,7 @@ void CxbxKrnlEmulate(uint32_t blocks_reserved[384]) return; // TODO : Halt(0); } -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU // verify virtual_memory_placeholder is located at 0x00011000 if ((UINT_PTR)(&(virtual_memory_placeholder[0])) != (XBE_IMAGE_BASE + CXBX_BASE_OF_CODE)) { @@ -1095,7 +1095,7 @@ void CxbxKrnlEmulate(uint32_t blocks_reserved[384]) } #endif -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU // Initialize the memory manager uint32_t SystemDevBlocksReserved[384] = { 0 }; g_VMManager.Initialize(0, BootFlags, SystemDevBlocksReserved); diff --git a/src/core/kernel/init/CxbxKrnl.h b/src/core/kernel/init/CxbxKrnl.h index 5d4533336..e5fdf234e 100644 --- a/src/core/kernel/init/CxbxKrnl.h +++ b/src/core/kernel/init/CxbxKrnl.h @@ -150,7 +150,7 @@ extern "C" { // fit in 51 MB. If we ever encounter an even larger XBE, this // value will have to be increased likewise (maybe up to 64 MB // for XBOX_MEMORY_SIZE or even 128 MB for CHIHIRO_MEMORY_SIZE). -#ifdef CXBX_LOADER +#ifdef CXBXR_EMU #define XBE_MAX_VA (128 * ONE_MB) #else #define XBE_MAX_VA (64 * ONE_MB) diff --git a/src/core/kernel/memory-manager/VMManager.cpp b/src/core/kernel/memory-manager/VMManager.cpp index 655620bad..10bba22fa 100644 --- a/src/core/kernel/memory-manager/VMManager.cpp +++ b/src/core/kernel/memory-manager/VMManager.cpp @@ -41,7 +41,7 @@ #include "core\kernel\exports\EmuKrnl.h" // For InitializeListHead(), etc. #include // Temporary usage for need ReserveAddressRanges func with cxbx.exe's emulation. -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU #include "common/ReserveAddressRanges.h" #endif @@ -60,7 +60,7 @@ bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const void VMManager::Initialize(int SystemType, int BootFlags, uint32_t blocks_reserved[384]) { -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU if ((BootFlags & BOOT_QUICK_REBOOT) == 0) { SystemType = g_bIsRetail ? SYSTEM_XBOX : g_bIsChihiro ? SYSTEM_CHIHIRO : SYSTEM_DEVKIT; // TODO: Temporary placeholder until loader is functional. g_EmuShared->SetMmLayout(&SystemType); diff --git a/src/gui/WinMain.cpp b/src/gui/WinMain.cpp index cb6605cde..56df1d9b6 100644 --- a/src/gui/WinMain.cpp +++ b/src/gui/WinMain.cpp @@ -56,7 +56,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine return EXIT_FAILURE; } -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU /*! verify Cxbx.exe is loaded to base address 0x00010000 */ if (!VerifyBaseAddr()) { CxbxShowError("Cxbx.exe is not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)"); @@ -81,16 +81,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } if (cli_config::hasKey("load")) { -#ifndef CXBX_LOADER +#ifndef CXBXR_EMU CxbxKrnlEmulate(nullptr); EmuShared::Cleanup(); return EXIT_SUCCESS; #else - if (!CxbxExec(false, nullptr, false)) { - CxbxShowError("Could not launch Cxbx-R loader!"); - EmuShared::Cleanup(); - return EXIT_FAILURE; - } + CxbxShowError("Emulation must be launched from cxbxr-ldr.exe!"); + EmuShared::Cleanup(); + return EXIT_FAILURE; #endif } diff --git a/src/gui/WndMain.cpp b/src/gui/WndMain.cpp index 59c993e80..ffcc32fed 100644 --- a/src/gui/WndMain.cpp +++ b/src/gui/WndMain.cpp @@ -1754,6 +1754,9 @@ void WndMain::RefreshMenus() //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 = g_Settings->m_core.loaderExperiment ? MF_CHECKED : MF_UNCHECKED; + CheckMenuItem(settings_menu, ID_EXPERIMENTAL_LOADERPROJECT, chk_flag); + chk_flag = (g_Settings->m_hacks.DisablePixelShaders) ? MF_CHECKED : MF_UNCHECKED; CheckMenuItem(settings_menu, ID_HACKS_DISABLEPIXELSHADERS, chk_flag); @@ -2268,10 +2271,10 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState / char szExeFileName[MAX_PATH]; GetModuleFileName(GetModuleHandle(nullptr), szExeFileName, MAX_PATH); -#ifdef CXBX_LOADER - PathRemoveFileSpec(szExeFileName); - PathAppend(szExeFileName, "\\cxbxr-ldr.exe"); -#endif + if (g_Settings->m_core.loaderExperiment) { + PathRemoveFileSpec(szExeFileName); + PathAppend(szExeFileName, "\\cxbxr-ldr.exe"); + } bool AttachLocalDebugger = (LocalDebuggerState == debuggerOn); g_EmuShared->SetDebuggingFlag(&AttachLocalDebugger); diff --git a/src/gui/resource/Cxbx.rc b/src/gui/resource/Cxbx.rc index ce03fc24d..fce096496 100644 --- a/src/gui/resource/Cxbx.rc +++ b/src/gui/resource/Cxbx.rc @@ -661,9 +661,13 @@ BEGIN MENUITEM "&Rescan title Symbol Cache", ID_CACHE_CLEARHLECACHE_CURRENT,MFT_STRING,MFS_ENABLED END MENUITEM "", -1, MFT_SEPARATOR - POPUP "&LLE (Experimental)", 65535,MFT_STRING,MFS_ENABLED + POPUP "Experimental", 65535,MFT_STRING,MFS_ENABLED BEGIN - MENUITEM "LLE &GPU", ID_EMULATION_LLE_GPU,MFT_STRING,MFS_GRAYED + POPUP "&LLE", 65535,MFT_STRING,MFS_ENABLED + BEGIN + MENUITEM "LLE &GPU", ID_EMULATION_LLE_GPU,MFT_STRING,MFS_GRAYED + END + MENUITEM "Loader Project", ID_EXPERIMENTAL_LOADERPROJECT,MFT_STRING,MFS_GRAYED END POPUP "Hacks", 65535,MFT_STRING,MFS_ENABLED BEGIN diff --git a/src/gui/resource/ResCxbx.h b/src/gui/resource/ResCxbx.h index f2b307c9d..91cc68481 100644 --- a/src/gui/resource/ResCxbx.h +++ b/src/gui/resource/ResCxbx.h @@ -362,6 +362,8 @@ #define ID_LOG 40110 #define ID_SETTINGS_CONFIG_NETWORK 40111 #define ID_SYNC_CONFIG_INPUT 40112 +#define ID_SETTINGS_EXPERIMENTAL 40113 +#define ID_EXPERIMENTAL_LOADERPROJECT 40114 #define IDC_STATIC -1 // Next default values for new objects @@ -369,8 +371,8 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 136 -#define _APS_NEXT_COMMAND_VALUE 40113 -#define _APS_NEXT_CONTROL_VALUE 1278 +#define _APS_NEXT_COMMAND_VALUE 40115 +#define _APS_NEXT_CONTROL_VALUE 1304 #define _APS_NEXT_SYMED_VALUE 109 #endif #endif