Use rzip to speed up cheat.dat loading - 3ds fix boot time (#1280)

This commit is contained in:
mahoneyt944 2022-01-24 08:18:30 -05:00 committed by GitHub
parent 9c0c954f0f
commit 96bb0a7e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 19 deletions

View File

@ -77,7 +77,7 @@ include:
# Nintendo 3DS
- project: 'libretro-infrastructure/ci-templates'
file: '/ctr-static.yml'
file: '/ctr-legacy-static.yml'
# Nintendo WiiU
- project: 'libretro-infrastructure/ci-templates'
@ -276,7 +276,7 @@ libretro-build-vita:
# Nintendo 3DS
libretro-build-ctr:
extends:
- .libretro-ctr-static-retroarch-master
- .libretro-ctr-legacy-static-retroarch-master
- .core-defs
only:
- master

View File

@ -802,6 +802,9 @@ CFLAGS += -DHAVE_SOCKLEN_T
CFLAGS += -D_LARGEFILE_SOURCE
CFLAGS += -D_FILE_OFFSET_BITS=64
# Required for RZIP support in cheat.c
CFLAGS += -DHAVE_ZLIB
# In theory, the RETRO_PROFILE could be set to different values for different
# architectures or for special builds to hint to the host system how many
# resources to allocate. In practice, there seems to be no standard way to

View File

@ -2681,10 +2681,19 @@ SOURCES_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_crc32.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/interface_stream.c \
$(LIBRETRO_COMM_DIR)/streams/memory_stream.c \
$(LIBRETRO_COMM_DIR)/streams/rzip_stream.c \
$(LIBRETRO_COMM_DIR)/streams/stdin_stream.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream_pipe.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream_zlib.c \
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
$(LIBRETRO_COMM_DIR)/utils/md5.c \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c \

View File

@ -5,7 +5,7 @@ CORE_DIR := $(ROOT_DIR)/src
include $(ROOT_DIR)/Makefile.common
COREFLAGS := $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS) $(ASMDEFS) $(DBGDEFS) -ffast-math -funroll-loops -DANDROID $(INCFLAGS)
COREFLAGS := $(DEFS) $(COREDEFS) $(CPUDEFS) $(SOUNDDEFS) $(ASMDEFS) $(DBGDEFS) -ffast-math -funroll-loops -DANDROID -DHAVE_ZLIB $(INCFLAGS)
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown")

View File

@ -376,9 +376,12 @@ is selected
#include "artwork.h"
#include "machine/eeprom.h"
#include <ctype.h>
#include <streams/interface_stream.h>
#define CHEAT_DATABASE_FILENAME "cheat.dat"
#define CHEAT_DATABASE_RZIP_FILENAME "cheat.rzip"
#define CHEAT_DATABASE_FILENAME "cheat.dat"
#define CHEAT_SAVE_FILENAME "save_cheat.dat"
#define OSD_READKEY_KLUDGE 1
@ -8225,16 +8228,76 @@ static void HandleLocalCommandCheat(UINT32 type, UINT32 address, UINT32 data, UI
static void LoadCheatDatabase()
{
mame_file * theFile;
intfstream_t * in_file = NULL;
intfstream_t * out_file = NULL;
char cheat_directory[PATH_MAX_LENGTH];
char cheat_path[PATH_MAX_LENGTH];
char formatString[256];
char oldFormatString[256];
char buf[2048];
int recordNames = 0;
theFile = mame_fopen(NULL, CHEAT_DATABASE_FILENAME, FILETYPE_CHEAT, 0);
cheat_directory[0] = '\0';
cheat_path[0] = '\0';
if(!theFile)
return;
/* Open existing cheat.rzip */
osd_get_path(FILETYPE_CHEAT, cheat_directory);
snprintf(cheat_path, PATH_MAX_LENGTH, "%s%c%s", cheat_directory, PATH_DEFAULT_SLASH_C(), CHEAT_DATABASE_RZIP_FILENAME);
in_file = intfstream_open_rzip_file(cheat_path, RETRO_VFS_FILE_ACCESS_READ);
if(!in_file)
{
/* Try to open cheat.dat */
cheat_path[0] = '\0';
snprintf(cheat_path, PATH_MAX_LENGTH, "%s%c%s", cheat_directory, PATH_DEFAULT_SLASH_C(), CHEAT_DATABASE_FILENAME);
in_file = intfstream_open_file(cheat_path, RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
if(!in_file)
goto end;
/* Create new cheat.rzip file */
cheat_path[0] = '\0';
snprintf(cheat_path, PATH_MAX_LENGTH, "%s%c%s", cheat_directory, PATH_DEFAULT_SLASH_C(), CHEAT_DATABASE_RZIP_FILENAME);
out_file = intfstream_open_rzip_file(cheat_path, RETRO_VFS_FILE_ACCESS_WRITE);
if(!out_file)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Failed to create cheat.rzip\n");
goto end;
}
/* Compression loop */
for(;;)
{
int64_t data_read = intfstream_read(in_file, buf, sizeof(buf));
int64_t data_write = 0;
if (data_read < 0)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Failed to read from cheat.dat\n");
goto end;
}
if (data_read == 0)
{
/* Finished, close cheat.rzip and rewind input file */
intfstream_close(out_file);
free(out_file);
out_file = NULL;
intfstream_rewind(in_file);
break;
}
data_write = intfstream_write(out_file, buf, data_read);
if (data_write != data_read)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "Failed to write to cheat.rzip\n");
goto end;
}
}
}
foundCheatDatabase = 1;
@ -8242,7 +8305,7 @@ static void LoadCheatDatabase()
sprintf(formatString, ":%s:%s", Machine->gamedrv->name, "%x:%x:%x:%x:%[^:\n\r]:%[^:\n\r]");
sprintf(oldFormatString, "%s:%s", Machine->gamedrv->name, "%d:%x:%x:%d:%[^:\n\r]:%[^:\n\r]");
while(mame_fgets(buf, 2048, theFile))
while(intfstream_gets(in_file, buf, 2048))
{
int type;
int address;
@ -8281,7 +8344,6 @@ static void LoadCheatDatabase()
}
}
/*logerror("cheat: processing %s\n", buf);*/
if(TEST_FIELD(type, RemoveFromList))
@ -8297,8 +8359,7 @@ static void LoadCheatDatabase()
if(cheatListLength == 0)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "LoadCheatDatabase: first cheat found was link cheat; bailing\n");
goto bail;
goto end;
}
/*logerror("cheat: doing link cheat\n");*/
@ -8315,8 +8376,7 @@ static void LoadCheatDatabase()
if(cheatListLength == 0)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "LoadCheatDatabase: cheat list resize failed; bailing\n");
goto bail;
goto end;
}
entry = &cheatList[cheatListLength - 1];
@ -8343,8 +8403,7 @@ static void LoadCheatDatabase()
if(entry->actionListLength == 0)
{
log_cb(RETRO_LOG_ERROR, LOGPRE "LoadCheatDatabase: action list resize failed; bailing\n");
goto bail;
goto end;
}
action = &entry->actionList[entry->actionListLength - 1];
@ -8362,9 +8421,19 @@ static void LoadCheatDatabase()
}
}
bail:
end:
mame_fclose(theFile);
if(in_file)
{
intfstream_close(in_file);
free(in_file);
}
if(out_file)
{
intfstream_close(out_file);
free(out_file);
}
UpdateAllCheatInfo();
}
@ -8396,7 +8465,7 @@ static void SaveCheat(CheatEntry * entry)
if(!entry || !entry->actionList)
return;
theFile = mame_fopen(NULL, CHEAT_DATABASE_FILENAME, FILETYPE_CHEAT, 1);
theFile = mame_fopen(NULL, CHEAT_SAVE_FILENAME, FILETYPE_CHEAT, 1);
if(!theFile)
return;

View File

@ -10,6 +10,7 @@
#include <string/stdstring.h>
#include <libretro.h>
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <math.h>
#if (HAS_DRZ80 || HAS_CYCLONE)
@ -211,7 +212,15 @@ static void check_system_specs(void)
void retro_set_environment(retro_environment_t cb)
{
struct retro_vfs_interface_info vfs_iface_info;
environ_cb = cb;
/* Initialise VFS */
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);
}