2012-11-01 15:19:01 +00: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 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00: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 17:59:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
2013-08-17 13:12:42 +00:00
|
|
|
#ifdef _WIN32
|
2015-09-23 17:29:39 +00:00
|
|
|
#pragma warning(disable:4091)
|
2013-07-29 03:43:25 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
2013-10-13 20:45:13 +00:00
|
|
|
#include <ShlObj.h>
|
2013-10-13 21:17:48 +00:00
|
|
|
#include <string>
|
2013-10-14 06:22:13 +00:00
|
|
|
#include <codecvt>
|
2013-03-28 19:17:45 +00:00
|
|
|
#endif
|
2017-12-20 09:22:15 +00:00
|
|
|
|
2017-02-27 19:51:36 +00:00
|
|
|
#include <thread>
|
2017-02-27 20:57:46 +00:00
|
|
|
#include <mutex>
|
2017-12-20 09:22:15 +00:00
|
|
|
#include <condition_variable>
|
2013-03-28 19:17:45 +00:00
|
|
|
|
2018-01-04 17:10:41 +00:00
|
|
|
#include "base/timeutil.h"
|
2018-05-08 21:05:09 +00:00
|
|
|
#include "base/NativeApp.h"
|
2014-03-23 09:05:11 +00:00
|
|
|
#include "math/math_util.h"
|
2015-09-06 19:19:33 +00:00
|
|
|
#include "thread/threadutil.h"
|
2013-08-26 17:00:16 +00:00
|
|
|
#include "util/text/utf8.h"
|
2013-08-09 06:30:45 +00:00
|
|
|
|
2019-09-29 04:36:03 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-07-29 15:12:46 +00:00
|
|
|
#include "Core/MemMap.h"
|
2014-03-15 17:38:46 +00:00
|
|
|
#include "Core/HDRemaster.h"
|
2013-07-29 15:12:46 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-11-30 19:57:44 +00:00
|
|
|
#include "Core/MIPS/MIPSAnalyst.h"
|
2019-09-29 04:36:03 +00:00
|
|
|
#include "Core/Debugger/SymbolMap.h"
|
2013-12-29 22:44:35 +00:00
|
|
|
#include "Core/Host.h"
|
2013-07-29 15:12:46 +00:00
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/HLE/HLE.h"
|
2013-12-17 22:40:27 +00:00
|
|
|
#include "Core/HLE/ReplaceTables.h"
|
2013-07-29 15:12:46 +00: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 23:23:25 +00:00
|
|
|
#include "Core/FileLoaders/RamCachingFileLoader.h"
|
2013-07-29 15:12:46 +00:00
|
|
|
#include "Core/FileSystems/MetaFileSystem.h"
|
|
|
|
#include "Core/Loaders.h"
|
|
|
|
#include "Core/PSPLoaders.h"
|
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2013-08-07 06:00:20 +00:00
|
|
|
#include "Core/SaveState.h"
|
2013-07-29 15:12:46 +00:00
|
|
|
#include "Common/LogManager.h"
|
2014-03-23 18:45:08 +00:00
|
|
|
#include "Core/HLE/sceAudiocodec.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/GPUInterface.h"
|
|
|
|
|
|
|
|
enum CPUThreadState {
|
|
|
|
CPU_THREAD_NOT_RUNNING,
|
|
|
|
CPU_THREAD_PENDING,
|
|
|
|
CPU_THREAD_STARTING,
|
|
|
|
CPU_THREAD_RUNNING,
|
|
|
|
CPU_THREAD_SHUTDOWN,
|
2014-12-21 00:11:19 +00:00
|
|
|
CPU_THREAD_QUIT,
|
2013-08-07 15:07:13 +00:00
|
|
|
|
|
|
|
CPU_THREAD_EXECUTE,
|
2014-12-21 00:11:19 +00:00
|
|
|
CPU_THREAD_RESUME,
|
2013-08-07 15:07:13 +00:00
|
|
|
};
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
MetaFileSystem pspFileSystem;
|
2013-01-02 20:00:10 +00:00
|
|
|
ParamSFOData g_paramSFO;
|
2014-06-22 07:38:46 +00:00
|
|
|
static GlobalUIState globalUIState;
|
2012-11-01 15:19:01 +00:00
|
|
|
static CoreParameter coreParameter;
|
2014-11-23 21:25:32 +00:00
|
|
|
static FileLoader *loadedFile;
|
2018-11-02 04:27:01 +00:00
|
|
|
// For background loading thread.
|
|
|
|
static std::mutex loadingLock;
|
|
|
|
// For loadingReason updates.
|
2018-03-13 01:06:46 +00:00
|
|
|
static std::mutex loadingReasonLock;
|
|
|
|
static std::string loadingReason;
|
2017-12-15 11:40:38 +00:00
|
|
|
|
2015-01-11 11:02:49 +00:00
|
|
|
bool audioInitialized;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-03-24 01:57:18 +00:00
|
|
|
bool coreCollectDebugStats = false;
|
|
|
|
bool coreCollectDebugStatsForced = false;
|
|
|
|
|
2013-03-29 19:51:14 +00:00
|
|
|
// This can be read and written from ANYWHERE.
|
|
|
|
volatile CoreState coreState = CORE_STEPPING;
|
|
|
|
// Note: intentionally not used for CORE_NEXTFRAME.
|
|
|
|
volatile bool coreStatePending = false;
|
2013-08-07 15:07:13 +00:00
|
|
|
static volatile CPUThreadState cpuThreadState = CPU_THREAD_NOT_RUNNING;
|
|
|
|
|
2016-01-06 06:37:28 +00:00
|
|
|
static GPUBackend gpuBackend;
|
2018-09-30 07:53:21 +00:00
|
|
|
static std::string gpuBackendDevice;
|
2016-01-06 06:37:28 +00:00
|
|
|
|
2017-04-15 23:33:30 +00:00
|
|
|
void ResetUIState() {
|
|
|
|
globalUIState = UISTATE_MENU;
|
|
|
|
}
|
|
|
|
|
2013-12-29 22:44:35 +00:00
|
|
|
void UpdateUIState(GlobalUIState newState) {
|
|
|
|
// Never leave the EXIT state.
|
|
|
|
if (globalUIState != newState && globalUIState != UISTATE_EXIT) {
|
|
|
|
globalUIState = newState;
|
|
|
|
host->UpdateDisassembly();
|
2018-05-08 21:05:09 +00:00
|
|
|
const char *state = nullptr;
|
|
|
|
switch (globalUIState) {
|
|
|
|
case UISTATE_EXIT: state = "exit"; break;
|
|
|
|
case UISTATE_INGAME: state = "ingame"; break;
|
|
|
|
case UISTATE_MENU: state = "menu"; break;
|
|
|
|
case UISTATE_PAUSEMENU: state = "pausemenu"; break;
|
|
|
|
}
|
|
|
|
if (state) {
|
|
|
|
System_SendMessage("uistate", state);
|
|
|
|
}
|
2013-12-29 22:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-22 07:38:46 +00:00
|
|
|
GlobalUIState GetUIState() {
|
|
|
|
return globalUIState;
|
|
|
|
}
|
|
|
|
|
2018-09-30 07:53:21 +00:00
|
|
|
void SetGPUBackend(GPUBackend type, const std::string &device) {
|
2016-01-06 06:37:28 +00:00
|
|
|
gpuBackend = type;
|
2018-09-30 07:53:21 +00:00
|
|
|
gpuBackendDevice = device;
|
2016-01-06 06:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GPUBackend GetGPUBackend() {
|
|
|
|
return gpuBackend;
|
|
|
|
}
|
|
|
|
|
2018-09-30 07:53:21 +00:00
|
|
|
std::string GetGPUBackendDevice() {
|
|
|
|
return gpuBackendDevice;
|
|
|
|
}
|
|
|
|
|
2013-08-14 12:44:36 +00:00
|
|
|
bool IsAudioInitialised() {
|
2015-01-11 11:02:49 +00:00
|
|
|
return audioInitialized;
|
2013-08-14 12:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Audio_Init() {
|
2015-01-11 11:02:49 +00:00
|
|
|
if (!audioInitialized) {
|
|
|
|
audioInitialized = true;
|
|
|
|
host->InitSound();
|
2013-08-14 12:44:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-31 04:17:29 +00:00
|
|
|
void Audio_Shutdown() {
|
|
|
|
if (audioInitialized) {
|
|
|
|
audioInitialized = false;
|
|
|
|
host->ShutdownSound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
bool CPU_IsReady() {
|
2018-01-02 03:52:24 +00:00
|
|
|
if (coreState == CORE_POWERUP)
|
|
|
|
return false;
|
2013-08-07 15:07:13 +00:00
|
|
|
return cpuThreadState == CPU_THREAD_RUNNING || cpuThreadState == CPU_THREAD_NOT_RUNNING;
|
|
|
|
}
|
2013-03-02 20:34:41 +00:00
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
bool CPU_IsShutdown() {
|
|
|
|
return cpuThreadState == CPU_THREAD_NOT_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPU_HasPendingAction() {
|
|
|
|
return cpuThreadState != CPU_THREAD_RUNNING;
|
|
|
|
}
|
|
|
|
|
2013-08-10 20:50:21 +00:00
|
|
|
void CPU_Shutdown();
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
void CPU_Init() {
|
2013-11-10 04:56:11 +00:00
|
|
|
coreState = CORE_POWERUP;
|
2013-12-29 23:11:29 +00:00
|
|
|
currentMIPS = &mipsr4k;
|
2016-08-27 18:38:05 +00:00
|
|
|
|
2015-10-31 22:01:19 +00:00
|
|
|
g_symbolMap = new SymbolMap();
|
2013-06-22 09:14:01 +00:00
|
|
|
|
2013-06-23 04:17:33 +00:00
|
|
|
// Default memory settings
|
|
|
|
// Seems to be the safest place currently..
|
2015-12-23 23:10:08 +00:00
|
|
|
Memory::g_MemorySize = Memory::RAM_NORMAL_SIZE; // 32 MB of ram by default
|
2013-11-28 19:37:10 +00:00
|
|
|
|
2013-06-23 04:17:33 +00:00
|
|
|
g_RemasterMode = false;
|
|
|
|
g_DoubleTextureCoordinates = false;
|
2013-11-28 20:34:11 +00:00
|
|
|
Memory::g_PSPModel = g_Config.iPSPModel;
|
2013-06-23 04:17:33 +00:00
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
std::string filename = coreParameter.fileToStart;
|
2015-12-28 03:25:28 +00:00
|
|
|
loadedFile = ResolveFileLoaderTarget(ConstructFileLoader(filename));
|
2015-12-19 23:23:25 +00:00
|
|
|
#ifdef _M_X64
|
|
|
|
if (g_Config.bCacheFullIsoInRam) {
|
|
|
|
loadedFile = new RamCachingFileLoader(loadedFile);
|
|
|
|
}
|
|
|
|
#endif
|
2014-11-23 21:25:32 +00:00
|
|
|
IdentifiedFileType type = Identify_File(loadedFile);
|
2013-06-22 09:14:01 +00:00
|
|
|
|
2014-11-23 21:59:56 +00:00
|
|
|
// TODO: Put this somewhere better?
|
|
|
|
if (coreParameter.mountIso != "") {
|
2014-11-23 22:02:35 +00:00
|
|
|
coreParameter.mountIsoLoader = ConstructFileLoader(coreParameter.mountIso);
|
2014-11-23 21:59:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-30 19:57:44 +00:00
|
|
|
MIPSAnalyst::Reset();
|
2013-12-17 22:40:27 +00:00
|
|
|
Replacement_Init();
|
2013-11-30 19:57:44 +00:00
|
|
|
|
2013-08-10 17:56:47 +00:00
|
|
|
switch (type) {
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_ISO:
|
|
|
|
case IdentifiedFileType::PSP_ISO_NP:
|
|
|
|
case IdentifiedFileType::PSP_DISC_DIRECTORY:
|
2014-11-23 21:25:32 +00:00
|
|
|
InitMemoryForGameISO(loadedFile);
|
2013-08-10 17:56:47 +00:00
|
|
|
break;
|
2017-03-02 11:29:03 +00:00
|
|
|
case IdentifiedFileType::PSP_PBP:
|
|
|
|
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
2016-03-09 16:02:53 +00:00
|
|
|
// This is normal for homebrew.
|
|
|
|
// ERROR_LOG(LOADER, "PBP directory resolution failed.");
|
2017-05-24 16:12:35 +00:00
|
|
|
InitMemoryForGamePBP(loadedFile);
|
2016-03-09 16:02:53 +00:00
|
|
|
break;
|
2013-08-10 17:56:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
2013-06-22 09:14:01 +00:00
|
|
|
|
2015-09-26 14:01:16 +00:00
|
|
|
// Here we have read the PARAM.SFO, let's see if we need any compatibility overrides.
|
2015-09-26 21:39:04 +00: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.
|
2017-06-03 03:54:28 +00:00
|
|
|
std::string discID = g_paramSFO.GetDiscID();
|
2017-05-26 21:15:04 +00:00
|
|
|
coreParameter.compat.Load(discID);
|
2015-09-26 14:01:16 +00:00
|
|
|
|
2013-06-22 09:14:01 +00:00
|
|
|
Memory::Init();
|
2012-11-01 15:19:01 +00:00
|
|
|
mipsr4k.Reset();
|
|
|
|
|
2013-03-31 04:42:43 +00:00
|
|
|
host->AttemptLoadSymbolMap();
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
if (coreParameter.enableSound) {
|
2013-08-14 12:44:36 +00:00
|
|
|
Audio_Init();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 09:12:40 +00:00
|
|
|
CoreTiming::Init();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// Init all the HLE modules
|
|
|
|
HLEInit();
|
|
|
|
|
|
|
|
// TODO: Check Game INI here for settings, patches and cheats, and modify coreParameter accordingly
|
|
|
|
|
2018-01-02 03:52:24 +00: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().
|
2014-11-23 22:08:14 +00:00
|
|
|
if (!LoadFile(&loadedFile, &coreParameter.errorString)) {
|
2013-08-10 20:50:21 +00:00
|
|
|
CPU_Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
coreParameter.fileToStart = "";
|
2013-08-07 15:07:13 +00:00
|
|
|
return;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 15:21:25 +00:00
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
if (coreParameter.updateRecent) {
|
2013-06-08 15:48:41 +00:00
|
|
|
g_Config.AddRecent(filename);
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 04:27:01 +00:00
|
|
|
PSP_LoadingLock::PSP_LoadingLock() {
|
|
|
|
loadingLock.lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
PSP_LoadingLock::~PSP_LoadingLock() {
|
|
|
|
loadingLock.unlock();
|
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
void CPU_Shutdown() {
|
2018-11-02 04:27:01 +00:00
|
|
|
// Since we load on a background thread, wait for startup to complete.
|
|
|
|
PSP_LoadingLock lock;
|
2019-09-28 18:07:57 +00:00
|
|
|
PSPLoaders_Shutdown();
|
2018-11-02 04:27:01 +00:00
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
if (g_Config.bAutoSaveSymbolMap) {
|
2013-03-31 04:42:43 +00:00
|
|
|
host->SaveSymbolMap();
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
2013-03-31 04:42:43 +00:00
|
|
|
|
2013-12-17 22:40:27 +00:00
|
|
|
Replacement_Shutdown();
|
|
|
|
|
2013-08-10 20:50:21 +00:00
|
|
|
CoreTiming::Shutdown();
|
|
|
|
__KernelShutdown();
|
|
|
|
HLEShutdown();
|
2013-08-07 15:07:13 +00:00
|
|
|
if (coreParameter.enableSound) {
|
2017-12-31 04:17:29 +00:00
|
|
|
Audio_Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-08-10 20:50:21 +00:00
|
|
|
pspFileSystem.Shutdown();
|
2014-01-28 10:32:54 +00:00
|
|
|
mipsr4k.Shutdown();
|
2013-01-13 15:46:45 +00:00
|
|
|
Memory::Shutdown();
|
2014-11-23 21:25:32 +00:00
|
|
|
|
|
|
|
delete loadedFile;
|
2014-11-23 21:59:56 +00:00
|
|
|
loadedFile = nullptr;
|
|
|
|
|
|
|
|
delete coreParameter.mountIsoLoader;
|
2015-10-31 22:01:19 +00:00
|
|
|
delete g_symbolMap;
|
|
|
|
g_symbolMap = nullptr;
|
|
|
|
|
2014-11-23 21:59:56 +00:00
|
|
|
coreParameter.mountIsoLoader = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Maybe loadedFile doesn't even belong here...
|
|
|
|
void UpdateLoadedFile(FileLoader *fileLoader) {
|
|
|
|
delete loadedFile;
|
|
|
|
loadedFile = fileLoader;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
void Core_UpdateState(CoreState newState) {
|
|
|
|
if ((coreState == CORE_RUNNING || coreState == CORE_NEXTFRAME) && newState != CORE_RUNNING)
|
|
|
|
coreStatePending = true;
|
|
|
|
coreState = newState;
|
2013-09-15 01:43:23 +00:00
|
|
|
Core_UpdateSingleStep();
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 10:57:53 +00:00
|
|
|
void Core_UpdateDebugStats(bool collectStats) {
|
|
|
|
if (coreCollectDebugStats != collectStats) {
|
|
|
|
coreCollectDebugStats = collectStats;
|
2017-03-24 01:57:18 +00:00
|
|
|
mipsr4k.ClearJitCache();
|
|
|
|
}
|
2017-04-02 21:49:18 +00:00
|
|
|
|
|
|
|
kernelStats.ResetFrame();
|
|
|
|
gpuStats.ResetFrame();
|
2017-03-24 01:57:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 14:21:08 +00:00
|
|
|
// Ugly!
|
2013-12-30 02:09:28 +00:00
|
|
|
static bool pspIsInited = false;
|
2014-01-19 22:17:34 +00:00
|
|
|
static bool pspIsIniting = false;
|
2017-11-05 18:34:48 +00:00
|
|
|
static bool pspIsQuitting = false;
|
2014-01-19 22:17:34 +00:00
|
|
|
|
|
|
|
bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) {
|
2017-11-05 18:34:48 +00:00
|
|
|
if (pspIsIniting || pspIsQuitting) {
|
2014-01-19 22:17:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-30 02:09:28 +00:00
|
|
|
|
2014-01-15 14:02:47 +00:00
|
|
|
#if defined(_WIN32) && defined(_M_X64)
|
2017-04-05 14:21:08 +00:00
|
|
|
INFO_LOG(BOOT, "PPSSPP %s Windows 64 bit", PPSSPP_GIT_VERSION);
|
2014-01-15 14:02:47 +00:00
|
|
|
#elif defined(_WIN32) && !defined(_M_X64)
|
2017-04-05 14:21:08 +00:00
|
|
|
INFO_LOG(BOOT, "PPSSPP %s Windows 32 bit", PPSSPP_GIT_VERSION);
|
2014-01-15 14:02:47 +00:00
|
|
|
#else
|
2017-04-05 14:21:08 +00:00
|
|
|
INFO_LOG(BOOT, "PPSSPP %s", PPSSPP_GIT_VERSION);
|
2014-01-15 14:02:47 +00:00
|
|
|
#endif
|
2016-08-27 18:38:05 +00:00
|
|
|
|
2018-04-22 15:33:22 +00:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STARTING);
|
2016-01-05 20:18:43 +00:00
|
|
|
GraphicsContext *temp = coreParameter.graphicsContext;
|
2013-08-07 15:07:13 +00:00
|
|
|
coreParameter = coreParam;
|
2016-03-13 17:38:38 +00:00
|
|
|
if (coreParameter.graphicsContext == nullptr) {
|
|
|
|
coreParameter.graphicsContext = temp;
|
|
|
|
}
|
2013-08-07 15:07:13 +00:00
|
|
|
coreParameter.errorString = "";
|
2014-01-19 22:17:34 +00:00
|
|
|
pspIsIniting = true;
|
2018-03-13 01:06:46 +00:00
|
|
|
PSP_SetLoading("Loading game...");
|
2013-08-07 15:07:13 +00:00
|
|
|
|
2017-12-15 11:40:38 +00:00
|
|
|
CPU_Init();
|
2013-08-07 15:07:13 +00:00
|
|
|
|
2019-10-22 19:38:14 +00: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) {
|
|
|
|
coreParameter.gpuCore = GPUCORE_SOFTWARE;
|
|
|
|
}
|
|
|
|
|
2014-01-19 22:17:34 +00:00
|
|
|
*error_string = coreParameter.errorString;
|
2014-02-28 17:58:10 +00:00
|
|
|
bool success = coreParameter.fileToStart != "";
|
|
|
|
if (!success) {
|
2018-04-22 15:33:22 +00:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
2014-02-28 17:58:10 +00:00
|
|
|
pspIsIniting = false;
|
|
|
|
}
|
|
|
|
return success;
|
2014-01-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSP_InitUpdate(std::string *error_string) {
|
|
|
|
if (pspIsInited || !pspIsIniting) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 18:34:48 +00:00
|
|
|
if (!CPU_IsReady()) {
|
2014-01-19 22:17:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
bool success = coreParameter.fileToStart != "";
|
2013-08-10 17:56:47 +00:00
|
|
|
*error_string = coreParameter.errorString;
|
2017-12-03 18:54:38 +00:00
|
|
|
if (success && gpu == nullptr) {
|
2018-03-13 01:06:46 +00:00
|
|
|
PSP_SetLoading("Starting graphics...");
|
2019-09-29 04:36:03 +00:00
|
|
|
Draw::DrawContext *draw = coreParameter.graphicsContext ? coreParameter.graphicsContext->GetDrawContext() : nullptr;
|
|
|
|
success = GPU_Init(coreParameter.graphicsContext, draw);
|
2013-09-08 05:30:30 +00:00
|
|
|
if (!success) {
|
|
|
|
*error_string = "Unable to initialize rendering engine.";
|
|
|
|
}
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
2018-05-20 21:15:09 +00:00
|
|
|
if (!success) {
|
|
|
|
PSP_Shutdown();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pspIsInited = GPU_IsReady();
|
|
|
|
pspIsIniting = !pspIsInited;
|
2018-04-22 15:33:22 +00:00
|
|
|
if (pspIsInited) {
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
|
|
|
}
|
2018-05-20 21:15:09 +00:00
|
|
|
return pspIsInited;
|
2014-01-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) {
|
|
|
|
PSP_InitStart(coreParam, error_string);
|
|
|
|
|
2018-01-04 17:10:41 +00:00
|
|
|
while (!PSP_InitUpdate(error_string))
|
|
|
|
sleep_ms(10);
|
2014-02-17 18:57:47 +00:00
|
|
|
return pspIsInited;
|
2014-01-19 22:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSP_IsIniting() {
|
|
|
|
return pspIsIniting;
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PSP_IsInited() {
|
2017-11-05 18:34:48 +00:00
|
|
|
return pspIsInited && !pspIsQuitting;
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 01:26:36 +00:00
|
|
|
bool PSP_IsQuitting() {
|
|
|
|
return pspIsQuitting;
|
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
void PSP_Shutdown() {
|
2014-02-15 05:53:59 +00:00
|
|
|
// Do nothing if we never inited.
|
2017-11-05 18:34:48 +00:00
|
|
|
if (!pspIsInited && !pspIsIniting && !pspIsQuitting) {
|
2014-02-15 05:53:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-22 15:33:22 +00:00
|
|
|
// Make sure things know right away that PSP memory, etc. is going away.
|
|
|
|
pspIsQuitting = true;
|
|
|
|
if (coreState == CORE_RUNNING)
|
|
|
|
Core_UpdateState(CORE_ERROR);
|
|
|
|
|
2014-02-08 18:29:22 +00:00
|
|
|
#ifndef MOBILE_DEVICE
|
2013-12-17 11:30:56 +00:00
|
|
|
if (g_Config.bFuncHashMap) {
|
|
|
|
MIPSAnalyst::StoreHashMap();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 15:33:22 +00:00
|
|
|
if (pspIsIniting)
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
|
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STOPPING);
|
2017-12-15 11:40:38 +00:00
|
|
|
CPU_Shutdown();
|
2013-08-07 15:07:13 +00:00
|
|
|
GPU_Shutdown();
|
2014-12-20 16:29:56 +00:00
|
|
|
g_paramSFO.Clear();
|
2013-08-20 15:21:25 +00:00
|
|
|
host->SetWindowTitle(0);
|
2013-12-29 23:11:29 +00:00
|
|
|
currentMIPS = 0;
|
2013-12-30 02:09:28 +00:00
|
|
|
pspIsInited = false;
|
2014-01-19 22:17:34 +00:00
|
|
|
pspIsIniting = false;
|
2017-11-05 18:34:48 +00:00
|
|
|
pspIsQuitting = false;
|
2014-12-19 13:52:44 +00:00
|
|
|
g_Config.unloadGameConfig();
|
2018-04-22 15:33:22 +00:00
|
|
|
Core_NotifyLifecycle(CoreLifecycle::STOPPED);
|
2013-08-07 15:07:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 22:49:02 +00:00
|
|
|
void PSP_BeginHostFrame() {
|
|
|
|
// Reapply the graphics state of the PSP
|
2016-01-06 22:53:21 +00:00
|
|
|
if (gpu) {
|
|
|
|
gpu->BeginHostFrame();
|
|
|
|
}
|
2016-01-06 22:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PSP_EndHostFrame() {
|
2016-01-06 22:53:21 +00:00
|
|
|
if (gpu) {
|
|
|
|
gpu->EndHostFrame();
|
|
|
|
}
|
2016-01-06 22:49:02 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 01:38:17 +00: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 17:58:30 +00:00
|
|
|
if (coreState == CORE_STEPPING) {
|
|
|
|
// Keep the UI responsive.
|
|
|
|
break;
|
|
|
|
}
|
2018-04-30 01:38:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-04 22:22:30 +00:00
|
|
|
void PSP_RunLoopUntil(u64 globalticks) {
|
2013-08-07 06:00:20 +00:00
|
|
|
SaveState::Process();
|
2013-09-15 04:19:10 +00:00
|
|
|
if (coreState == CORE_POWERDOWN || coreState == CORE_ERROR) {
|
|
|
|
return;
|
2018-04-30 01:38:17 +00:00
|
|
|
} else if (coreState == CORE_STEPPING) {
|
|
|
|
Core_ProcessStepping();
|
|
|
|
return;
|
2013-09-15 04:19:10 +00:00
|
|
|
}
|
2013-08-07 15:07:13 +00:00
|
|
|
|
2017-12-15 11:40:38 +00:00
|
|
|
mipsr4k.RunLoopUntil(globalticks);
|
2014-06-23 04:42:29 +00:00
|
|
|
gpu->CleanupBeforeUI();
|
2013-08-04 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PSP_RunLoopFor(int cycles) {
|
|
|
|
PSP_RunLoopUntil(CoreTiming::GetTicks() + cycles);
|
|
|
|
}
|
|
|
|
|
2018-03-13 01:06:46 +00: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;
|
|
|
|
}
|
|
|
|
|
2013-08-07 15:07:13 +00:00
|
|
|
CoreParameter &PSP_CoreParameter() {
|
2012-11-01 15:19:01 +00:00
|
|
|
return coreParameter;
|
|
|
|
}
|
2013-03-28 19:17:45 +00:00
|
|
|
|
2013-10-15 06:03:39 +00:00
|
|
|
std::string GetSysDirectory(PSPDirectories directoryType) {
|
|
|
|
switch (directoryType) {
|
|
|
|
case DIRECTORY_CHEATS:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/Cheats/";
|
2013-10-15 06:03:39 +00:00
|
|
|
case DIRECTORY_GAME:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/GAME/";
|
2013-10-15 06:03:39 +00:00
|
|
|
case DIRECTORY_SAVEDATA:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/SAVEDATA/";
|
2013-10-15 06:03:39 +00:00
|
|
|
case DIRECTORY_SCREENSHOT:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/SCREENSHOT/";
|
2013-10-15 06:03:39 +00:00
|
|
|
case DIRECTORY_SYSTEM:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/SYSTEM/";
|
2013-10-15 06:03:39 +00:00
|
|
|
case DIRECTORY_PAUTH:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PAUTH/";
|
2014-02-27 06:19:32 +00:00
|
|
|
case DIRECTORY_DUMP:
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory + "PSP/SYSTEM/DUMP/";
|
2015-06-11 21:59:02 +00:00
|
|
|
case DIRECTORY_SAVESTATE:
|
|
|
|
return g_Config.memStickDirectory + "PSP/PPSSPP_STATE/";
|
2015-06-28 01:32:21 +00:00
|
|
|
case DIRECTORY_CACHE:
|
|
|
|
return g_Config.memStickDirectory + "PSP/SYSTEM/CACHE/";
|
2016-04-30 21:05:03 +00:00
|
|
|
case DIRECTORY_TEXTURES:
|
|
|
|
return g_Config.memStickDirectory + "PSP/TEXTURES/";
|
2016-01-17 21:11:28 +00:00
|
|
|
case DIRECTORY_APP_CACHE:
|
|
|
|
if (!g_Config.appCacheDirectory.empty()) {
|
|
|
|
return g_Config.appCacheDirectory;
|
|
|
|
}
|
|
|
|
return g_Config.memStickDirectory + "PSP/SYSTEM/CACHE/";
|
2016-09-03 22:26:01 +00:00
|
|
|
case DIRECTORY_VIDEO:
|
|
|
|
return g_Config.memStickDirectory + "PSP/VIDEO/";
|
|
|
|
case DIRECTORY_AUDIO:
|
|
|
|
return g_Config.memStickDirectory + "PSP/AUDIO/";
|
2013-10-15 06:03:39 +00:00
|
|
|
// Just return the memory stick root if we run into some sort of problem.
|
|
|
|
default:
|
|
|
|
ERROR_LOG(FILESYS, "Unknown directory type.");
|
2014-10-19 21:20:51 +00:00
|
|
|
return g_Config.memStickDirectory;
|
2013-10-15 06:03:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-24 12:21:35 +00:00
|
|
|
#if defined(_WIN32)
|
2013-10-15 06:03:39 +00:00
|
|
|
// Run this at startup time. Please use GetSysDirectory if you need to query where folders are.
|
|
|
|
void InitSysDirectories() {
|
2014-10-19 21:20:51 +00:00
|
|
|
if (!g_Config.memStickDirectory.empty() && !g_Config.flash0Directory.empty())
|
2013-10-15 06:03:39 +00:00
|
|
|
return;
|
2013-10-15 06:41:10 +00:00
|
|
|
|
2013-11-17 18:15:49 +00:00
|
|
|
const std::string path = File::GetExeDirectory();
|
2013-03-28 19:17:45 +00:00
|
|
|
|
2013-10-13 22:43:45 +00:00
|
|
|
// Mount a filesystem
|
2017-03-31 21:50:17 +00:00
|
|
|
g_Config.flash0Directory = path + "assets/flash0/";
|
2013-03-28 19:17:45 +00:00
|
|
|
|
2013-10-13 20:45:13 +00:00
|
|
|
// Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder.
|
2017-02-24 17:59:41 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2017-02-28 00:47:13 +00:00
|
|
|
// We set g_Config.memStickDirectory outside.
|
2017-02-25 00:38:48 +00:00
|
|
|
|
2017-02-24 17:59:41 +00:00
|
|
|
#else
|
2013-10-13 20:45:13 +00:00
|
|
|
wchar_t myDocumentsPath[MAX_PATH];
|
2013-10-14 03:19:30 +00:00
|
|
|
const HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath);
|
2013-10-15 06:03:39 +00:00
|
|
|
const std::string myDocsPath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
|
2013-11-17 18:15:49 +00:00
|
|
|
const std::string installedFile = path + "installed.txt";
|
2013-10-14 03:19:30 +00:00
|
|
|
const bool installed = File::Exists(installedFile);
|
2013-10-13 20:45:13 +00:00
|
|
|
|
2013-10-13 21:17:48 +00:00
|
|
|
// If installed.txt exists(and we can determine the Documents directory)
|
2013-10-13 21:52:09 +00:00
|
|
|
if (installed && (result == S_OK)) {
|
2017-08-31 20:15:05 +00:00
|
|
|
#if defined(_WIN32) && defined(__MINGW32__)
|
|
|
|
std::ifstream inputFile(installedFile);
|
|
|
|
#else
|
2013-10-14 06:46:05 +00:00
|
|
|
std::ifstream inputFile(ConvertUTF8ToWString(installedFile));
|
2017-08-31 20:15:05 +00:00
|
|
|
#endif
|
2013-10-14 06:46:05 +00:00
|
|
|
|
2013-10-14 06:22:13 +00:00
|
|
|
if (!inputFile.fail() && inputFile.is_open()) {
|
2013-10-14 06:46:05 +00:00
|
|
|
std::string tempString;
|
2013-10-14 21:08:47 +00:00
|
|
|
|
2013-10-14 06:22:13 +00:00
|
|
|
std::getline(inputFile, tempString);
|
|
|
|
|
2013-10-14 06:46:05 +00:00
|
|
|
// Skip UTF-8 encoding bytes if there are any. There are 3 of them.
|
2013-10-14 21:08:47 +00:00
|
|
|
if (tempString.substr(0, 3) == "\xEF\xBB\xBF")
|
2013-10-14 06:46:05 +00:00
|
|
|
tempString = tempString.substr(3);
|
|
|
|
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = tempString;
|
2013-10-14 03:19:30 +00:00
|
|
|
}
|
2013-10-14 06:22:13 +00:00
|
|
|
inputFile.close();
|
2013-10-13 21:17:48 +00:00
|
|
|
|
2013-10-13 22:43:45 +00:00
|
|
|
// Check if the file is empty first, before appending the slash.
|
2014-10-19 21:20:51 +00:00
|
|
|
if (g_Config.memStickDirectory.empty())
|
|
|
|
g_Config.memStickDirectory = myDocsPath;
|
2013-10-13 22:43:45 +00:00
|
|
|
|
2014-10-19 21:20:51 +00:00
|
|
|
size_t lastSlash = g_Config.memStickDirectory.find_last_of("/");
|
|
|
|
if (lastSlash != (g_Config.memStickDirectory.length() - 1))
|
|
|
|
g_Config.memStickDirectory.append("/");
|
2013-10-13 20:45:13 +00:00
|
|
|
} else {
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = path + "memstick/";
|
2013-10-13 20:45:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 21:08:47 +00:00
|
|
|
// Create the memstickpath before trying to write to it, and fall back on Documents yet again
|
|
|
|
// if we can't make it.
|
2014-10-19 21:20:51 +00:00
|
|
|
if (!File::Exists(g_Config.memStickDirectory)) {
|
|
|
|
if (!File::CreateDir(g_Config.memStickDirectory))
|
|
|
|
g_Config.memStickDirectory = myDocsPath;
|
2015-09-23 07:48:55 +00:00
|
|
|
INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str());
|
2013-10-14 21:08:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 20:50:29 +00:00
|
|
|
const std::string testFile = g_Config.memStickDirectory + "/_writable_test.$$$";
|
2013-10-13 21:17:48 +00:00
|
|
|
|
2013-10-14 21:08:47 +00:00
|
|
|
// If any directory is read-only, fall back to the Documents directory.
|
|
|
|
// We're screwed anyway if we can't write to Documents, or can't detect it.
|
2015-09-22 20:50:29 +00:00
|
|
|
if (!File::CreateEmptyFile(testFile))
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = myDocsPath;
|
2013-10-13 20:45:13 +00:00
|
|
|
|
2013-10-13 21:52:09 +00:00
|
|
|
// Clean up our mess.
|
2015-09-22 20:50:29 +00:00
|
|
|
if (File::Exists(testFile))
|
|
|
|
File::Delete(testFile);
|
2017-02-28 00:47:13 +00:00
|
|
|
#endif
|
2013-10-15 06:03:39 +00:00
|
|
|
|
2017-02-20 13:46:44 +00: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.
|
|
|
|
File::CreateDir(g_Config.memStickDirectory + "PSP");
|
|
|
|
File::CreateDir(g_Config.memStickDirectory + "PSP/COMMON");
|
2018-09-02 17:27:11 +00:00
|
|
|
File::CreateDir(GetSysDirectory(DIRECTORY_GAME));
|
|
|
|
File::CreateDir(GetSysDirectory(DIRECTORY_SAVEDATA));
|
|
|
|
File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE));
|
2017-02-20 13:46:44 +00:00
|
|
|
|
2013-10-15 06:03:39 +00:00
|
|
|
if (g_Config.currentDirectory.empty()) {
|
|
|
|
g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME);
|
|
|
|
}
|
2013-03-28 19:17:45 +00:00
|
|
|
}
|
2013-10-15 06:41:10 +00:00
|
|
|
#endif
|