diff --git a/Makefile b/Makefile index 78aa343..a67309f 100644 --- a/Makefile +++ b/Makefile @@ -195,16 +195,22 @@ else ifeq ($(platform), psl1ght) else ifeq ($(platform), psp1) TARGET := $(TARGET_NAME)_libretro_psp1.a CC = psp-gcc$(EXE_EXT) - CC_AS = psp-gcc$(EXE_EXT) - CXX = psp-g++$(EXE_EXT) AR = psp-ar$(EXE_EXT) PLATFORM_DEFINES := -DPSP CFLAGS += -G0 - CXXFLAGS += -G0 STATIC_LINKING = 1 HAVE_COMPAT = 1 EXTRA_INCLUDES := -I$(shell psp-config --pspsdk-path)/include +# Vita +else ifeq ($(platform), vita) + EXT=a + TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT) + CC = arm-vita-eabi-gcc$(EXE_EXT) + AR = arm-vita-eabi-ar$(EXE_EXT) + PLATFORM_DEFINES := -DVITA + STATIC_LINKING = 1 + # CTR (3DS) else ifeq ($(platform), ctr) EXT=a @@ -219,15 +225,6 @@ else ifeq ($(platform), ctr) CFLAGS += -D_3DS STATIC_LINKING=1 -# Vita -else ifeq ($(platform), vita) - EXT=a - TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT) - CC = arm-vita-eabi-gcc$(EXE_EXT) - AR = arm-vita-eabi-ar$(EXE_EXT) - PLATFORM_DEFINES := -DVITA - STATIC_LINKING = 1 - # Xbox 360 else ifeq ($(platform), xenon) TARGET := $(TARGET_NAME)_libretro_xenon360.a diff --git a/atari800/src/util.c b/atari800/src/util.c index 2129f26..e12a7a5 100644 --- a/atari800/src/util.c +++ b/atari800/src/util.c @@ -53,6 +53,8 @@ #ifdef VITA #include +#elif defined(PSP) +#include #endif #include "atari.h" @@ -484,7 +486,7 @@ void Util_sleep(double s) #if defined(WIIU) /* no need to sleep on retroarch (we are awake) so bypass it for wiiu */ return; -#elif defined(VITA) +#elif defined(VITA) || defined(PSP) sceKernelDelayThread(1e6 * s); #else diff --git a/libretro/config.h b/libretro/config.h index d241fe3..6452081 100644 --- a/libretro/config.h +++ b/libretro/config.h @@ -577,7 +577,7 @@ code using `volatile' can become incorrect without. Disable with care. */ /* #undef volatile */ -#ifdef VITA +#if defined(VITA) || defined(PSP) #undef HAVE_CHMOD diff --git a/libretro/libretro-common/libco/libco.c b/libretro/libretro-common/libco/libco.c index 8d6f934..cbc995c 100644 --- a/libretro/libretro-common/libco/libco.c +++ b/libretro/libretro-common/libco/libco.c @@ -24,6 +24,8 @@ #include "ppc.c" #elif defined(__aarch64__) #include "aarch64.c" + #elif defined(PSP) + #include "psp1.c" #elif defined VITA #include "scefiber.c" #elif defined(__ARM_EABI__) || defined(__arm__) diff --git a/libretro/libretro-common/libco/psp1.c b/libretro/libretro-common/libco/psp1.c new file mode 100644 index 0000000..45850a4 --- /dev/null +++ b/libretro/libretro-common/libco/psp1.c @@ -0,0 +1,45 @@ +#define LIBCO_C +#include "libco.h" + +#include +#include + +/* Since cothread_t is a void pointer it must contain an address. We can't return a reference to a local variable + * because it would go out of scope, so we create a static variable instead so we can return a reference to it. + */ +static SceUID active_thread_id = 0; + +cothread_t co_active() +{ + active_thread_id = sceKernelGetThreadId(); + return &active_thread_id; +} + +cothread_t co_create(unsigned int size, void (*entrypoint)(void)) +{ + /* Similar scenario as with active_thread_id except there will only be one active_thread_id while there could be many + * new threads each with their own handle, so we create them on the heap instead and delete them manually when they're + * no longer needed in co_delete(). + */ + cothread_t handle = malloc(sizeof(cothread_t)); + + /* SceKernelThreadEntry has a different signature than entrypoint, but in practice this seems to work */ + SceUID new_thread_id = sceKernelCreateThread("cothread", (SceKernelThreadEntry)entrypoint, 0x12, size, 0, NULL); + sceKernelStartThread(new_thread_id, 0, NULL); + + *(SceUID *)handle = new_thread_id; + return handle; +} + +void co_delete(cothread_t handle) +{ + sceKernelTerminateDeleteThread(*(SceUID *)handle); + free(handle); +} + +void co_switch(cothread_t handle) +{ + sceKernelWakeupThread(*(SceUID *)handle); + /* Sleep the currently active thread so the new thread can start */ + sceKernelSleepThread(); +} \ No newline at end of file