diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d7fcc73..4243ca8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,7 +62,11 @@ include: # Nintendo Switch - project: 'libretro-infrastructure/ci-templates' file: '/libnx-static.yml' - + + # PlayStation 2 + - project: 'libretro-infrastructure/ci-templates' + file: '/ps2-static.yml' + # PlayStation Portable - project: 'libretro-infrastructure/ci-templates' file: '/psp-static.yml' @@ -140,6 +144,12 @@ android-x86: - .core-defs ################################### CONSOLES ################################# +# PlayStation 2 +libretro-build-ps2: + extends: + - .libretro-ps2-static-retroarch-master + - .core-defs + # PlayStation Portable libretro-build-psp: extends: diff --git a/Makefile b/Makefile index d8e4b9a..7ec236e 100644 --- a/Makefile +++ b/Makefile @@ -179,9 +179,19 @@ else ifeq ($(platform), psl1ght) STATIC_LINKING = 1 HAVE_COMPAT = 1 +# PS2 +else ifeq ($(platform), ps2) + TARGET := $(TARGET_NAME)_libretro_$(platform).a + CC = mips64r5900el-ps2-elf-gcc$(EXE_EXT) + AR = mips64r5900el-ps2-elf-ar$(EXE_EXT) + PLATFORM_DEFINES := -DPS2 -D_EE -DABGR1555 -G0 -O3 + STATIC_LINKING = 1 + HAVE_COMPAT = 1 + EXTRA_INCLUDES := -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include + # PSP else ifeq ($(platform), psp1) - TARGET := $(TARGET_NAME)_libretro_psp1.a + TARGET := $(TARGET_NAME)_libretro_$(platform).a CC = psp-gcc$(EXE_EXT) AR = psp-ar$(EXE_EXT) PLATFORM_DEFINES := -DPSP @@ -489,7 +499,7 @@ include Makefile.common HEADERS += $(ROMS:.rom=.h) $(SNAPS:.szx=.h) OBJECTS += $(SOURCES_C:.c=.o) $(SOURCES_CXX:.cpp=.o) -INCDIRS := $(EXTRA_INCLUDES) $(INCFLAGS) +INCDIRS := $(INCFLAGS) $(EXTRA_INCLUDES) OBJOUT = -o LINKOUT = -o diff --git a/libretro/config.h b/libretro/config.h index 7571c23..589451f 100644 --- a/libretro/config.h +++ b/libretro/config.h @@ -568,6 +568,10 @@ code using `volatile' can become incorrect without. Disable with care. */ /* #undef volatile */ +#if defined(PS2) +#undef HAVE_CHMOD +#endif + #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 36cd7da..44a65d5 100644 --- a/libretro/libretro-common/libco/libco.c +++ b/libretro/libretro-common/libco/libco.c @@ -29,6 +29,8 @@ void genode_free_secondary_stack(void *stack); #include "ppc.c" #elif defined(__aarch64__) #include "aarch64.c" + #elif defined(PS2) + #include "ps2.c" #elif defined(PSP) #include "psp1.c" #elif defined VITA diff --git a/libretro/libretro-common/libco/ps2.c b/libretro/libretro-common/libco/ps2.c new file mode 100644 index 0000000..3e88cda --- /dev/null +++ b/libretro/libretro-common/libco/ps2.c @@ -0,0 +1,66 @@ +#define LIBCO_C +#include "libco.h" + +#include +#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 int32_t active_thread_id = -1; +extern void *_gp; + +cothread_t co_active() +{ + active_thread_id = GetThreadId(); + 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)); + ee_thread_t thread; + + // u8 threadStack[size/8] __attribute__ ((aligned(16))); + void *threadStack = (void *)malloc(size); + + if ( threadStack== NULL) + { + printf("libco: ERROR: creating threadStack\n"); + return(-1); + } + + thread.stack_size = size; + thread.gp_reg = &_gp; + thread.func = (void *)entrypoint; + thread.stack = threadStack; + thread.option = 0; + thread.initial_priority = 1; + + int32_t new_thread_id = CreateThread(&thread); + if (new_thread_id < 0) + printf("libco: ERROR: creating thread\n"); + + StartThread(new_thread_id, NULL); + *(uint32_t *)handle = new_thread_id; + return handle; +} + +void co_delete(cothread_t handle) +{ + TerminateThread(*(uint32_t *)handle); + DeleteThread(*(uint32_t *)handle); + free(handle); +} + +void co_switch(cothread_t handle) +{ + WakeupThread(*(uint32_t *)handle); + /* Sleep the currently active thread so the new thread can start */ + SleepThread(); +} diff --git a/libretro/libretro-core.h b/libretro/libretro-core.h index 558fff2..3563680 100644 --- a/libretro/libretro-core.h +++ b/libretro/libretro-core.h @@ -59,8 +59,12 @@ extern int pauseg; #ifndef RENDER16B #define RGB565(r, g, b) (((r) << (5+16)) | ((g) << (5+8)) | (b<<5)) #else +#if defined(ABGR1555) +#define RGB565(r, g, b) (((b) << (10)) | ((g) << 5) | (r)) +#else #define RGB565(r, g, b) (((r) << (5+6)) | ((g) << 6) | (b)) #endif +#endif #define uint32 unsigned int #define uint8 unsigned char #endif