Merge pull request #465 from jdgleaver/vfs-support

Replace direct file access with VFS routines
This commit is contained in:
Autechre
2021-10-20 18:15:10 +02:00
committed by GitHub
44 changed files with 5853 additions and 575 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -26,6 +26,8 @@
#define NO_CACHE
#define NO_RAM
#include <streams/file_stream.h>
#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;
}

View File

@@ -22,6 +22,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <string/stdstring.h>
#include <streams/file_stream.h>
#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++)

View File

@@ -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);

View File

@@ -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);

View File

@@ -22,38 +22,44 @@
#include <string.h>
#include <stdlib.h>
#include <streams/file_stream.h>
#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

View File

@@ -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.

View File

@@ -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

View File

@@ -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 <ctype.h>
#include <compat/posix_string.h>
#ifdef _WIN32
#undef strcasecmp
#undef strdup
#undef isblank
#undef strtok_r
#include <ctype.h>
#include <stdlib.h>
#include <stddef.h>
#include <compat/strl.h>
#include <string.h>
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

View File

@@ -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 <ctype.h>
#include <compat/strcasestr.h>
/* 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;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_path_io.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <boolean.h>
#include <file/file_path.h>
#include <retro_assert.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <retro_miscellaneous.h>
#include <string/stdstring.h>
#define VFS_FRONTEND
#include <vfs/vfs_implementation.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h> /* stat() is defined here */
#endif
/* TODO/FIXME - globals */
static retro_vfs_stat_t path_stat_cb = retro_vfs_stat_impl;
static retro_vfs_mkdir_t path_mkdir_cb = retro_vfs_mkdir_impl;
void path_vfs_init(const struct retro_vfs_interface_info* vfs_info)
{
const struct retro_vfs_interface*
vfs_iface = vfs_info->iface;
path_stat_cb = retro_vfs_stat_impl;
path_mkdir_cb = retro_vfs_mkdir_impl;
if (vfs_info->required_interface_version < PATH_REQUIRED_VFS_VERSION || !vfs_iface)
return;
path_stat_cb = vfs_iface->stat;
path_mkdir_cb = vfs_iface->mkdir;
}
int path_stat(const char *path)
{
return path_stat_cb(path, NULL);
}
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path)
{
return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_DIRECTORY) != 0;
}
bool path_is_character_special(const char *path)
{
return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_CHARACTER_SPECIAL) != 0;
}
bool path_is_valid(const char *path)
{
return (path_stat_cb(path, NULL) & RETRO_VFS_STAT_IS_VALID) != 0;
}
int32_t path_get_size(const char *path)
{
int32_t filesize = 0;
if (path_stat_cb(path, &filesize) != 0)
return filesize;
return -1;
}
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir)
{
bool norecurse = false;
char *basedir = NULL;
if (!(dir && *dir))
return false;
/* Use heap. Real chance of stack
* overflow if we recurse too hard. */
basedir = strdup(dir);
if (!basedir)
return false;
path_parent_dir(basedir);
if (!*basedir || !strcmp(basedir, dir))
{
free(basedir);
return false;
}
if ( path_is_directory(basedir)
|| path_mkdir(basedir))
norecurse = true;
free(basedir);
if (norecurse)
{
int ret = path_mkdir_cb(dir);
/* Don't treat this as an error. */
if (ret == -2 && path_is_directory(dir))
return true;
else if (ret == 0)
return true;
}
return false;
}

View File

@@ -1,7 +1,7 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (utf.h).
* The following license statement only applies to this file (posix_string.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
@@ -20,44 +20,41 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_ENCODINGS_WIN32_H
#define _LIBRETRO_ENCODINGS_WIN32_H
#ifndef __LIBRETRO_SDK_COMPAT_POSIX_STRING_H
#define __LIBRETRO_SDK_COMPAT_POSIX_STRING_H
#include <retro_common_api.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
RETRO_BEGIN_DECLS
#ifndef _XBOX
#ifdef _WIN32
/*#define UNICODE
#include <tchar.h>
#include <wchar.h>*/
#undef strtok_r
#define strtok_r(str, delim, saveptr) retro_strtok_r__(str, delim, saveptr)
#ifdef __cplusplus
extern "C" {
char *strtok_r(char *str, const char *delim, char **saveptr);
#endif
#include <encodings/utf.h>
#ifdef _MSC_VER
#undef strcasecmp
#undef strdup
#define strcasecmp(a, b) retro_strcasecmp__(a, b)
#define strdup(orig) retro_strdup__(orig)
int strcasecmp(const char *a, const char *b);
char *strdup(const char *orig);
#ifdef __cplusplus
}
/* isblank is available since MSVC 2013 */
#if _MSC_VER < 1800
#undef isblank
#define isblank(c) retro_isblank__(c)
int isblank(int c);
#endif
#endif
#endif
#ifdef UNICODE
#define CHAR_TO_WCHAR_ALLOC(s, ws) \
size_t ws##_size = (NULL != s && s[0] ? strlen(s) : 0) + 1; \
wchar_t *ws = (wchar_t*)calloc(ws##_size, 2); \
if (NULL != s && s[0]) \
MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, ws##_size / sizeof(wchar_t));
#define WCHAR_TO_CHAR_ALLOC(ws, s) \
size_t s##_size = ((NULL != ws && ws[0] ? wcslen((const wchar_t*)ws) : 0) / 2) + 1; \
char *s = (char*)calloc(s##_size, 1); \
if (NULL != ws && ws[0]) \
utf16_to_char_string((const uint16_t*)ws, s, s##_size);
#else
#define CHAR_TO_WCHAR_ALLOC(s, ws) char *ws = (NULL != s && s[0] ? strdup(s) : NULL);
#define WCHAR_TO_CHAR_ALLOC(ws, s) char *s = (NULL != ws && ws[0] ? strdup(ws) : NULL);
#endif
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,48 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (strcasestr.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_COMPAT_STRCASESTR_H
#define __LIBRETRO_SDK_COMPAT_STRCASESTR_H
#include <string.h>
#if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H)
#include "../../../config.h"
#endif
#ifndef HAVE_STRCASESTR
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
/* Avoid possible naming collisions during link
* since we prefer to use the actual name. */
#define strcasestr(haystack, needle) strcasestr_retro__(haystack, needle)
char *strcasestr(const char *haystack, const char *needle);
RETRO_END_DECLS
#endif
#endif

View File

@@ -1,48 +0,0 @@
#ifndef _LIBRETRO_ENCODINGS_BASE64_H
#define _LIBRETRO_ENCODINGS_BASE64_H
#include <stdint.h>
#include <stddef.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
const static char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* maps A=>0,B=>1.. */
const static unsigned char unb64[]={
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 0, 0,
0, 0, 0, 0, 0, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 0, 0, 0, 0, 0, 0, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
}; /* This array has 256 elements */
char* base64(const void* binaryData, int len, int *flen);
unsigned char* unbase64(const char* ascii, int len, int *flen);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,538 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_path.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_FILE_PATH_H
#define __LIBRETRO_SDK_FILE_PATH_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <libretro.h>
#include <retro_common_api.h>
#include <boolean.h>
RETRO_BEGIN_DECLS
#define PATH_REQUIRED_VFS_VERSION 3
void path_vfs_init(const struct retro_vfs_interface_info* vfs_info);
/* Order in this enum is equivalent to negative sort order in filelist
* (i.e. DIRECTORY is on top of PLAIN_FILE) */
enum
{
RARCH_FILETYPE_UNSET,
RARCH_PLAIN_FILE,
RARCH_COMPRESSED_FILE_IN_ARCHIVE,
RARCH_COMPRESSED_ARCHIVE,
RARCH_DIRECTORY,
RARCH_FILE_UNSUPPORTED
};
/**
* path_is_compressed_file:
* @path : path
*
* Checks if path is a compressed file.
*
* Returns: true (1) if path is a compressed file, otherwise false (0).
**/
bool path_is_compressed_file(const char *path);
/**
* path_contains_compressed_file:
* @path : path
*
* Checks if path contains a compressed file.
*
* Currently we only check for hash symbol (#) inside the pathname.
* If path is ever expanded to a general URI, we should check for that here.
*
* Example: Somewhere in the path there might be a compressed file
* E.g.: /path/to/file.7z#mygame.img
*
* Returns: true (1) if path contains compressed file, otherwise false (0).
**/
#define path_contains_compressed_file(path) (path_get_archive_delim((path)) != NULL)
/**
* path_get_archive_delim:
* @path : path
*
* Gets delimiter of an archive file. Only the first '#'
* after a compression extension is considered.
*
* Returns: pointer to the delimiter in the path if it contains
* a compressed file, otherwise NULL.
*/
const char *path_get_archive_delim(const char *path);
/**
* path_get_extension:
* @path : path
*
* Gets extension of file. Only '.'s
* after the last slash are considered.
*
* Returns: extension part from the path.
*/
const char *path_get_extension(const char *path);
/**
* path_remove_extension:
* @path : path
*
* Mutates path by removing its extension. Removes all
* text after and including the last '.'.
* Only '.'s after the last slash are considered.
*
* Returns:
* 1) If path has an extension, returns path with the
* extension removed.
* 2) If there is no extension, returns NULL.
* 3) If path is empty or NULL, returns NULL
*/
char *path_remove_extension(char *path);
/**
* path_basename:
* @path : path
*
* Get basename from @path.
*
* Returns: basename from path.
**/
const char *path_basename(const char *path);
const char *path_basename_nocompression(const char *path);
/**
* path_basedir:
* @path : path
*
* Extracts base directory by mutating path.
* Keeps trailing '/'.
**/
void path_basedir(char *path);
/**
* path_parent_dir:
* @path : path
*
* Extracts parent directory by mutating path.
* Assumes that path is a directory. Keeps trailing '/'.
* If the path was already at the root directory, returns empty string
**/
void path_parent_dir(char *path);
/**
* path_resolve_realpath:
* @buf : input and output buffer for path
* @size : size of buffer
* @resolve_symlinks : whether to resolve symlinks or not
*
* Resolves use of ".", "..", multiple slashes etc in absolute paths.
*
* Relative paths are rebased on the current working dir.
*
* Returns: @buf if successful, NULL otherwise.
* Note: Not implemented on consoles
* Note: Symlinks are only resolved on Unix-likes
* Note: The current working dir might not be what you expect,
* e.g. on Android it is "/"
* Use of fill_pathname_resolve_relative() should be prefered
**/
char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks);
/**
* path_relative_to:
* @out : buffer to write the relative path to
* @path : path to be expressed relatively
* @base : relative to this
* @size : size of output buffer
*
* Turns @path into a path relative to @base and writes it to @out.
*
* @base is assumed to be a base directory, i.e. a path ending with '/' or '\'.
* Both @path and @base are assumed to be absolute paths without "." or "..".
*
* E.g. path /a/b/e/f.cgp with base /a/b/c/d/ turns into ../../e/f.cgp
**/
size_t path_relative_to(char *out, const char *path, const char *base, size_t size);
/**
* path_is_absolute:
* @path : path
*
* Checks if @path is an absolute path or a relative path.
*
* Returns: true if path is absolute, false if path is relative.
**/
bool path_is_absolute(const char *path);
/**
* fill_pathname:
* @out_path : output path
* @in_path : input path
* @replace : what to replace
* @size : buffer size of output path
*
* FIXME: Verify
*
* Replaces filename extension with 'replace' and outputs result to out_path.
* The extension here is considered to be the string from the last '.'
* to the end.
*
* Only '.'s after the last slash are considered as extensions.
* If no '.' is present, in_path and replace will simply be concatenated.
* 'size' is buffer size of 'out_path'.
* E.g.: in_path = "/foo/bar/baz/boo.c", replace = ".asm" =>
* out_path = "/foo/bar/baz/boo.asm"
* E.g.: in_path = "/foo/bar/baz/boo.c", replace = "" =>
* out_path = "/foo/bar/baz/boo"
*/
void fill_pathname(char *out_path, const char *in_path,
const char *replace, size_t size);
/**
* fill_dated_filename:
* @out_filename : output filename
* @ext : extension of output filename
* @size : buffer size of output filename
*
* Creates a 'dated' filename prefixed by 'RetroArch', and
* concatenates extension (@ext) to it.
*
* E.g.:
* out_filename = "RetroArch-{month}{day}-{Hours}{Minutes}.{@ext}"
**/
size_t fill_dated_filename(char *out_filename,
const char *ext, size_t size);
/**
* fill_str_dated_filename:
* @out_filename : output filename
* @in_str : input string
* @ext : extension of output filename
* @size : buffer size of output filename
*
* Creates a 'dated' filename prefixed by the string @in_str, and
* concatenates extension (@ext) to it.
*
* E.g.:
* out_filename = "RetroArch-{year}{month}{day}-{Hour}{Minute}{Second}.{@ext}"
**/
void fill_str_dated_filename(char *out_filename,
const char *in_str, const char *ext, size_t size);
/**
* fill_pathname_noext:
* @out_path : output path
* @in_path : input path
* @replace : what to replace
* @size : buffer size of output path
*
* Appends a filename extension 'replace' to 'in_path', and outputs
* result in 'out_path'.
*
* Assumes in_path has no extension. If an extension is still
* present in 'in_path', it will be ignored.
*
*/
size_t fill_pathname_noext(char *out_path, const char *in_path,
const char *replace, size_t size);
/**
* find_last_slash:
* @str : input path
*
* Gets a pointer to the last slash in the input path.
*
* Returns: a pointer to the last slash in the input path.
**/
char *find_last_slash(const char *str);
/**
* fill_pathname_dir:
* @in_dir : input directory path
* @in_basename : input basename to be appended to @in_dir
* @replace : replacement to be appended to @in_basename
* @size : size of buffer
*
* Appends basename of 'in_basename', to 'in_dir', along with 'replace'.
* Basename of in_basename is the string after the last '/' or '\\',
* i.e the filename without directories.
*
* If in_basename has no '/' or '\\', the whole 'in_basename' will be used.
* 'size' is buffer size of 'in_dir'.
*
* E.g..: in_dir = "/tmp/some_dir", in_basename = "/some_content/foo.c",
* replace = ".asm" => in_dir = "/tmp/some_dir/foo.c.asm"
**/
size_t fill_pathname_dir(char *in_dir, const char *in_basename,
const char *replace, size_t size);
/**
* fill_pathname_base:
* @out : output path
* @in_path : input path
* @size : size of output path
*
* Copies basename of @in_path into @out_path.
**/
size_t fill_pathname_base(char *out_path, const char *in_path, size_t size);
void fill_pathname_base_noext(char *out_dir,
const char *in_path, size_t size);
size_t fill_pathname_base_ext(char *out,
const char *in_path, const char *ext,
size_t size);
/**
* fill_pathname_basedir:
* @out_dir : output directory
* @in_path : input path
* @size : size of output directory
*
* Copies base directory of @in_path into @out_path.
* If in_path is a path without any slashes (relative current directory),
* @out_path will get path "./".
**/
void fill_pathname_basedir(char *out_path, const char *in_path, size_t size);
void fill_pathname_basedir_noext(char *out_dir,
const char *in_path, size_t size);
/**
* fill_pathname_parent_dir_name:
* @out_dir : output directory
* @in_dir : input directory
* @size : size of output directory
*
* Copies only the parent directory name of @in_dir into @out_dir.
* The two buffers must not overlap. Removes trailing '/'.
* Returns true on success, false if a slash was not found in the path.
**/
bool fill_pathname_parent_dir_name(char *out_dir,
const char *in_dir, size_t size);
/**
* fill_pathname_parent_dir:
* @out_dir : output directory
* @in_dir : input directory
* @size : size of output directory
*
* Copies parent directory of @in_dir into @out_dir.
* Assumes @in_dir is a directory. Keeps trailing '/'.
* If the path was already at the root directory, @out_dir will be an empty string.
**/
void fill_pathname_parent_dir(char *out_dir,
const char *in_dir, size_t size);
/**
* fill_pathname_resolve_relative:
* @out_path : output path
* @in_refpath : input reference path
* @in_path : input path
* @size : size of @out_path
*
* Joins basedir of @in_refpath together with @in_path.
* If @in_path is an absolute path, out_path = in_path.
* E.g.: in_refpath = "/foo/bar/baz.a", in_path = "foobar.cg",
* out_path = "/foo/bar/foobar.cg".
**/
void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
const char *in_path, size_t size);
/**
* fill_pathname_join:
* @out_path : output path
* @dir : directory
* @path : path
* @size : size of output path
*
* Joins a directory (@dir) and path (@path) together.
* Makes sure not to get two consecutive slashes
* between directory and path.
**/
size_t fill_pathname_join(char *out_path, const char *dir,
const char *path, size_t size);
size_t fill_pathname_join_special_ext(char *out_path,
const char *dir, const char *path,
const char *last, const char *ext,
size_t size);
size_t fill_pathname_join_concat_noext(char *out_path,
const char *dir, const char *path,
const char *concat,
size_t size);
size_t fill_pathname_join_concat(char *out_path,
const char *dir, const char *path,
const char *concat,
size_t size);
void fill_pathname_join_noext(char *out_path,
const char *dir, const char *path, size_t size);
/**
* fill_pathname_join_delim:
* @out_path : output path
* @dir : directory
* @path : path
* @delim : delimiter
* @size : size of output path
*
* Joins a directory (@dir) and path (@path) together
* using the given delimiter (@delim).
**/
size_t fill_pathname_join_delim(char *out_path, const char *dir,
const char *path, const char delim, size_t size);
size_t fill_pathname_join_delim_concat(char *out_path, const char *dir,
const char *path, const char delim, const char *concat,
size_t size);
/**
* fill_short_pathname_representation:
* @out_rep : output representation
* @in_path : input path
* @size : size of output representation
*
* Generates a short representation of path. It should only
* be used for displaying the result; the output representation is not
* binding in any meaningful way (for a normal path, this is the same as basename)
* In case of more complex URLs, this should cut everything except for
* the main image file.
*
* E.g.: "/path/to/game.img" -> game.img
* "/path/to/myarchive.7z#folder/to/game.img" -> game.img
*/
size_t fill_short_pathname_representation(char* out_rep,
const char *in_path, size_t size);
void fill_short_pathname_representation_noext(char* out_rep,
const char *in_path, size_t size);
void fill_pathname_expand_special(char *out_path,
const char *in_path, size_t size);
void fill_pathname_abbreviate_special(char *out_path,
const char *in_path, size_t size);
void fill_pathname_abbreviated_or_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size);
void pathname_conform_slashes_to_os(char *path);
void pathname_make_slashes_portable(char *path);
/**
* path_basedir:
* @path : path
*
* Extracts base directory by mutating path.
* Keeps trailing '/'.
**/
void path_basedir_wrapper(char *path);
/**
* path_char_is_slash:
* @c : character
*
* Checks if character (@c) is a slash.
*
* Returns: true (1) if character is a slash, otherwise false (0).
*/
#ifdef _WIN32
#define PATH_CHAR_IS_SLASH(c) (((c) == '/') || ((c) == '\\'))
#else
#define PATH_CHAR_IS_SLASH(c) ((c) == '/')
#endif
/**
* path_default_slash and path_default_slash_c:
*
* Gets the default slash separator.
*
* Returns: default slash separator.
*/
#ifdef _WIN32
#define PATH_DEFAULT_SLASH() "\\"
#define PATH_DEFAULT_SLASH_C() '\\'
#else
#define PATH_DEFAULT_SLASH() "/"
#define PATH_DEFAULT_SLASH_C() '/'
#endif
/**
* fill_pathname_slash:
* @path : path
* @size : size of path
*
* Assumes path is a directory. Appends a slash
* if not already there.
**/
void fill_pathname_slash(char *path, size_t size);
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
void fill_pathname_application_path(char *buf, size_t size);
void fill_pathname_application_dir(char *buf, size_t size);
void fill_pathname_home_dir(char *buf, size_t size);
#endif
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir);
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path);
bool path_is_character_special(const char *path);
int path_stat(const char *path);
bool path_is_valid(const char *path);
int32_t path_get_size(const char *path);
bool is_path_accessible_using_standard_io(const char *path);
RETRO_END_DECLS
#endif

View File

@@ -1,7 +1,7 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (crc32.h).
* The following license statement only applies to this file (retro_assert.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
@@ -20,19 +20,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_ENCODINGS_CRC32_H
#define _LIBRETRO_ENCODINGS_CRC32_H
#ifndef __RETRO_ASSERT_H
#define __RETRO_ASSERT_H
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
uint32_t encoding_crc32(uint32_t crc, const uint8_t *buf, size_t len);
uint32_t file_crc32(uint32_t crc, const char *path);
RETRO_END_DECLS
#ifdef RARCH_INTERNAL
#include <stdio.h>
#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

View File

@@ -0,0 +1,114 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_environment.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_ENVIRONMENT_H
#define __LIBRETRO_SDK_ENVIRONMENT_H
/*
This file is designed to create a normalized environment for compiling
libretro-common's private implementations, or any other sources which might
enjoy use of it's environment (RetroArch for instance).
This should be an elaborately crafted environment so that sources don't
need to be full of platform-specific workarounds.
*/
#if defined (__cplusplus)
#if 0
printf("This is C++, version %d.\n", __cplusplus);
#endif
/* The expected values would be
* 199711L, for ISO/IEC 14882:1998 or 14882:2003
*/
#elif defined(__STDC__)
/* This is standard C. */
#if (__STDC__ == 1)
/* The implementation is ISO-conforming. */
#define __STDC_ISO__
#else
/* The implementation is not ISO-conforming. */
#endif
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 201112L)
/* This is C11. */
#define __STDC_C11__
#elif (__STDC_VERSION__ >= 199901L)
/* This is C99. */
#define __STDC_C99__
#elif (__STDC_VERSION__ >= 199409L)
/* This is C89 with amendment 1. */
#define __STDC_C89__
#define __STDC_C89_AMENDMENT_1__
#else
/* This is C89 without amendment 1. */
#define __STDC_C89__
#endif
#else /* !defined(__STDC_VERSION__) */
/* This is C89. __STDC_VERSION__ is not defined. */
#define __STDC_C89__
#endif
#else /* !defined(__STDC__) */
/* This is not standard C. __STDC__ is not defined. */
#endif
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
/* Try to find out if we're compiling for WinRT or non-WinRT */
#if defined(_MSC_VER) && defined(__has_include)
#if __has_include(<winapifamily.h>)
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#endif
/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
#define HAVE_WINAPIFAMILY_H 1
#else
#define HAVE_WINAPIFAMILY_H 0
#endif
#if HAVE_WINAPIFAMILY_H
#include <winapifamily.h>
#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
#else
#define WINAPI_FAMILY_WINRT 0
#endif /* HAVE_WINAPIFAMILY_H */
#if WINAPI_FAMILY_WINRT
#undef __WINRT__
#define __WINRT__ 1
#endif
/* MSVC obviously has to have some non-standard constants... */
#if _M_IX86_FP == 1
#define __SSE__ 1
#elif _M_IX86_FP == 2 || (defined(_M_AMD64) || defined(_M_X64))
#define __SSE__ 1
#define __SSE2__ 1
#endif
#endif
#endif

View File

@@ -0,0 +1,203 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_miscellaneous.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 __RARCH_MISCELLANEOUS_H
#define __RARCH_MISCELLANEOUS_H
#define RARCH_MAX_SUBSYSTEMS 10
#define RARCH_MAX_SUBSYSTEM_ROMS 10
#include <stdint.h>
#include <boolean.h>
#include <retro_inline.h>
#if defined(_WIN32)
#if defined(_XBOX)
#include <Xtl.h>
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#endif
#endif
#include <limits.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
static INLINE void bits_or_bits(uint32_t *a, uint32_t *b, uint32_t count)
{
uint32_t i;
for (i = 0; i < count;i++)
a[i] |= b[i];
}
static INLINE void bits_clear_bits(uint32_t *a, uint32_t *b, uint32_t count)
{
uint32_t i;
for (i = 0; i < count;i++)
a[i] &= ~b[i];
}
static INLINE bool bits_any_set(uint32_t* ptr, uint32_t count)
{
uint32_t i;
for (i = 0; i < count; i++)
{
if (ptr[i] != 0)
return true;
}
return false;
}
#ifndef PATH_MAX_LENGTH
#if defined(_XBOX1) || defined(_3DS) || defined(PSP) || defined(PS2) || defined(GEKKO)|| defined(WIIU) || defined(ORBIS) || defined(__PSL1GHT__) || defined(__PS3__)
#define PATH_MAX_LENGTH 512
#else
#define PATH_MAX_LENGTH 4096
#endif
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define BITS_GET_ELEM(a, i) ((a).data[i])
#define BITS_GET_ELEM_PTR(a, i) ((a)->data[i])
#define BIT_SET(a, bit) ((a)[(bit) >> 3] |= (1 << ((bit) & 7)))
#define BIT_CLEAR(a, bit) ((a)[(bit) >> 3] &= ~(1 << ((bit) & 7)))
#define BIT_GET(a, bit) (((a)[(bit) >> 3] >> ((bit) & 7)) & 1)
#define BIT16_SET(a, bit) ((a) |= (1 << ((bit) & 15)))
#define BIT16_CLEAR(a, bit) ((a) &= ~(1 << ((bit) & 15)))
#define BIT16_GET(a, bit) (((a) >> ((bit) & 15)) & 1)
#define BIT16_CLEAR_ALL(a) ((a) = 0)
#define BIT32_SET(a, bit) ((a) |= (UINT32_C(1) << ((bit) & 31)))
#define BIT32_CLEAR(a, bit) ((a) &= ~(UINT32_C(1) << ((bit) & 31)))
#define BIT32_GET(a, bit) (((a) >> ((bit) & 31)) & 1)
#define BIT32_CLEAR_ALL(a) ((a) = 0)
#define BIT64_SET(a, bit) ((a) |= (UINT64_C(1) << ((bit) & 63)))
#define BIT64_CLEAR(a, bit) ((a) &= ~(UINT64_C(1) << ((bit) & 63)))
#define BIT64_GET(a, bit) (((a) >> ((bit) & 63)) & 1)
#define BIT64_CLEAR_ALL(a) ((a) = 0)
#define BIT128_SET(a, bit) ((a).data[(bit) >> 5] |= (UINT32_C(1) << ((bit) & 31)))
#define BIT128_CLEAR(a, bit) ((a).data[(bit) >> 5] &= ~(UINT32_C(1) << ((bit) & 31)))
#define BIT128_GET(a, bit) (((a).data[(bit) >> 5] >> ((bit) & 31)) & 1)
#define BIT128_CLEAR_ALL(a) memset(&(a), 0, sizeof(a))
#define BIT128_SET_PTR(a, bit) BIT128_SET(*a, bit)
#define BIT128_CLEAR_PTR(a, bit) BIT128_CLEAR(*a, bit)
#define BIT128_GET_PTR(a, bit) BIT128_GET(*a, bit)
#define BIT128_CLEAR_ALL_PTR(a) BIT128_CLEAR_ALL(*a)
#define BIT256_SET(a, bit) BIT128_SET(a, bit)
#define BIT256_CLEAR(a, bit) BIT128_CLEAR(a, bit)
#define BIT256_GET(a, bit) BIT128_GET(a, bit)
#define BIT256_CLEAR_ALL(a) BIT128_CLEAR_ALL(a)
#define BIT256_SET_PTR(a, bit) BIT256_SET(*a, bit)
#define BIT256_CLEAR_PTR(a, bit) BIT256_CLEAR(*a, bit)
#define BIT256_GET_PTR(a, bit) BIT256_GET(*a, bit)
#define BIT256_CLEAR_ALL_PTR(a) BIT256_CLEAR_ALL(*a)
#define BIT512_SET(a, bit) BIT256_SET(a, bit)
#define BIT512_CLEAR(a, bit) BIT256_CLEAR(a, bit)
#define BIT512_GET(a, bit) BIT256_GET(a, bit)
#define BIT512_CLEAR_ALL(a) BIT256_CLEAR_ALL(a)
#define BIT512_SET_PTR(a, bit) BIT512_SET(*a, bit)
#define BIT512_CLEAR_PTR(a, bit) BIT512_CLEAR(*a, bit)
#define BIT512_GET_PTR(a, bit) BIT512_GET(*a, bit)
#define BIT512_CLEAR_ALL_PTR(a) BIT512_CLEAR_ALL(*a)
#define BITS_COPY16_PTR(a,bits) \
{ \
BIT128_CLEAR_ALL_PTR(a); \
BITS_GET_ELEM_PTR(a, 0) = (bits) & 0xffff; \
}
#define BITS_COPY32_PTR(a,bits) \
{ \
BIT128_CLEAR_ALL_PTR(a); \
BITS_GET_ELEM_PTR(a, 0) = (bits); \
}
#define BITS_COPY64_PTR(a,bits) \
{ \
BIT128_CLEAR_ALL_PTR(a); \
BITS_GET_ELEM_PTR(a, 0) = (bits); \
BITS_GET_ELEM_PTR(a, 1) = (bits >> 32); \
}
/* Helper macros and struct to keep track of many booleans. */
/* This struct has 256 bits. */
typedef struct
{
uint32_t data[8];
} retro_bits_t;
/* This struct has 512 bits. */
typedef struct
{
uint32_t data[16];
} retro_bits_512_t;
#ifdef _WIN32
# ifdef _WIN64
# define PRI_SIZET PRIu64
# else
# if _MSC_VER == 1800
# define PRI_SIZET PRIu32
# else
# define PRI_SIZET "u"
# endif
# endif
#elif defined(PS2)
# define PRI_SIZET "u"
#else
# if (SIZE_MAX == 0xFFFF)
# define PRI_SIZET "hu"
# elif (SIZE_MAX == 0xFFFFFFFF)
# define PRI_SIZET "u"
# elif (SIZE_MAX == 0xFFFFFFFFFFFFFFFF)
# define PRI_SIZET "lu"
# else
# error PRI_SIZET: unknown SIZE_MAX
# endif
#endif
#endif

View File

@@ -0,0 +1,117 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream.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_FILE_STREAM_H
#define __LIBRETRO_SDK_FILE_STREAM_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/types.h>
#include <libretro.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include <boolean.h>
#include <stdarg.h>
#include <vfs/vfs_implementation.h>
#define FILESTREAM_REQUIRED_VFS_VERSION 2
RETRO_BEGIN_DECLS
typedef struct RFILE RFILE;
#define FILESTREAM_REQUIRED_VFS_VERSION 2
void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info);
int64_t filestream_get_size(RFILE *stream);
int64_t filestream_truncate(RFILE *stream, int64_t length);
/**
* filestream_open:
* @path : path to file
* @mode : file mode to use when opening (read/write)
* @bufsize : optional buffer size (-1 or 0 to use default)
*
* Opens a file for reading or writing, depending on the requested mode.
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/
RFILE* filestream_open(const char *path, unsigned mode, unsigned hints);
int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position);
int64_t filestream_read(RFILE *stream, void *data, int64_t len);
int64_t filestream_write(RFILE *stream, const void *data, int64_t len);
int64_t filestream_tell(RFILE *stream);
void filestream_rewind(RFILE *stream);
int filestream_close(RFILE *stream);
int64_t filestream_read_file(const char *path, void **buf, int64_t *len);
char* filestream_gets(RFILE *stream, char *s, size_t len);
int filestream_getc(RFILE *stream);
int filestream_vscanf(RFILE *stream, const char* format, va_list *args);
int filestream_scanf(RFILE *stream, const char* format, ...);
int filestream_eof(RFILE *stream);
bool filestream_write_file(const char *path, const void *data, int64_t size);
int filestream_putc(RFILE *stream, int c);
int filestream_vprintf(RFILE *stream, const char* format, va_list args);
int filestream_printf(RFILE *stream, const char* format, ...);
int filestream_error(RFILE *stream);
int filestream_flush(RFILE *stream);
int filestream_delete(const char *path);
int filestream_rename(const char *old_path, const char *new_path);
const char* filestream_get_path(RFILE *stream);
bool filestream_exists(const char *path);
/* Returned pointer must be freed by the caller. */
char* filestream_getline(RFILE *stream);
libretro_vfs_implementation_file* filestream_get_vfs_handle(RFILE *stream);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,101 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream_transforms.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_FILE_STREAM_TRANSFORMS_H
#define __LIBRETRO_SDK_FILE_STREAM_TRANSFORMS_H
#include <stdint.h>
#include <string.h>
#include <retro_common_api.h>
#include <streams/file_stream.h>
RETRO_BEGIN_DECLS
#ifndef SKIP_STDIO_REDEFINES
#define FILE RFILE
#undef fopen
#undef fclose
#undef ftell
#undef fseek
#undef fread
#undef fgets
#undef fgetc
#undef fwrite
#undef fputc
#undef fflush
#undef fprintf
#undef ferror
#undef feof
#undef fscanf
#define fopen rfopen
#define fclose rfclose
#define ftell rftell
#define fseek rfseek
#define fread rfread
#define fgets rfgets
#define fgetc rfgetc
#define fwrite rfwrite
#define fputc rfputc
#define fflush rfflush
#define fprintf rfprintf
#define ferror rferror
#define feof rfeof
#define fscanf rfscanf
#endif
RFILE* rfopen(const char *path, const char *mode);
int rfclose(RFILE* stream);
int64_t rftell(RFILE* stream);
int64_t rfseek(RFILE* stream, int64_t offset, int origin);
int64_t rfread(void* buffer,
size_t elem_size, size_t elem_count, RFILE* stream);
char *rfgets(char *buffer, int maxCount, RFILE* stream);
int rfgetc(RFILE* stream);
int64_t rfwrite(void const* buffer,
size_t elem_size, size_t elem_count, RFILE* stream);
int rfputc(int character, RFILE * stream);
int64_t rfflush(RFILE * stream);
int rfprintf(RFILE * stream, const char * format, ...);
int rferror(RFILE* stream);
int rfeof(RFILE* stream);
int rfscanf(RFILE * stream, const char * format, ...);
RETRO_END_DECLS
#endif

View File

@@ -148,9 +148,61 @@ char *string_trim_whitespace_right(char *const s);
/* Remove leading and trailing whitespaces */
char *string_trim_whitespace(char *const s);
/* max_lines == 0 means no limit */
char *word_wrap(char *buffer, const char *string,
int line_width, bool unicode, unsigned max_lines);
/*
* Wraps string specified by 'src' to destination buffer
* specified by 'dst' and 'dst_size'.
* This function assumes that all glyphs in the string
* have an on-screen pixel width similar to that of
* regular Latin characters - i.e. it will not wrap
* correctly any text containing so-called 'wide' Unicode
* characters (e.g. CJK languages, emojis, etc.).
*
* @param dst pointer to destination buffer.
* @param dst_size size of destination buffer.
* @param src pointer to input string.
* @param line_width max number of characters per line.
* @param wideglyph_width not used, but is necessary to keep
* compatibility with word_wrap_wideglyph().
* @param max_lines max lines of destination string.
* 0 means no limit.
*/
void word_wrap(char *dst, size_t dst_size, const char *src,
int line_width, int wideglyph_width, unsigned max_lines);
/*
* Wraps string specified by 'src' to destination buffer
* specified by 'dst' and 'dst_size'.
* This function assumes that all glyphs in the string
* are:
* - EITHER 'non-wide' Unicode glyphs, with an on-screen
* pixel width similar to that of regular Latin characters
* - OR 'wide' Unicode glyphs (e.g. CJK languages, emojis, etc.)
* with an on-screen pixel width defined by 'wideglyph_width'
* Note that wrapping may occur in inappropriate locations
* if 'src' string contains 'wide' Unicode characters whose
* on-screen pixel width deviates greatly from the set
* 'wideglyph_width' value.
*
* @param dst pointer to destination buffer.
* @param dst_size size of destination buffer.
* @param src pointer to input string.
* @param line_width max number of characters per line.
* @param wideglyph_width effective width of 'wide' Unicode glyphs.
* the value here is normalised relative to the
* typical on-screen pixel width of a regular
* Latin character:
* - a regular Latin character is defined to
* have an effective width of 100
* - wideglyph_width = 100 * (wide_character_pixel_width / latin_character_pixel_width)
* - e.g. if 'wide' Unicode characters in 'src'
* have an on-screen pixel width twice that of
* regular Latin characters, wideglyph_width
* would be 200
* @param max_lines max lines of destination string.
* 0 means no limit.
*/
void word_wrap_wideglyph(char *dst, size_t dst_size, const char *src,
int line_width, int wideglyph_width, unsigned max_lines);
/* Splits string into tokens seperated by 'delim'
* > Returned token string must be free()'d

View File

@@ -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 <retro_common_api.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
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

View File

@@ -0,0 +1,111 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (vfs_implementation.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_VFS_H
#define __LIBRETRO_SDK_VFS_H
#include <retro_common_api.h>
#include <boolean.h>
#ifdef RARCH_INTERNAL
#ifndef VFS_FRONTEND
#define VFS_FRONTEND
#endif
#endif
RETRO_BEGIN_DECLS
#ifdef _WIN32
typedef void* HANDLE;
#endif
#ifdef HAVE_CDROM
typedef struct
{
int64_t byte_pos;
char *cue_buf;
size_t cue_len;
unsigned cur_lba;
unsigned last_frame_lba;
unsigned char cur_min;
unsigned char cur_sec;
unsigned char cur_frame;
unsigned char cur_track;
unsigned char last_frame[2352];
char drive;
bool last_frame_valid;
} vfs_cdrom_t;
#endif
enum vfs_scheme
{
VFS_SCHEME_NONE = 0,
VFS_SCHEME_CDROM
};
#ifndef __WINRT__
#ifdef VFS_FRONTEND
struct retro_vfs_file_handle
#else
struct libretro_vfs_implementation_file
#endif
{
#ifdef HAVE_CDROM
vfs_cdrom_t cdrom; /* int64_t alignment */
#endif
int64_t size;
uint64_t mappos;
uint64_t mapsize;
FILE *fp;
#ifdef _WIN32
HANDLE fh;
#endif
char *buf;
char* orig_path;
uint8_t *mapped;
int fd;
unsigned hints;
enum vfs_scheme scheme;
};
#endif
/* Replace the following symbol with something appropriate
* to signify the file is being compiled for a front end instead of a core.
* This allows the same code to act as reference implementation
* for VFS and as fallbacks for when the front end does not provide VFS functionality.
*/
#ifdef VFS_FRONTEND
typedef struct retro_vfs_file_handle libretro_vfs_implementation_file;
#else
typedef struct libretro_vfs_implementation_file libretro_vfs_implementation_file;
#endif
#ifdef VFS_FRONTEND
typedef struct retro_vfs_dir_handle libretro_vfs_implementation_dir;
#else
typedef struct libretro_vfs_implementation_dir libretro_vfs_implementation_dir;
#endif
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,76 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (vfs_implementation.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_VFS_IMPLEMENTATION_H
#define __LIBRETRO_SDK_VFS_IMPLEMENTATION_H
#include <stdio.h>
#include <stdint.h>
#include <libretro.h>
#include <retro_environment.h>
#include <vfs/vfs.h>
RETRO_BEGIN_DECLS
libretro_vfs_implementation_file *retro_vfs_file_open_impl(const char *path, unsigned mode, unsigned hints);
int retro_vfs_file_close_impl(libretro_vfs_implementation_file *stream);
int retro_vfs_file_error_impl(libretro_vfs_implementation_file *stream);
int64_t retro_vfs_file_size_impl(libretro_vfs_implementation_file *stream);
int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file *stream, int64_t length);
int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file *stream);
int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file *stream, int64_t offset, int seek_position);
int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file *stream, void *s, uint64_t len);
int64_t retro_vfs_file_write_impl(libretro_vfs_implementation_file *stream, const void *s, uint64_t len);
int retro_vfs_file_flush_impl(libretro_vfs_implementation_file *stream);
int retro_vfs_file_remove_impl(const char *path);
int retro_vfs_file_rename_impl(const char *old_path, const char *new_path);
const char *retro_vfs_file_get_path_impl(libretro_vfs_implementation_file *stream);
int retro_vfs_stat_impl(const char *path, int32_t *size);
int retro_vfs_mkdir_impl(const char *dir);
libretro_vfs_implementation_dir *retro_vfs_opendir_impl(const char *dir, bool include_hidden);
bool retro_vfs_readdir_impl(libretro_vfs_implementation_dir *dirstream);
const char *retro_vfs_dirent_get_name_impl(libretro_vfs_implementation_dir *dirstream);
bool retro_vfs_dirent_is_dir_impl(libretro_vfs_implementation_dir *dirstream);
int retro_vfs_closedir_impl(libretro_vfs_implementation_dir *dirstream);
RETRO_END_DECLS
#endif

View File

@@ -0,0 +1,678 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
#include <string/stdstring.h>
#include <streams/file_stream.h>
#define VFS_FRONTEND
#include <vfs/vfs_implementation.h>
#define VFS_ERROR_RETURN_VALUE -1
struct RFILE
{
struct retro_vfs_file_handle *hfile;
bool error_flag;
bool eof_flag;
};
static retro_vfs_get_path_t filestream_get_path_cb = NULL;
static retro_vfs_open_t filestream_open_cb = NULL;
static retro_vfs_close_t filestream_close_cb = NULL;
static retro_vfs_size_t filestream_size_cb = NULL;
static retro_vfs_truncate_t filestream_truncate_cb = NULL;
static retro_vfs_tell_t filestream_tell_cb = NULL;
static retro_vfs_seek_t filestream_seek_cb = NULL;
static retro_vfs_read_t filestream_read_cb = NULL;
static retro_vfs_write_t filestream_write_cb = NULL;
static retro_vfs_flush_t filestream_flush_cb = NULL;
static retro_vfs_remove_t filestream_remove_cb = NULL;
static retro_vfs_rename_t filestream_rename_cb = NULL;
/* VFS Initialization */
void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info)
{
const struct retro_vfs_interface *
vfs_iface = vfs_info->iface;
filestream_get_path_cb = NULL;
filestream_open_cb = NULL;
filestream_close_cb = NULL;
filestream_tell_cb = NULL;
filestream_size_cb = NULL;
filestream_truncate_cb = NULL;
filestream_seek_cb = NULL;
filestream_read_cb = NULL;
filestream_write_cb = NULL;
filestream_flush_cb = NULL;
filestream_remove_cb = NULL;
filestream_rename_cb = NULL;
if (
(vfs_info->required_interface_version <
FILESTREAM_REQUIRED_VFS_VERSION)
|| !vfs_iface)
return;
filestream_get_path_cb = vfs_iface->get_path;
filestream_open_cb = vfs_iface->open;
filestream_close_cb = vfs_iface->close;
filestream_size_cb = vfs_iface->size;
filestream_truncate_cb = vfs_iface->truncate;
filestream_tell_cb = vfs_iface->tell;
filestream_seek_cb = vfs_iface->seek;
filestream_read_cb = vfs_iface->read;
filestream_write_cb = vfs_iface->write;
filestream_flush_cb = vfs_iface->flush;
filestream_remove_cb = vfs_iface->remove;
filestream_rename_cb = vfs_iface->rename;
}
/* Callback wrappers */
bool filestream_exists(const char *path)
{
RFILE *dummy = NULL;
if (!path || !*path)
return false;
dummy = filestream_open(
path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!dummy)
return false;
if (filestream_close(dummy) != 0)
if (dummy)
free(dummy);
dummy = NULL;
return true;
}
int64_t filestream_get_size(RFILE *stream)
{
int64_t output;
if (filestream_size_cb)
output = filestream_size_cb(stream->hfile);
else
output = retro_vfs_file_size_impl(
(libretro_vfs_implementation_file*)stream->hfile);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
return output;
}
int64_t filestream_truncate(RFILE *stream, int64_t length)
{
int64_t output;
if (filestream_truncate_cb)
output = filestream_truncate_cb(stream->hfile, length);
else
output = retro_vfs_file_truncate_impl(
(libretro_vfs_implementation_file*)stream->hfile, length);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
return output;
}
/**
* filestream_open:
* @path : path to file
* @mode : file mode to use when opening (read/write)
* @hints :
*
* Opens a file for reading or writing, depending on the requested mode.
* Returns a pointer to an RFILE if opened successfully, otherwise NULL.
**/
RFILE* filestream_open(const char *path, unsigned mode, unsigned hints)
{
struct retro_vfs_file_handle *fp = NULL;
RFILE* output = NULL;
if (filestream_open_cb)
fp = (struct retro_vfs_file_handle*)
filestream_open_cb(path, mode, hints);
else
fp = (struct retro_vfs_file_handle*)
retro_vfs_file_open_impl(path, mode, hints);
if (!fp)
return NULL;
output = (RFILE*)malloc(sizeof(RFILE));
output->error_flag = false;
output->eof_flag = false;
output->hfile = fp;
return output;
}
char* filestream_gets(RFILE *stream, char *s, size_t len)
{
int c = 0;
char *p = s;
if (!stream)
return NULL;
/* get max bytes or up to a newline */
for (len--; len > 0; len--)
{
if ((c = filestream_getc(stream)) == EOF)
break;
*p++ = c;
if (c == '\n')
break;
}
*p = 0;
if (p == s && c == EOF)
return NULL;
return (s);
}
int filestream_getc(RFILE *stream)
{
char c = 0;
if (stream && filestream_read(stream, &c, 1) == 1)
return (int)(unsigned char)c;
return EOF;
}
int filestream_vscanf(RFILE *stream, const char* format, va_list *args)
{
char buf[4096];
char subfmt[64];
va_list args_copy;
const char * bufiter = buf;
int ret = 0;
int64_t startpos = filestream_tell(stream);
int64_t maxlen = filestream_read(stream, buf, sizeof(buf)-1);
if (maxlen <= 0)
return EOF;
buf[maxlen] = '\0';
/* Have to copy the input va_list here
* > Calling va_arg() on 'args' directly would
* cause the va_list to have an indeterminate value
* in the function calling filestream_vscanf(),
* leading to unexpected behaviour */
va_copy(args_copy, *args);
while (*format)
{
if (*format == '%')
{
int sublen;
char* subfmtiter = subfmt;
bool asterisk = false;
*subfmtiter++ = *format++; /* '%' */
/* %[*][width][length]specifier */
if (*format == '*')
{
asterisk = true;
*subfmtiter++ = *format++;
}
while (ISDIGIT((unsigned char)*format))
*subfmtiter++ = *format++; /* width */
/* length */
if (*format == 'h' || *format == 'l')
{
if (format[1] == format[0])
*subfmtiter++ = *format++;
*subfmtiter++ = *format++;
}
else if (
*format == 'j' ||
*format == 'z' ||
*format == 't' ||
*format == 'L')
{
*subfmtiter++ = *format++;
}
/* specifier - always a single character (except ]) */
if (*format == '[')
{
while (*format != ']')
*subfmtiter++ = *format++;
*subfmtiter++ = *format++;
}
else
*subfmtiter++ = *format++;
*subfmtiter++ = '%';
*subfmtiter++ = 'n';
*subfmtiter++ = '\0';
if (sizeof(void*) != sizeof(long*))
abort(); /* all pointers must have the same size */
if (asterisk)
{
int v = sscanf(bufiter, subfmt, &sublen);
if (v == EOF)
return EOF;
if (v != 0)
break;
}
else
{
int v = sscanf(bufiter, subfmt, va_arg(args_copy, void*), &sublen);
if (v == EOF)
return EOF;
if (v != 1)
break;
}
ret++;
bufiter += sublen;
}
else if (isspace((unsigned char)*format))
{
while (isspace((unsigned char)*bufiter))
bufiter++;
format++;
}
else
{
if (*bufiter != *format)
break;
bufiter++;
format++;
}
}
va_end(args_copy);
filestream_seek(stream, startpos+(bufiter-buf),
RETRO_VFS_SEEK_POSITION_START);
return ret;
}
int filestream_scanf(RFILE *stream, const char* format, ...)
{
int result;
va_list vl;
va_start(vl, format);
result = filestream_vscanf(stream, format, &vl);
va_end(vl);
return result;
}
int64_t filestream_seek(RFILE *stream, int64_t offset, int seek_position)
{
int64_t output;
if (filestream_seek_cb)
output = filestream_seek_cb(stream->hfile, offset, seek_position);
else
output = retro_vfs_file_seek_impl(
(libretro_vfs_implementation_file*)stream->hfile,
offset, seek_position);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
stream->eof_flag = false;
return output;
}
int filestream_eof(RFILE *stream)
{
return stream->eof_flag;
}
int64_t filestream_tell(RFILE *stream)
{
int64_t output;
if (filestream_size_cb)
output = filestream_tell_cb(stream->hfile);
else
output = retro_vfs_file_tell_impl(
(libretro_vfs_implementation_file*)stream->hfile);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
return output;
}
void filestream_rewind(RFILE *stream)
{
if (!stream)
return;
filestream_seek(stream, 0L, RETRO_VFS_SEEK_POSITION_START);
stream->error_flag = false;
stream->eof_flag = false;
}
int64_t filestream_read(RFILE *stream, void *s, int64_t len)
{
int64_t output;
if (filestream_read_cb)
output = filestream_read_cb(stream->hfile, s, len);
else
output = retro_vfs_file_read_impl(
(libretro_vfs_implementation_file*)stream->hfile, s, len);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
if (output < len)
stream->eof_flag = true;
return output;
}
int filestream_flush(RFILE *stream)
{
int output;
if (filestream_flush_cb)
output = filestream_flush_cb(stream->hfile);
else
output = retro_vfs_file_flush_impl(
(libretro_vfs_implementation_file*)stream->hfile);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
return output;
}
int filestream_delete(const char *path)
{
if (filestream_remove_cb)
return filestream_remove_cb(path);
return retro_vfs_file_remove_impl(path);
}
int filestream_rename(const char *old_path, const char *new_path)
{
if (filestream_rename_cb)
return filestream_rename_cb(old_path, new_path);
return retro_vfs_file_rename_impl(old_path, new_path);
}
const char* filestream_get_path(RFILE *stream)
{
if (filestream_get_path_cb)
return filestream_get_path_cb(stream->hfile);
return retro_vfs_file_get_path_impl(
(libretro_vfs_implementation_file*)stream->hfile);
}
int64_t filestream_write(RFILE *stream, const void *s, int64_t len)
{
int64_t output;
if (filestream_write_cb)
output = filestream_write_cb(stream->hfile, s, len);
else
output = retro_vfs_file_write_impl(
(libretro_vfs_implementation_file*)stream->hfile, s, len);
if (output == VFS_ERROR_RETURN_VALUE)
stream->error_flag = true;
return output;
}
int filestream_putc(RFILE *stream, int c)
{
char c_char = (char)c;
if (!stream)
return EOF;
return filestream_write(stream, &c_char, 1) == 1
? (int)(unsigned char)c
: EOF;
}
int filestream_vprintf(RFILE *stream, const char* format, va_list args)
{
static char buffer[8 * 1024];
int64_t num_chars = vsnprintf(buffer, sizeof(buffer),
format, args);
if (num_chars < 0)
return -1;
else if (num_chars == 0)
return 0;
return (int)filestream_write(stream, buffer, num_chars);
}
int filestream_printf(RFILE *stream, const char* format, ...)
{
va_list vl;
int result;
va_start(vl, format);
result = filestream_vprintf(stream, format, vl);
va_end(vl);
return result;
}
int filestream_error(RFILE *stream)
{
if (stream && stream->error_flag)
return 1;
return 0;
}
int filestream_close(RFILE *stream)
{
int output;
struct retro_vfs_file_handle* fp = stream->hfile;
if (filestream_close_cb)
output = filestream_close_cb(fp);
else
output = retro_vfs_file_close_impl(
(libretro_vfs_implementation_file*)fp);
if (output == 0)
free(stream);
return output;
}
/**
* filestream_read_file:
* @path : path to file.
* @buf : buffer to allocate and read the contents of the
* file into. Needs to be freed manually.
* @len : optional output integer containing bytes read.
*
* Read the contents of a file into @buf.
*
* Returns: non zero on success.
*/
int64_t filestream_read_file(const char *path, void **buf, int64_t *len)
{
int64_t ret = 0;
int64_t content_buf_size = 0;
void *content_buf = NULL;
RFILE *file = filestream_open(path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!file)
{
*buf = NULL;
return 0;
}
content_buf_size = filestream_get_size(file);
if (content_buf_size < 0)
goto error;
content_buf = malloc((size_t)(content_buf_size + 1));
if (!content_buf)
goto error;
if ((int64_t)(uint64_t)(content_buf_size + 1) != (content_buf_size + 1))
goto error;
ret = filestream_read(file, content_buf, (int64_t)content_buf_size);
if (ret < 0)
goto error;
if (filestream_close(file) != 0)
if (file)
free(file);
*buf = content_buf;
/* Allow for easy reading of strings to be safe.
* Will only work with sane character formatting (Unix). */
((char*)content_buf)[ret] = '\0';
if (len)
*len = ret;
return 1;
error:
if (file)
if (filestream_close(file) != 0)
free(file);
if (content_buf)
free(content_buf);
if (len)
*len = -1;
*buf = NULL;
return 0;
}
/**
* filestream_write_file:
* @path : path to file.
* @data : contents to write to the file.
* @size : size of the contents.
*
* Writes data to a file.
*
* Returns: true (1) on success, false (0) otherwise.
*/
bool filestream_write_file(const char *path, const void *data, int64_t size)
{
int64_t ret = 0;
RFILE *file = filestream_open(path,
RETRO_VFS_FILE_ACCESS_WRITE,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!file)
return false;
ret = filestream_write(file, data, size);
if (filestream_close(file) != 0)
if (file)
free(file);
if (ret != size)
return false;
return true;
}
/* Returned pointer must be freed by the caller. */
char* filestream_getline(RFILE *stream)
{
char *newline_tmp = NULL;
size_t cur_size = 8;
size_t idx = 0;
int in = 0;
char *newline = (char*)malloc(9);
if (!stream || !newline)
{
if (newline)
free(newline);
return NULL;
}
in = filestream_getc(stream);
while (in != EOF && in != '\n')
{
if (idx == cur_size)
{
cur_size *= 2;
newline_tmp = (char*)realloc(newline, cur_size + 1);
if (!newline_tmp)
{
free(newline);
return NULL;
}
newline = newline_tmp;
}
newline[idx++] = in;
in = filestream_getc(stream);
}
newline[idx] = '\0';
return newline;
}
libretro_vfs_implementation_file* filestream_get_vfs_handle(RFILE *stream)
{
return (libretro_vfs_implementation_file*)stream->hfile;
}

View File

@@ -0,0 +1,159 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_stream_transforms.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 <string.h>
#include <stdarg.h>
#include <libretro.h>
#include <streams/file_stream.h>
RFILE* rfopen(const char *path, const char *mode)
{
RFILE *output = NULL;
unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ;
bool position_to_end = false;
if (strstr(mode, "r"))
{
retro_mode = RETRO_VFS_FILE_ACCESS_READ;
if (strstr(mode, "+"))
{
retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE |
RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
}
}
else if (strstr(mode, "w"))
{
retro_mode = RETRO_VFS_FILE_ACCESS_WRITE;
if (strstr(mode, "+"))
retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE;
}
else if (strstr(mode, "a"))
{
retro_mode = RETRO_VFS_FILE_ACCESS_WRITE |
RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
position_to_end = true;
if (strstr(mode, "+"))
{
retro_mode = RETRO_VFS_FILE_ACCESS_READ_WRITE |
RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING;
}
}
output = filestream_open(path, retro_mode,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (output && position_to_end)
filestream_seek(output, 0, RETRO_VFS_SEEK_POSITION_END);
return output;
}
int rfclose(RFILE* stream)
{
return filestream_close(stream);
}
int64_t rftell(RFILE* stream)
{
return filestream_tell(stream);
}
int64_t rfseek(RFILE* stream, int64_t offset, int origin)
{
int seek_position = -1;
switch (origin)
{
case SEEK_SET:
seek_position = RETRO_VFS_SEEK_POSITION_START;
break;
case SEEK_CUR:
seek_position = RETRO_VFS_SEEK_POSITION_CURRENT;
break;
case SEEK_END:
seek_position = RETRO_VFS_SEEK_POSITION_END;
break;
}
return filestream_seek(stream, offset, seek_position);
}
int64_t rfread(void* buffer,
size_t elem_size, size_t elem_count, RFILE* stream)
{
return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size);
}
char *rfgets(char *buffer, int maxCount, RFILE* stream)
{
return filestream_gets(stream, buffer, maxCount);
}
int rfgetc(RFILE* stream)
{
return filestream_getc(stream);
}
int64_t rfwrite(void const* buffer,
size_t elem_size, size_t elem_count, RFILE* stream)
{
return filestream_write(stream, buffer, elem_size * elem_count);
}
int rfputc(int character, RFILE * stream)
{
return filestream_putc(stream, character);
}
int64_t rfflush(RFILE * stream)
{
return filestream_flush(stream);
}
int rfprintf(RFILE * stream, const char * format, ...)
{
int result;
va_list vl;
va_start(vl, format);
result = filestream_vprintf(stream, format, vl);
va_end(vl);
return result;
}
int rferror(RFILE* stream)
{
return filestream_error(stream);
}
int rfeof(RFILE* stream)
{
return filestream_eof(stream);
}
int rfscanf(RFILE * stream, const char * format, ...)
{
int result;
va_list vl;
va_start(vl, format);
result = filestream_vscanf(stream, format, &vl);
va_end(vl);
return result;
}

View File

@@ -187,88 +187,207 @@ char *string_trim_whitespace(char *const s)
return s;
}
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode, unsigned max_lines)
void word_wrap(char *dst, size_t dst_size, const char *src, int line_width, int wideglyph_width, unsigned max_lines)
{
unsigned i = 0;
unsigned len = (unsigned)strlen(string);
unsigned lines = 1;
char *lastspace = NULL;
unsigned counter = 0;
unsigned lines = 1;
size_t src_len = strlen(src);
const char *src_end = src + src_len;
while (i < len)
/* Prevent buffer overflow */
if (dst_size < src_len + 1)
return;
/* Early return if src string length is less
* than line width */
if (src_len < line_width)
{
unsigned counter;
int pos = (int)(&buffer[i] - buffer);
strcpy(dst, src);
return;
}
/* copy string until the end of the line is reached */
for (counter = 1; counter <= (unsigned)line_width; counter++)
while (*src != '\0')
{
unsigned char_len;
char_len = (unsigned)(utf8skip(src, 1) - src);
counter++;
if (*src == ' ')
lastspace = dst; /* Remember the location of the whitespace */
else if (*src == '\n')
{
const char *character;
unsigned char_len;
unsigned j = i;
/* If newlines embedded in the input,
* reset the index */
lines++;
counter = 0;
/* check if end of string reached */
if (i == len)
/* Early return if remaining src string
* length is less than line width */
if (src_end - src <= line_width)
{
buffer[i] = 0;
return buffer;
strcpy(dst, src);
return;
}
}
character = utf8skip(&string[i], 1);
char_len = (unsigned)(character - &string[i]);
while (char_len--)
*dst++ = *src++;
if (!unicode)
counter += char_len - 1;
do
{
buffer[i] = string[i];
char_len--;
i++;
} while (char_len);
/* check for newlines embedded in the original input
* and reset the index */
if (buffer[j] == '\n')
{
lines++;
counter = 1;
}
}
/* check for whitespace */
if (string[i] == ' ')
if (counter >= (unsigned)line_width)
{
if ((max_lines == 0 || lines < max_lines))
counter = 0;
if (lastspace && (max_lines == 0 || lines < max_lines))
{
buffer[i] = '\n';
i++;
/* Replace nearest (previous) whitespace
* with newline character */
*lastspace = '\n';
lines++;
src -= dst - lastspace - 1;
dst = lastspace + 1;
lastspace = NULL;
/* Early return if remaining src string
* length is less than line width */
if (src_end - src < line_width)
{
strcpy(dst, src);
return;
}
}
}
else
{
int k;
/* check for nearest whitespace back in string */
for (k = i; k > 0; k--)
{
if (string[k] != ' ' || (max_lines != 0 && lines >= max_lines))
continue;
buffer[k] = '\n';
/* set string index back to character after this one */
i = k + 1;
lines++;
break;
}
if (&buffer[i] - buffer == pos)
return buffer;
}
}
buffer[i] = 0;
*dst = '\0';
}
return buffer;
void word_wrap_wideglyph(char *dst, size_t dst_size, const char *src, int line_width, int wideglyph_width, unsigned max_lines)
{
char *lastspace = NULL;
char *lastwideglyph = NULL;
const char *src_end = src + strlen(src);
unsigned lines = 1;
/* 'line_width' means max numbers of characters per line,
* but this metric is only meaningful when dealing with
* 'regular' glyphs that have an on-screen pixel width
* similar to that of regular Latin characters.
* When handing so-called 'wide' Unicode glyphs, it is
* necessary to consider the actual on-screen pixel width
* of each character.
* In order to do this, we create a distinction between
* regular Latin 'non-wide' glyphs and 'wide' glyphs, and
* normalise all values relative to the on-screen pixel
* width of regular Latin characters:
* - Regular 'non-wide' glyphs have a normalised width of 100
* - 'line_width' is therefore normalised to 100 * (width_in_characters)
* - 'wide' glyphs have a normalised width of
* 100 * (wide_character_pixel_width / latin_character_pixel_width)
* - When a character is detected, the position in the current
* line is incremented by the regular normalised width of 100
* - If that character is then determined to be a 'wide'
* glyph, the position in the current line is further incremented
* by the difference between the normalised 'wide' and 'non-wide'
* width values */
unsigned counter_normalized = 0;
int line_width_normalized = line_width * 100;
int additional_counter_normalized = wideglyph_width - 100;
/* Early return if src string length is less
* than line width */
if (src_end - src < line_width)
{
strlcpy(dst, src, dst_size);
return;
}
while (*src != '\0')
{
unsigned char_len;
char_len = (unsigned)(utf8skip(src, 1) - src);
counter_normalized += 100;
/* Prevent buffer overflow */
if (char_len >= dst_size)
break;
if (*src == ' ')
lastspace = dst; /* Remember the location of the whitespace */
else if (*src == '\n')
{
/* If newlines embedded in the input,
* reset the index */
lines++;
counter_normalized = 0;
/* Early return if remaining src string
* length is less than line width */
if (src_end - src <= line_width)
{
strlcpy(dst, src, dst_size);
return;
}
}
else if (char_len >= 3)
{
/* Remember the location of the first byte
* whose length as UTF-8 >= 3*/
lastwideglyph = dst;
counter_normalized += additional_counter_normalized;
}
dst_size -= char_len;
while (char_len--)
*dst++ = *src++;
if (counter_normalized >= (unsigned)line_width_normalized)
{
counter_normalized = 0;
if (max_lines != 0 && lines >= max_lines)
continue;
else if (lastwideglyph && (!lastspace || lastwideglyph > lastspace))
{
/* Insert newline character */
*lastwideglyph = '\n';
lines++;
src -= dst - lastwideglyph;
dst = lastwideglyph + 1;
lastwideglyph = NULL;
/* Early return if remaining src string
* length is less than line width */
if (src_end - src <= line_width)
{
strlcpy(dst, src, dst_size);
return;
}
}
else if (lastspace)
{
/* Replace nearest (previous) whitespace
* with newline character */
*lastspace = '\n';
lines++;
src -= dst - lastspace - 1;
dst = lastspace + 1;
lastspace = NULL;
/* Early return if remaining src string
* length is less than line width */
if (src_end - src < line_width)
{
strlcpy(dst, src, dst_size);
return;
}
}
}
}
*dst = '\0';
}
/* Splits string into tokens seperated by 'delim'

View File

@@ -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 <rthreads/rthreads.h>
#include <retro_assert.h>
#include <stdlib.h>
#endif
#include <string.h>
#include <time/rtime.h>
#ifdef HAVE_THREADS
/* TODO/FIXME - global */
slock_t *rtime_localtime_lock = NULL;
#endif
/* Must be called before using rtime_localtime() */
void rtime_init(void)
{
rtime_deinit();
#ifdef HAVE_THREADS
if (!rtime_localtime_lock)
rtime_localtime_lock = slock_new();
retro_assert(rtime_localtime_lock);
#endif
}
/* Must be called upon program termination */
void rtime_deinit(void)
{
#ifdef HAVE_THREADS
if (rtime_localtime_lock)
{
slock_free(rtime_localtime_lock);
rtime_localtime_lock = NULL;
}
#endif
}
/* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result)
{
struct tm *time_info = NULL;
/* Lock mutex */
#ifdef HAVE_THREADS
slock_lock(rtime_localtime_lock);
#endif
time_info = localtime(timep);
if (time_info)
memcpy(result, time_info, sizeof(struct tm));
/* Unlock mutex */
#ifdef HAVE_THREADS
slock_unlock(rtime_localtime_lock);
#endif
return result;
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,14 @@
#include <stdarg.h>
#include <ctype.h>
#ifdef _MSC_VER
#include <compat/msvc.h>
#endif
#include <libretro.h>
#include <compat/fopen_utf8.h>
#include <string/stdstring.h>
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <streams/memory_stream.h>
#include <libretro_dipswitch.h>
#include <libretro_core_options.h>
@@ -288,13 +294,6 @@ void FCEUD_SoundToggle (void)
FCEUI_SetSoundVolume(sndvolume);
}
FILE *FCEUD_UTF8fopen(const char *n, const char *m)
{
if (n)
return fopen_utf8(n, m);
return NULL;
}
/*palette for FCEU*/
#define PAL_TOTAL 16 /* total no. of palettes in palettes[] */
#define PAL_DEFAULT (PAL_TOTAL + 1)
@@ -1027,6 +1026,8 @@ static void set_variables(void)
void retro_set_environment(retro_environment_t cb)
{
struct retro_vfs_interface_info vfs_iface_info;
static const struct retro_controller_description pads1[] = {
{ "Auto", RETRO_DEVICE_AUTO },
{ "Gamepad", RETRO_DEVICE_GAMEPAD },
@@ -1073,13 +1074,31 @@ void retro_set_environment(retro_environment_t cb)
{ 0, 0 },
};
static const struct retro_system_content_info_override content_overrides[] = {
{
"fds|nes|unf|unif", /* extensions */
false, /* need_fullpath */
false /* persistent_data */
},
{ NULL, false, false }
};
environ_cb = cb;
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
vfs_iface_info.required_interface_version = 1;
vfs_iface_info.iface = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VFS_INTERFACE, &vfs_iface_info))
filestream_vfs_init(&vfs_iface_info);
environ_cb(RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE,
(void*)content_overrides);
}
void retro_get_system_info(struct retro_system_info *info)
{
info->need_fullpath = false;
info->need_fullpath = true;
info->valid_extensions = "fds|nes|unf|unif";
#ifdef GIT_VERSION
info->library_version = "(SVN)" GIT_VERSION;
@@ -2413,17 +2432,10 @@ static const struct cartridge_db famicom_4p_db_list[] =
}
};
#ifdef _WIN32
static char slash = '\\';
#else
static char slash = '/';
#endif
bool retro_load_game(const struct retro_game_info *game)
bool retro_load_game(const struct retro_game_info *info)
{
unsigned i, j;
char* dir=NULL;
char* sav_dir=NULL;
const char *system_dir = NULL;
size_t fourscore_len = sizeof(fourscore_db_list) / sizeof(fourscore_db_list[0]);
size_t famicom_4p_len = sizeof(famicom_4p_db_list) / sizeof(famicom_4p_db_list[0]);
enum retro_pixel_format rgb565;
@@ -2482,8 +2494,43 @@ bool retro_load_game(const struct retro_game_info *game)
struct retro_memory_descriptor descs[64 + 4];
struct retro_memory_map mmaps;
if (!game)
return false;
struct retro_game_info_ext *info_ext = NULL;
const uint8_t *content_data = NULL;
size_t content_size = 0;
char content_path[2048] = {0};
/* Attempt to fetch extended game info */
if (environ_cb(RETRO_ENVIRONMENT_GET_GAME_INFO_EXT, &info_ext) && info_ext)
{
content_data = (const uint8_t *)info_ext->data;
content_size = info_ext->size;
if (info_ext->file_in_archive)
{
/* We don't have a 'physical' file in this
* case, but the core still needs a filename
* in order to detect the region of iNES v1.0
* ROMs. We therefore fake it, using the content
* directory, canonical content name, and content
* file extension */
snprintf(content_path, sizeof(content_path), "%s%c%s.%s",
info_ext->dir,
PATH_DEFAULT_SLASH_C(),
info_ext->name,
info_ext->ext);
}
else
strlcpy(content_path, info_ext->full_path,
sizeof(content_path));
}
else
{
if (!info || string_is_empty(info->path))
return false;
strlcpy(content_path, info->path,
sizeof(content_path));
}
#ifdef FRONTEND_SUPPORTS_RGB565
rgb565 = RETRO_PIXEL_FORMAT_RGB565;
@@ -2524,10 +2571,8 @@ bool retro_load_game(const struct retro_game_info *game)
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
FCEUI_SetBaseDirectory(dir);
if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &sav_dir) && sav_dir)
FCEUI_SetSaveDirectory(sav_dir);
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir)
FCEUI_SetBaseDirectory(system_dir);
memset(base_palette, 0, sizeof(base_palette));
@@ -2536,7 +2581,7 @@ bool retro_load_game(const struct retro_game_info *game)
FCEUI_SetSoundVolume(sndvolume);
FCEUI_Sound(sndsamplerate);
GameInfo = (FCEUGI*)FCEUI_LoadGame(game->path, (uint8_t*)game->data, game->size);
GameInfo = (FCEUGI*)FCEUI_LoadGame(content_path, content_data, content_size);
if (!GameInfo)
{
struct retro_message msg;
@@ -2557,7 +2602,8 @@ bool retro_load_game(const struct retro_game_info *game)
external_palette_exist = ipalette;
if (external_palette_exist)
FCEU_printf(" Loading custom palette: %s%cnes.pal\n", dir, slash);
FCEU_printf(" Loading custom palette: %s%cnes.pal\n",
system_dir, PATH_DEFAULT_SLASH_C());
/* Save region and dendy mode for region-auto detect */
systemRegion = (dendy << 1) | (retro_get_region() & 1);

View File

@@ -46,37 +46,6 @@ void FlipByteOrder(uint8 *src, uint32 count)
}
}
int write16le(uint16 b, FILE *fp)
{
uint8 s[2];
s[0] = b;
s[1] = b >> 8;
return((fwrite(s, 1, 2, fp) < 2) ? 0 : 2);
}
int write32le(uint32 b, FILE *fp)
{
uint8 s[4];
s[0] = b;
s[1] = b >> 8;
s[2] = b >> 16;
s[3] = b >> 24;
return((fwrite(s, 1, 4, fp) < 4) ? 0 : 4);
}
int read32le(uint32 *Bufo, FILE *fp)
{
uint32 buf;
if (fread(&buf, 1, 4, fp) < 4)
return 0;
#ifdef MSB_FIRST
*(uint32*)Bufo = ((buf & 0xFF) << 24) | ((buf & 0xFF00) << 8) | ((buf & 0xFF0000) >> 8) | ((buf & 0xFF000000) >> 24);
#else
*(uint32*)Bufo = buf;
#endif
return 1;
}
int write32le_mem(uint32 b, memstream_t *mem)
{
uint8 s[4];
@@ -100,18 +69,6 @@ int read32le_mem(uint32 *Bufo, memstream_t *mem)
return 1;
}
int read16le(char *d, FILE *fp)
{
#ifdef MSB_FIRST
int ret;
ret = fread(d + 1, 1, 1, fp);
ret += fread(d, 1, 1, fp);
return ret < 2 ? 0 : 2;
#else
return((fread(d, 1, 2, fp) < 2) ? 0 : 2);
#endif
}
void FCEU_en32lsb(uint8 *buf, uint32 morp)
{
buf[0] = morp;
@@ -120,7 +77,7 @@ void FCEU_en32lsb(uint8 *buf, uint32 morp)
buf[3] = morp >> 24;
}
uint32 FCEU_de32lsb(uint8 *morp)
uint32 FCEU_de32lsb(const uint8 *morp)
{
return(morp[0] | (morp[1] << 8) | (morp[2] << 16) | (morp[3] << 24));
}

View File

@@ -2,17 +2,14 @@
#define _FCEU_ENDIAN_H
#include "fceu-memory.h"
#include "drivers/libretro/libretro-common/include/streams/memory_stream.h"
#include <streams/memory_stream.h>
int write32le_mem(uint32 b, memstream_t *mem);
int read32le_mem(uint32 *Bufo, memstream_t *mem);
int write16le(uint16 b, FILE *fp);
int write32le(uint32 b, FILE *fp);
int read32le(uint32 *Bufo, FILE *fp);
void FlipByteOrder(uint8 *src, uint32 count);
void FCEU_en32lsb(uint8 *, uint32);
uint32 FCEU_de32lsb(uint8 *);
uint32 FCEU_de32lsb(const uint8 *);
#endif

View File

@@ -29,23 +29,6 @@
#define FCEU_dwmemset(d, c, n) { int _x; for (_x = n - 4; _x >= 0; _x -= 4) *(uint32*)& (d)[_x] = c; }
#if defined(STATE_LIBRETRO) || defined(ENDIAN_LIBRETRO) || defined(GENERAL_LIBRETRO)
#include "drivers/libretro/libretro-common/include/streams/memstream.h"
#define HAVE_MEMSTREAM
#define MEM_TYPE memstream_t
#define fwrite(ptr, size, nmemb, stream) memstream_write((stream), (ptr), (nmemb))
#define fclose(fp) memstream_close((fp))
#define fgetc(stream) memstream_getc((stream))
#define fputc(c, stream) memstream_putc((stream), (c))
#define ftell(a) memstream_pos((a))
#define fread(ptr, size, nmemb, stream) memstream_read((stream), (ptr), (nmemb))
#define fseek(stream, offset, whence) memstream_seek((stream), (offset), (whence))
#else
#define MEM_TYPE FILE
#endif
void *FCEU_malloc(uint32 size);
void *FCEU_gmalloc(uint32 size);
void FCEU_gfree(void *ptr);

View File

@@ -41,9 +41,6 @@ typedef unsigned __int64 uint64;
#define GINLINE /* Can't declare a function INLINE
* and global in MSVC. Bummer.
*/
#define PSS_STYLE 2 /* Does MSVC compile for anything
* other than Windows/DOS targets?
*/
#else
typedef unsigned long long uint64;
typedef long long int64;
@@ -62,29 +59,6 @@ typedef long long int64;
#endif
#endif
#if PSS_STYLE == 2
#define PSS "\\"
#define PS '\\'
#elif PSS_STYLE == 1
#define PSS "/"
#define PS '/'
#elif PSS_STYLE == 3
#define PSS "\\"
#define PS '\\'
#elif PSS_STYLE == 4
#define PSS ":"
#define PS ':'
#endif
#ifdef __GNUC__
#ifdef C80x86
#define FASTAPASS(x) __attribute__((regparm(x)))

View File

@@ -193,7 +193,7 @@ void FCEUI_CloseGame(void)
free(GameInfo->name);
GameInfo->name = 0;
if (GameInfo->type != GIT_NSF)
FCEU_FlushGameCheats(0, 0);
FCEU_FlushGameCheats();
GameInterface(GI_CLOSE);
ResetExState(0, 0);
FCEU_CloseGenie();
@@ -226,7 +226,7 @@ int iNESLoad(const char *name, FCEUFILE *fp);
int FDSLoad(const char *name, FCEUFILE *fp);
int NSFLoad(FCEUFILE *fp);
FCEUGI *FCEUI_LoadGame(const char *name, uint8_t *databuf, size_t databufsize)
FCEUGI *FCEUI_LoadGame(const char *name, const uint8_t *databuf, size_t databufsize)
{
FCEUFILE *fp;
@@ -244,9 +244,7 @@ FCEUGI *FCEUI_LoadGame(const char *name, uint8_t *databuf, size_t databufsize)
GameInfo->inputfc = -1;
GameInfo->cspecial = 0;
GetFileBase(name);
fp = FCEU_fopen(name, NULL, "rb", 0, databuf, databufsize);
fp = FCEU_fopen(name, databuf, databufsize);
if (!fp) {
FCEU_PrintError("Error opening \"%s\"!", name);
@@ -278,7 +276,7 @@ endlseq:
if (GameInfo->type != GIT_NSF) {
FCEU_LoadGamePalette();
FCEU_LoadGameCheats(0);
FCEU_LoadGameCheats();
}
FCEU_ResetPalette();
@@ -321,7 +319,7 @@ FCEUGI *FCEUI_CopyFamiStart(void)
if (GameInfo->type != GIT_NSF) {
FCEU_LoadGamePalette();
FCEU_LoadGameCheats(0);
FCEU_LoadGameCheats();
}
FCEU_ResetPalette();

View File

@@ -708,7 +708,7 @@ int FDSLoad(const char *name, FCEUFILE *fp) {
char *fn = FCEU_MakeFName(FCEUMKF_FDSROM, 0, 0);
if (!(zp = FCEU_fopen(fn, 0, "rb", 0, NULL, 0))) {
if (!(zp = FCEU_fopen(fn, NULL, 0))) {
FCEU_PrintError("FDS BIOS ROM image missing!\n");
free(fn);
return 0;
@@ -728,13 +728,11 @@ int FDSLoad(const char *name, FCEUFILE *fp) {
if (FDSBIOS)
free(FDSBIOS);
FDSBIOS = NULL;
free(zp->fp->data);
FCEU_fclose(zp);
FCEU_PrintError("Error reading FDS BIOS ROM image.\n");
return 0;
}
free(zp->fp->data);
FCEU_fclose(zp);
FCEU_fseek(fp, 0, SEEK_SET);
@@ -753,37 +751,6 @@ int FDSLoad(const char *name, FCEUFILE *fp) {
DiskWritten = 1;
#if 0
/* auxillary rom loading for save file is now handled
* using retro_get_memory_size/data */
{
FCEUFILE *tp;
char *fn = FCEU_MakeFName(FCEUMKF_FDS, 0, 0);
int x;
for (x = 0; x < TotalSides; x++) {
diskdatao[x] = (uint8*)FCEU_malloc(65500);
memcpy(diskdatao[x], diskdata[x], 65500);
}
if ((tp = FCEU_fopen(fn, 0, "rb", 0, NULL, 0))) {
FCEU_printf("Disk was written. Auxillary FDS file open \"%s\".\n", fn);
FreeFDSMemory();
if (!SubLoad(tp)) {
FCEU_PrintError("Error reading auxillary FDS file.\n");
if (FDSBIOS)
free(FDSBIOS);
FDSBIOS = NULL;
free(fn);
return(0);
}
FCEU_fclose(tp);
DiskWritten = 1; /* For save state handling. */
}
free(fn);
}
#endif
GameInfo->type = GIT_FDS;
GameInterface = FDSGI;

View File

@@ -27,6 +27,9 @@
#include <unistd.h>
#endif
#include <string/stdstring.h>
#include <streams/file_stream.h>
#include "fceu-types.h"
#include "file.h"
#include "fceu-endian.h"
@@ -34,30 +37,33 @@
#include "driver.h"
#include "general.h"
static MEMWRAP *MakeMemWrap(void *tz, int type)
static MEMWRAP *MakeMemWrap(RFILE *tz)
{
MEMWRAP *tmp;
MEMWRAP *tmp = NULL;
if (!(tmp = (MEMWRAP*)FCEU_malloc(sizeof(MEMWRAP))))
goto doret;
tmp->location = 0;
fseek((FILE*)tz, 0, SEEK_END);
tmp->size = ftell((FILE*)tz);
fseek((FILE*)tz, 0, SEEK_SET);
if (!(tmp->data = (uint8*)FCEU_malloc(tmp->size)))
filestream_seek(tz, 0, RETRO_VFS_SEEK_POSITION_END);
tmp->size = filestream_tell(tz);
filestream_seek(tz, 0, RETRO_VFS_SEEK_POSITION_START);
if (!(tmp->data_int = (uint8*)FCEU_malloc(tmp->size)))
{
free(tmp);
tmp = 0;
tmp = NULL;
goto doret;
}
fread(tmp->data, 1, tmp->size, (FILE*)tz);
filestream_read(tz, tmp->data_int, tmp->size);
tmp->data = tmp->data_int;
doret:
return tmp;
}
static MEMWRAP *MakeMemWrapBuffer(uint8 *buffer, size_t bufsize)
static MEMWRAP *MakeMemWrapBuffer(const uint8 *buffer, size_t bufsize)
{
MEMWRAP *tmp = (MEMWRAP*)FCEU_malloc(sizeof(MEMWRAP));
@@ -66,43 +72,57 @@ static MEMWRAP *MakeMemWrapBuffer(uint8 *buffer, size_t bufsize)
tmp->location = 0;
tmp->size = bufsize;
tmp->data_int = NULL;
tmp->data = buffer;
return tmp;
}
FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn,
char *mode, char *ext, uint8 *buffer, size_t bufsize)
FCEUFILE * FCEU_fopen(const char *path, const uint8 *buffer, size_t bufsize)
{
FCEUFILE *fceufp = (FCEUFILE*)malloc(sizeof(FCEUFILE));
fceufp->type = 0;
if (buffer)
fceufp->fp = MakeMemWrapBuffer(buffer, bufsize);
else
{
void *t = FCEUD_UTF8fopen(path, mode);
RFILE *t = NULL;
if (!string_is_empty(path))
t = filestream_open(path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!t)
{
free(fceufp);
return 0;
return NULL;
}
fseek((FILE*)t, 0, SEEK_SET);
fceufp->fp = MakeMemWrap(t, 0);
fclose((FILE*)t);
fceufp->fp = MakeMemWrap(t);
filestream_close(t);
}
return fceufp;
}
int FCEU_fclose(FCEUFILE *fp)
{
if (!fp)
return 0;
if (fp->fp)
{
if (fp->fp->data_int)
free(fp->fp->data_int);
fp->fp->data_int = NULL;
free(fp->fp);
}
fp->fp = NULL;
free(fp);
fp = 0;
fp = NULL;
return 1;
}

View File

@@ -2,27 +2,23 @@
#define _FCEU_FILE_H
typedef struct {
uint8 *data;
uint32 size;
uint32 location;
uint8 *data_int;
const uint8 *data;
uint32 size;
uint32 location;
} MEMWRAP;
typedef struct {
MEMWRAP *fp;
uint32 type; /* 0=normal file, 1=gzip, 2=zip */
} FCEUFILE;
FCEUFILE *FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, uint8 *buffer, size_t bufsize);
FCEUFILE *FCEU_fopen(const char *path, const uint8 *buffer, size_t bufsize);
int FCEU_fclose(FCEUFILE*);
uint64 FCEU_fread(void *ptr, size_t size, size_t nmemb, FCEUFILE*);
uint64 FCEU_fwrite(void *ptr, size_t size, size_t nmemb, FCEUFILE*);
int FCEU_fseek(FCEUFILE*, long offset, int whence);
uint64 FCEU_ftell(FCEUFILE*);
void FCEU_rewind(FCEUFILE*);
int FCEU_read32le(uint32 *Bufo, FCEUFILE*);
int FCEU_read16le(uint16 *Bufo, FCEUFILE*);
int FCEU_fgetc(FCEUFILE*);
uint64 FCEU_fgetsize(FCEUFILE*);
int FCEU_fisarchive(FCEUFILE*);
#endif

View File

@@ -31,6 +31,8 @@
#include <unistd.h>
#endif
#include <file/file_path.h>
#include "fceu-types.h"
#include "fceu.h"
@@ -41,25 +43,14 @@
#include "md5.h"
static char BaseDirectory[2048];
static char SaveDirectory[2048];
static char FileBase[2048];
static char FileExt[2048]; /* Includes the . character, as in ".nes" */
static char BaseDirectory[2048] = {0};
static char FileBaseDirectory[2048];
void FCEUI_SetBaseDirectory(char *dir)
void FCEUI_SetBaseDirectory(const char *dir)
{
strncpy(BaseDirectory, dir, 2047);
BaseDirectory[2047] = 0;
}
void FCEUI_SetSaveDirectory(char *sav_dir)
{
strncpy(SaveDirectory, sav_dir, 2047);
SaveDirectory[2047] = 0;
}
static char *odirs[FCEUIOD__COUNT] = { 0, 0, 0, 0, 0, 0 }; /* odirs, odors. ^_^ */
void FCEUI_SetDirOverride(int which, char *n)
@@ -75,16 +66,16 @@ char *FCEU_MakeFName(int type, int id1, char *cd1)
switch (type)
{
case FCEUMKF_GGROM:
sprintf(tmp, "%s%c%s", BaseDirectory, PS, "gg.rom");
fill_pathname_join(tmp, BaseDirectory,
"gg.rom", sizeof(tmp));
break;
case FCEUMKF_FDSROM:
sprintf(tmp, "%s%c%s", BaseDirectory, PS, "disksys.rom");
fill_pathname_join(tmp, BaseDirectory,
"disksys.rom", sizeof(tmp));
break;
case FCEUMKF_PALETTE:
sprintf(tmp, "%s%c%s", BaseDirectory, PS, "nes.pal");
break;
case FCEUMKF_FDS:
sprintf(tmp, "%s%c%s%s", SaveDirectory, PS, FileBase, ".sav");
fill_pathname_join(tmp, BaseDirectory,
"nes.pal", sizeof(tmp));
break;
default:
break;
@@ -98,46 +89,6 @@ char *FCEU_MakeFName(int type, int id1, char *cd1)
return(ret);
}
void GetFileBase(const char *f)
{
const char *tp1, *tp3;
#if PSS_STYLE == 4
tp1 = ((char*)strrchr(f, ':'));
#elif PSS_STYLE == 1
tp1 = ((char*)strrchr(f, '/'));
#else
tp1 = ((char*)strrchr(f, '\\'));
#if PSS_STYLE != 3
tp3 = ((char*)strrchr(f, '/'));
if (tp1 < tp3) tp1 = tp3;
#endif
#endif
if (!tp1)
{
tp1 = f;
strcpy(FileBaseDirectory, ".");
}
else
{
memcpy(FileBaseDirectory, f, tp1 - f);
FileBaseDirectory[tp1 - f] = 0;
tp1++;
}
if (((tp3 = strrchr(f, '.')) != NULL) && (tp3 > tp1))
{
memcpy(FileBase, tp1, tp3 - tp1);
FileBase[tp3 - tp1] = 0;
strcpy(FileExt, tp3);
}
else
{
strcpy(FileBase, tp1);
FileExt[0] = 0;
}
}
uint32 uppow2(uint32 n)
{
int x;

View File

@@ -1,17 +1,15 @@
#ifndef _FCEU_GENERAL_H
#define _FCEU_GENERAL_H
void GetFileBase(const char *f);
extern uint32 uppow2(uint32 n);
char *FCEU_MakeFName(int type, int id1, char *cd1);
enum FILE_TYPES
{
FCEUMKF_FDSROM = 1,
FCEUMKF_PALETTE,
FCEUMKF_GGROM,
FCEUMKF_FDS
FCEUMKF_FDSROM = 1,
FCEUMKF_PALETTE,
FCEUMKF_GGROM
};
#endif

View File

@@ -22,6 +22,9 @@
#include <stdlib.h>
#include <math.h>
#include <string/stdstring.h>
#include <streams/file_stream.h>
#include "fceu-types.h"
#include "fceu.h"
#include "general.h"
@@ -187,17 +190,22 @@ int ipalette = 0;
void FCEU_LoadGamePalette(void) {
uint8 ptmp[192];
FILE *fp;
char *fn;
RFILE *fp = NULL;
char *fn = NULL;
ipalette = 0;
fn = FCEU_MakeFName(FCEUMKF_PALETTE, 0, 0);
if ((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) {
int x;
fread(ptmp, 1, 192, fp);
fclose(fp);
filestream_read(fp, ptmp, 192);
filestream_close(fp);
for (x = 0; x < 64; x++) {
palettei[x].r = ptmp[x + x + x];
palettei[x].g = ptmp[x + x + x + 1];

View File

@@ -23,11 +23,6 @@
#include "fceu-memory.h"
void FCEUSS_Save(char *);
int FCEUSS_Load(char *);
int FCEUSS_SaveFP(MEM_TYPE *);
int FCEUSS_LoadFP(MEM_TYPE *);
void FCEUSS_Load_Mem(void);
void FCEUSS_Save_Mem(void);