From d30fd6393b83d04200ce64c28407f2060457ab4c Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Mon, 25 Nov 2024 15:51:02 -0300 Subject: [PATCH] Experimental: Libretro: Pause FreeJ2ME when libretro pauses as well Doesn't work very well yet, mostly because some JVM subsystems rely on the system's time, and the MIDI Sequencer also has issues resuming. Nonetheless, it's a start, just has to be refined quite a bit, and already works on nearly all of the tested jars without any issues other than midi playback. --- src/libretro/freej2me_libretro.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libretro/freej2me_libretro.c b/src/libretro/freej2me_libretro.c index db5a9b7..55198fe 100755 --- a/src/libretro/freej2me_libretro.c +++ b/src/libretro/freej2me_libretro.c @@ -657,6 +657,19 @@ void retro_unload_game(void) quit(0); } +void pauseFreeJ2ME(bool pause) +{ +#ifdef __linux__ + // Note: Despite being a "kill" function, it really just sends a signal to stop and continue the process here + if(pause) { kill(javaProcess, SIGTSTP); } + else { kill(javaProcess, SIGCONT); } +#elif _WIN32 + // NOTE: Untested, tries to suspend/resume java app's main thread. + if(pause) { SuspendThread(javaProcess.hThread); } + else { ResumeThread(javaProcess.hThread); } +#endif +} + void retro_run(void) { int i = 0; @@ -673,6 +686,8 @@ void retro_run(void) // These are only used if useAnalogAsEntireKeypad is enabled. bool num1pressed = false, num3pressed = false, num7pressed = false, num9pressed = false; + pauseFreeJ2ME(false); + if (Environ(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated_vars) && updated_vars) { check_variables(false); } if(isRunning(javaProcess)) @@ -1059,6 +1074,8 @@ void retro_run(void) else { retro_deinit(); } /* send frame to libretro irrespective of FreeJ2ME running (for error messages) */ Video(frame, frameWidth, frameHeight, sizeof(unsigned int) * frameWidth); + + pauseFreeJ2ME(true); } unsigned retro_get_region(void)