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/.
|
|
|
|
|
2013-03-28 19:17:45 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "MemMap.h"
|
|
|
|
|
|
|
|
#include "MIPS/MIPS.h"
|
|
|
|
|
2012-11-26 03:25:14 +00:00
|
|
|
#include "MIPS/JitCommon/JitCommon.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "System.h"
|
|
|
|
// Bad dependency
|
|
|
|
#include "GPU/GLES/Framebuffer.h"
|
|
|
|
#include "GPU/GLES/TextureCache.h"
|
|
|
|
#include "GPU/GLES/ShaderManager.h"
|
|
|
|
|
|
|
|
#include "PSPMixer.h"
|
|
|
|
#include "HLE/HLE.h"
|
|
|
|
#include "HLE/sceKernel.h"
|
|
|
|
#include "HLE/sceKernelMemory.h"
|
|
|
|
#include "HLE/sceAudio.h"
|
2013-03-02 20:34:41 +00:00
|
|
|
#include "Config.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "Core.h"
|
|
|
|
#include "CoreTiming.h"
|
|
|
|
#include "CoreParameter.h"
|
|
|
|
#include "FileSystems/MetaFileSystem.h"
|
|
|
|
#include "Loaders.h"
|
2013-01-02 20:00:10 +00:00
|
|
|
#include "ELF/ParamSFO.h"
|
2013-01-15 12:57:35 +00:00
|
|
|
#include "../Common/LogManager.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
MetaFileSystem pspFileSystem;
|
2013-01-02 20:00:10 +00:00
|
|
|
ParamSFOData g_paramSFO;
|
2013-03-29 18:32:20 +00:00
|
|
|
GlobalUIState globalUIState;
|
2012-11-01 15:19:01 +00:00
|
|
|
static CoreParameter coreParameter;
|
2013-01-13 15:46:45 +00:00
|
|
|
static PSPMixer *mixer;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
void Core_UpdateState(CoreState newState)
|
|
|
|
{
|
|
|
|
if ((coreState == CORE_RUNNING || coreState == CORE_NEXTFRAME) && newState != CORE_RUNNING)
|
|
|
|
coreStatePending = true;
|
|
|
|
coreState = newState;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string)
|
|
|
|
{
|
2013-03-02 20:34:41 +00:00
|
|
|
INFO_LOG(HLE, "PPSSPP %s", PPSSPP_GIT_VERSION);
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
coreParameter = coreParam;
|
|
|
|
currentCPU = &mipsr4k;
|
|
|
|
numCPUs = 1;
|
|
|
|
Memory::Init();
|
|
|
|
mipsr4k.Reset();
|
|
|
|
mipsr4k.pc = 0;
|
|
|
|
|
2013-03-31 04:42:43 +00:00
|
|
|
host->AttemptLoadSymbolMap();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
if (coreParameter.enableSound)
|
|
|
|
{
|
2013-01-13 15:46:45 +00:00
|
|
|
mixer = new PSPMixer();
|
|
|
|
host->InitSound(mixer);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 12:57:35 +00:00
|
|
|
if (coreParameter.disableG3Dlog)
|
|
|
|
{
|
|
|
|
LogManager::GetInstance()->SetEnable(LogTypes::G3D, false);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (!LoadFile(coreParameter.fileToStart.c_str(), error_string))
|
|
|
|
{
|
2013-01-10 11:27:10 +00:00
|
|
|
pspFileSystem.Shutdown();
|
2013-01-17 09:12:40 +00:00
|
|
|
CoreTiming::Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
__KernelShutdown();
|
|
|
|
HLEShutdown();
|
|
|
|
host->ShutdownSound();
|
|
|
|
Memory::Shutdown();
|
|
|
|
coreParameter.fileToStart = "";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-24 19:03:42 +00:00
|
|
|
g_Config.AddRecent(coreParameter.fileToStart);
|
2012-11-01 15:19:01 +00:00
|
|
|
// Setup JIT here.
|
|
|
|
if (coreParameter.startPaused)
|
|
|
|
coreState = CORE_STEPPING;
|
|
|
|
else
|
|
|
|
coreState = CORE_RUNNING;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PSP_IsInited()
|
|
|
|
{
|
|
|
|
return currentCPU != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PSP_Shutdown()
|
|
|
|
{
|
2013-01-10 11:27:10 +00:00
|
|
|
pspFileSystem.Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-01-17 09:12:40 +00:00
|
|
|
CoreTiming::Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-03-31 04:42:43 +00:00
|
|
|
if (g_Config.bAutoSaveSymbolMap)
|
|
|
|
host->SaveSymbolMap();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
if (coreParameter.enableSound)
|
|
|
|
{
|
|
|
|
host->ShutdownSound();
|
2013-01-13 16:10:59 +00:00
|
|
|
mixer = 0; // deleted in ShutdownSound
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
__KernelShutdown();
|
|
|
|
HLEShutdown();
|
2013-01-13 15:46:45 +00:00
|
|
|
Memory::Shutdown();
|
2012-11-01 15:19:01 +00:00
|
|
|
currentCPU = 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 20:06:47 +00:00
|
|
|
CoreParameter &PSP_CoreParameter()
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
return coreParameter;
|
|
|
|
}
|
2013-03-28 19:17:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void GetSysDirectories(std::string &memstickpath, std::string &flash0path) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT];
|
|
|
|
char memstickpath_buf[_MAX_PATH];
|
|
|
|
char flash0path_buf[_MAX_PATH];
|
|
|
|
|
|
|
|
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
|
|
|
|
|
|
|
|
char *winpos = strstr(path_buffer, "Windows");
|
|
|
|
if (winpos)
|
|
|
|
*winpos = 0;
|
|
|
|
strcat(path_buffer, "dummy.txt");
|
|
|
|
|
|
|
|
_splitpath_s(path_buffer, drive, dir, file, ext );
|
|
|
|
|
|
|
|
// Mount a couple of filesystems
|
|
|
|
sprintf(memstickpath_buf, "%s%smemstick\\", drive, dir);
|
|
|
|
sprintf(flash0path_buf, "%s%sflash0\\", drive, dir);
|
|
|
|
|
|
|
|
memstickpath = memstickpath_buf;
|
|
|
|
flash0path = flash0path_buf;
|
|
|
|
#else
|
|
|
|
// TODO
|
|
|
|
memstickpath = g_Config.memCardDirectory;
|
|
|
|
flash0path = g_Config.flashDirectory;
|
|
|
|
#endif
|
|
|
|
}
|