From e33f1d37f23b4e38cd01e23bf80ad658c69badd9 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 24 Feb 2019 12:31:27 -0800 Subject: [PATCH] PSP2: Fix file descriptors dying on suspend (fixes #1123) --- CHANGES | 1 + src/feature/gui/gui-runner.c | 12 +++++++++++- src/platform/psp2/main.c | 3 ++- src/platform/psp2/psp2-context.c | 16 ++++++++++++++++ src/platform/psp2/psp2-context.h | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 754f9a28f..35624b77f 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,7 @@ Bugfixes: - GBA: Fix video timing when skipping BIOS (fixes mgba.io/i/1318) - 3DS: Work around menu freezing (fixes mgba.io/i/1294) - GBA DMA: Fix invalid DMA handling (fixes mgba.io/i/1301) + - PSP2: Fix file descriptors dying on suspend (fixes mgba.io/i/1123) Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index 0afbd355e..50c9dea42 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -271,7 +271,17 @@ static void _log(struct mLogger* logger, int category, enum mLogLevel level, con if (len >= sizeof(log2)) { len = sizeof(log2) - 1; } - guiLogger->vf->write(guiLogger->vf, log2, len); + if (guiLogger->vf->write(guiLogger->vf, log2, len) < 0) { + char path[PATH_MAX]; + mCoreConfigDirectory(path, PATH_MAX); + strncat(path, PATH_SEP "log", PATH_MAX - strlen(path)); + guiLogger->vf->close(guiLogger->vf); + guiLogger->vf = VFileOpen(path, O_CREAT | O_WRONLY | O_APPEND); + if (guiLogger->vf->write(guiLogger->vf, log2, len) < 0) { + guiLogger->vf->close(guiLogger->vf); + guiLogger->vf = NULL; + } + } } void mGUIRun(struct mGUIRunner* runner, const char* path) { diff --git a/src/platform/psp2/main.c b/src/platform/psp2/main.c index 8060d26ae..f5843a911 100644 --- a/src/platform/psp2/main.c +++ b/src/platform/psp2/main.c @@ -160,7 +160,8 @@ int main() { .unpaused = mPSP2Unpaused, .incrementScreenMode = mPSP2IncrementScreenMode, .setFrameLimiter = mPSP2SetFrameLimiter, - .pollGameInput = mPSP2PollInput + .pollGameInput = mPSP2PollInput, + .running = mPSP2SystemPoll }; sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START); diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index 41e3a4a11..98f44934c 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,9 @@ #define RUMBLE_PWM 8 #define CDRAM_ALIGN 0x40000 +mLOG_DECLARE_CATEGORY(GUI_PSP2); +mLOG_DEFINE_CATEGORY(GUI_PSP2, "Vita", "gui.psp2"); + static enum ScreenMode { SM_BACKDROP, SM_PLAIN, @@ -539,6 +543,18 @@ void mPSP2IncrementScreenMode(struct mGUIRunner* runner) { mCoreConfigSetUIntValue(&runner->config, "screenMode", screenMode); } +bool mPSP2SystemPoll(struct mGUIRunner* runner) { + SceAppMgrSystemEvent event; + if (sceAppMgrReceiveSystemEvent(&event) < 0) { + return true; + } + if (event.systemEvent == SCE_APPMGR_SYSTEMEVENT_ON_RESUME) { + mLOG(GUI_PSP2, INFO, "Suspend detected, reloading save"); + mCoreAutoloadSave(runner->core); + } + return true; +} + __attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) { printf("ASSERT FAILED: %s in %s at %s:%i\n", expr, func, file, line); exit(1); diff --git a/src/platform/psp2/psp2-context.h b/src/platform/psp2/psp2-context.h index 28a403ba3..389f9f534 100644 --- a/src/platform/psp2/psp2-context.h +++ b/src/platform/psp2/psp2-context.h @@ -25,5 +25,6 @@ void mPSP2DrawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsig void mPSP2IncrementScreenMode(struct mGUIRunner* runner); void mPSP2SetFrameLimiter(struct mGUIRunner* runner, bool limit); uint16_t mPSP2PollInput(struct mGUIRunner* runner); +bool mPSP2SystemPoll(struct mGUIRunner* runner); #endif