Skip to content

Commit

Permalink
Experimental: Libretro: Pause FreeJ2ME when libretro pauses as well
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AShiningRay committed Nov 25, 2024
1 parent b6d424b commit 6da0226
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libretro/freej2me_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: These are undocumented but used by Win32's Resource Monitor. Are also much easier to understand compared to its alternatives
if(pause) { NtSuspendProcess(javaProcess.hProcess); }
else { NtSuspendProcess(javaProcess.hProcess); }
#endif
}

void retro_run(void)
{
int i = 0;
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6da0226

Please sign in to comment.