From c8830343720e44abd7a413b3db31c819ec17bd28 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Wed, 16 Feb 2022 14:56:45 +0100 Subject: [PATCH] Cleanup system selection, so it's no longer abusing xbeType Rename g_bIsDebug into g_bIsDevKit for consistency with system selection Cleaned up related comments --- src/Cxbx.h | 9 ++--- src/core/kernel/exports/EmuKrnlEx.cpp | 2 +- src/core/kernel/init/CxbxKrnl.cpp | 50 ++++++++++++++------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/Cxbx.h b/src/Cxbx.h index a459da12b..6f88afd58 100644 --- a/src/Cxbx.h +++ b/src/Cxbx.h @@ -61,13 +61,14 @@ enum DebugMode { DM_NONE, DM_CONSOLE, DM_FILE }; /*! debugger enable state */ enum DebuggerState { debuggerOff, debuggerOn }; -/*! indicates emulation of an Chihiro (arcade, instead of Xbox console) executable */ +/*! indicates emulation of a Chihiro system */ extern bool g_bIsChihiro; -/*! indicates emulation of a Debug xbe executable */ -extern bool g_bIsDebug; +/*! indicates emulation of a DevKit system */ +/* Note: Our DevKit emulation lacks the kernel debugging interface and virtual dvd-rom emulator card, so this is actually a Debug Kit */ +extern bool g_bIsDevKit; -/*! indicates emulation of a Retail xbe executable*/ +/*! indicates emulation of a Retail system */ extern bool g_bIsRetail; /*! indicates ability to save on exit (needed for settings reset) */ diff --git a/src/core/kernel/exports/EmuKrnlEx.cpp b/src/core/kernel/exports/EmuKrnlEx.cpp index 8eb59a5b4..869e7339d 100644 --- a/src/core/kernel/exports/EmuKrnlEx.cpp +++ b/src/core/kernel/exports/EmuKrnlEx.cpp @@ -641,7 +641,7 @@ XBSYSAPI EXPORTNUM(29) xbox::ntstatus_xt NTAPI xbox::ExSaveNonVolatileSetting RETURN(X_STATUS_OBJECT_NAME_NOT_FOUND); // handle eeprom write - if (g_bIsDebug || ValueIndex <= XC_MAX_OS || ValueIndex > XC_MAX_FACTORY) + if (g_bIsDevKit || ValueIndex <= XC_MAX_OS || ValueIndex > XC_MAX_FACTORY) { const EEPROMInfo* info = EmuFindEEPROMInfo((XC_VALUE_INDEX)ValueIndex); if (info != nullptr) { diff --git a/src/core/kernel/init/CxbxKrnl.cpp b/src/core/kernel/init/CxbxKrnl.cpp index 1d8152ea2..a5c963a02 100644 --- a/src/core/kernel/init/CxbxKrnl.cpp +++ b/src/core/kernel/init/CxbxKrnl.cpp @@ -103,7 +103,7 @@ char szFilePath_Xbe[xbox::max_path*2] = { 0 }; // NOTE: LAUNCH_DATA_HEADER's szL Xbe* CxbxKrnl_Xbe = NULL; bool g_bIsChihiro = false; -bool g_bIsDebug = false; +bool g_bIsDevKit = false; bool g_bIsRetail = false; // Indicates to disable/enable all interrupts when cli and sti instructions are executed @@ -615,7 +615,7 @@ static void CxbxrKrnlSetupMemorySystem(int BootFlags, unsigned emulate_system, u static bool CxbxrKrnlXbeSystemSelector(int BootFlags, unsigned& reserved_systems, blocks_reserved_t blocks_reserved) { - XbeType xbeType = XbeType::xtRetail; + unsigned int emulate_system = 0; // Get title path : std::string xbePath; cli_config::GetValue(cli_config::load, &xbePath); @@ -739,41 +739,43 @@ static bool CxbxrKrnlXbeSystemSelector(int BootFlags, unsigned& reserved_systems // If CLI has given console type, then enforce it. if (cli_config::hasKey(cli_config::system_chihiro)) { EmuLogInit(LOG_LEVEL::INFO, "Auto detect is disabled, running as chihiro."); - xbeType = XbeType::xtChihiro; + emulate_system = SYSTEM_CHIHIRO; } else if (cli_config::hasKey(cli_config::system_devkit)) { EmuLogInit(LOG_LEVEL::INFO, "Auto detect is disabled, running as devkit."); - xbeType = XbeType::xtDebug; + emulate_system = SYSTEM_DEVKIT; } else if (cli_config::hasKey(cli_config::system_retail)) { EmuLogInit(LOG_LEVEL::INFO, "Auto detect is disabled, running as retail."); - xbeType = XbeType::xtRetail; + emulate_system = SYSTEM_XBOX; } // Otherwise, use auto detect method. else { // Detect XBE type : - xbeType = CxbxKrnl_Xbe->GetXbeType(); + XbeType xbeType = CxbxKrnl_Xbe->GetXbeType(); EmuLogInit(LOG_LEVEL::INFO, "Auto detect: XbeType = %s", GetXbeTypeToStr(xbeType)); + // Convert XBE type into corresponding system to emulate. + switch (xbeType) { + case XbeType::xtChihiro: + emulate_system = SYSTEM_CHIHIRO; + break; + case XbeType::xtDebug: + emulate_system = SYSTEM_DEVKIT; + break; + case XbeType::xtRetail: + emulate_system = SYSTEM_XBOX; + break; + DEFAULT_UNREACHABLE; + } } EmuLogInit(LOG_LEVEL::INFO, "Host's compatible system types: %2X", reserved_systems); - unsigned int emulate_system = 0; - // Set reserved_systems which system we will about to emulate. - if (isSystemFlagSupport(reserved_systems, SYSTEM_CHIHIRO) && xbeType == XbeType::xtChihiro) { - emulate_system = SYSTEM_CHIHIRO; - } - else if (isSystemFlagSupport(reserved_systems, SYSTEM_DEVKIT) && xbeType == XbeType::xtDebug) { - emulate_system = SYSTEM_DEVKIT; - } - else if (isSystemFlagSupport(reserved_systems, SYSTEM_XBOX) && xbeType == XbeType::xtRetail) { - emulate_system = SYSTEM_XBOX; - } - // If none of system type requested to emulate isn't supported on host's end. Then enforce failure. - else { + // If the system to emulate isn't supported on host, enforce failure. + if (!isSystemFlagSupport(reserved_systems, emulate_system)) { CxbxrKrnlAbort("Unable to emulate system type due to host is not able to reserve required memory ranges."); return false; } - // Clear emulation system from reserved systems to be free. + // Clear emulation system from reserved systems so all unneeded memory ranges can be freed. reserved_systems &= ~emulate_system; // Once we have determine which system type to run as, enforce it in future reboots. @@ -782,10 +784,10 @@ static bool CxbxrKrnlXbeSystemSelector(int BootFlags, unsigned& reserved_systems cli_config::SetSystemType(system_str); } - // Register if we're running an Chihiro executable or a debug xbe, otherwise it's an Xbox retail executable - g_bIsChihiro = (xbeType == XbeType::xtChihiro); - g_bIsDebug = (xbeType == XbeType::xtDebug); - g_bIsRetail = (xbeType == XbeType::xtRetail); + // Register if we're running a Chihiro arcade or Xbox Devkit (otherwise it's a retail Xbox console) system + g_bIsChihiro = (emulate_system == SYSTEM_CHIHIRO); + g_bIsDevKit = (emulate_system == SYSTEM_DEVKIT); + g_bIsRetail = (emulate_system == SYSTEM_XBOX); #ifdef CHIHIRO_WORK // If this is a Chihiro title, we need to patch the init flags to disable HDD setup