2012-11-01 16:19:01 +01:00
|
|
|
// Copyright (C) 2012 PPSSPP Project
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
2017-02-24 18:59:41 +01:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
|
2013-08-17 15:12:42 +02:00
|
|
|
#ifdef _WIN32
|
2015-09-23 19:29:39 +02:00
|
|
|
#pragma warning(disable:4091)
|
2013-07-28 20:43:25 -07:00
|
|
|
#include "Common/CommonWindows.h"
|
2013-10-13 16:45:13 -04:00
|
|
|
#include <ShlObj.h>
|
2013-10-13 17:17:48 -04:00
|
|
|
#include <string>
|
2013-10-14 02:22:13 -04:00
|
|
|
#include <codecvt>
|
2020-01-04 10:57:23 -08:00
|
|
|
#if !PPSSPP_PLATFORM(UWP)
|
|
|
|
|
#include "Windows/W32Util/ShellUtil.h"
|
|
|
|
|
#endif
|
2013-03-28 20:17:45 +01:00
|
|
|
#endif
|
2017-12-20 10:22:15 +01:00
|
|
|
|
2017-02-27 20:51:36 +01:00
|
|
|
#include <thread>
|
2017-02-27 21:57:46 +01:00
|
|
|
#include <mutex>
|
2017-12-20 10:22:15 +01:00
|
|
|
#include <condition_variable>
|
2013-03-28 20:17:45 +01:00
|
|
|
|
2024-10-24 00:58:13 +02:00
|
|
|
#include "ext/lua/lapi.h"
|
|
|
|
|
|
2020-10-04 10:30:18 +02:00
|
|
|
#include "Common/System/System.h"
|
2023-03-22 23:25:00 +01:00
|
|
|
#include "Common/System/Request.h"
|
2021-05-06 01:31:38 +02:00
|
|
|
#include "Common/File/Path.h"
|
2023-03-24 18:08:31 +01:00
|
|
|
#include "Common/File/FileUtil.h"
|
|
|
|
|
#include "Common/File/DirListing.h"
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Common/Math/math_util.h"
|
2020-10-01 09:27:25 +02:00
|
|
|
#include "Common/Thread/ThreadUtil.h"
|
2020-10-01 13:05:04 +02:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2020-08-15 20:53:08 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
2019-09-28 21:36:03 -07:00
|
|
|
#include "Common/GraphicsContext.h"
|
2023-03-24 18:08:31 +01:00
|
|
|
|
2023-07-12 01:11:09 +02:00
|
|
|
#include "Core/RetroAchievements.h"
|
2020-07-15 12:10:33 +02:00
|
|
|
#include "Core/MemFault.h"
|
2014-03-15 10:38:46 -07:00
|
|
|
#include "Core/HDRemaster.h"
|
2013-07-29 08:12:46 -07:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-11-30 20:57:44 +01:00
|
|
|
#include "Core/MIPS/MIPSAnalyst.h"
|
2020-11-23 23:51:07 +01:00
|
|
|
#include "Core/MIPS/MIPSVFPUUtils.h"
|
2019-09-28 21:36:03 -07:00
|
|
|
#include "Core/Debugger/SymbolMap.h"
|
2013-07-29 08:12:46 -07:00
|
|
|
#include "Core/System.h"
|
|
|
|
|
#include "Core/HLE/HLE.h"
|
2020-08-25 19:54:51 -07:00
|
|
|
#include "Core/HLE/Plugins.h"
|
2013-12-17 23:40:27 +01:00
|
|
|
#include "Core/HLE/ReplaceTables.h"
|
2013-07-29 08:12:46 -07:00
|
|
|
#include "Core/HLE/sceKernel.h"
|
|
|
|
|
#include "Core/HLE/sceKernelMemory.h"
|
|
|
|
|
#include "Core/HLE/sceAudio.h"
|
|
|
|
|
#include "Core/Config.h"
|
|
|
|
|
#include "Core/Core.h"
|
|
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
|
#include "Core/CoreParameter.h"
|
2015-12-19 15:23:25 -08:00
|
|
|
#include "Core/FileLoaders/RamCachingFileLoader.h"
|
2013-07-29 08:12:46 -07:00
|
|
|
#include "Core/FileSystems/MetaFileSystem.h"
|
|
|
|
|
#include "Core/Loaders.h"
|
|
|
|
|
#include "Core/PSPLoaders.h"
|
|
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2013-08-06 23:00:20 -07:00
|
|
|
#include "Core/SaveState.h"
|
2019-02-11 11:11:56 +01:00
|
|
|
#include "Common/ExceptionHandlerSetup.h"
|
2014-03-23 19:45:08 +01:00
|
|
|
#include "Core/HLE/sceAudiocodec.h"
|
2013-08-07 08:07:13 -07:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
|
#include "GPU/GPUInterface.h"
|
2020-09-06 14:38:56 -07:00
|
|
|
#include "GPU/Debugger/RecordFormat.h"
|
2023-07-12 01:11:09 +02:00
|
|
|
#include "Core/RetroAchievements.h"
|
2013-08-07 08:07:13 -07:00
|
|
|
|
|
|
|
|
enum CPUThreadState {
|
|
|
|
|
CPU_THREAD_NOT_RUNNING,
|
|
|
|
|
CPU_THREAD_PENDING,
|
|
|
|
|
CPU_THREAD_STARTING,
|
|
|
|
|
CPU_THREAD_RUNNING,
|
|
|
|
|
CPU_THREAD_SHUTDOWN,
|
2014-12-20 16:11:19 -08:00
|
|
|
CPU_THREAD_QUIT,
|
2013-08-07 08:07:13 -07:00
|
|
|
|
|
|
|
|
CPU_THREAD_EXECUTE,
|
2014-12-20 16:11:19 -08:00
|
|
|
CPU_THREAD_RESUME,
|
2013-08-07 08:07:13 -07:00
|
|
|
};
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
MetaFileSystem pspFileSystem;
|
2013-01-02 21:00:10 +01:00
|
|
|
ParamSFOData g_paramSFO;
|
2014-06-22 09:38:46 +02:00
|
|
|
static GlobalUIState globalUIState;
|
2022-04-30 23:49:51 +02:00
|
|
|
CoreParameter g_CoreParameter;
|
2023-09-25 22:09:28 -07:00
|
|
|
static FileLoader *g_loadedFile;
|
2018-11-01 21:27:01 -07:00
|
|
|
// For background loading thread.
|
|
|
|
|
static std::mutex loadingLock;
|
|
|
|
|
// For loadingReason updates.
|
2018-03-12 18:06:46 -07:00
|
|
|
static std::mutex loadingReasonLock;
|
|
|
|
|
static std::string loadingReason;
|
2017-12-15 12:40:38 +01:00
|
|
|
|
2015-01-11 12:02:49 +01:00
|
|
|
bool audioInitialized;
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2017-03-23 18:57:18 -07:00
|
|
|
bool coreCollectDebugStats = false;
|
2021-09-19 15:17:13 -07:00
|
|
|
static int coreCollectDebugStatsCounter = 0;
|
2017-03-23 18:57:18 -07:00
|
|
|
|
2013-03-29 20:51:14 +01:00
|
|
|
// This can be read and written from ANYWHERE.
|
|
|
|
|
volatile CoreState coreState = CORE_STEPPING;
|
2020-07-04 23:45:03 +02:00
|
|
|
// If true, core state has been changed, but JIT has probably not noticed yet.
|
2013-03-29 20:51:14 +01:00
|
|
|
volatile bool coreStatePending = false;
|
2020-07-04 20:30:05 +02:00
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
static volatile CPUThreadState cpuThreadState = CPU_THREAD_NOT_RUNNING;
|
2013-03-29 20:51:14 +01:00
|
|
|
|
2016-01-05 22:37:28 -08:00
|
|
|
static GPUBackend gpuBackend;
|
2018-09-30 00:53:21 -07:00
|
|
|
static std::string gpuBackendDevice;
|
2016-01-05 22:37:28 -08:00
|
|
|
|
2020-07-04 20:30:05 +02:00
|
|
|
// Ugly!
|
2020-08-18 09:18:24 +02:00
|
|
|
static volatile bool pspIsInited = false;
|
|
|
|
|
static volatile bool pspIsIniting = false;
|
|
|
|
|
static volatile bool pspIsQuitting = false;
|
2022-10-01 18:13:22 -07:00
|
|
|
static volatile bool pspIsRebooting = false;
|
2020-07-04 20:30:05 +02:00
|
|
|
|
2024-11-03 20:49:20 +01:00
|
|
|
// This is called on EmuThread before RunLoop.
|
|
|
|
|
void Core_ProcessStepping(MIPSDebugInterface *cpu);
|
|
|
|
|
|
2017-04-15 16:33:30 -07:00
|
|
|
void ResetUIState() {
|
|
|
|
|
globalUIState = UISTATE_MENU;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-29 23:44:35 +01:00
|
|
|
void UpdateUIState(GlobalUIState newState) {
|
|
|
|
|
// Never leave the EXIT state.
|
|
|
|
|
if (globalUIState != newState && globalUIState != UISTATE_EXIT) {
|
|
|
|
|
globalUIState = newState;
|
2023-03-21 11:21:19 +01:00
|
|
|
System_Notify(SystemNotification::DISASSEMBLY);
|
2024-05-26 09:55:50 +02:00
|
|
|
System_Notify(SystemNotification::UI_STATE_CHANGED);
|
2024-05-20 14:03:54 +02:00
|
|
|
System_SetKeepScreenBright(globalUIState == UISTATE_INGAME);
|
2013-12-29 23:44:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-22 09:38:46 +02:00
|
|
|
GlobalUIState GetUIState() {
|
|
|
|
|
return globalUIState;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 00:53:21 -07:00
|
|
|
void SetGPUBackend(GPUBackend type, const std::string &device) {
|
2016-01-05 22:37:28 -08:00
|
|
|
gpuBackend = type;
|
2018-09-30 00:53:21 -07:00
|
|
|
gpuBackendDevice = device;
|
2016-01-05 22:37:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUBackend GetGPUBackend() {
|
|
|
|
|
return gpuBackend;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 00:53:21 -07:00
|
|
|
std::string GetGPUBackendDevice() {
|
|
|
|
|
return gpuBackendDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
bool CPU_IsReady() {
|
2018-01-01 19:52:24 -08:00
|
|
|
if (coreState == CORE_POWERUP)
|
|
|
|
|
return false;
|
2013-08-07 08:07:13 -07:00
|
|
|
return cpuThreadState == CPU_THREAD_RUNNING || cpuThreadState == CPU_THREAD_NOT_RUNNING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPU_IsShutdown() {
|
|
|
|
|
return cpuThreadState == CPU_THREAD_NOT_RUNNING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPU_HasPendingAction() {
|
|
|
|
|
return cpuThreadState != CPU_THREAD_RUNNING;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:50:21 -07:00
|
|
|
void CPU_Shutdown();
|
|
|
|
|
|
2023-03-24 18:08:31 +01:00
|
|
|
static Path SymbolMapFilename(const Path ¤tFilename, const char *ext) {
|
|
|
|
|
File::FileInfo info{};
|
|
|
|
|
// can't fail, definitely exists if it gets this far
|
|
|
|
|
File::GetFileInfo(currentFilename, &info);
|
|
|
|
|
if (info.isDirectory) {
|
|
|
|
|
return currentFilename / (std::string(".ppsspp-symbols") + ext);
|
|
|
|
|
}
|
|
|
|
|
return currentFilename.WithReplacedExtension(ext);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool LoadSymbolsIfSupported() {
|
|
|
|
|
if (System_GetPropertyBool(SYSPROP_HAS_DEBUGGER)) {
|
|
|
|
|
if (!g_symbolMap)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-12-29 12:17:10 +01:00
|
|
|
if (PSP_CoreParameter().fileToStart.Type() == PathType::HTTP) {
|
|
|
|
|
// We don't support loading symbols over HTTP.
|
|
|
|
|
g_symbolMap->Clear();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 18:08:31 +01:00
|
|
|
bool result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
|
|
|
|
|
// Load the old-style map file.
|
|
|
|
|
if (!result1)
|
|
|
|
|
result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".map"));
|
|
|
|
|
bool result2 = g_symbolMap->LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".sym"));
|
|
|
|
|
return result1 || result2;
|
|
|
|
|
} else {
|
|
|
|
|
g_symbolMap->Clear();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool SaveSymbolMapIfSupported() {
|
|
|
|
|
if (g_symbolMap) {
|
|
|
|
|
return g_symbolMap->SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
bool DiscIDFromGEDumpPath(const Path &path, FileLoader *fileLoader, std::string *id) {
|
2020-09-06 14:38:56 -07:00
|
|
|
using namespace GPURecord;
|
|
|
|
|
|
|
|
|
|
// For newer files, it's stored in the dump.
|
|
|
|
|
Header header;
|
|
|
|
|
if (fileLoader->ReadAt(0, sizeof(header), &header) == sizeof(header)) {
|
|
|
|
|
const bool magicMatch = memcmp(header.magic, HEADER_MAGIC, sizeof(header.magic)) == 0;
|
|
|
|
|
if (magicMatch && header.version <= VERSION && header.version >= 4) {
|
|
|
|
|
size_t gameIDLength = strnlen(header.gameID, sizeof(header.gameID));
|
|
|
|
|
if (gameIDLength != 0) {
|
|
|
|
|
*id = std::string(header.gameID, gameIDLength);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fall back to using the filename.
|
2021-05-14 23:08:00 -07:00
|
|
|
std::string filename = path.GetFilename();
|
2020-08-30 11:48:58 +02:00
|
|
|
// Could be more discerning, but hey..
|
2023-12-30 22:06:52 +01:00
|
|
|
if (filename.size() > 10 && (filename[0] == 'U' || filename[0] == 'N') && filename[9] == '_') {
|
2020-08-30 11:48:58 +02:00
|
|
|
*id = filename.substr(0, 9);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 01:11:09 +02:00
|
|
|
bool CPU_Init(std::string *errorString, FileLoader *loadedFile) {
|
2013-11-09 20:56:11 -08:00
|
|
|
coreState = CORE_POWERUP;
|
2013-12-30 00:11:29 +01:00
|
|
|
currentMIPS = &mipsr4k;
|
2016-08-27 14:38:05 -04:00
|
|
|
|
2015-10-31 23:01:19 +01:00
|
|
|
g_symbolMap = new SymbolMap();
|
2013-06-22 05:14:01 -04:00
|
|
|
|
2013-06-23 00:17:33 -04:00
|
|
|
// Default memory settings
|
|
|
|
|
// Seems to be the safest place currently..
|
2015-12-23 15:10:08 -08:00
|
|
|
Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE; // 32 MB of ram by default
|
2013-11-28 14:37:10 -05:00
|
|
|
|
2013-06-23 00:17:33 -04:00
|
|
|
g_RemasterMode = false;
|
|
|
|
|
g_DoubleTextureCoordinates = false;
|
2013-11-28 15:34:11 -05:00
|
|
|
Memory::g_PSPModel = g_Config.iPSPModel;
|
2013-06-23 00:17:33 -04:00
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
Path filename = g_CoreParameter.fileToStart;
|
2021-08-07 11:54:45 +02:00
|
|
|
|
|
|
|
|
IdentifiedFileType type = Identify_File(loadedFile, errorString);
|
2013-06-22 05:14:01 -04:00
|
|
|
|
2014-11-23 13:59:56 -08:00
|
|
|
// TODO: Put this somewhere better?
|
2022-04-30 23:49:51 +02:00
|
|
|
if (!g_CoreParameter.mountIso.empty()) {
|
|
|
|
|
g_CoreParameter.mountIsoLoader = ConstructFileLoader(g_CoreParameter.mountIso);
|
2014-11-23 13:59:56 -08:00
|
|
|
}
|
2024-11-01 20:27:09 +01:00
|
|
|
g_CoreParameter.fileType = type;
|
2014-11-23 13:59:56 -08:00
|
|
|
|
2013-11-30 20:57:44 +01:00
|
|
|
MIPSAnalyst::Reset();
|
2013-12-17 23:40:27 +01:00
|
|
|
Replacement_Init();
|
2013-11-30 20:57:44 +01:00
|
|
|
|
2021-01-31 09:22:20 -08:00
|
|
|
bool allowPlugins = true;
|
|
|
|
|
std::string geDumpDiscID;
|
2020-08-30 11:48:58 +02:00
|
|
|
|
2013-08-10 19:56:47 +02:00
|
|
|
switch (type) {
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
|
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
2014-11-23 13:25:32 -08:00
|
|
|
InitMemoryForGameISO(loadedFile);
|
2013-08-10 19:56:47 +02:00
|
|
|
break;
|
2017-03-02 12:29:03 +01:00
|
|
|
case IdentifiedFileType::PSP_PBP:
|
|
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
2016-03-09 17:02:53 +01:00
|
|
|
// This is normal for homebrew.
|
2024-07-14 14:42:59 +02:00
|
|
|
// ERROR_LOG(Log::Loader, "PBP directory resolution failed.");
|
2017-05-24 18:12:35 +02:00
|
|
|
InitMemoryForGamePBP(loadedFile);
|
2016-03-09 17:02:53 +01:00
|
|
|
break;
|
2020-03-16 19:54:48 -07:00
|
|
|
case IdentifiedFileType::PSP_ELF:
|
|
|
|
|
if (Memory::g_PSPModel != PSP_MODEL_FAT) {
|
2024-07-14 14:42:59 +02:00
|
|
|
INFO_LOG(Log::Loader, "ELF, using full PSP-2000 memory access");
|
2020-03-16 19:54:48 -07:00
|
|
|
Memory::g_MemorySize = Memory::RAM_DOUBLE_SIZE;
|
|
|
|
|
}
|
2020-08-30 11:48:58 +02:00
|
|
|
break;
|
|
|
|
|
case IdentifiedFileType::PPSSPP_GE_DUMP:
|
2023-12-30 22:06:52 +01:00
|
|
|
// Try to grab the disc ID from the filename or GE dump.
|
2021-01-31 09:22:20 -08:00
|
|
|
if (DiscIDFromGEDumpPath(filename, loadedFile, &geDumpDiscID)) {
|
|
|
|
|
// Store in SFO, otherwise it'll generate a fake disc ID.
|
|
|
|
|
g_paramSFO.SetValue("DISC_ID", geDumpDiscID, 16);
|
2020-08-30 11:48:58 +02:00
|
|
|
}
|
2021-01-31 09:22:20 -08:00
|
|
|
allowPlugins = false;
|
2020-03-16 19:54:48 -07:00
|
|
|
break;
|
2013-08-10 19:56:47 +02:00
|
|
|
default:
|
2021-08-07 11:54:45 +02:00
|
|
|
// Can we even get here?
|
2024-10-31 23:56:36 +01:00
|
|
|
ERROR_LOG(Log::Loader, "CPU_Init didn't recognize file. %s", errorString->c_str());
|
|
|
|
|
return false;
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
2013-06-22 05:14:01 -04:00
|
|
|
|
2015-09-26 16:01:16 +02:00
|
|
|
// Here we have read the PARAM.SFO, let's see if we need any compatibility overrides.
|
2015-09-26 23:39:04 +02:00
|
|
|
// Homebrew usually has an empty discID, and even if they do have a disc id, it's not
|
|
|
|
|
// likely to collide with any commercial ones.
|
2022-04-30 23:49:51 +02:00
|
|
|
g_CoreParameter.compat.Load(g_paramSFO.GetDiscID());
|
2015-09-26 16:01:16 +02:00
|
|
|
|
2023-03-09 23:23:33 -05:00
|
|
|
InitVFPU();
|
2020-11-23 23:51:07 +01:00
|
|
|
|
2021-01-31 09:22:20 -08:00
|
|
|
if (allowPlugins)
|
|
|
|
|
HLEPlugins::Init();
|
2020-07-19 20:32:15 +02:00
|
|
|
if (!Memory::Init()) {
|
|
|
|
|
// We're screwed.
|
2022-09-03 21:05:58 -07:00
|
|
|
*errorString = "Memory init failed";
|
2020-07-19 20:32:15 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2012-11-01 16:19:01 +01:00
|
|
|
mipsr4k.Reset();
|
|
|
|
|
|
2023-03-24 18:08:31 +01:00
|
|
|
LoadSymbolsIfSupported();
|
2013-03-30 21:42:43 -07:00
|
|
|
|
2013-01-17 01:12:40 -08:00
|
|
|
CoreTiming::Init();
|
|
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
// Init all the HLE modules
|
|
|
|
|
HLEInit();
|
|
|
|
|
|
|
|
|
|
// TODO: Check Game INI here for settings, patches and cheats, and modify coreParameter accordingly
|
|
|
|
|
|
2018-01-01 19:52:24 -08:00
|
|
|
// 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().
|
2023-09-25 22:09:28 -07:00
|
|
|
g_loadedFile = loadedFile;
|
2022-04-30 23:49:51 +02:00
|
|
|
if (!LoadFile(&loadedFile, &g_CoreParameter.errorString)) {
|
2013-08-10 13:50:21 -07:00
|
|
|
CPU_Shutdown();
|
2022-04-30 23:49:51 +02:00
|
|
|
g_CoreParameter.fileToStart.clear();
|
2020-07-19 20:32:15 +02:00
|
|
|
return false;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
if (g_CoreParameter.updateRecent) {
|
2021-05-06 01:31:38 +02:00
|
|
|
g_Config.AddRecent(filename.ToString());
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
2019-02-11 11:11:56 +01:00
|
|
|
|
|
|
|
|
InstallExceptionHandler(&Memory::HandleFault);
|
2020-07-19 20:32:15 +02:00
|
|
|
return true;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-01 21:27:01 -07:00
|
|
|
PSP_LoadingLock::PSP_LoadingLock() {
|
|
|
|
|
loadingLock.lock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PSP_LoadingLock::~PSP_LoadingLock() {
|
|
|
|
|
loadingLock.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
void CPU_Shutdown() {
|
2019-02-11 11:11:56 +01:00
|
|
|
UninstallExceptionHandler();
|
|
|
|
|
|
2018-11-01 21:27:01 -07:00
|
|
|
// Since we load on a background thread, wait for startup to complete.
|
|
|
|
|
PSP_LoadingLock lock;
|
2019-09-28 11:07:57 -07:00
|
|
|
PSPLoaders_Shutdown();
|
2018-11-01 21:27:01 -07:00
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
if (g_Config.bAutoSaveSymbolMap) {
|
2023-03-24 18:08:31 +01:00
|
|
|
SaveSymbolMapIfSupported();
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
2013-03-30 21:42:43 -07:00
|
|
|
|
2013-12-17 23:40:27 +01:00
|
|
|
Replacement_Shutdown();
|
|
|
|
|
|
2013-08-10 13:50:21 -07:00
|
|
|
CoreTiming::Shutdown();
|
|
|
|
|
__KernelShutdown();
|
|
|
|
|
HLEShutdown();
|
2021-07-24 10:31:15 +02:00
|
|
|
|
2013-08-10 13:50:21 -07:00
|
|
|
pspFileSystem.Shutdown();
|
2014-01-28 11:32:54 +01:00
|
|
|
mipsr4k.Shutdown();
|
2013-01-13 16:46:45 +01:00
|
|
|
Memory::Shutdown();
|
2020-08-25 19:54:51 -07:00
|
|
|
HLEPlugins::Shutdown();
|
2014-11-23 13:25:32 -08:00
|
|
|
|
2023-09-25 22:09:28 -07:00
|
|
|
delete g_loadedFile;
|
|
|
|
|
g_loadedFile = nullptr;
|
2014-11-23 13:59:56 -08:00
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
delete g_CoreParameter.mountIsoLoader;
|
2015-10-31 23:01:19 +01:00
|
|
|
delete g_symbolMap;
|
|
|
|
|
g_symbolMap = nullptr;
|
|
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
g_CoreParameter.mountIsoLoader = nullptr;
|
2014-11-23 13:59:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Maybe loadedFile doesn't even belong here...
|
|
|
|
|
void UpdateLoadedFile(FileLoader *fileLoader) {
|
2023-09-25 22:09:28 -07:00
|
|
|
delete g_loadedFile;
|
|
|
|
|
g_loadedFile = fileLoader;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
void Core_UpdateState(CoreState newState) {
|
|
|
|
|
if ((coreState == CORE_RUNNING || coreState == CORE_NEXTFRAME) && newState != CORE_RUNNING)
|
|
|
|
|
coreStatePending = true;
|
|
|
|
|
coreState = newState;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 11:57:53 +01:00
|
|
|
void Core_UpdateDebugStats(bool collectStats) {
|
2021-09-19 15:17:13 -07:00
|
|
|
bool newState = collectStats || coreCollectDebugStatsCounter > 0;
|
|
|
|
|
if (coreCollectDebugStats != newState) {
|
|
|
|
|
coreCollectDebugStats = newState;
|
2017-03-23 18:57:18 -07:00
|
|
|
mipsr4k.ClearJitCache();
|
|
|
|
|
}
|
2017-04-02 14:49:18 -07:00
|
|
|
|
2022-01-30 10:47:10 -08:00
|
|
|
if (!PSP_CoreParameter().frozen && !Core_IsStepping()) {
|
|
|
|
|
kernelStats.ResetFrame();
|
|
|
|
|
gpuStats.ResetFrame();
|
|
|
|
|
}
|
2017-03-23 18:57:18 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-19 15:17:13 -07:00
|
|
|
void Core_ForceDebugStats(bool enable) {
|
|
|
|
|
if (enable) {
|
|
|
|
|
coreCollectDebugStatsCounter++;
|
|
|
|
|
} else {
|
|
|
|
|
coreCollectDebugStatsCounter--;
|
|
|
|
|
}
|
|
|
|
|
_assert_(coreCollectDebugStatsCounter >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-19 14:17:34 -08:00
|
|
|
bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) {
|
2017-11-05 19:34:48 +01:00
|
|
|
if (pspIsIniting || pspIsQuitting) {
|
2014-01-19 14:17:34 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-12-29 18:09:28 -08:00
|
|
|
|
2023-07-23 23:40:53 +02:00
|
|
|
if (!Achievements::IsReadyToStart()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 21:49:21 -08:00
|
|
|
#if defined(_WIN32) && PPSSPP_ARCH(AMD64)
|
2024-07-14 14:42:59 +02:00
|
|
|
NOTICE_LOG(Log::Boot, "PPSSPP %s Windows 64 bit", PPSSPP_GIT_VERSION);
|
2021-03-02 21:49:21 -08:00
|
|
|
#elif defined(_WIN32) && !PPSSPP_ARCH(AMD64)
|
2024-07-14 14:42:59 +02:00
|
|
|
NOTICE_LOG(Log::Boot, "PPSSPP %s Windows 32 bit", PPSSPP_GIT_VERSION);
|
2017-03-16 15:31:27 +01:00
|
|
|
#else
|
2024-07-14 14:42:59 +02:00
|
|
|
NOTICE_LOG(Log::Boot, "PPSSPP %s", PPSSPP_GIT_VERSION);
|
2014-01-15 22:02:47 +08:00
|
|
|
#endif
|
2016-08-27 14:38:05 -04:00
|
|
|
|
2018-04-22 08:33:22 -07:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STARTING);
|
2022-04-30 23:49:51 +02:00
|
|
|
GraphicsContext *temp = g_CoreParameter.graphicsContext;
|
|
|
|
|
g_CoreParameter = coreParam;
|
|
|
|
|
if (g_CoreParameter.graphicsContext == nullptr) {
|
|
|
|
|
g_CoreParameter.graphicsContext = temp;
|
2016-03-13 10:38:38 -07:00
|
|
|
}
|
2022-09-30 12:26:30 +03:00
|
|
|
g_CoreParameter.errorString.clear();
|
2014-01-19 14:17:34 -08:00
|
|
|
pspIsIniting = true;
|
2018-03-12 18:06:46 -07:00
|
|
|
PSP_SetLoading("Loading game...");
|
2013-08-07 08:07:13 -07:00
|
|
|
|
2023-07-12 01:11:09 +02:00
|
|
|
Path filename = g_CoreParameter.fileToStart;
|
|
|
|
|
FileLoader *loadedFile = ResolveFileLoaderTarget(ConstructFileLoader(filename));
|
|
|
|
|
#if PPSSPP_ARCH(AMD64)
|
|
|
|
|
if (g_Config.bCacheFullIsoInRam) {
|
|
|
|
|
loadedFile = new RamCachingFileLoader(loadedFile);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-09-06 11:19:13 +02:00
|
|
|
if (g_Config.bAchievementsEnable) {
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
2023-07-12 01:11:09 +02:00
|
|
|
|
|
|
|
|
if (!CPU_Init(&g_CoreParameter.errorString, loadedFile)) {
|
2022-04-30 23:49:51 +02:00
|
|
|
*error_string = g_CoreParameter.errorString;
|
2021-04-06 07:04:25 -07:00
|
|
|
if (error_string->empty()) {
|
|
|
|
|
*error_string = "Failed initializing CPU/Memory";
|
|
|
|
|
}
|
2021-02-04 21:41:40 -08:00
|
|
|
pspIsIniting = false;
|
2020-07-19 20:32:15 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-08-07 08:07:13 -07:00
|
|
|
|
2019-10-22 21:38:14 +02:00
|
|
|
// Compat flags get loaded in CPU_Init (which is a bit of a misnomer) so we check for SW renderer here.
|
|
|
|
|
if (g_Config.bSoftwareRendering || PSP_CoreParameter().compat.flags().ForceSoftwareRenderer) {
|
2022-04-30 23:49:51 +02:00
|
|
|
g_CoreParameter.gpuCore = GPUCORE_SOFTWARE;
|
2019-10-22 21:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
*error_string = g_CoreParameter.errorString;
|
|
|
|
|
bool success = !g_CoreParameter.fileToStart.empty();
|
2014-02-28 09:58:10 -08:00
|
|
|
if (!success) {
|
2018-04-22 08:33:22 -07:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
2022-10-01 18:13:22 -07:00
|
|
|
pspIsRebooting = false;
|
2022-08-12 22:30:15 -07:00
|
|
|
// In this case, we must call shutdown since the caller won't know to.
|
|
|
|
|
// It must've partially started since CPU_Init returned true.
|
|
|
|
|
PSP_Shutdown();
|
2014-02-28 09:58:10 -08:00
|
|
|
}
|
|
|
|
|
return success;
|
2014-01-19 14:17:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PSP_InitUpdate(std::string *error_string) {
|
|
|
|
|
if (pspIsInited || !pspIsIniting) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 19:34:48 +01:00
|
|
|
if (!CPU_IsReady()) {
|
2014-01-19 14:17:34 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 23:49:51 +02:00
|
|
|
bool success = !g_CoreParameter.fileToStart.empty();
|
2023-07-24 12:08:15 +02:00
|
|
|
if (!g_CoreParameter.errorString.empty()) {
|
|
|
|
|
*error_string = g_CoreParameter.errorString;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-03 10:54:38 -08:00
|
|
|
if (success && gpu == nullptr) {
|
2018-03-12 18:06:46 -07:00
|
|
|
PSP_SetLoading("Starting graphics...");
|
2022-04-30 23:49:51 +02:00
|
|
|
Draw::DrawContext *draw = g_CoreParameter.graphicsContext ? g_CoreParameter.graphicsContext->GetDrawContext() : nullptr;
|
|
|
|
|
success = GPU_Init(g_CoreParameter.graphicsContext, draw);
|
2013-09-07 22:30:30 -07:00
|
|
|
if (!success) {
|
|
|
|
|
*error_string = "Unable to initialize rendering engine.";
|
|
|
|
|
}
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
2018-05-20 14:15:09 -07:00
|
|
|
if (!success) {
|
2022-10-01 18:13:22 -07:00
|
|
|
pspIsRebooting = false;
|
2018-05-20 14:15:09 -07:00
|
|
|
PSP_Shutdown();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pspIsInited = GPU_IsReady();
|
|
|
|
|
pspIsIniting = !pspIsInited;
|
2018-04-22 08:33:22 -07:00
|
|
|
if (pspIsInited) {
|
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
2022-10-01 18:13:22 -07:00
|
|
|
pspIsRebooting = false;
|
2023-01-01 06:59:14 -08:00
|
|
|
|
|
|
|
|
// If GPU init failed during IsReady checks, bail.
|
|
|
|
|
if (!GPU_IsStarted()) {
|
|
|
|
|
*error_string = "Unable to initialize rendering engine.";
|
|
|
|
|
pspIsRebooting = false;
|
|
|
|
|
PSP_Shutdown();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-22 08:33:22 -07:00
|
|
|
}
|
2018-05-20 14:15:09 -07:00
|
|
|
return pspIsInited;
|
2014-01-19 14:17:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) {
|
2024-10-24 00:58:13 +02:00
|
|
|
// Spawn a lua instance
|
|
|
|
|
|
2021-05-30 21:12:30 -07:00
|
|
|
if (!PSP_InitStart(coreParam, error_string))
|
|
|
|
|
return false;
|
2014-01-19 14:17:34 -08:00
|
|
|
|
2018-01-04 18:10:41 +01:00
|
|
|
while (!PSP_InitUpdate(error_string))
|
|
|
|
|
sleep_ms(10);
|
2014-02-17 10:57:47 -08:00
|
|
|
return pspIsInited;
|
2014-01-19 14:17:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PSP_IsIniting() {
|
|
|
|
|
return pspIsIniting;
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PSP_IsInited() {
|
2022-10-01 18:13:22 -07:00
|
|
|
return pspIsInited && !pspIsQuitting && !pspIsRebooting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PSP_IsRebooting() {
|
|
|
|
|
return pspIsRebooting;
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
|
|
|
|
|
2018-04-21 18:26:36 -07:00
|
|
|
bool PSP_IsQuitting() {
|
|
|
|
|
return pspIsQuitting;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 08:07:13 -07:00
|
|
|
void PSP_Shutdown() {
|
2024-10-29 11:19:32 +01:00
|
|
|
// Reduce the risk for weird races with the Windows GE debugger.
|
|
|
|
|
gpuDebug = nullptr;
|
|
|
|
|
|
2023-07-16 09:10:39 +02:00
|
|
|
Achievements::UnloadGame();
|
|
|
|
|
|
2014-02-14 21:53:59 -08:00
|
|
|
// Do nothing if we never inited.
|
2017-11-05 19:34:48 +01:00
|
|
|
if (!pspIsInited && !pspIsIniting && !pspIsQuitting) {
|
2014-02-14 21:53:59 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 08:33:22 -07:00
|
|
|
// Make sure things know right away that PSP memory, etc. is going away.
|
2022-10-01 18:13:22 -07:00
|
|
|
pspIsQuitting = !pspIsRebooting;
|
2018-04-22 08:33:22 -07:00
|
|
|
if (coreState == CORE_RUNNING)
|
2021-01-07 23:14:54 -08:00
|
|
|
Core_Stop();
|
2018-04-22 08:33:22 -07:00
|
|
|
|
2013-12-17 12:30:56 +01:00
|
|
|
if (g_Config.bFuncHashMap) {
|
|
|
|
|
MIPSAnalyst::StoreHashMap();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 08:33:22 -07:00
|
|
|
if (pspIsIniting)
|
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STOPPING);
|
2017-12-15 12:40:38 +01:00
|
|
|
CPU_Shutdown();
|
2013-08-07 08:07:13 -07:00
|
|
|
GPU_Shutdown();
|
2014-12-20 08:29:56 -08:00
|
|
|
g_paramSFO.Clear();
|
2023-03-24 17:40:03 +01:00
|
|
|
System_SetWindowTitle("");
|
2013-12-30 00:11:29 +01:00
|
|
|
currentMIPS = 0;
|
2013-12-29 18:09:28 -08:00
|
|
|
pspIsInited = false;
|
2014-01-19 14:17:34 -08:00
|
|
|
pspIsIniting = false;
|
2017-11-05 19:34:48 +01:00
|
|
|
pspIsQuitting = false;
|
2014-12-19 14:52:44 +01:00
|
|
|
g_Config.unloadGameConfig();
|
2018-04-22 08:33:22 -07:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STOPPED);
|
2013-08-07 08:07:13 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-01 18:13:22 -07:00
|
|
|
bool PSP_Reboot(std::string *error_string) {
|
|
|
|
|
if (!pspIsInited || pspIsQuitting)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
pspIsRebooting = true;
|
|
|
|
|
Core_Stop();
|
|
|
|
|
Core_WaitInactive();
|
|
|
|
|
PSP_Shutdown();
|
|
|
|
|
std::string resetError;
|
|
|
|
|
return PSP_Init(PSP_CoreParameter(), error_string);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 23:49:02 +01:00
|
|
|
void PSP_BeginHostFrame() {
|
2016-01-06 23:53:21 +01:00
|
|
|
if (gpu) {
|
|
|
|
|
gpu->BeginHostFrame();
|
|
|
|
|
}
|
2016-01-06 23:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PSP_EndHostFrame() {
|
2016-01-06 23:53:21 +01:00
|
|
|
if (gpu) {
|
|
|
|
|
gpu->EndHostFrame();
|
|
|
|
|
}
|
2021-02-21 08:18:13 -08:00
|
|
|
SaveState::Cleanup();
|
2016-01-06 23:49:02 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-29 18:38:17 -07:00
|
|
|
void PSP_RunLoopWhileState() {
|
|
|
|
|
// We just run the CPU until we get to vblank. This will quickly sync up pretty nicely.
|
|
|
|
|
// The actual number of cycles doesn't matter so much here as we will break due to CORE_NEXTFRAME, most of the time hopefully...
|
|
|
|
|
int blockTicks = usToCycles(1000000 / 10);
|
|
|
|
|
|
|
|
|
|
// Run until CORE_NEXTFRAME
|
|
|
|
|
while (coreState == CORE_RUNNING || coreState == CORE_STEPPING) {
|
|
|
|
|
PSP_RunLoopFor(blockTicks);
|
2018-06-23 10:58:30 -07:00
|
|
|
if (coreState == CORE_STEPPING) {
|
|
|
|
|
// Keep the UI responsive.
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-29 18:38:17 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-04 15:22:30 -07:00
|
|
|
void PSP_RunLoopUntil(u64 globalticks) {
|
2020-07-04 20:19:56 +02:00
|
|
|
if (coreState == CORE_POWERDOWN || coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR) {
|
2013-09-14 21:19:10 -07:00
|
|
|
return;
|
2018-04-29 18:38:17 -07:00
|
|
|
} else if (coreState == CORE_STEPPING) {
|
2024-11-03 20:49:20 +01:00
|
|
|
Core_ProcessStepping(currentDebugMIPS);
|
2018-04-29 18:38:17 -07:00
|
|
|
return;
|
2013-09-14 21:19:10 -07:00
|
|
|
}
|
2013-08-07 08:07:13 -07:00
|
|
|
|
2024-07-20 00:46:13 +02:00
|
|
|
if (coreState != CORE_NEXTFRAME) { // Can be set by SaveState as well as by sceDisplay
|
|
|
|
|
mipsr4k.RunLoopUntil(globalticks);
|
|
|
|
|
}
|
2013-08-04 15:22:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PSP_RunLoopFor(int cycles) {
|
|
|
|
|
PSP_RunLoopUntil(CoreTiming::GetTicks() + cycles);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 18:06:46 -07:00
|
|
|
void PSP_SetLoading(const std::string &reason) {
|
|
|
|
|
std::lock_guard<std::mutex> guard(loadingReasonLock);
|
|
|
|
|
loadingReason = reason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string PSP_GetLoading() {
|
|
|
|
|
std::lock_guard<std::mutex> guard(loadingReasonLock);
|
|
|
|
|
return loadingReason;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
Path GetSysDirectory(PSPDirectories directoryType) {
|
2021-12-16 11:37:05 -08:00
|
|
|
const Path &memStickDirectory = g_Config.memStickDirectory;
|
2021-05-29 22:55:43 +02:00
|
|
|
Path pspDirectory;
|
2021-12-16 11:37:05 -08:00
|
|
|
if (!strcasecmp(memStickDirectory.GetFilename().c_str(), "PSP")) {
|
2021-05-29 22:55:43 +02:00
|
|
|
// Let's strip this off, to easily allow choosing a root directory named "PSP" on Android.
|
|
|
|
|
pspDirectory = memStickDirectory;
|
|
|
|
|
} else {
|
|
|
|
|
pspDirectory = memStickDirectory / "PSP";
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-15 02:03:39 -04:00
|
|
|
switch (directoryType) {
|
2021-07-24 18:16:12 +02:00
|
|
|
case DIRECTORY_PSP:
|
|
|
|
|
return pspDirectory;
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_CHEATS:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "Cheats";
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_GAME:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "GAME";
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_SAVEDATA:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SAVEDATA";
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_SCREENSHOT:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SCREENSHOT";
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_SYSTEM:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SYSTEM";
|
2013-10-15 02:03:39 -04:00
|
|
|
case DIRECTORY_PAUTH:
|
2021-05-29 22:55:43 +02:00
|
|
|
return memStickDirectory / "PAUTH"; // This one's at the root...
|
2021-07-18 22:28:59 +02:00
|
|
|
case DIRECTORY_EXDATA:
|
|
|
|
|
return memStickDirectory / "EXDATA"; // This one's traditionally at the root...
|
2014-02-27 01:19:32 -05:00
|
|
|
case DIRECTORY_DUMP:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SYSTEM/DUMP";
|
2015-06-11 23:59:02 +02:00
|
|
|
case DIRECTORY_SAVESTATE:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "PPSSPP_STATE";
|
2015-06-27 18:32:21 -07:00
|
|
|
case DIRECTORY_CACHE:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SYSTEM/CACHE";
|
2016-04-30 14:05:03 -07:00
|
|
|
case DIRECTORY_TEXTURES:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "TEXTURES";
|
2020-08-25 19:54:51 -07:00
|
|
|
case DIRECTORY_PLUGINS:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "PLUGINS";
|
2016-01-17 22:11:28 +01:00
|
|
|
case DIRECTORY_APP_CACHE:
|
|
|
|
|
if (!g_Config.appCacheDirectory.empty()) {
|
2021-05-15 09:32:41 -07:00
|
|
|
return g_Config.appCacheDirectory;
|
2016-01-17 22:11:28 +01:00
|
|
|
}
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "SYSTEM/CACHE";
|
2016-09-03 18:26:01 -04:00
|
|
|
case DIRECTORY_VIDEO:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "VIDEO";
|
2016-09-03 18:26:01 -04:00
|
|
|
case DIRECTORY_AUDIO:
|
2021-05-29 22:55:43 +02:00
|
|
|
return pspDirectory / "AUDIO";
|
2021-07-18 22:28:59 +02:00
|
|
|
case DIRECTORY_CUSTOM_SHADERS:
|
|
|
|
|
return pspDirectory / "shaders";
|
2022-02-11 12:32:23 +01:00
|
|
|
case DIRECTORY_CUSTOM_THEMES:
|
|
|
|
|
return pspDirectory / "themes";
|
2021-07-18 22:28:59 +02:00
|
|
|
|
2020-12-16 00:06:39 +01:00
|
|
|
case DIRECTORY_MEMSTICK_ROOT:
|
|
|
|
|
return g_Config.memStickDirectory;
|
2013-10-15 02:03:39 -04:00
|
|
|
// Just return the memory stick root if we run into some sort of problem.
|
|
|
|
|
default:
|
2024-07-14 14:42:59 +02:00
|
|
|
ERROR_LOG(Log::FileSystem, "Unknown directory type.");
|
2014-10-19 23:20:51 +02:00
|
|
|
return g_Config.memStickDirectory;
|
2013-10-15 02:03:39 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-28 20:17:45 +01:00
|
|
|
|
2023-08-18 12:56:38 +02:00
|
|
|
bool CreateSysDirectories() {
|
|
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
|
const bool createNoMedia = true;
|
|
|
|
|
#else
|
|
|
|
|
const bool createNoMedia = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Path pspDir = GetSysDirectory(DIRECTORY_PSP);
|
2024-07-14 14:42:59 +02:00
|
|
|
INFO_LOG(Log::IO, "Creating '%s' and subdirs:", pspDir.c_str());
|
2023-08-18 12:56:38 +02:00
|
|
|
File::CreateDir(pspDir);
|
|
|
|
|
if (!File::Exists(pspDir)) {
|
2024-07-14 14:42:59 +02:00
|
|
|
INFO_LOG(Log::IO, "Not a workable memstick directory. Giving up");
|
2023-08-18 12:56:38 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 14:46:44 +01:00
|
|
|
// Create the default directories that a real PSP creates. Good for homebrew so they can
|
|
|
|
|
// expect a standard environment. Skipping THEME though, that's pointless.
|
2023-08-18 12:56:38 +02:00
|
|
|
static const PSPDirectories sysDirs[] = {
|
|
|
|
|
DIRECTORY_CHEATS,
|
|
|
|
|
DIRECTORY_SAVEDATA,
|
|
|
|
|
DIRECTORY_SAVESTATE,
|
|
|
|
|
DIRECTORY_GAME,
|
|
|
|
|
DIRECTORY_SYSTEM,
|
|
|
|
|
DIRECTORY_TEXTURES,
|
|
|
|
|
DIRECTORY_PLUGINS,
|
|
|
|
|
DIRECTORY_CACHE,
|
|
|
|
|
};
|
2017-02-20 14:46:44 +01:00
|
|
|
|
2023-08-18 12:56:38 +02:00
|
|
|
for (auto dir : sysDirs) {
|
|
|
|
|
Path path = GetSysDirectory(dir);
|
|
|
|
|
File::CreateFullPath(path);
|
|
|
|
|
if (createNoMedia) {
|
|
|
|
|
// Create a nomedia file in each specified subdirectory.
|
|
|
|
|
File::CreateEmptyFile(path / ".nomedia");
|
|
|
|
|
}
|
2013-10-15 02:03:39 -04:00
|
|
|
}
|
2023-08-18 12:56:38 +02:00
|
|
|
return true;
|
2013-03-28 20:17:45 +01:00
|
|
|
}
|