From 0880bd00b09bb378d8a8f6494684cf8f4948936f Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Tue, 18 Sep 2018 08:08:06 +0200 Subject: [PATCH] PS2 is compiling with null drivers --- Makefile.ps2 | 109 ++ audio/audio_driver.h | 1 + config.def.h | 4 +- configuration.c | 20 + core_info.c | 2 +- frontend/drivers/platform_ps2.c | 502 +++++++++ frontend/frontend_driver.c | 9 + frontend/frontend_driver.h | 1 + gfx/drivers/ps2_gfx.c | 980 ++++++++++++++++++ gfx/video_driver.c | 3 + griffin/griffin.c | 9 + input/drivers/ps2_input.c | 161 +++ input/drivers_joypad/ps2_joypad.c | 208 ++++ input/input_autodetect_builtin.c | 29 + input/input_driver.c | 6 + input/input_driver.h | 2 + libretro-common/features/features_cpu.c | 13 +- libretro-common/file/file_path.c | 30 +- libretro-common/file/retro_dirent.c | 24 +- libretro-common/include/compat/intrinsics.h | 2 +- libretro-common/include/compat/posix_string.h | 4 + libretro-common/include/compat/strcasestr.h | 4 + libretro-common/include/memmap.h | 2 +- libretro-common/include/retro_environment.h | 2 +- libretro-common/include/retro_miscellaneous.h | 2 +- libretro-common/include/retro_timers.h | 17 + libretro-common/rthreads/rthreads.c | 4 + libretro-common/vfs/vfs_implementation.c | 19 +- menu/drivers/rgui.c | 6 +- ps2/compat_ctype.c | 108 ++ ps2/include/compat_ctype.h | 9 + ps2/include/inttypes.h | 8 + ps2/include/math.h | 21 + ps2/include/pte_types.h | 26 + ps2/include/stdint.h | 30 + tasks/task_content.c | 2 +- 36 files changed, 2356 insertions(+), 23 deletions(-) create mode 100644 Makefile.ps2 create mode 100644 frontend/drivers/platform_ps2.c create mode 100644 gfx/drivers/ps2_gfx.c create mode 100644 input/drivers/ps2_input.c create mode 100644 input/drivers_joypad/ps2_joypad.c create mode 100644 ps2/compat_ctype.c create mode 100644 ps2/include/compat_ctype.h create mode 100644 ps2/include/inttypes.h create mode 100644 ps2/include/math.h create mode 100644 ps2/include/pte_types.h create mode 100644 ps2/include/stdint.h diff --git a/Makefile.ps2 b/Makefile.ps2 new file mode 100644 index 0000000000..ba9d92549b --- /dev/null +++ b/Makefile.ps2 @@ -0,0 +1,109 @@ +BUILD_PRX = 0 +DEBUG = 0 +HAVE_KERNEL_PRX = 0 +HAVE_LOGGER = 0 +HAVE_FILE_LOGGER = 0 +HAVE_THREADS = 0 +BIG_STACK = 0 +WHOLE_ARCHIVE_LINK = 0 +PS2_IP = 192.168.1.150 + +#Configuration for IRX +EE_BIN2O = bin2o +IRX_DIR = $(PS2SDK)/iop/irx + +TARGET = retroarchps2.elf + +ifeq ($(DEBUG), 1) + OPTIMIZE_LV := -O0 -g +else + OPTIMIZE_LV := -O2 +endif + +ifeq ($(WHOLE_ARCHIVE_LINK), 1) + WHOLE_START := -Wl,--whole-archive + WHOLE_END := -Wl,--no-whole-archive +endif + +INCDIR = -I$(PS2SDK)/ports/include -I$(PS2DEV)/gsKit/include -I$(PS2SDK)/iop/include -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include +INCDIR += -Ips2 -Ips2/include -Ilibretro-common/include +INCDIR += -Ideps -Ideps/stb -Ideps/libz -Ideps/7zip -Ideps/pthreads -Ideps/pthreads/platform/ps2 -Ideps/pthreads/platform/helper +GPVAL = -G0 +CFLAGS = $(OPTIMIZE_LV) -ffast-math -fsingle-precision-constant +ASFLAGS = $(CFLAGS) + +RARCH_DEFINES = -DPS2 -DUSE_IOP_CTYPE_MACRO -D_MIPS_ARCH_R5900 -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DWANT_ZLIB +RARCH_DEFINES += -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER + +LIBDIR = +LDFLAGS =-L$(PS2SDK)/ports/lib -L$(PS2SDK)/ee/lib -L. +#LIBS = $(WHOLE_START) -lretro_ps2 $(WHOLE_END) -lstdc++ -lm -lz -lgskit -ldmakit -lpng -laudsrv -lpad -lcdvd -lmad -lfileXio -lpatches +LIBS = -Xlinker --start-group +LIBS += $(WHOLE_START) -lretro_ps2 $(WHOLE_END) +LIBS += -lfileXio -lm -lg -lz -ldebug -lfileXio -laudsrv -lpatches -lpoweroff + +#IRX modules +# IRX modules - modules have to be in IRX_DIR +IRX = iomanX.irx fileXio.irx usbd.irx usbhdfsd.irx freesd.irx audsrv.irx poweroff.irx ps2dev9.irx ps2atad.irx ps2hdd.irx ps2fs.irx +IRX_OBJ = $(IRX:.irx=.o) +EE_OBJS += $(IRX_OBJ) + +ifeq ($(HAVE_THREADS), 1) +RARCH_DEFINES += -DHAVE_THREADS +endif + +ifeq ($(HAVE_FILE_LOGGER), 1) +CFLAGS += -DHAVE_FILE_LOGGER +endif + +ifeq ($(HAVE_KERNEL_PRX), 1) +CFLAGS += -DHAVE_KERNEL_PRX +endif + +ifeq ($(BIG_STACK), 1) +CFLAGS += -DBIG_STACK +endif + +CFLAGS += $(RARCH_DEFINES) + +# Missing objecst on the PS2SDK +EE_OBJS += ps2/compat_ctype.o + +#EE_OBJS = griffin/griffin.o bootstrap/ps2/kernel_functions.o +EE_OBJS += griffin/griffin.o + +EE_CFLAGS = $(CFLAGS) +EE_LDFLAGS = $(LDFLAGS) +EE_LIBS = $(LIBS) +EE_ASFLAGS = $(ASFLAGS) +EE_INCS = $(INCDIR) +EE_IRX_OBJ = $(IRX_OBJ) +EE_BIN = $(TARGET) +EE_GPVAL = $(GPVAL) + +all: $(EE_IRX_OBJ) $(EE_BIN) + +clean: + rm -f $(EE_BIN) $(EE_OBJS) + +prepare: + ps2client -h $(PS2_IP) reset + ps2client -h $(PS2_IP) netdump + +run: + ps2client -h $(PS2_IP) execee host:$(EE_BIN) + +debug: clean prepare all run + +#Specific file name and output per IRX Module +$(EE_IRX_OBJ): + $(EE_BIN2O) $(EE_GPVAL) $(IRX_DIR)/$(@:.o=.irx) $@ $(@:.o=_irx) + +#Include preferences +include $(PS2SDK)/samples/Makefile.pref +include $(PS2SDK)/samples/Makefile.eeglobal + +#EE_CFLAGS += -O2 + +EE_LIBS += -Xlinker --end-group + \ No newline at end of file diff --git a/audio/audio_driver.h b/audio/audio_driver.h index 1d67fa0768..c90db9873c 100644 --- a/audio/audio_driver.h +++ b/audio/audio_driver.h @@ -335,6 +335,7 @@ extern audio_driver_t audio_ps3; extern audio_driver_t audio_gx; extern audio_driver_t audio_ax; extern audio_driver_t audio_psp; +extern audio_driver_t audio_ps2; extern audio_driver_t audio_ctr_csnd; extern audio_driver_t audio_ctr_dsp; extern audio_driver_t audio_switch; diff --git a/config.def.h b/config.def.h index 80a10a7f61..2791384be9 100644 --- a/config.def.h +++ b/config.def.h @@ -188,7 +188,7 @@ static const bool video_threaded = false; #endif #if defined(HAVE_THREADS) -#if defined(GEKKO) || defined(PSP) +#if defined(GEKKO) || defined(PSP) || defined(PS2) /* For single-core consoles right now it's better to have this be disabled. */ static const bool threaded_data_runloop_enable = false; #else @@ -731,7 +731,7 @@ static const bool desktop_menu_enable = true; #if defined(__QNX__) || defined(_XBOX1) || defined(_XBOX360) || defined(__CELLOS_LV2__) || (defined(__MACH__) && defined(IOS)) || defined(ANDROID) || defined(WIIU) || defined(HAVE_NEON) || defined(GEKKO) || defined(__ARM_NEON__) static enum resampler_quality audio_resampler_quality_level = RESAMPLER_QUALITY_LOWER; -#elif defined(PSP) || defined(_3DS) || defined(VITA) +#elif defined(PSP) || defined(_3DS) || defined(VITA) || defined(PS2) static enum resampler_quality audio_resampler_quality_level = RESAMPLER_QUALITY_LOWEST; #else static enum resampler_quality audio_resampler_quality_level = RESAMPLER_QUALITY_NORMAL; diff --git a/configuration.c b/configuration.c index 0329a77778..65f6a70b7c 100644 --- a/configuration.c +++ b/configuration.c @@ -148,6 +148,7 @@ enum video_driver_enum VIDEO_XENON360, VIDEO_PSP1, VIDEO_VITA2D, + VIDEO_PS2, VIDEO_CTR, VIDEO_SWITCH, VIDEO_D3D8, @@ -191,6 +192,7 @@ enum audio_driver_enum AUDIO_WIIU, AUDIO_RWEBAUDIO, AUDIO_PSP, + AUDIO_PS2, AUDIO_CTR, AUDIO_SWITCH, AUDIO_NULL @@ -214,6 +216,7 @@ enum input_driver_enum INPUT_DINPUT, INPUT_PS3, INPUT_PSP, + INPUT_PS2, INPUT_CTR, INPUT_SWITCH, INPUT_XENON360, @@ -237,6 +240,7 @@ enum joypad_driver_enum JOYPAD_WIIU, JOYPAD_XDK, JOYPAD_PSP, + JOYPAD_PS2, JOYPAD_CTR, JOYPAD_SWITCH, JOYPAD_DINPUT, @@ -325,6 +329,8 @@ static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_VG; static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_VITA2D; #elif defined(PSP) static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_PSP1; +#elif defined(PS2) +static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_PS2; #elif defined(_3DS) static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_CTR; #elif defined(SWITCH) @@ -355,6 +361,8 @@ static enum audio_driver_enum AUDIO_DEFAULT_DRIVER = AUDIO_WII; static enum audio_driver_enum AUDIO_DEFAULT_DRIVER = AUDIO_WIIU; #elif defined(PSP) || defined(VITA) static enum audio_driver_enum AUDIO_DEFAULT_DRIVER = AUDIO_PSP; +#elif defined(PS2) +static enum audio_driver_enum AUDIO_DEFAULT_DRIVER = AUDIO_PS2; #elif defined(_3DS) static enum audio_driver_enum AUDIO_DEFAULT_DRIVER = AUDIO_CTR; #elif defined(SWITCH) @@ -435,6 +443,8 @@ static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_DINPUT; static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_PS3; #elif defined(PSP) || defined(VITA) static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_PSP; +#elif defined(PS2) +static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_PS2; #elif defined(_3DS) static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_CTR; #elif defined(SWITCH) @@ -477,6 +487,8 @@ static enum joypad_driver_enum JOYPAD_DEFAULT_DRIVER = JOYPAD_WIIU; static enum joypad_driver_enum JOYPAD_DEFAULT_DRIVER = JOYPAD_XDK; #elif defined(PSP) || defined(VITA) static enum joypad_driver_enum JOYPAD_DEFAULT_DRIVER = JOYPAD_PSP; +#elif defined(PS2) +static enum joypad_driver_enum JOYPAD_DEFAULT_DRIVER = JOYPAD_PS2; #elif defined(_3DS) static enum joypad_driver_enum JOYPAD_DEFAULT_DRIVER = JOYPAD_CTR; #elif defined(SWITCH) @@ -663,6 +675,8 @@ const char *config_get_default_audio(void) #else return "psp"; #endif + case AUDIO_PS2: + return "ps2"; case AUDIO_CTR: return "csnd"; case AUDIO_SWITCH: @@ -758,6 +772,8 @@ const char *config_get_default_video(void) return "d3d12"; case VIDEO_PSP1: return "psp1"; + case VIDEO_PS2: + return "ps2"; case VIDEO_VITA2D: return "vita2d"; case VIDEO_CTR: @@ -818,6 +834,8 @@ const char *config_get_default_input(void) #else return "psp"; #endif + case INPUT_PS2: + return "ps2"; case INPUT_CTR: return "ctr"; case INPUT_SWITCH: @@ -888,6 +906,8 @@ const char *config_get_default_joypad(void) #else return "psp"; #endif + case JOYPAD_PS2: + return "ps2"; case JOYPAD_CTR: return "ctr"; case JOYPAD_SWITCH: diff --git a/core_info.c b/core_info.c index 18c8caf448..d7ea70ed91 100644 --- a/core_info.c +++ b/core_info.c @@ -205,7 +205,7 @@ static bool core_info_list_iterate( current_path, info_path_base_size); -#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP)) +#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(PS2) && !defined(HW_WUP)) substr = strrchr(info_path_base, '_'); if (substr) *substr = '\0'; diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c new file mode 100644 index 0000000000..2c6b9a3b06 --- /dev/null +++ b/frontend/drivers/platform_ps2.c @@ -0,0 +1,502 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include + +#include "../frontend_driver.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +enum BootDeviceIDs{ + BOOT_DEVICE_UNKNOWN = -1, + BOOT_DEVICE_MC0 = 0, + BOOT_DEVICE_MC1, + BOOT_DEVICE_CDROM, + BOOT_DEVICE_MASS, + BOOT_DEVICE_HDD, + BOOT_DEVICE_HOST, + + BOOT_DEVICE_COUNT, +}; + +extern unsigned char poweroff_irx_start[]; +extern unsigned int poweroff_irx_size; + +extern unsigned char ps2dev9_irx_start[]; +extern unsigned int ps2dev9_irx_size; + +extern unsigned char ps2atad_irx_start[]; +extern unsigned int ps2atad_irx_size; + +extern unsigned char ps2hdd_irx_start[]; +extern unsigned int ps2hdd_irx_size; + +extern unsigned char ps2fs_irx_start[]; +extern unsigned int ps2fs_irx_size; + +extern unsigned char iomanX_irx_start[]; +extern unsigned int iomanX_irx_size; + +extern unsigned char fileXio_irx_start[]; +extern unsigned int fileXio_irx_size; + +extern unsigned char freesd_irx_start[]; +extern unsigned int freesd_irx_size; + +extern unsigned char audsrv_irx_start[]; +extern unsigned int audsrv_irx_size; + +extern unsigned char usbd_irx_start[]; +extern unsigned int usbd_irx_size; + +extern unsigned char usbhdfsd_irx_start[]; +extern unsigned int usbhdfsd_irx_size; + +static unsigned char HDDModulesLoaded=0; + +char eboot_path[512]; +char user_path[512]; + +static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE; + +//Only paths residing on "basic" devices (devices that don't require mounting) +//can be specified here, since this system doesn't perform mounting based on the path. +#define DEFAULT_PATH "mass:" + +static int getBootDeviceID(char *path) { + int result = BOOT_DEVICE_HOST; + + if(!strncmp(path, "mc0:", 4)) result=BOOT_DEVICE_MC0; + else if(!strncmp(path, "mc1:", 4)) result=BOOT_DEVICE_MC1; + else if(!strncmp(path, "cdrom0:", 7)) result=BOOT_DEVICE_CDROM; + else if(!strncmp(path, "mass:", 5) || !strncmp(path, "mass0:", 6)) result=BOOT_DEVICE_MASS; + else if(!strncmp(path, "hdd:", 4) || !strncmp(path, "hdd0:", 5)) result=BOOT_DEVICE_HDD; + else if(!strncmp(path, "host", 4) && ((path[4]>='0' && path[4]<='9') || path[4]==':')) result=BOOT_DEVICE_HOST; + else result=BOOT_DEVICE_UNKNOWN; + + return result; +} + +//HACK! If booting from a USB device, keep trying to open this program again until it succeeds. This will ensure that the emulator will be able to load its files. +static void waitUntilDeviceIsReady(const char *path) { + FILE *file; + + while((file=fopen(path, "rb"))==NULL){ + //Wait for a while first, or the IOP will get swamped by requests from the EE. + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + nopdelay(); + }; + + fclose(file); +} + +void setPWDOnPFS(const char *FullCWD_path) { + int i; + char *path; + + path=NULL; + for(i=strlen(FullCWD_path); i>=0; i--){ /* Try to seperate the CWD from the path to this ELF. */ + if(FullCWD_path[i]==':'){ + if((path=malloc(i+6+2))!=NULL){ + strcpy(path, "pfs0:/"); + strncat(path, FullCWD_path, i+1); + path[i+1+6]='\0'; + } + break; + } + else if((FullCWD_path[i]=='\\')||(FullCWD_path[i]=='/')){ + if((path=malloc(i+6+1))!=NULL){ + strcpy(path, "pfs0:/"); + strncat(path, FullCWD_path, i); + path[i+6]='\0'; + } + break; + } + } + + if(path!=NULL){ + chdir(path); + free(path); + } +} + +static const char *getMountParams(const char *command, char *BlockDevice) { + const char *MountPath; + int BlockDeviceNameLen; + + MountPath=NULL; + if(strlen(command)>6 && (MountPath=strchr(&command[5], ':'))!=NULL){ + BlockDeviceNameLen=(unsigned int)MountPath-(unsigned int)command; + strncpy(BlockDevice, command, BlockDeviceNameLen); + BlockDevice[BlockDeviceNameLen]='\0'; + + MountPath++; //This is the location of the mount path; + } + + return MountPath; +} + +static void create_path_names(void) +{ +#ifndef IS_SALAMANDER +#if defined(HAVE_LOGGER) + +#elif defined(HAVE_FILE_LOGGER) + retro_main_log_file_init("ux0:/temp/retroarch-log.txt"); // It really depend from where we are executing this +#endif +#endif + + 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, + "CONFIG", sizeof(g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS], user_path, + "DOWNLOADS", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_PLAYLIST], user_path, + "PLAYLISTS", sizeof(g_defaults.dirs[DEFAULT_DIR_PLAYLIST])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_REMAP], g_defaults.dirs[DEFAULT_DIR_MENU_CONFIG], + "REMAPS", sizeof(g_defaults.dirs[DEFAULT_DIR_REMAP])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SRAM], user_path, + "SAVEFILES", sizeof(g_defaults.dirs[DEFAULT_DIR_SRAM])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SAVESTATE], user_path, + "SAVESTATES", sizeof(g_defaults.dirs[DEFAULT_DIR_SAVESTATE])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT], user_path, + "SCREENSHOTS", sizeof(g_defaults.dirs[DEFAULT_DIR_SCREENSHOT])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SYSTEM], user_path, + "SYSTEM", sizeof(g_defaults.dirs[DEFAULT_DIR_SYSTEM])); + + /* cache dir */ + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CACHE], user_path, + "TEMP", sizeof(g_defaults.dirs[DEFAULT_DIR_CACHE])); + + /* history and main config */ + strlcpy(g_defaults.dirs[DEFAULT_DIR_CONTENT_HISTORY], + user_path, sizeof(g_defaults.dirs[DEFAULT_DIR_CONTENT_HISTORY])); + fill_pathname_join(g_defaults.path.config, user_path, + file_path_str(FILE_PATH_MAIN_CONFIG), sizeof(g_defaults.path.config)); +} + +static void poweroffCallback(void *arg) +{ + //Close all files and unmount all partitions. + //close(fd); + + //If you use PFS, close all files and unmount all partitions. + //fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0) + + //Shut down DEV9, if you used it. + //while(fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0) < 0){}; + + printf("Shutdown!"); + poweroffShutdown(); +} + +static void frontend_ps2_get_environment_settings(int *argc, char *argv[], + void *args, void *params_data) +{ + char cwd[FILENAME_MAX], blockDevice[16]; + const char *mountPoint; + int bootDeviceID; + + //TODO: I DONT KNOW YET, WHY IT CRASHES IF UNCOMENT THIS PART + getcwd(cwd, sizeof(cwd)); + bootDeviceID=getBootDeviceID(cwd); + //Mount the HDD partition, if required. + if(bootDeviceID==BOOT_DEVICE_HDD){ + /* Try not to adjust this unless you know what you are doing. The tricky part i keeping the NULL character in the middle of that argument list separated from the number 4. */ + static const char PS2HDD_args[]="-o\0""2"; + static const char PS2FS_args[]="-o\0""8"; + + if(!HDDModulesLoaded){ + SifExecModuleBuffer(poweroff_irx_start, poweroff_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(ps2dev9_irx_start, ps2dev9_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(ps2atad_irx_start, ps2atad_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(ps2hdd_irx_start, ps2hdd_irx_size, sizeof(PS2HDD_args), PS2HDD_args, NULL); + SifExecModuleBuffer(ps2fs_irx_start, ps2fs_irx_size, sizeof(PS2FS_args), PS2FS_args, NULL); + HDDModulesLoaded=1; + } + + //Attempt to mount the partition. + if((mountPoint=getMountParams(cwd, blockDevice))!=NULL && !strncmp(mountPoint, "pfs:", 4)){ + fileXioMount("pfs0:", blockDevice, FIO_MT_RDWR); + + setPWDOnPFS(&mountPoint[4]); + } + } else if(bootDeviceID==BOOT_DEVICE_CDROM){ + chdir(DEFAULT_PATH); + } else if(bootDeviceID==BOOT_DEVICE_MASS){ + waitUntilDeviceIsReady(argv[0]); + } else if (bootDeviceID==BOOT_DEVICE_UNKNOWN) { + + } + + create_path_names(); + +#ifndef IS_SALAMANDER + if (!string_is_empty(argv[1])) + { + static char path[PATH_MAX_LENGTH] = {0}; + struct rarch_main_wrap *args = + (struct rarch_main_wrap*)params_data; + + if (args) + { + strlcpy(path, argv[1], sizeof(path)); + + args->touched = true; + args->no_content = false; + args->verbose = false; + args->config_path = NULL; + args->sram_path = NULL; + args->state_path = NULL; + args->content_path = path; + args->libretro_path = NULL; + + 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]); + } + } +#endif + int i; + for (i = 0; i < DEFAULT_DIR_LAST; i++) + { + const char *dir_path = g_defaults.dirs[i]; + if (!string_is_empty(dir_path)) + path_mkdir(dir_path); + } + +} + +static void frontend_ps2_init(void *data) +{ + SifInitRpc(0); + while(!SifIopSync()){}; + SifInitRpc(0); + sbv_patch_enable_lmb(); + + SifExecModuleBuffer(iomanX_irx_start, iomanX_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(fileXio_irx_start, fileXio_irx_size, 0, NULL, NULL); + + SifLoadModule("rom0:SIO2MAN", 0, NULL); + SifLoadModule("rom0:MCMAN", 0, NULL); + SifLoadModule("rom0:MCSERV", 0, NULL); + SifLoadModule("rom0:PADMAN", 0, NULL); + + SifExecModuleBuffer(usbd_irx_start, usbd_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(usbhdfsd_irx_start, usbhdfsd_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(freesd_irx_start, freesd_irx_size, 0, NULL, NULL); + SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL); + + fileXioInit(); + audsrv_init(); +} + +static void frontend_ps2_deinit(void *data) +{ + (void)data; +#ifndef IS_SALAMANDER + verbosity_disable(); +#ifdef HAVE_FILE_LOGGER + command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL); +#endif + +#endif + fileXioUmount("pfs0:"); + fileXioExit(); + + SifExitRpc(); +} + +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; + +#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; + } +#endif + + RARCH_LOG("Attempt to load executable: [%s].\n", path); + // exitspawn_kernel(path, args, argp); // I don't know what this is doing +#endif +} + +#ifndef IS_SALAMANDER +static bool frontend_ps2_set_fork(enum frontend_fork fork_mode) +{ + switch (fork_mode) + { + case FRONTEND_FORK_CORE: + RARCH_LOG("FRONTEND_FORK_CORE\n"); + ps2_fork_mode = fork_mode; + break; + case FRONTEND_FORK_CORE_WITH_ARGS: + RARCH_LOG("FRONTEND_FORK_CORE_WITH_ARGS\n"); + ps2_fork_mode = fork_mode; + break; + case FRONTEND_FORK_RESTART: + RARCH_LOG("FRONTEND_FORK_RESTART\n"); + /* NOTE: We don't implement Salamander, so just turn + * this into FRONTEND_FORK_CORE. */ + ps2_fork_mode = FRONTEND_FORK_CORE; + break; + case FRONTEND_FORK_NONE: + default: + return false; + } + + return true; +} +#endif + +static void frontend_ps2_exitspawn(char *core_path, size_t core_path_size) +{ + bool should_load_game = false; +#ifndef IS_SALAMANDER + if (ps2_fork_mode == FRONTEND_FORK_NONE) + return; + + switch (ps2_fork_mode) + { + case FRONTEND_FORK_CORE_WITH_ARGS: + should_load_game = true; + break; + case FRONTEND_FORK_NONE: + default: + break; + } +#endif + frontend_ps2_exec(core_path, should_load_game); +} + +static void frontend_ps2_shutdown(bool unused) +{ + poweroffInit(); + //Set callback function + poweroffSetCallback(&poweroffCallback, NULL); +} + +static int frontend_ps2_get_rating(void) +{ + return 10; +} + +enum frontend_architecture frontend_ps2_get_architecture(void) +{ + return FRONTEND_ARCH_MIPS; +} + +static int frontend_ps2_parse_drive_list(void *data, bool load_content) +{ +#ifndef IS_SALAMANDER + file_list_t *list = (file_list_t*)data; + enum msg_hash_enums enum_idx = load_content ? + MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR : + MSG_UNKNOWN; + + menu_entries_append_enum(list, + "mc0:/", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); + menu_entries_append_enum(list, + "mc1:/", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); + menu_entries_append_enum(list, + "mass:/", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); + menu_entries_append_enum(list, + "hdd0:/", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); +#endif + + return 0; +} + +frontend_ctx_driver_t frontend_ctx_ps2 = { + frontend_ps2_get_environment_settings, /* environment_get */ + frontend_ps2_init, /* init */ + frontend_ps2_deinit, /* deinit */ + frontend_ps2_exitspawn, /* exitspawn */ + NULL, /* process_args */ + frontend_ps2_exec, /* exec */ + #ifdef IS_SALAMANDER + NULL, /* set_fork */ +#else + frontend_ps2_set_fork, /* set_fork */ +#endif + frontend_ps2_shutdown, /* shutdown */ + NULL, /* get_name */ + NULL, /* get_os */ + frontend_ps2_get_rating, /* get_rating */ + NULL, /* load_content */ + frontend_ps2_get_architecture, /* get_architecture */ + NULL, /* get_powerstate */ + NULL, /* parse_drive_list */ + NULL, /* get_mem_total */ + NULL, /* get_mem_free */ + NULL, /* install_signal_handler */ + NULL, /* get_sighandler_state */ + NULL, /* set_sighandler_state */ + NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ +#ifdef HAVE_LAKKA + NULL, /* get_lakka_version */ +#endif + NULL, /* watch_path_for_changes */ + NULL, /* check_for_path_changes */ + NULL, /* set_sustained_performance_mode */ + "null", +}; diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c index d846ed5928..ca800f4900 100644 --- a/frontend/frontend_driver.c +++ b/frontend/frontend_driver.c @@ -56,6 +56,9 @@ static frontend_ctx_driver_t *frontend_ctx_drivers[] = { #if defined(PSP) || defined(VITA) &frontend_ctx_psp, #endif +#if defined(PS2) + &frontend_ctx_ps2, //TODO: FJTRUJY +#endif #if defined(_3DS) &frontend_ctx_ctr, #endif @@ -141,6 +144,9 @@ bool frontend_driver_get_core_extension(char *s, size_t len) #elif defined(VITA) strlcpy(s, "self|bin", len); return true; +#elif defined(PS2) + strlcpy(s, "elf", len); + return true; #elif defined(_XBOX1) strlcpy(s, "xbe", len); return true; @@ -187,6 +193,9 @@ bool frontend_driver_get_salamander_basename(char *s, size_t len) #elif defined(VITA) strlcpy(s, "eboot.bin", len); return true; +#elif defined(PS2) + strlcpy(s, "eboot.elf", len); + return true; #elif defined(_XBOX1) strlcpy(s, "default.xbe", len); return true; diff --git a/frontend/frontend_driver.h b/frontend/frontend_driver.h index c6092ad7ef..f5de976563 100644 --- a/frontend/frontend_driver.h +++ b/frontend/frontend_driver.h @@ -120,6 +120,7 @@ extern frontend_ctx_driver_t frontend_ctx_qnx; extern frontend_ctx_driver_t frontend_ctx_darwin; extern frontend_ctx_driver_t frontend_ctx_unix; extern frontend_ctx_driver_t frontend_ctx_psp; +extern frontend_ctx_driver_t frontend_ctx_ps2; extern frontend_ctx_driver_t frontend_ctx_ctr; extern frontend_ctx_driver_t frontend_ctx_switch; extern frontend_ctx_driver_t frontend_ctx_win32; diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c new file mode 100644 index 0000000000..a460584513 --- /dev/null +++ b/gfx/drivers/ps2_gfx.c @@ -0,0 +1,980 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014-2017 - Ali Bouhlel + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#ifdef HAVE_MENU +#include "../../menu/menu_driver.h" +#endif + +#include "../font_driver.h" + +#include "../../defines/ps2_defines.h" + +#ifndef SCEGU_SCR_WIDTH +#define SCEGU_SCR_WIDTH 480 +#endif + +#ifndef SCEGU_SCR_HEIGHT +#define SCEGU_SCR_HEIGHT 272 +#endif + +#ifndef SCEGU_VRAM_WIDTH +#define SCEGU_VRAM_WIDTH 512 +#endif + +/* Frame buffer */ +#define SCEGU_VRAM_TOP (0x44000000) +/* 16bit mode */ +#define SCEGU_VRAM_BUFSIZE (SCEGU_VRAM_WIDTH*SCEGU_SCR_HEIGHT*2) +#define SCEGU_VRAM_BP_0 ((void *)(SCEGU_VRAM_TOP)) +#define SCEGU_VRAM_BP_1 ((void *)(SCEGU_VRAM_TOP+SCEGU_VRAM_BUFSIZE)) +#define SCEGU_VRAM_BP_2 ((void *)(SCEGU_VRAM_TOP+(SCEGU_VRAM_BUFSIZE*2))) +/* 32bit mode */ +#define SCEGU_VRAM_BUFSIZE32 (SCEGU_VRAM_WIDTH*SCEGU_SCR_HEIGHT*4) +#define SCEGU_VRAM_BP32_0 ((void *)(SCEGU_VRAM_TOP)) +#define SCEGU_VRAM_BP32_1 ((void *)(SCEGU_VRAM_TOP+SCEGU_VRAM_BUFSIZE32)) +#define SCEGU_VRAM_BP32_2 ((void *)(SCEGU_VRAM_TOP+(SCEGU_VRAM_BUFSIZE32*2))) + +#define TO_UNCACHED_PTR(ptr) ((void *)((uint32_t)(ptr)|0x40000000)) +#define TO_CACHED_PTR(ptr) ((void *)((uint32_t)(ptr)&~0x40000000)) + +#define FROM_GU_POINTER(ptr) ((void *)((uint32_t)(ptr)|0x44000000)) +#define TO_GU_POINTER(ptr) ((void *)((uint32_t)(ptr)&~0x44000000)) + +typedef struct __attribute__((packed)) ps2_vertex +{ + float u,v; + float x,y,z; + +} ps2_vertex_t; + +typedef struct __attribute__((packed)) ps2_sprite +{ + ps2_vertex_t v0; + ps2_vertex_t v1; +} ps2_sprite_t; + +typedef struct ps2_menu_frame +{ + void* dList; + void* frame; + ps2_sprite_t* frame_coords; + + bool active; + + PspGeContext context_storage; +} ps2_menu_frame_t; + +typedef struct ps2_video +{ + void* main_dList; + void* frame_dList; + void* draw_buffer; + void* texture; + ps2_sprite_t* frame_coords; + int tex_filter; + + bool vsync; + bool rgb32; + int bpp_log2; + + ps2_menu_frame_t menu; + + video_viewport_t vp; + + unsigned rotation; + bool vblank_not_reached; + bool keep_aspect; + bool should_resize; + bool hw_render; +} ps2_video_t; + +// both row and column count need to be a power of 2 +#define PSP_FRAME_ROWS_COUNT 4 +#define PSP_FRAME_COLUMNS_COUNT 16 +#define PSP_FRAME_SLICE_COUNT (PSP_FRAME_ROWS_COUNT * PSP_FRAME_COLUMNS_COUNT) +#define PSP_FRAME_VERTEX_COUNT (PSP_FRAME_SLICE_COUNT * 2) + +static INLINE void ps2_set_screen_coords (ps2_sprite_t* framecoords, + int x, int y, int width, int height, unsigned rotation) +{ + int i; + float x0, y0, step_x, step_y; + int current_column = 0; + + if (rotation == 0) + { + x0 = x; + y0 = y; + step_x = ((float) width) / PSP_FRAME_COLUMNS_COUNT; + step_y = ((float) height) / PSP_FRAME_ROWS_COUNT; + + for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) + { + framecoords[i].v0.x = x0; + framecoords[i].v0.y = y0; + + framecoords[i].v1.x = (x0 += step_x); + framecoords[i].v1.y = y0 + step_y; + + if (++current_column == PSP_FRAME_COLUMNS_COUNT) + { + x0 = x; + y0 += step_y; + current_column = 0; + } + } + } + else if (rotation == 1) /* 90° */ + { + x0 = x + width; + y0 = y; + step_x = -((float) width) / PSP_FRAME_ROWS_COUNT; + step_y = ((float) height) / PSP_FRAME_COLUMNS_COUNT; + + for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) + { + framecoords[i].v0.x = x0; + framecoords[i].v0.y = y0; + + framecoords[i].v1.x = x0 + step_x; + framecoords[i].v1.y = (y0 += step_y); + + if (++current_column == PSP_FRAME_COLUMNS_COUNT) + { + y0 = y; + x0 += step_x; + current_column = 0; + } + } + } + else if (rotation == 2) /* 180° */ + { + x0 = x + width; + y0 = y + height; + step_x = -((float) width) / PSP_FRAME_COLUMNS_COUNT; + step_y = -((float) height) / PSP_FRAME_ROWS_COUNT; + + for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) + { + framecoords[i].v0.x = x0; + framecoords[i].v0.y = y0; + + framecoords[i].v1.x = (x0 += step_x); + framecoords[i].v1.y = y0 + step_y; + + if (++current_column == PSP_FRAME_COLUMNS_COUNT) + { + x0 = x + width; + y0 += step_y; + current_column = 0; + } + } + } + else /* 270° */ + { + x0 = x; + y0 = y + height; + step_x = ((float) width) / PSP_FRAME_ROWS_COUNT; + step_y = -((float) height) / PSP_FRAME_COLUMNS_COUNT; + + for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) + { + framecoords[i].v0.x = x0; + framecoords[i].v0.y = y0; + framecoords[i].v1.x = x0 + step_x; + framecoords[i].v1.y = (y0 += step_y); + + if (++current_column == PSP_FRAME_COLUMNS_COUNT) + { + y0 = y + height; + x0 += step_x; + current_column = 0; + } + } + } +} + +static INLINE void ps2_set_tex_coords (ps2_sprite_t* framecoords, + int width, int height) +{ + int i; + int current_column = 0; + float u0 = 0; + float v0 = 0; + float step_u = ((float) width) / PSP_FRAME_COLUMNS_COUNT; + float step_v = ((float) height) / PSP_FRAME_ROWS_COUNT; + + for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) + { + framecoords[i].v0.u = u0; + framecoords[i].v0.v = v0; + u0 += step_u; + framecoords[i].v1.u = u0; + framecoords[i].v1.v = v0 + step_v; + + if (++current_column == PSP_FRAME_COLUMNS_COUNT) + { + u0 = 0; + v0 += step_v; + current_column = 0; + } + } +} + +static void ps2_update_viewport(ps2_video_t* ps2, + video_frame_info_t *video_info); + +static void ps2_on_vblank(u32 sub, ps2_video_t *ps2) +{ + if (ps2) + ps2->vblank_not_reached = false; +} + +static void *ps2_init(const video_info_t *video, + const input_driver_t **input, void **input_data) +{ + /* TODO : add ASSERT() checks or use main RAM if + * VRAM is too low for desired video->input_scale. */ + + int pixel_format, lut_pixel_format, lut_block_count; + unsigned int red_shift, color_mask; + void *ps2input = NULL; + void *displayBuffer = NULL; + void *LUT_r = NULL; + void *LUT_b = NULL; + ps2_video_t *ps2 = (ps2_video_t*)calloc(1, sizeof(ps2_video_t)); + + if (!ps2) + return NULL; + + sceGuInit(); + + ps2->vp.x = 0; + ps2->vp.y = 0; + ps2->vp.width = SCEGU_SCR_WIDTH; + ps2->vp.height = SCEGU_SCR_HEIGHT; + ps2->vp.full_width = SCEGU_SCR_WIDTH; + ps2->vp.full_height = SCEGU_SCR_HEIGHT; + + /* Make sure anything using uncached pointers reserves + * whole cachelines (memory address and size need to be a multiple of 64) + * so it isn't overwritten by an unlucky cache writeback. + * + * This includes display lists since the Gu library uses + * uncached pointers to write to them. */ + + /* Allocate more space if bigger display lists are needed. */ + ps2->main_dList = memalign(64, 256); + + ps2->frame_dList = memalign(64, 256); + ps2->menu.dList = memalign(64, 256); + ps2->menu.frame = memalign(16, 2 * 480 * 272); + ps2->frame_coords = memalign(64, + (((PSP_FRAME_SLICE_COUNT * sizeof(ps2_sprite_t)) + 63) & ~63)); + ps2->menu.frame_coords = memalign(64, + (((PSP_FRAME_SLICE_COUNT * sizeof(ps2_sprite_t)) + 63) & ~63)); + + memset(ps2->frame_coords, 0, + PSP_FRAME_SLICE_COUNT * sizeof(ps2_sprite_t)); + memset(ps2->menu.frame_coords, 0, + PSP_FRAME_SLICE_COUNT * sizeof(ps2_sprite_t)); + + sceKernelDcacheWritebackInvalidateAll(); + ps2->frame_coords = TO_UNCACHED_PTR(ps2->frame_coords); + ps2->menu.frame_coords = TO_UNCACHED_PTR(ps2->menu.frame_coords); + + ps2->frame_coords->v0.x = 60; + ps2->frame_coords->v0.y = 0; + ps2->frame_coords->v0.u = 0; + ps2->frame_coords->v0.v = 0; + + ps2->frame_coords->v1.x = 420; + ps2->frame_coords->v1.y = SCEGU_SCR_HEIGHT; + ps2->frame_coords->v1.u = 256; + ps2->frame_coords->v1.v = 240; + + ps2->vsync = video->vsync; + ps2->rgb32 = video->rgb32; + + if(ps2->rgb32) + { + u32 i; + uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2); + uint32_t* LUT_b_local = (uint32_t*)(SCEGU_VRAM_BP32_2) + (1 << 8); + + red_shift = 8 + 8; + color_mask = 0xFF; + lut_block_count = (1 << 8) / 8; + + ps2->texture = (void*)(LUT_b_local + (1 << 8)); + ps2->draw_buffer = SCEGU_VRAM_BP32_0; + ps2->bpp_log2 = 2; + + pixel_format = GU_PSM_8888; + lut_pixel_format = GU_PSM_T32; + + displayBuffer = SCEGU_VRAM_BP32_1; + + for (i = 0; i < (1 << 8); i++) + { + LUT_r_local[i] = i; + LUT_b_local[i] = i << (8 + 8); + } + + LUT_r = (void*)LUT_r_local; + LUT_b = (void*)LUT_b_local; + + } + else + { + u16 i; + uint16_t* LUT_r_local = (uint16_t*)(SCEGU_VRAM_BP_2); + uint16_t* LUT_b_local = (uint16_t*)(SCEGU_VRAM_BP_2) + (1 << 5); + + red_shift = 6 + 5; + color_mask = 0x1F; + lut_block_count = (1 << 5) / 8; + + ps2->texture = (void*)(LUT_b_local + (1 << 5)); + ps2->draw_buffer = SCEGU_VRAM_BP_0; + ps2->bpp_log2 = 1; + + pixel_format = + (video_driver_get_pixel_format() == RETRO_PIXEL_FORMAT_0RGB1555) + ? GU_PSM_5551 : GU_PSM_5650 ; + + lut_pixel_format = GU_PSM_T16; + + displayBuffer = SCEGU_VRAM_BP_1; + + for (i = 0; i < (1 << 5); i++) + { + LUT_r_local[i] = i; + LUT_b_local[i] = i << (5 + 6); + } + + LUT_r = (void*)LUT_r_local; + LUT_b = (void*)LUT_b_local; + + } + + ps2->tex_filter = video->smooth? GU_LINEAR : GU_NEAREST; + + /* TODO: check if necessary. */ + sceDisplayWaitVblankStart(); + + sceGuDisplay(GU_FALSE); + + sceGuStart(GU_DIRECT, ps2->main_dList); + + sceGuDrawBuffer(pixel_format, TO_GU_POINTER(ps2->draw_buffer), + SCEGU_VRAM_WIDTH); + sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, + TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH); + sceGuClearColor(0); + sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT); + sceGuEnable(GU_SCISSOR_TEST); + sceGuTexFilter(ps2->tex_filter, ps2->tex_filter); + sceGuTexWrap (GU_CLAMP, GU_CLAMP); + sceGuEnable(GU_TEXTURE_2D); + sceGuDisable(GU_DEPTH_TEST); + sceGuCallMode(GU_FALSE); + + sceGuFinish(); + sceGuSync(0, 0); + + /* TODO : check if necessary */ + sceDisplayWaitVblankStart(); + sceGuDisplay(GU_TRUE); + + ps2DebugScreenSetColorMode(pixel_format); + ps2DebugScreenSetBase(ps2->draw_buffer); + + /* fill frame_dList : */ + sceGuStart(GU_CALL, ps2->frame_dList); + + sceGuTexMode(pixel_format, 0, 0, GU_FALSE); + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); + sceGuEnable(GU_BLEND); + + /* green only */ + sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(ps2->frame_coords)); + + /* restore */ + sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); + + sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE); + + sceGuClutMode(pixel_format, red_shift, color_mask, 0); + sceGuClutLoad(lut_block_count, LUT_r); + + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(ps2->frame_coords)); + + sceGuClutMode(pixel_format, 0, color_mask, 0); + sceGuClutLoad(lut_block_count, LUT_b); + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(ps2->frame_coords)); + + sceGuFinish(); + + if (input && input_data) + { + settings_t *settings = config_get_ptr(); + ps2input = input_ps2.init(settings->arrays.input_joypad_driver); + *input = ps2input ? &input_ps2 : NULL; + *input_data = ps2input; + } + + ps2->vblank_not_reached = true; + sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, ps2_on_vblank, ps2); + sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); + + ps2->keep_aspect = true; + ps2->should_resize = true; + ps2->hw_render = false; + + return ps2; +} + +#if 0 +#define DISPLAY_FPS +#endif + +static bool ps2_frame(void *data, const void *frame, + unsigned width, unsigned height, uint64_t frame_count, + unsigned pitch, const char *msg, video_frame_info_t *video_info) +{ +#ifdef DISPLAY_FPS + uint32_t diff; + static uint64_t currentTick,lastTick; + static int frames; + static float fps = 0.0; +#endif + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (!width || !height) + return false; + + if (((uint32_t)frame&0x04000000) || (frame == RETRO_HW_FRAME_BUFFER_VALID)) + ps2->hw_render = true; + else if (frame) + ps2->hw_render = false; + + if (!ps2->hw_render) + sceGuSync(0, 0); /* let the core decide when to sync when HW_RENDER */ + + ps2DebugScreenSetBase(ps2->draw_buffer); + + ps2DebugScreenSetXY(0,0); + + if (video_info->fps_show) + { + ps2DebugScreenSetXY(68 - strlen(video_info->fps_text) - 1,0); + ps2DebugScreenPuts(video_info->fps_text); + ps2DebugScreenSetXY(0,1); + } + + if (msg) + ps2DebugScreenPuts(msg); + + if ((ps2->vsync)&&(ps2->vblank_not_reached)) + sceDisplayWaitVblankStart(); + + ps2->vblank_not_reached = true; + +#ifdef DISPLAY_FPS + frames++; + sceRtcGetCurrentTick(¤tTick); + diff = currentTick - lastTick; + if(diff > 1000000) + { + fps = (float)frames * 1000000.0 / diff; + lastTick = currentTick; + frames = 0; + } + + ps2DebugScreenSetXY(0,0); + ps2DebugScreenPrintf("%f", fps); +#endif + + ps2->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers()); + + if (ps2->should_resize) + ps2_update_viewport(ps2, video_info); + + ps2_set_tex_coords(ps2->frame_coords, width, height); + + sceGuStart(GU_DIRECT, ps2->main_dList); + + sceGuTexFilter(ps2->tex_filter, ps2->tex_filter); + sceGuClear(GU_COLOR_BUFFER_BIT); + + /* frame in VRAM ? texture/palette was + * set in core so draw directly */ + if (ps2->hw_render) + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + (void*)(ps2->frame_coords)); + else + { + if (frame) + { + sceKernelDcacheWritebackRange(frame,pitch * height); + sceGuCopyImage(ps2->rgb32? GU_PSM_8888 : GU_PSM_5650, ((u32)frame & 0xF) >> ps2->bpp_log2, + 0, width, height, pitch >> ps2->bpp_log2, + (void*)((u32)frame & ~0xF), 0, 0, width, ps2->texture); + } + sceGuTexImage(0, next_pow2(width), next_pow2(height), width, ps2->texture); + sceGuCallList(ps2->frame_dList); + } + + sceGuFinish(); + +#ifdef HAVE_MENU + menu_driver_frame(video_info); +#endif + + if(ps2->menu.active) + { + sceGuSendList(GU_TAIL, ps2->menu.dList, &(ps2->menu.context_storage)); + sceGuSync(0, 0); + } + + return true; +} + +static void ps2_set_nonblock_state(void *data, bool toggle) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + ps2->vsync = !toggle; +} + +static bool ps2_alive(void *data) +{ + (void)data; + return true; +} + +static bool ps2_focus(void *data) +{ + (void)data; + return true; +} + +static bool ps2_suppress_screensaver(void *data, bool enable) +{ + (void)data; + (void)enable; + return false; +} + +static void ps2_free(void *data) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if(!(ps2) || !(ps2->main_dList)) + return; + + sceDisplayWaitVblankStart(); + sceGuDisplay(GU_FALSE); + sceGuTerm(); + + if (ps2->main_dList) + free(ps2->main_dList); + if (ps2->frame_dList) + free(ps2->frame_dList); + if (ps2->frame_coords) + free(TO_CACHED_PTR(ps2->frame_coords)); + if (ps2->menu.frame_coords) + free(TO_CACHED_PTR(ps2->menu.frame_coords)); + if (ps2->menu.dList) + free(ps2->menu.dList); + if (ps2->menu.frame) + free(ps2->menu.frame); + + free(data); + + sceKernelDisableSubIntr(PSP_VBLANK_INT, 0); + sceKernelReleaseSubIntrHandler(PSP_VBLANK_INT,0); +} + +static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, + unsigned width, unsigned height, float alpha) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + (void) rgb32; + (void) alpha; + +#ifdef DEBUG + /* ps2->menu.frame buffer size is (480 * 272)*2 Bytes */ + retro_assert((width*height) < (480 * 272)); +#endif + + ps2_set_screen_coords(ps2->menu.frame_coords, 0, 0, + SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, 0); + ps2_set_tex_coords(ps2->menu.frame_coords, width, height); + + sceKernelDcacheWritebackRange(frame, width * height * 2); + + sceGuStart(GU_DIRECT, ps2->main_dList); + sceGuCopyImage(GU_PSM_4444, 0, 0, width, height, width, + (void*)frame, 0, 0, width, ps2->menu.frame); + sceGuFinish(); + + sceGuStart(GU_SEND, ps2->menu.dList); + sceGuTexMode(GU_PSM_4444, 0, 0, GU_FALSE); + sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB); + sceGuTexFilter(GU_LINEAR, GU_LINEAR); + sceGuTexImage(0, next_pow2(width), next_pow2(height), width, ps2->menu.frame); + sceGuEnable(GU_BLEND); + +#if 0 + /* default blending */ + sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); +#endif + sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xF0F0F0F0, 0x0F0F0F0F); +; + sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | + GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL, + ps2->menu.frame_coords); + sceGuFinish(); + +} + +static void ps2_set_texture_enable(void *data, bool state, bool full_screen) +{ + (void) full_screen; + + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + ps2->menu.active = state; +} + +static void ps2_update_viewport(ps2_video_t* ps2, + video_frame_info_t *video_info) +{ + int x = 0; + int y = 0; + float device_aspect = ((float)SCEGU_SCR_WIDTH) / SCEGU_SCR_HEIGHT; + float width = SCEGU_SCR_WIDTH; + float height = SCEGU_SCR_HEIGHT; + settings_t *settings = config_get_ptr(); + + if (settings->bools.video_scale_integer) + { + video_viewport_get_scaled_integer(&ps2->vp, SCEGU_SCR_WIDTH, + SCEGU_SCR_HEIGHT, video_driver_get_aspect_ratio(), ps2->keep_aspect); + width = ps2->vp.width; + height = ps2->vp.height; + } + else if (ps2->keep_aspect) + { +#if defined(HAVE_MENU) + if (settings->uints.video_aspect_ratio_idx == ASPECT_RATIO_CUSTOM) + { + x = video_info->custom_vp_x; + y = video_info->custom_vp_y; + width = video_info->custom_vp_width; + height = video_info->custom_vp_height; + } + else +#endif + { + float delta; + float desired_aspect = video_driver_get_aspect_ratio(); + + if ((fabsf(device_aspect - desired_aspect) < 0.0001f) + || (fabsf((16.0/9.0) - desired_aspect) < 0.02f)) + { + /* If the aspect ratios of screen and desired aspect + * ratio are sufficiently equal (floating point stuff), + * assume they are actually equal. + */ + } + else if (device_aspect > desired_aspect) + { + delta = (desired_aspect / device_aspect - 1.0f) + / 2.0f + 0.5f; + x = (int)roundf(width * (0.5f - delta)); + width = (unsigned)roundf(2.0f * width * delta); + } + else + { + delta = (device_aspect / desired_aspect - 1.0f) + / 2.0f + 0.5f; + y = (int)roundf(height * (0.5f - delta)); + height = (unsigned)roundf(2.0f * height * delta); + } + } + + ps2->vp.x = x; + ps2->vp.y = y; + ps2->vp.width = width; + ps2->vp.height = height; + } + else + { + ps2->vp.x = ps2->vp.y = 0; + ps2->vp.width = width; + ps2->vp.height = height; + } + + ps2->vp.width += ps2->vp.width&0x1; + ps2->vp.height += ps2->vp.height&0x1; + + ps2_set_screen_coords(ps2->frame_coords, ps2->vp.x, + ps2->vp.y, ps2->vp.width, ps2->vp.height, ps2->rotation); + + ps2->should_resize = false; + +} + +static void ps2_set_rotation(void *data, unsigned rotation) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (!ps2) + return; + + ps2->rotation = rotation; + ps2->should_resize = true; +} +static void ps2_set_filtering(void *data, unsigned index, bool smooth) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + ps2->tex_filter = smooth? GU_LINEAR : GU_NEAREST; +} + +static void ps2_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + switch (aspect_ratio_idx) + { + case ASPECT_RATIO_SQUARE: + video_driver_set_viewport_square_pixel(); + break; + + case ASPECT_RATIO_CORE: + video_driver_set_viewport_core(); + break; + + case ASPECT_RATIO_CONFIG: + video_driver_set_viewport_config(); + break; + + default: + break; + } + + video_driver_set_aspect_ratio_value(aspectratio_lut[aspect_ratio_idx].value); + + ps2->keep_aspect = true; + ps2->should_resize = true; +} + +static void ps2_apply_state_changes(void *data) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + ps2->should_resize = true; +} + +static void ps2_viewport_info(void *data, struct video_viewport *vp) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; + + if (ps2) + *vp = ps2->vp; +} + +static const video_poke_interface_t ps2_poke_interface = { + NULL, /* get_flags */ + NULL, /* set_coords */ + NULL, /* set_mvp */ + NULL, + NULL, + NULL, + NULL, /* get_refresh_rate */ + ps2_set_filtering, + NULL, /* get_video_output_size */ + NULL, /* get_video_output_prev */ + NULL, /* get_video_output_next */ + NULL, /* get_current_framebuffer */ + NULL, /* get_proc_address */ + ps2_set_aspect_ratio, + ps2_apply_state_changes, + ps2_set_texture_frame, + ps2_set_texture_enable, + NULL, /* set_osd_msg */ + NULL, /* show_mouse */ + NULL, /* grab_mouse_toggle */ + NULL, /* get_current_shader */ + NULL, /* get_current_software_framebuffer */ + NULL /* get_hw_render_interface */ +}; + +static void ps2_get_poke_interface(void *data, + const video_poke_interface_t **iface) +{ + (void)data; + *iface = &ps2_poke_interface; +} + +static bool ps2_read_viewport(void *data, uint8_t *buffer, bool is_idle) +{ + void* src_buffer; + int i, j, src_bufferwidth, src_pixelformat, src_x, src_y, src_x_max, src_y_max; + uint8_t* dst = buffer; + ps2_video_t *ps2 = (ps2_video_t*)data; + + (void)data; + (void)buffer; + + sceDisplayGetFrameBuf(&src_buffer, &src_bufferwidth, &src_pixelformat, PSP_DISPLAY_SETBUF_NEXTFRAME); + + src_x = (ps2->vp.x > 0)? ps2->vp.x : 0; + src_y = (ps2->vp.y > 0)? ps2->vp.y : 0; + src_x_max = ((ps2->vp.x + ps2->vp.width) < src_bufferwidth)? (ps2->vp.x + ps2->vp.width): src_bufferwidth; + src_y_max = ((ps2->vp.y + ps2->vp.height) < SCEGU_SCR_HEIGHT)? (ps2->vp.y + ps2->vp.height): SCEGU_SCR_HEIGHT; + + switch(src_pixelformat) + { + case PSP_DISPLAY_PIXEL_FORMAT_565: + for (j = (src_y_max - 1); j >= src_y ; j--) + { + uint16_t* src = (uint16_t*)src_buffer + src_bufferwidth * j + src_x; + for (i = src_x; i < src_x_max; i++) + { + + *(dst++) = ((*src) >> 11) << 3; + *(dst++) = (((*src) >> 5) << 2) &0xFF; + *(dst++) = ((*src) & 0x1F) << 3; + src++; + } + } + return true; + + case PSP_DISPLAY_PIXEL_FORMAT_5551: + for (j = (src_y_max - 1); j >= src_y ; j--) + { + uint16_t* src = (uint16_t*)src_buffer + src_bufferwidth * j + src_x; + for (i = src_x; i < src_x_max; i++) + { + + *(dst++) = (((*src) >> 10) << 3) &0xFF; + *(dst++) = (((*src) >> 5) << 3) &0xFF; + *(dst++) = ((*src) & 0x1F) << 3; + src++; + } + } + return true; + + case PSP_DISPLAY_PIXEL_FORMAT_4444: + for (j = (src_y_max - 1); j >= src_y ; j--) + { + uint16_t* src = (uint16_t*)src_buffer + src_bufferwidth * j + src_x; + for (i = src_x; i < src_x_max; i++) + { + + *(dst++) = ((*src) >> 4) & 0xF0; + *(dst++) = (*src) & 0xF0; + *(dst++) = ((*src) << 4) & 0xF0; + src++; + } + } + return true; + + case PSP_DISPLAY_PIXEL_FORMAT_8888: + for (j = (src_y_max - 1); j >= src_y ; j--) + { + uint32_t* src = (uint32_t*)src_buffer + src_bufferwidth * j + src_x; + for (i = src_x; i < src_x_max; i++) + { + + *(dst++) = ((*src) >> 16) & 0xFF; + *(dst++) = ((*src) >> 8 ) & 0xFF; + *(dst++) = (*src) & 0xFF; + src++; + } + } + return true; + } + + + return false; +} + +static bool ps2_set_shader(void *data, + enum rarch_shader_type type, const char *path) +{ + (void)data; + (void)type; + (void)path; + + return false; +} + +video_driver_t video_ps2 = { + ps2_init, + ps2_frame, + ps2_set_nonblock_state, + ps2_alive, + ps2_focus, + ps2_suppress_screensaver, + NULL, /* has_windowed */ + ps2_set_shader, + ps2_free, + "ps2", + NULL, /* set_viewport */ + ps2_set_rotation, + ps2_viewport_info, + ps2_read_viewport, + NULL, /* read_frame_raw */ +#ifdef HAVE_OVERLAY + NULL, +#endif + ps2_get_poke_interface +}; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 07d6ffea55..1f5eddd24c 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -295,6 +295,9 @@ static const video_driver_t *video_drivers[] = { #ifdef PSP &video_psp1, #endif +#ifdef PS2 +// &video_ps2, // TODO: FJTRUJY +#endif #ifdef _3DS &video_ctr, #endif diff --git a/griffin/griffin.c b/griffin/griffin.c index f84450d833..224ecec0ff 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -438,6 +438,8 @@ VIDEO DRIVER #include "../gfx/drivers/gx_gfx.c" #elif defined(PSP) #include "../gfx/drivers/psp1_gfx.c" +#elif defined(PS2) +// #include "../gfx/drivers/ps2_gfx.c" #elif defined(HAVE_VITA2D) #include "../deps/libvita2d/source/vita2d.c" #include "../deps/libvita2d/source/vita2d_texture.c" @@ -567,6 +569,9 @@ INPUT #elif defined(SN_TARGET_PSP2) || defined(PSP) || defined(VITA) #include "../input/drivers/psp_input.c" #include "../input/drivers_joypad/psp_joypad.c" +#elif defined(PS2) +// #include "../input/drivers/ps2_input.c" +// #include "../input/drivers_joypad/ps2_joypad.c" #elif defined(HAVE_COCOA) || defined(HAVE_COCOATOUCH) || defined(HAVE_COCOA_METAL) #include "../input/drivers/cocoa_input.c" #elif defined(_3DS) @@ -764,6 +769,8 @@ AUDIO #include "../audio/drivers/rwebaudio.c" #elif defined(PSP) || defined(VITA) #include "../audio/drivers/psp_audio.c" +#elif defined(PS2) +// #include "../audio/drivers/ps2_audio.c" #elif defined(_3DS) #include "../audio/drivers/ctr_csnd_audio.c" #include "../audio/drivers/ctr_dsp_audio.c" @@ -959,6 +966,8 @@ FRONTEND #include "../frontend/drivers/platform_wiiu.c" #elif defined(PSP) || defined(VITA) #include "../frontend/drivers/platform_psp.c" +#elif defined(PS2) +#include "../frontend/drivers/platform_ps2.c" #elif defined(_3DS) #include "../frontend/drivers/platform_ctr.c" #elif defined(SWITCH) && defined(HAVE_LIBNX) diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c new file mode 100644 index 0000000000..1db7a758ce --- /dev/null +++ b/input/drivers/ps2_input.c @@ -0,0 +1,161 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#ifdef HAVE_CONFIG_H +#include "../../config.h" +#endif + +#include + +#include +#include +#include + +#ifdef HAVE_KERNEL_PRX +#include "../../bootstrap/ps2/kernel_functions.h" +#endif + +#include "../../defines/ps2_defines.h" + +#include "../input_driver.h" + +/* TODO/FIXME - + * fix game focus toggle */ + +typedef struct ps2_input +{ + bool blocked; + const input_device_driver_t *joypad; +} ps2_input_t; + +static void ps2_input_poll(void *data) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + + if (ps2 && ps2->joypad) + ps2->joypad->poll(); +} + +static int16_t ps2_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, + unsigned port, unsigned device, + unsigned idx, unsigned id) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + + switch (device) + { + case RETRO_DEVICE_JOYPAD: + return input_joypad_pressed(ps2->joypad, joypad_info, port, binds[port], id); + case RETRO_DEVICE_ANALOG: + if (binds[port]) + return input_joypad_analog(ps2->joypad, joypad_info, port, idx, id, binds[port]); + break; + } + + return 0; +} + +static void ps2_input_free_input(void *data) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + + if (ps2 && ps2->joypad) + ps2->joypad->destroy(); + + free(data); +} + +static void* ps2_input_initialize(const char *joypad_driver) +{ + ps2_input_t *ps2 = (ps2_input_t*)calloc(1, sizeof(*ps2)); + if (!ps2) + return NULL; + + ps2->joypad = input_joypad_init_driver(joypad_driver, ps2); + + return ps2; +} + +static uint64_t ps2_input_get_capabilities(void *data) +{ + (void)data; + + return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG); +} + +static const input_device_driver_t *ps2_input_get_joypad_driver(void *data) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + if (ps2) + return ps2->joypad; + return NULL; +} + +static void ps2_input_grab_mouse(void *data, bool state) +{ + (void)data; + (void)state; +} + +static bool ps2_input_set_rumble(void *data, unsigned port, + enum retro_rumble_effect effect, uint16_t strength) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + + if (ps2 && ps2->joypad) + return input_joypad_set_rumble(ps2->joypad, + port, effect, strength); + return false; +} + +static bool ps2_input_keyboard_mapping_is_blocked(void *data) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + if (!ps2) + return false; + return ps2->blocked; +} + +static void ps2_input_keyboard_mapping_set_block(void *data, bool value) +{ + ps2_input_t *ps2 = (ps2_input_t*)data; + if (!ps2) + return; + ps2->blocked = value; +} + +input_driver_t input_ps2 = { + ps2_input_initialize, + ps2_input_poll, + ps2_input_state, + ps2_input_free_input, + NULL, + NULL, + ps2_input_get_capabilities, + "ps2", + ps2_input_grab_mouse, + NULL, + ps2_input_set_rumble, + ps2_input_get_joypad_driver, + NULL, + ps2_input_keyboard_mapping_is_blocked, + ps2_input_keyboard_mapping_set_block, +}; diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c new file mode 100644 index 0000000000..61a541be29 --- /dev/null +++ b/input/drivers_joypad/ps2_joypad.c @@ -0,0 +1,208 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2017 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#include "../input_driver.h" + +#include "../../tasks/tasks_internal.h" + +#include "../../configuration.h" + +#include "../../defines/ps2_defines.h" + +#ifdef HAVE_MENU +#include "../../menu/menu_driver.h" +#endif + +#define PS2_MAX_PADS 1 + +static uint64_t pad_state[PS2_MAX_PADS]; +static int16_t analog_state[PS2_MAX_PADS][2][2]; + +extern uint64_t lifecycle_state; + +static const char *ps2_joypad_name(unsigned pad) +{ + return "PS2 Controller"; +} + +static bool ps2_joypad_init(void *data) +{ + unsigned i; + unsigned players_count = PS2_MAX_PADS; + + for (i = 0; i < players_count; i++) + { + if (!input_autoconfigure_connect( + ps2_joypad_name(i), + NULL, + ps2_joypad.ident, + i, + 0, + 0 + )) + input_config_set_device_name(i, ps2_joypad_name(i)); + } + + return true; +} + +static bool ps2_joypad_button(unsigned port_num, uint16_t key) +{ + if (port_num >= PS2_MAX_PADS) + return false; + + return (pad_state[port_num] & (UINT64_C(1) << key)); +} + +static void ps2_joypad_get_buttons(unsigned port_num, input_bits_t *state) +{ + if (port_num < PS2_MAX_PADS) + { + BITS_COPY16_PTR( state, pad_state[port_num] ); + } + else + BIT256_CLEAR_ALL_PTR(state); +} + +static int16_t ps2_joypad_axis(unsigned port_num, uint32_t joyaxis) +{ + int val = 0; + int axis = -1; + bool is_neg = false; + bool is_pos = false; + + if (joyaxis == AXIS_NONE || port_num >= PS2_MAX_PADS) + return 0; + + if (AXIS_NEG_GET(joyaxis) < 4) + { + axis = AXIS_NEG_GET(joyaxis); + is_neg = true; + } + else if (AXIS_POS_GET(joyaxis) < 4) + { + axis = AXIS_POS_GET(joyaxis); + is_pos = true; + } + + switch (axis) + { + case 0: + val = analog_state[port_num][0][0]; + break; + case 1: + val = analog_state[port_num][0][1]; + break; + case 2: + val = analog_state[port_num][1][0]; + break; + case 3: + val = analog_state[port_num][1][1]; + break; + } + + if (is_neg && val > 0) + val = 0; + else if (is_pos && val < 0) + val = 0; + + return val; +} + +static void ps2_joypad_poll(void) +{ + unsigned player; + unsigned players_count = PS2_MAX_PADS; + + BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE); + + for (player = 0; player < players_count; player++) + { + unsigned j, k; + unsigned i = player; + unsigned p = player; + int32_t state_tmp = padGetState(player, player); + + + pad_state[i] = 0; + analog_state[i][0][0] = analog_state[i][0][1] = + analog_state[i][1][0] = analog_state[i][1][1] = 0; + +#ifdef HAVE_KERNEL_PRX + state_tmp.Buttons = (state_tmp.Buttons & 0x0000FFFF) + | (read_system_buttons() & 0xFFFF0000); +#endif + + pad_state[i] |= (state_tmp & PAD_LEFT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + pad_state[i] |= (state_tmp & PAD_DOWN) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + pad_state[i] |= (state_tmp & PAD_RIGHT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + pad_state[i] |= (state_tmp & PAD_UP) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + pad_state[i] |= (state_tmp & PAD_START) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_START) : 0; + pad_state[i] |= (state_tmp & PAD_SELECT) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0; + pad_state[i] |= (state_tmp & PAD_TRIANGLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_X) : 0; + pad_state[i] |= (state_tmp & PAD_SQUARE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + pad_state[i] |= (state_tmp & PAD_CROSS) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_B) : 0; + pad_state[i] |= (state_tmp & PAD_CIRCLE) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_A) : 0; + pad_state[i] |= (state_tmp & PAD_R1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R) : 0; + pad_state[i] |= (state_tmp & PAD_L1) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L) : 0; + pad_state[i] |= (state_tmp & PAD_R2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R2) : 0; + pad_state[i] |= (state_tmp & PAD_L2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0; + pad_state[i] |= (state_tmp & PAD_R3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0; + pad_state[i] |= (state_tmp & PAD_L3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0; + +#ifdef HAVE_KERNEL_PRX + if (state_tmp & PS2_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) + analog_state[i][j][k] = -0x7fff; + } +} + +static bool ps2_joypad_query_pad(unsigned pad) +{ + return pad < PS2_MAX_PADS && pad_state[pad]; +} + +static bool ps2_joypad_rumble(unsigned pad, + enum retro_rumble_effect effect, uint16_t strength) +{ + return false; +} + + +static void ps2_joypad_destroy(void) +{ +} + +input_device_driver_t ps2_joypad = { + ps2_joypad_init, + ps2_joypad_query_pad, + ps2_joypad_destroy, + ps2_joypad_button, + ps2_joypad_get_buttons, + ps2_joypad_axis, + ps2_joypad_poll, + ps2_joypad_rumble, + ps2_joypad_name, + "ps2", +}; diff --git a/input/input_autodetect_builtin.c b/input/input_autodetect_builtin.c index df74a8627f..98d9e3405d 100644 --- a/input/input_autodetect_builtin.c +++ b/input/input_autodetect_builtin.c @@ -178,6 +178,32 @@ DECL_AXIS_EX(r_x_minus, -2, "R-Stick left") \ DECL_AXIS_EX(r_y_plus, +3, "R-Stick down") \ DECL_AXIS_EX(r_y_minus, -3, "R-Stick up") +#define PS2INPUT_DEFAULT_BINDS \ +DECL_BTN_EX(a, 8, "Circle") \ +DECL_BTN_EX(b, 0, "Cross") \ +DECL_BTN_EX(x, 9, "Triangle") \ +DECL_BTN_EX(y, 1, "Square") \ +DECL_BTN_EX(start, 3, "Start") \ +DECL_BTN_EX(select, 2, "Select") \ +DECL_BTN_EX(up, 4, "D-Pad up") \ +DECL_BTN_EX(down, 5, "D-Pad down") \ +DECL_BTN_EX(left, 6, "D-Pad left") \ +DECL_BTN_EX(right, 7, "D-Pad right") \ +DECL_BTN_EX(l, 10, "L1") \ +DECL_BTN_EX(r, 11, "R1") \ +DECL_BTN_EX(l2, 12, "L2") \ +DECL_BTN_EX(r2, 13, "R2") \ +DECL_BTN_EX(l3, 14, "L3") \ +DECL_BTN_EX(r3, 15, "R3") \ +DECL_AXIS_EX(l_x_plus, +0, "L-Stick right") \ +DECL_AXIS_EX(l_x_minus, -0, "L-Stick left") \ +DECL_AXIS_EX(l_y_plus, +1, "L-Stick down") \ +DECL_AXIS_EX(l_y_minus, -1, "L-Stick up") \ +DECL_AXIS_EX(r_x_plus, +2, "R-Stick right") \ +DECL_AXIS_EX(r_x_minus, -2, "R-Stick left") \ +DECL_AXIS_EX(r_y_plus, +3, "R-Stick down") \ +DECL_AXIS_EX(r_y_minus, -3, "R-Stick up") + #define CTRINPUT_DEFAULT_BINDS \ DECL_BTN(a, 8) \ DECL_BTN(b, 0) \ @@ -641,6 +667,9 @@ const char* const input_builtin_autoconfs[] = #elif defined(PSP) DECL_AUTOCONF_DEVICE("PSP Controller", "psp", PSPINPUT_DEFAULT_BINDS), #endif +#if defined(PS2) + DECL_AUTOCONF_DEVICE("PS2 Controller", "ps2", PS2INPUT_DEFAULT_BINDS), +#endif #ifdef _3DS DECL_AUTOCONF_DEVICE("3DS Controller", "ctr", CTRINPUT_DEFAULT_BINDS), #endif diff --git a/input/input_driver.c b/input/input_driver.c index 4a6a6fb8b5..447cccec0b 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -86,6 +86,9 @@ static const input_driver_t *input_drivers[] = { #if defined(SN_TARGET_PSP2) || defined(PSP) || defined(VITA) &input_psp, #endif +#if defined(PS2) +// &input_ps2, TODO: FJTRUJY +#endif #if defined(_3DS) &input_ctr, #endif @@ -161,6 +164,9 @@ static input_device_driver_t *joypad_drivers[] = { #if defined(PSP) || defined(VITA) &psp_joypad, #endif +#if defined(PS2) +// &ps2_joypad, // TODO: FJTRUJY +#endif #ifdef _3DS &ctr_joypad, #endif diff --git a/input/input_driver.h b/input/input_driver.h index 6c5b4f1a0f..b3169021ec 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -806,6 +806,7 @@ extern input_device_driver_t xinput_joypad; extern input_device_driver_t sdl_joypad; extern input_device_driver_t ps3_joypad; extern input_device_driver_t psp_joypad; +extern input_device_driver_t ps2_joypad; extern input_device_driver_t ctr_joypad; extern input_device_driver_t switch_joypad; extern input_device_driver_t xdk_joypad; @@ -825,6 +826,7 @@ extern input_driver_t input_dinput; extern input_driver_t input_x; extern input_driver_t input_ps3; extern input_driver_t input_psp; +extern input_driver_t input_ps2; extern input_driver_t input_ctr; extern input_driver_t input_switch; extern input_driver_t input_xenon360; diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index fdefe92714..84c9836d22 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -65,6 +65,11 @@ #include #endif +#if defined(PS2) +#include +#include +#endif + #if defined(__PSL1GHT__) #include #elif defined(__CELLOS_LV2__) @@ -184,6 +189,8 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) sceRtcGetCurrentTick((uint64_t*)&time_ticks); #elif defined(VITA) sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); +#elif defined(PS2) + time_ticks = ((uint64_t)cpu_ticks()); #elif defined(_3DS) time_ticks = svcGetSystemTick(); #elif defined(WIIU) @@ -232,6 +239,8 @@ retro_time_t cpu_features_get_time_usec(void) return tv.tv_sec * INT64_C(1000000) + (tv.tv_nsec + 500) / 1000; #elif defined(EMSCRIPTEN) return emscripten_get_now() * 1000; +#elif defined(PS2) + return cpu_ticks()/295.0; #elif defined(__mips__) || defined(DJGPP) struct timeval tv; gettimeofday(&tv,NULL); @@ -479,7 +488,7 @@ unsigned cpu_features_get_core_amount(void) return sysinfo.dwNumberOfProcessors; #elif defined(GEKKO) return 1; -#elif defined(PSP) +#elif defined(PSP) || defined(PS2) return 1; #elif defined(VITA) return 4; @@ -787,7 +796,7 @@ uint64_t cpu_features_get(void) cpu |= RETRO_SIMD_VMX; #elif defined(XBOX360) cpu |= RETRO_SIMD_VMX128; -#elif defined(PSP) +#elif defined(PSP) || defined(PS2) cpu |= RETRO_SIMD_VFPU; #elif defined(GEKKO) cpu |= RETRO_SIMD_PS; diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 2e90537210..1e910f4ec1 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -79,6 +79,11 @@ #include #endif +#if defined(PS2) +#include +#include +#endif + #if defined(__CELLOS_LV2__) #include #endif @@ -122,7 +127,19 @@ static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) return false; } free(tmp); +#elif defined(PS2) + iox_stat_t buf; + char *tmp = strdup(path); + size_t len = strlen(tmp); + if (tmp[len-1] == '/') + tmp[len-1]='\0'; + if (fileXioGetStat(tmp, &buf) < 0) + { + free(tmp); + return false; + } + free(tmp); #elif defined(__CELLOS_LV2__) CellFsStat buf; if (cellFsStat(path, &buf) < 0) @@ -167,13 +184,18 @@ static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) #endif if (size) +#if defined(PS2) + *size = (int32_t)buf.size; +#else *size = (int32_t)buf.st_size; - +#endif switch (mode) { case IS_DIRECTORY: #if defined(VITA) || defined(PSP) return FIO_S_ISDIR(buf.st_mode); +#elif defined(PS2) + return FIO_S_ISDIR(buf.mode); #elif defined(__CELLOS_LV2__) return ((buf.st_mode & S_IFMT) == S_IFDIR); #elif defined(_WIN32) @@ -182,7 +204,7 @@ static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) return S_ISDIR(buf.st_mode); #endif case IS_CHARACTER_SPECIAL: -#if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32) +#if defined(VITA) || defined(PSP) || defined(PS2) || defined(__CELLOS_LV2__) || defined(_WIN32) return false; #else return S_ISCHR(buf.st_mode); @@ -230,7 +252,7 @@ static bool path_mkdir_error(int ret) { #if defined(VITA) return (ret == SCE_ERROR_ERRNO_EEXIST); -#elif defined(PSP) || defined(_3DS) || defined(WIIU) || defined(SWITCH) +#elif defined(PSP) || defined(PS2) || defined(_3DS) || defined(WIIU) || defined(SWITCH) return (ret == -1); #else return (ret < 0 && errno == EEXIST); @@ -299,6 +321,8 @@ bool path_mkdir(const char *dir) int ret = mkdir(dir, 0755); #elif defined(VITA) || defined(PSP) int ret = sceIoMkdir(dir, 0777); +#elif defined(PS2) + int ret =fileXioMkdir(dir, 0777); #elif defined(__QNX__) int ret = mkdir(dir, 0777); #else diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index 0b6ecad246..ea8d520fcb 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -49,11 +49,14 @@ #elif defined(VITA) # include # include -#include +# include #else # if defined(PSP) # include # endif +# if defined(PS2) +# include +# endif # include # include # include @@ -64,7 +67,7 @@ #include #endif -#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) +#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) || defined(PS2) #include /* stat() is defined here */ #endif @@ -88,6 +91,9 @@ struct RDIR #elif defined(VITA) || defined(PSP) SceUID directory; SceIoDirent entry; +#elif defined(PS2) + int directory; + iox_dirent_t entry; #elif defined(__CELLOS_LV2__) CellFsErrno error; int directory; @@ -146,6 +152,8 @@ struct RDIR *retro_opendir(const char *name) #elif defined(VITA) || defined(PSP) rdir->directory = sceIoDopen(name); +#elif defined(PS2) + rdir->directory = fileXioDopen(name); #elif defined(_3DS) rdir->directory = !string_is_empty(name) ? opendir(name) : NULL; rdir->entry = NULL; @@ -167,7 +175,7 @@ bool retro_dirent_error(struct RDIR *rdir) { #if defined(_WIN32) return (rdir->directory == INVALID_HANDLE_VALUE); -#elif defined(VITA) || defined(PSP) +#elif defined(VITA) || defined(PSP) || defined(PS2) return (rdir->directory < 0); #elif defined(__CELLOS_LV2__) return (rdir->error != CELL_FS_SUCCEEDED); @@ -190,6 +198,8 @@ int retro_readdir(struct RDIR *rdir) return (rdir->directory != INVALID_HANDLE_VALUE); #elif defined(VITA) || defined(PSP) return (sceIoDread(rdir->directory, &rdir->entry) > 0); +#elif defined(PS2) + return (fileXioDread(rdir->directory, &rdir->entry) > 0); #elif defined(__CELLOS_LV2__) uint64_t nread; rdir->error = cellFsReaddir(rdir->directory, &rdir->entry, &nread); @@ -220,6 +230,8 @@ const char *retro_dirent_get_name(struct RDIR *rdir) return (char*)rdir->entry.cFileName; #elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) return rdir->entry.d_name; +#elif defined(PS2) + return rdir->entry.name; #else return rdir->entry->d_name; @@ -244,10 +256,14 @@ bool retro_dirent_is_dir(struct RDIR *rdir, const char *path) return entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; #elif defined(PSP) || defined(VITA) const SceIoDirent *entry = (const SceIoDirent*)&rdir->entry; +#elif defined(PS2) + const iox_dirent_t *entry = (const iox_dirent_t*)&rdir->entry; #if defined(PSP) return (entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; #elif defined(VITA) return SCE_S_ISDIR(entry->d_stat.st_mode); +#elif defined(PS2) + return (entry->stat.attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; #endif #elif defined(__CELLOS_LV2__) CellFsDirent *entry = (CellFsDirent*)&rdir->entry; @@ -289,6 +305,8 @@ void retro_closedir(struct RDIR *rdir) FindClose(rdir->directory); #elif defined(VITA) || defined(PSP) sceIoDclose(rdir->directory); +#elif defined(PS2) + fileXioDclose(rdir->directory); #elif defined(__CELLOS_LV2__) rdir->error = cellFsClosedir(rdir->directory); #else diff --git a/libretro-common/include/compat/intrinsics.h b/libretro-common/include/compat/intrinsics.h index 3fc7d92918..f9e39dd97b 100644 --- a/libretro-common/include/compat/intrinsics.h +++ b/libretro-common/include/compat/intrinsics.h @@ -41,7 +41,7 @@ RETRO_BEGIN_DECLS /* Count Leading Zero, unsigned 16bit input value */ static INLINE unsigned compat_clz_u16(uint16_t val) { -#ifdef __GNUC__ +#if defined(__GNUC__) && !defined(PS2) return __builtin_clz(val << 16 | 0x8000); #else unsigned ret = 0; diff --git a/libretro-common/include/compat/posix_string.h b/libretro-common/include/compat/posix_string.h index 9f56322ab9..46c14413c5 100644 --- a/libretro-common/include/compat/posix_string.h +++ b/libretro-common/include/compat/posix_string.h @@ -29,6 +29,10 @@ #include #endif +#if defined(PS2) +#include +#endif + RETRO_BEGIN_DECLS #ifdef _WIN32 diff --git a/libretro-common/include/compat/strcasestr.h b/libretro-common/include/compat/strcasestr.h index f849593b0f..02f28d0192 100644 --- a/libretro-common/include/compat/strcasestr.h +++ b/libretro-common/include/compat/strcasestr.h @@ -25,6 +25,10 @@ #include +#if defined(PS2) +#include +#endif + #if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H) #include "../../../config.h" #endif diff --git a/libretro-common/include/memmap.h b/libretro-common/include/memmap.h index 2bedd5c926..e1d75c39fc 100644 --- a/libretro-common/include/memmap.h +++ b/libretro-common/include/memmap.h @@ -26,7 +26,7 @@ #include #include -#if defined(__CELLOS_LV2__) || defined(PSP) || defined(GEKKO) || defined(VITA) || defined(_XBOX) || defined(_3DS) || defined(WIIU) || defined(SWITCH) +#if defined(__CELLOS_LV2__) || defined(PSP) || defined(PS2) || defined(GEKKO) || defined(VITA) || defined(_XBOX) || defined(_3DS) || defined(WIIU) || defined(SWITCH) /* No mman available */ #elif defined(_WIN32) && !defined(_XBOX) #include diff --git a/libretro-common/include/retro_environment.h b/libretro-common/include/retro_environment.h index 0a40593e31..e220c1529b 100644 --- a/libretro-common/include/retro_environment.h +++ b/libretro-common/include/retro_environment.h @@ -103,4 +103,4 @@ printf("This is C++, version %d.\n", __cplusplus); #endif -#endif \ No newline at end of file +#endif diff --git a/libretro-common/include/retro_miscellaneous.h b/libretro-common/include/retro_miscellaneous.h index 2fd97d54c1..5972c1796f 100644 --- a/libretro-common/include/retro_miscellaneous.h +++ b/libretro-common/include/retro_miscellaneous.h @@ -77,7 +77,7 @@ static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count) #ifndef PATH_MAX_LENGTH #if defined(__CELLOS_LV2__) #define PATH_MAX_LENGTH CELL_FS_MAX_FS_PATH_LENGTH -#elif defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(GEKKO)|| defined(WIIU) +#elif defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) #define PATH_MAX_LENGTH 512 #else #define PATH_MAX_LENGTH 4096 diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h index 6c164e65d0..1670b98e70 100644 --- a/libretro-common/include/retro_timers.h +++ b/libretro-common/include/retro_timers.h @@ -37,6 +37,8 @@ #include #elif defined(VITA) #include +#elif defined(PS2) +#include #elif defined(_3DS) #include <3ds.h> #else @@ -77,6 +79,13 @@ static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp) #define nanosleep nanosleepDOS #endif +#if defined(PS2) +static void threadWakeupCB(s32 alarm_id, u16 time, void *common) +{ + iWakeupThread(*(int*)common); +} +#endif + /** * retro_sleep: * @msec : amount in milliseconds to sleep @@ -89,6 +98,14 @@ static INLINE void retro_sleep(unsigned msec) sys_timer_usleep(1000 * msec); #elif defined(PSP) || defined(VITA) sceKernelDelayThread(1000 * msec); +#elif defined(PS2) + int ThreadID; + + if(msec>0){ + ThreadID=GetThreadId(); + SetAlarm(msec * 16, &threadWakeupCB, &ThreadID); + SleepThread(); + } #elif defined(_3DS) svcSleepThread(1000000 * (s64)msec); #elif defined(__WINRT__) diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index b5db30d788..085952b9ef 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -852,6 +852,10 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us) sys_time_get_current_time(&s, &n); now.tv_sec = s; now.tv_nsec = n; +#elif defined(PS2) + int tickUS = cpu_ticks()/295.0; + now.tv_sec = tickUS/1000000; + now.tv_nsec = tickUS * 1000; #elif defined(__mips__) || defined(VITA) || defined(_3DS) struct timeval tm; diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index 3443381bc7..0213c06091 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -47,6 +47,9 @@ # if defined(PSP) # include # endif +# if defined(PS2) +# include +# endif # include # include # if !defined(VITA) @@ -125,6 +128,8 @@ int64_t retro_vfs_file_seek_internal(libretro_vfs_implementation_file *stream, i return _fseeki64(stream->fp, offset, whence); #elif defined(__CELLOS_LV2__) || defined(_MSC_VER) && _MSC_VER <= 1310 return fseek(stream->fp, (long)offset, whence); +#elif defined(PS2) + return fioLseek(fileno(stream->fp), (off_t)offset, whence); #else return fseeko(stream->fp, (off_t)offset, whence); #endif @@ -231,7 +236,9 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns mode_str = "wb"; flags = O_WRONLY | O_CREAT | O_TRUNC; -#ifndef _WIN32 +#if defined(PS2) + flags |= FIO_S_IRUSR | FIO_S_IWUSR; +#elif !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; @@ -242,7 +249,9 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns mode_str = "w+b"; flags = O_RDWR | O_CREAT | O_TRUNC; -#ifndef _WIN32 +#if defined(PS2) + flags |= FIO_S_IRUSR | FIO_S_IWUSR; +#elif !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; @@ -254,7 +263,9 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, uns mode_str = "r+b"; flags = O_RDWR; -#ifndef _WIN32 +#if defined(PS2) + flags |= FIO_S_IRUSR | FIO_S_IWUSR; +#elif !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; @@ -391,7 +402,7 @@ int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, i #ifdef _WIN32 if(_chsize(_fileno(stream->fp), length) != 0) return -1; -#elif !defined(VITA) && !defined(PSP) && (!defined(SWITCH) || defined(HAVE_LIBNX)) +#elif !defined(VITA) && !defined(PSP) && !defined(PS2) && (!defined(SWITCH) || defined(HAVE_LIBNX)) if(ftruncate(fileno(stream->fp), length) != 0) return -1; #endif diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 346be1ab5d..3740c53610 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -69,7 +69,7 @@ typedef struct static uint16_t *rgui_framebuf_data = NULL; -#if defined(GEKKO)|| defined(PSP) +#if defined(GEKKO)|| defined(PSP) || defined(PS2) #define HOVER_COLOR(settings) ((3 << 0) | (10 << 4) | (3 << 8) | (7 << 12)) #define NORMAL_COLOR(settings) 0x7FFF #define TITLE_COLOR(settings) HOVER_COLOR(settings) @@ -93,7 +93,7 @@ static uint16_t rgui_gray_filler(rgui_t *rgui, unsigned x, unsigned y) { unsigned shft = (rgui->bg_thickness ? 1 : 0); unsigned col = (((x >> shft) + (y >> shft)) & 1) + 1; -#if defined(GEKKO) || defined(PSP) +#if defined(GEKKO) || defined(PSP) || defined(PS2) return (6 << 12) | (col << 8) | (col << 4) | (col << 0); #elif defined(HAVE_LIBNX) && !defined(HAVE_OPENGL) return (((31 * (54)) / 255) << 11) | @@ -108,7 +108,7 @@ static uint16_t rgui_green_filler(rgui_t *rgui, unsigned x, unsigned y) { unsigned shft = (rgui->border_thickness ? 1 : 0); unsigned col = (((x >> shft) + (y >> shft)) & 1) + 1; -#if defined(GEKKO) || defined(PSP) +#if defined(GEKKO) || defined(PSP) || defined(PS2) return (6 << 12) | (col << 8) | (col << 5) | (col << 0); #elif defined(HAVE_LIBNX) && !defined(HAVE_OPENGL) return (((31 * (54)) / 255) << 11) | diff --git a/ps2/compat_ctype.c b/ps2/compat_ctype.c new file mode 100644 index 0000000000..94e773356c --- /dev/null +++ b/ps2/compat_ctype.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +#define ULLONG_MAX UINT64_C(0xffffffffffffffff) + +char * strtok_r(char *str, const char *delim, char **nextp) +{ + char *ret; + + if (str == NULL) { + str = *nextp; + } + + str += strspn(str, delim); + + if (*str == '\0') { + return NULL; + } + + ret = str; + + str += strcspn(str, delim); + + if (*str) { + *str++ = '\0'; + } + + *nextp = str; + + return ret; +} + +unsigned long long strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long long acc; + char c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULLONG_MAX / base; + cutlim = ULLONG_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} + +int link(const char *oldpath, const char *newpath) +{ + return fileXioSymlink(oldpath, newpath); +} diff --git a/ps2/include/compat_ctype.h b/ps2/include/compat_ctype.h new file mode 100644 index 0000000000..ca3f5fefc5 --- /dev/null +++ b/ps2/include/compat_ctype.h @@ -0,0 +1,9 @@ +#ifndef COMPAT_CTYPE_H +#define COMPAT_CTYPE_H + +unsigned long long strtoull(const char * __restrict nptr, char ** __restrict endptr, int base); +char * strtok_r(char *str, const char *delim, char **nextp); + +int link(const char *oldpath, const char *newpath); + +#endif diff --git a/ps2/include/inttypes.h b/ps2/include/inttypes.h new file mode 100644 index 0000000000..3049fbdbba --- /dev/null +++ b/ps2/include/inttypes.h @@ -0,0 +1,8 @@ +#ifndef INTTYPES_H +#define INTTYPES_H + +#define PRId64 "ld" +#define PRIu64 "lu" +#define PRIuPTR "lu" + +#endif //INTTYPES_H diff --git a/ps2/include/math.h b/ps2/include/math.h new file mode 100644 index 0000000000..bf0071edb1 --- /dev/null +++ b/ps2/include/math.h @@ -0,0 +1,21 @@ +#ifndef MATH_H +#define MATH_H + +#include +#define roundf(in) (in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f)) + +#define cos(x) ((double)cosf((float)x)) +#define pow(x, y) ((double)powf((float)x, (float)y)) +#define sin(x) ((double)sinf((float)x)) +#define ceil(x) ((double)ceilf((float)x)) +#define floor(x) ((double)floorf((float)x)) +#define sqrt(x) ((double)sqrtf((float)x)) +#define fabs(x) ((double)fabsf((float)(x))) + +#define fmaxf(a, b) (((a) > (b)) ? (a) : (b)) +#define fminf(a, b) (((a) < (b)) ? (a) : (b)) + +#define exp(a) ((double)expf((float)a)) +#define log(a) ((double)logf((float)a)) + +#endif //MATH_H diff --git a/ps2/include/pte_types.h b/ps2/include/pte_types.h new file mode 100644 index 0000000000..7e81156684 --- /dev/null +++ b/ps2/include/pte_types.h @@ -0,0 +1,26 @@ +/* pte_types.h */ + +#ifndef PTE_TYPES_H +#define PTE_TYPES_H + +#include +#include +#include +#include + +/** UIDs are used to describe many different kernel objects. */ +typedef int SceUID; + +/* Misc. kernel types. */ +typedef unsigned int SceSize; +typedef int SceSSize; + +typedef unsigned char SceUChar; +typedef unsigned int SceUInt; + +/* File I/O types. */ +typedef int SceMode; +typedef long SceOff; +typedef long SceIores; + +#endif /* PTE_TYPES_H */ diff --git a/ps2/include/stdint.h b/ps2/include/stdint.h new file mode 100644 index 0000000000..813efd21f8 --- /dev/null +++ b/ps2/include/stdint.h @@ -0,0 +1,30 @@ +#ifndef STDINT_H +#define STDINT_H + +typedef unsigned long uintptr_t; +typedef signed long intptr_t; + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long uint64_t; + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#define INT8_C(val) val##c +#define INT16_C(val) val##h +#define INT32_C(val) val##i +#define INT64_C(val) val##l + +#define UINT8_C(val) val##uc +#define UINT16_C(val) val##uh +#define UINT32_C(val) val##ui +#define UINT64_C(val) val##ul + +#endif //STDINT_H diff --git a/tasks/task_content.c b/tasks/task_content.c index 5747236df6..af28c4fcac 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1654,7 +1654,7 @@ bool task_push_start_builtin_core( /* Preliminary stuff that has to be done before we * load the actual content. Can differ per mode. */ retroarch_set_current_core_type(type, true); - + printf("Step 1\n"); /* Load content */ if (!task_load_content_callback(content_info, true, false)) {