diff --git a/Makefile.common b/Makefile.common index 9876d85..1aa3df5 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1,68 +1,77 @@ LIBRETRO_COMM_DIR := $(CORE_DIR)/drivers/libretro/libretro-common -INCFLAGS := -I$(CORE_DIR)/drivers/libretro -I$(LIBRETRO_COMM_DIR)/include -I$(CORE_DIR) -I$(CORE_DIR)/input -I$(CORE_DIR)/boards -COREDEFINES = -D__LIBRETRO__ -DSOUND_QUALITY=0 -DPATH_MAX=1024 -DFCEU_VERSION_NUMERIC=9813 -DFRONTEND_SUPPORTS_RGB565 -ifeq ($(PSS_STYLE),2) -COREDEFINES += -DPSS_STYLE=2 -else -COREDEFINES += -DPSS_STYLE=1 +INCFLAGS := \ + -I$(CORE_DIR)/drivers/libretro \ + -I$(LIBRETRO_COMM_DIR)/include \ + -I$(CORE_DIR) \ + -I$(CORE_DIR)/input \ + -I$(CORE_DIR)/boards + +ifneq (,$(findstring msvc2003,$(platform))) + INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc endif -ifeq ($(TUP_CWD),) -FCEU_SRC_DIRS := $(CORE_DIR)/boards $(CORE_DIR)/input $(CORE_DIR)/mappers -SOURCES_C := $(foreach dir,$(FCEU_SRC_DIRS),$(wildcard $(dir)/*.c)) -else -SOURCES_C = $(CORE_DIR)/boards/*.c $(CORE_DIR)/input/*.c -endif +COREDEFINES = \ + -D__LIBRETRO__ \ + -DPATH_MAX=1024 \ + -DFCEU_VERSION_NUMERIC=9813 \ + -DFRONTEND_SUPPORTS_RGB565 + +FCEU_SRC_DIRS := \ + $(CORE_DIR)/boards \ + $(CORE_DIR)/input + +SOURCES_C := $(foreach dir,$(FCEU_SRC_DIRS),$(wildcard $(dir)/*.c)) ifeq ($(HAVE_NTSC),1) -COREDEFINES += -DHAVE_NTSC_FILTER -I$(CORE_DIR)/ntsc -SOURCES_C += $(CORE_DIR)/ntsc/nes_ntsc.c -endif - -ifeq ($(HAVE_GRIFFIN),1) -SOURCES_C += $(CORE_DIR)/drivers/libretro/griffin.c -else -SOURCES_C += \ - $(CORE_DIR)/drivers/libretro/libretro.c \ - $(CORE_DIR)/cart.c \ - $(CORE_DIR)/cheat.c \ - $(CORE_DIR)/crc32.c \ - $(CORE_DIR)/fceu-endian.c \ - $(CORE_DIR)/fceu-memory.c \ - $(CORE_DIR)/misc.c \ - $(CORE_DIR)/fceu.c \ - $(CORE_DIR)/fds.c \ - $(CORE_DIR)/fds_apu.c \ - $(CORE_DIR)/file.c \ - $(CORE_DIR)/filter.c \ - $(CORE_DIR)/general.c \ - $(CORE_DIR)/input.c \ - $(CORE_DIR)/md5.c \ - $(CORE_DIR)/nsf.c \ - $(CORE_DIR)/palette.c \ - $(CORE_DIR)/ppu.c \ - $(CORE_DIR)/sound.c \ - $(CORE_DIR)/state.c \ - $(CORE_DIR)/video.c \ - $(CORE_DIR)/vsuni.c - -ifeq ($(STATIC_LINKING),1) -else -SOURCES_C += $(CORE_DIR)/drivers/libretro/libretro-common/streams/memory_stream.c \ - $(CORE_DIR)/drivers/libretro/libretro-common/compat/compat_snprintf.c \ - $(CORE_DIR)/drivers/libretro/libretro-common/string/stdstring.c \ - $(CORE_DIR)/drivers/libretro/libretro-common/encodings/encoding_utf.c \ - $(CORE_DIR)/drivers/libretro/libretro-common/compat/compat_strl.c \ - $(CORE_DIR)/drivers/libretro/libretro-common/compat/fopen_utf8.c -endif - -ifeq ($(DEBUG),1) -SOURCES_C += $(CORE_DIR)/debug.c -endif + COREDEFINES += \ + -DHAVE_NTSC_FILTER \ + -I$(CORE_DIR)/ntsc + SOURCES_C += $(CORE_DIR)/ntsc/nes_ntsc.c endif SOURCES_C += \ - $(CORE_DIR)/ines.c \ - $(CORE_DIR)/unif.c $(CORE_DIR)/x6502.c \ - $(CORE_DIR)/drivers/libretro/libretro_dipswitch.c + $(CORE_DIR)/drivers/libretro/libretro.c \ + $(CORE_DIR)/drivers/libretro/libretro_dipswitch.c \ + $(CORE_DIR)/cart.c \ + $(CORE_DIR)/cheat.c \ + $(CORE_DIR)/crc32.c \ + $(CORE_DIR)/fceu-endian.c \ + $(CORE_DIR)/fceu-memory.c \ + $(CORE_DIR)/misc.c \ + $(CORE_DIR)/fceu.c \ + $(CORE_DIR)/fds.c \ + $(CORE_DIR)/fds_apu.c \ + $(CORE_DIR)/file.c \ + $(CORE_DIR)/filter.c \ + $(CORE_DIR)/general.c \ + $(CORE_DIR)/input.c \ + $(CORE_DIR)/md5.c \ + $(CORE_DIR)/nsf.c \ + $(CORE_DIR)/palette.c \ + $(CORE_DIR)/ppu.c \ + $(CORE_DIR)/sound.c \ + $(CORE_DIR)/state.c \ + $(CORE_DIR)/video.c \ + $(CORE_DIR)/vsuni.c \ + $(CORE_DIR)/ines.c \ + $(CORE_DIR)/unif.c \ + $(CORE_DIR)/x6502.c + +ifneq ($(STATIC_LINKING), 1) + SOURCES_C += \ + $(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \ + $(LIBRETRO_COMM_DIR)/compat/compat_snprintf.c \ + $(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \ + $(LIBRETRO_COMM_DIR)/compat/compat_strl.c \ + $(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \ + $(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \ + $(LIBRETRO_COMM_DIR)/file/file_path.c \ + $(LIBRETRO_COMM_DIR)/file/file_path_io.c \ + $(LIBRETRO_COMM_DIR)/streams/file_stream.c \ + $(LIBRETRO_COMM_DIR)/streams/file_stream_transforms.c \ + $(LIBRETRO_COMM_DIR)/streams/memory_stream.c \ + $(LIBRETRO_COMM_DIR)/string/stdstring.c \ + $(LIBRETRO_COMM_DIR)/time/rtime.c \ + $(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c +endif diff --git a/Makefile.libretro b/Makefile.libretro index d4e86bf..ce0b618 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -1,7 +1,5 @@ DEBUG=0 -PSS_STYLE=1 EXTERNAL_ZLIB=0 -HAVE_GRIFFIN=1 STATIC_LINKING=0 ENDIANNESS_DEFINES= SIGNED_CHAR=0 @@ -161,7 +159,7 @@ else ifeq ($(platform), ps2) TARGET := $(TARGET_NAME)_libretro_$(platform).a CC = mips64r5900el-ps2-elf-gcc$(EXE_EXT) AR = mips64r5900el-ps2-elf-ar$(EXE_EXT) - FCEU_DEFINES := -DPATH_MAX=1024 -DINLINE=inline -DPSS_STYLE=1 -DFCEU_VERSION_NUMERIC=9813 -DHAVE_ASPRINTF + FCEU_DEFINES := -DPATH_MAX=1024 -DINLINE=inline -DFCEU_VERSION_NUMERIC=9813 -DHAVE_ASPRINTF ENDIANNESS_DEFINES := -DLSB_FIRST -DLOCAL_LE=1 PLATFORM_DEFINES := -DPS2 -D_EE -G0 -DFRONTEND_SUPPORTS_ABGR1555 -DRENDER_GSKIT_PS2 PLATFORM_DEFINES += -I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(PS2DEV)/gsKit/include @@ -540,7 +538,6 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) export INCLUDE := $(INCLUDE);$(WindowsSDKSharedIncludeDir);$(WindowsSDKUCRTIncludeDir);$(WindowsSDKUMIncludeDir) export LIB := $(LIB);$(WindowsSDKUCRTLibDir);$(WindowsSDKUMLibDir) TARGET := $(TARGET_NAME)_libretro.dll - PSS_STYLE :=2 LDFLAGS += -DLL # Windows MSVC 2010 x64 @@ -564,7 +561,6 @@ INCFLAGS_PLATFORM = -I"$(WindowsSDKIncludeDir)" export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKGlIncludeDir) export LIB := $(LIB);$(WindowsSDKLibDir) TARGET := $(TARGET_NAME)_libretro.dll -PSS_STYLE :=2 LDFLAGS += -DLL # Windows MSVC 2010 x86 @@ -588,7 +584,6 @@ INCFLAGS_PLATFORM = -I"$(WindowsSDKIncludeDir)" export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKGlIncludeDir) export LIB := $(LIB);$(WindowsSDKLibDir) TARGET := $(TARGET_NAME)_libretro.dll -PSS_STYLE :=2 LDFLAGS += -DLL # Windows MSVC 2003 Xbox 1 @@ -602,7 +597,6 @@ export INCLUDE := $(XDK)\xbox\include export LIB := $(XDK)\xbox\lib PATH := $(call unixcygpath,$(XDK)/xbox/bin/vc71):$(PATH) -PSS_STYLE :=2 CFLAGS += -D_XBOX -D_XBOX1 CXXFLAGS += -D_XBOX -D_XBOX1 STATIC_LINKING=1 @@ -618,7 +612,6 @@ export INCLUDE := $(XEDK)/include/xbox export LIB := $(XEDK)/lib/xbox PATH := $(call unixcygpath,$(XEDK)/bin/win32):$(PATH) -PSS_STYLE :=2 CFLAGS += -D_XBOX -D_XBOX360 CXXFLAGS += -D_XBOX -D_XBOX360 ENDIANNESS_DEFINES += -DMSB_FIRST @@ -640,7 +633,6 @@ WindowsSdkDir := $(INETSDK) export INCLUDE := $(INCLUDE);$(INETSDK)/Include export LIB := $(LIB);$(WindowsSdkDir);$(INETSDK)/Lib TARGET := $(TARGET_NAME)_libretro.dll -PSS_STYLE :=2 LDFLAGS += -DLL CFLAGS += -D_CRT_SECURE_NO_DEPRECATE @@ -667,7 +659,6 @@ WindowsSDKLibDir := $(shell cygpath -w "$(WindowsSdkDir)\Lib") export INCLUDE := $(INCLUDE);$(WindowsSDKIncludeDir);$(WindowsSDKAtlIncludeDir);$(WindowsSDKCrtIncludeDir);$(WindowsSDKGlIncludeDir);$(WindowsSDKMfcIncludeDir);libretro-common/include/compat/msvc export LIB := $(LIB);$(WindowsSDKLibDir) TARGET := $(TARGET_NAME)_libretro.dll -PSS_STYLE :=2 LDFLAGS += -DLL CFLAGS += -D_CRT_SECURE_NO_DEPRECATE @@ -687,7 +678,6 @@ WindowsSdkDir := $(INETSDK) export INCLUDE := $(INCLUDE);$(INETSDK)/Include export LIB := $(LIB);$(WindowsSdkDir);$(INETSDK)/Lib TARGET := $(TARGET_NAME)_libretro.dll -PSS_STYLE :=2 LDFLAGS += -DLL CFLAGS += -D_CRT_SECURE_NO_DEPRECATE @@ -696,7 +686,6 @@ else TARGET := $(TARGET_NAME)_libretro.dll CC ?= gcc SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=src/drivers/libretro/link.T - PSS_STYLE :=2 endif ifeq ($(DEBUG), 1) @@ -751,8 +740,6 @@ ifneq (,$(findstring msvc,$(platform))) COREDEFINES += -DINLINE=_inline endif -CFLAGS += -DWANT_GRIFFIN - OBJECTS := $(SOURCES_C:.c=.o) OBJECTS += $(RETROARCH_OBJECTS) diff --git a/src/boards/copyfami_hwi.c b/src/boards/copyfami_hwi.c index 7660c61..fde8fa4 100644 --- a/src/boards/copyfami_hwi.c +++ b/src/boards/copyfami_hwi.c @@ -26,6 +26,8 @@ #define NO_CACHE #define NO_RAM +#include + #include "__serial.h" #include "mapinc.h" @@ -167,28 +169,32 @@ static void GetStatus(SYNC_STATE *state) { } static int32 FetchNewCHRBank(int32 slot) { - FILE *ofile; + RFILE *ofile; char name[256]; int32 bank = chr_data.count++; CHR1KGetCmd[1] = slot << 2; SENDGET(CHR1KGetCmd, chr_data.buf[bank * 1024], 1024); sprintf(name, "%04x.chr", bank); - ofile = FCEUD_UTF8fopen(name, "wb"); - fwrite((void*)&chr_data.buf[bank * 1024], 1, 1024, ofile); - fclose(ofile); + ofile = filestream_open(name, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + filestream_write(ofile, (void*)&chr_data.buf[bank * 1024], 1024); + filestream_close(ofile); return bank; } static int32 FetchNewPRGBank(int32 slot) { - FILE *ofile; + RFILE *ofile; char name[256]; int32 bank = prg_data.count++; PRG8KGetCmd[1] = 0x80 + (slot << 5); SENDGET(PRG8KGetCmd, prg_data.buf[bank * 8192], 8192); sprintf(name, "%04x.prg", bank); - ofile = FCEUD_UTF8fopen(name, "wb"); - fwrite((void*)&prg_data.buf[bank * 8192], 1, 8192, ofile); - fclose(ofile); + ofile = filestream_open(name, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + filestream_write(ofile, (void*)&prg_data.buf[bank * 8192], 8192); + filestream_close(ofile); return bank; } diff --git a/src/cart.c b/src/cart.c index 911cb0c..345c419 100644 --- a/src/cart.c +++ b/src/cart.c @@ -22,6 +22,9 @@ #include #include +#include +#include + #include "fceu-types.h" #include "fceu.h" #include "ppu.h" @@ -340,7 +343,7 @@ void FixGenieMap(void); /* Called when a game(file) is opened successfully. */ void FCEU_OpenGenie(void) { - FILE *fp; + RFILE *fp = NULL; int x; if (!GENIEROM) { @@ -349,33 +352,38 @@ void FCEU_OpenGenie(void) { if (!(GENIEROM = (uint8*)FCEU_malloc(4096 + 1024))) return; fn = FCEU_MakeFName(FCEUMKF_GGROM, 0, 0); - fp = FCEUD_UTF8fopen(fn, "rb"); + + if (!string_is_empty(fn)) + fp = filestream_open(fn, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + if (!fp) { FCEU_PrintError("Error opening Game Genie ROM image!"); free(GENIEROM); GENIEROM = 0; return; } - if (fread(GENIEROM, 1, 16, fp) != 16) { + if (filestream_read(fp, GENIEROM, 16) != 16) { grerr: FCEU_PrintError("Error reading from Game Genie ROM image!"); free(GENIEROM); GENIEROM = 0; - fclose(fp); + filestream_close(fp); return; } if (GENIEROM[0] == 0x4E) { /* iNES ROM image */ - if (fread(GENIEROM, 1, 4096, fp) != 4096) + if (filestream_read(fp, GENIEROM, 4096) != 4096) goto grerr; - if (fseek(fp, 16384 - 4096, SEEK_CUR)) + if (filestream_seek(fp, 16384 - 4096, RETRO_VFS_SEEK_POSITION_CURRENT)) goto grerr; - if (fread(GENIEROM + 4096, 1, 256, fp) != 256) + if (filestream_read(fp, GENIEROM + 4096, 256) != 256) goto grerr; } else { - if (fread(GENIEROM + 16, 1, 4352 - 16, fp) != (4352 - 16)) + if (filestream_read(fp, GENIEROM + 16, 4352 - 16) != (4352 - 16)) goto grerr; } - fclose(fp); + filestream_close(fp); /* Workaround for the FCE Ultra CHR page size only being 1KB */ for (x = 0; x < 4; x++) diff --git a/src/cheat.c b/src/cheat.c index 0e82364..66af7b6 100644 --- a/src/cheat.c +++ b/src/cheat.c @@ -162,13 +162,13 @@ static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int st return(1); } -void FCEU_LoadGameCheats(FILE *override) +void FCEU_LoadGameCheats(void) { numsubcheats = savecheats = 0; RebuildSubCheats(); } -void FCEU_FlushGameCheats(FILE *override, int nosave) { +void FCEU_FlushGameCheats(void) { if (CheatComp) { free(CheatComp); diff --git a/src/cheat.h b/src/cheat.h index 9081c96..3052f54 100644 --- a/src/cheat.h +++ b/src/cheat.h @@ -6,8 +6,8 @@ extern uint8 *MMapPtrs[64]; void FCEU_CheatResetRAM(void); void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p); -void FCEU_LoadGameCheats(FILE *override); -void FCEU_FlushGameCheats(FILE *override, int nosave); +void FCEU_LoadGameCheats(void); +void FCEU_FlushGameCheats(void); void FCEU_ApplyPeriodicCheats(void); void FCEU_PowerCheats(void); diff --git a/src/debug.c b/src/debug.c index 53449d6..bc48739 100644 --- a/src/debug.c +++ b/src/debug.c @@ -22,38 +22,44 @@ #include #include +#include + #include "fceu-types.h" #include "x6502.h" #include "fceu.h" #include "debug.h" #include "cart.h" - void FCEUI_DumpVid(const char *fname, uint32 start, uint32 end) { - FILE *fp = FCEUD_UTF8fopen(fname, "wb"); + RFILE *fp = filestream_open(fname, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); fceuindbg = 1; start &= 0x3FFF; end &= 0x3FFF; for (; start <= end; start++) - fputc(VPage[start >> 10][start], fp); - fclose(fp); + filestream_putc(fp, VPage[start >> 10][start]); + filestream_close(fp); fceuindbg = 0; } void FCEUI_DumpMem(const char *fname, uint32 start, uint32 end) { - FILE *fp = FCEUD_UTF8fopen(fname, "wb"); + RFILE *fp = filestream_open(fname, + RETRO_VFS_FILE_ACCESS_WRITE, + RETRO_VFS_FILE_ACCESS_HINT_NONE); fceuindbg = 1; for (; start <= end; start++) - fputc(ARead[start](start), fp); - fclose(fp); + filestream_putc(fp, ARead[start](start)); + filestream_close(fp); fceuindbg = 0; } void FCEUI_LoadMem(const char *fname, uint32 start, int hl) { int t; - - FILE *fp = FCEUD_UTF8fopen(fname, "rb"); - while ((t = fgetc(fp)) >= 0) { + RFILE *fp = filestream_open(fname, + RETRO_VFS_FILE_ACCESS_READ, + RETRO_VFS_FILE_ACCESS_HINT_NONE); + while ((t = filestream_getc(fp)) >= 0) { if (start > 0xFFFF) break; if (hl) { extern uint8 *Page[32]; @@ -63,7 +69,7 @@ void FCEUI_LoadMem(const char *fname, uint32 start, int hl) { BWrite[start](start, t); start++; } - fclose(fp); + filestream_close(fp); } #ifdef FCEUDEF_DEBUGGER diff --git a/src/driver.h b/src/driver.h index 6c83d97..e16476e 100644 --- a/src/driver.h +++ b/src/driver.h @@ -27,8 +27,6 @@ extern "C" { #define FCEUNPCMD_LOADCHEATS 0x82 #define FCEUNPCMD_TEXT 0x90 -FILE *FCEUD_UTF8fopen(const char *fn, const char *mode); - /* This makes me feel dirty for some reason. */ void FCEU_printf(char *format, ...); #define FCEUI_printf FCEU_printf @@ -101,7 +99,7 @@ void FCEUI_DisableSpriteLimitation(int a); /* -1 = no change, 0 = show, 1 = hide, 2 = internal toggle */ void FCEUI_SetRenderDisable(int sprites, int bg); -FCEUGI *FCEUI_LoadGame(const char *name, uint8_t *buf, size_t bufsize); +FCEUGI *FCEUI_LoadGame(const char *name, const uint8_t *buf, size_t bufsize); #ifdef COPYFAMI /* Fake UNIF board to start new CFHI instance */ @@ -140,12 +138,9 @@ void FCEUI_FrameSkip(int x); /* First and last scanlines to render, for ntsc and pal emulation. */ void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); -/* Sets the base directory(save states, snapshots, etc. are saved in directories - below this directory. */ -void FCEUI_SetBaseDirectory(char *dir); - -void FCEUI_SetSaveDirectory(char *sav_dir); - +/* Sets the base directory (bios and palette files are saved + in this directory. */ +void FCEUI_SetBaseDirectory(const char *dir); /* Tells FCE Ultra to copy the palette data pointed to by pal and use it. Data pointed to by pal needs to be 64*3 bytes in length. diff --git a/src/drivers/libretro/griffin.c b/src/drivers/libretro/griffin.c deleted file mode 100644 index 9a215eb..0000000 --- a/src/drivers/libretro/griffin.c +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef WANT_GRIFFIN - -#include "drivers/libretro/libretro.c" - -#ifndef STATIC_LINKING -#include "drivers/libretro/libretro-common/streams/memory_stream.c" -#include "drivers/libretro/libretro-common/string/stdstring.c" -#include "drivers/libretro/libretro-common/encodings/encoding_utf.c" -#include "drivers/libretro/libretro-common/compat/compat_strl.c" -#include "drivers/libretro/libretro-common/compat/fopen_utf8.c" -#endif - -#include "cart.c" -#include "cheat.c" -#include "crc32.c" - -#ifdef DEBUG -#include "debug.c" -#endif -#include "fceu-endian.c" -#include "fceu-memory.c" -#include "misc.c" -#include "fceu.c" -#include "fds.c" -#include "fds_apu.c" -#include "file.c" -#include "filter.c" -#include "general.c" -#include "input.c" -#include "md5.c" -#include "nsf.c" -#include "palette.c" -#include "ppu.c" -#include "sound.c" -#include "state.c" -#include "video.c" -#include "vsuni.c" - -/* #include "x6502.c" */ -/* #include "ines.c" */ -/* #include "unif.c" */ - -#endif diff --git a/src/drivers/libretro/libretro-common/compat/compat_posix_string.c b/src/drivers/libretro/libretro-common/compat/compat_posix_string.c new file mode 100644 index 0000000..6a2f07e --- /dev/null +++ b/src/drivers/libretro/libretro-common/compat/compat_posix_string.c @@ -0,0 +1,104 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (compat_posix_string.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. + */ + +#include + +#include + +#ifdef _WIN32 + +#undef strcasecmp +#undef strdup +#undef isblank +#undef strtok_r +#include +#include +#include +#include + +#include + +int retro_strcasecmp__(const char *a, const char *b) +{ + while (*a && *b) + { + int a_ = tolower(*a); + int b_ = tolower(*b); + + if (a_ != b_) + return a_ - b_; + + a++; + b++; + } + + return tolower(*a) - tolower(*b); +} + +char *retro_strdup__(const char *orig) +{ + size_t len = strlen(orig) + 1; + char *ret = (char*)malloc(len); + if (!ret) + return NULL; + + strlcpy(ret, orig, len); + return ret; +} + +int retro_isblank__(int c) +{ + return (c == ' ') || (c == '\t'); +} + +char *retro_strtok_r__(char *str, const char *delim, char **saveptr) +{ + char *first = NULL; + if (!saveptr || !delim) + return NULL; + + if (str) + *saveptr = str; + + do + { + char *ptr = NULL; + first = *saveptr; + while (*first && strchr(delim, *first)) + *first++ = '\0'; + + if (*first == '\0') + return NULL; + + ptr = first + 1; + + while (*ptr && !strchr(delim, *ptr)) + ptr++; + + *saveptr = ptr + (*ptr ? 1 : 0); + *ptr = '\0'; + } while (strlen(first) == 0); + + return first; +} + +#endif diff --git a/src/drivers/libretro/libretro-common/compat/compat_strcasestr.c b/src/drivers/libretro/libretro-common/compat/compat_strcasestr.c new file mode 100644 index 0000000..4129dab --- /dev/null +++ b/src/drivers/libretro/libretro-common/compat/compat_strcasestr.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (compat_strcasestr.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. + */ + +#include + +#include + +/* Pretty much strncasecmp. */ +static int casencmp(const char *a, const char *b, size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + { + int a_lower = tolower(a[i]); + int b_lower = tolower(b[i]); + if (a_lower != b_lower) + return a_lower - b_lower; + } + + return 0; +} + +char *strcasestr_retro__(const char *haystack, const char *needle) +{ + size_t i, search_off; + size_t hay_len = strlen(haystack); + size_t needle_len = strlen(needle); + + if (needle_len > hay_len) + return NULL; + + search_off = hay_len - needle_len; + for (i = 0; i <= search_off; i++) + if (!casencmp(haystack + i, needle, needle_len)) + return (char*)haystack + i; + + return NULL; +} diff --git a/src/drivers/libretro/libretro-common/file/file_path.c b/src/drivers/libretro/libretro-common/file/file_path.c new file mode 100644 index 0000000..fc11270 --- /dev/null +++ b/src/drivers/libretro/libretro-common/file/file_path.c @@ -0,0 +1,1381 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (file_path.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. + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include