diff --git a/.github/workflows/PSP.yml b/.github/workflows/PSP.yml new file mode 100644 index 0000000000..b0f1ce51f5 --- /dev/null +++ b/.github/workflows/PSP.yml @@ -0,0 +1,44 @@ +name: CI PSP + +on: + push: + pull_request: + repository_dispatch: + types: [run_build] + +jobs: + build: + runs-on: ubuntu-latest + container: + image: git.libretro.com:5050/libretro-infrastructure/libretro-build-psp:latest + options: --user root + + steps: + - uses: actions/checkout@v2 + + - name: Compile bootstrap + run: | + cd bootstrap/psp1/kernel_functions_prx + make -j$(getconf _NPROCESSORS_ONLN) clean + make -j$(getconf _NPROCESSORS_ONLN) + + - name: Compile Salamander + run: | + make -f Makefile.psp1.salamander -j$(getconf _NPROCESSORS_ONLN) clean + make -f Makefile.psp1.salamander -j$(getconf _NPROCESSORS_ONLN) + + - name: Compile RA + run: | + make -f Makefile.psp1 -j$(getconf _NPROCESSORS_ONLN) clean + make -f Makefile.psp1 -j$(getconf _NPROCESSORS_ONLN) HAVE_STATIC_DUMMY=1 + + - name: Get short SHA + id: slug + run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)" + + - uses: actions/upload-artifact@v2 + with: + name: RA-PSP-dummy-${{ steps.slug.outputs.sha8 }} + path: | + kernel_functions.prx + EBOOT.PBP diff --git a/Makefile.psp1 b/Makefile.psp1 index e9b0bdf0a0..9134dcb978 100644 --- a/Makefile.psp1 +++ b/Makefile.psp1 @@ -4,8 +4,8 @@ DEBUG ?= 0 HAVE_KERNEL_PRX ?= 1 HAVE_THREADS ?= 1 BIG_STACK ?= 0 -WHOLE_ARCHIVE_LINK ?= 0 LOAD_WITHOUT_CORE_INFO ?= 0 +HAVE_STATIC_DUMMY ?= 0 TARGET = retroarchpsp @@ -15,13 +15,8 @@ else OPTIMIZE_LV := -O3 endif -ifeq ($(WHOLE_ARCHIVE_LINK), 1) - WHOLE_START := -Wl,--whole-archive - WHOLE_END := -Wl,--no-whole-archive -endif - INCDIR = deps deps/stb deps/7zip libretro-common/include libretro-common/include/compat/zlib -CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math -fsingle-precision-constant +CFLAGS = $(OPTIMIZE_LV) -ffast-math -fsingle-precision-constant ASFLAGS = $(CFLAGS) RARCH_DEFINES = -DPSP \ @@ -51,14 +46,21 @@ RARCH_DEFINES = -DPSP \ -DHAVE_CORE_INFO_CACHE LIBDIR = -LDFLAGS = -LIBS = $(WHOLE_START) -lretro_psp1 $(WHOLE_END) -lstdc++ -lpspgu -lpspgum -lm -lpspaudio -lpspfpu -lpsppower -lpsprtc -lpthread-psp +LDFLAGS = -L$(shell psp-config --psp-prefix) + +ifeq ($(HAVE_STATIC_DUMMY),1) + RARCH_DEFINES += -DHAVE_STATIC_DUMMY +else + LIBS += -lretro_psp1 +endif +LIBS += -lstdc++ -lpspgu -lpspgum -lpspaudio -lpspfpu -lpsppower -lpsprtc -lpthread ifeq ($(HAVE_THREADS), 1) RARCH_DEFINES += -DHAVE_THREADS endif ifeq ($(HAVE_KERNEL_PRX), 1) +OBJS += bootstrap/psp1/kernel_functions.o CFLAGS += -DHAVE_KERNEL_PRX endif @@ -75,9 +77,7 @@ CFLAGS += $(RARCH_DEFINES) EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = RetroArch PSP1 -PSP_OBJECTS = griffin/griffin.o bootstrap/psp1/kernel_functions.o - -OBJS = $(PSP_OBJECTS) +OBJS += griffin/griffin.o PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak @@ -96,3 +96,6 @@ pspsh-run: debug: clean all pspsh-debug run: clean all pspsh-run + +sim: + /Applications/PPSSPPSDL.app/Contents/MacOS/PPSSPPSDL $(shell pwd)/EBOOT.PBP diff --git a/Makefile.psp1.salamander b/Makefile.psp1.salamander index 49ea944c4b..11d797c7ee 100644 --- a/Makefile.psp1.salamander +++ b/Makefile.psp1.salamander @@ -1,5 +1,6 @@ BUILD_PRX = 0 PSP_LARGE_MEMORY = 1 +HAVE_KERNEL_PRX = 1 DEBUG = 0 TARGET = retroarchpsp_salamander @@ -7,18 +8,18 @@ TARGET = retroarchpsp_salamander ifeq ($(DEBUG), 1) OPTIMIZE_LV := -O0 -g else - OPTIMIZE_LV := -O2 + OPTIMIZE_LV := -O3 endif INCDIR = $(PSPPATH)/include libretro-common/include -CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math +CFLAGS = $(OPTIMIZE_LV) -ffast-math -fsingle-precision-constant ASFLAGS = $(CFLAGS) RARCH_DEFINES = -DPSP -DIS_SALAMANDER -DRARCH_CONSOLE LIBDIR = LDFLAGS = -LIBS = -lstdc++ -lm -lpsppower +LIBS = -lstdc++ -lpsppower CFLAGS += $(RARCH_DEFINES) @@ -45,8 +46,12 @@ OBJS = frontend/frontend_salamander.o \ libretro-common/vfs/vfs_implementation.o \ libretro-common/hash/lrc_hash.o \ libretro-common/time/rtime.o \ - verbosity.o \ - bootstrap/psp1/kernel_functions.o + verbosity.o + +ifeq ($(HAVE_KERNEL_PRX), 1) +OBJS += bootstrap/psp1/kernel_functions.o +CFLAGS += -DHAVE_KERNEL_PRX +endif PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak diff --git a/audio/drivers/psp_audio.c b/audio/drivers/psp_audio.c index 6faab4e1d0..211b14014e 100644 --- a/audio/drivers/psp_audio.c +++ b/audio/drivers/psp_audio.c @@ -54,7 +54,7 @@ typedef struct psp_audio SceUID thread; - int rate; + int port; volatile uint16_t read_pos; volatile uint16_t write_pos; @@ -67,22 +67,27 @@ typedef struct psp_audio #define AUDIO_BUFFER_SIZE (1u<<13u) #define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1) +/* Return port used */ +static int configureAudio(unsigned rate) { + int port; +#if defined(VITA) + port = sceAudioOutOpenPort( + SCE_AUDIO_OUT_PORT_TYPE_MAIN, AUDIO_OUT_COUNT, + rate, SCE_AUDIO_OUT_MODE_STEREO); +#elif defined(ORBIS) + port = sceAudioOutOpen(0xff, + SCE_AUDIO_OUT_PORT_TYPE_MAIN, 0, AUDIO_OUT_COUNT, + rate, SCE_AUDIO_OUT_MODE_STEREO); +#else + port = sceAudioSRCChReserve(AUDIO_OUT_COUNT, rate, 2); +#endif + return port; +} + static void audioMainLoop(void *data) { psp_audio_t* psp = (psp_audio_t*)data; -#if defined(VITA) - int port = sceAudioOutOpenPort( - SCE_AUDIO_OUT_PORT_TYPE_MAIN, AUDIO_OUT_COUNT, - psp->rate, SCE_AUDIO_OUT_MODE_STEREO); -#elif defined(ORBIS) - int port = sceAudioOutOpen(0xff, - SCE_AUDIO_OUT_PORT_TYPE_MAIN, 0, AUDIO_OUT_COUNT, - psp->rate, SCE_AUDIO_OUT_MODE_STEREO); -#else - sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2); -#endif - while (psp->running) { bool cond = false; @@ -107,7 +112,7 @@ static void audioMainLoop(void *data) slock_unlock(psp->cond_lock); #if defined(VITA) || defined(ORBIS) - sceAudioOutOutput(port, + sceAudioOutOutput(psp->port, cond ? (psp->zeroBuffer) : (psp->buffer + read_pos_2)); #else @@ -116,14 +121,6 @@ static void audioMainLoop(void *data) #endif } -#if defined(VITA) - sceAudioOutReleasePort(port); -#elif defined(ORBIS) - sceAudioOutClose(port); -#else - sceAudioSRCChRelease(); -#endif - return; } @@ -137,8 +134,9 @@ static void *psp_audio_init(const char *device, if (!psp) return NULL; - (void)device; - (void)latency; + int port = configureAudio(rate); + if (port < 0) + return NULL; #ifdef ORBIS psp->buffer = (uint32_t*) @@ -161,7 +159,7 @@ static void *psp_audio_init(const char *device, psp->read_pos = 0; psp->write_pos = 0; - psp->rate = rate; + psp->port = port; psp->fifo_lock = slock_new(); psp->cond_lock = slock_new(); @@ -197,7 +195,17 @@ static void psp_audio_free(void *data) free(psp->buffer); psp->worker_thread = NULL; free(psp->zeroBuffer); + +#if defined(VITA) + sceAudioOutReleasePort(psp->port); +#elif defined(ORBIS) + sceAudioOutClose(psp->port); +#else + sceAudioSRCChRelease(); +#endif + free(psp); + } static ssize_t psp_audio_write(void *data, const void *buf, size_t size) diff --git a/bootstrap/psp1/kernel_functions_prx/kernel_functions.exp b/bootstrap/psp1/kernel_functions_prx/kernel_functions.exp index 14e8d4c031..dadc1d076c 100644 --- a/bootstrap/psp1/kernel_functions_prx/kernel_functions.exp +++ b/bootstrap/psp1/kernel_functions_prx/kernel_functions.exp @@ -9,7 +9,6 @@ PSP_EXPORT_VAR_HASH(module_info) PSP_EXPORT_END PSP_EXPORT_START(kernel_functions, 0, 0x4001) -PSP_EXPORT_FUNC(read_system_buttons) PSP_EXPORT_FUNC(exitspawn_kernel) PSP_EXPORT_END diff --git a/bootstrap/psp1/kernel_functions_prx/main.c b/bootstrap/psp1/kernel_functions_prx/main.c index 8c26ee560e..c2b93211c1 100644 --- a/bootstrap/psp1/kernel_functions_prx/main.c +++ b/bootstrap/psp1/kernel_functions_prx/main.c @@ -1,49 +1,17 @@ #include #include -#include #include -#include #include -#include PSP_MODULE_INFO("kernel_functions", PSP_MODULE_KERNEL, 0, 0); PSP_MAIN_THREAD_ATTR(0); -static volatile int thread_active; -static unsigned int buttons; -static SceUID main_thread_id; - -static int main_thread(SceSize args, void *argp) -{ - SceCtrlData paddata; - - thread_active = 1; - - while (thread_active) - { - sceCtrlPeekBufferPositive(&paddata, 1); - buttons = paddata.Buttons; - sceKernelDelayThread(1000000/60); - } - - sceKernelExitThread(0); - - return 0; -} - -unsigned int read_system_buttons(void) -{ - return buttons; -} - void exitspawn_kernel(const char *fileName, SceSize args, void *argp) { int k1; struct SceKernelLoadExecVSHParam game_param; - thread_active = 0; - memset(&game_param,0,sizeof(game_param)); game_param.size = sizeof(game_param); @@ -57,34 +25,16 @@ void exitspawn_kernel(const char *fileName, SceSize args, void *argp) game_param.unk5 = 0x10000; k1 = pspSdkSetK1(0); -#if 0 - sceKernelSuspendAllUserThreads(); -#endif sceKernelLoadExecVSHMs2(fileName, &game_param); pspSdkSetK1(k1); } int module_start(SceSize args, void *argp) { - (void)args; - (void)argp; - - buttons = 0; - thread_active = 0; - main_thread_id = sceKernelCreateThread("main Thread", main_thread, 0x11, 0x200, 0, NULL); - - if (main_thread >= 0) - sceKernelStartThread(main_thread_id, 0, 0); - return 0; } int module_stop(void) { - if (main_thread_id >= 0) - { - thread_active = 0; - sceKernelWaitThreadEnd(main_thread_id, NULL); - } return 0; } diff --git a/frontend/drivers/platform_psp.c b/frontend/drivers/platform_psp.c index 751ecc6649..8d12e860d5 100644 --- a/frontend/drivers/platform_psp.c +++ b/frontend/drivers/platform_psp.c @@ -60,11 +60,9 @@ #include "../../paths.h" #include "../../verbosity.h" -#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) -#ifndef VITA +#if defined(PSP) && defined(HAVE_KERNEL_PRX) #include "../../bootstrap/psp1/kernel_functions.h" #endif -#endif #if defined(HAVE_VITAGLES) #include "../../deps/Pigs-In-A-Blanket/include/pib.h" @@ -73,10 +71,6 @@ #ifndef VITA PSP_MODULE_INFO("RetroArch", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER|THREAD_ATTR_VFPU); -#ifdef BIG_STACK -PSP_MAIN_THREAD_STACK_SIZE_KB(4*1024); -#endif -PSP_HEAP_SIZE_MAX(); #endif #ifdef SCE_LIBC_SIZE @@ -241,7 +235,7 @@ static void frontend_psp_shutdown(bool unused) //sceKernelExitProcess(0); return; #else - sceKernelExitGame(); + exit(0); #endif } @@ -309,16 +303,13 @@ static void frontend_psp_init(void *data) #endif -#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) -#ifndef VITA +#if defined(PSP) && defined(HAVE_KERNEL_PRX) pspSdkLoadStartModule("kernel_functions.prx", PSP_MEMORY_PARTITION_KERNEL); #endif -#endif } static void frontend_psp_exec(const char *path, bool should_load_game) { -#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) || defined(VITA) #ifdef IS_SALAMANDER char boot_params[1024]; char core_name[256]; @@ -326,7 +317,7 @@ static void frontend_psp_exec(const char *path, bool should_load_game) char argp[512] = {0}; SceSize args = 0; -#if !defined(VITA) +#if defined(PSP) strlcpy(argp, eboot_path, sizeof(argp)); args = strlen(argp) + 1; #endif @@ -392,10 +383,9 @@ static void frontend_psp_exec(const char *path, bool should_load_game) int ret = sceAppMgrLoadExec(path, args == 0 ? NULL : (char * const*)((const char*[]){argp, 0}), NULL); RARCH_LOG("Attempt to load executable: [%d].\n", ret); } -#else +#elif defined(PSP) && defined(HAVE_KERNEL_PRX) exitspawn_kernel(path, args, argp); #endif -#endif } #ifndef IS_SALAMANDER diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 4b77749abf..2378d69760 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -43,10 +43,6 @@ #include #include -#ifdef HAVE_KERNEL_PRX -#include "../../bootstrap/psp1/kernel_functions.h" -#endif - #include #include "../input_driver.h" diff --git a/input/drivers_joypad/psp_joypad.c b/input/drivers_joypad/psp_joypad.c index 4e602e26ac..8b39d17cda 100644 --- a/input/drivers_joypad/psp_joypad.c +++ b/input/drivers_joypad/psp_joypad.c @@ -322,10 +322,6 @@ static void psp_joypad_poll(void) } } #endif -#ifdef HAVE_KERNEL_PRX - state_tmp.Buttons = (state_tmp.Buttons & 0x0000FFFF) - | (read_system_buttons() & 0xFFFF0000); -#endif pad_state[i] |= (STATE_BUTTON(state_tmp) & PSP_CTRL_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; pad_state[i] |= (STATE_BUTTON(state_tmp) & PSP_CTRL_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; @@ -352,12 +348,6 @@ static void psp_joypad_poll(void) analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = (int16_t)(STATE_ANALOGRX(state_tmp)-128) * 256; analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = (int16_t)(STATE_ANALOGRY(state_tmp)-128) * 256; #endif - -#ifdef HAVE_KERNEL_PRX - if (STATE_BUTTON(state_tmp) & PSP_CTRL_NOTE) - BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE); -#endif - for (j = 0; j < 2; j++) for (k = 0; k < 2; k++) if (analog_state[i][j][k] == -0x8000) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 8660cfa810..0b90b7a7a8 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -1350,11 +1350,8 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort) if (!file) return false; - /* TODO: this is only useful for a few platforms, find which and add ifdef */ -#if !defined(PSP) buf = calloc(1, 0x4000); setvbuf(file, (char*)buf, _IOFBF, 0x4000); -#endif config_file_dump(conf, file, sort); diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h index e5f74d02db..56567e9d09 100644 --- a/libretro-common/include/retro_timers.h +++ b/libretro-common/include/retro_timers.h @@ -83,7 +83,7 @@ static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp) * * Sleeps for a specified amount of milliseconds (@msec). **/ -#if defined(PSP) || defined(VITA) +#if defined(VITA) #define retro_sleep(msec) (sceKernelDelayThread(1000 * (msec))) #elif defined(_3DS) #define retro_sleep(msec) (svcSleepThread(1000000 * (s64)(msec))) diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 7a24a95e86..afd4f0f634 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -460,7 +460,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( if (stream->fp) setvbuf(stream->fp, stream->buf, _IOFBF, bufsize); } -#elif !defined(PSP) if (stream->scheme != VFS_SCHEME_CDROM) { stream->buf = (char*)calloc(1, 0x4000); @@ -890,7 +889,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) { bool is_dir = false; bool is_character_special = false; -#if defined(VITA) || defined(PSP) +#if defined(VITA) /* Vita / PSP */ SceIoStat buf; int dir_ret; @@ -1058,7 +1057,7 @@ int retro_vfs_mkdir_impl(const char *dir) #endif #elif defined(IOS) int ret = mkdir(dir, 0755); -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) int ret = sceIoMkdir(dir, 0777); #elif defined(ORBIS) int ret = orbisMkdir(dir, 0755); @@ -1111,7 +1110,7 @@ struct libretro_vfs_implementation_dir HANDLE directory; bool next; char path[PATH_MAX_LENGTH]; -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) SceUID directory; SceIoDirent entry; #elif defined(__PSL1GHT__) || defined(__PS3__) @@ -1131,7 +1130,7 @@ static bool dirent_check_error(libretro_vfs_implementation_dir *rdir) { #if defined(_WIN32) return (rdir->directory == INVALID_HANDLE_VALUE); -#elif defined(VITA) || defined(PSP) || defined(ORBIS) +#elif defined(VITA) || defined(ORBIS) return (rdir->directory < 0); #elif defined(__PSL1GHT__) || defined(__PS3__) return (rdir->error != FS_SUCCEEDED); @@ -1193,7 +1192,7 @@ libretro_vfs_implementation_dir *retro_vfs_opendir_impl( free(path_wide); #endif -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) rdir->directory = sceIoDopen(name); #elif defined(_3DS) rdir->directory = !string_is_empty(name) ? opendir(name) : NULL; @@ -1233,7 +1232,7 @@ bool retro_vfs_readdir_impl(libretro_vfs_implementation_dir *rdir) rdir->next = true; return (rdir->directory != INVALID_HANDLE_VALUE); -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) return (sceIoDread(rdir->directory, &rdir->entry) > 0); #elif defined(__PSL1GHT__) || defined(__PS3__) uint64_t nread; @@ -1259,7 +1258,7 @@ const char *retro_vfs_dirent_get_name_impl(libretro_vfs_implementation_dir *rdir if (name) free(name); return (char*)rdir->entry.cFileName; -#elif defined(VITA) || defined(PSP) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__) +#elif defined(VITA) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__) return rdir->entry.d_name; #else if (!rdir || !rdir->entry) @@ -1273,13 +1272,9 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir) #if defined(_WIN32) const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)&rdir->entry; return entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; -#elif defined(PSP) || defined(VITA) - const SceIoDirent *entry = (const SceIoDirent*)&rdir->entry; -#if defined(PSP) - return (entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; #elif defined(VITA) + const SceIoDirent *entry = (const SceIoDirent*)&rdir->entry; return SCE_S_ISDIR(entry->d_stat.st_mode); -#endif #elif defined(__PSL1GHT__) || defined(__PS3__) sysFSDirent *entry = (sysFSDirent*)&rdir->entry; return (entry->d_type == FS_TYPE_DIR); @@ -1317,7 +1312,7 @@ int retro_vfs_closedir_impl(libretro_vfs_implementation_dir *rdir) #if defined(_WIN32) if (rdir->directory != INVALID_HANDLE_VALUE) FindClose(rdir->directory); -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) sceIoDclose(rdir->directory); #elif defined(__PSL1GHT__) || defined(__PS3__) rdir->error = sysFsClosedir(rdir->directory);