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 01/24] 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)) { From d7cc3b798364a0a0283f09b5a025c8a8ff3f26c8 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Tue, 9 Oct 2018 19:20:58 +0200 Subject: [PATCH 02/24] PS2 making the gfx driver clean the screen --- Makefile.ps2 | 4 +- gfx/drivers/ps2_gfx.c | 1021 ++++++----------------------------------- gfx/video_driver.c | 2 +- gfx/video_driver.h | 1 + griffin/griffin.c | 2 +- 5 files changed, 139 insertions(+), 891 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index ba9d92549b..642a9940dd 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -36,11 +36,11 @@ RARCH_DEFINES = -DPS2 -DUSE_IOP_CTYPE_MACRO -D_MIPS_ARCH_R5900 -DHAVE_ZLIB -DHAV 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. +LDFLAGS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/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 +LIBS += -lfileXio -lm -lg -lz -ldebug -lfileXio -laudsrv -lpatches -lpoweroff -ldma -lgskit -ldmakit #IRX modules # IRX modules - modules have to be in IRX_DIR diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index a460584513..697685181d 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -1,5 +1,5 @@ /* RetroArch - A frontend for libretro. - * Copyright (C) 2014-2017 - Ali Bouhlel + * 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 @@ -14,940 +14,157 @@ * If not, see . */ -#include -#include -#include -#include -#include -#include +#include "../video_driver.h" -#include -#include -#include +#include "../../driver.h" +#include "../../verbosity.h" -#ifdef HAVE_CONFIG_H -#include "../../config.h" -#endif +#include +#include +#include +#include -#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; + GSGLOBAL *gsGlobal; + GSTEXTURE *backgroundTexture; } 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) +// PRIVATE METHODS +static void initGSGlobal(ps2_video_t *ps2) { + /* Initilize DMAKit */ + dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); -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; + /* Initialize the DMAC */ + dmaKit_chan_init(DMA_CHANNEL_GIF); - if (rotation == 0) - { - x0 = x; - y0 = y; - step_x = ((float) width) / PSP_FRAME_COLUMNS_COUNT; - step_y = ((float) height) / PSP_FRAME_ROWS_COUNT; + // /* Initilize the GS */ + if(ps2->gsGlobal!=NULL) { + gsKit_deinit_global(ps2->gsGlobal); + } + ps2->gsGlobal=gsKit_init_global(); - for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) - { - framecoords[i].v0.x = x0; - framecoords[i].v0.y = y0; + ps2->gsGlobal->DoubleBuffering = GS_SETTING_OFF; /* Disable double buffering to get rid of the "Out of VRAM" error */ + ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ + ps2->gsGlobal->ZBuffering = GS_SETTING_OFF; + ps2->gsGlobal->PSM=GS_PSM_CT16; - 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; - } - } + ps2->gsGlobal->Interlace = GS_INTERLACED; + ps2->gsGlobal->Mode = GS_MODE_NTSC; + ps2->gsGlobal->Field = GS_FIELD; + ps2->gsGlobal->Width = 640; + ps2->gsGlobal->Height = 448; + + gsKit_init_screen(ps2->gsGlobal); /* Apply settings. */ + gsKit_mode_switch(ps2->gsGlobal, GS_ONESHOT); +} + +static size_t gskitTextureSize(GSTEXTURE *texture) { + return gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM); +} + +static void prepareTexture(GSTEXTURE *texture, int delayed) { + texture->Width = 640; + texture->Height = 448; + texture->PSM = GS_PSM_CT16; + if (delayed) { + texture->Delayed = GS_SETTING_ON; } - 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; + texture->Filter = GS_FILTER_NEAREST; + texture->Mem = memalign(128, gskitTextureSize(texture)); + gsKit_setup_tbw(texture); +} - for (i=0; i < PSP_FRAME_SLICE_COUNT; i++) - { - framecoords[i].v0.x = x0; - framecoords[i].v0.y = y0; +static void initBackgroundTexture(ps2_video_t *ps2) { + ps2->backgroundTexture = malloc(sizeof *ps2->backgroundTexture); + prepareTexture(ps2->backgroundTexture, 1); +} - 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 void deinitTexturePTR(void *texture_ptr) { + if(texture_ptr!=NULL){ + free(texture_ptr); + texture_ptr=NULL; } } -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 deinitTexture(GSTEXTURE *texture) { + deinitTexturePTR(texture->Mem); + deinitTexturePTR(texture->Clut); } -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, +static void *ps2_gfx_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. */ + *input = NULL; + *input_data = NULL; + (void)video; - 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)); + 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; + initGSGlobal(ps2); + initBackgroundTexture(ps2); return ps2; } -#if 0 -#define DISPLAY_FPS -#endif - -static bool ps2_frame(void *data, const void *frame, +static bool ps2_gfx_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); - } + (void)data; + (void)frame; + (void)width; + (void)height; + (void)pitch; + (void)msg; return true; } -static void ps2_set_nonblock_state(void *data, bool toggle) +static void ps2_gfx_set_nonblock_state(void *data, bool toggle) { - ps2_video_t *ps2 = (ps2_video_t*)data; - - if (ps2) - ps2->vsync = !toggle; + (void)data; + (void)toggle; } -static bool ps2_alive(void *data) +static bool ps2_gfx_alive(void *data) { (void)data; return true; } -static bool ps2_focus(void *data) +static bool ps2_gfx_focus(void *data) { (void)data; return true; } -static bool ps2_suppress_screensaver(void *data, bool enable) +static bool ps2_gfx_suppress_screensaver(void *data, bool enable) { (void)data; (void)enable; return false; } -static void ps2_free(void *data) +static bool ps2_gfx_has_windowed(void *data) +{ + (void)data; + return true; +} + +static void ps2_gfx_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); + deinitTexture(ps2->backgroundTexture); + gsKit_deinit_global(ps2->gsGlobal); 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, +static bool ps2_gfx_set_shader(void *data, enum rarch_shader_type type, const char *path) { (void)data; @@ -957,24 +174,54 @@ static bool ps2_set_shader(void *data, return false; } +static void ps2_gfx_set_rotation(void *data, + unsigned rotation) +{ + (void)data; + (void)rotation; +} + +static void ps2_gfx_viewport_info(void *data, + struct video_viewport *vp) +{ + (void)data; + (void)vp; +} + +static bool ps2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle) +{ + (void)data; + (void)buffer; + + return true; +} + +static void ps2_gfx_get_poke_interface(void *data, + const video_poke_interface_t **iface) +{ + (void)data; + (void)iface; +} + 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_gfx_init, + ps2_gfx_frame, + ps2_gfx_set_nonblock_state, + ps2_gfx_alive, + ps2_gfx_focus, + ps2_gfx_suppress_screensaver, + ps2_gfx_has_windowed, + ps2_gfx_set_shader, + ps2_gfx_free, "ps2", NULL, /* set_viewport */ - ps2_set_rotation, - ps2_viewport_info, - ps2_read_viewport, + ps2_gfx_set_rotation, + ps2_gfx_viewport_info, + ps2_gfx_read_viewport, NULL, /* read_frame_raw */ + #ifdef HAVE_OVERLAY - NULL, + NULL, /* overlay_interface */ #endif - ps2_get_poke_interface + ps2_gfx_get_poke_interface, }; diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 1f5eddd24c..75f2f46bfb 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -296,7 +296,7 @@ static const video_driver_t *video_drivers[] = { &video_psp1, #endif #ifdef PS2 -// &video_ps2, // TODO: FJTRUJY + &video_ps2, #endif #ifdef _3DS &video_ctr, diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 4c151afbbb..3a261ebdb8 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -1251,6 +1251,7 @@ extern video_driver_t video_vulkan; extern video_driver_t video_metal; extern video_driver_t video_psp1; extern video_driver_t video_vita2d; +extern video_driver_t video_ps2; extern video_driver_t video_ctr; extern video_driver_t video_switch; extern video_driver_t video_d3d8; diff --git a/griffin/griffin.c b/griffin/griffin.c index 224ecec0ff..62cc840c86 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -439,7 +439,7 @@ VIDEO DRIVER #elif defined(PSP) #include "../gfx/drivers/psp1_gfx.c" #elif defined(PS2) -// #include "../gfx/drivers/ps2_gfx.c" +#include "../gfx/drivers/ps2_gfx.c" #elif defined(HAVE_VITA2D) #include "../deps/libvita2d/source/vita2d.c" #include "../deps/libvita2d/source/vita2d_texture.c" From 1f756533f9c24e181c1d1ad60d7178f3069beb69 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 10 Oct 2018 08:02:13 +0200 Subject: [PATCH 03/24] First Content on the Screen!! --- gfx/drivers/ps2_gfx.c | 169 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 8 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 697685181d..d6c62e1183 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -24,11 +24,27 @@ #include #include +#define GS_SCREEN_WIDTH 640; +#define GS_SCREEN_HEIGHT 448; + +#define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) // turn black GS Screen + +typedef struct psp1_menu_frame +{ + void* frame; + int width; + int height; + bool rgb32; + +} ps2_menu_frame_t; typedef struct ps2_video { GSGLOBAL *gsGlobal; GSTEXTURE *backgroundTexture; + + ps2_menu_frame_t menu; + } ps2_video_t; // PRIVATE METHODS @@ -54,25 +70,34 @@ static void initGSGlobal(ps2_video_t *ps2) { ps2->gsGlobal->Interlace = GS_INTERLACED; ps2->gsGlobal->Mode = GS_MODE_NTSC; ps2->gsGlobal->Field = GS_FIELD; - ps2->gsGlobal->Width = 640; - ps2->gsGlobal->Height = 448; + ps2->gsGlobal->Width = GS_SCREEN_WIDTH; + ps2->gsGlobal->Height = GS_SCREEN_HEIGHT; gsKit_init_screen(ps2->gsGlobal); /* Apply settings. */ gsKit_mode_switch(ps2->gsGlobal, GS_ONESHOT); } +static u32 textureSize(GSTEXTURE *texture) { + return gsKit_texture_size(texture->Width, texture->Height, texture->PSM); +} + static size_t gskitTextureSize(GSTEXTURE *texture) { return gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM); } +static void *textureEndPTR(GSTEXTURE *texture) { + return ((void *)((unsigned int)texture->Mem+textureSize(texture))); +} + static void prepareTexture(GSTEXTURE *texture, int delayed) { - texture->Width = 640; - texture->Height = 448; + texture->Width = GS_SCREEN_WIDTH; + texture->Height = GS_SCREEN_HEIGHT; texture->PSM = GS_PSM_CT16; if (delayed) { texture->Delayed = GS_SETTING_ON; } texture->Filter = GS_FILTER_NEAREST; + free(texture->Mem); texture->Mem = memalign(128, gskitTextureSize(texture)); gsKit_setup_tbw(texture); } @@ -94,6 +119,27 @@ static void deinitTexture(GSTEXTURE *texture) { deinitTexturePTR(texture->Clut); } +static void syncGSGlobalChache(GSGLOBAL *gsGlobal) { + gsKit_queue_exec(gsGlobal); +} + +static void syncTextureChache(GSTEXTURE *texture, GSGLOBAL *gsGlobal) { + SyncDCache(texture->Mem, textureEndPTR(texture)); + gsKit_texture_send_inline(gsGlobal, texture->Mem, texture->Width, texture->Height, texture->Vram, texture->PSM, texture->TBW, GS_CLUT_NONE); +} + +static void syncBackgroundChache(ps2_video_t *ps2) { + // We need to create the VRAM just in this state I dont know why... +// ps2->backgroundTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->backgroundTexture) , GSKIT_ALLOC_USERBUFFER); + syncTextureChache(ps2->backgroundTexture, ps2->gsGlobal); +} + + + + + + + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { @@ -106,6 +152,8 @@ static void *ps2_gfx_init(const video_info_t *video, initGSGlobal(ps2); initBackgroundTexture(ps2); + memset(ps2->backgroundTexture->Mem, 255, gskitTextureSize(ps2->backgroundTexture)); + return ps2; } @@ -113,13 +161,38 @@ static bool ps2_gfx_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) { - (void)data; (void)frame; - (void)width; - (void)height; (void)pitch; (void)msg; +#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; + + printf("Size backgroundTexture:%i, size menu:%i\n", gskitTextureSize(ps2->backgroundTexture), ps2->menu.width * ps2->menu.height * (ps2->menu.rgb32 ? 4 : 2)); + uint8_t *src = (uint8_t *)ps2->menu.frame; + uint8_t *dst = (uint8_t *)ps2->backgroundTexture->Mem; + int src_stride = ps2->menu.width * (ps2->menu.rgb32 ? 4 : 2); + int dst_stride = ps2->backgroundTexture->Width * (ps2->menu.rgb32 ? 4 : 2); + while(src < (uint8_t *)ps2->menu.frame + ps2->menu.height * src_stride) + { + memcpy(dst, src, src_stride); + src += src_stride; + dst += dst_stride; + } + + syncBackgroundChache(ps2); + syncGSGlobalChache(ps2->gsGlobal); + + dmaKit_wait_fast(); + return true; } @@ -160,6 +233,8 @@ static void ps2_gfx_free(void *data) deinitTexture(ps2->backgroundTexture); gsKit_deinit_global(ps2->gsGlobal); + + free(ps2->menu.frame); free(data); } @@ -196,11 +271,89 @@ static bool ps2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle) return true; } +static void ps2_set_filtering(void *data, unsigned index, bool smooth) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; +} + +static void ps2_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; +} + +static void ps2_apply_state_changes(void *data) +{ + ps2_video_t *ps2 = (ps2_video_t*)data; +} + +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 (640 * 448)*2 Bytes */ + retro_assert((width*height) < (480 * 448)); +#endif + + printf("ps2_set_texture_frame, width:%i, height:%i, rgb32:%i, alpha:%f\n", width, height, rgb32, alpha); + if ( !ps2->menu.frame || + ps2->menu.width != width || + ps2->menu.height != height || + ps2->menu.rgb32 != rgb32 ) { + free(ps2->menu.frame); + ps2->menu.frame = malloc(width * height * (rgb32 ? 4 : 2)); + ps2->menu.width = width; + ps2->menu.height = height; + ps2->menu.rgb32 = rgb32; + } + + memcpy(ps2->menu.frame, frame, width * height * (rgb32 ? 4 : 2)); + +} + +static void ps2_set_texture_enable(void *data, bool state, bool full_screen) +{ + (void) full_screen; + + ps2_video_t *ps2 = (ps2_video_t*)data; +} + +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_gfx_get_poke_interface(void *data, const video_poke_interface_t **iface) { (void)data; - (void)iface; + *iface = &ps2_poke_interface; } video_driver_t video_ps2 = { From f4680b03eb9b1cb825bbc310e57ee32b07f54a4a Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Mon, 15 Oct 2018 00:48:22 +0200 Subject: [PATCH 04/24] now it looks full screen --- gfx/drivers/ps2_gfx.c | 167 ++++++++++++++++-------------------------- menu/drivers/rgui.c | 2 +- 2 files changed, 64 insertions(+), 105 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index d6c62e1183..7f791b44cb 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -28,53 +28,42 @@ #define GS_SCREEN_HEIGHT 448; #define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) // turn black GS Screen - -typedef struct psp1_menu_frame -{ - void* frame; - int width; - int height; - bool rgb32; - -} ps2_menu_frame_t; +#define GS_WHITE GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00) // turn white GS Screen +#define GS_TEXCOL GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) typedef struct ps2_video { GSGLOBAL *gsGlobal; GSTEXTURE *backgroundTexture; - ps2_menu_frame_t menu; + int counter; } ps2_video_t; // PRIVATE METHODS static void initGSGlobal(ps2_video_t *ps2) { - /* Initilize DMAKit */ - dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); + u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0xFF,0x00); - /* Initialize the DMAC */ - dmaKit_chan_init(DMA_CHANNEL_GIF); + ps2->gsGlobal = gsKit_init_global() - // /* Initilize the GS */ - if(ps2->gsGlobal!=NULL) { - gsKit_deinit_global(ps2->gsGlobal); - } - ps2->gsGlobal=gsKit_init_global(); + ps2->gsGlobal->PSM = GS_PSM_CT16; + // ps2->gsGlobal->PSMZ = GS_PSMZ_16S; + ps2->gsGlobal->DoubleBuffering = GS_SETTING_OFF; + ps2->gsGlobal->ZBuffering = GS_SETTING_OFF; + ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ - ps2->gsGlobal->DoubleBuffering = GS_SETTING_OFF; /* Disable double buffering to get rid of the "Out of VRAM" error */ - ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ - ps2->gsGlobal->ZBuffering = GS_SETTING_OFF; - ps2->gsGlobal->PSM=GS_PSM_CT16; + dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, + D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); + // Initialize the DMAC + dmaKit_chan_init(DMA_CHANNEL_GIF); - ps2->gsGlobal->Interlace = GS_INTERLACED; - ps2->gsGlobal->Mode = GS_MODE_NTSC; - ps2->gsGlobal->Field = GS_FIELD; - ps2->gsGlobal->Width = GS_SCREEN_WIDTH; - ps2->gsGlobal->Height = GS_SCREEN_HEIGHT; + gsKit_init_screen(ps2->gsGlobal); - gsKit_init_screen(ps2->gsGlobal); /* Apply settings. */ - gsKit_mode_switch(ps2->gsGlobal, GS_ONESHOT); + // gsKit_mode_switch(ps2->gsGlobal, GS_PERSISTENT); + gsKit_mode_switch(ps2->gsGlobal, GS_ONESHOT); + + gsKit_clear(ps2->gsGlobal, GS_WHITE); } static u32 textureSize(GSTEXTURE *texture) { @@ -85,26 +74,8 @@ static size_t gskitTextureSize(GSTEXTURE *texture) { return gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM); } -static void *textureEndPTR(GSTEXTURE *texture) { - return ((void *)((unsigned int)texture->Mem+textureSize(texture))); -} - -static void prepareTexture(GSTEXTURE *texture, int delayed) { - texture->Width = GS_SCREEN_WIDTH; - texture->Height = GS_SCREEN_HEIGHT; - texture->PSM = GS_PSM_CT16; - if (delayed) { - texture->Delayed = GS_SETTING_ON; - } - texture->Filter = GS_FILTER_NEAREST; - free(texture->Mem); - texture->Mem = memalign(128, gskitTextureSize(texture)); - gsKit_setup_tbw(texture); -} - static void initBackgroundTexture(ps2_video_t *ps2) { ps2->backgroundTexture = malloc(sizeof *ps2->backgroundTexture); - prepareTexture(ps2->backgroundTexture, 1); } static void deinitTexturePTR(void *texture_ptr) { @@ -117,28 +88,9 @@ static void deinitTexturePTR(void *texture_ptr) { static void deinitTexture(GSTEXTURE *texture) { deinitTexturePTR(texture->Mem); deinitTexturePTR(texture->Clut); +// deinitTexturePTR(texture->Vram); } -static void syncGSGlobalChache(GSGLOBAL *gsGlobal) { - gsKit_queue_exec(gsGlobal); -} - -static void syncTextureChache(GSTEXTURE *texture, GSGLOBAL *gsGlobal) { - SyncDCache(texture->Mem, textureEndPTR(texture)); - gsKit_texture_send_inline(gsGlobal, texture->Mem, texture->Width, texture->Height, texture->Vram, texture->PSM, texture->TBW, GS_CLUT_NONE); -} - -static void syncBackgroundChache(ps2_video_t *ps2) { - // We need to create the VRAM just in this state I dont know why... -// ps2->backgroundTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->backgroundTexture) , GSKIT_ALLOC_USERBUFFER); - syncTextureChache(ps2->backgroundTexture, ps2->gsGlobal); -} - - - - - - static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) @@ -148,12 +100,11 @@ static void *ps2_gfx_init(const video_info_t *video, (void)video; ps2_video_t *ps2 = (ps2_video_t*)calloc(1, sizeof(ps2_video_t)); + ps2->counter = 0; initGSGlobal(ps2); initBackgroundTexture(ps2); - memset(ps2->backgroundTexture->Mem, 255, gskitTextureSize(ps2->backgroundTexture)); - return ps2; } @@ -161,10 +112,6 @@ static bool ps2_gfx_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) { - (void)frame; - (void)pitch; - (void)msg; - #ifdef DISPLAY_FPS uint32_t diff; static uint64_t currentTick,lastTick; @@ -176,22 +123,8 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (!width || !height) return false; - printf("Size backgroundTexture:%i, size menu:%i\n", gskitTextureSize(ps2->backgroundTexture), ps2->menu.width * ps2->menu.height * (ps2->menu.rgb32 ? 4 : 2)); - uint8_t *src = (uint8_t *)ps2->menu.frame; - uint8_t *dst = (uint8_t *)ps2->backgroundTexture->Mem; - int src_stride = ps2->menu.width * (ps2->menu.rgb32 ? 4 : 2); - int dst_stride = ps2->backgroundTexture->Width * (ps2->menu.rgb32 ? 4 : 2); - while(src < (uint8_t *)ps2->menu.frame + ps2->menu.height * src_stride) - { - memcpy(dst, src, src_stride); - src += src_stride; - dst += dst_stride; - } - - syncBackgroundChache(ps2); - syncGSGlobalChache(ps2->gsGlobal); - - dmaKit_wait_fast(); + gsKit_sync_flip(ps2->gsGlobal); + gsKit_queue_exec(ps2->gsGlobal); return true; } @@ -233,8 +166,6 @@ static void ps2_gfx_free(void *data) deinitTexture(ps2->backgroundTexture); gsKit_deinit_global(ps2->gsGlobal); - - free(ps2->menu.frame); free(data); } @@ -295,23 +226,51 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, (void) alpha; #ifdef DEBUG - /* ps2->menu.frame buffer size is (640 * 448)*2 Bytes */ + /* ps2->backgroundTexture.Mem buffer size is (640 * 448)*2 Bytes */ retro_assert((width*height) < (480 * 448)); #endif - + int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; printf("ps2_set_texture_frame, width:%i, height:%i, rgb32:%i, alpha:%f\n", width, height, rgb32, alpha); - if ( !ps2->menu.frame || - ps2->menu.width != width || - ps2->menu.height != height || - ps2->menu.rgb32 != rgb32 ) { - free(ps2->menu.frame); - ps2->menu.frame = malloc(width * height * (rgb32 ? 4 : 2)); - ps2->menu.width = width; - ps2->menu.height = height; - ps2->menu.rgb32 = rgb32; + if ( !ps2->backgroundTexture->Mem || + ps2->backgroundTexture->Width != width || + ps2->backgroundTexture->Height != height || + ps2->backgroundTexture->PSM != PSM ) { + ps2->backgroundTexture->Width = width; + ps2->backgroundTexture->Height = height; + ps2->backgroundTexture->PSM = PSM; + ps2->backgroundTexture->Filter = GS_FILTER_NEAREST; + ps2->backgroundTexture->Mem = memalign(128, gskitTextureSize(ps2->backgroundTexture)); } - memcpy(ps2->menu.frame, frame, width * height * (rgb32 ? 4 : 2)); + + memcpy(ps2->backgroundTexture->Mem, frame, width * height * (rgb32 ? 4 : 2)); + + printf("Counter %i\n", ps2->counter); + ps2->counter++; + + gsKit_vram_clear(ps2->gsGlobal); + ps2->backgroundTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->backgroundTexture) , GSKIT_ALLOC_USERBUFFER); + if(ps2->backgroundTexture->Vram == GSKIT_ALLOC_ERROR) + { + printf("VRAM Allocation Failed. Will not upload texture.\n"); + } + + // Upload texture + gsKit_texture_upload(ps2->gsGlobal, ps2->backgroundTexture); + + printf("Texure 2 VRAM Range = 0x%X - 0x%X\n",ps2->backgroundTexture->Vram, ps2->backgroundTexture->Vram +gsKit_texture_size(ps2->backgroundTexture->Width, ps2->backgroundTexture->Height, ps2->backgroundTexture->PSM) - 1); + + gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->backgroundTexture, + 0.0f, + 0.0f, // Y1 + 0.0f, // U1 + 0.0f, // V1 + ps2->gsGlobal->Width, // X2 + ps2->gsGlobal->Height, // Y2 + ps2->backgroundTexture->Width, // U2 + ps2->backgroundTexture->Height, // V2 + 2, + GS_WHITE); } diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 3740c53610..2c8b7bb89e 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) || defined(PS2) +#if defined(GEKKO)|| defined(PSP) #define HOVER_COLOR(settings) ((3 << 0) | (10 << 4) | (3 << 8) | (7 << 12)) #define NORMAL_COLOR(settings) 0x7FFF #define TITLE_COLOR(settings) HOVER_COLOR(settings) From 21587ba2a46e58ef7a1e85b066ed0c9864c06a48 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Tue, 16 Oct 2018 01:35:09 +0200 Subject: [PATCH 05/24] Now RGUI shows fullscreen proper colors --- gfx/drivers/ps2_gfx.c | 16 +--------------- menu/drivers/rgui.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 7f791b44cb..6a679695c5 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -35,9 +35,6 @@ typedef struct ps2_video { GSGLOBAL *gsGlobal; GSTEXTURE *backgroundTexture; - - int counter; - } ps2_video_t; // PRIVATE METHODS @@ -88,7 +85,6 @@ static void deinitTexturePTR(void *texture_ptr) { static void deinitTexture(GSTEXTURE *texture) { deinitTexturePTR(texture->Mem); deinitTexturePTR(texture->Clut); -// deinitTexturePTR(texture->Vram); } @@ -100,7 +96,6 @@ static void *ps2_gfx_init(const video_info_t *video, (void)video; ps2_video_t *ps2 = (ps2_video_t*)calloc(1, sizeof(ps2_video_t)); - ps2->counter = 0; initGSGlobal(ps2); initBackgroundTexture(ps2); @@ -165,6 +160,7 @@ static void ps2_gfx_free(void *data) ps2_video_t *ps2 = (ps2_video_t*)data; deinitTexture(ps2->backgroundTexture); + gsKit_vram_clear(ps2->gsGlobal); gsKit_deinit_global(ps2->gsGlobal); free(data); @@ -222,9 +218,6 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, { ps2_video_t *ps2 = (ps2_video_t*)data; - (void) rgb32; - (void) alpha; - #ifdef DEBUG /* ps2->backgroundTexture.Mem buffer size is (640 * 448)*2 Bytes */ retro_assert((width*height) < (480 * 448)); @@ -242,12 +235,8 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, ps2->backgroundTexture->Mem = memalign(128, gskitTextureSize(ps2->backgroundTexture)); } - memcpy(ps2->backgroundTexture->Mem, frame, width * height * (rgb32 ? 4 : 2)); - printf("Counter %i\n", ps2->counter); - ps2->counter++; - gsKit_vram_clear(ps2->gsGlobal); ps2->backgroundTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->backgroundTexture) , GSKIT_ALLOC_USERBUFFER); if(ps2->backgroundTexture->Vram == GSKIT_ALLOC_ERROR) @@ -257,9 +246,6 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, // Upload texture gsKit_texture_upload(ps2->gsGlobal, ps2->backgroundTexture); - - printf("Texure 2 VRAM Range = 0x%X - 0x%X\n",ps2->backgroundTexture->Vram, ps2->backgroundTexture->Vram +gsKit_texture_size(ps2->backgroundTexture->Width, ps2->backgroundTexture->Height, ps2->backgroundTexture->PSM) - 1); - gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->backgroundTexture, 0.0f, 0.0f, // Y1 diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 2c8b7bb89e..16e2996a9f 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -73,6 +73,10 @@ static uint16_t *rgui_framebuf_data = NULL; #define HOVER_COLOR(settings) ((3 << 0) | (10 << 4) | (3 << 8) | (7 << 12)) #define NORMAL_COLOR(settings) 0x7FFF #define TITLE_COLOR(settings) HOVER_COLOR(settings) +#elif defined(PS2) +#define HOVER_COLOR(settings) 0x03E0 +#define NORMAL_COLOR(settings) 0x7FFF +#define TITLE_COLOR(settings) HOVER_COLOR(settings) #else #define HOVER_COLOR(settings) (argb32_to_rgba4444(settings->uints.menu_entry_hover_color)) #define NORMAL_COLOR(settings) (argb32_to_rgba4444(settings->uints.menu_entry_normal_color)) @@ -93,8 +97,10 @@ 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) || defined(PS2) - return (6 << 12) | (col << 8) | (col << 4) | (col << 0); +#if defined(GEKKO) || defined(PSP) + return (6 << 12) | (col << 8) | (col << 4) | (col << 0); +#elif defined(PS2) + return (0 << 15) | (col << 12) | (col << 7) | (col << 2); #elif defined(HAVE_LIBNX) && !defined(HAVE_OPENGL) return (((31 * (54)) / 255) << 11) | (((63 * (54)) / 255) << 5) | @@ -108,8 +114,10 @@ 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) || defined(PS2) +#if defined(GEKKO) || defined(PSP) return (6 << 12) | (col << 8) | (col << 5) | (col << 0); +#elif defined(PS2) + return (0 << 15) | (col << 12) | (col << 8) | (col << 2); #elif defined(HAVE_LIBNX) && !defined(HAVE_OPENGL) return (((31 * (54)) / 255) << 11) | (((63 * (109)) / 255) << 5) | From 8a0266cf8dbf4c5b79c991bc4200b87f34de4f74 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 17 Oct 2018 19:02:50 +0200 Subject: [PATCH 06/24] PS2 Input looks to be ready --- frontend/frontend_driver.c | 2 +- gfx/drivers/ps2_gfx.c | 10 +++++++++- griffin/griffin.c | 2 +- input/drivers/ps2_input.c | 9 --------- input/input_driver.c | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c index ca800f4900..b8ff69a442 100644 --- a/frontend/frontend_driver.c +++ b/frontend/frontend_driver.c @@ -57,7 +57,7 @@ static frontend_ctx_driver_t *frontend_ctx_drivers[] = { &frontend_ctx_psp, #endif #if defined(PS2) - &frontend_ctx_ps2, //TODO: FJTRUJY + &frontend_ctx_ps2, #endif #if defined(_3DS) &frontend_ctx_ctr, diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 6a679695c5..0c99bd1099 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -91,7 +91,7 @@ static void deinitTexture(GSTEXTURE *texture) { static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - *input = NULL; + void *ps2input = NULL; *input_data = NULL; (void)video; @@ -100,6 +100,14 @@ static void *ps2_gfx_init(const video_info_t *video, initGSGlobal(ps2); initBackgroundTexture(ps2); + 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; + } + return ps2; } diff --git a/griffin/griffin.c b/griffin/griffin.c index 62cc840c86..89ab44800c 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -570,7 +570,7 @@ INPUT #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/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" diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index 1db7a758ce..6942c700f9 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -27,17 +27,8 @@ #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; diff --git a/input/input_driver.c b/input/input_driver.c index 447cccec0b..0d3f6c3ea0 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -87,7 +87,7 @@ static const input_driver_t *input_drivers[] = { &input_psp, #endif #if defined(PS2) -// &input_ps2, TODO: FJTRUJY + &input_ps2, #endif #if defined(_3DS) &input_ctr, From fc9cd8f639537f85031b8610bf2a110a1cc4cdfe Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 17 Oct 2018 21:11:21 +0200 Subject: [PATCH 07/24] JoyPad implemented --- Makefile.ps2 | 9 +- frontend/drivers/platform_ps2.c | 4 + griffin/griffin.c | 2 +- input/drivers_joypad/ps2_joypad.c | 175 ++++++++++--------------- input/drivers_joypad/ps2_joypad_copy.c | 0 input/input_driver.c | 2 +- 6 files changed, 78 insertions(+), 114 deletions(-) create mode 100644 input/drivers_joypad/ps2_joypad_copy.c diff --git a/Makefile.ps2 b/Makefile.ps2 index 642a9940dd..13afa113b4 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -1,5 +1,5 @@ BUILD_PRX = 0 -DEBUG = 0 +DEBUG = 1 HAVE_KERNEL_PRX = 0 HAVE_LOGGER = 0 HAVE_FILE_LOGGER = 0 @@ -15,7 +15,8 @@ IRX_DIR = $(PS2SDK)/iop/irx TARGET = retroarchps2.elf ifeq ($(DEBUG), 1) - OPTIMIZE_LV := -O0 -g + OPTIMIZE_LV := -O2 -g + RARCH_DEFINES += -DDEBUG else OPTIMIZE_LV := -O2 endif @@ -32,7 +33,7 @@ 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 += -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 = @@ -40,7 +41,7 @@ LDFLAGS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/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 -ldma -lgskit -ldmakit +LIBS += -lfileXio -lm -lg -lz -ldebug -lfileXio -laudsrv -lpatches -lpoweroff -ldma -lgskit -ldmakit -lpad #IRX modules # IRX modules - modules have to be in IRX_DIR diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 2c6b9a3b06..760a9e7f06 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -306,6 +306,10 @@ static void frontend_ps2_get_environment_settings(int *argc, char *argv[], static void frontend_ps2_init(void *data) { SifInitRpc(0); +#if !defined(DEBUG) + while(!SifIopReset(NULL, 0)){}; // Comment this line if you don't wanna debug the output +#endif + while(!SifIopSync()){}; SifInitRpc(0); sbv_patch_enable_lmb(); diff --git a/griffin/griffin.c b/griffin/griffin.c index 89ab44800c..d2b8b5dedc 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -571,7 +571,7 @@ INPUT #include "../input/drivers_joypad/psp_joypad.c" #elif defined(PS2) #include "../input/drivers/ps2_input.c" -// #include "../input/drivers_joypad/ps2_joypad.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) diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c index 61a541be29..969c075ebe 100644 --- a/input/drivers_joypad/ps2_joypad.c +++ b/input/drivers_joypad/ps2_joypad.c @@ -1,6 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2013-2014 - CatalystG * * 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- @@ -15,26 +16,24 @@ */ #include -#include +#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 +#include "libpad.h" #define PS2_MAX_PADS 1 -static uint64_t pad_state[PS2_MAX_PADS]; -static int16_t analog_state[PS2_MAX_PADS][2][2]; +/* + * Global var's + */ +// pad_dma_buf is provided by the user, one buf for each pad +// contains the pad's current state +static char padBuf[256] __attribute__((aligned(64))); + +static uint64_t pad_state[PS2_MAX_PADS]; -extern uint64_t lifecycle_state; static const char *ps2_joypad_name(unsigned pad) { @@ -48,134 +47,94 @@ static bool ps2_joypad_init(void *data) for (i = 0; i < players_count; i++) { - if (!input_autoconfigure_connect( - ps2_joypad_name(i), - NULL, - ps2_joypad.ident, - i, - 0, - 0 - )) + bool auto_configure = input_autoconfigure_connect( ps2_joypad_name(i), + NULL, + ps2_joypad.ident, + i, + 0, + 0); + if (!auto_configure) { input_config_set_device_name(i, ps2_joypad_name(i)); + } + + padInit(i); + + int ret; + int port, slot; + + port = 0; // 0 -> Connector 1, 1 -> Connector 2 + slot = 0; // Always zero if not using multitap + + printf("PortMax: %d\n", padGetPortMax()); + printf("SlotMax: %d\n", padGetSlotMax(port)); + + + if((ret = padPortOpen(port, slot, padBuf)) == 0) { + printf("padOpenPort failed: %d\n", ret); + } + + } return true; } -static bool ps2_joypad_button(unsigned port_num, uint16_t key) +static bool ps2_joypad_button(unsigned port_num, uint16_t joykey) { if (port_num >= PS2_MAX_PADS) return false; - return (pad_state[port_num] & (UINT64_C(1) << key)); + return (pad_state[port_num] & (UINT64_C(1) << joykey)); } 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); + 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; + return 0; } static void ps2_joypad_poll(void) { unsigned player; unsigned players_count = PS2_MAX_PADS; - - BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE); + struct padButtonStatus buttons; for (player = 0; player < players_count; player++) { unsigned j, k; unsigned i = player; unsigned p = player; - int32_t state_tmp = padGetState(player, player); - + + int ret = padRead(player, player, &buttons); // port, slot, buttons + if (ret != 0) + { + int32_t state_tmp = 0xffff ^ buttons.btns; - 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; + pad_state[i] = 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; + 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; + } } + } static bool ps2_joypad_query_pad(unsigned pad) diff --git a/input/drivers_joypad/ps2_joypad_copy.c b/input/drivers_joypad/ps2_joypad_copy.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/input/input_driver.c b/input/input_driver.c index 0d3f6c3ea0..2e264c7159 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -165,7 +165,7 @@ static input_device_driver_t *joypad_drivers[] = { &psp_joypad, #endif #if defined(PS2) -// &ps2_joypad, // TODO: FJTRUJY + &ps2_joypad, #endif #ifdef _3DS &ctr_joypad, From 802c38bd921777214a20542d975dbf6b4c8b9bf5 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 19 Oct 2018 21:32:18 +0200 Subject: [PATCH 08/24] Fix why default entries doesn't appear --- frontend/drivers/platform_ps2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 760a9e7f06..c4242f7465 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -463,6 +463,11 @@ static int frontend_ps2_parse_drive_list(void *data, bool load_content) 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, + "host:/", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); #endif return 0; @@ -487,7 +492,7 @@ frontend_ctx_driver_t frontend_ctx_ps2 = { NULL, /* load_content */ frontend_ps2_get_architecture, /* get_architecture */ NULL, /* get_powerstate */ - NULL, /* parse_drive_list */ + frontend_ps2_parse_drive_list, /* parse_drive_list */ NULL, /* get_mem_total */ NULL, /* get_mem_free */ NULL, /* install_signal_handler */ From b4aedc801b244c90548118c7fd4229f983101228 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 20 Oct 2018 17:25:03 +0200 Subject: [PATCH 09/24] Fixed issue on retro_dirent with if clausules --- libretro-common/file/retro_dirent.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index ea8d520fcb..c066361636 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -256,15 +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(PS2) + const iox_dirent_t *entry = (const iox_dirent_t*)&rdir->entry; + return (entry->stat.attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; #elif defined(__CELLOS_LV2__) CellFsDirent *entry = (CellFsDirent*)&rdir->entry; return (entry->d_type == CELL_FS_TYPE_DIRECTORY); From 5ba2509e7c0f0fc59d554a972aee1e435b7575e3 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sat, 20 Oct 2018 18:07:37 +0200 Subject: [PATCH 10/24] Now the directories are working --- libretro-common/file/retro_dirent.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index c066361636..561c1b055a 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -199,7 +199,10 @@ int retro_readdir(struct RDIR *rdir) #elif defined(VITA) || defined(PSP) return (sceIoDread(rdir->directory, &rdir->entry) > 0); #elif defined(PS2) - return (fileXioDread(rdir->directory, &rdir->entry) > 0); + iox_dirent_t record; + int ret = fileXioDread(rdir->directory, &record); + rdir->entry = record; + return ( ret > 0); #elif defined(__CELLOS_LV2__) uint64_t nread; rdir->error = cellFsReaddir(rdir->directory, &rdir->entry, &nread); @@ -263,7 +266,7 @@ bool retro_dirent_is_dir(struct RDIR *rdir, const char *path) #endif #elif defined(PS2) const iox_dirent_t *entry = (const iox_dirent_t*)&rdir->entry; - return (entry->stat.attr & FIO_SO_IFDIR) == FIO_SO_IFDIR; + return FIO_S_ISDIR(entry->stat.mode); #elif defined(__CELLOS_LV2__) CellFsDirent *entry = (CellFsDirent*)&rdir->entry; return (entry->d_type == CELL_FS_TYPE_DIRECTORY); From 17d30f9dd52ef5cf442af14bcfcdbeef9c8fb649 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 19 Oct 2018 00:56:14 +0200 Subject: [PATCH 11/24] Use SDL timer for counters and sleep the thread --- Makefile.ps2 | 4 ++-- frontend/drivers/platform_ps2.c | 3 +++ libretro-common/features/features_cpu.c | 7 +++++-- libretro-common/include/retro_timers.h | 17 ++--------------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index 13afa113b4..6b33332618 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -15,7 +15,7 @@ IRX_DIR = $(PS2SDK)/iop/irx TARGET = retroarchps2.elf ifeq ($(DEBUG), 1) - OPTIMIZE_LV := -O2 -g + OPTIMIZE_LV := -O0 -g RARCH_DEFINES += -DDEBUG else OPTIMIZE_LV := -O2 @@ -41,7 +41,7 @@ LDFLAGS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/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 -ldma -lgskit -ldmakit -lpad +LIBS += -lm -lg -lz -ldebug -lfileXio -laudsrv -lpatches -lpoweroff -ldma -lgskit -ldmakit -lpad -lsdl #IRX modules # IRX modules - modules have to be in IRX_DIR diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index c4242f7465..93d389d889 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -26,6 +26,7 @@ #include #include #include +#include enum BootDeviceIDs{ @@ -329,6 +330,8 @@ static void frontend_ps2_init(void *data) fileXioInit(); audsrv_init(); + + SDL_Init(SDL_INIT_TIMER); } static void frontend_ps2_deinit(void *data) diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 84c9836d22..cc9dcabb3a 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -68,6 +68,7 @@ #if defined(PS2) #include #include +#include #endif #if defined(__PSL1GHT__) @@ -190,7 +191,7 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) #elif defined(VITA) sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); #elif defined(PS2) - time_ticks = ((uint64_t)cpu_ticks()); + time_ticks = SDL_GetTicks()*294912; // 294,912MHZ / 1000 msecs #elif defined(_3DS) time_ticks = svcGetSystemTick(); #elif defined(WIIU) @@ -240,7 +241,7 @@ retro_time_t cpu_features_get_time_usec(void) #elif defined(EMSCRIPTEN) return emscripten_get_now() * 1000; #elif defined(PS2) - return cpu_ticks()/295.0; + return SDL_GetTicks()*1000; #elif defined(__mips__) || defined(DJGPP) struct timeval tv; gettimeofday(&tv,NULL); @@ -802,6 +803,8 @@ uint64_t cpu_features_get(void) cpu |= RETRO_SIMD_PS; #endif +printf("CPU is %i\n", cpu); + if (cpu & RETRO_SIMD_MMX) strlcat(buf, " MMX", sizeof(buf)); if (cpu & RETRO_SIMD_MMXEXT) strlcat(buf, " MMXEXT", sizeof(buf)); if (cpu & RETRO_SIMD_SSE) strlcat(buf, " SSE", sizeof(buf)); diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h index 1670b98e70..d11e67e7c2 100644 --- a/libretro-common/include/retro_timers.h +++ b/libretro-common/include/retro_timers.h @@ -38,7 +38,7 @@ #elif defined(VITA) #include #elif defined(PS2) -#include +#include #elif defined(_3DS) #include <3ds.h> #else @@ -79,13 +79,6 @@ 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 @@ -99,13 +92,7 @@ static INLINE void retro_sleep(unsigned 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(); - } + SDL_Delay(msec); #elif defined(_3DS) svcSleepThread(1000000 * (s64)msec); #elif defined(__WINRT__) From 99b77a2c9caa000e0ccd1dbffd5aa31577033c78 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 25 Oct 2018 02:22:11 +0200 Subject: [PATCH 12/24] Copied from core compat string methods --- libretro-common/features/features_cpu.c | 2 -- ps2/compat_ctype.c | 38 ++++++++++++++----------- ps2/include/compat_ctype.h | 3 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index cc9dcabb3a..1a04ce07c5 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -803,8 +803,6 @@ uint64_t cpu_features_get(void) cpu |= RETRO_SIMD_PS; #endif -printf("CPU is %i\n", cpu); - if (cpu & RETRO_SIMD_MMX) strlcat(buf, " MMX", sizeof(buf)); if (cpu & RETRO_SIMD_MMXEXT) strlcat(buf, " MMXEXT", sizeof(buf)); if (cpu & RETRO_SIMD_SSE) strlcat(buf, " SSE", sizeof(buf)); diff --git a/ps2/compat_ctype.c b/ps2/compat_ctype.c index 94e773356c..cdcfaca0ff 100644 --- a/ps2/compat_ctype.c +++ b/ps2/compat_ctype.c @@ -6,31 +6,35 @@ #define ULLONG_MAX UINT64_C(0xffffffffffffffff) -char * strtok_r(char *str, const char *delim, char **nextp) +char *strtok_r(char *str, const char *delim, char **saveptr) { - char *ret; + char *first = NULL; + if (!saveptr || !delim) + return NULL; - if (str == NULL) { - str = *nextp; - } + if (str) + *saveptr = str; - str += strspn(str, delim); + do + { + char *ptr = NULL; + first = *saveptr; + while (*first && strchr(delim, *first)) + *first++ = '\0'; - if (*str == '\0') { - return NULL; - } + if (*first == '\0') + return NULL; - ret = str; + ptr = first + 1; - str += strcspn(str, delim); + while (*ptr && !strchr(delim, *ptr)) + ptr++; - if (*str) { - *str++ = '\0'; - } + *saveptr = ptr + (*ptr ? 1 : 0); + *ptr = '\0'; + } while (strlen(first) == 0); - *nextp = str; - - return ret; + return first; } unsigned long long strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) diff --git a/ps2/include/compat_ctype.h b/ps2/include/compat_ctype.h index ca3f5fefc5..1d80025c28 100644 --- a/ps2/include/compat_ctype.h +++ b/ps2/include/compat_ctype.h @@ -1,8 +1,9 @@ #ifndef COMPAT_CTYPE_H #define COMPAT_CTYPE_H +char *strtok_r(char *str, const char *delim, char **saveptr); + 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); From 4c77e426fafbbfc004ae3fe5ca8e8164f1acc6e7 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 28 Oct 2018 21:00:34 +0100 Subject: [PATCH 13/24] Replaced a lot of functions from libc to C implementation in compat_ctype.c --- ps2/compat_ctype.c | 369 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 342 insertions(+), 27 deletions(-) diff --git a/ps2/compat_ctype.c b/ps2/compat_ctype.c index cdcfaca0ff..0c5dba835d 100644 --- a/ps2/compat_ctype.c +++ b/ps2/compat_ctype.c @@ -6,35 +6,347 @@ #define ULLONG_MAX UINT64_C(0xffffffffffffffff) -char *strtok_r(char *str, const char *delim, char **saveptr) +/* Do not link from libc */ + +int islower(int c) { - char *first = NULL; - if (!saveptr || !delim) + if ((c < 'a') || (c > 'z')) + return 0; + + // passed both criteria, so it + // is a lower case alpha char + return 1; +} + +int tolower(int ch) +{ + if(ch >= 'A' && ch <= 'Z') + return ('a' + ch - 'A'); + else + return ch; +} + +int toupper(int c) +{ + if (islower(c)) + c -= 32; + + return c; +} + +int memcmp(const void *s1, const void *s2, unsigned int length) +{ + const char *a = s1; + const char *b = s2; + + while (length--) { + if (*a++ != *b++) + return 1; + } + + return 0; +} + +void * memcpy (void *dest, const void *src, size_t len) +{ + char *d = dest; + const char *s = src; + while (len--) + *d++ = *s++; + return dest; +} + +void * memset (void *dest, int val, size_t len) +{ + unsigned char *ptr = dest; + while (len-- > 0) + *ptr++ = val; + return dest; +} + +int sprintf (char *s, const char *format, ...) +{ + va_list arg; + int done; + va_start (arg, format); + done = vsprintf (s, format, arg); + va_end (arg); + return done; +} + +char * strcat(char *dest, const char *src) +{ + size_t i,j; + for (i = 0; dest[i] != '\0'; i++) + ; + for (j = 0; src[j] != '\0'; j++) + dest[i+j] = src[j]; + dest[i+j] = '\0'; + return dest; +} + +char *strchr(const char *string, int c) +{ + while (*string) { + if (*string == c) + return (char *)string; + string++; + } + + if (*string == c) + return (char *)string; + + return NULL; +} + +int strcmp(const char *s1, const char *s2) +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + return (*(unsigned char *)s1 - *(unsigned char *)--s2); +} + +char * strcpy(char *to, const char *from) +{ + char *save = to; + + for (; (*to = *from) != '\0'; ++from, ++to); + return(save); +} + +size_t strcspn(const char *s1, const char *s2) +{ + const char *p, *spanp; + char c, sc; + + /* + * Stop as soon as we find any character from s2. Note that there + * must be a NUL in s2; it suffices to stop when we find that, too. + */ + for (p = s1;;) { + c = *p++; + spanp = s2; + do { + if ((sc = *spanp++) == c) + return (p - 1 - s1); + } while (sc != 0); + } + /* NOTREACHED */ +} + +size_t strlen(const char *str) +{ + const char *s; + + for (s = str; *s; ++s) + ; + return (s - str); +} + +char * strncat(char *dst, const char *src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return (dst); +} + +int strncmp(const char *s1, const char *s2, size_t n) +{ + if (n == 0) + return (0); + do { + if (*s1 != *s2++) + return (*(unsigned char *)s1 - *(unsigned char *)--s2); + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} + +char * strncpy(char *dst, const char *src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + do { + if ((*d++ = *s++) == 0) { + /* NUL pad the remaining n-1 bytes */ + while (--n != 0) + *d++ = 0; + break; + } + } while (--n != 0); + } + return (dst); +} + +char * strpbrk(const char *s1, const char *s2) +{ + const char *scanp; + int c, sc; + + while ((c = *s1++) != 0) { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + return ((char *)(s1 - 1)); + } + return (NULL); +} + +/* Do not link to strrchr() from libc */ +char * strrchr(const char *p, int ch) +{ + char *save; + + for (save = NULL;; ++p) { + if (*p == (char) ch) + save = (char *)p; + if (!*p) + return(save); + } + /* NOTREACHED */ +} + +size_t strspn(const char *s1, const char *s2) +{ + const char *p = s1, *spanp; + char c, sc; + + /* + * Skip any characters in s2, excluding the terminating \0. + */ +cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (p - 1 - s1); +} + +char *strstr(const char *string, const char *substring) +{ + char *strpos; + + if (string == 0) + return 0; + + if (strlen(substring) == 0) + return (char *)string; + + strpos = (char *)string; + + while (*strpos != 0) { + if (strncmp(strpos, substring, strlen(substring)) == 0) + return strpos; + + strpos++; + } + + return 0; +} + +size_t strnlen(const char *str, size_t maxlen) +{ + const char *cp; + + for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) + ; + + return (size_t)(cp - str); +} + +char *strtok(char *strToken, const char *strDelimit) +{ + static char *start; + static char *end; + + if (strToken != NULL) + start = strToken; + else { + if (*end == 0) + return 0; + + start = end; + } + + if (*start == 0) + return 0; + + // Strip out any leading delimiters + while (strchr(strDelimit, *start)) { + // If a character from the delimiting string + // then skip past it + + start++; + + if (*start == 0) + return 0; + } + + if (*start == 0) + return 0; + + end = start; + + while (*end != 0) { + if (strchr(strDelimit, *end)) { + // if we find a delimiting character + // before the end of the string, then + // terminate the token and move the end + // pointer to the next character + *end = 0; + end++; + return start; + } + end++; + } + + // reached the end of the string before finding a delimiter + // so dont move on to the next character + return start; +} + +char * strtok_r (char *s, const char *delim, char **save_ptr) +{ + char *end; + if (s == NULL) + s = *save_ptr; + if (*s == '\0') + { + *save_ptr = s; return NULL; - - if (str) - *saveptr = str; - - do - { - char *ptr = NULL; - first = *saveptr; - while (*first && strchr(delim, *first)) - *first++ = '\0'; - - if (*first == '\0') - return NULL; - - ptr = first + 1; - - while (*ptr && !strchr(delim, *ptr)) - ptr++; - - *saveptr = ptr + (*ptr ? 1 : 0); - *ptr = '\0'; - } while (strlen(first) == 0); - - return first; + } + /* Scan leading delimiters. */ + s += strspn (s, delim); + if (*s == '\0') + { + *save_ptr = s; + return NULL; + } + /* Find the end of the token. */ + end = s + strcspn (s, delim); + if (*end == '\0') + { + *save_ptr = end; + return s; + } + /* Terminate the token and make *SAVE_PTR point past it. */ + *end = '\0'; + *save_ptr = end + 1; + return s; } unsigned long long strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) @@ -106,6 +418,9 @@ noconv: return (acc); } +//long strtol(const char *s, char **endptr, int base); FJTRUJY MISSING +//unsigned long strtoul(const char *s, char **endptr, int base); FJTRUJY MISSING + int link(const char *oldpath, const char *newpath) { return fileXioSymlink(oldpath, newpath); From b378ecf26bb17f04050ba85f50ae6fec108dabfa Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 31 Oct 2018 19:45:43 +0100 Subject: [PATCH 14/24] Test Core working with 2 textures --- gfx/drivers/ps2_gfx.c | 152 ++++++++++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 43 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 0c99bd1099..273f6378e5 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -34,14 +34,14 @@ typedef struct ps2_video { GSGLOBAL *gsGlobal; - GSTEXTURE *backgroundTexture; + GSTEXTURE *menuTexture; + GSTEXTURE *coreTexture; + bool menuVisible; } ps2_video_t; // PRIVATE METHODS static void initGSGlobal(ps2_video_t *ps2) { - u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0xFF,0x00); - - ps2->gsGlobal = gsKit_init_global() + ps2->gsGlobal = gsKit_init_global() ps2->gsGlobal->PSM = GS_PSM_CT16; // ps2->gsGlobal->PSMZ = GS_PSMZ_16S; @@ -71,8 +71,8 @@ static size_t gskitTextureSize(GSTEXTURE *texture) { return gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM); } -static void initBackgroundTexture(ps2_video_t *ps2) { - ps2->backgroundTexture = malloc(sizeof *ps2->backgroundTexture); +static void initTexture(GSTEXTURE *texture) { + texture = malloc(sizeof *texture); } static void deinitTexturePTR(void *texture_ptr) { @@ -97,8 +97,12 @@ static void *ps2_gfx_init(const video_info_t *video, ps2_video_t *ps2 = (ps2_video_t*)calloc(1, sizeof(ps2_video_t)); + if (!ps2) + return NULL; + initGSGlobal(ps2); - initBackgroundTexture(ps2); + ps2->menuTexture = malloc(sizeof *ps2->menuTexture); + ps2->coreTexture = malloc(sizeof *ps2->coreTexture); if (input && input_data) { @@ -126,6 +130,85 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (!width || !height) return false; + + gsKit_vram_clear(ps2->gsGlobal); + + if (frame) + { + int PSM = GS_PSM_CT16; + if ( !ps2->coreTexture->Mem || + ps2->coreTexture->Width != width || + ps2->coreTexture->Height != height || + ps2->coreTexture->PSM != PSM ) { + ps2->coreTexture->Width = width; + ps2->coreTexture->Height = height; + ps2->coreTexture->PSM = PSM; + ps2->coreTexture->Filter = GS_FILTER_NEAREST; + free(ps2->coreTexture->Mem); + ps2->coreTexture->Mem = memalign(128, gskitTextureSize(ps2->coreTexture)); + } + + memcpy(ps2->coreTexture->Mem, frame, width * height * 2); + } + + if (frame) + { + ps2->coreTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->coreTexture) , GSKIT_ALLOC_USERBUFFER); + if(ps2->coreTexture->Vram == GSKIT_ALLOC_ERROR) + { + printf("VRAM Allocation Failed. Will not upload texture.\n"); + } + } + + if (ps2->menuVisible) + { + ps2->menuTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->menuTexture) , GSKIT_ALLOC_USERBUFFER); + if(ps2->menuTexture->Vram == GSKIT_ALLOC_ERROR) + { + printf("VRAM Allocation Failed. Will not upload texture.\n"); + } + } + + if (frame) + { + gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); + } + + if (ps2->menuVisible) + { + gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture); + } + + if (frame) + { + gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->coreTexture, + 0.0f, + 0.0f, // Y1 + 0.0f, // U1 + 0.0f, // V1 + ps2->gsGlobal->Width, // X2 + ps2->gsGlobal->Height, // Y2 + ps2->coreTexture->Width, // U2 + ps2->coreTexture->Height, // V2 + 2, + GS_WHITE); + } + + if (ps2->menuVisible) + { + gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->menuTexture, + 0.0f, + 0.0f, // Y1 + 0.0f, // U1 + 0.0f, // V1 + ps2->gsGlobal->Width, // X2 + ps2->gsGlobal->Height, // Y2 + ps2->menuTexture->Width, // U2 + ps2->menuTexture->Height, // V2 + 2, + GS_WHITE); + } + gsKit_sync_flip(ps2->gsGlobal); gsKit_queue_exec(ps2->gsGlobal); @@ -167,7 +250,10 @@ static void ps2_gfx_free(void *data) { ps2_video_t *ps2 = (ps2_video_t*)data; - deinitTexture(ps2->backgroundTexture); + gsKit_clear(ps2->gsGlobal, GS_WHITE); + + deinitTexture(ps2->menuTexture); + deinitTexture(ps2->coreTexture); gsKit_vram_clear(ps2->gsGlobal); gsKit_deinit_global(ps2->gsGlobal); @@ -227,52 +313,32 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, ps2_video_t *ps2 = (ps2_video_t*)data; #ifdef DEBUG - /* ps2->backgroundTexture.Mem buffer size is (640 * 448)*2 Bytes */ - retro_assert((width*height) < (480 * 448)); + /* ps2->menuTexture.Mem buffer size is (640 * 448)*2 Bytes */ +// retro_assert((width*height) < (480 * 448)); #endif int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; printf("ps2_set_texture_frame, width:%i, height:%i, rgb32:%i, alpha:%f\n", width, height, rgb32, alpha); - if ( !ps2->backgroundTexture->Mem || - ps2->backgroundTexture->Width != width || - ps2->backgroundTexture->Height != height || - ps2->backgroundTexture->PSM != PSM ) { - ps2->backgroundTexture->Width = width; - ps2->backgroundTexture->Height = height; - ps2->backgroundTexture->PSM = PSM; - ps2->backgroundTexture->Filter = GS_FILTER_NEAREST; - ps2->backgroundTexture->Mem = memalign(128, gskitTextureSize(ps2->backgroundTexture)); + if ( !ps2->menuTexture->Mem || + ps2->menuTexture->Width != width || + ps2->menuTexture->Height != height || + ps2->menuTexture->PSM != PSM ) { + ps2->menuTexture->Width = width; + ps2->menuTexture->Height = height; + ps2->menuTexture->PSM = PSM; + ps2->menuTexture->Filter = GS_FILTER_NEAREST; + free(ps2->menuTexture->Mem); + ps2->menuTexture->Mem = memalign(128, gskitTextureSize(ps2->menuTexture)); } - memcpy(ps2->backgroundTexture->Mem, frame, width * height * (rgb32 ? 4 : 2)); - - gsKit_vram_clear(ps2->gsGlobal); - ps2->backgroundTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->backgroundTexture) , GSKIT_ALLOC_USERBUFFER); - if(ps2->backgroundTexture->Vram == GSKIT_ALLOC_ERROR) - { - printf("VRAM Allocation Failed. Will not upload texture.\n"); - } - - // Upload texture - gsKit_texture_upload(ps2->gsGlobal, ps2->backgroundTexture); - gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->backgroundTexture, - 0.0f, - 0.0f, // Y1 - 0.0f, // U1 - 0.0f, // V1 - ps2->gsGlobal->Width, // X2 - ps2->gsGlobal->Height, // Y2 - ps2->backgroundTexture->Width, // U2 - ps2->backgroundTexture->Height, // V2 - 2, - GS_WHITE); - + memcpy(ps2->menuTexture->Mem, frame, width * height * (rgb32 ? 4 : 2)); } -static void ps2_set_texture_enable(void *data, bool state, bool full_screen) +static void ps2_set_texture_enable(void *data, bool enable, bool full_screen) { (void) full_screen; ps2_video_t *ps2 = (ps2_video_t*)data; + ps2->menuVisible = enable; } static const video_poke_interface_t ps2_poke_interface = { From 18dc40117d8f9837b54e468f426ddcd5f46d3e46 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 01:53:13 +0100 Subject: [PATCH 15/24] Applied color correction to the libretro core --- gfx/drivers/ps2_gfx.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 273f6378e5..49ccd6a880 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -87,6 +87,17 @@ static void deinitTexture(GSTEXTURE *texture) { deinitTexturePTR(texture->Clut); } +static void ConvertColors32(u32 *buffer, u32 dimensions) +{ + u32 i; + u32 x32; + for (i = 0; i < dimensions; i++) { + + x32 = buffer[i]; + buffer[i] = ((x32 >> 16) & 0xFF) | ((x32 << 16) & 0xFF0000) | (x32 & 0xFF00FF00); + } +} + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) @@ -135,7 +146,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (frame) { - int PSM = GS_PSM_CT16; + int PSM = GS_PSM_CT32; if ( !ps2->coreTexture->Mem || ps2->coreTexture->Width != width || ps2->coreTexture->Height != height || @@ -148,7 +159,8 @@ static bool ps2_gfx_frame(void *data, const void *frame, ps2->coreTexture->Mem = memalign(128, gskitTextureSize(ps2->coreTexture)); } - memcpy(ps2->coreTexture->Mem, frame, width * height * 2); + ConvertColors32(frame, width * height); + memcpy(ps2->coreTexture->Mem, frame, width * height * 4); } if (frame) From 6b5ae4cdd643f89fcb762a61192e78f2dff65729 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 02:36:49 +0100 Subject: [PATCH 16/24] Make more generic to choose the 32bits or 16bits --- gfx/drivers/ps2_gfx.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 49ccd6a880..05ef3a2b56 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -37,6 +37,7 @@ typedef struct ps2_video GSTEXTURE *menuTexture; GSTEXTURE *coreTexture; bool menuVisible; + bool rgb32; } ps2_video_t; // PRIVATE METHODS @@ -99,6 +100,18 @@ static void ConvertColors32(u32 *buffer, u32 dimensions) } +static void ConvertColors16(u16 *buffer, u32 dimensions) +{ + u32 i; + u16 x16; + for (i = 0; i < dimensions; i++) { + + x16 = buffer[i]; + buffer[i] = (x16 & 0x8000) | ((x16 << 10) & 0x7C00) | (x16 & 0x3E0) | ((x16 >> 10) & 0x1F); + } +} + + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { @@ -115,6 +128,8 @@ static void *ps2_gfx_init(const video_info_t *video, ps2->menuTexture = malloc(sizeof *ps2->menuTexture); ps2->coreTexture = malloc(sizeof *ps2->coreTexture); + ps2->rgb32 = video->rgb32; + if (input && input_data) { settings_t *settings = config_get_ptr(); @@ -146,7 +161,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (frame) { - int PSM = GS_PSM_CT32; + int PSM = ps2->rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; if ( !ps2->coreTexture->Mem || ps2->coreTexture->Width != width || ps2->coreTexture->Height != height || @@ -159,8 +174,13 @@ static bool ps2_gfx_frame(void *data, const void *frame, ps2->coreTexture->Mem = memalign(128, gskitTextureSize(ps2->coreTexture)); } - ConvertColors32(frame, width * height); - memcpy(ps2->coreTexture->Mem, frame, width * height * 4); + if (ps2->rgb32) { + ConvertColors32(frame, width * height); + memcpy(ps2->coreTexture->Mem, frame, width * height * 4); + } else { + ConvertColors16(frame, width * height); + memcpy(ps2->coreTexture->Mem, frame, width * height * 2); + } } if (frame) From b4d2c5d85a2d55896271b807241aa58decfb06e1 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 11:35:30 +0100 Subject: [PATCH 17/24] Refactor method where transfer the frame to the textures --- gfx/drivers/ps2_gfx.c | 86 +++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 48 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 05ef3a2b56..749fb76cbb 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -1,6 +1,5 @@ /* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2018 - Francisco Javier Trujillo Mata * * 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- @@ -24,19 +23,17 @@ #include #include -#define GS_SCREEN_WIDTH 640; -#define GS_SCREEN_HEIGHT 448; - -#define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) // turn black GS Screen #define GS_WHITE GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00) // turn white GS Screen -#define GS_TEXCOL GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) typedef struct ps2_video { GSGLOBAL *gsGlobal; GSTEXTURE *menuTexture; GSTEXTURE *coreTexture; + bool menuVisible; + bool full_screen; + bool rgb32; } ps2_video_t; @@ -111,6 +108,36 @@ static void ConvertColors16(u16 *buffer, u32 dimensions) } } +static void transfer_texture(GSTEXTURE *texture, const void *frame, + int width, int height, bool rgb32, bool color_correction) { + + int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; + size_t size = gsKit_texture_size_ee(width, height, PSM); + if ( !texture->Mem || + texture->Width != width || + texture->Height != height || + texture->PSM != PSM ) { + texture->Width = width; + texture->Height = height; + texture->PSM = PSM; + texture->Filter = GS_FILTER_NEAREST; + free(texture->Mem); + texture->Mem = memalign(128, size); +} + +if (color_correction) { + int pixels = width * height; + int *buffer = (int *)frame; + if (rgb32) { + ConvertColors32(buffer, pixels); + } else { + ConvertColors16(buffer, pixels); + } +} + + memcpy(texture->Mem, frame, size); +} + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) @@ -159,28 +186,8 @@ static bool ps2_gfx_frame(void *data, const void *frame, gsKit_vram_clear(ps2->gsGlobal); - if (frame) - { - int PSM = ps2->rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; - if ( !ps2->coreTexture->Mem || - ps2->coreTexture->Width != width || - ps2->coreTexture->Height != height || - ps2->coreTexture->PSM != PSM ) { - ps2->coreTexture->Width = width; - ps2->coreTexture->Height = height; - ps2->coreTexture->PSM = PSM; - ps2->coreTexture->Filter = GS_FILTER_NEAREST; - free(ps2->coreTexture->Mem); - ps2->coreTexture->Mem = memalign(128, gskitTextureSize(ps2->coreTexture)); - } - - if (ps2->rgb32) { - ConvertColors32(frame, width * height); - memcpy(ps2->coreTexture->Mem, frame, width * height * 4); - } else { - ConvertColors16(frame, width * height); - memcpy(ps2->coreTexture->Mem, frame, width * height * 2); - } + if (frame) { + transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, 1); } if (frame) @@ -344,25 +351,7 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, { ps2_video_t *ps2 = (ps2_video_t*)data; -#ifdef DEBUG - /* ps2->menuTexture.Mem buffer size is (640 * 448)*2 Bytes */ -// retro_assert((width*height) < (480 * 448)); -#endif - int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; - printf("ps2_set_texture_frame, width:%i, height:%i, rgb32:%i, alpha:%f\n", width, height, rgb32, alpha); - if ( !ps2->menuTexture->Mem || - ps2->menuTexture->Width != width || - ps2->menuTexture->Height != height || - ps2->menuTexture->PSM != PSM ) { - ps2->menuTexture->Width = width; - ps2->menuTexture->Height = height; - ps2->menuTexture->PSM = PSM; - ps2->menuTexture->Filter = GS_FILTER_NEAREST; - free(ps2->menuTexture->Mem); - ps2->menuTexture->Mem = memalign(128, gskitTextureSize(ps2->menuTexture)); - } - - memcpy(ps2->menuTexture->Mem, frame, width * height * (rgb32 ? 4 : 2)); + transfer_texture(ps2->menuTexture, frame, width, height, rgb32, 0); } static void ps2_set_texture_enable(void *data, bool enable, bool full_screen) @@ -371,6 +360,7 @@ static void ps2_set_texture_enable(void *data, bool enable, bool full_screen) ps2_video_t *ps2 = (ps2_video_t*)data; ps2->menuVisible = enable; + ps2->full_screen = full_screen; } static const video_poke_interface_t ps2_poke_interface = { From 66159a44e574d900693b928a3bd0eb585350d2f4 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 13:56:35 +0100 Subject: [PATCH 18/24] Some clean in gfx --- gfx/drivers/ps2_gfx.c | 171 ++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 105 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 749fb76cbb..10f0320b1c 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -38,14 +38,14 @@ typedef struct ps2_video } ps2_video_t; // PRIVATE METHODS -static void initGSGlobal(ps2_video_t *ps2) { - ps2->gsGlobal = gsKit_init_global() +static GSGLOBAL *init_GSGlobal(void) { + GSGLOBAL *gsGlobal = gsKit_init_global() - ps2->gsGlobal->PSM = GS_PSM_CT16; - // ps2->gsGlobal->PSMZ = GS_PSMZ_16S; - ps2->gsGlobal->DoubleBuffering = GS_SETTING_OFF; - ps2->gsGlobal->ZBuffering = GS_SETTING_OFF; - ps2->gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ + gsGlobal->PSM = GS_PSM_CT16; + // gsGlobal->PSMZ = GS_PSMZ_16S; + gsGlobal->DoubleBuffering = GS_SETTING_OFF; + gsGlobal->ZBuffering = GS_SETTING_OFF; + gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); @@ -53,58 +53,44 @@ static void initGSGlobal(ps2_video_t *ps2) { // Initialize the DMAC dmaKit_chan_init(DMA_CHANNEL_GIF); - gsKit_init_screen(ps2->gsGlobal); + gsKit_init_screen(gsGlobal); + gsKit_mode_switch(gsGlobal, GS_ONESHOT); - // gsKit_mode_switch(ps2->gsGlobal, GS_PERSISTENT); - gsKit_mode_switch(ps2->gsGlobal, GS_ONESHOT); + gsKit_clear(gsGlobal, GS_WHITE); - gsKit_clear(ps2->gsGlobal, GS_WHITE); + return gsGlobal; } -static u32 textureSize(GSTEXTURE *texture) { - return gsKit_texture_size(texture->Width, texture->Height, texture->PSM); -} - -static size_t gskitTextureSize(GSTEXTURE *texture) { - return gsKit_texture_size_ee(texture->Width, texture->Height, texture->PSM); -} - -static void initTexture(GSTEXTURE *texture) { - texture = malloc(sizeof *texture); -} - -static void deinitTexturePTR(void *texture_ptr) { - if(texture_ptr!=NULL){ - free(texture_ptr); - texture_ptr=NULL; - } +static void init_ps2_video(ps2_video_t *ps2) { + ps2->gsGlobal = init_GSGlobal(); + ps2->menuTexture = malloc(sizeof *ps2->menuTexture); + ps2->coreTexture = malloc(sizeof *ps2->coreTexture); } static void deinitTexture(GSTEXTURE *texture) { - deinitTexturePTR(texture->Mem); - deinitTexturePTR(texture->Clut); + free(texture->Mem); + free(texture->Clut); + texture->Mem = NULL; + texture->Clut = NULL; } -static void ConvertColors32(u32 *buffer, u32 dimensions) +static void color_correction32(uint32_t *buffer, uint32_t dimensions) { - u32 i; - u32 x32; + uint32_t i; + uint32_t x32; for (i = 0; i < dimensions; i++) { - - x32 = buffer[i]; - buffer[i] = ((x32 >> 16) & 0xFF) | ((x32 << 16) & 0xFF0000) | (x32 & 0xFF00FF00); + x32 = buffer[i]; + buffer[i] = ((x32 >> 16) & 0xFF) | ((x32 << 16) & 0xFF0000) | (x32 & 0xFF00FF00); } } - -static void ConvertColors16(u16 *buffer, u32 dimensions) +static void color_correction16(uint16_t *buffer, uint32_t dimensions) { - u32 i; - u16 x16; + uint32_t i; + uint16_t x16; for (i = 0; i < dimensions; i++) { - - x16 = buffer[i]; - buffer[i] = (x16 & 0x8000) | ((x16 << 10) & 0x7C00) | (x16 & 0x3E0) | ((x16 >> 10) & 0x1F); + x16 = buffer[i]; + buffer[i] = (x16 & 0x8000) | ((x16 << 10) & 0x7C00) | (x16 & 0x3E0) | ((x16 >> 10) & 0x1F); } } @@ -127,17 +113,40 @@ static void transfer_texture(GSTEXTURE *texture, const void *frame, if (color_correction) { int pixels = width * height; - int *buffer = (int *)frame; if (rgb32) { - ConvertColors32(buffer, pixels); + uint32_t *buffer = (uint32_t *)frame; + color_correction32(buffer, pixels); } else { - ConvertColors16(buffer, pixels); + uint16_t *buffer = (uint16_t *)frame; + color_correction16(buffer, pixels); } } memcpy(texture->Mem, frame, size); } +static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) { + uint32_t size = gsKit_texture_size(texture->Width, texture->Height, texture->PSM); + texture->Vram=gsKit_vram_alloc(gsGlobal, size, GSKIT_ALLOC_USERBUFFER); + if(texture->Vram == GSKIT_ALLOC_ERROR) { + printf("VRAM Allocation Failed. Will not upload texture.\n"); + } +} + +static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool full_screen) { + gsKit_prim_sprite_texture( gsGlobal, texture, + 0.0f, + 0.0f, // Y1 + 0.0f, // U1 + 0.0f, // V1 + gsGlobal->Width, // X2 + gsGlobal->Height, // Y2 + texture->Width, // U2 + texture->Height, // V2 + zPosition, + GS_WHITE); +} + static void *ps2_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) @@ -151,10 +160,7 @@ static void *ps2_gfx_init(const video_info_t *video, if (!ps2) return NULL; - initGSGlobal(ps2); - ps2->menuTexture = malloc(sizeof *ps2->menuTexture); - ps2->coreTexture = malloc(sizeof *ps2->coreTexture); - + init_ps2_video(ps2); ps2->rgb32 = video->rgb32; if (input && input_data) @@ -183,69 +189,23 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (!width || !height) return false; + if (frame_count%120==0) { + printf("ps2_gfx_frame %i\n", frame_count); + } gsKit_vram_clear(ps2->gsGlobal); if (frame) { transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, 1); - } - - if (frame) - { - ps2->coreTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->coreTexture) , GSKIT_ALLOC_USERBUFFER); - if(ps2->coreTexture->Vram == GSKIT_ALLOC_ERROR) - { - printf("VRAM Allocation Failed. Will not upload texture.\n"); - } - } - - if (ps2->menuVisible) - { - ps2->menuTexture->Vram=gsKit_vram_alloc(ps2->gsGlobal, textureSize(ps2->menuTexture) , GSKIT_ALLOC_USERBUFFER); - if(ps2->menuTexture->Vram == GSKIT_ALLOC_ERROR) - { - printf("VRAM Allocation Failed. Will not upload texture.\n"); - } - } - - if (frame) - { + vram_alloc(ps2->gsGlobal, ps2->coreTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); + prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, 1); } - if (ps2->menuVisible) - { + if (ps2->menuVisible) { + vram_alloc(ps2->gsGlobal, ps2->menuTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture); - } - - if (frame) - { - gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->coreTexture, - 0.0f, - 0.0f, // Y1 - 0.0f, // U1 - 0.0f, // V1 - ps2->gsGlobal->Width, // X2 - ps2->gsGlobal->Height, // Y2 - ps2->coreTexture->Width, // U2 - ps2->coreTexture->Height, // V2 - 2, - GS_WHITE); - } - - if (ps2->menuVisible) - { - gsKit_prim_sprite_texture( ps2->gsGlobal, ps2->menuTexture, - 0.0f, - 0.0f, // Y1 - 0.0f, // U1 - 0.0f, // V1 - ps2->gsGlobal->Width, // X2 - ps2->gsGlobal->Height, // Y2 - ps2->menuTexture->Width, // U2 - ps2->menuTexture->Height, // V2 - 2, - GS_WHITE); + prim_texture(ps2->gsGlobal, ps2->menuTexture, 1, 1); } gsKit_sync_flip(ps2->gsGlobal); @@ -290,10 +250,11 @@ static void ps2_gfx_free(void *data) ps2_video_t *ps2 = (ps2_video_t*)data; gsKit_clear(ps2->gsGlobal, GS_WHITE); + gsKit_vram_clear(ps2->gsGlobal); deinitTexture(ps2->menuTexture); deinitTexture(ps2->coreTexture); - gsKit_vram_clear(ps2->gsGlobal); + gsKit_deinit_global(ps2->gsGlobal); free(data); From 4e1624359a77b8881b2d2697c7d37f8a4620fd0c Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 14:27:15 +0100 Subject: [PATCH 19/24] Added Filter option in the creation of Textures --- gfx/drivers/ps2_gfx.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 10f0320b1c..f6fa206682 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -35,6 +35,8 @@ typedef struct ps2_video bool full_screen; bool rgb32; + int menu_filter; + int core_filter; } ps2_video_t; // PRIVATE METHODS @@ -95,7 +97,7 @@ static void color_correction16(uint16_t *buffer, uint32_t dimensions) } static void transfer_texture(GSTEXTURE *texture, const void *frame, - int width, int height, bool rgb32, bool color_correction) { + int width, int height, bool rgb32, int filter, bool color_correction) { int PSM = rgb32 ? GS_PSM_CT32 : GS_PSM_CT16; size_t size = gsKit_texture_size_ee(width, height, PSM); @@ -106,7 +108,7 @@ static void transfer_texture(GSTEXTURE *texture, const void *frame, texture->Width = width; texture->Height = height; texture->PSM = PSM; - texture->Filter = GS_FILTER_NEAREST; + texture->Filter = filter; free(texture->Mem); texture->Mem = memalign(128, size); } @@ -162,6 +164,7 @@ static void *ps2_gfx_init(const video_info_t *video, init_ps2_video(ps2); ps2->rgb32 = video->rgb32; + ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; if (input && input_data) { @@ -196,7 +199,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, gsKit_vram_clear(ps2->gsGlobal); if (frame) { - transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, 1); + transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, ps2->core_filter, 1); vram_alloc(ps2->gsGlobal, ps2->coreTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, 1); @@ -295,6 +298,8 @@ static bool ps2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle) static void ps2_set_filtering(void *data, unsigned index, bool smooth) { ps2_video_t *ps2 = (ps2_video_t*)data; + + ps2->menu_filter = smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; } static void ps2_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) @@ -312,7 +317,7 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, { ps2_video_t *ps2 = (ps2_video_t*)data; - transfer_texture(ps2->menuTexture, frame, width, height, rgb32, 0); + transfer_texture(ps2->menuTexture, frame, width, height, rgb32, ps2->menu_filter, 0); } static void ps2_set_texture_enable(void *data, bool enable, bool full_screen) From 52544115db8e0ff423c1cfac7f3c87fe7fe6c2c8 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 14:36:59 +0100 Subject: [PATCH 20/24] Add fullscreen parameter --- gfx/drivers/ps2_gfx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index f6fa206682..e57b8147c4 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -32,7 +32,7 @@ typedef struct ps2_video GSTEXTURE *coreTexture; bool menuVisible; - bool full_screen; + bool fullscreen; bool rgb32; int menu_filter; @@ -135,7 +135,7 @@ static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) { } } -static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool full_screen) { +static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool fullscreen) { gsKit_prim_sprite_texture( gsGlobal, texture, 0.0f, 0.0f, // Y1 @@ -164,6 +164,7 @@ static void *ps2_gfx_init(const video_info_t *video, init_ps2_video(ps2); ps2->rgb32 = video->rgb32; + ps2->fullscreen = video->fullscreen; ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; if (input && input_data) @@ -202,13 +203,13 @@ static bool ps2_gfx_frame(void *data, const void *frame, transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, ps2->core_filter, 1); vram_alloc(ps2->gsGlobal, ps2->coreTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); - prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, 1); + prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->fullscreen); } if (ps2->menuVisible) { vram_alloc(ps2->gsGlobal, ps2->menuTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture); - prim_texture(ps2->gsGlobal, ps2->menuTexture, 1, 1); + prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen); } gsKit_sync_flip(ps2->gsGlobal); @@ -320,13 +321,11 @@ static void ps2_set_texture_frame(void *data, const void *frame, bool rgb32, transfer_texture(ps2->menuTexture, frame, width, height, rgb32, ps2->menu_filter, 0); } -static void ps2_set_texture_enable(void *data, bool enable, bool full_screen) +static void ps2_set_texture_enable(void *data, bool enable, bool fullscreen) { - (void) full_screen; - ps2_video_t *ps2 = (ps2_video_t*)data; ps2->menuVisible = enable; - ps2->full_screen = full_screen; + ps2->fullscreen = fullscreen; } static const video_poke_interface_t ps2_poke_interface = { From 7fa7bd32d366a514319e7fdb261f22f8c3b879e2 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Thu, 1 Nov 2018 17:26:27 +0100 Subject: [PATCH 21/24] Now it supports force_aspect ratio --- gfx/drivers/ps2_gfx.c | 46 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index e57b8147c4..9db6c94bad 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -24,6 +24,7 @@ #include #define GS_WHITE GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00) // turn white GS Screen +#define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) // turn white GS Screen typedef struct ps2_video { @@ -35,6 +36,7 @@ typedef struct ps2_video bool fullscreen; bool rgb32; + bool force_aspect; int menu_filter; int core_filter; } ps2_video_t; @@ -58,7 +60,7 @@ static GSGLOBAL *init_GSGlobal(void) { gsKit_init_screen(gsGlobal); gsKit_mode_switch(gsGlobal, GS_ONESHOT); - gsKit_clear(gsGlobal, GS_WHITE); + gsKit_clear(gsGlobal, GS_BLACK); return gsGlobal; } @@ -135,14 +137,41 @@ static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) { } } -static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool fullscreen) { +static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool force_aspect) { + float x1, y1, x2, y2; + if (force_aspect) { + float delta = 1.0f; + float texture_aspect_ratio = texture->Width / texture->Height; + float gsGlobal_aspect_ratio = gsGlobal->Width / gsGlobal->Height; + if (texture_aspect_ratio < gsGlobal_aspect_ratio) { + //height + delta = gsGlobal->Height / texture->Height; + } else { + //width + delta = gsGlobal->Width / texture->Width; + } + float newWidth = texture->Width * delta; + float newHeight = texture->Height * delta; + + x1 = (gsGlobal->Width - newWidth) / 2.0f; + y1 = (gsGlobal->Height - newHeight) / 2.0f; + x2 = newWidth + x1; + y2 = newHeight + y1; + + } else { + x1 = 0.0f; + y1 = 0.0f; + x2 = gsGlobal->Width; + y2 = gsGlobal->Height; + } + gsKit_prim_sprite_texture( gsGlobal, texture, - 0.0f, - 0.0f, // Y1 + x1, //X1 + y1, // Y1 0.0f, // U1 0.0f, // V1 - gsGlobal->Width, // X2 - gsGlobal->Height, // Y2 + x2, // X2 + y2, // Y2 texture->Width, // U2 texture->Height, // V2 zPosition, @@ -166,6 +195,7 @@ static void *ps2_gfx_init(const video_info_t *video, ps2->rgb32 = video->rgb32; ps2->fullscreen = video->fullscreen; ps2->core_filter = video->smooth ? GS_FILTER_LINEAR : GS_FILTER_NEAREST; + ps2->force_aspect = video->force_aspect; if (input && input_data) { @@ -203,7 +233,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, transfer_texture(ps2->coreTexture, frame, width, height, ps2->rgb32, ps2->core_filter, 1); vram_alloc(ps2->gsGlobal, ps2->coreTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->coreTexture); - prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->fullscreen); + prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect); } if (ps2->menuVisible) { @@ -253,7 +283,7 @@ static void ps2_gfx_free(void *data) { ps2_video_t *ps2 = (ps2_video_t*)data; - gsKit_clear(ps2->gsGlobal, GS_WHITE); + gsKit_clear(ps2->gsGlobal, GS_BLACK); gsKit_vram_clear(ps2->gsGlobal); deinitTexture(ps2->menuTexture); From 801927aaf5d1289d72acf14a31384273b47a9456 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 4 Nov 2018 13:15:42 +0100 Subject: [PATCH 22/24] Fixed issues with the colors. Now it is working fine with 2048 --- gfx/drivers/ps2_gfx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 9db6c94bad..d76e455ee4 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -23,7 +23,7 @@ #include #include -#define GS_WHITE GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00) // turn white GS Screen +#define GS_TEXT GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00) // turn white GS Screen #define GS_BLACK GS_SETREG_RGBAQ(0x00,0x00,0x00,0x00,0x00) // turn white GS Screen typedef struct ps2_video @@ -45,11 +45,11 @@ typedef struct ps2_video static GSGLOBAL *init_GSGlobal(void) { GSGLOBAL *gsGlobal = gsKit_init_global() - gsGlobal->PSM = GS_PSM_CT16; - // gsGlobal->PSMZ = GS_PSMZ_16S; - gsGlobal->DoubleBuffering = GS_SETTING_OFF; + gsGlobal->PSM = GS_PSM_CT24; + gsGlobal->PSMZ = GS_PSMZ_16S; + gsGlobal->DoubleBuffering = GS_SETTING_ON; gsGlobal->ZBuffering = GS_SETTING_OFF; - gsGlobal->PrimAlphaEnable = GS_SETTING_ON; /* Enable alpha blending for primitives. */ + gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF); @@ -107,11 +107,11 @@ static void transfer_texture(GSTEXTURE *texture, const void *frame, texture->Width != width || texture->Height != height || texture->PSM != PSM ) { + deinitTexture(texture); texture->Width = width; texture->Height = height; texture->PSM = PSM; texture->Filter = filter; - free(texture->Mem); texture->Mem = memalign(128, size); } @@ -175,7 +175,7 @@ static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, texture->Width, // U2 texture->Height, // V2 zPosition, - GS_WHITE); + GS_TEXT); } From 4655e15a855711516127d82faf93af257873ffed Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 9 Nov 2018 19:48:42 +0100 Subject: [PATCH 23/24] Remove unusefull things in Makefile --- Makefile.ps2 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index 6b33332618..cbd9a5c556 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -39,7 +39,6 @@ RARCH_DEFINES += -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU - LIBDIR = LDFLAGS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/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 += -lm -lg -lz -ldebug -lfileXio -laudsrv -lpatches -lpoweroff -ldma -lgskit -ldmakit -lpad -lsdl @@ -103,8 +102,4 @@ $(EE_IRX_OBJ): #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 From 8065e19cc1b0b11185a5d0e820d063ab1fe7ccc1 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Fri, 9 Nov 2018 21:11:59 +0100 Subject: [PATCH 24/24] Improve Initalisation of GSTextures --- gfx/drivers/ps2_gfx.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index d76e455ee4..cb921bbc68 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -43,11 +43,11 @@ typedef struct ps2_video // PRIVATE METHODS static GSGLOBAL *init_GSGlobal(void) { - GSGLOBAL *gsGlobal = gsKit_init_global() + GSGLOBAL *gsGlobal = gsKit_init_global(); - gsGlobal->PSM = GS_PSM_CT24; + gsGlobal->PSM = GS_PSM_CT16; gsGlobal->PSMZ = GS_PSMZ_16S; - gsGlobal->DoubleBuffering = GS_SETTING_ON; + gsGlobal->DoubleBuffering = GS_SETTING_OFF; gsGlobal->ZBuffering = GS_SETTING_OFF; gsGlobal->PrimAlphaEnable = GS_SETTING_OFF; @@ -65,10 +65,18 @@ static GSGLOBAL *init_GSGlobal(void) { return gsGlobal; } +static GSTEXTURE * prepare_new_texture(void) { + GSTEXTURE *texture = malloc(sizeof *texture); + texture->Width = 0; + texture->Height = 0; + texture->Mem = NULL; + return texture; +} + static void init_ps2_video(ps2_video_t *ps2) { ps2->gsGlobal = init_GSGlobal(); - ps2->menuTexture = malloc(sizeof *ps2->menuTexture); - ps2->coreTexture = malloc(sizeof *ps2->coreTexture); + ps2->menuTexture = prepare_new_texture(); + ps2->coreTexture = prepare_new_texture(); } static void deinitTexture(GSTEXTURE *texture) { @@ -107,11 +115,11 @@ static void transfer_texture(GSTEXTURE *texture, const void *frame, texture->Width != width || texture->Height != height || texture->PSM != PSM ) { - deinitTexture(texture); texture->Width = width; texture->Height = height; texture->PSM = PSM; texture->Filter = filter; + free(texture->Mem); texture->Mem = memalign(128, size); } @@ -226,7 +234,6 @@ static bool ps2_gfx_frame(void *data, const void *frame, if (frame_count%120==0) { printf("ps2_gfx_frame %i\n", frame_count); } - gsKit_vram_clear(ps2->gsGlobal); if (frame) { @@ -236,7 +243,8 @@ static bool ps2_gfx_frame(void *data, const void *frame, prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect); } - if (ps2->menuVisible) { + bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height; + if (ps2->menuVisible && !texture_empty) { vram_alloc(ps2->gsGlobal, ps2->menuTexture); gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture); prim_texture(ps2->gsGlobal, ps2->menuTexture, 2, ps2->fullscreen);