diff --git a/Makefile.orbis b/Makefile.orbis index 39b16801c1..302ab93c0c 100644 --- a/Makefile.orbis +++ b/Makefile.orbis @@ -3,6 +3,11 @@ DEBUG ?= 0 GRIFFIN_BUILD = 0 WHOLE_ARCHIVE_LINK = 0 +HAVE_STATIC_DUMMY ?= 0 +HAVE_GLES3 ?= 0 +HAVE_MOUSE ?= 0 +HAVE_KEYBOARD ?= 0 + PS4_TITLE_ID := RETROARCH PS4_TITLE_NAME := RetroArch @@ -10,14 +15,28 @@ PC_DEVELOPMENT_IP_ADDRESS = PC_DEVELOPMENT_UDP_PORT = OBJ := - DEFINES := +# OBJ += memory/ps4/user_mem.o \ +# memory/ps4/user_new.o \ +# input/drivers/ps4_input.o \ +# input/drivers_joypad/ps4_joypad.o \ +# audio/drivers/psp_audio.o \ +# gfx/drivers_context/orbis_ctx.o \ +# frontend/drivers/platform_orbis.o + +ifeq ($(HAVE_GLES3),1) + DEFINES += -DHAVE_OPENGLES3 +endif + +ifeq ($(HAVE_STATIC_DUMMY),1) + DEFINES += -DHAVE_STATIC_DUMMY +endif + ifeq ($(GRIFFIN_BUILD), 1) OBJ += griffin/griffin.o DEFINES += -DHAVE_GRIFFIN=1 - DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE -DHAVE_PATCH -DHAVE_SCREENSHOTS -DHAVE_CHEATS - DEFINES += -DHAVE_REWIND + DEFINES += -DHAVE_MENU -DHAVE_LIBRETRODB -DHAVE_CONFIGFILE DEFINES += -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DHAVE_RBMP -DHAVE_RTGA -DHAVE_CC_RESAMPLER DEFINES += -DHAVE_CORE_INFO_CACHE ifeq ($(DEBUG), 1) @@ -25,39 +44,52 @@ ifeq ($(GRIFFIN_BUILD), 1) endif else - HAVE_DSP_FILTER := 1 - HAVE_VIDEO_FILTER := 1 HAVE_FILTERS_BUILTIN := 1 - HAVE_LANGEXTRA := 0 - HAVE_RPNG := 1 - HAVE_RJPEG := 1 - HAVE_RBMP := 1 - HAVE_RTGA := 1 - HAVE_ZLIB := 1 - HAVE_OVERLAY := 1 - HAVE_VIDEO_LAYOUT := 0 - HAVE_7ZIP := 1 - HAVE_EGL := 1 - HAVE_GFX_WIDGETS := 1 - HAVE_GLSL := 1 - HAVE_OPENGLES := 1 - HAVE_NETWORKING := 0 - HAVE_SOCKET_LEGACY := 0 - HAVE_MENU := 1 - HAVE_MENU_COMMON := 1 - HAVE_CONFIGFILE := 1 - HAVE_SCREENSHOTS := 1 - HAVE_REWIND := 1 - HAVE_PATCH := 1 - HAVE_CHEATS := 1 - HAVE_RGUI := 0 - HAVE_MATERIALUI := 0 - HAVE_XMB := 1 - HAVE_THREADS := 1 - HAVE_LIBRETRODB := 1 - HAVE_CC_RESAMPLER := 1 - HAVE_CHEEVOS := 1 - RARCH_CONSOLE := 1 + HAVE_LANGEXTRA := 1 + HAVE_IMAGEVIEWER := 1 + HAVE_RPNG := 1 + HAVE_RJPEG := 1 + HAVE_RBMP := 1 + HAVE_RTGA := 1 + HAVE_ZLIB := 1 + HAVE_BUILTINZLIB := 1 + HAVE_OVERLAY := 1 + HAVE_VIDEO_LAYOUT := 1 + HAVE_7ZIP := 1 + HAVE_EGL := 1 + HAVE_GFX_WIDGETS := 1 + HAVE_GLSL := 1 + HAVE_SHADERPIPELINE := 1 + HAVE_OPENGL := 1 + HAVE_OPENGLES := 1 + HAVE_OPENGLES2 := 1 + HAVE_NETWORKING := 0 + HAVE_SOCKET_LEGACY := 1 + HAVE_MENU := 1 + HAVE_MENU_COMMON := 1 + HAVE_RGUI := 1 + HAVE_STB_FONT := 1 + HAVE_STB_VORBIS := 1 + HAVE_DR_FLAC := 1 + HAVE_DR_MP3 := 1 + HAVE_MATERIALUI := 1 + HAVE_XMB := 1 + HAVE_OZONE := 1 + HAVE_RGUI := 1 + HAVE_THREADS := 1 + HAVE_THREAD_ATTR := 1 + HAVE_LIBRETRODB := 1 + HAVE_CC_RESAMPLER := 1 + HAVE_CHEEVOS := 1 + HAVE_RUNAHEAD := 1 + RARCH_CONSOLE := 1 + HAVE_MAIN := 1 + HAVE_ONLINE_UPDATER := 1 + HAVE_COMPRESSION := 1 + HAVE_UPDATE_ASSETS := 1 + HAVE_UPDATE_CORES := 1 + HAVE_CONFIGFILE := 1 + HAVE_CHD := 1 HAVE_STATIC_VIDEO_FILTERS = 1 HAVE_STATIC_AUDIO_FILTERS = 1 HAVE_CORE_INFO_CACHE := 1 @@ -68,107 +100,107 @@ else include Makefile.common CFLAGS += $(DEF_FLAGS) - BLACKLIST := + BLACKLIST := libretro-common/file/nbio/nbio_orbis.o OBJ := $(filter-out $(BLACKLIST),$(OBJ)) endif -ifeq ($(strip $(PS4SDK)),) -$(error "Please set PS4SDK in your environment. export PS4SDK=ps4sdk") +ifeq ($(strip $(ORBISDEV)),) +$(error "Please set ORBISDEV in your environment. export ORBISDEV=orbisdev") endif -export PATH := $(PATH):$(PS4SDK)/bin - PREFIX := +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + CDIR := linux +endif +ifeq ($(UNAME_S),Darwin) + #PREFIX := /usr/local/opt/llvm/bin/ + CDIR := macos +endif -CC := $(PREFIX)clang -CXX := $(PREFIX)clang -AS := $(PREFIX)clang -AR := $(PREFIX)ar +CC := $(PREFIX)clang++ +CXX := $(PREFIX)clang++ +AS := $(PREFIX)as +AR := $(PREFIX)orbis-ar OBJCOPY := $(PREFIX)objcopy STRIP := $(PREFIX)strip NM := $(PREFIX)nm -LD := $(CXX) +LD := $(PREFIX)clang -INCDIRS := -I. -Ideps/7zip -Ilibretro-common/include -Ideps/stb -Ilibretro-common/include/compat/zlib -LIBDIRS := -L. +LIBDIRS += -L. -Lcores -Lmemory/ps4 -Lbuild +INCDIRS += -I. -Idefines -Imemory/ps4 -Ideps -Ideps/7zip -Ideps/libz -Ilibretro-common/include -Ideps/stb \ + -Ilibretro-common/include/compat/zlib -Ideps/rcheevos/include -I$(ORBISDEV)/usr/include -I$(ORBISDEV)/usr/include/c++/v1 -I$(ORBISDEV)/usr/include/orbis -ARCHFLAGS := -m64 -DORBIS -CFLAGS += $(ARCHFLAGS) -std=c11 -mcmodel=large -ffreestanding -nostdlib -nostdinc -fno-builtin -fno-stack-protector +ARCHFLAGS += -DORBIS -D__ORBIS__ +DEFINES += -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_FILTERS_BUILTIN \ + -DHAVE_XMB -DHAVE_RGUI -DHAVE_OZONE \ + -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_CORES -DHAVE_UPDATE_ASSETS -D__PS4__ -D_BSD_SOURCE -ifeq ($(DEBUG), 1) - CFLAGS += -O2 -g -else - CFLAGS += -O3 +ifeq ($(HAVE_KEYBOARD), 1) + DEFINES += -DHAVE_KEYBOARD + PS4_LIBS += -lSceDbgKeyboard_stub endif -ASFLAGS := $(ARCHFLAGS) -I$(PS4SDK)/include -target x86_64-scei-ps4-elf -fPIE -LDFLAGS := -O3 -Wall -m64 -nostartfiles -nostdlib -L$(PS4SDK)/lib -pie -ARFLAGS := rcs - -CRTFILE ?= $(PS4SDK)/crt0.s - -CFLAGS += -Wall -pedantic -Wno-zero-length-array -Wno-format-pedantic -CFLAGS += -D__PS4__ -I$(PS4SDK)/include -I $(PS4SDK)/include/sce -CFLAGS += -target x86_64-scei-ps4-elf -fPIE -CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE -CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES) +ifeq ($(HAVE_MOUSE),1) + DEFINES += -DHAVE_MOUSE + PS4_LIBS += -lSceMouse_stub +endif ifneq ($(PC_DEVELOPMENT_IP_ADDRESS),) - CFLAGS += -DPC_DEVELOPMENT_IP_ADDRESS='"$(PC_DEVELOPMENT_IP_ADDRESS)"' + DEFINES += -DPC_DEVELOPMENT_IP_ADDRESS='"$(PC_DEVELOPMENT_IP_ADDRESS)"' endif ifneq ($(PC_DEVELOPMENT_UDP_PORT),) - CFLAGS += -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) + DEFINES += -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) endif ifeq ($(WHOLE_ARCHIVE_LINK), 1) - WHOLE_START := -Wl,--whole-archive - WHOLE_END := -Wl,--no-whole-archive + WHOLE_START := --whole-archive + WHOLE_END := --no-whole-archive endif -CXXFLAGS := $(CFLAGS) -PS4_LIBS := -lps4link -ldebugnet -lorbisFile -lelfloader -lorbisKeyboard -lorbis2d -lpng -lz -lorbisGl -lorbisPad -lorbisAudio -lmod -lorbisFileBrowser -lorbisXbmFont -lSceNet_stub -lScePigletv2VSH_stub -lSceSystemService_stub -lSceUserService_stub -lScePad_stub -lSceAudioOut_stub -lSceIme_stub -lSceSysmodule_stub \ - -lPs4_extension_kernel_call_standard -lPs4_extension_kernel_execute_dynlib_prepare_dlclose -lPs4_common_kernel -lPs4_common_user -lPs4_common_generic -lPs4LibCInternalAdaptive_stub -lPs4LibKernelAdaptive_stub -lSceLibcInternal_stub -lkernel_stub -lps4Kernel_stub -lPs4_base_stub_resolve_minimal -lPs4_base_kernel_dlsym_standard -lPs4_base_kernel_seek_elf_address_standard -lPs4_base_assembler_register_parameter_standard -lPs4_base_assembler_system_call_standard +PS4_LIBS += -lkernel_stub -lSceLibcInternal_stub -lSceSysmodule_stub -lSceSystemService_stub \ + -lSceUserService_stub -lSceAudioOut_stub -lScePad_stub -lSceNet_stub -lSceNetCtl_stub -lScePigletv2VSH_stub -LIBS := $(WHOLE_START) -lretro_orbis $(WHOLE_END) $(PS4_LIBS) +LIBS := $(WHOLE_START) -lretro_ps4 $(WHOLE_END) $(PS4_LIBS) + +CFLAGS := -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -mcmodel=large -Wno-zero-length-array -Wno-format-pedantic -emit-obj -std=c11 $(ARCHFLAGS) $(INCDIRS) $(DEFINES) +CXXFLAGS := -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -Wall -pedantic -m64 -mcmodel=large -Wno-zero-length-array -Wno-format-pedantic -emit-obj -std=c++11 $(ARCHFLAGS) $(INCDIRS) $(DEFINES) +LDFLAGS := -isysroot $(ORBISDEV)/usr -L. -Llib -Wl,--gc-sections -Wl,-z -Wl,max-page-size=0x4000 -Wl,--dynamic-linker="/libexec/ld-elf.so.1" -Wl,-pie -Wl,--eh-frame-hdr -L$(ORBISDEV)/usr/lib -target x86_64-scei-ps4-elf -T $(ORBISDEV)/linker.x $(PS4_LIBS) +ARFLAGS := rcs + +ifeq ($(DEBUG), 1) + CFLAGS += -O0 -fdebugger-support -fno-inline + CXXFLAGS += -O0 -fdebugger-support -fno-inline +else + CFLAGS += -O3 + CXXFLAGS += -O3 +endif TARGETS := $(TARGET).elf -DEPFLAGS = -MT $@ -MMD -MP -MF $*.Tdepend -POSTCOMPILE = mv -f $*.Tdepend $*.depend - all: $(TARGETS) %.o: %.cpp -%.o: %.cpp %.depend - $(CXX) -c -o $@ $< $(CXXFLAGS) $(INCDIRS) $(DEPFLAGS) - $(POSTCOMPILE) + $(CXX) $(CXXFLAGS) -o $@ $< %.o: %.c -%.o: %.c %.depend - $(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS) $(DEPFLAGS) - $(POSTCOMPILE) + $(CC) $(CFLAGS) -o $@ $< %.o: %.S -%.o: %.S %.depend - $(CC) -c -o $@ $< $(ASFLAGS) $(INCDIRS) $(DEPFLAGS) - $(POSTCOMPILE) + $(AS) $(ASFLAGS) -o $@ $< %.o: %.s -%.o: %.s %.depend - $(CC) -c -o $@ $< $(ASFLAGS) $(INCDIRS) $(DEPFLAGS) - $(POSTCOMPILE) + $(AS) -o $@ $< -%.depend: ; +$(TARGET).elf: $(OBJ) + $(LD) $(ORBISDEV)/crt0.s $(OBJ) $(LDFLAGS) $(LIBS) -o $(TARGET).elf -$(TARGET).elf: $(OBJ) libretro_orbis.a - $(LD) $(CRTFILE) $(OBJ) $(LDFLAGS) $(LIBDIRS) $(LIBS) -o $@ +$(TARGET).a: $(OBJ) + $(AR) $(ARFLAGS) $(TARGET).a $(OBJ) + #$(OO_PS4_TOOLCHAIN)/bin/$(CDIR)/create-eboot -in=$(TARGET).elf -out=$(TARGET).oelf --paid 0x3800000000000011 clean: - rm -f $(OBJ) $(TARGET).elf - rm -f $(OBJ:.o=.depend) + rm -f $(OBJ) $(TARGET).elf $(TARGET).oelf .PHONY: clean all -.PRECIOUS: %.depend - --include $(OBJ:.o=.depend) diff --git a/audio/drivers/psp_audio.c b/audio/drivers/psp_audio.c index 211b14014e..af79589f36 100644 --- a/audio/drivers/psp_audio.c +++ b/audio/drivers/psp_audio.c @@ -34,10 +34,9 @@ #include #include #elif defined(ORBIS) -#include -#define SCE_AUDIO_OUT_PORT_TYPE_MAIN 0 -#define SCE_AUDIO_OUT_MODE_STEREO 1 -#define SceUID uint32_t +#include +#include +#include #endif #include "../audio_driver.h" @@ -55,6 +54,7 @@ typedef struct psp_audio SceUID thread; int port; + int rate; volatile uint16_t read_pos; volatile uint16_t write_pos; @@ -138,23 +138,24 @@ static void *psp_audio_init(const char *device, if (port < 0) return NULL; -#ifdef ORBIS - psp->buffer = (uint32_t*) - malloc(AUDIO_BUFFER_SIZE * sizeof(uint32_t)); -#else - /* Cache aligned, not necessary but helpful. */ - psp->buffer = (uint32_t*) - memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t)); +#if defined(ORBIS) + sceAudioOutInit(); #endif + /* Cache aligned, not necessary but helpful. */ + psp->buffer = (uint32_t*)malloc(AUDIO_BUFFER_SIZE * sizeof(uint32_t)); + //(uint32_t*)memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t)); + if(!psp->buffer) + { + RARCH_LOG("[%s][%s][%d] psp->buffer NULL\n",__FILE__,__PRETTY_FUNCTION__,__LINE__); + } + else + { + RARCH_LOG("[%s][%s][%d] psp->buffer NOT NULL %d %x\n",__FILE__,__PRETTY_FUNCTION__,__LINE__,AUDIO_BUFFER_SIZE * sizeof(uint32_t),psp->buffer); + } memset(psp->buffer, 0, AUDIO_BUFFER_SIZE * sizeof(uint32_t)); -#ifdef ORBIS - psp->zeroBuffer = (uint32_t*) - malloc(AUDIO_OUT_COUNT * sizeof(uint32_t)); -#else - psp->zeroBuffer = (uint32_t*) - memalign(64, AUDIO_OUT_COUNT * sizeof(uint32_t)); -#endif + psp->zeroBuffer = (uint32_t*)malloc(AUDIO_OUT_COUNT * sizeof(uint32_t)); + //(uint32_t*)memalign(64, AUDIO_OUT_COUNT * sizeof(uint32_t)); memset(psp->zeroBuffer, 0, AUDIO_OUT_COUNT * sizeof(uint32_t)); psp->read_pos = 0; @@ -263,6 +264,9 @@ static bool psp_audio_stop(void *data) { psp_audio_t* psp = (psp_audio_t*)data; +#if defined(ORBIS) + return false; +#else if (psp){ psp->running = false; @@ -273,6 +277,7 @@ static bool psp_audio_stop(void *data) psp->worker_thread = NULL; } return true; +#endif } static bool psp_audio_start(void *data, bool is_shutdown) diff --git a/frontend/drivers/platform_orbis.c b/frontend/drivers/platform_orbis.c index 1a9e4a703b..2ffb9ddbaa 100644 --- a/frontend/drivers/platform_orbis.c +++ b/frontend/drivers/platform_orbis.c @@ -25,6 +25,15 @@ #include #include +#if defined(HAVE_OOSDK) +#include +#include +#include +#include +#include +#include +#include +#elif defined(HAVE_LIBORBIS) #include #include #include @@ -35,6 +44,17 @@ #include #include #include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "../../memory/ps4/user_mem.h" #include @@ -56,6 +76,29 @@ #include "../../paths.h" #include "../../verbosity.h" +#if defined(HAVE_LIBORBIS) +#define CONTENT_PATH_ARG_INDEX 2 +#define EBOOT_PATH "host0:app" +#define USER_PATH "host0:app/data/retroarch/" +#define CORE_PATH EBOOT_PATH +#define CORE_DIR "" +#define CORE_INFO_PATH EBOOT_PATH +#else +#define CONTENT_PATH_ARG_INDEX 1 +#define EBOOT_PATH "/app0/" +#define USER_PATH "/data/retroarch/" +#define CORE_DIR "cores" +#define CORE_INFO_PATH USER_PATH +#if defined(BUNDLE_CORES) +#define CORE_PATH EBOOT_PATH +#else +#define CORE_PATH "/data/self/retroarch/" +#endif +#endif +#define MODULE_PATH "/data/self/system/common/lib/" +#define MODULE_PATH_EXT "/app0/sce_module/" + +#if defined(HAVE_LIBORBIS) typedef struct OrbisGlobalConf { Orbis2dConfig *conf; @@ -67,33 +110,24 @@ typedef struct OrbisGlobalConf }OrbisGlobalConf; OrbisGlobalConf *myConf; +#endif +#if defined(HAVE_OOSDK) +FILE _Stdin, _Stderr, _Stdout; +#endif char eboot_path[512]; char user_path[512]; +SceKernelModule s_piglet_module; +SceKernelModule s_shacc_module; static enum frontend_fork orbis_fork_mode = FRONTEND_FORK_NONE; -#ifdef __cplusplus -extern "C" -#endif -int main(int argc, char *argv[]) +#if defined(HAVE_TAUON_SDK) +void catchReturnFromMain(int exit_code) { - int ret; - - sceSystemServiceHideSplashScreen(); - - uintptr_t intptr=0; - sscanf(argv[1],"%p",&intptr); - myConf=(OrbisGlobalConf *)intptr; - ret=ps4LinkInitWithConf(myConf->confLink); - if(!ret) - { - ps4LinkFinish(); - return -1; - } - - return rarch_main(argc, argv, NULL); + kill(getpid(), SIGTERM); } +#endif static void frontend_orbis_get_env(int *argc, char *argv[], void *args, void *params_data) @@ -107,7 +141,11 @@ static void frontend_orbis_get_env(int *argc, char *argv[], #if defined(HAVE_LOGGER) logger_init(); #elif defined(HAVE_FILE_LOGGER) +#if defined(HAVE_LIBORBIS) retro_main_log_file_init("host0:app/temp/retroarch-log.txt"); +#else + retro_main_log_file_init("/data/retroarch/temp/retroarch-log.txt"); +#endif #endif #endif @@ -115,6 +153,7 @@ static void frontend_orbis_get_env(int *argc, char *argv[], sceSystemServiceHideSplashScreen(); +#if defined(HAVE_LIBORBIS) uintptr_t intptr=0; sscanf(argv[1],"%p",&intptr); argv[1] = NULL; @@ -128,17 +167,23 @@ static void frontend_orbis_get_env(int *argc, char *argv[], orbisFileInit(); orbisPadInitWithConf(myConf->confPad); scePadClose(myConf->confPad->padHandle); +#else + // SceUserServiceInitializeParams param; + // memset(¶m, 0, sizeof(param)); + // param.priority = SCE_KERNEL_PRIO_FIFO_DEFAULT; + // sceUserServiceInitialize(¶m); +#endif - strcpy_literal(eboot_path, "host0:app"); + strlcpy(eboot_path, EBOOT_PATH, sizeof(eboot_path)); strlcpy(g_defaults.dirs[DEFAULT_DIR_PORT], eboot_path, sizeof(g_defaults.dirs[DEFAULT_DIR_PORT])); - strcpy_literal(user_path, "host0:app/data/retroarch/"); + strlcpy(user_path, USER_PATH, sizeof(user_path)); RARCH_LOG("port dir: [%s]\n", g_defaults.dirs[DEFAULT_DIR_PORT]); - /* bundle data*/ - fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], g_defaults.dirs[DEFAULT_DIR_PORT], - "", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); - fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], g_defaults.dirs[DEFAULT_DIR_PORT], + /* bundle data */ + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], CORE_PATH, + CORE_DIR, sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], CORE_INFO_PATH, "info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO])); /* user data*/ fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_ASSETS], user_path, @@ -163,6 +208,8 @@ static void frontend_orbis_get_env(int *argc, char *argv[], "savestates", sizeof(g_defaults.dirs[DEFAULT_DIR_SAVESTATE])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SYSTEM], user_path, "system", sizeof(g_defaults.dirs[DEFAULT_DIR_SYSTEM])); + fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], user_path, + "shaders", sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CACHE], user_path, "temp", sizeof(g_defaults.dirs[DEFAULT_DIR_CACHE])); fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_OVERLAY], user_path, @@ -184,7 +231,7 @@ static void frontend_orbis_get_env(int *argc, char *argv[], params = (struct rarch_main_wrap*)params_data; params->verbose = true; - if (!string_is_empty(argv[2])) + if (!string_is_empty(argv[CONTENT_PATH_ARG_INDEX])) { static char path[PATH_MAX_LENGTH] = {0}; struct rarch_main_wrap *args = @@ -192,7 +239,7 @@ static void frontend_orbis_get_env(int *argc, char *argv[], if (args) { - strlcpy(path, argv[2], sizeof(path)); + strlcpy(path, argv[CONTENT_PATH_ARG_INDEX], sizeof(path)); args->touched = true; args->no_content = false; @@ -207,7 +254,7 @@ static void frontend_orbis_get_env(int *argc, char *argv[], RARCH_LOG("argv[1]: %s\n", argv[1]); RARCH_LOG("argv[2]: %s\n", argv[2]); - RARCH_LOG("Auto-start game %s.\n", argv[2]); + RARCH_LOG("Auto-start game %s.\n", argv[CONTENT_PATH_ARG_INDEX]); } } @@ -218,13 +265,9 @@ static void frontend_orbis_get_env(int *argc, char *argv[], static void frontend_orbis_deinit(void *data) { (void)data; -#ifndef IS_SALAMANDER - verbosity_disable(); -#ifdef HAVE_FILE_LOGGER - retro_main_log_file_deinit(); -#endif -#endif +#if defined(HAVE_LIBORBIS) ps4LinkFinish(); +#endif } static void frontend_orbis_shutdown(bool unused) @@ -235,28 +278,61 @@ static void frontend_orbis_shutdown(bool unused) static void frontend_orbis_init(void *data) { + int ret=initOrbisLinkAppVanillaGl(); + sceSystemServiceHideSplashScreen(); + + + logger_init(); + RARCH_LOG("[%s][%s][%d] Hello from retroarch level info\n",__FILE__,__PRETTY_FUNCTION__,__LINE__); + RARCH_ERR("[%s][%s][%d] Hello from retroarch level error\n",__FILE__,__PRETTY_FUNCTION__,__LINE__); + RARCH_WARN("[%s][%s][%d] Hello from retroarch level warning no warning level on debugnet yet\n",__FILE__,__PRETTY_FUNCTION__,__LINE__); + RARCH_DBG("[%s][%s][%d] Hello from retroarch level debug\n",__FILE__,__PRETTY_FUNCTION__,__LINE__); + + ret=sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_AUDIO_OUT); + if (ret) + { + RARCH_LOG("sceSysmoduleLoadModuleInternal(%s) failed: 0x%08X\n", "SCE_SYSMODULE_INTERNAL_AUDIO_OUT", ret); + + } + + + verbosity_enable(); } static void frontend_orbis_exec(const char *path, bool should_load_game) { + int ret; char argp[512] = {0}; int args = 0; +#if !defined(HAVE_LIBORBIS) + // SceKernelStat sb; + // sceKernelStat(path, &sb); + // if (!(sb.st_mode & S_IXUSR)) + // sceKernelChmod(path, S_IRWXU); +#endif + #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; + char game_path[PATH_MAX_LENGTH]; + strlcpy(game_path, path_get(RARCH_PATH_CONTENT), sizeof(game_path)); + const char * const argp[] = { + eboot_path, + game_path, + NULL + }; + args = 2; + RARCH_LOG("Attempt to load executable: %d [%s].\n", args, argp); + // ret = sceSystemServiceLoadExec(path, (char *const *)argp); } + else #endif - - RARCH_LOG("Attempt to load executable: [%s].\n", path); - RARCH_LOG("Attempt to load executable: %d [%s].\n", args, argp); - //int ret = sceAppMgrLoadExec(path, args==0? NULL : (char * const*)((const char*[]){argp, 0}), NULL); + { + // ret = sceSystemServiceLoadExec(path, NULL); + } //RARCH_LOG("Attempt to load executable: [%d].\n", ret); - } #ifndef IS_SALAMANDER @@ -325,18 +401,51 @@ static int frontend_orbis_parse_drive_list(void *data, bool load_content) MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR : MENU_ENUM_LABEL_FILE_BROWSER_DIRECTORY; +#if defined(HAVE_LIBORBIS) menu_entries_append_enum(list, "host0:app", msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), enum_idx, FILE_TYPE_DIRECTORY, 0, 0); +#else + menu_entries_append_enum(list, + "/", + 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, + "/data", + 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, + "/usb0", + msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR), + enum_idx, + FILE_TYPE_DIRECTORY, 0, 0); +#endif #endif return 0; - } +// static size_t frontend_orbis_get_mem_total(void) +// { +// size_t max_mem = 0, cur_mem = 0; +// get_user_mem_size(&max_mem, &cur_mem); +// return max_mem; +// } + +// static size_t frontend_orbis_get_mem_used(void) +// { +// size_t max_mem = 0, cur_mem = 0; +// get_user_mem_size(&max_mem, &cur_mem); +// return cur_mem; +// } + frontend_ctx_driver_t frontend_ctx_orbis = { - frontend_orbis_get_env, + NULL, /*frontend_orbis_get_env,*/ frontend_orbis_init, frontend_orbis_deinit, frontend_orbis_exitspawn, @@ -355,8 +464,8 @@ frontend_ctx_driver_t frontend_ctx_orbis = { frontend_orbis_get_arch, NULL, frontend_orbis_parse_drive_list, - NULL, /* get_total_mem */ - NULL, /* get_free_mem */ + NULL, /* TODO: frontend_orbis_get_mem_total,*/ + NULL, /* TODO: frontend_orbis_get_mem_used,*/ NULL, /* install_signal_handler */ NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c index 90e4ae6ee0..c1df540b5d 100644 --- a/frontend/frontend_driver.c +++ b/frontend/frontend_driver.c @@ -195,6 +195,9 @@ bool frontend_driver_get_core_extension(char *s, size_t len) #if defined(PSP) strcpy_literal(s, "pbp"); return true; +#elif defined(ORBIS) + strlcpy(s, "self|bin", len); + return true; #elif defined(VITA) strcpy_literal(s, "self|bin"); return true; @@ -247,6 +250,9 @@ bool frontend_driver_get_salamander_basename(char *s, size_t len) #if defined(PSP) strcpy_literal(s, "EBOOT.PBP"); return true; +#elif defined(ORBIS) + strlcpy(s, "eboot.bin", len); + return true; #elif defined(VITA) strcpy_literal(s, "eboot.bin"); return true; diff --git a/gfx/common/orbis_common.h b/gfx/common/orbis_common.h index 289c7786cf..965cc1ac2a 100644 --- a/gfx/common/orbis_common.h +++ b/gfx/common/orbis_common.h @@ -9,11 +9,27 @@ #define ATTR_ORBISGL_WIDTH 1920 #define ATTR_ORBISGL_HEIGHT 1080 +#if defined(HAVE_OOSDK) +#define SIZEOF_SCE_SHDR_CACHE_CONFIG 0x10C +TYPE_BEGIN(struct _SceShdrCacheConfig, SIZEOF_SCE_SHDR_CACHE_CONFIG); + TYPE_FIELD(uint32_t ver, 0x00); + TYPE_FIELD(uint32_t unk1, 0x04); + TYPE_FIELD(uint32_t unk2, 0x08); + TYPE_FIELD(char cache_dir[128], 0x0C); +TYPE_END(); +typedef struct _SceShdrCacheConfig SceShdrCacheConfig; + +bool scePigletSetShaderCacheConfiguration(const SceShdrCacheConfig *config); +#endif + typedef struct { #ifdef HAVE_EGL egl_ctx_data_t egl; ScePglConfig pgl_config; +#if defined(HAVE_OOSDK) + SceShdrCacheConfig shdr_cache_config; +#endif #endif SceWindow native_window; diff --git a/gfx/drivers_context/orbis_ctx.c b/gfx/drivers_context/orbis_ctx.c index 548e8db806..b1baa34870 100644 --- a/gfx/drivers_context/orbis_ctx.c +++ b/gfx/drivers_context/orbis_ctx.c @@ -15,8 +15,10 @@ */ #include - +#include #include +#include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -29,12 +31,14 @@ #include "../common/orbis_common.h" #include "../../frontend/frontend_driver.h" #include "../../configuration.h" +#include /* TODO/FIXME - static globals */ static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API; /* TODO/FIXME - global reference */ extern bool platform_orbis_has_focus; +extern SceKernelModule s_piglet_module; void orbis_ctx_destroy(void *data) { @@ -53,7 +57,7 @@ void orbis_ctx_destroy(void *data) static void orbis_ctx_get_video_size(void *data, unsigned *width, unsigned *height) { - orbis_ctx_data_t + orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; *width = ATTR_ORBISGL_WIDTH; @@ -75,7 +79,11 @@ static void *orbis_ctx_init(void *video_driver) EGL_STENCIL_SIZE, 0, EGL_SAMPLE_BUFFERS, 0, EGL_SAMPLES, 0, +#if defined(HAVE_OPENGLES3) + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, +#else EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, +#endif EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE}; #endif @@ -91,18 +99,18 @@ static void *orbis_ctx_init(void *video_driver) memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config)); { - ctx_orbis->pgl_config.size = + ctx_orbis->pgl_config.size = sizeof(ctx_orbis->pgl_config); - ctx_orbis->pgl_config.flags = - SCE_PGL_FLAGS_USE_COMPOSITE_EXT - | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY + ctx_orbis->pgl_config.flags = + SCE_PGL_FLAGS_USE_COMPOSITE_EXT + | SCE_PGL_FLAGS_USE_FLEXIBLE_MEMORY | 0x60; ctx_orbis->pgl_config.processOrder = 1; - ctx_orbis->pgl_config.systemSharedMemorySize = 0x200000; - ctx_orbis->pgl_config.videoSharedMemorySize = 0x2400000; - ctx_orbis->pgl_config.maxMappedFlexibleMemory = 0xAA00000; - ctx_orbis->pgl_config.drawCommandBufferSize = 0xC0000; - ctx_orbis->pgl_config.lcueResourceBufferSize = 0x10000; + ctx_orbis->pgl_config.systemSharedMemorySize = 0x1000000; + ctx_orbis->pgl_config.videoSharedMemorySize = 0x3000000; + ctx_orbis->pgl_config.maxMappedFlexibleMemory = 0xFFFFFFFF; + ctx_orbis->pgl_config.drawCommandBufferSize = 0x100000; + ctx_orbis->pgl_config.lcueResourceBufferSize = 0x1000000; ctx_orbis->pgl_config.dbgPosCmd_0x40 = ATTR_ORBISGL_WIDTH; ctx_orbis->pgl_config.dbgPosCmd_0x44 = ATTR_ORBISGL_HEIGHT; ctx_orbis->pgl_config.dbgPosCmd_0x48 = 0; @@ -116,6 +124,22 @@ static void *orbis_ctx_init(void *video_driver) goto error; } +#if defined(HAVE_OOSDK) + const char *shdr_cache_dir = "/data/retroarch/temp/"; + memset(&ctx_orbis->shdr_cache_config, 0, sizeof(ctx_orbis->shdr_cache_config)); + { + ctx_orbis->shdr_cache_config.ver = 0x00010064; + snprintf(ctx_orbis->shdr_cache_config.cache_dir, strlen(shdr_cache_dir) + 1, "%s", shdr_cache_dir); + } + + ret = scePigletSetShaderCacheConfiguration(&ctx_orbis->shdr_cache_config); + if (!ret) + { + printf("[ORBISGL] scePigletSetShaderCacheConfiguration failed 0x%08X.\n",ret); + goto error; + } +#endif + if (!egl_init_context(&ctx_orbis->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor, &n, attribs, NULL)) { @@ -154,10 +178,14 @@ static bool orbis_ctx_set_video_mode(void *data, bool fullscreen) { /* Create an EGL rendering context */ - static const EGLint + static const EGLint contextAttributeList[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, +#if defined(HAVE_OPENGLES3) + EGL_CONTEXT_CLIENT_VERSION, 3, // GLES3 +#else + EGL_CONTEXT_CLIENT_VERSION, 2, // GLES2 +#endif EGL_NONE}; orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; @@ -239,6 +267,16 @@ static void orbis_ctx_swap_buffers(void *data) #endif } +static gfx_ctx_proc_t orbis_ctx_get_proc_address(const char *symbol) +{ + gfx_ctx_proc_t ptr_sym = NULL; +#ifdef HAVE_EGL + ptr_sym = egl_get_proc_address(symbol); +#endif + if (!ptr_sym && s_piglet_module > 0) + sceKernelDlsym(s_piglet_module, symbol, (void **)&ptr_sym); + return ptr_sym; +} static void orbis_ctx_bind_hw_render(void *data, bool enable) { orbis_ctx_data_t *ctx_orbis = (orbis_ctx_data_t *)data; diff --git a/gfx/drivers_font_renderer/stb_unicode.c b/gfx/drivers_font_renderer/stb_unicode.c index 233b001667..7159535656 100644 --- a/gfx/drivers_font_renderer/stb_unicode.c +++ b/gfx/drivers_font_renderer/stb_unicode.c @@ -312,6 +312,14 @@ static const char *font_renderer_stb_unicode_get_default_font(void) "vs0:data/external/font/pvf/k006004ds.ttf", "vs0:data/external/font/pvf/n023055ms.ttf", "vs0:data/external/font/pvf/n023055ts.ttf", +#elif defined(ORBIS) + "/preinst/common/font/c041056ts.ttf", + "/preinst/common/font/d013013ds.ttf", + "/preinst/common/font/e046323ms.ttf", + "/preinst/common/font/e046323ts.ttf", + "/preinst/common/font/k006004ds.ttf", + "/preinst/common/font/n023055ms.ttf", + "/preinst/common/font/n023055ts.ttf", #elif !defined(__WINRT__) "/usr/share/fonts/TTF/DejaVuSansMono.ttf", "/usr/share/fonts/TTF/DejaVuSans.ttf", diff --git a/gfx/font_driver.c b/gfx/font_driver.c index 3aede8eba2..0970b0c435 100644 --- a/gfx/font_driver.c +++ b/gfx/font_driver.c @@ -35,7 +35,7 @@ static const font_renderer_driver_t *font_backends[] = { &coretext_font_renderer, #endif #ifdef HAVE_STB_FONT -#if defined(VITA) || defined(WIIU) || defined(ANDROID) || (defined(_WIN32) && !defined(_XBOX) && !defined(_MSC_VER) && _MSC_VER >= 1400) || (defined(_WIN32) && !defined(_XBOX) && defined(_MSC_VER)) || defined(HAVE_LIBNX) || defined(__linux__) || defined (HAVE_EMSCRIPTEN) || defined(__APPLE__) || defined(HAVE_ODROIDGO2) || defined(__PS3__) +#if defined(VITA) || defined(ORBIS) || defined(WIIU) || defined(ANDROID) || (defined(_WIN32) && !defined(_XBOX) && !defined(_MSC_VER) && _MSC_VER >= 1400) || (defined(_WIN32) && !defined(_XBOX) && defined(_MSC_VER)) || defined(HAVE_LIBNX) || defined(__linux__) || defined (HAVE_EMSCRIPTEN) || defined(__APPLE__) || defined(HAVE_ODROIDGO2) || defined(__PS3__) &stb_unicode_font_renderer, #else &stb_font_renderer, diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index 016eb5843f..b0b98a4d8c 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -21,7 +21,8 @@ #include "../../config.h" #endif -#include +#include +#include #include #include diff --git a/input/drivers_joypad/ps4_joypad.c b/input/drivers_joypad/ps4_joypad.c index 4a0042e4c8..31e3e5a7ab 100644 --- a/input/drivers_joypad/ps4_joypad.c +++ b/input/drivers_joypad/ps4_joypad.c @@ -22,33 +22,14 @@ #include "../input_driver.h" #include "../../tasks/tasks_internal.h" +#include "../../verbosity.h" -#include -#include +#include +#include -#define PS4_MAX_ORBISPADS 16 -#define SCE_USER_SERVICE_MAX_LOGIN_USERS 16 -#define SCE_USER_SERVICE_USER_ID_INVALID 0xFFFFFFFF -#define SCE_ORBISPAD_ERROR_ALREADY_OPENED 0x80920004 - -#define ORBISPAD_L3 0x00000002 -#define ORBISPAD_R3 0x00000004 -#define ORBISPAD_OPTIONS 0x00000008 -#define ORBISPAD_UP 0x00000010 -#define ORBISPAD_RIGHT 0x00000020 -#define ORBISPAD_DOWN 0x00000040 -#define ORBISPAD_LEFT 0x00000080 -#define ORBISPAD_L2 0x00000100 -#define ORBISPAD_R2 0x00000200 -#define ORBISPAD_L1 0x00000400 -#define ORBISPAD_R1 0x00000800 -#define ORBISPAD_TRIANGLE 0x00001000 -#define ORBISPAD_CIRCLE 0x00002000 -#define ORBISPAD_CROSS 0x00004000 -#define ORBISPAD_SQUARE 0x00008000 -#define ORBISPAD_TOUCH_PAD 0x00100000 -#define ORBISPAD_INTERCEPTED 0x80000000 +#define LERP(p, f, t) ((((p * 10) * (t * 10)) / (f * 10)) / 10) +#if defined(HAVE_LIBORBIS) || defined(ORBIS) typedef struct SceUserServiceLoginUserIdList { int32_t userId[SCE_USER_SERVICE_MAX_LOGIN_USERS]; @@ -56,6 +37,7 @@ typedef struct SceUserServiceLoginUserIdList int sceUserServiceGetLoginUserIdList( SceUserServiceLoginUserIdList* userIdList); +#endif /* * Global var's @@ -63,7 +45,7 @@ int sceUserServiceGetLoginUserIdList( typedef struct { SceUserServiceUserId userId; - int handle; + int handle[PS4_MAX_PAD_PORT_TYPES]; bool connected; } ds_joypad_state; @@ -73,6 +55,13 @@ static uint64_t pad_state[PS4_MAX_ORBISPADS]; static int16_t analog_state[PS4_MAX_ORBISPADS][2][2]; static int16_t num_players = 0; +static INLINE int16_t convert_u8_to_s16(uint8_t val) +{ + if (val == 0) + return -0x7fff; + return val * 0x0101 - 0x8000; +} + static const char *ps4_joypad_name(unsigned pad) { return "PS4 Controller"; @@ -80,17 +69,17 @@ static const char *ps4_joypad_name(unsigned pad) static void *ps4_joypad_init(void *data) { - int result; + int result, handle; SceUserServiceLoginUserIdList userIdList; num_players = 0; scePadInit(); - result = sceUserServiceGetLoginUserIdList(&userIdList); + result = sceUserServiceGetLoginUserIdList(&userIdList); - if (result == 0) - { + if (result == 0) + { unsigned i; for (i = 0; i < SCE_USER_SERVICE_MAX_LOGIN_USERS; i++) { @@ -108,8 +97,22 @@ static void *ps4_joypad_init(void *data) if (index == num_players) { - ds_joypad_states[num_players].handle = scePadOpen(userId, 0, 0, NULL); - if (ds_joypad_states[num_players].handle > 0) + ds_joypad_states[num_players].handle[0] = scePadOpen(userId, SCE_PAD_PORT_TYPE_STANDARD, 0, NULL); + // if (ds_joypad_states[num_players].handle[0] == SCE_ORBISPAD_ERROR_ALREADY_OPENED) + // ds_joypad_states[num_players].handle[0] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_STANDARD, 0); + + ds_joypad_states[num_players].handle[1] = scePadOpen(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0, NULL); + // if (ds_joypad_states[num_players].handle[1] == SCE_ORBISPAD_ERROR_ALREADY_OPENED) + // ds_joypad_states[num_players].handle[1] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0); + + ds_joypad_states[num_players].handle[2] = scePadOpen(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0, NULL); + // if (ds_joypad_states[num_players].handle[2] == SCE_ORBISPAD_ERROR_ALREADY_OPENED) + // ds_joypad_states[num_players].handle[2] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0); + + RARCH_LOG("USER %x HANDLE %x\n", userId, handle); + if (ds_joypad_states[num_players].handle[0] > 0 || + ds_joypad_states[num_players].handle[1] > 0 || + ds_joypad_states[num_players].handle[2] > 0) { ds_joypad_states[num_players].connected = true; ds_joypad_states[num_players].userId = userId; @@ -125,9 +128,7 @@ static void *ps4_joypad_init(void *data) } } } - } - } return (void*)-1; @@ -142,8 +143,47 @@ static int32_t ps4_joypad_button(unsigned port, uint16_t joykey) static int16_t ps4_joypad_axis(unsigned port, uint32_t joyaxis) { - /* TODO/FIXME - implement */ - return 0; + int val = 0; + int axis = -1; + bool is_neg = false; + bool is_pos = false; + + if (joyaxis == AXIS_NONE || port >= PS4_MAX_ORBISPADS) + 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][0][0]; + break; + case 1: + val = analog_state[port][0][1]; + break; + case 2: + val = analog_state[port][1][0]; + break; + case 3: + val = analog_state[port][1][1]; + break; + } + + if (is_neg && val > 0) + val = 0; + else if (is_pos && val < 0) + val = 0; + + return val; } static int16_t ps4_joypad_state( @@ -164,7 +204,7 @@ static int16_t ps4_joypad_state( const uint64_t joykey = (binds[i].joykey != NO_BTN) ? binds[i].joykey : joypad_info->auto_binds[i].joykey; if ( - (uint16_t)joykey != NO_BTN + (uint16_t)joykey != NO_BTN && pad_state[port_idx] & (UINT64_C(1) << (uint16_t)joykey) ) ret |= ( 1 << i); @@ -189,12 +229,21 @@ static void ps4_joypad_poll(void) unsigned players_count = num_players; ScePadData buttons; - for (player = 0; player < players_count; player++) + for (player = 0; player < SCE_USER_SERVICE_MAX_LOGIN_USERS; player++) { unsigned j, k; unsigned i = player; - unsigned p = player; - int ret = scePadReadState(ds_joypad_states[player].handle,&buttons); + + if (ds_joypad_states[player].connected == false) + continue; + + int ret = scePadReadState(ds_joypad_states[player].handle[0],&buttons); + + if (buttons.connected == false) + { + ds_joypad_states[player].connected = false; + continue; + } if (ret == 0) { @@ -217,9 +266,16 @@ static void ps4_joypad_poll(void) pad_state[i] |= (state_tmp & ORBISPAD_L2) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L2) : 0; pad_state[i] |= (state_tmp & ORBISPAD_R3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_R3) : 0; pad_state[i] |= (state_tmp & ORBISPAD_L3) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_L3) : 0; + analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = convert_u8_to_s16(buttons.lx); + analog_state[i][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = convert_u8_to_s16(buttons.ly); + analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = convert_u8_to_s16(buttons.rx); + analog_state[i][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = convert_u8_to_s16(buttons.ry); } + 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 ps4_joypad_query_pad(unsigned pad) @@ -229,8 +285,48 @@ static bool ps4_joypad_query_pad(unsigned pad) static bool ps4_joypad_rumble(unsigned pad, enum retro_rumble_effect effect, uint16_t strength) { return false; } + // ScePadVibrationParam params; + + // switch (effect) + // { + // case RETRO_RUMBLE_WEAK: + // params.smallMotor = LERP(strength, 0xffff, 0xff); + // break; + // case RETRO_RUMBLE_STRONG: + // params.largeMotor = LERP(strength, 0xffff, 0xff); + // break; + // } + + // scePadSetVibration(ds_joypad_states[pad].handle[0], ¶ms); + + // return true; static void ps4_joypad_destroy(void) { } +// int result, handle; +// SceUserServiceLoginUserIdList userIdList; +// SceUserServiceUserId userId; + +// result = sceUserServiceGetLoginUserIdList(&userIdList); +// if (result == 0) +// { +// unsigned i; +// for (i = 0; i < SCE_USER_SERVICE_MAX_LOGIN_USERS; i++) +// { +// userId = userIdList.userId[i]; +// if (userId != SCE_USER_SERVICE_USER_ID_INVALID) +// { + // handle = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_STANDARD, 0); + // if (handle > 0) + // scePadClose(handle); + // handle = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0); + // if (handle > 0) + // scePadClose(handle); + // handle = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0); + // if (handle > 0) + // scePadClose(handle); +// } +// } +// } input_device_driver_t ps4_joypad = { ps4_joypad_init, diff --git a/input/input_driver.h b/input/input_driver.h index fed67d30bd..9b087d6e26 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -68,7 +68,7 @@ #define DOS_KEYBOARD_PORT DEFAULT_MAX_PADS #elif defined(XENON) #define DEFAULT_MAX_PADS 4 -#elif defined(VITA) || defined(SN_TARGET_PSP2) +#elif defined(VITA) || defined(SN_TARGET_PSP2) || defined(ORBIS) #define DEFAULT_MAX_PADS 4 #elif defined(PSP) #define DEFAULT_MAX_PADS 1 diff --git a/input/input_keymaps.c b/input/input_keymaps.c index e722e9772b..96c65798de 100644 --- a/input/input_keymaps.c +++ b/input/input_keymaps.c @@ -459,6 +459,146 @@ const struct rarch_key_map rarch_key_map_vita[] = { }; #endif +#if defined(ORBIS) +const struct rarch_key_map rarch_key_map_ps4[] = { + { 0x02A, RETROK_BACKSPACE }, + { 0x02B, RETROK_TAB }, + { 0x09C, RETROK_CLEAR }, + { 0x028, RETROK_RETURN }, + { 0x048, RETROK_PAUSE }, + { 0x029, RETROK_ESCAPE }, + { 0x02C, RETROK_SPACE }, + /*{ ?, RETROK_EXCLAIM },*/ + /*{ ?, RETROK_QUOTEDBL },*/ + /*{ ?, RETROK_HASH },*/ + /*{ ?, RETROK_DOLLAR },*/ + /*{ ?, RETROK_AMPERSAND },*/ + { 0x034, RETROK_QUOTE }, + /*{ ?, RETROK_LEFTPAREN },*/ + /*{ ?, RETROK_RIGHTPAREN },*/ + /*{ ?, RETROK_ASTERISK },*/ + /*{ ?, RETROK_PLUS },*/ + { 0x036, RETROK_COMMA }, + { 0x02D, RETROK_MINUS }, + { 0x037, RETROK_PERIOD }, + { 0x038, RETROK_SLASH }, + { 0x027, RETROK_0 }, + { 0x01E, RETROK_1 }, + { 0x01F, RETROK_2 }, + { 0x020, RETROK_3 }, + { 0x021, RETROK_4 }, + { 0x022, RETROK_5 }, + { 0x023, RETROK_6 }, + { 0x024, RETROK_7 }, + { 0x025, RETROK_8 }, + { 0x026, RETROK_9 }, + /*{ ?, RETROK_COLON },*/ + { 0x033, RETROK_SEMICOLON }, + /*{ ?, RETROK_OEM_102 },*/ + { 0x02E, RETROK_EQUALS }, + /*{ ?, RETROK_GREATER },*/ + /*{ ?, RETROK_QUESTION },*/ + /*{ ?, RETROK_AT },*/ + { 0x02F, RETROK_LEFTBRACKET }, + { 0x031, RETROK_BACKSLASH }, + { 0x030, RETROK_RIGHTBRACKET }, + /*{ ?, RETROK_CARET },*/ + /*{ ?, RETROK_UNDERSCORE },*/ + { 0x035, RETROK_BACKQUOTE }, + { 0x004, RETROK_a }, + { 0x005, RETROK_b }, + { 0x006, RETROK_c }, + { 0x007, RETROK_d }, + { 0x008, RETROK_e }, + { 0x009, RETROK_f }, + { 0x00A, RETROK_g }, + { 0x00B, RETROK_h }, + { 0x00C, RETROK_i }, + { 0x00D, RETROK_j }, + { 0x00E, RETROK_k }, + { 0x00F, RETROK_l }, + { 0x010, RETROK_m }, + { 0x011, RETROK_n }, + { 0x012, RETROK_o }, + { 0x013, RETROK_p }, + { 0x014, RETROK_q }, + { 0x015, RETROK_r }, + { 0x016, RETROK_s }, + { 0x017, RETROK_t }, + { 0x018, RETROK_u }, + { 0x019, RETROK_v }, + { 0x01A, RETROK_w }, + { 0x01B, RETROK_x }, + { 0x01C, RETROK_y }, + { 0x01D, RETROK_z }, + { 0x04C, RETROK_DELETE }, + { 0x062, RETROK_KP0 }, + { 0x059, RETROK_KP1 }, + { 0x05A, RETROK_KP2 }, + { 0x05B, RETROK_KP3 }, + { 0x05C, RETROK_KP4 }, + { 0x05D, RETROK_KP5 }, + { 0x05E, RETROK_KP6 }, + { 0x05F, RETROK_KP7 }, + { 0x060, RETROK_KP8 }, + { 0x061, RETROK_KP9 }, + { 0x063, RETROK_KP_PERIOD }, + { 0x054, RETROK_KP_DIVIDE }, + { 0x055, RETROK_KP_MULTIPLY }, + { 0x056, RETROK_KP_MINUS }, + { 0x057, RETROK_KP_PLUS }, + { 0x058, RETROK_KP_ENTER }, + { 0x067, RETROK_KP_EQUALS }, + { 0x052, RETROK_UP }, + { 0x051, RETROK_DOWN }, + { 0x04F, RETROK_RIGHT }, + { 0x050, RETROK_LEFT }, + { 0x049, RETROK_INSERT }, + { 0x04A, RETROK_HOME }, + { 0x04D, RETROK_END }, + { 0x04B, RETROK_PAGEUP }, + { 0x04E, RETROK_PAGEDOWN }, + { 0x03A, RETROK_F1 }, + { 0x03B, RETROK_F2 }, + { 0x03C, RETROK_F3 }, + { 0x03D, RETROK_F4 }, + { 0x03E, RETROK_F5 }, + { 0x03F, RETROK_F6 }, + { 0x040, RETROK_F7 }, + { 0x041, RETROK_F8 }, + { 0x042, RETROK_F9 }, + { 0x043, RETROK_F10 }, + { 0x044, RETROK_F11 }, + { 0x045, RETROK_F12 }, + { 0x068, RETROK_F13 }, + { 0x069, RETROK_F14 }, + { 0x06A, RETROK_F15 }, + { 0x053, RETROK_NUMLOCK }, + { 0x039, RETROK_CAPSLOCK }, + { 0x047, RETROK_SCROLLOCK }, + { 0x0E5, RETROK_RSHIFT }, + { 0x0E1, RETROK_LSHIFT }, + { 0x0E4, RETROK_RCTRL }, + { 0x0E0, RETROK_LCTRL }, + { 0x0E6, RETROK_RALT }, + { 0x0E2, RETROK_LALT }, + /* { ?, RETROK_RMETA }, */ + /* { ?, RETROK_LMETA }, */ + { 0x0E3, RETROK_LSUPER }, + { 0x0E7, RETROK_RSUPER }, + /* { ?, RETROK_MODE },*/ + { 0x075, RETROK_HELP }, + { 0x046, RETROK_PRINT }, + { 0x09A, RETROK_SYSREQ }, + { 0x048, RETROK_BREAK }, + { 0x076, RETROK_MENU }, + { 0x066, RETROK_POWER }, + /*{ ?, RETROK_EURO },*/ + { 0x07A, RETROK_UNDO }, + { 0, RETROK_UNKNOWN }, +}; +#endif + #if defined(HAVE_SDL) || defined(HAVE_SDL2) const struct rarch_key_map rarch_key_map_sdl[] = { { SDLK_BACKSPACE, RETROK_BACKSPACE }, diff --git a/input/input_keymaps.h b/input/input_keymaps.h index 33c6fb8d5d..89fbcbe9d1 100644 --- a/input/input_keymaps.h +++ b/input/input_keymaps.h @@ -61,6 +61,9 @@ extern const struct rarch_key_map rarch_key_map_switch[]; #ifdef VITA extern const struct rarch_key_map rarch_key_map_vita[]; #endif +#ifdef ORBIS +extern const struct rarch_key_map rarch_key_map_ps4[]; +#endif #if defined(_WIN32) && _WIN32_WINNT >= 0x0501 && !defined(__WINRT__) enum winraw_scancodes { diff --git a/libretro-common/dynamic/dylib.c b/libretro-common/dynamic/dylib.c index e967ac6cfa..680ce58677 100644 --- a/libretro-common/dynamic/dylib.c +++ b/libretro-common/dynamic/dylib.c @@ -25,14 +25,20 @@ #include #include +#if defined(ORBIS) +#include +#endif + #ifdef NEED_DYNAMIC #ifdef _WIN32 #include #include #else +#if !defined(ORBIS) #include #endif +#endif /* Assume W-functions do not work below Win2K and Xbox platforms */ #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX) @@ -118,6 +124,9 @@ dylib_t dylib_load(const char *path) return NULL; } last_dyn_error[0] = 0; +#elif defined(ORBIS) + int res; + dylib_t lib = (dylib_t)sceKernelLoadStartModule(path, 0, NULL, 0, NULL, &res); #else dylib_t lib = dlopen(path, RTLD_LAZY | RTLD_LOCAL); #endif @@ -161,6 +170,14 @@ function_t dylib_proc(dylib_t lib, const char *proc) return NULL; } last_dyn_error[0] = 0; +#elif defined(ORBIS) + void *ptr_sym = NULL; + sym = NULL; + + if (lib) { + sceKernelDlsym((SceKernelModule)lib, proc, &ptr_sym); + memcpy(&sym, &ptr_sym, sizeof(void*)); + } #else void *ptr_sym = NULL; @@ -196,6 +213,9 @@ void dylib_close(dylib_t lib) if (!FreeLibrary((HMODULE)lib)) set_dl_error(); last_dyn_error[0] = 0; +#elif defined(ORBIS) + int res; + sceKernelStopUnloadModule((SceKernelModule)lib, 0, NULL, 0, NULL, &res); #else #ifndef NO_DLCLOSE dlclose(lib); diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index b5dec4fa1d..18c783bf8b 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -75,6 +75,11 @@ #include #endif +#if defined(ORBIS) +#include +// #include +#endif + #if defined(PS2) #include #endif @@ -195,6 +200,8 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) __asm__ volatile( "mrs %0, cntvct_el0" : "=r"(time_ticks) ); #elif defined(PSP) || defined(VITA) time_ticks = sceKernelGetSystemTimeWide(); +#elif defined(ORBIS) + sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); #elif defined(PS2) time_ticks = ps2_clock(); #elif defined(_3DS) @@ -255,6 +262,8 @@ retro_time_t cpu_features_get_time_usec(void) return sceKernelGetSystemTimeWide(); #elif defined(DJGPP) return uclock() * 1000000LL / UCLOCKS_PER_SEC; +#elif defined(ORBIS) + return sceKernelGetProcessTime(); #else #error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue." #endif diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 0b90b7a7a8..36b6c3bef0 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -28,8 +28,10 @@ #ifdef ORBIS #include +#if defined(HAVE_LIBORBIS) #include #endif +#endif #include #include #include @@ -1338,13 +1340,6 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort) if (!string_is_empty(path)) { -#ifdef ORBIS - int fd = orbisOpen(path,O_RDWR|O_CREAT,0644); - if (fd < 0) - return false; - config_file_dump_orbis(conf,fd); - orbisClose(fd); -#else void* buf = NULL; FILE *file = (FILE*)fopen_utf8(path, "wb"); if (!file) @@ -1359,7 +1354,6 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort) fclose(file); if (buf) free(buf); -#endif /* Only update modified flag if config file * is actually written to disk */ @@ -1371,53 +1365,6 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort) return true; } -#ifdef ORBIS -void config_file_dump_orbis(config_file_t *conf, int fd) -{ - struct config_entry_list *list = NULL; - struct config_include_list *includes = conf->includes; - - if (conf->reference) - { - pathname_make_slashes_portable(conf->reference); - fprintf(file, "#reference \"%s\"\n", conf->reference); - } - - - list = config_file_merge_sort_linked_list( - (struct config_entry_list*)conf->entries, - config_file_sort_compare_func); - conf->entries = list; - - while (list) - { - if (!list->readonly && list->key) - { - char newlist[256]; - snprintf(newlist, sizeof(newlist), - "%s = %s\n", list->key, list->value); - orbisWrite(fd, newlist, strlen(newlist)); - } - list = list->next; - } - - /* Config files are read from the top down - if - * duplicate entries are found then the topmost - * one in the list takes precedence. This means - * '#include' directives must go *after* individual - * config entries, otherwise they will override - * any custom-set values */ - while (includes) - { - char cad[256]; - snprintf(cad, sizeof(cad), - "#include %s\n", includes->path); - orbisWrite(fd, cad, strlen(cad)); - includes = includes->next; - } -} -#endif - void config_file_dump(config_file_t *conf, FILE *file, bool sort) { struct config_entry_list *list = NULL; diff --git a/libretro-common/file/nbio/nbio_intf.c b/libretro-common/file/nbio/nbio_intf.c index 76a495d79a..6d975d953c 100644 --- a/libretro-common/file/nbio/nbio_intf.c +++ b/libretro-common/file/nbio/nbio_intf.c @@ -32,7 +32,7 @@ extern nbio_intf_t nbio_linux; extern nbio_intf_t nbio_mmap_unix; extern nbio_intf_t nbio_mmap_win32; -#if defined(ORBIS) +#if defined(ORBIS) && defined(HAVE_LIBORBIS) extern nbio_intf_t nbio_orbis; #endif extern nbio_intf_t nbio_stdio; @@ -61,7 +61,7 @@ static nbio_intf_t *internal_nbio = &nbio_linux; static nbio_intf_t *internal_nbio = &nbio_mmap_unix; #elif defined(HAVE_MMAP_WIN32) static nbio_intf_t *internal_nbio = &nbio_mmap_win32; -#elif defined(ORBIS) +#elif defined(ORBIS) && defined(HAVE_LIBORBIS) static nbio_intf_t *internal_nbio = &nbio_orbis; #else static nbio_intf_t *internal_nbio = &nbio_stdio; diff --git a/libretro-common/file/nbio/nbio_orbis.c b/libretro-common/file/nbio/nbio_orbis.c index 7f0676310e..e55deeca04 100644 --- a/libretro-common/file/nbio/nbio_orbis.c +++ b/libretro-common/file/nbio/nbio_orbis.c @@ -25,7 +25,7 @@ #if defined(ORBIS) #include #include -#include +// #include #include #include diff --git a/libretro-common/include/defines/ps4_defines.h b/libretro-common/include/defines/ps4_defines.h new file mode 100644 index 0000000000..d40acb71c0 --- /dev/null +++ b/libretro-common/include/defines/ps4_defines.h @@ -0,0 +1,48 @@ +#ifndef _PS4_DEFINES_H +#define _PS4_DEFINES_H + +#define PS4_MAX_ORBISPADS 16 +#define PS4_MAX_PAD_PORT_TYPES 3 + +#define ORBISPAD_L3 0x00000002 +#define ORBISPAD_R3 0x00000004 +#define ORBISPAD_OPTIONS 0x00000008 +#define ORBISPAD_UP 0x00000010 +#define ORBISPAD_RIGHT 0x00000020 +#define ORBISPAD_DOWN 0x00000040 +#define ORBISPAD_LEFT 0x00000080 +#define ORBISPAD_L2 0x00000100 +#define ORBISPAD_R2 0x00000200 +#define ORBISPAD_L1 0x00000400 +#define ORBISPAD_R1 0x00000800 +#define ORBISPAD_TRIANGLE 0x00001000 +#define ORBISPAD_CIRCLE 0x00002000 +#define ORBISPAD_CROSS 0x00004000 +#define ORBISPAD_SQUARE 0x00008000 +#define ORBISPAD_TOUCH_PAD 0x00100000 +#define ORBISPAD_INTERCEPTED 0x80000000 + +#if defined(HAVE_OOSDK) || defined(HAVE_LIBORBIS) || defined(ORBIS) +#define SceUID uint32_t +#define SceKernelStat OrbisKernelStat +#define SCE_KERNEL_PRIO_FIFO_DEFAULT 700 +#define SCE_AUDIO_OUT_PORT_TYPE_MAIN 0 +#define SCE_AUDIO_OUT_MODE_STEREO 1 +#define SCE_MOUSE_BUTTON_PRIMARY 0x00000001 +#define SCE_MOUSE_BUTTON_SECONDARY 0x00000002 +#define SCE_MOUSE_BUTTON_OPTIONAL 0x00000004 +#define SCE_MOUSE_BUTTON_INTERCEPTED 0x80000000 +#define SCE_MOUSE_OPEN_PARAM_MERGED 0x01 +#define SCE_MOUSE_PORT_TYPE_STANDARD 0 +#define SCE_DBG_KEYBOARD_PORT_TYPE_STANDARD 0 +#define SCE_USER_SERVICE_MAX_LOGIN_USERS 16 +#define SCE_USER_SERVICE_USER_ID_INVALID 0xFFFFFFFF +#define SCE_ORBISPAD_ERROR_ALREADY_OPENED 0x80920004 +#define SCE_PAD_PORT_TYPE_STANDARD 0 +#define SCE_PAD_PORT_TYPE_SPECIAL 2 +#define SCE_PAD_PORT_TYPE_REMOTE_CONTROL 16 +#define SCE_KERNEL_PROT_CPU_RW 0x02 +#define SCE_KERNEL_MAP_FIXED 0x10 +#endif + +#endif diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index 87e4b32b42..014d5ba722 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -214,10 +214,6 @@ bool config_file_write(config_file_t *conf, const char *path, bool val); * Does not close the file. */ void config_file_dump(config_file_t *conf, FILE *file, bool val); -#ifdef ORBIS -void config_file_dump_orbis(config_file_t *conf, int fd); -#endif - bool config_file_exists(const char *path); RETRO_END_DECLS diff --git a/libretro-common/vfs/vfs_implementation.c b/libretro-common/vfs/vfs_implementation.c index afd4f0f634..12e4703176 100644 --- a/libretro-common/vfs/vfs_implementation.c +++ b/libretro-common/vfs/vfs_implementation.c @@ -57,11 +57,6 @@ # include # endif # include -# if defined(ORBIS) -# include -# include -# include -# endif # if defined(WIIU) # include # endif @@ -74,11 +69,6 @@ # include # include # include -#elif defined(ORBIS) -# include -# include -# include -# include #elif !defined(_WIN32) # if defined(PSP) # include @@ -124,11 +114,7 @@ #include #endif -#if defined(ORBIS) -#include -#include -#include -#endif + #if defined(PSP) #include #endif @@ -200,13 +186,6 @@ int64_t retro_vfs_file_seek_internal( #ifdef ATLEAST_VC2005 /* VC2005 and up have a special 64-bit fseek */ return _fseeki64(stream->fp, offset, whence); -#elif defined(ORBIS) - { - int ret = orbisLseek(stream->fd, offset, whence); - if (ret < 0) - return -1; - return 0; - } #elif defined(HAVE_64BIT_OFFSETS) return fseeko(stream->fp, (off_t)offset, whence); #else @@ -359,24 +338,20 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( mode_str = "wb"; flags = O_WRONLY | O_CREAT | O_TRUNC; -#if !defined(ORBIS) #if !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; -#endif #endif break; case RETRO_VFS_FILE_ACCESS_READ_WRITE: mode_str = "w+b"; flags = O_RDWR | O_CREAT | O_TRUNC; -#if !defined(ORBIS) #if !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; -#endif #endif break; @@ -385,12 +360,10 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( mode_str = "r+b"; flags = O_RDWR; -#if !defined(ORBIS) #if !defined(_WIN32) flags |= S_IRUSR | S_IWUSR; #else flags |= O_BINARY; -#endif #endif break; @@ -400,15 +373,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { -#ifdef ORBIS - int fd = orbisOpen(path, flags, 0644); - if (fd < 0) - { - stream->fd = -1; - goto error; - } - stream->fd = fd; -#else FILE *fp; #ifdef HAVE_CDROM if (stream->scheme == VFS_SCHEME_CDROM) @@ -466,7 +430,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( if (stream->fp) setvbuf(stream->fp, stream->buf, _IOFBF, 0x4000); } -#endif #endif } else @@ -510,10 +473,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( } #endif } -#ifdef ORBIS - stream->size = orbisLseek(stream->fd, 0, SEEK_END); - orbisLseek(stream->fd, 0, SEEK_SET); -#else #ifdef HAVE_CDROM if (stream->scheme == VFS_SCHEME_CDROM) { @@ -534,7 +493,6 @@ libretro_vfs_implementation_file *retro_vfs_file_open_impl( retro_vfs_file_seek_internal(stream, 0, SEEK_SET); } -#endif return stream; error: @@ -570,12 +528,7 @@ int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream) if (stream->fd > 0) { -#ifdef ORBIS - orbisClose(stream->fd); - stream->fd = -1; -#else close(stream->fd); -#endif } #ifdef HAVE_CDROM end: @@ -599,12 +552,7 @@ int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream) if (stream->scheme == VFS_SCHEME_CDROM) return retro_vfs_file_error_cdrom(stream); #endif -#ifdef ORBIS - /* TODO/FIXME - implement this? */ - return 0; -#else return ferror(stream->fp); -#endif } int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream) @@ -641,14 +589,6 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream) if (stream->scheme == VFS_SCHEME_CDROM) return retro_vfs_file_tell_cdrom(stream); #endif -#ifdef ORBIS - { - int64_t ret = orbisLseek(stream->fd, 0, SEEK_CUR); - if (ret < 0) - return -1; - return ret; - } -#else #ifdef ATLEAST_VC2005 /* VC2005 and up have a special 64-bit ftell */ return _ftelli64(stream->fp); @@ -656,7 +596,6 @@ int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream) return ftello(stream->fp); #else return ftell(stream->fp); -#endif #endif } #ifdef HAVE_MMAP @@ -704,13 +643,7 @@ int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, if (stream->scheme == VFS_SCHEME_CDROM) return retro_vfs_file_read_cdrom(stream, s, len); #endif -#ifdef ORBIS - if (orbisRead(stream->fd, s, (size_t)len) < 0) - return -1; - return 0; -#else return fread(s, 1, (size_t)len, stream->fp); -#endif } #ifdef HAVE_MMAP if (stream->hints & RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS) @@ -738,13 +671,7 @@ int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, cons if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { -#ifdef ORBIS - if (orbisWrite(stream->fd, s, (size_t)len) < 0) - return -1; - return 0; -#else return fwrite(s, 1, (size_t)len, stream->fp); -#endif } #ifdef HAVE_MMAP @@ -758,11 +685,7 @@ int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream) { if (!stream) return -1; -#ifdef ORBIS - return 0; -#else return fflush(stream->fp) == 0 ? 0 : -1; -#endif } int retro_vfs_file_remove_impl(const char *path) @@ -801,10 +724,6 @@ int retro_vfs_file_remove_impl(const char *path) } #endif return -1; -#elif defined(ORBIS) - /* Orbis - * TODO/FIXME - stub for now */ - return 0; #else if (remove(path) == 0) return 0; @@ -861,13 +780,6 @@ int retro_vfs_file_rename_impl(const char *old_path, const char *new_path) #endif return ret; -#elif defined(ORBIS) - /* Orbis */ - /* TODO/FIXME - Stub for now */ - if (!old_path || !*old_path || !new_path || !*new_path) - return -1; - return 0; - #else /* Every other platform */ if (!old_path || !*old_path || !new_path || !*new_path) @@ -913,21 +825,6 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) *size = (int32_t)buf.st_size; is_dir = FIO_S_ISDIR(buf.st_mode); -#elif defined(ORBIS) - /* Orbis */ - int dir_ret = 0; - - if (!path || !*path) - return 0; - - if (size) - *size = (int32_t)buf.st_size; - - dir_ret = orbisDopen(path); - is_dir = dir_ret > 0; - orbisDclose(dir_ret); - - is_character_special = S_ISCHR(buf.st_mode); #elif defined(__PSL1GHT__) || defined(__PS3__) /* Lowlevel Lv2 */ sysFSStat buf; @@ -1034,7 +931,7 @@ int retro_vfs_stat_impl(const char *path, int32_t *size) #if defined(VITA) #define path_mkdir_error(ret) (((ret) == SCE_ERROR_ERRNO_EEXIST)) -#elif defined(PSP) || defined(PS2) || defined(_3DS) || defined(WIIU) || defined(SWITCH) || defined(ORBIS) +#elif defined(PSP) || defined(PS2) || defined(_3DS) || defined(WIIU) || defined(SWITCH) #define path_mkdir_error(ret) ((ret) == -1) #else #define path_mkdir_error(ret) ((ret) < 0 && errno == EEXIST) @@ -1059,8 +956,6 @@ int retro_vfs_mkdir_impl(const char *dir) int ret = mkdir(dir, 0755); #elif defined(VITA) int ret = sceIoMkdir(dir, 0777); -#elif defined(ORBIS) - int ret = orbisMkdir(dir, 0755); #elif defined(__QNX__) int ret = mkdir(dir, 0777); #elif defined(GEKKO) @@ -1117,9 +1012,6 @@ struct libretro_vfs_implementation_dir int error; int directory; sysFSDirent entry; -#elif defined(ORBIS) - int directory; - struct dirent entry; #else DIR *directory; const struct dirent *entry; @@ -1199,8 +1091,6 @@ libretro_vfs_implementation_dir *retro_vfs_opendir_impl( rdir->entry = NULL; #elif defined(__PSL1GHT__) || defined(__PS3__) rdir->error = sysFsOpendir(name, &rdir->directory); -#elif defined(ORBIS) - rdir->directory = orbisDopen(name); #else rdir->directory = opendir(name); rdir->entry = NULL; @@ -1238,8 +1128,6 @@ bool retro_vfs_readdir_impl(libretro_vfs_implementation_dir *rdir) uint64_t nread; rdir->error = sysFsReaddir(rdir->directory, &rdir->entry, &nread); return (nread != 0); -#elif defined(ORBIS) - return (orbisDread(rdir->directory, &rdir->entry) > 0); #else return ((rdir->entry = readdir(rdir->directory)) != NULL); #endif @@ -1258,7 +1146,7 @@ const char *retro_vfs_dirent_get_name_impl(libretro_vfs_implementation_dir *rdir if (name) free(name); return (char*)rdir->entry.cFileName; -#elif defined(VITA) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__) +#elif defined(VITA) || defined(__PSL1GHT__) || defined(__PS3__) return rdir->entry.d_name; #else if (!rdir || !rdir->entry) @@ -1278,12 +1166,6 @@ bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *rdir) #elif defined(__PSL1GHT__) || defined(__PS3__) sysFSDirent *entry = (sysFSDirent*)&rdir->entry; return (entry->d_type == FS_TYPE_DIR); -#elif defined(ORBIS) - const struct dirent *entry = &rdir->entry; - if (entry->d_type == DT_DIR) - return true; - if (!(entry->d_type == DT_UNKNOWN || entry->d_type == DT_LNK)) - return false; #else struct stat buf; char path[PATH_MAX_LENGTH]; @@ -1316,8 +1198,6 @@ int retro_vfs_closedir_impl(libretro_vfs_implementation_dir *rdir) sceIoDclose(rdir->directory); #elif defined(__PSL1GHT__) || defined(__PS3__) rdir->error = sysFsClosedir(rdir->directory); -#elif defined(ORBIS) - orbisDclose(rdir->directory); #else if (rdir->directory) closedir(rdir->directory); diff --git a/memory/ps4/user_mem.c b/memory/ps4/user_mem.c new file mode 100644 index 0000000000..0fca9f7363 --- /dev/null +++ b/memory/ps4/user_mem.c @@ -0,0 +1,224 @@ +#include +#if defined(HAVE_OOSDK) +#include +#include +#else +#include +#include +#endif +#include "../../defines/ps4_defines.h" +#include "user_mem.h" + +static OrbisMspace s_mspace = 0; +static OrbisMallocManagedSize s_mmsize; +static void *s_mem_start = 0; +static size_t s_mem_size = MEM_SIZE; + +int malloc_init(void) +{ + int res; + + if (s_mspace) + return 0; + + res = sceKernelReserveVirtualRange(&s_mem_start, MEM_SIZE, 0, MEM_ALIGN); + if (res < 0) + return 1; + + res = sceKernelMapNamedSystemFlexibleMemory(&s_mem_start, MEM_SIZE, SCE_KERNEL_PROT_CPU_RW, SCE_KERNEL_MAP_FIXED, "User Mem"); + if (res < 0) + return 1; + + s_mspace = sceLibcMspaceCreate("User Mspace", s_mem_start, s_mem_size, 0); + if (!s_mspace) + return 1; + + s_mmsize.sz = sizeof(s_mmsize); + s_mmsize.ver = 1; + res = sceLibcMspaceMallocStatsFast(s_mspace, &s_mmsize); + return 0; +} + +int malloc_finalize(void) +{ + int res; + + if (s_mspace) + { + res = sceLibcMspaceDestroy(s_mspace); + if (res != 0) + return 1; + } + + res = sceKernelReleaseFlexibleMemory(s_mem_start, s_mem_size); + if (res < 0) + return 1; + + res = sceKernelMunmap(s_mem_start, s_mem_size); + if (res < 0) + return 1; + + return 0; +} + +void *malloc(size_t size) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceMalloc(s_mspace, size); +} + +void free(void *ptr) +{ + + if (!ptr || !s_mspace) + return; + + sceLibcMspaceFree(s_mspace, ptr); +} + +void *calloc(size_t nelem, size_t size) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceCalloc(s_mspace, nelem, size); +} + +void *realloc(void *ptr, size_t size) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceRealloc(s_mspace, ptr, size); +} + +void *memalign(size_t boundary, size_t size) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceMemalign(s_mspace, boundary, size); +} + +int posix_memalign(void **ptr, size_t boundary, size_t size) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspacePosixMemalign(s_mspace, ptr, boundary, size); +} + +void *reallocalign(void *ptr, size_t size, size_t boundary) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceReallocalign(s_mspace, ptr, boundary, size); +} + +int malloc_stats(OrbisMallocManagedSize *mmsize) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceMallocStats(s_mspace, mmsize); +} + +int malloc_stats_fast(OrbisMallocManagedSize *mmsize) +{ + if (!s_mspace) + malloc_init(); + + return sceLibcMspaceMallocStatsFast(s_mspace, mmsize); +} + +size_t malloc_usable_size(void *ptr) +{ + if (!ptr) + return 0; + + return sceLibcMspaceMallocUsableSize(ptr); +} + +int vasprintf(char **bufp, const char *format, va_list ap) +{ + va_list ap1; + int bytes; + char *p; + + va_copy(ap1, ap); + + bytes = vsnprintf(NULL, 0, format, ap1) + 1; + va_end(ap1); + + *bufp = p = malloc(bytes); + if (!p) + return -1; + + return vsnprintf(p, bytes, format, ap); +} + +int asprintf(char **bufp, const char *format, ...) +{ + va_list ap, ap1; + int rv; + int bytes; + char *p; + + va_start(ap, format); + va_copy(ap1, ap); + + bytes = vsnprintf(NULL, 0, format, ap1) + 1; + va_end(ap1); + + *bufp = p = malloc(bytes); + if (!p) + return -1; + + rv = vsnprintf(p, bytes, format, ap); + va_end(ap); + + return rv; +} + +char *strdup(const char *s) +{ + size_t len = strlen(s) + 1; + void *new_s = malloc(sizeof(char) * len); + + if (!new_s) + return NULL; + + return (char *)memcpy(new_s, s, len); +} + +char *strndup(const char *s, size_t n) +{ + if (!s) + return NULL; + + char *result; + size_t len = strnlen(s, n); + + result = (char *)malloc(sizeof(char) * (len + 1)); + if (!result) + return 0; + + result[len] = '\0'; + return (char *)memcpy(result, s, len); +} + +void get_user_mem_size(size_t *max_mem, size_t *cur_mem) +{ + int res; + size_t size; + + s_mmsize.sz = sizeof(s_mmsize); + s_mmsize.ver = 1; + res = sceLibcMspaceMallocStatsFast(s_mspace, &s_mmsize); + *max_mem += s_mmsize.curSysSz; + *cur_mem += s_mmsize.curSysSz - s_mmsize.curUseSz; +} + diff --git a/memory/ps4/user_mem.h b/memory/ps4/user_mem.h new file mode 100644 index 0000000000..d07ae5246b --- /dev/null +++ b/memory/ps4/user_mem.h @@ -0,0 +1,51 @@ +#ifndef _USER_MEM_H +#define _USER_MEM_H + +#define MEM_SIZE (0xA0000000) /* 2600 MiB */ +#define MEM_ALIGN (16UL * 1024) + +#if defined(HAVE_OOSDK) +typedef void* OrbisMspace; + +typedef struct OrbisMallocManagedSize { + unsigned short sz; + unsigned short ver; + unsigned int reserv; + size_t maxSysSz; + size_t curSysSz; + size_t maxUseSz; + size_t curUseSz; +} OrbisMallocManagedSize; +#endif + +#if defined(__cplusplus) +extern "C" { +#endif +int malloc_init(void); +int malloc_finalize(void); +char *strdup(const char *s); +char *strndup(const char *s, size_t n); +int asprintf(char **bufp, const char *format, ...); +int vasprintf(char **bufp, const char *format, va_list ap); +void get_user_mem_size(size_t *max_mem, size_t *cur_mem); +#if defined(__cplusplus) +} +#endif + +#if defined(__cplusplus) +void *user_new(std::size_t size) throw(std::bad_alloc); +void *user_new(std::size_t size, const std::nothrow_t& x) throw(); +void *user_new_array(std::size_t size) throw(std::bad_alloc); +void *user_new_array(std::size_t size, const std::nothrow_t& x) throw(); +void user_delete(void *ptr) throw(); +void user_delete(void *ptr, const std::nothrow_t& x) throw(); +void user_delete_array(void *ptr) throw(); +void user_delete_array(void *ptr, const std::nothrow_t& x) throw(); +#if (__cplusplus >= 201402L) // C++14 +void user_delete(void *ptr, std::size_t size) throw(); +void user_delete(void *ptr, std::size_t size, const std::nothrow_t& x) throw(); +void user_delete_array(void *ptr, std::size_t size) throw(); +void user_delete_array(void *ptr, std::size_t size, const std::nothrow_t& x) throw(); +#endif // __cplusplus >= 201402L +#endif // __cplusplus +#endif // _USER_MEM_H diff --git a/memory/ps4/user_new.cpp b/memory/ps4/user_new.cpp new file mode 100644 index 0000000000..5347dae3bb --- /dev/null +++ b/memory/ps4/user_new.cpp @@ -0,0 +1,175 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../defines/ps4_defines.h" +#include "user_mem.h" + +void *user_new(std::size_t size) throw(std::bad_alloc) +{ + void *ptr; + + if (size == 0) + size = 1; + + while ((ptr = (void *)malloc(size)) == NULL) + { + std::new_handler handler = std::get_new_handler(); + + if (!handler) + throw std::bad_alloc(); + else + (*handler)(); + } + return ptr; +} + +void *user_new(std::size_t size, const std::nothrow_t& x) throw() +{ + void *ptr; + (void)x; + + if (size == 0) + size = 1; + + while ((ptr = (void *)malloc(size)) == NULL) + { + std::new_handler handler = std::get_new_handler(); + + if (!handler) + return NULL; + + try + { + (*handler)(); + } + catch (std::bad_alloc) + { + return NULL; + } + } + return ptr; +} + +void *user_new_array(std::size_t size) throw(std::bad_alloc) +{ + return user_new(size); +} + +void *user_new_array(std::size_t size, const std::nothrow_t& x) throw() +{ + return user_new(size, x); +} + +void user_delete(void *ptr) throw() +{ + if (ptr != NULL) + free(ptr); +} + +void user_delete(void *ptr, const std::nothrow_t& x) throw() +{ + (void)x; + if (ptr != NULL) + free(ptr); +} + +void user_delete_array(void *ptr) throw() +{ + user_delete(ptr); +} + +void user_delete_array(void *ptr, const std::nothrow_t& x) throw() +{ + user_delete(ptr, x); +} + +void *operator new(std::size_t size) throw(std::bad_alloc) +{ + return user_new(size); +} + +void *operator new(std::size_t size, const std::nothrow_t& x) throw() +{ + return user_new(size, x); +} + +void *operator new[](std::size_t size) throw(std::bad_alloc) +{ + return user_new_array(size); +} + +void *operator new[](std::size_t size, const std::nothrow_t& x) throw() +{ + return user_new_array(size, x); +} + +void operator delete(void *ptr) throw() +{ + user_delete(ptr); +} + +void operator delete(void *ptr, const std::nothrow_t& x) throw() +{ + user_delete(ptr, x); +} + +void operator delete[](void *ptr) throw() +{ + user_delete_array(ptr); +} + +void operator delete[](void *ptr, const std::nothrow_t& x) throw() +{ + user_delete_array(ptr, x); +} + +#if (__cplusplus >= 201402L) // C++14 +void user_delete(void *ptr, std::size_t size) throw() +{ + (void)size; + if (ptr != NULL) + free(ptr); +} + +void user_delete(void *ptr, std::size_t size, const std::nothrow_t& x) throw() +{ + (void)x; + if (ptr != NULL) + free(ptr); +} + +void user_delete_array(void *ptr, std::size_t size) throw() +{ + user_delete(ptr, size); +} + +void user_delete_array(void *ptr, std::size_t size, const std::nothrow_t& x) throw() +{ + user_delete(ptr, size, x); +} + +void operator delete(void *ptr, std::size_t size) throw() +{ + user_delete(ptr, size); +} + +void operator delete(void *ptr, std::size_t size, const std::nothrow_t& x) throw() +{ + user_delete(ptr, size, x); +} + +void operator delete[](void *ptr, std::size_t size) throw() +{ + user_delete_array(ptr, size); +} + +void operator delete[](void *ptr, std::size_t size, const std::nothrow_t& x) throw() +{ + user_delete_array(ptr, size, x); +} +#endif // C++14 diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 13dcd32ffb..af9cf2646a 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -6540,11 +6540,6 @@ static void xmb_context_reset_background(xmb_handle_t *xmb, const char *iconpath video_driver_supports_rgba(), 0, menu_display_handle_wallpaper_upload, NULL); } - -#ifdef ORBIS - /* To avoid weird behaviour on orbis with remote host */ - sleep(5); -#endif } static void xmb_context_reset_internal(xmb_handle_t *xmb, diff --git a/retroarch.c b/retroarch.c index bcfa74f273..4355071825 100644 --- a/retroarch.c +++ b/retroarch.c @@ -4604,10 +4604,7 @@ static bool retroarch_parse_input_and_config( optstring = "hs:fvS:A:U:DN:d:e:" BSV_MOVIE_ARG NETPLAY_ARG DYNAMIC_ARG FFMPEG_RECORD_ARG CONFIG_FILE_ARG; -#if defined(ORBIS) - argv = &(argv[2]); - argc = argc - 2; -#elif defined(WEBOS) +#if defined(WEBOS) argv = &(argv[1]); argc = argc - 1; #endif