From e2e99caeee5ea579431f01bc6d6b84c3d5821872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 26 Mar 2025 09:23:38 +0100 Subject: [PATCH] Some minor reordering, reduce the calls to Identify_File --- Core/CoreParameter.h | 2 +- Core/Loaders.cpp | 3 +-- Core/Loaders.h | 2 +- Core/System.cpp | 36 ++++++++++++++++++++---------------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index 13deda4162..a2f0dd5d03 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -75,7 +75,7 @@ struct CoreParameter { int pixelWidth; int pixelHeight; - // Can be modified at runtime. + // Can be modified at runtime. Do not belong here. bool fastForward = false; FPSLimit fpsLimit = FPSLimit::NORMAL; int analogFpsLimit = 0; diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 3891082b6f..c3696235f1 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -249,9 +249,8 @@ Path ResolvePBPFile(const Path &filename) { } } -bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) { +bool LoadFile(FileLoader **fileLoaderPtr, IdentifiedFileType type, std::string *error_string) { FileLoader *&fileLoader = *fileLoaderPtr; - IdentifiedFileType type = Identify_File(fileLoader, error_string); switch (type) { case IdentifiedFileType::PSP_PBP_DIRECTORY: { diff --git a/Core/Loaders.h b/Core/Loaders.h index 7cb0c1938e..71f12afae2 100644 --- a/Core/Loaders.h +++ b/Core/Loaders.h @@ -148,6 +148,6 @@ Path ResolvePBPFile(const Path &filename); IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString); // Can modify the string filename, as it calls IdentifyFile above. -bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string); +bool LoadFile(FileLoader **fileLoaderPtr, IdentifiedFileType type, std::string *error_string); bool UmdReplace(const Path &filepath, FileLoader **fileLoader, std::string &error); diff --git a/Core/System.cpp b/Core/System.cpp index 6339d5ba89..541744fbd9 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -225,12 +225,6 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy g_DoubleTextureCoordinates = false; Memory::g_PSPModel = g_Config.iPSPModel; - Path filename = g_CoreParameter.fileToStart; - - // TODO: Put this somewhere better? - if (!g_CoreParameter.mountIso.empty()) { - g_CoreParameter.mountIsoLoader = ConstructFileLoader(g_CoreParameter.mountIso); - } g_CoreParameter.fileType = type; MIPSAnalyst::Reset(); @@ -243,7 +237,10 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy case IdentifiedFileType::PSP_ISO: case IdentifiedFileType::PSP_ISO_NP: case IdentifiedFileType::PSP_DISC_DIRECTORY: - MountGameISO(loadedFile); + if (!MountGameISO(loadedFile)) { + *errorString = "Failed to mount ISO file - invalid format?"; + return false; + } if (LoadParamSFOFromDisc()) { InitMemorySizeForGame(); } @@ -264,7 +261,7 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy break; case IdentifiedFileType::PPSSPP_GE_DUMP: // Try to grab the disc ID from the filename or GE dump. - if (DiscIDFromGEDumpPath(filename, loadedFile, &geDumpDiscID)) { + if (DiscIDFromGEDumpPath(g_CoreParameter.fileToStart, loadedFile, &geDumpDiscID)) { // Store in SFO, otherwise it'll generate a fake disc ID. g_paramSFO.SetValue("DISC_ID", geDumpDiscID, 16); } @@ -281,16 +278,17 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy // likely to collide with any commercial ones. g_CoreParameter.compat.Load(g_paramSFO.GetDiscID()); - InitVFPU(); - - if (allowPlugins) - HLEPlugins::Init(); + // Initialize the memory map as early as possible (now that we've read the PARAM.SFO). if (!Memory::Init()) { // We're screwed. *errorString = "Memory init failed"; return false; } - mipsr4k.Reset(); + + InitVFPU(); + + if (allowPlugins) + HLEPlugins::Init(); LoadSymbolsIfSupported(); @@ -299,19 +297,26 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile, IdentifiedFileTy // Init all the HLE modules HLEInit(); + // TODO: Put this somewhere better? + if (!g_CoreParameter.mountIso.empty()) { + g_CoreParameter.mountIsoLoader = ConstructFileLoader(g_CoreParameter.mountIso); + } + + mipsr4k.Reset(); + // TODO: Check Game INI here for settings, patches and cheats, and modify coreParameter accordingly // If they shut down early, we'll catch it when load completes. // Note: this may return before init is complete, which is checked if CPU_IsReady(). g_loadedFile = loadedFile; - if (!LoadFile(&loadedFile, &g_CoreParameter.errorString)) { + if (!LoadFile(&loadedFile, type, &g_CoreParameter.errorString)) { CPU_Shutdown(); g_CoreParameter.fileToStart.clear(); return false; } if (g_CoreParameter.updateRecent) { - g_Config.AddRecent(filename.ToString()); + g_Config.AddRecent(g_CoreParameter.fileToStart.ToString()); } InstallExceptionHandler(&Memory::HandleFault); @@ -424,7 +429,6 @@ bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) { // Need to re-identify after ResolveFileLoaderTarget - although in practice probably not, // but also, re-using the identification would require some plumbing, to be done later. std::string errorString; - IdentifiedFileType type = Identify_File(loadedFile, &errorString); Achievements::SetGame(filename, type, loadedFile); }