diff --git a/Core/Core.cpp b/Core/Core.cpp index b0a80defda..325874bf85 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -29,6 +29,7 @@ #include "Core/MIPS/MIPS.h" #ifdef _WIN32 #include "Windows/OpenGLBase.h" +#include "Windows/InputDevice.h" #endif #include "Host.h" @@ -39,19 +40,10 @@ event m_hStepEvent; recursive_mutex m_hStepMutex; event m_hInactiveEvent; recursive_mutex m_hInactiveMutex; + +#ifdef _WIN32 InputState input_state; - -// 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; -} +#endif void Core_ErrorPause() { @@ -108,17 +100,20 @@ void UpdateScreenScale() { pixel_in_dps = (float)pixel_xres / dp_xres; } +#ifdef _WIN32 void Core_RunLoop() { while (!coreState) { time_update(); UpdateScreenScale(); { - lock_guard guard(input_state.lock); - if (GetAsyncKeyState(VK_ESCAPE)) { - input_state.pad_buttons |= PAD_BUTTON_MENU; - } else { - input_state.pad_buttons &= ~PAD_BUTTON_MENU; + { + lock_guard guard(input_state.lock); + if (GetAsyncKeyState(VK_ESCAPE)) { + input_state.pad_buttons |= PAD_BUTTON_MENU; + } else { + input_state.pad_buttons &= ~PAD_BUTTON_MENU; + } } NativeUpdate(input_state); } @@ -129,6 +124,7 @@ void Core_RunLoop() GL_SwapBuffers(); } } +#endif void Core_DoSingleStep() { diff --git a/Core/Core.h b/Core/Core.h index e5a91872a3..19fc377c51 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -17,8 +17,9 @@ #pragma once -#include "../Globals.h" -#include "CoreParameter.h" +#include "Globals.h" +#include "Core/Core.h" +#include "Core/CoreParameter.h" // called from emu thread void Core_Run(); @@ -33,22 +34,8 @@ void Core_Halt(const char *msg); bool Core_IsStepping(); -// RUNNING must be at 0. -enum CoreState -{ - CORE_RUNNING = 0, - CORE_STEPPING, - CORE_POWERDOWN, - CORE_ERROR, - CORE_NEXTFRAME, -}; - -void Core_UpdateState(CoreState newState); bool Core_IsInactive(); void Core_WaitInactive(); void Core_WaitInactive(int milliseconds); -void UpdateScreenScale(); - - -extern volatile CoreState coreState; +void UpdateScreenScale(); \ No newline at end of file diff --git a/Core/MIPS/ARM/ArmAsm.cpp b/Core/MIPS/ARM/ArmAsm.cpp index e26ce21be7..c208cf4f9a 100644 --- a/Core/MIPS/ARM/ArmAsm.cpp +++ b/Core/MIPS/ARM/ArmAsm.cpp @@ -16,16 +16,15 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "../../MemMap.h" - -#include "../MIPS.h" -#include "ArmEmitter.h" -#include "../../CoreTiming.h" +#include "Core/MemMap.h" +#include "Core/MIPS/MIPS.h" +#include "Core/System.h" +#include "Core/CoreTiming.h" #include "MemoryUtil.h" +#include "ArmEmitter.h" #include "ArmJit.h" #include "../JitCommon/JitCommon.h" -#include "../../Core.h" #include "ArmAsm.h" using namespace ArmGen; diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index a27774bd3d..5fc4208d54 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -15,16 +15,16 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "MIPSTables.h" - -#include "MIPS.h" -#include "MIPSDis.h" -#include "MIPSDisVFPU.h" -#include "MIPSInt.h" -#include "MIPSIntVFPU.h" -#include "MIPSCodeUtils.h" -#include "../../Core/CoreTiming.h" -#include "../Debugger/Breakpoints.h" +#include "Core/System.h" +#include "Core/MIPS/MIPS.h" +#include "Core/MIPS/MIPSDis.h" +#include "Core/MIPS/MIPSDisVFPU.h" +#include "Core/MIPS/MIPSInt.h" +#include "Core/MIPS/MIPSIntVFPU.h" +#include "Core/MIPS/MIPSCodeUtils.h" +#include "Core/MIPS/MIPSTables.h" +#include "Core/CoreTiming.h" +#include "Core/Debugger/Breakpoints.h" #include "JitCommon/JitCommon.h" diff --git a/Core/MIPS/x86/Asm.cpp b/Core/MIPS/x86/Asm.cpp index e02d7cc9c3..476e3382e5 100644 --- a/Core/MIPS/x86/Asm.cpp +++ b/Core/MIPS/x86/Asm.cpp @@ -20,11 +20,12 @@ #include "../../MemMap.h" -#include "../MIPS.h" -#include "../../CoreTiming.h" -#include "MemoryUtil.h" +#include "Core/Core.h" +#include "Core/System.h" +#include "Core/MIPS/MIPS.h" +#include "Core/CoreTiming.h" +#include "Common/MemoryUtil.h" -#include "ABI.h" #include "Jit.h" #include "../JitCommon/JitCommon.h" #include "../../Core.h" diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 0dfa1ff0d9..cf5814138c 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -18,13 +18,14 @@ #include #include #include "Common/ChunkFile.h" -#include "../../Core.h" -#include "../../CoreTiming.h" -#include "../../Config.h" -#include "../MIPS.h" -#include "../MIPSCodeUtils.h" -#include "../MIPSInt.h" -#include "../MIPSTables.h" +#include "Core/Core.h" +#include "Core/System.h" +#include "Core/CoreTiming.h" +#include "Core/Config.h" +#include "Core/MIPS/MIPS.h" +#include "Core/MIPS/MIPSCodeUtils.h" +#include "Core/MIPS/MIPSInt.h" +#include "Core/MIPS/MIPSTables.h" #include "RegCache.h" #include "Jit.h" diff --git a/Core/System.cpp b/Core/System.cpp index d72f369d25..a15f1675fa 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -53,6 +53,18 @@ GlobalUIState globalUIState; static CoreParameter coreParameter; static PSPMixer *mixer; +// 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; +} + bool PSP_Init(const CoreParameter &coreParam, std::string *error_string) { INFO_LOG(HLE, "PPSSPP %s", PPSSPP_GIT_VERSION); diff --git a/Core/System.h b/Core/System.h index 75079f2934..9ed6e7bbd9 100644 --- a/Core/System.h +++ b/Core/System.h @@ -45,4 +45,18 @@ void PSP_SWI(); void GetSysDirectories(std::string &memstickpath, std::string &flash0path); +// RUNNING must be at 0. +enum CoreState +{ + CORE_RUNNING = 0, + CORE_STEPPING, + CORE_POWERDOWN, + CORE_ERROR, + CORE_NEXTFRAME, +}; + +extern volatile CoreState coreState; +extern volatile bool coreStatePending; +void Core_UpdateState(CoreState newState); + CoreParameter &PSP_CoreParameter(); \ No newline at end of file diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 83f49111fc..a3d958db04 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -55,12 +55,10 @@ DWORD TheThread(LPVOID x) { Host *oldHost = host; UpdateScreenScale(); - NativeInit(0, 0, memstick.c_str(), "C:\\", "1234"); + NativeInit(0, 0, memstick.c_str(), memstick.c_str(), "1234"); Host *nativeHost = host; host = oldHost; - CoreParameter coreParameter; - host->UpdateUI(); std::string error_string; @@ -78,7 +76,6 @@ DWORD TheThread(LPVOID x) { _dbg_update_(); Core_EnableStepping(FALSE); - Core_Run(); shutdown: diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index dc6fc9678b..597a13cf54 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -357,8 +357,7 @@ namespace MainWindow SendMessage(memoryWindow[i]->GetDlgHandle(), WM_CLOSE, 0, 0); NativeMessageReceived("stop", ""); - - // EmuThread_Stop(); + SetPlaying(0); Update(); UpdateMenus(); @@ -373,25 +372,7 @@ namespace MainWindow break; case ID_EMULATION_RESET: - /* - for (int i=0; iGetDlgHandle(), WM_COMMAND, IDC_STOP, 0); - - Core_WaitInactive(); - - for (int i=0; iGetDlgHandle(), WM_CLOSE, 0, 0); - for (int i=0; iGetDlgHandle(), WM_CLOSE, 0, 0); - - - EmuThread_Stop(); - - EmuThread_Start(GetCurrentFilename());*/ - + NativeMessageReceived("reset", ""); break; case ID_EMULATION_SPEEDLIMIT: @@ -710,7 +691,6 @@ namespace MainWindow return 0; } - void UpdateMenus() { HMENU menu = GetMenu(GetHWND()); @@ -741,7 +721,7 @@ namespace MainWindow EnableMenuItem(menu,ID_EMULATION_RUN, (Core_IsStepping() || globalUIState == UISTATE_PAUSEMENU) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(menu,ID_EMULATION_PAUSE, globalUIState == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED); EnableMenuItem(menu,ID_EMULATION_STOP, globalUIState == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED); - EnableMenuItem(menu,ID_EMULATION_RESET, MF_GRAYED); //pspRunning ? MF_ENABLED : MF_GRAYED); + EnableMenuItem(menu,ID_EMULATION_RESET, globalUIState == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED); UINT enable = globalUIState == UISTATE_MENU ? MF_ENABLED : MF_GRAYED; EnableMenuItem(menu,ID_FILE_LOAD,enable); diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index 3f3f54c3ce..cf30d6dfb3 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -2,7 +2,8 @@ #include #include -#include + +#include "Core/System.h" namespace MainWindow { diff --git a/android/jni/EmuScreen.cpp b/android/jni/EmuScreen.cpp index 63de51007d..d25cc82857 100644 --- a/android/jni/EmuScreen.cpp +++ b/android/jni/EmuScreen.cpp @@ -24,16 +24,17 @@ #include "input/input_state.h" #include "ui/ui.h" -#include "../../Core/Config.h" -#include "../../Core/CoreTiming.h" -#include "../../Core/CoreParameter.h" -#include "../../Core/Core.h" -#include "../../Core/Host.h" -#include "../../Core/System.h" -#include "../../Core/MIPS/MIPS.h" -#include "../../GPU/GPUState.h" -#include "../../GPU/GPUInterface.h" -#include "../../Core/HLE/sceCtrl.h" +#include "Core/Config.h" +#include "Core/CoreTiming.h" +#include "Core/CoreParameter.h" +#include "Core/Core.h" +#include "Core/Host.h" +#include "Core/System.h" +#include "Core/MIPS/MIPS.h" +#include "GPU/GPUState.h" +#include "GPU/GPUInterface.h" +#include "Core/HLE/sceCtrl.h" +#include "Core/Debugger/SymbolMap.h" #include "GamepadEmu.h" #include "UIShader.h" @@ -80,11 +81,16 @@ EmuScreen::EmuScreen(const std::string &filename) : invalid_(true) } host->BootDone(); + host->AttemptLoadSymbolMap(); + host->UpdateDisassembly(); + +#ifdef _WIN32 if (g_Config.bAutoRun) { Core_EnableStepping(false); } else { Core_EnableStepping(true); } +#endif LayoutGamepad(dp_xres, dp_yres); @@ -95,6 +101,8 @@ EmuScreen::~EmuScreen() { if (!invalid_) { // If we were invalid, it would already be shutdown. + + // symbolMap.SaveSymbolMap(SymbolMapFilename(coreParam.fileToStart).c_str()); PSP_Shutdown(); } } @@ -112,6 +120,23 @@ void EmuScreen::sendMessage(const char *message, const char *value) screenManager()->push(new PauseScreen()); } else if (!strcmp(message, "stop")) { screenManager()->switchScreen(new MenuScreen()); + } else if (!strcmp(message, "reset")) { + PSP_Shutdown(); + std::string resetError; + if (!PSP_Init(PSP_CoreParameter(), &resetError)) { + ELOG("Error resetting: %s", resetError); + screenManager()->switchScreen(new MenuScreen()); + return; + } + host->BootDone(); + host->UpdateDisassembly(); +#ifdef _WIN32 + if (g_Config.bAutoRun) { + Core_EnableStepping(false); + } else { + Core_EnableStepping(true); + } +#endif } } diff --git a/android/jni/NativeApp.cpp b/android/jni/NativeApp.cpp index b64cec1330..b3b9da9ee8 100644 --- a/android/jni/NativeApp.cpp +++ b/android/jni/NativeApp.cpp @@ -36,6 +36,7 @@ #include "ui/screen.h" #include "ui/ui.h" +#include "base/mutex.h" #include "FileUtil.h" #include "LogManager.h" #include "../../Core/PSPMixer.h" @@ -60,6 +61,12 @@ ScreenManager *screenManager; std::string config_filename; std::string game_title; +recursive_mutex pendingMutex; +static bool isMessagePending; +static std::string pendingMessage; +static std::string pendingValue; + + class AndroidLogger : public LogListener { public: @@ -149,7 +156,7 @@ int NativeMix(short *audio, int num_samples) else { //memset(audio, 0, numSamples * 2); - return num_samples; + return 0; } } @@ -168,7 +175,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co { EnableFZ(); std::string user_data_path = savegame_directory; - + isMessagePending = false; // We want this to be FIRST. #ifdef BLACKBERRY // Packed assets are included in app/native/ dir @@ -362,6 +369,14 @@ void NativeRender() void NativeUpdate(InputState &input) { + { + lock_guard lock(pendingMutex); + if (isMessagePending) { + screenManager->sendMessage(pendingMessage.c_str(), pendingValue.c_str()); + isMessagePending = false; + } + } + UIUpdateMouse(0, input.pointer_x[0], input.pointer_y[0], input.pointer_down[0]); screenManager->update(input); } @@ -394,7 +409,13 @@ void NativeTouch(int finger, float x, float y, double time, TouchEvent event) void NativeMessageReceived(const char *message, const char *value) { - screenManager->sendMessage(message, value); + // We can only have one message queued. + lock_guard lock(pendingMutex); + if (!isMessagePending) { + pendingMessage = message; + pendingValue = value; + isMessagePending = true; + } } void NativeShutdownGraphics() diff --git a/ios/AudioEngine.mm b/ios/AudioEngine.mm index aeb187cbe5..818e8cbe5e 100644 --- a/ios/AudioEngine.mm +++ b/ios/AudioEngine.mm @@ -19,7 +19,7 @@ static volatile BOOL done = 0; #define SAMPLE_SIZE 44100 static short stream[SAMPLE_SIZE]; -int NativeMixCount(short *audio, int num_samples); +int NativeMix(short *audio, int num_samples); @interface AudioEngine () @@ -124,7 +124,7 @@ int NativeMixCount(short *audio, int num_samples); { size_t frames_ready; if (![self playing]) - frames_ready = NativeMixCount(stream, SAMPLE_SIZE / 2); + frames_ready = NativeMix(stream, SAMPLE_SIZE / 2); else frames_ready = 0; diff --git a/native b/native index a47c3b465e..4f5a60d82b 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit a47c3b465eb2a37f817dd0950cec8cd81375a2db +Subproject commit 4f5a60d82b38dbb609084782211a272b9e4e53fb