Add VFS interface

This commit is contained in:
sonninnos committed 2021-11-09 02:10:21 +02:00
1 parent 717b49505d
commit fceb654149
13 files changed
+96 -26

No files matched your search

+1 -1
View File
@@ -290,7 +290,7 @@ CFLAGS += -DHAVE_7ZIP -D_7ZIP_ST
# CHD
HAVE_CHD = 1
CFLAGS += -std=gnu99 -DINLINE="inline" -D__LIBRETRO__
CFLAGS += -std=gnu99 -DINLINE="inline" -D__LIBRETRO__ -DUSE_LIBRETRO_VFS
include Makefile.common
+5 -5
View File
@@ -186,11 +186,6 @@ SOURCES_C += \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c
endif
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
ifeq ($(HAVE_CHD), 1)
CFLAGS += -DWITH_CHD
INCFLAGS += \
@@ -205,3 +200,8 @@ ifeq ($(HAVE_CHD), 1)
$(DEPS_DIR)/libchdr/src/libchdr_flac.c \
$(DEPS_DIR)/libchdr/src/libchdr_huffman.c
endif
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
+9
View File
@@ -20,6 +20,14 @@ typedef int32_t INT32;
typedef int16_t INT16;
typedef int8_t INT8;
#ifdef USE_LIBRETRO_VFS
#define core_file RFILE
#define core_fopen(file) rfopen(file, "rb")
#define core_fseek rfseek
#define core_ftell rftell
#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
#define core_fclose rfclose
#else /* USE_LIBRETRO_VFS */
#define core_file FILE
#define core_fopen(file) fopen(file, "rb")
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__)
@@ -34,6 +42,7 @@ typedef int8_t INT8;
#endif
#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
#define core_fclose fclose
#endif /* USE_LIBRETRO_VFS */
static UINT64 core_fsize(core_file *f)
{
+1 -1
View File
@@ -12,7 +12,7 @@ HAVE_CHD = 1
include $(CORE_DIR)/Makefile.common
COREFLAGS := -DANDROID -D__LIBRETRO__ $(CFLAGS) $(INCFLAGS) -I$(LOCAL_PATH)/include
COREFLAGS := -DANDROID -D__LIBRETRO__ -DUSE_LIBRETRO_VFS $(CFLAGS) $(INCFLAGS) -I$(LOCAL_PATH)/include
include $(CLEAR_VARS)
LOCAL_MODULE := retro
@@ -69,11 +69,17 @@ RFILE* rfopen(const char *path, const char *mode)
int rfclose(RFILE* stream)
{
if (!stream)
return EOF;
return filestream_close(stream);
}
int64_t rftell(RFILE* stream)
{
if (!stream)
return EOF;
return filestream_tell(stream);
}
@@ -93,6 +99,9 @@ int64_t rfseek(RFILE* stream, int64_t offset, int origin)
break;
}
if (!stream)
return EOF;
return filestream_seek(stream, offset, seek_position);
}
@@ -115,7 +124,7 @@ int rfgetc(RFILE* 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);
return (filestream_write(stream, buffer, elem_size * elem_count) / elem_size);
}
int rfputc(int character, RFILE * stream)
+23 -10
View File
@@ -25,6 +25,11 @@
#include "memory_uae.h"
#include "sounddep/sound.h"
#ifdef USE_LIBRETRO_VFS
#undef utf8_to_local_string_alloc
#define utf8_to_local_string_alloc strdup
#endif
unsigned int libretro_runloop_active = 0;
unsigned short int retro_bmp[RETRO_BMP_SIZE] = {0};
int defaultw = EMULATOR_DEF_WIDTH;
@@ -2423,6 +2428,14 @@ void retro_set_environment(retro_environment_t cb)
environ_cb(RETRO_ENVIRONMENT_GET_LED_INTERFACE, &led_interface);
if (led_interface.set_led_state)
led_state_cb = led_interface.set_led_state;
#ifdef USE_LIBRETRO_VFS
struct retro_vfs_interface_info vfs_iface_info;
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);
#endif
}
static void update_variables(void)
@@ -5228,7 +5241,7 @@ static bool retro_create_config(void)
if (zip_dirp->d_name[0] == '.' || strendswith(zip_dirp->d_name, "m3u") || zip_mode > 1 || browsed_file[0] != '\0')
continue;
zip_lastfile = strdup(zip_dirp->d_name);
zip_lastfile = local_to_utf8_string_alloc(zip_dirp->d_name);
/* Multi file mode, generate playlist */
if (dc_get_image_type(zip_lastfile) == DC_IMAGE_TYPE_FLOPPY ||
@@ -6132,7 +6145,7 @@ static void update_video_center_vertical(void)
thisframe_y_adjust = thisframe_y_adjust_new;
#if 0
fprintf(stdout, "FIRSTDRAWN:%6d LASTDRAWN:%6d yadjust:%3d old:%3d zoomed_h:%d\n", retro_thisframe_first_drawn_line, retro_thisframe_last_drawn_line, thisframe_y_adjust, thisframe_y_adjust_old, zoomed_height);
printf("FIRSTDRAWN:%6d LASTDRAWN:%6d yadjust:%3d old:%3d zoomed_h:%d\n", retro_thisframe_first_drawn_line, retro_thisframe_last_drawn_line, thisframe_y_adjust, thisframe_y_adjust_old, zoomed_height);
#endif
/* Remember the previous value */
@@ -6177,7 +6190,7 @@ static void update_video_center_horizontal(void)
visible_left_border = visible_left_border_new;
#if 0
fprintf(stdout, "DIWSTART :%6d DIWSTOP :%6d lborder:%3d old:%3d width:%3d\n", retro_min_diwstart, retro_max_diwstop, visible_left_border, visible_left_border_old, (retro_max_diwstop - retro_min_diwstart));
printf("DIWSTART :%6d DIWSTOP :%6d lborder:%3d old:%3d width:%3d\n", retro_min_diwstart, retro_max_diwstop, visible_left_border, visible_left_border_old, (retro_max_diwstop - retro_min_diwstart));
#endif
/* Remember the previous value */
@@ -6472,7 +6485,7 @@ static bool retro_update_av_info(void)
float aspect_ratio_old = aspect_ratio;
if (av_log)
fprintf(stdout, "* Trying to update AV timing:%d to: ntsc:%d hz:%0.4f, from video_config:%d, video_aspect:%d, hz:%0.4f\n", change_timing, isntsc, hz, video_config, video_config_aspect, retro_refresh);
printf("* Trying to update AV timing:%d to: ntsc:%d hz:%0.4f, from video_config:%d, video_aspect:%d, hz:%0.4f\n", change_timing, isntsc, hz, video_config, video_config_aspect, retro_refresh);
/* Change PAL/NTSC with a twist, thanks to Dyna Blaster
*
@@ -6560,7 +6573,7 @@ static bool retro_update_av_info(void)
if (video_config_old == video_config && retro_refresh == hz)
{
if (av_log)
fprintf(stdout, " * Already at wanted AV\n");
printf(" * Already at wanted AV\n");
change_timing = false; /* Allow other calculations but don't alter timing */
}
}
@@ -6681,7 +6694,7 @@ static bool retro_update_av_info(void)
}
#if 0
fprintf(stdout, "statusbar:%3d old:%3d offset:%3d, defaulth:%d retroh:%d\n", opt_statusbar_position, opt_statusbar_position_old, opt_statusbar_position_offset, defaulth, retroh);
printf("statusbar:%3d old:%3d offset:%3d, defaulth:%d retroh:%d\n", opt_statusbar_position, opt_statusbar_position_old, opt_statusbar_position_offset, defaulth, retroh);
#endif
/* Apply zoom mode croppings */
@@ -6833,7 +6846,7 @@ static bool retro_update_av_info(void)
opt_statusbar_position = 0;
}
#if 0
fprintf(stdout, "ztatusbar:%3d old:%3d offset:%3d, defaulth:%d retroz:%d\n", opt_statusbar_position, opt_statusbar_position_old, opt_statusbar_position_offset, defaulth, zoomed_height);
printf("ztatusbar:%3d old:%3d offset:%3d, defaulth:%d retroz:%d\n", opt_statusbar_position, opt_statusbar_position_old, opt_statusbar_position_offset, defaulth, zoomed_height);
#endif
}
@@ -6872,11 +6885,11 @@ static bool retro_update_av_info(void)
if (av_log)
{
if (change_timing)
fprintf(stdout, " * Update av_info : %dx%d %0.4fHz, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, hz, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
printf(" * Update av_info : %dx%d %0.4fHz, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, hz, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
else if (change_geometry)
fprintf(stdout, " * Update geometry: %dx%d, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
printf(" * Update geometry: %dx%d, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
else
fprintf(stdout, " * Update center : %dx%d, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
printf(" * Update center : %dx%d, zoomed: %dx%d, aspect:%0.3f, video_config:%d\n", retrow, retroh, zoomed_width, zoomed_height, retro_get_aspect_ratio(zoomed_width, zoomed_height, false), video_config_geometry);
}
/* Triggers check_prefs_changed_gfx() in vsync_handle_check() */
+4
View File
@@ -10,6 +10,10 @@
#include "zfile.h"
#ifdef USE_LIBRETRO_VFS
#include <streams/file_stream_transforms.h>
#endif
#include "libretro-glue.h"
#include "libretro-dc.h"
#include "string/stdstring.h"
+8 -5
View File
@@ -1598,7 +1598,8 @@ void zip_uncompress(char *in, char *out, char *lastfile)
int skip = 0;
unsigned x = 0;
write_filename = strdup(filename_withpath);
write_filename = local_to_utf8_string_alloc(filename_withpath);
/* Replace non-ascii chars with underscore */
for (x = 128; x < 256; x++)
string_replace_all_chars(write_filename, x, '_');
@@ -1833,9 +1834,11 @@ void sevenzip_uncompress(char *in, char *out, char *lastfile)
if (dc_get_image_type(output_path) == DC_IMAGE_TYPE_FLOPPY && lastfile != NULL)
snprintf(lastfile, RETRO_PATH_MAX, "%s", path_basename(output_path));
#if 0
/* Replace non-ascii chars with underscore */
for (x = 128; x < 256; x++)
string_replace_all_chars(output_path, x, '_');
#endif
for (j = 0; output_path[j] != 0; j++)
{
@@ -1972,12 +1975,12 @@ int make_hdf (char *hdf_path, char *hdf_size, char *device_name)
}
if (size <= 0) {
fprintf (stderr, "Invalid size\n");
printf ("Invalid size\n");
exit (EXIT_FAILURE);
}
if ((size >= (1LL << 31)) && (sizeof (off_t) < sizeof (uae_u64))) {
fprintf (stderr, "Specified size too large (2GB file size is maximum).\n");
printf ("Specified size too large (2GB file size is maximum).\n");
exit (EXIT_FAILURE);
}
@@ -1985,7 +1988,7 @@ int make_hdf (char *hdf_path, char *hdf_size, char *device_name)
/* We don't want more than (2^32)-1 blocks */
if (num_blocks >= (1LL << 32)) {
fprintf (stderr, "Specified size too large (too many blocks).\n");
printf ("Specified size too large (too many blocks).\n");
exit (EXIT_FAILURE);
}
@@ -2004,7 +2007,7 @@ int make_hdf (char *hdf_path, char *hdf_size, char *device_name)
cylinders = num_blocks / (blocks_per_track * surfaces);
if (cylinders == 0) {
fprintf (stderr, "Specified size is too small.\n");
printf ("Specified size is too small.\n");
exit (EXIT_FAILURE);
}
+17 -1
View File
@@ -66,7 +66,12 @@ int my_existstype(const char *name, int mode)
int ret = 0;
char *utf8 = NULL;
#ifdef USE_LIBRETRO_VFS
utf8 = my_strdup(name);
#else
utf8 = local_to_utf8_string_alloc(name);
#endif
if (path_is_valid(utf8))
{
switch (mode)
@@ -218,9 +223,17 @@ int my_rename(const TCHAR *oldname, const TCHAR *newname)
struct my_openfile_s *my_open(const TCHAR *name, int flags)
{
char *name_utf8;
if (log_filesys)
write_log("my_open '%s' flags=%x\n", name, flags);
#ifdef USE_LIBRETRO_VFS
name_utf8 = local_to_utf8_string_alloc(name);
#else
name_utf8 = my_strdup(name);
#endif
#ifdef FD_OPEN
int open_flags = O_BINARY;
if (flags & O_TRUNC)
@@ -250,11 +263,14 @@ struct my_openfile_s *my_open(const TCHAR *name, int flags)
if (flags & O_TRUNC)
strcpy(fopen_flags, "wb+");
fp = fopen(name, fopen_flags);
fp = fopen(name_utf8, fopen_flags);
free(fopen_flags);
fopen_flags = NULL;
#endif
free(name_utf8);
name_utf8 = NULL;
struct my_openfile_s *mos;
mos = xmalloc (struct my_openfile_s, 1);
if (!mos)
+12
View File
@@ -545,4 +545,16 @@
code using `volatile' can become incorrect without. Disable with care. */
/* #undef volatile */
#ifdef USE_LIBRETRO_VFS
#include <streams/file_stream_transforms.h>
#undef stderr
#define stderr 0
#undef putc
#define putc fputc
#undef fseeko
#define fseeko rfseek
#undef ftello
#define ftello rftell
#endif
#endif /* UAE_SYSCONFIG_H */
-1
View File
@@ -506,7 +506,6 @@ extern int gui_message_multibutton (int flags, const char *format,...);
#define ULONG unsigned long
#endif
#define _strtoui64 strtoul
#define _tcscspn(wcs, reject) wcscspn((const wchar_t*)(wcs), (const wchar_t*)(reject))
#ifndef _stat64
#define _stat64 stat64
+6
View File
@@ -32,4 +32,10 @@ extern char *my_strdup (const char *s);
# endif
#endif
#ifdef __LIBRETRO__
#define _tcscspn strcspn
#else
#define _tcscspn(wcs, reject) wcscspn((const wchar_t*)(wcs), (const wchar_t*)(reject))
#endif
#endif /* UAE_STRING_H */
-1
View File
@@ -11,7 +11,6 @@
#include "sysconfig.h"
#include "sysdeps.h"
#include <assert.h>
#include <wchar.h>
#include "cfgfile.h"
#include "threaddep/thread.h"