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-29 17:50:08 +00:00
|
|
|
#include "base/NativeApp.h"
|
|
|
|
#include "base/display.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "base/mutex.h"
|
|
|
|
#include "base/timeutil.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "input/input_state.h"
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/MemMap.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-02-18 22:25:06 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "Windows/OpenGLBase.h"
|
2013-03-29 19:51:14 +00:00
|
|
|
#include "Windows/InputDevice.h"
|
2013-02-18 22:25:06 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "Host.h"
|
|
|
|
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
event m_hStepEvent;
|
|
|
|
recursive_mutex m_hStepMutex;
|
2013-02-23 20:59:40 +00:00
|
|
|
event m_hInactiveEvent;
|
|
|
|
recursive_mutex m_hInactiveMutex;
|
|
|
|
|
2013-03-29 19:51:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
InputState input_state;
|
2013-03-29 21:56:57 +00:00
|
|
|
#else
|
|
|
|
extern InputState input_state;
|
2013-03-29 19:51:14 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
void Core_ErrorPause()
|
|
|
|
{
|
2013-02-23 20:59:40 +00:00
|
|
|
Core_UpdateState(CORE_ERROR);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core_Halt(const char *msg)
|
|
|
|
{
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
ERROR_LOG(CPU, "CPU HALTED : %s",msg);
|
|
|
|
_dbg_update_();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core_Stop()
|
|
|
|
{
|
2013-02-23 20:59:40 +00:00
|
|
|
Core_UpdateState(CORE_POWERDOWN);
|
2012-11-01 15:19:01 +00:00
|
|
|
m_hStepEvent.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Core_IsStepping()
|
|
|
|
{
|
|
|
|
return coreState == CORE_STEPPING || coreState == CORE_POWERDOWN;
|
|
|
|
}
|
|
|
|
|
2013-02-23 20:59:40 +00:00
|
|
|
bool Core_IsInactive()
|
|
|
|
{
|
|
|
|
return coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && !coreStatePending;
|
|
|
|
}
|
2013-02-23 21:21:28 +00:00
|
|
|
|
2013-02-23 20:59:40 +00:00
|
|
|
void Core_WaitInactive()
|
|
|
|
{
|
|
|
|
while (!Core_IsInactive())
|
|
|
|
m_hInactiveEvent.wait(m_hInactiveMutex);
|
|
|
|
}
|
|
|
|
|
2013-02-23 21:21:28 +00:00
|
|
|
void Core_WaitInactive(int milliseconds)
|
|
|
|
{
|
2013-02-23 21:32:12 +00:00
|
|
|
while (!Core_IsInactive())
|
|
|
|
m_hInactiveEvent.wait_for(m_hInactiveMutex, milliseconds);
|
2013-02-23 21:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 17:50:08 +00:00
|
|
|
void UpdateScreenScale() {
|
|
|
|
dp_xres = PSP_CoreParameter().pixelWidth;
|
|
|
|
dp_yres = PSP_CoreParameter().pixelHeight;
|
|
|
|
pixel_xres = PSP_CoreParameter().pixelWidth;
|
|
|
|
pixel_yres = PSP_CoreParameter().pixelHeight;
|
|
|
|
g_dpi = 72;
|
|
|
|
g_dpi_scale = 1.0f;
|
|
|
|
pixel_in_dps = (float)pixel_xres / dp_xres;
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void Core_RunLoop()
|
|
|
|
{
|
2013-02-18 22:25:06 +00:00
|
|
|
while (!coreState) {
|
2013-03-29 18:32:20 +00:00
|
|
|
time_update();
|
2013-03-29 17:50:08 +00:00
|
|
|
UpdateScreenScale();
|
2013-02-18 22:25:06 +00:00
|
|
|
{
|
2013-03-29 19:51:14 +00:00
|
|
|
{
|
|
|
|
lock_guard guard(input_state.lock);
|
2013-03-29 21:56:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// Temporary hack.
|
2013-03-29 19:51:14 +00:00
|
|
|
if (GetAsyncKeyState(VK_ESCAPE)) {
|
|
|
|
input_state.pad_buttons |= PAD_BUTTON_MENU;
|
|
|
|
} else {
|
|
|
|
input_state.pad_buttons &= ~PAD_BUTTON_MENU;
|
|
|
|
}
|
2013-03-29 21:56:57 +00:00
|
|
|
#endif
|
2013-03-29 18:32:20 +00:00
|
|
|
}
|
2013-03-29 17:50:08 +00:00
|
|
|
NativeUpdate(input_state);
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
2013-03-29 17:50:08 +00:00
|
|
|
NativeRender();
|
|
|
|
// Simple throttling to not burn the GPU in the menu.
|
2013-03-29 21:56:57 +00:00
|
|
|
#ifdef _WIN32
|
2013-03-30 07:34:27 +00:00
|
|
|
if (globalUIState != UISTATE_INGAME) {
|
2013-03-29 17:50:08 +00:00
|
|
|
Sleep(15);
|
2013-03-30 07:34:27 +00:00
|
|
|
GL_SwapBuffers();
|
|
|
|
} else if (!Core_IsStepping()) {
|
|
|
|
GL_SwapBuffers();
|
|
|
|
}
|
2013-03-29 21:56:57 +00:00
|
|
|
#endif
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core_DoSingleStep()
|
|
|
|
{
|
|
|
|
m_hStepEvent.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core_SingleStep()
|
|
|
|
{
|
|
|
|
currentMIPS->SingleStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Some platforms, like Android, do not call this function but handle things on their own.
|
|
|
|
void Core_Run()
|
|
|
|
{
|
2012-12-26 07:52:40 +00:00
|
|
|
#if defined(_DEBUG)
|
2012-11-01 15:19:01 +00:00
|
|
|
host->UpdateDisassembly();
|
|
|
|
#endif
|
2013-01-14 15:13:53 +00:00
|
|
|
#if !defined(USING_QT_UI) || defined(USING_GLES2)
|
2012-11-01 15:19:01 +00:00
|
|
|
while (true)
|
2013-01-13 23:29:42 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
reswitch:
|
2013-01-04 09:26:14 +00:00
|
|
|
switch (coreState)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
case CORE_RUNNING:
|
|
|
|
//1: enter a fast runloop
|
|
|
|
Core_RunLoop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// We should never get here on Android.
|
|
|
|
case CORE_STEPPING:
|
2013-03-23 17:30:52 +00:00
|
|
|
if (coreStatePending) {
|
|
|
|
coreStatePending = false;
|
2013-02-23 20:59:40 +00:00
|
|
|
m_hInactiveEvent.notify_one();
|
2013-03-23 17:30:52 +00:00
|
|
|
}
|
2013-02-23 20:59:40 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
//1: wait for step command..
|
2013-02-10 15:36:06 +00:00
|
|
|
#if defined(USING_QT_UI) || defined(_DEBUG)
|
2013-02-17 00:06:06 +00:00
|
|
|
host->UpdateDisassembly();
|
|
|
|
host->UpdateMemView();
|
2013-02-10 15:36:06 +00:00
|
|
|
host->SendCoreWait(true);
|
|
|
|
#endif
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
m_hStepEvent.wait(m_hStepMutex);
|
2013-02-10 15:36:06 +00:00
|
|
|
|
|
|
|
#if defined(USING_QT_UI) || defined(_DEBUG)
|
|
|
|
host->SendCoreWait(false);
|
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
if (coreState == CORE_POWERDOWN)
|
|
|
|
return;
|
|
|
|
if (coreState != CORE_STEPPING)
|
2013-01-14 15:13:53 +00:00
|
|
|
#if defined(USING_QT_UI) && !defined(USING_GLES2)
|
2013-01-13 23:29:42 +00:00
|
|
|
return;
|
|
|
|
#else
|
2012-11-01 15:19:01 +00:00
|
|
|
goto reswitch;
|
2013-01-13 23:29:42 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
currentCPU = &mipsr4k;
|
|
|
|
Core_SingleStep();
|
|
|
|
//4: update disasm dialog
|
2013-02-10 15:36:06 +00:00
|
|
|
#if defined(USING_QT_UI) || defined(_DEBUG)
|
2012-11-01 15:19:01 +00:00
|
|
|
host->UpdateDisassembly();
|
|
|
|
host->UpdateMemView();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CORE_POWERDOWN:
|
|
|
|
case CORE_ERROR:
|
|
|
|
//1: Exit loop!!
|
2013-03-23 17:30:52 +00:00
|
|
|
if (coreStatePending) {
|
|
|
|
coreStatePending = false;
|
2013-02-23 20:59:40 +00:00
|
|
|
m_hInactiveEvent.notify_one();
|
2013-03-23 17:30:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-23 20:59:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case CORE_NEXTFRAME:
|
2012-11-01 15:19:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-29 20:21:27 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void Core_EnableStepping(bool step)
|
|
|
|
{
|
|
|
|
if (step)
|
|
|
|
{
|
|
|
|
sleep_ms(1);
|
2012-12-26 07:52:40 +00:00
|
|
|
#if defined(_DEBUG)
|
2012-11-01 15:19:01 +00:00
|
|
|
host->SetDebugMode(true);
|
|
|
|
#endif
|
2013-02-23 20:59:40 +00:00
|
|
|
Core_UpdateState(CORE_STEPPING);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-26 07:52:40 +00:00
|
|
|
#if defined(_DEBUG)
|
2012-11-01 15:19:01 +00:00
|
|
|
host->SetDebugMode(false);
|
|
|
|
#endif
|
|
|
|
coreState = CORE_RUNNING;
|
2013-02-23 20:59:40 +00:00
|
|
|
coreStatePending = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
m_hStepEvent.notify_one();
|
|
|
|
}
|
|
|
|
}
|