summaryrefslogtreecommitdiff
path: root/libretro.c
diff options
context:
space:
mode:
authorDavid Guillen Fandos2021-03-08 18:44:03 +0100
committerDavid Guillen Fandos2021-03-08 18:44:03 +0100
commit56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e (patch)
treecf3b14a8d1bc593248398d0c544251ea8987b40e /libretro.c
parent02e35339ee89f92d346d290c24497bbbae59ea79 (diff)
downloadpicogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.tar.gz
picogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.tar.bz2
picogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.zip
Remove libco
This removes libco and all the usages of it (+pthreads). Rewired all dynarecs and interpreter to return after every frame so that libretro can process events. This required to make dynarec re-entrant. Dynarecs were updated to check for new frame on every update (IRQ, cycle exhaustion, I/O write, etc). The performance impact of doing so should be minimal (and definitely outweight the libco gains). While at it, fixed small issues to get a bit more perf: arm dynarec was not idling correctly, mips was using stack when not needed, etc. Tested on PSP (mips), OGA (armv7), Linux (x86 and interpreter). Not tested on Android though.
Diffstat (limited to 'libretro.c')
-rw-r--r--libretro.c87
1 files changed, 7 insertions, 80 deletions
diff --git a/libretro.c b/libretro.c
index 397cca2..165600e 100644
--- a/libretro.c
+++ b/libretro.c
@@ -4,8 +4,6 @@
#include <string.h>
#include <stdint.h>
#include "common.h"
-#include "libco.h"
-#include "retro_emu_thread.h"
#include "libretro.h"
#include "libretro_core_options.h"
#include "memmap.h"
@@ -76,10 +74,6 @@ static retro_environment_t environ_cb;
struct retro_perf_callback perf_cb;
-#if defined(USE_LIBCO)
-static cothread_t main_thread;
-static cothread_t cpu_thread;
-#endif
int dynarec_enable;
int use_libretro_save_method = 0;
@@ -95,58 +89,6 @@ static void (*video_post_process)(void) = NULL;
static bool post_process_cc = false;
static bool post_process_mix = false;
-void switch_to_main_thread(void)
-{
-#if defined(USE_LIBCO)
- co_switch(main_thread);
-#else
- retro_switch_thread();
-#endif
-}
-
-static inline void switch_to_cpu_thread(void)
-{
-#if defined(USE_LIBCO)
- co_switch(cpu_thread);
-#else
- retro_switch_thread();
-#endif
-}
-
-#if defined(USE_LIBCO)
-static void cpu_thread_entry(void)
-{
-#ifdef HAVE_DYNAREC
- if (dynarec_enable)
- execute_arm_translate(execute_cycles);
-#endif
- execute_arm(execute_cycles);
-}
-#endif
-
-static inline void init_context_switch(void)
-{
-#if defined(USE_LIBCO)
- main_thread = co_active();
- cpu_thread = co_create(0x20000, cpu_thread_entry);
-#else
- if (!retro_init_emu_thread(dynarec_enable, execute_cycles))
- if (log_cb)
- log_cb(RETRO_LOG_ERROR, "[gpSP]: Failed to initialize emulation thread!\n");
-#endif
-}
-
-static inline void deinit_context_switch(void)
-{
-#if defined(USE_LIBCO)
- co_delete(cpu_thread);
-#else
- retro_cancel_emu_thread();
- retro_join_emu_thread();
- retro_deinit_emu_thread();
-#endif
-}
-
#if defined(PSP)
static uint32_t next_pow2(uint32_t v)
{
@@ -649,12 +591,8 @@ void retro_set_controller_port_device(unsigned port, unsigned device) {}
void retro_reset(void)
{
- deinit_context_switch();
-
update_backup();
reset_gba();
-
- init_context_switch();
}
size_t retro_serialize_size(void)
@@ -930,8 +868,6 @@ bool retro_load_game(const struct retro_game_info* info)
reset_gba();
- init_context_switch();
-
set_memory_descriptors();
return true;
@@ -945,7 +881,6 @@ bool retro_load_game_special(unsigned game_type,
void retro_unload_game(void)
{
- deinit_context_switch();
update_backup();
}
@@ -1019,20 +954,6 @@ void retro_run(void)
{
bool updated = false;
-#if !defined(USE_LIBCO)
- if (!retro_is_emu_thread_initialized())
- {
- environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL);
- return;
- }
- if (retro_emu_thread_exited())
- {
- environ_cb(RETRO_ENVIRONMENT_SHUTDOWN, NULL);
- retro_join_emu_thread();
- return;
- }
-#endif
-
update_input();
input_poll_cb();
@@ -1107,7 +1028,13 @@ void retro_run(void)
update_audio_latency = false;
}
- switch_to_cpu_thread();
+ /* This runs just a frame */
+ #ifdef HAVE_DYNAREC
+ if (dynarec_enable)
+ execute_arm_translate(execute_cycles);
+ else
+ #endif
+ execute_arm(execute_cycles);
render_audio();
video_run();