From: kub Date: Tue, 19 Apr 2022 21:58:59 +0000 (+0200) Subject: Merge from libretro/master:7ff457f for repo synchronization X-Git-Tag: v2.00~312 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5085db3eace399b8eeec5f899e08937b7da600f;p=picodrive.git Merge from libretro/master:7ff457f for repo synchronization --- diff --git a/Makefile b/Makefile index cddd3c08..9d0c986a 100644 --- a/Makefile +++ b/Makefile @@ -223,19 +223,25 @@ USE_FRONTEND = 1 endif ifeq "$(PLATFORM)" "libretro" OBJS += platform/libretro/libretro.o -ifeq "$(USE_LIBRETRO_VFS)" "1" +ifneq ($(STATIC_LINKING), 1) OBJS += platform/libretro/libretro-common/compat/compat_strcasestr.o +ifeq "$(USE_LIBRETRO_VFS)" "1" OBJS += platform/libretro/libretro-common/compat/compat_posix_string.o OBJS += platform/libretro/libretro-common/compat/compat_strl.o OBJS += platform/libretro/libretro-common/compat/fopen_utf8.o -OBJS += platform/libretro/libretro-common/memmap/memmap.o OBJS += platform/libretro/libretro-common/encodings/encoding_utf.o OBJS += platform/libretro/libretro-common/string/stdstring.o -OBJS += platform/libretro/libretro-common/file/file_path.o +OBJS += platform/libretro/libretro-common/time/rtime.o OBJS += platform/libretro/libretro-common/streams/file_stream.o OBJS += platform/libretro/libretro-common/streams/file_stream_transforms.o +OBJS += platform/libretro/libretro-common/file/file_path.o OBJS += platform/libretro/libretro-common/vfs/vfs_implementation.o endif +endif +ifeq "$(USE_LIBRETRO_VFS)" "1" +OBJS += platform/libretro/libretro-common/memmap/memmap.o +endif + PLATFORM_ZLIB ?= 1 endif @@ -298,7 +304,10 @@ LZMA_OBJS += $(LZMA)/src/Sort.o $(LZMA)/src/LzmaDec.o $(LZMA)/src/LzFind.o LZMA_OBJS += $(LZMA)/src/Delta.o $(LZMA_OBJS): CFLAGS += -D_7ZIP_ST -OBJS += $(CHDR_OBJS) $(LZMA_OBJS) +OBJS += $(CHDR_OBJS) +ifneq ($(STATIC_LINKING), 1) +OBJS += $(LZMA_OBJS) +endif # ouf... prepend includes to overload headers available in the toolchain CHDR_I = $(shell find $(CHDR) -name 'include') CFLAGS := $(patsubst %, -I%, $(CHDR_I)) $(CFLAGS) @@ -343,7 +352,7 @@ clean: $(TARGET): $(OBJS) -ifeq ($(STATIC_LINKING), 1) +ifeq ($(STATIC_LINKING_LINK), 1) $(AR) rcs $@ $^ else $(LD) $(LINKOUT)$@ $^ $(CFLAGS) $(LDFLAGS) $(LDLIBS) @@ -364,7 +373,7 @@ pprof: platform/linux/pprof.c $(CC) $(CFLAGS) -O2 -ggdb -DPPROF -DPPROF_TOOL -I../../ -I. $^ -o $@ $(LDFLAGS) $(LDLIBS) pico/pico_int_offs.h: tools/mkoffsets.sh - make -C tools/ XCC="$(CC)" XCFLAGS="$(CFLAGS)" XPLATFORM="$(platform)" + make -C tools/ XCC="$(CC)" XCFLAGS="$(CFLAGS) -UUSE_LIBRETRO_VFS" XPLATFORM="$(platform)" %.o: %.c $(CC) -c $(OBJOUT)$@ $< $(CFLAGS) diff --git a/Makefile.libretro b/Makefile.libretro index cf9ac1d1..967a0c37 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -35,7 +35,9 @@ CFLAGS += -I platform/libretro/libretro-common/include/string CFLAGS += -I platform/libretro/libretro-common/include/vfs USE_LIBRETRO_VFS := 1 -STATIC_LINKING := 0 +STATIC_LINKING:= 0 +STATIC_LINKING_LINK:= 0 +LOW_MEMORY := 0 TARGET_NAME := picodrive LIBM := -lm GIT_VERSION ?= $(shell git rev-parse --short HEAD || echo unknown) @@ -60,6 +62,24 @@ ifneq ($(findstring SunOS,$(shell uname -a)),) CC=gcc endif +# x86/x86_64 generic +else ifneq (,$(findstring x86,$(platform))) + TARGET := $(TARGET_NAME)_libretro.so + ARCH := 86 + fpic := -fPIC + SHARED := -shared + DONT_COMPILE_IN_ZLIB = 1 + CFLAGS += -DFAMEC_NO_GOTOS + +# AARCH64 generic +else ifeq ($(platform), aarch64) + TARGET := $(TARGET_NAME)_libretro.so + ARCH = aarch64 + fpic := -fPIC + SHARED := -shared + DONT_COMPILE_IN_ZLIB = 1 + CFLAGS += -DFAMEC_NO_GOTOS + # Portable Linux else ifeq ($(platform), linux-portable) EXT ?= so @@ -76,13 +96,20 @@ else ifeq ($(platform), osx) SHARED := -dynamiclib fpic := -fPIC APPLE := 1 - ifeq ($(shell uname -p),powerpc) - CFLAGS += -DHAVE_NO_LANGEXTRA - CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__ -DFAMEC_NO_GOTOS - endif - OSXVER = `sw_vers -productVersion | cut -d. -f 2` - OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"` - SHARED += -mmacosx-version-min=10.6 + + ifeq ($(CROSS_COMPILE),1) + TARGET_RULE = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT) + CFLAGS += $(TARGET_RULE) + CPPFLAGS += $(TARGET_RULE) + CXXFLAGS += $(TARGET_RULE) + LDFLAGS += $(TARGET_RULE) + endif + + ifndef ($(NOUNIVERSAL)) + CFLAGS += $(ARCHFLAGS) + LDFLAGS += $(ARCHFLAGS) + endif + CFLAGS += -DUINT8=uint8_t -DUINT16=uint16_t -DUINT32=uint32_t -DINT8=int8_t -DINT16=int16_t -DINT32=int32_t else ifeq ($(platform), staticios) TARGET := $(TARGET_NAME)_libretro_ios.a @@ -102,13 +129,15 @@ else ifeq ($(platform), staticios) CFLAGS += -miphoneos-version-min=8.0 STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # iOS else ifneq (,$(findstring ios,$(platform))) - TARGET := $(TARGET_NAME)_libretro_ios.dylib - SHARED := -dynamiclib - fpic := -fPIC - APPLE := 1 + TARGET := $(TARGET_NAME)_libretro_ios.dylib + SHARED := -dynamiclib + fpic := -fPIC + APPLE := 1 + MINVERSION := ifeq ($(IOSSDK),) IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path) endif @@ -127,16 +156,14 @@ else ifneq (,$(findstring ios,$(platform))) CFLAGS += -DIOS ifeq ($(platform),$(filter $(platform),ios9 ios-arm64)) - CC += -miphoneos-version-min=8.0 - CXX += -miphoneos-version-min=8.0 - CC_AS += -miphoneos-version-min=8.0 - CFLAGS += -miphoneos-version-min=8.0 + MINVERSION = -miphoneos-version-min=8.0 else - CC += -miphoneos-version-min=5.0 - CXX += -miphoneos-version-min=5.0 - CC_AS += -miphoneos-version-min=5.0 - CFLAGS += -miphoneos-version-min=5.0 + MINVERSION = -miphoneos-version-min=5.0 endif + CC += $(MINVERSION) + CXX += $(MINVERSION) + CC_AS += $(MINVERSION) + CFLAGS += $(MINVERSION) # tvOS else ifeq ($(platform), tvos-arm64) @@ -144,45 +171,27 @@ else ifeq ($(platform), tvos-arm64) SHARED := -dynamiclib fpic := -fPIC APPLE := 1 - ifeq ($(IOSSDK),) - IOSSDK := $(shell xcodebuild -version -sdk appletvos Path) - endif - CC_AS = perl ./tools/gas-preprocessor.pl $(CC) - CC = clang -arch arm64 -isysroot $(IOSSDK) - CXX = clang++ -arch arm64 -isysroot $(IOSSDK) + ifeq ($(IOSSDK),) + IOSSDK := $(shell xcodebuild -version -sdk appletvos Path) + endif + CC_AS = perl ./tools/gas-preprocessor.pl $(CC) + CC = cc -arch arm64 -isysroot $(IOSSDK) + CXX = c++ -arch arm64 -isysroot $(IOSSDK) CFLAGS += -marm -DARM -D__aarch64__=1 CFLAGS += -DIOS -# PS3 -else ifeq ($(platform), ps3) - TARGET := $(TARGET_NAME)_libretro_$(platform).a - CC = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-gcc.exe - AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe - CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__ -DFAMEC_NO_GOTOS - STATIC_LINKING = 1 - # PS3 has memory mapped in a way not suitable for DRC - use_sh2drc = 0 - use_svpdrc = 0 - -# sncps3 -else ifeq ($(platform), sncps3) - ARCH = powerpc - TARGET := $(TARGET_NAME)_libretro_ps3.a - CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe - AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe - CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__ -DFAMEC_NO_GOTOS - STATIC_LINKING = 1 - # PS3 has memory mapped in a way not suitable for DRC - use_sh2drc = 0 - use_svpdrc = 0 - # Lightweight PS3 Homebrew SDK -else ifeq ($(platform), psl1ght) +else ifneq (,$(filter $(platform), ps3 psl1ght)) TARGET := $(TARGET_NAME)_libretro_$(platform).a - CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT) - AR = $(PS3DEV)/ppu/bin/ppu-ar$(EXE_EXT) - CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__ -DFAMEC_NO_GOTOS + CC = $(PS3DEV)/ppu/bin/ppu-$(COMMONLV)gcc$(EXE_EXT) + AR = $(PS3DEV)/ppu/bin/ppu-$(COMMONLV)ar$(EXE_EXT) + CFLAGS += -DFAMEC_NO_GOTOS -D__PS3__ STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 + NO_MMAP = 1 + ifeq ($(platform), psl1ght) + FLAGS += -D__PSL1GHT__ + endif # PS3 has memory mapped in a way not suitable for DRC use_sh2drc = 0 use_svpdrc = 0 @@ -193,20 +202,21 @@ else ifeq ($(platform), psp1) TARGET := $(TARGET_NAME)_libretro_$(platform).a CC = psp-gcc$(EXE_EXT) AR = psp-ar$(EXE_EXT) - CFLAGS += -G0 -ftracer - CFLAGS += -DPSP + CFLAGS += -DPSP -G0 -ftracer + CFLAGS += -I$(shell psp-config --pspsdk-path)/include STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # PS2 else ifeq ($(platform), ps2) ARCH = mipsel TARGET := $(TARGET_NAME)_libretro_$(platform).a - CC = ee-gcc$(EXE_EXT) - AR = ee-ar$(EXE_EXT) - CFLAGS += -Wall -DPS2 -DUSE_BGR555 -DFAMEC_NO_GOTOS -DRENDER_GSKIT_PS2 -fsingle-precision-constant + CC = mips64r5900el-ps2-elf-gcc$(EXE_EXT) + AR = mips64r5900el-ps2-elf-ar$(EXE_EXT) + CFLAGS += -Wall -DPS2 -D_EE -DUSE_BGR555 -DFAMEC_NO_GOTOS -DRENDER_GSKIT_PS2 -fsingle-precision-constant CFLAGS += -I$(PS2DEV)/gsKit/include -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include - CFLAGS += -DHAVE_NO_LANGEXTRA STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # CTR (3DS) else ifeq ($(platform), ctr) @@ -219,18 +229,26 @@ else ifeq ($(platform), ctr) CFLAGS += -Wall -mword-relocations CFLAGS += -fomit-frame-pointer -ffast-math STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 OBJS += platform/libretro/3ds/3ds_utils.o platform/libretro/3ds/utils.o -# Raspberry Pi (original model) Raspbian -else ifeq ($(platform), raspberrypi) - CFLAGS += -marm -mfpu=vfp -mfloat-abi=hard -march=armv6j +# Raspberry Pi +else ifneq (,$(findstring rpi,$(platform))) CFLAGS += -Wall -mword-relocations CFLAGS += -fomit-frame-pointer -ffast-math TARGET := $(TARGET_NAME)_libretro.so SHARED := -shared fpic := -fPIC + + ifneq (,$(findstring rpi1,$(platform))) + CFLAGS += -marm -mfpu=vfp -mfloat-abi=hard -march=armv6j + else ifneq (,$(findstring rpi2,$(platform))) + CFLAGS += -marm -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard + else ifneq (,$(findstring rpi3,$(platform))) + CFLAGS += -marm -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard + endif # Vita else ifeq ($(platform), vita) @@ -243,29 +261,32 @@ else ifeq ($(platform), vita) CFLAGS += -mword-relocations -fno-unwind-tables CFLAGS += -fno-optimize-sibling-calls STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # Xbox 360 else ifeq ($(platform), xenon) TARGET := $(TARGET_NAME)_libretro_xenon360.a CC = xenon-gcc$(EXE_EXT) AR = xenon-ar$(EXE_EXT) - CFLAGS += -D__LIBXENON__ -m32 -D__ppc__ + CFLAGS += -D__LIBXENON__ -m32 # Nintendo Game Cube else ifeq ($(platform), ngc) TARGET := $(TARGET_NAME)_libretro_$(platform).a CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) - CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST + CFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # Nintendo Wii else ifeq ($(platform), wii) TARGET := $(TARGET_NAME)_libretro_$(platform).a CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) - CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST + CFLAGS += -DGEKKO -DHW_RVL -mrvl -mcpu=750 -meabi -mhard-float STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # Nintendo Wii U else ifeq ($(platform), wiiu) @@ -273,14 +294,16 @@ else ifeq ($(platform), wiiu) CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) CXX = $(DEVKITPPC)/bin/powerpc-eabi-g++$(EXE_EXT) AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) - CFLAGS += -DGEKKO -DWIIU -DHW_RVL -DHW_WUP -mwup -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST + CFLAGS += -DGEKKO -DWIIU -DHW_RVL -DHW_WUP -mwup -mcpu=750 -meabi -mhard-float STATIC_LINKING = 1 + STATIC_LINKING_LINK = 1 # Nintendo Switch (libtransistor) else ifeq ($(platform), switch) TARGET := $(TARGET_NAME)_libretro_$(platform).a include $(LIBTRANSISTOR_HOME)/libtransistor.mk STATIC_LINKING=1 + STATIC_LINKING_LINK = 1 # Nintendo Switch (libnx) else ifeq ($(platform), libnx) @@ -292,6 +315,7 @@ else ifeq ($(platform), libnx) CFLAGS += -DARM -D__aarch64__=1 -march=armv8-a -mtune=cortex-a57 -mtp=soft -ffast-math -mcpu=cortex-a57+crc+fp+simd -ffunction-sections CFLAGS += -Ifrontend/switch -ftree-vectorize STATIC_LINKING=1 + STATIC_LINKING_LINK = 1 # QNX else ifeq ($(platform), qnx) @@ -413,6 +437,25 @@ else ifeq ($(platform), emscripten) TARGET := $(TARGET_NAME)_libretro_$(platform).bc ARCH = unknown + STATIC_LINKING = 1 + +# RS90 +else ifeq ($(platform), rs90) + TARGET := $(TARGET_NAME)_libretro.so +ifeq (,$(shell command -v $(RS90_PREFIX)mipsel-rs90-linux-uclibc-gcc 2>/dev/null)) + # locate the toolchain for buildbot if it isn't in path or prefix not set + RS90_PREFIX = /opt/rs90-toolchain/usr/bin/ +endif + CC = $(RS90_PREFIX)mipsel-linux-gcc + AR = $(RS90_PREFIX)mipsel-linux-ar + SHARED := -shared -nostdlib + fpic := -fPIC + LIBM := + CFLAGS += -fomit-frame-pointer -ffast-math -march=mips32 -mtune=mips32 -D__GCW0__ + # clear_cache uses SYNCI instead of a syscall + CFLAGS += -DMIPS_USE_SYNCI + LOW_MEMORY = 1 + # GCW0 else ifeq ($(platform), gcw0) TARGET := $(TARGET_NAME)_libretro.so @@ -425,7 +468,38 @@ endif SHARED := -shared -nostdlib fpic := -fPIC LIBM := - CFLAGS += -fomit-frame-pointer -ffast-math -march=mips32 -mtune=mips32r2 -mhard-float + CFLAGS += -fomit-frame-pointer -ffast-math -march=mips32 -mtune=mips32r2 -mhard-float -D__GCW0__ + # clear_cache uses SYNCI instead of a syscall + CFLAGS += -DMIPS_USE_SYNCI + +# RETROFW +else ifeq ($(platform), retrofw) + TARGET := $(TARGET_NAME)_libretro.so +ifeq (,$(shell command -v $(GCW0_PREFIX)mipsel-gcw0-linux-uclibc-gcc 2>/dev/null)) + # locate the toolchain for buildbot if it isn't in path or prefix not set + GCW0_PREFIX = /opt/retrofw-toolchain/usr/bin/ +endif + CC = $(GCW0_PREFIX)mipsel-linux-gcc + AR = $(GCW0_PREFIX)mipsel-linux-ar + SHARED := -shared -nostdlib + fpic := -fPIC + LIBM := + CFLAGS += -fomit-frame-pointer -ffast-math -march=mips32 -mtune=mips32 -mhard-float -D__GCW0__ + # clear_cache uses SYNCI instead of a syscall + CFLAGS += -DMIPS_USE_SYNCI + +# MIYOO +else ifeq ($(platform), miyoo) + TARGET := $(TARGET_NAME)_libretro.so + CC = /opt/miyoo/usr/bin/arm-linux-gcc + AR = /opt/miyoo/usr/bin/arm-linux-ar + SHARED := -shared -nostdlib + fpic := -fPIC + LIBM := + DONT_COMPILE_IN_ZLIB = 1 + CFLAGS += -fomit-frame-pointer -ffast-math -march=armv5te -mtune=arm926ej-s -D__GCW0__ + HAVE_ARMv6 = 0 + LOW_MEMORY = 1 # Windows MSVC 2017 all architectures else ifneq (,$(findstring windows_msvc2017,$(platform))) @@ -527,7 +601,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) # Windows else TARGET := $(TARGET_NAME)_libretro.dll - CC = gcc + CC ?= gcc fpic := -fPIC SHARED := -shared -static-libgcc -static-libstdc++ CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__ @@ -540,6 +614,10 @@ ifeq ($(USE_LIBRETRO_VFS),1) CFLAGS += -DUSE_LIBRETRO_VFS endif +ifeq ($(LOW_MEMORY), 1) + CFLAGS += -DLOW_MEMORY +endif + ifeq ($(NO_ARM_ASM),1) use_cyclone = 0 use_fame = 1 @@ -634,3 +712,7 @@ else endif include Makefile + +ifeq ($(platform), osx) +pico/cd/libchdr/src/libchdr_chd.o: CFLAGS += -D__MACTYPES__=1 +endif \ No newline at end of file diff --git a/cpu/sh2/compiler.c b/cpu/sh2/compiler.c index 5b5cbdf6..360fcd03 100644 --- a/cpu/sh2/compiler.c +++ b/cpu/sh2/compiler.c @@ -483,7 +483,7 @@ static void rcache_free_tmp(int hr); #include "../drc/emit_mips.c" #elif defined(__riscv__) || defined(__riscv) #include "../drc/emit_riscv.c" -#elif defined(__powerpc__) || defined(__ppc__) || defined(_M_PPC) +#elif defined(__powerpc__) || defined(__PPC__) || defined(__ppc__) || defined(_M_PPC) #include "../drc/emit_ppc.c" #elif defined(__i386__) || defined(_M_X86) #include "../drc/emit_x86.c" diff --git a/cpu/sh2/compiler.h b/cpu/sh2/compiler.h index f0322743..5cb0942b 100644 --- a/cpu/sh2/compiler.h +++ b/cpu/sh2/compiler.h @@ -47,7 +47,7 @@ u16 scan_block(u32 base_pc, int is_slave, u8 *op_flags, u32 *end_pc, #elif defined(__riscv__) || defined(__riscv) #define DRC_SR_REG "s11" #define DRC_REG_LL 0 // no ABI for (__ILP32__ && __riscv_xlen != 32) -#elif defined(__powerpc__) || defined(__ppc__) +#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) #define DRC_SR_REG "r28" #define DRC_REG_LL 0 // no ABI for __ILP32__ #elif defined(__i386__) diff --git a/jni/Android.mk b/jni/Android.mk index e8e9caca..b73f4be4 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -54,12 +54,21 @@ endif include $(COMMON_DIR)/common.mak SOURCES_C := $(LIBRETRO_DIR)/libretro.c \ + $(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \ $(COMMON_DIR)/mp3.c \ $(COMMON_DIR)/mp3_sync.c \ $(COMMON_DIR)/mp3_dummy.c \ - $(UNZIP_DIR)/unzip.c - -COREFLAGS := $(addprefix -D,$(DEFINES)) -fno-strict-aliasing + $(UNZIP_DIR)/unzip.c \ + $(CORE_DIR)/pico/cd/libchdr/src/libchdr_bitstream.c \ + $(CORE_DIR)/pico/cd/libchdr/src/libchdr_cdrom.c \ + $(CORE_DIR)/pico/cd/libchdr/src/libchdr_chd.c \ + $(CORE_DIR)/pico/cd/libchdr/src/libchdr_flac.c \ + $(CORE_DIR)/pico/cd/libchdr/src/libchdr_huffman.c \ + $(CORE_DIR)/pico/cd/libchdr/deps/lzma-19.00/src/LzFind.c \ + $(CORE_DIR)/pico/cd/libchdr/deps/lzma-19.00/src/LzmaDec.c \ + $(CORE_DIR)/pico/cd/libchdr/deps/lzma-19.00/src/LzmaEnc.c + +COREFLAGS := $(addprefix -D,$(DEFINES)) -fno-strict-aliasing -DUSE_LIBCHDR=1 -D_7ZIP_ST -I$(CORE_DIR)/pico/cd/libchdr/include -I$(CORE_DIR)/pico/cd/libchdr/deps/lzma-19.00/include GIT_VERSION := $(shell git rev-parse --short HEAD || echo unknown) ifneq ($(GIT_VERSION),"unknown") diff --git a/pico/cart.c b/pico/cart.c index 4e0c2e62..3e578dd9 100644 --- a/pico/cart.c +++ b/pico/cart.c @@ -738,65 +738,75 @@ static unsigned char *PicoCartAlloc(int filesize, int is_sms) return rom; } -int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms) +int PicoCartLoad(pm_file *f, const unsigned char *rom, unsigned int romsize, + unsigned char **prom, unsigned int *psize, int is_sms) { - unsigned char *rom; + unsigned char *rom_data = NULL; int size, bytes_read; - if (f == NULL) + if (!f && !rom) return 1; - size = f->size; + if (!rom) + size = f->size; + else + size = romsize; + if (size <= 0) return 1; size = (size+3)&~3; // Round up to a multiple of 4 // Allocate space for the rom plus padding - rom = PicoCartAlloc(size, is_sms); - if (rom == NULL) { + rom_data = PicoCartAlloc(size, is_sms); + if (rom_data == NULL) { elprintf(EL_STATUS, "out of memory (wanted %i)", size); return 2; } - if (PicoCartLoadProgressCB != NULL) - { - // read ROM in blocks, just for fun - int ret; - unsigned char *p = rom; - bytes_read=0; - do + if (!rom) { + if (PicoCartLoadProgressCB != NULL) { - int todo = size - bytes_read; - if (todo > 256*1024) todo = 256*1024; - ret = pm_read(p,todo,f); - bytes_read += ret; - p += ret; - PicoCartLoadProgressCB(bytes_read * 100LL / size); + // read ROM in blocks, just for fun + int ret; + unsigned char *p = rom_data; + bytes_read=0; + do + { + int todo = size - bytes_read; + if (todo > 256*1024) todo = 256*1024; + ret = pm_read(p,todo,f); + bytes_read += ret; + p += ret; + PicoCartLoadProgressCB(bytes_read * 100LL / size); + } + while (ret > 0); + } + else + bytes_read = pm_read(rom_data,size,f); // Load up the rom + + if (bytes_read <= 0) { + elprintf(EL_STATUS, "read failed"); + plat_munmap(rom_data, rom_alloc_size); + return 3; } - while (ret > 0); } else - bytes_read = pm_read(rom,size,f); // Load up the rom - if (bytes_read <= 0) { - elprintf(EL_STATUS, "read failed"); - plat_munmap(rom, rom_alloc_size); - return 3; - } + memcpy(rom_data, rom, romsize); if (!is_sms) { // maybe we are loading MegaCD BIOS? - if (!(PicoIn.AHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || - !strncmp((char *)rom+0x128, "BOOT", 4))) { + if (!(PicoIn.AHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom_data+0x124, "BOOT", 4) || + !strncmp((char *)rom_data+0x128, "BOOT", 4))) { PicoIn.AHW |= PAHW_MCD; } // Check for SMD: if (size >= 0x4200 && (size&0x3fff) == 0x200 && - ((rom[0x2280] == 'S' && rom[0x280] == 'E') || (rom[0x280] == 'S' && rom[0x2281] == 'E'))) { + ((rom_data[0x2280] == 'S' && rom_data[0x280] == 'E') || (rom_data[0x280] == 'S' && rom_data[0x2281] == 'E'))) { elprintf(EL_STATUS, "SMD format detected."); - DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD + DecodeSmd(rom_data,size); size-=0x200; // Decode and byteswap SMD } - else Byteswap(rom, rom, size); // Just byteswap + else Byteswap(rom_data, rom_data, size); // Just byteswap } else { @@ -804,11 +814,11 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms) elprintf(EL_STATUS, "SMD format detected."); // at least here it's not interleaved size -= 0x200; - memmove(rom, rom + 0x200, size); + memmove(rom_data, rom_data + 0x200, size); } } - if (prom) *prom = rom; + if (prom) *prom = rom_data; if (psize) *psize = size; return 0; diff --git a/pico/media.c b/pico/media.c index ca5036dc..e79bb302 100644 --- a/pico/media.c +++ b/pico/media.c @@ -31,35 +31,50 @@ static void get_ext(const char *file, char *ext) strlwr_(ext); } -static int detect_media(const char *fname) +static int detect_media(const char *fname, const unsigned char *rom, unsigned int romsize) { static const short sms_offsets[] = { 0x7ff0, 0x3ff0, 0x1ff0 }; static const char *sms_exts[] = { "sms", "gg", "sg" }; static const char *md_exts[] = { "gen", "smd", "md" }; static const char *pico_exts[] = { "pco" }; char buff0[512], buff[32]; - unsigned short *d16; - pm_file *pmf; - char ext[5]; + unsigned short *d16 = NULL; + pm_file *pmf = NULL; + const char *ext_ptr = NULL; + char ext[8]; int i; - get_ext(fname, ext); + ext[0] = '\0'; + if ((ext_ptr = strrchr(fname, '.'))) { + strncpy(ext, ext_ptr + 1, sizeof(ext)); + ext[sizeof(ext) - 1] = '\0'; + } // detect wrong extensions - if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) // s.gz ~ .mds.gz + if (!strcmp(ext, "srm") || !strcmp(ext, "gz")) // s.gz ~ .mds.gz return PM_BAD_DETECT; - /* don't believe in extensions, except .cue */ - if (strcasecmp(ext, ".cue") == 0 || strcasecmp(ext, ".chd") == 0) + /* don't believe in extensions, except .cue and .chd */ + if (strcasecmp(ext, "cue") == 0 || strcasecmp(ext, "chd") == 0) return PM_CD; - pmf = pm_open(fname); - if (pmf == NULL) - return PM_BAD_DETECT; + /* Open rom file, if required */ + if (!rom) { + pmf = pm_open(fname); + if (pmf == NULL) + return PM_BAD_DETECT; + romsize = pmf->size; + } - if (pm_read(buff0, 512, pmf) != 512) { - pm_close(pmf); - return PM_BAD_DETECT; + if (!rom) { + if (pm_read(buff0, 512, pmf) != 512) { + pm_close(pmf); + return PM_BAD_DETECT; + } + } else { + if (romsize < 512) + return PM_BAD_DETECT; + memcpy(buff0, rom, 512); } if (strncasecmp("SEGADISCSYSTEM", buff0 + 0x00, 14) == 0 || @@ -69,32 +84,53 @@ static int detect_media(const char *fname) } /* check for SMD evil */ - if (pmf->size >= 0x4200 && (pmf->size & 0x3fff) == 0x200) { - if (pm_seek(pmf, sms_offsets[0] + 0x200, SEEK_SET) == sms_offsets[0] + 0x200 && - pm_read(buff, 16, pmf) == 16 && - strncmp("TMR SEGA", buff, 8) == 0) + if (romsize >= 0x4200 && (romsize & 0x3fff) == 0x200) { + buff[0] = '\0'; + + if (!rom) { + if (pm_seek(pmf, sms_offsets[0] + 0x200, SEEK_SET) == sms_offsets[0] + 0x200) + pm_read(buff, 16, pmf); + } else { + if (romsize >= sms_offsets[0] + 0x200 + 16) + memcpy(buff, rom + sms_offsets[0] + 0x200, 16); + } + + if (strncmp("TMR SEGA", buff, 8) == 0) goto looks_like_sms; /* could parse further but don't bother */ goto extension_check; } - if (pm_seek(pmf, 0x100, SEEK_SET) == 0x100 && pm_read(buff, 16, pmf) == 16) { - /* PICO header? Almost always appropriately marked */ - buff[16] = '\0'; - if (strstr(buff, " PICO ")) - goto looks_like_pico; - /* MD header? Act as TMSS BIOS here */ - if (strncmp(buff, "SEGA", 4) == 0 || strncmp(buff, " SEG", 4) == 0) - goto looks_like_md; + /* fetch header info */ + memset(buff, '\0', 17); + if (!rom) { + if (pm_seek(pmf, 0x100, SEEK_SET) == 0x100) + pm_read(buff, 16, pmf); + } else { + if (romsize >= 0x100 + 16) + memcpy(buff, rom + 0x100, 16); } + /* PICO header? Almost always appropriately marked */ + if (strstr(buff, " PICO ")) + goto looks_like_pico; + /* MD header? Act as TMSS BIOS here */ + if (strncmp(buff, "SEGA", 4) == 0 || strncmp(buff, " SEG", 4) == 0) + goto looks_like_md; for (i = 0; i < ARRAY_SIZE(sms_offsets); i++) { - if (pm_seek(pmf, sms_offsets[i], SEEK_SET) != sms_offsets[i]) - continue; + if (!rom) { + if (pm_seek(pmf, sms_offsets[i], SEEK_SET) != sms_offsets[i]) + continue; + + if (pm_read(buff, 16, pmf) != 16) + continue; + } else { + if (romsize < sms_offsets[i] + 16) + continue; - if (pm_read(buff, 16, pmf) != 16) - continue; + memcpy(buff, rom + sms_offsets[i], 16); + } if (strncmp("TMR SEGA", buff, 8) == 0) goto looks_like_sms; @@ -103,20 +139,20 @@ static int detect_media(const char *fname) extension_check: /* probably some headerless thing. Maybe check the extension after all. */ for (i = 0; i < ARRAY_SIZE(md_exts); i++) - if (strcasecmp(pmf->ext, md_exts[i]) == 0) + if (strcasecmp(ext, md_exts[i]) == 0) goto looks_like_md; for (i = 0; i < ARRAY_SIZE(sms_exts); i++) - if (strcasecmp(pmf->ext, sms_exts[i]) == 0) + if (strcasecmp(ext, sms_exts[i]) == 0) goto looks_like_sms; for (i = 0; i < ARRAY_SIZE(pico_exts); i++) - if (strcasecmp(pmf->ext, pico_exts[i]) == 0) + if (strcasecmp(ext, pico_exts[i]) == 0) goto looks_like_pico; /* If everything else fails, make a guess on the reset vector */ d16 = (unsigned short *)(buff0 + 4); - if ((((d16[0] << 16) | d16[1]) & 0xffffff) >= pmf->size) { + if ((((d16[0] << 16) | d16[1]) & 0xffffff) >= romsize) { lprintf("bad MD reset vector, assuming SMS\n"); goto looks_like_sms; } @@ -215,6 +251,7 @@ int PicoCdCheck(const char *fname_in, int *pregion) } enum media_type_e PicoLoadMedia(const char *filename, + const unsigned char *rom, unsigned int romsize, const char *carthw_cfg_fname, const char *(*get_bios_filename)(int *region, const char *cd_fname), void (*do_region_override)(const char *media_filename)) @@ -222,13 +259,13 @@ enum media_type_e PicoLoadMedia(const char *filename, const char *rom_fname = filename; enum media_type_e media_type; enum cd_track_type cd_img_type = CT_UNKNOWN; + pm_file *rom_file = NULL; unsigned char *rom_data = NULL; unsigned int rom_size = 0; - pm_file *rom = NULL; int cd_region = 0; int ret; - media_type = detect_media(filename); + media_type = detect_media(filename, rom, romsize); if (media_type == PM_BAD_DETECT) goto out; @@ -267,14 +304,16 @@ enum media_type_e PicoLoadMedia(const char *filename, PicoIn.AHW = PAHW_PICO; } - rom = pm_open(rom_fname); - if (rom == NULL) { - lprintf("Failed to open ROM\n"); - media_type = PM_ERROR; - goto out; + if (!rom) { + rom_file = pm_open(rom_fname); + if (rom_file == NULL) { + lprintf("Failed to open ROM\n"); + media_type = PM_ERROR; + goto out; + } } - ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoIn.AHW & PAHW_SMS) ? 1 : 0); + ret = PicoCartLoad(rom_file, rom, romsize, &rom_data, &rom_size, (PicoIn.AHW & PAHW_SMS) ? 1 : 0); if (ret != 0) { if (ret == 2) lprintf("Out of memory\n"); else if (ret == 3) lprintf("Read failed\n"); @@ -314,10 +353,19 @@ enum media_type_e PicoLoadMedia(const char *filename, // simple test for GG. Do this here since m.hardware is nulled in Insert if ((PicoIn.AHW & PAHW_SMS) && !PicoIn.hwSelect) { - if (!strcmp(rom->ext,"gg")) { + const char *ext = NULL; + if (rom_file && rom_file->ext && (*rom_file->ext != '\0')) { + ext = rom_file->ext; + } + else if ((ext = strrchr(filename, '.'))) { + if (*(++ext) == '\0') { + ext = NULL; + } + } + if (ext && !strcmp(ext,"gg") && !PicoIn.hwSelect) { Pico.m.hardware |= PMS_HW_GG; lprintf("detected GG ROM\n"); - } else if (!strcmp(rom->ext,"sg")) { + } else if (ext && !strcmp(ext,"sg")) { Pico.m.hardware |= PMS_HW_SG; lprintf("detected SG-1000 ROM\n"); } else @@ -340,8 +388,8 @@ enum media_type_e PicoLoadMedia(const char *filename, PicoSetInputDevice(0, PICO_INPUT_PAD_6BTN); out: - if (rom) - pm_close(rom); + if (rom_file) + pm_close(rom_file); if (rom_data) free(rom_data); return media_type; diff --git a/pico/pico.h b/pico/pico.h index 1baf4438..9b8df316 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -188,7 +188,8 @@ size_t pm_read(void *ptr, size_t bytes, pm_file *stream); size_t pm_read_audio(void *ptr, size_t bytes, pm_file *stream); int pm_seek(pm_file *stream, long offset, int whence); int pm_close(pm_file *fp); -int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms); +int PicoCartLoad(pm_file *f, const unsigned char *rom, unsigned int romsize, + unsigned char **prom, unsigned int *psize, int is_sms); int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_cfg); void PicoCartUnload(void); extern void (*PicoCartLoadProgressCB)(int percent); @@ -299,6 +300,7 @@ typedef struct enum media_type_e PicoLoadMedia(const char *filename, + const unsigned char *rom, unsigned int romsize, const char *carthw_cfg_fname, const char *(*get_bios_filename)(int *region, const char *cd_fname), void (*do_region_override)(const char *media_filename)); diff --git a/platform/common/emu.c b/platform/common/emu.c index 47581c00..f371f5bc 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -451,7 +451,7 @@ int emu_reload_rom(const char *rom_fname_in) emu_make_path(carthw_path, "carthw.cfg", sizeof(carthw_path)); - media_type = PicoLoadMedia(rom_fname, carthw_path, + media_type = PicoLoadMedia(rom_fname, NULL, 0, carthw_path, find_bios, do_region_override); switch (media_type) { diff --git a/platform/common/mp3_drmp3.c b/platform/common/mp3_drmp3.c index 54d3496d..c22c6ac4 100644 --- a/platform/common/mp3_drmp3.c +++ b/platform/common/mp3_drmp3.c @@ -9,6 +9,10 @@ #include #include +// Ugh, drmp3 tries to use wfopen on windows, which breaks libretro VFS... +#define __acrt_iob_func __acrt_iob_func2 +#define _wfopen_s(p,m) NULL +#define _wfopen(p,m) NULL #define DR_MP3_IMPLEMENTATION #include "dr_libs/dr_mp3.h" #include "mp3.h" diff --git a/platform/libretro/libretro-common/include/libretro.h b/platform/libretro/libretro-common/include/libretro.h index 2887e5e8..72e64257 100644 --- a/platform/libretro/libretro-common/include/libretro.h +++ b/platform/libretro/libretro-common/include/libretro.h @@ -69,7 +69,7 @@ extern "C" { # endif # endif # else -# if defined(__GNUC__) && __GNUC__ >= 4 +# if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__PS3__) # define RETRO_API RETRO_CALLCONV __attribute__((__visibility__("default"))) # else # define RETRO_API RETRO_CALLCONV diff --git a/platform/libretro/libretro-common/include/retro_assert.h b/platform/libretro/libretro-common/include/retro_assert.h new file mode 100644 index 00000000..79dbb32e --- /dev/null +++ b/platform/libretro/libretro-common/include/retro_assert.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (retro_assert.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __RETRO_ASSERT_H +#define __RETRO_ASSERT_H + +#include + +#ifdef RARCH_INTERNAL +#include +#define retro_assert(cond) ((void)( (cond) || (printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__), abort(), 0) )) +#else +#define retro_assert(cond) assert(cond) +#endif + +#endif diff --git a/platform/libretro/libretro-common/include/retro_miscellaneous.h b/platform/libretro/libretro-common/include/retro_miscellaneous.h index bd71c916..7fdbbf06 100644 --- a/platform/libretro/libretro-common/include/retro_miscellaneous.h +++ b/platform/libretro/libretro-common/include/retro_miscellaneous.h @@ -75,8 +75,10 @@ static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count) } #ifndef PATH_MAX_LENGTH -#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__) +#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS) #define PATH_MAX_LENGTH 512 +#elif defined(__PS3__) +#define PATH_MAX_LENGTH 1024 #else #define PATH_MAX_LENGTH 4096 #endif diff --git a/platform/libretro/libretro-common/include/time/rtime.h b/platform/libretro/libretro-common/include/time/rtime.h new file mode 100644 index 00000000..7629c1ea --- /dev/null +++ b/platform/libretro/libretro-common/include/time/rtime.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (rtime.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_RTIME_H__ +#define __LIBRETRO_SDK_RTIME_H__ + +#include + +#include +#include +#include + +RETRO_BEGIN_DECLS + +/* TODO/FIXME: Move all generic time handling functions + * to this file */ + +/* Must be called before using rtime_localtime() */ +void rtime_init(void); + +/* Must be called upon program termination */ +void rtime_deinit(void); + +/* Thread-safe wrapper for localtime() */ +struct tm *rtime_localtime(const time_t *timep, struct tm *result); + +RETRO_END_DECLS + +#endif diff --git a/platform/libretro/libretro-common/time/rtime.c b/platform/libretro/libretro-common/time/rtime.c new file mode 100644 index 00000000..d66c228f --- /dev/null +++ b/platform/libretro/libretro-common/time/rtime.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (rtime.c). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_THREADS +#include +#include +#include +#endif + +#include +#include