From 37878bd4cebc0de5a18ef8f3d8b6ec575752fc9a Mon Sep 17 00:00:00 2001 From: aliaspider Date: Thu, 5 Jun 2014 00:17:37 +0100 Subject: [PATCH] (PSP) implemented salamander and added support for switching between cores. --- Makefile.psp1 | 6 +- Makefile.psp1.salamander | 34 ++++ frontend/platform/platform_psp.c | 160 +++++++++++++++--- input/psp_input.c | 4 +- psp1/kernelFunctionsPrx/Makefile | 2 +- psp1/kernelFunctionsPrx/kernelFunctions.h | 15 -- ...rnelFunctions.exp => kernel_functions.exp} | 6 +- psp1/kernelFunctionsPrx/kernel_functions.h | 17 ++ psp1/kernelFunctionsPrx/main.c | 21 ++- 9 files changed, 211 insertions(+), 54 deletions(-) create mode 100644 Makefile.psp1.salamander delete mode 100644 psp1/kernelFunctionsPrx/kernelFunctions.h rename psp1/kernelFunctionsPrx/{kernelFunctions.exp => kernel_functions.exp} (74%) create mode 100644 psp1/kernelFunctionsPrx/kernel_functions.h diff --git a/Makefile.psp1 b/Makefile.psp1 index 4ada315639..1f5fc70b61 100644 --- a/Makefile.psp1 +++ b/Makefile.psp1 @@ -20,7 +20,7 @@ RARCH_DEFINES = -DPSP -D_MIPS_ARCH_ALLEGREX1 -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_Z LIBDIR = LDFLAGS = -LIBS = -lretro_psp1 -lstdc++ -lpspgu -lpspgum -lm -lpspaudio -lpspfpu -lpsppower -lpsprtc +LIBS = -lretro_psp1 -lstdc++ -lpspgu -lpspgum -lm -lpspaudio -lpspfpu -lpsppower -lpsprtc ifeq ($(HAVE_THREADS), 1) RARCH_DEFINES += -DHAVE_THREADS @@ -31,7 +31,7 @@ ifeq ($(HAVE_FILE_LOGGER), 1) CFLAGS += -DHAVE_FILE_LOGGER endif -ifeq ($(HAVE_KERNEL_RX), 1) +ifeq ($(HAVE_KERNEL_PRX), 1) CFLAGS += -DHAVE_KERNEL_PRX endif @@ -41,7 +41,7 @@ CFLAGS += $(RARCH_DEFINES) EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = RetroArch PSP1 -PSP_OBJECTS = griffin/griffin.o psp1/kernelFunctions.o +PSP_OBJECTS = griffin/griffin.o psp1/kernel_functions.o OBJS = $(PSP_OBJECTS) diff --git a/Makefile.psp1.salamander b/Makefile.psp1.salamander new file mode 100644 index 0000000000..059e0aa4e4 --- /dev/null +++ b/Makefile.psp1.salamander @@ -0,0 +1,34 @@ +BUILD_PRX = 1 +DEBUG = 0 + +TARGET = retroarchpsp_salamander + +ifeq ($(DEBUG), 1) + OPTIMIZE_LV := -O0 -g +else + OPTIMIZE_LV := -O2 -g +endif + +INCDIR = $(PSPPATH)/include +CFLAGS = $(OPTIMIZE_LV) -G0 -std=gnu99 -ffast-math +ASFLAGS = $(CFLAGS) + +RARCH_DEFINES = -DPSP -DIS_SALAMANDER -DRARCH_CONSOLE -DRARCH_INTERNAL + +LIBDIR = +LDFLAGS = +LIBS = -lstdc++ -lm + +ifeq ($(HAVE_FILE_LOGGER), 1) +CFLAGS += -DHAVE_FILE_LOGGER +endif + +CFLAGS += $(RARCH_DEFINES) + +EXTRA_TARGETS = EBOOT.PBP +PSP_EBOOT_TITLE = RetroArch PSP1 + +OBJS = frontend/frontend_salamander.o frontend/frontend_context.o frontend/platform/platform_null.o file_path.o compat/compat.o conf/config_file.o psp1/kernel_functions.o + +PSPSDK=$(shell psp-config --pspsdk-path) +include $(PSPSDK)/lib/build.mak diff --git a/frontend/platform/platform_psp.c b/frontend/platform/platform_psp.c index 1193f4389e..38e307b21e 100644 --- a/frontend/platform/platform_psp.c +++ b/frontend/platform/platform_psp.c @@ -26,24 +26,75 @@ #include #include "../../psp/sdk_defines.h" +#include "../../file.h" + +#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) +#include "../../psp1/kernel_functions.h" +#endif PSP_MODULE_INFO("RetroArch PSP", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER|THREAD_ATTR_VFPU); PSP_HEAP_SIZE_MAX(); -static int exit_callback(int arg1, int arg2, void *common) -{ - g_extern.verbose = false; +char eboot_path[512]; -#ifdef HAVE_FILE_LOGGER - if (g_extern.log_file) - fclose(g_extern.log_file); - g_extern.log_file = NULL; +#ifdef IS_SALAMANDER +#include "../../file_ext.h" + +char libretro_path[512]; + +static void find_first_libretro_core(char *first_file, + size_t size_of_first_file, const char *dir, + const char * ext); +static void find_and_set_first_file(void) +{ + //Last fallback - we'll need to start the first executable file + // we can find in the RetroArch cores directory + + char first_file[PATH_MAX]; + find_first_libretro_core(first_file, sizeof(first_file), default_paths.core_dir, EXT_EXECUTABLES); + + if(first_file) + { + fill_pathname_join(libretro_path, default_paths.core_dir, first_file, sizeof(libretro_path)); + RARCH_LOG("libretro_path now set to: %s.\n", libretro_path); + } + else + RARCH_ERR("Failed last fallback - RetroArch Salamander will exit.\n"); +} + +static void frontend_psp_salamander_init(void) +{ + //normal executable loading path + char tmp_str[PATH_MAX]; + bool config_file_exists = false; + + if (path_file_exists(default_paths.config_path)) + config_file_exists = true; + + if (config_file_exists) + { + config_file_t * conf = config_file_new(default_paths.config_path); + config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); + config_file_free(conf); + strlcpy(libretro_path, tmp_str, sizeof(libretro_path)); + } + + if (!config_file_exists || !strcmp(libretro_path, "")) + find_and_set_first_file(); + else + RARCH_LOG("Start [%s] found in retroarch.cfg.\n", libretro_path); + + if (!config_file_exists) + { + config_file_t *new_conf = config_file_new(NULL); + config_set_string(new_conf, "libretro_path", libretro_path); + config_file_write(new_conf, default_paths.config_path); + config_file_free(new_conf); + } +} #endif - sceKernelExitGame(); - return 0; -} static void frontend_psp_get_environment_settings(int *argc, char *argv[], void *args, void *params_data) @@ -59,6 +110,8 @@ static void frontend_psp_get_environment_settings(int *argc, char *argv[], #endif #endif + strlcpy(eboot_path, argv[0], sizeof(eboot_path)); + fill_pathname_basedir(default_paths.port_dir, argv[0], sizeof(default_paths.port_dir)); RARCH_LOG("port dir: [%s]\n", default_paths.port_dir); @@ -97,6 +150,33 @@ static void frontend_psp_get_environment_settings(int *argc, char *argv[], } } +static void frontend_psp_deinit(void *data) +{ + (void)data; +#ifndef IS_SALAMANDER + g_extern.verbose = false; +#endif + +#ifdef HAVE_FILE_LOGGER + if (g_extern.log_file) + fclose(g_extern.log_file); + g_extern.log_file = NULL; +#endif +} + +static void frontend_psp_shutdown(bool unused) +{ + (void)unused; + sceKernelExitGame(); +} + +static int exit_callback(int arg1, int arg2, void *common) +{ + frontend_psp_deinit(NULL); + frontend_psp_shutdown(false); + return 0; +} + int callback_thread(SceSize args, void *argp) { int cbid = sceKernelCreateCallback("Exit callback", exit_callback, NULL); @@ -118,6 +198,7 @@ static int setup_callback(void) static void frontend_psp_init(void *data) { +#ifndef IS_SALAMANDER (void)data; //initialize debug screen pspDebugScreenInit(); @@ -127,16 +208,57 @@ static void frontend_psp_init(void *data) pspFpuSetEnable(0);//disable FPU exceptions scePowerSetClockFrequency(333,333,166); +#endif -#ifdef HAVE_KERNEL_PRX - pspSdkLoadStartModule("kernelFunctions.prx", PSP_MEMORY_PARTITION_KERNEL); +#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) + pspSdkLoadStartModule("kernel_functions.prx", PSP_MEMORY_PARTITION_KERNEL); #endif } -static void frontend_psp_deinit(void *data) + + +static void frontend_psp_exec(const char *path, bool should_load_game) { - (void)data; - sceKernelExitGame(); +#if defined(HAVE_KERNEL_PRX) || defined(IS_SALAMANDER) + + char argp[512]; + SceSize args = 0; + + argp[0] = '\0'; + strlcpy(argp, eboot_path, sizeof(argp)); + args = strlen(argp) + 1; + +#ifndef IS_SALAMANDER + if (should_load_game && g_extern.fullpath[0] != '\0') + { + argp[args] = '\0'; + strlcat(argp + args, g_extern.fullpath, sizeof(argp) - args); + args += strlen(argp + args) + 1; + } +#endif + + RARCH_LOG("Attempt to load executable: [%s].\n", path); + + exitspawn_kernel(path, args, argp); + +#endif +} + + +static void frontend_psp_exitspawn(void) +{ +#ifdef IS_SALAMANDER + frontend_psp_exec(libretro_path, false); +#else + char core_launch[256]; + + strlcpy(core_launch, g_settings.libretro, sizeof(core_launch)); + bool should_load_game = false; + if (g_extern.lifecycle_state & (1ULL << MODE_EXITSPAWN_START_GAME)) + should_load_game = true; + + frontend_psp_exec(core_launch, should_load_game); +#endif } static int frontend_psp_get_rating(void) @@ -148,14 +270,14 @@ const frontend_ctx_driver_t frontend_ctx_psp = { frontend_psp_get_environment_settings, /* get_environment_settings */ frontend_psp_init, /* init */ frontend_psp_deinit, /* deinit */ - NULL, /* exitspawn */ + frontend_psp_exitspawn, /* exitspawn */ NULL, /* process_args */ NULL, /* process_events */ - NULL, /* exec */ - NULL, /* shutdown */ + frontend_psp_exec, /* exec */ + frontend_psp_shutdown, /* shutdown */ frontend_psp_get_rating, /* get_rating */ "psp", #ifdef IS_SALAMANDER - NULL, + frontend_psp_salamander_init, #endif }; diff --git a/input/psp_input.c b/input/psp_input.c index ed9e0d06aa..43523f39c9 100644 --- a/input/psp_input.c +++ b/input/psp_input.c @@ -31,7 +31,7 @@ #include "../libretro.h" #include "../general.h" #ifdef HAVE_KERNEL_PRX -#include "../psp1/kernelFunctions.h" +#include "../psp1/kernel_functions.h" #endif enum { @@ -132,7 +132,7 @@ static void psp_input_poll(void *data) sceCtrlSetSamplingMode(DEFAULT_SAMPLING_MODE); ret = CtrlPeekBufferPositive(0, &state_tmp, 1); #ifdef HAVE_KERNEL_PRX - state_tmp.Buttons = (state_tmp.Buttons&0x0000FFFF)|(readSystemButtons()&0xFFFF0000); + state_tmp.Buttons = (state_tmp.Buttons&0x0000FFFF)|(read_system_buttons()&0xFFFF0000); #endif (void)ret; diff --git a/psp1/kernelFunctionsPrx/Makefile b/psp1/kernelFunctionsPrx/Makefile index ab48cd5123..b417ccb4f2 100644 --- a/psp1/kernelFunctionsPrx/Makefile +++ b/psp1/kernelFunctionsPrx/Makefile @@ -1,4 +1,4 @@ -TARGET = kernelFunctions +TARGET = kernel_functions OBJS = main.o PSP_FW_VERSION = 150 diff --git a/psp1/kernelFunctionsPrx/kernelFunctions.h b/psp1/kernelFunctionsPrx/kernelFunctions.h deleted file mode 100644 index dd82531bff..0000000000 --- a/psp1/kernelFunctionsPrx/kernelFunctions.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SYSTEMBUTTONS_PRX_H -#define SYSTEMBUTTONS_PRX_H - -#ifdef __cplusplus -extern "C" { -#endif - -unsigned int readSystemButtons(void); -void loadGame( const char* fileName, void * argp); - -#ifdef __cplusplus -} -#endif - -#endif /* SYSTEMBUTTONS_PRX_H */ diff --git a/psp1/kernelFunctionsPrx/kernelFunctions.exp b/psp1/kernelFunctionsPrx/kernel_functions.exp similarity index 74% rename from psp1/kernelFunctionsPrx/kernelFunctions.exp rename to psp1/kernelFunctionsPrx/kernel_functions.exp index c3d6232941..14e8d4c031 100644 --- a/psp1/kernelFunctionsPrx/kernelFunctions.exp +++ b/psp1/kernelFunctionsPrx/kernel_functions.exp @@ -8,9 +8,9 @@ PSP_EXPORT_FUNC_HASH(module_start) PSP_EXPORT_VAR_HASH(module_info) PSP_EXPORT_END -PSP_EXPORT_START(kernelFunctions, 0, 0x4001) -PSP_EXPORT_FUNC(readSystemButtons) -PSP_EXPORT_FUNC(loadGame) +PSP_EXPORT_START(kernel_functions, 0, 0x4001) +PSP_EXPORT_FUNC(read_system_buttons) +PSP_EXPORT_FUNC(exitspawn_kernel) PSP_EXPORT_END PSP_END_EXPORTS diff --git a/psp1/kernelFunctionsPrx/kernel_functions.h b/psp1/kernelFunctionsPrx/kernel_functions.h new file mode 100644 index 0000000000..52cec35adb --- /dev/null +++ b/psp1/kernelFunctionsPrx/kernel_functions.h @@ -0,0 +1,17 @@ +#ifndef KERNEL_FUNCTIONS_PRX_H +#define KERNEL_FUNCTIONS_PRX_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +unsigned int read_system_buttons(void); +void exitspawn_kernel( const char* fileName, SceSize args, void * argp); + +#ifdef __cplusplus +} +#endif + +#endif /* SYSTEMBUTTONS_PRX_H */ diff --git a/psp1/kernelFunctionsPrx/main.c b/psp1/kernelFunctionsPrx/main.c index e9cf9713f8..ae2774d382 100644 --- a/psp1/kernelFunctionsPrx/main.c +++ b/psp1/kernelFunctionsPrx/main.c @@ -7,15 +7,15 @@ #include #include -PSP_MODULE_INFO("kernelFunctions", PSP_MODULE_KERNEL, 0, 0); +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; +static SceUID main_thread_id; -static int mainThread(SceSize args, void *argp) +static int main_thread(SceSize args, void *argp) { SceCtrlData paddata; @@ -34,20 +34,19 @@ static int mainThread(SceSize args, void *argp) } -unsigned int readSystemButtons(void) +unsigned int read_system_buttons(void) { return buttons; } -void loadGame(const char* fileName, void * argp){ +void exitspawn_kernel( const char* fileName, SceSize args, void * argp){ thread_active = 0; struct SceKernelLoadExecVSHParam game_param; - pspDebugScreenClear(); memset(&game_param,0,sizeof(game_param)); game_param.size = sizeof(game_param); - game_param.args = strlen(argp)+1; + game_param.args = args; game_param.argp = argp; game_param.key = "game"; game_param.vshmain_args_size = 0; @@ -68,10 +67,10 @@ int module_start(SceSize args, void *argp) buttons = 0; thread_active = 0; - main_thread = sceKernelCreateThread("main Thread", mainThread, 0x11, 0x200, 0, NULL); + main_thread_id = sceKernelCreateThread("main Thread", main_thread, 0x11, 0x200, 0, NULL); if (main_thread >= 0) - sceKernelStartThread(main_thread, 0, 0); + sceKernelStartThread(main_thread_id, 0, 0); return 0; } @@ -79,10 +78,10 @@ int module_start(SceSize args, void *argp) int module_stop(void) { - if (main_thread >= 0) + if (main_thread_id >= 0) { thread_active = 0; - sceKernelWaitThreadEnd(main_thread, NULL); + sceKernelWaitThreadEnd(main_thread_id, NULL); } return 0; }