From 9d2a1b5ac4c76634e4b1ee139f079beb195146ca Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 7 Jun 2020 21:00:47 +0200 Subject: [PATCH] Improve dist scripts Improve cores folder Improve WaitTillDeviceIsReady Now every single driver, init and deinit the IRX binaries Improve platform PS2 Make salamander to open proper elf --- Makefile.ps2 | 7 +- Makefile.ps2.salamander | 103 ++++++++++++++++++++++ dist-scripts/dist-cores.sh | 8 +- frontend/drivers/platform_ps2.c | 149 ++++++++++++++++---------------- gfx/drivers/ps2_gfx.c | 1 - input/drivers/ps2_input.c | 2 - ps2/compat_files/ps2_devices.c | 19 ++-- 7 files changed, 196 insertions(+), 93 deletions(-) create mode 100644 Makefile.ps2.salamander diff --git a/Makefile.ps2 b/Makefile.ps2 index 62ada01d33..4ed8c95647 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -6,12 +6,11 @@ HAVE_THREADS = 0 MUTE_WARNINGS = 1 PS2_IP = 192.168.1.150 -TARGET = retroarchps2.elf -TARGET_RELEASE = retroarchps2-release.elf +TARGET = retroarchps2-debug.elf +TARGET_RELEASE = retroarchps2.elf # Compile the IRXs first IRX_DIR = ps2/irx -IRX_FILES = $(wildcard ps2/irx/*.c) ifeq ($(DEBUG), 1) OPTIMIZE_LV := -O0 -g @@ -36,7 +35,7 @@ RARCH_DEFINES += -DHAVE_ZLIB -DHAVE_NO_BUILTINZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHA LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L. # Lib cdvd is needed to get proper time -LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd +LIBS += -lretro_ps2 -lpatches -lpoweroff -lgskit -ldmakit -laudsrv -lpadx -lmtap -lz -lcdvd -lelf-loader ifeq ($(BUILD_FOR_PCSX2), 1) RARCH_DEFINES += -DBUILD_FOR_PCSX2 diff --git a/Makefile.ps2.salamander b/Makefile.ps2.salamander new file mode 100644 index 0000000000..b25103d2ea --- /dev/null +++ b/Makefile.ps2.salamander @@ -0,0 +1,103 @@ +BUILD_FOR_PCSX2 = 0 +DEBUG = 0 +HAVE_FILE_LOGGER = 0 +MUTE_WARNINGS = 1 +PS2_IP = 192.168.1.150 + +TARGET = raboot-debug.elf +TARGET_RELEASE = raboot.elf + +# Compile the IRXs first +IRX_DIR = ps2/irx + +ifeq ($(DEBUG), 1) + OPTIMIZE_LV := -O0 -g + RARCH_DEFINES += -DDEBUG +else + OPTIMIZE_LV := -O3 + LDFLAGS := -s +endif + +ifeq ($(MUTE_WARNINGS), 1) + DISABLE_WARNINGS := -Wno-sign-compare -Wno-unused -Wno-parentheses +endif + +INCDIR = -Ilibretro-common/include +INCDIR += -Ips2/include +CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant +ASFLAGS = $(CFLAGS) + +RARCH_DEFINES += -DPS2 -DIS_SALAMANDER -DRARCH_CONSOLE + +LIBDIR = +LDFLAGS = +LIBS = -lm -lelf-loader -lpatches -lpoweroff + +ifeq ($(BUILD_FOR_PCSX2), 1) +RARCH_DEFINES += -DBUILD_FOR_PCSX2 +endif + +ifeq ($(HAVE_FILE_LOGGER), 1) +CFLAGS += -DHAVE_FILE_LOGGER +endif + +CFLAGS += $(RARCH_DEFINES) + +EE_OBJS = frontend/frontend_salamander.o \ + frontend/frontend_driver.o \ + frontend/drivers/platform_ps2.o \ + libretro-common/file/file_path.o \ + libretro-common/file/file_path_io.o \ + libretro-common/string/stdstring.o \ + libretro-common/lists/string_list.o \ + libretro-common/lists/dir_list.o \ + libretro-common/file/retro_dirent.o \ + libretro-common/encodings/encoding_utf.o \ + libretro-common/compat/fopen_utf8.o \ + libretro-common/compat/compat_strl.o \ + libretro-common/compat/compat_strcasestr.o \ + libretro-common/file/config_file.o \ + libretro-common/streams/file_stream.o \ + libretro-common/vfs/vfs_implementation.o \ + libretro-common/hash/rhash.o \ + libretro-common/time/rtime.o \ + file_path_str.o \ + verbosity.o \ + ps2/compat_files/ps2_devices.o + +# Needed IRX objects +EE_OBJS += $(IRX_DIR)/freesio2_irx.o $(IRX_DIR)/iomanX_irx.o $(IRX_DIR)/cdfs_irx.o +EE_OBJS += $(IRX_DIR)/fileXio_irx.o $(IRX_DIR)/mcman_irx.o $(IRX_DIR)/mcserv_irx.o $(IRX_DIR)/usbd_irx.o +EE_OBJS += $(IRX_DIR)/usbhdfsd_irx.o $(IRX_DIR)/freesd_irx.o $(IRX_DIR)/poweroff_irx.o + +EE_CFLAGS = $(CFLAGS) +EE_CXXFLAGS = $(CFLAGS) +EE_LDFLAGS = $(LDFLAGS) +EE_LIBS = $(LIBS) +EE_ASFLAGS = $(ASFLAGS) +EE_INCS = $(INCDIR) +EE_BIN = $(TARGET) +EE_GPVAL = $(GPVAL) + +all: irxdir $(EE_BIN) + +irxdir: + $(MAKE) -C $(IRX_DIR) + +clean: + rm -f $(EE_BIN) $(EE_OBJS) + $(MAKE) -C $(IRX_DIR) clean + +debug: clean all run + +run: + ps2client -h $(PS2_IP) execee host:$(EE_BIN) + +package: + ps2-packer $(EE_BIN) $(TARGET_RELEASE) + +release: clean all package + +#Include preferences +include $(PS2SDK)/samples/Makefile.pref +include $(PS2SDK)/samples/Makefile.eeglobal_cpp diff --git a/dist-scripts/dist-cores.sh b/dist-scripts/dist-cores.sh index 974df83229..0c8c6f1374 100755 --- a/dist-scripts/dist-cores.sh +++ b/dist-scripts/dist-cores.sh @@ -20,7 +20,7 @@ cd dist-scripts elif [ $PLATFORM = "ps2" ] ; then platform=ps2 -SALAMANDER=NO +SALAMANDER=yes EXT=a mkdir -p ../pkg/${platform}/cores/ @@ -151,6 +151,9 @@ fi # Compile Salamander core if [ $SALAMANDER = "yes" ]; then make -C ../ -f Makefile.${platform}.salamander $OPTS || exit 1 + if [ $PLATFORM = "ps2" ] ; then + mv -f ../raboot.elf ../pkg/${platform}/raboot.PBP + fi if [ $PLATFORM = "psp1" ] ; then mv -f ../EBOOT.PBP ../pkg/${platform}/EBOOT.PBP fi @@ -287,7 +290,7 @@ for f in `ls -v *_${platform}.${EXT}`; do fi fi elif [ $PLATFORM = "ps2" ] ; then - mv -f ../retroarchps2-release.elf ../pkg/${platform}/cores/retroarchps2_${name}.elf + mv -f ../retroarchps2.elf ../pkg/${platform}/cores/${name}_libretro_${platform}.elf elif [ $PLATFORM = "psp1" ] ; then mv -f ../EBOOT.PBP ../pkg/${platform}/cores/${name}_libretro.PBP elif [ $PLATFORM = "vita" ] ; then @@ -330,6 +333,7 @@ for f in `ls -v *_${platform}.${EXT}`; do rm -f ../retroarch_${platform}.elf ../retroarch_${platform}.self ../CORE.SELF elif [ $PLATFORM = "ps2" ] ; then rm -f ../retroarchps2.elf + rm -f ../retroarchps2-debug.elf elif [ $PLATFORM = "psp1" ] ; then rm -f ../retroarchpsp.elf elif [ $PLATFORM = "vita" ] ; then diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 3a4dcfafc8..2096bcaf43 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -13,50 +13,46 @@ */ #include - -#include "../frontend_driver.h" - -#include +#include +#include #include +#include + #include #include #include #include -#include -#include -#include #include #include +#include + +#include +#include + +#include "../frontend_driver.h" +#include "../../defaults.h" +#include "../../file_path_special.h" +#include "../../verbosity.h" +#include -static char eboot_path[512]; -static char user_path[512]; static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE; +static int bootDeviceID; +char cwd[FILENAME_MAX]; static void create_path_names(void) { - char cwd[FILENAME_MAX]; - int bootDeviceID; + char user_path[FILENAME_MAX]; -#if defined(BUILD_FOR_PCSX2) - strlcpy(cwd, rootDevicePath(BOOT_DEVICE_MC0), sizeof(cwd)); -#else - getcwd(cwd, sizeof(cwd)); - bootDeviceID=getBootDeviceID(cwd); - strlcpy(cwd, rootDevicePath(bootDeviceID), sizeof(cwd)); -#endif - strcat(cwd, "RETROARCH"); + strlcpy(user_path, rootDevicePath(bootDeviceID), rootDevicePath(bootDeviceID)); + strcat(user_path, "RETROARCH"); + + // Content in the same folder + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], cwd, + "cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], cwd, + "info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO])); - strlcpy(eboot_path, cwd, sizeof(eboot_path)); - strlcpy(g_defaults.dirs[DEFAULT_DIR_PORT], eboot_path, sizeof(g_defaults.dirs[DEFAULT_DIR_PORT])); - strlcpy(user_path, eboot_path, sizeof(user_path)); - - fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], g_defaults.dirs[DEFAULT_DIR_PORT], - "CORES", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); - fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], g_defaults.dirs[DEFAULT_DIR_PORT], - "INFO", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO])); - - /* user data */ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CHEATS], user_path, "CHEATS", sizeof(g_defaults.dirs[DEFAULT_DIR_CHEATS])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG], user_path, @@ -95,6 +91,20 @@ static void poweroffCallback(void *arg) poweroffShutdown(); } +static void reset_IOP() +{ + SifInitRpc(0); +#if !defined(DEBUG) || defined(BUILD_FOR_PCSX2) + /* Comment this line if you don't wanna debug the output */ + while(!SifIopReset(NULL, 0)){}; +#endif + + while(!SifIopSync()){}; + SifInitRpc(0); + sbv_patch_enable_lmb(); + sbv_patch_disable_prefix_check(); +} + static void frontend_ps2_get_environment_settings(int *argc, char *argv[], void *args, void *params_data) { @@ -103,7 +113,7 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[], #ifndef IS_SALAMANDER if (!string_is_empty(argv[1])) { - static char path[PATH_MAX_LENGTH] = {0}; + static char path[FILENAME_MAX] = {0}; struct rarch_main_wrap *args = (struct rarch_main_wrap*)params_data; @@ -122,7 +132,6 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[], RARCH_LOG("argv[0]: %s\n", argv[0]); RARCH_LOG("argv[1]: %s\n", argv[1]); - RARCH_LOG("argv[2]: %s\n", argv[2]); RARCH_LOG("Auto-start game %s.\n", argv[1]); } @@ -139,18 +148,7 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[], static void frontend_ps2_init(void *data) { - char cwd[FILENAME_MAX]; - int bootDeviceID; - - SifInitRpc(0); -#if !defined(DEBUG) || defined(BUILD_FOR_PCSX2) - /* Comment this line if you don't wanna debug the output */ - while (!SifIopReset(NULL, 0)) { }; -#endif - - while (!SifIopSync()) { }; - SifInitRpc(0); - sbv_patch_enable_lmb(); + reset_IOP(); /* I/O Files */ SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL); @@ -161,21 +159,22 @@ static void frontend_ps2_init(void *data) SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL); SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL); - /* Controllers */ - SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL); - SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL); - /* USB */ SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL); SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL); + /* CDFS */ + SifExecModuleBuffer(&cdfs_irx, size_cdfs_irx, 0, NULL, NULL); + +#ifndef IS_SALAMANDER + /* Controllers */ + SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL); + SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL); + /* Audio */ SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL); SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL); - /* CDVD */ - SifExecModuleBuffer(&cdfs_irx, size_cdfs_irx, 0, NULL, NULL); - /* Initializes audsrv library */ if (audsrv_init()) { RARCH_ERR("audsrv library not initalizated\n"); @@ -192,48 +191,52 @@ static void frontend_ps2_init(void *data) if (mtapPortOpen(0) != 1) { RARCH_ERR("mtapPortOpen library not initalizated\n"); } +#endif + +#if defined(BUILD_FOR_PCSX2) + bootDeviceID = BOOT_DEVICE_MC0; + strlcpy(cwd, rootDevicePath(bootDeviceID), sizeof(rootDevicePath(bootDeviceID))); +#else + getcwd(cwd, sizeof(cwd)); + bootDeviceID = getBootDeviceID(cwd); +#if !defined(IS_SALAMANDER) && !defined(DEBUG) + // If it is not salamander we need to go one level up for set the CWD. + path_parent_dir(cwd); +#endif +#endif #if defined(HAVE_FILE_LOGGER) - retro_main_log_file_init("retroarch.log", false); + char fileLog[FILENAME_MAX]; + strlcpy(fileLog, rootDevicePath(bootDeviceID), sizeof(fileLog)); + strcat(fileLog, "retroarch.log"); + retro_main_log_file_init(fileLog, false); verbosity_enable(); #endif + + waitUntilDeviceIsReady(bootDeviceID); } static void frontend_ps2_deinit(void *data) { - (void)data; #if defined(HAVE_FILE_LOGGER) verbosity_disable(); - command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL); + retro_main_log_file_deinit(); #endif - padEnd(); - audsrv_quit(); - Exit(0); } static void frontend_ps2_exec(const char *path, bool should_load_game) { -#if defined(IS_SALAMANDER) - char argp[512] = {0}; - SceSize args = 0; - - strlcpy(argp, eboot_path, sizeof(argp)); - args = strlen(argp) + 1; - + int args = 0; + static char *argv[1]; + RARCH_LOG("Attempt to load executable: [%s].\n", path); #ifndef IS_SALAMANDER if (should_load_game && !path_is_empty(RARCH_PATH_CONTENT)) { - argp[args] = '\0'; - strlcat(argp + args, path_get(RARCH_PATH_CONTENT), sizeof(argp) - args); - args += strlen(argp + args) + 1; + args++; + argv[0] = path_get(RARCH_PATH_CONTENT); } #endif - - RARCH_LOG("Attempt to load executable: [%s].\n", path); -#if 0 - exitspawn_kernel(path, args, argp); /* I don't know what this is doing */ -#endif -#endif + LoadELFFromFile(path, args, argv); } #ifndef IS_SALAMANDER @@ -353,7 +356,7 @@ frontend_ctx_driver_t frontend_ctx_ps2 = { frontend_ps2_exitspawn, /* exitspawn */ NULL, /* process_args */ frontend_ps2_exec, /* exec */ - #ifdef IS_SALAMANDER +#ifdef IS_SALAMANDER NULL, /* set_fork */ #else frontend_ps2_set_fork, /* set_fork */ diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 6b7a977b2f..9ac2d02476 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -165,7 +165,6 @@ static void refreshScreen(ps2_video_t *ps2) gsKit_sync_flip(ps2->gsGlobal); gsKit_queue_exec(ps2->gsGlobal); gsKit_TexManager_nextFrame(ps2->gsGlobal); - } static void *ps2_gfx_init(const video_info_t *video, diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index ceefb1d18b..94a0236f9d 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -20,8 +20,6 @@ #include "../../config.h" #endif -#include - #include #include #include diff --git a/ps2/compat_files/ps2_devices.c b/ps2/compat_files/ps2_devices.c index 7ba3fe87b2..bd020d7b50 100644 --- a/ps2/compat_files/ps2_devices.c +++ b/ps2/compat_files/ps2_devices.c @@ -19,6 +19,7 @@ #include #include #include +#include #define DEVICE_SLASH "/" @@ -161,14 +162,14 @@ enum BootDeviceIDs getBootDeviceID(char *path) bool waitUntilDeviceIsReady(enum BootDeviceIDs device_id) { - DIR *dir; - int ret = 0; - int retries = 3; + struct stat buffer; + int ret = -1; + int retries = 10; char *rootDevice = rootDevicePath(device_id); - while(dir == NULL && retries > 0) + while(ret != 0 && retries > 0) { - dir = opendir(rootDevice); + ret = stat(rootDevice, &buffer); /* Wait untill the device is ready */ nopdelay(); nopdelay(); @@ -181,10 +182,6 @@ bool waitUntilDeviceIsReady(enum BootDeviceIDs device_id) retries--; } - if (dir) { - ret = 1; - closedir(dir); - } - - return ret; + + return ret == 0; }