Update CHD code to use libretro VFS
This commit is contained in:
parent
9a4aee02e3
commit
6c7cb8619e
6 changed files with 48 additions and 37 deletions
|
|
@ -14,6 +14,9 @@ add_library(libchdr
|
|||
src/libchdr_huffman.c
|
||||
)
|
||||
|
||||
target_include_directories(libchdr PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_include_directories(libchdr PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../libretro-common/include"
|
||||
)
|
||||
target_link_libraries(libchdr PRIVATE zlib lzma)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ extern "C" {
|
|||
#include <libchdr/coretypes.h>
|
||||
#include <libchdr/chdconfig.h>
|
||||
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
/***************************************************************************
|
||||
|
||||
Compressed Hunks of Data header format. All numbers are stored in
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef USE_LIBRETRO_VFS
|
||||
#include <streams/file_stream_transforms.h>
|
||||
#endif
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
|
|
@ -29,29 +27,29 @@ typedef int32_t INT32;
|
|||
typedef int16_t INT16;
|
||||
typedef int8_t INT8;
|
||||
|
||||
#define core_file FILE
|
||||
#define core_fopen(file) fopen(file, "rb")
|
||||
#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) rfread(buff, 1, len, fc)
|
||||
#define core_fclose rfclose
|
||||
|
||||
#if defined USE_LIBRETRO_VFS
|
||||
#define core_fseek fseek
|
||||
#define core_ftell ftell
|
||||
#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__)
|
||||
#define core_fseek _fseeki64
|
||||
#define core_ftell _ftelli64
|
||||
#elif defined(_LARGEFILE_SOURCE) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
|
||||
#define core_fseek fseeko64
|
||||
#define core_ftell ftello64
|
||||
#elif defined(__PS3__) && !defined(__PSL1GHT__) || defined(__SWITCH__)
|
||||
#define core_fseek(x,y,z) fseek(x,(off_t)y,z)
|
||||
#define core_ftell(x) (off_t)ftell(x)
|
||||
#else
|
||||
#define core_fseek fseeko
|
||||
#define core_ftell ftello
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
|
||||
#define core_fclose fclose
|
||||
|
||||
static UINT64 core_fsize(core_file *f)
|
||||
RFILE* rfopen(const char *path, const char *mode);
|
||||
extern int64_t rfseek(RFILE* stream, int64_t offset, int origin);
|
||||
extern int64_t rftell(RFILE* stream);
|
||||
extern int64_t rfread(void* buffer,
|
||||
size_t elem_size, size_t elem_count, RFILE* stream);
|
||||
extern int rfclose(RFILE* stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static INLINE UINT64 core_fsize(core_file *f)
|
||||
{
|
||||
UINT64 rv;
|
||||
UINT64 p = core_ftell(f);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ private:
|
|||
|
||||
bool ReadHunk(u32 hunk_index);
|
||||
|
||||
std::FILE* m_fp = nullptr;
|
||||
RFILE* m_fp = nullptr;
|
||||
chd_file* m_chd = nullptr;
|
||||
u32 m_hunk_size = 0;
|
||||
u32 m_sectors_per_hunk = 0;
|
||||
|
|
@ -77,12 +77,12 @@ CDImageCHD::~CDImageCHD()
|
|||
if (m_chd)
|
||||
chd_close(m_chd);
|
||||
if (m_fp)
|
||||
std::fclose(m_fp);
|
||||
rfclose(m_fp);
|
||||
}
|
||||
|
||||
bool CDImageCHD::Open(const char* filename, Common::Error* error)
|
||||
{
|
||||
m_fp = FileSystem::OpenCFile(filename, "rb");
|
||||
m_fp = FileSystem::OpenRFile(filename, "rb");
|
||||
if (!m_fp)
|
||||
{
|
||||
Log_ErrorPrintf("Failed to open CHD '%s': errno %d", filename, errno);
|
||||
|
|
|
|||
|
|
@ -31,17 +31,17 @@
|
|||
#include <file/file_path.h>
|
||||
#include <streams/file_stream.h>
|
||||
|
||||
int rferror(RFILE* stream)
|
||||
extern "C" int rferror(RFILE* stream)
|
||||
{
|
||||
return filestream_error(stream);
|
||||
}
|
||||
|
||||
int rfeof(RFILE* stream)
|
||||
extern "C" int rfeof(RFILE* stream)
|
||||
{
|
||||
return filestream_eof(stream);
|
||||
}
|
||||
|
||||
char *rfgets(char *buffer, int maxCount, RFILE* stream)
|
||||
extern "C" char *rfgets(char *buffer, int maxCount, RFILE* stream)
|
||||
{
|
||||
if (!stream)
|
||||
return NULL;
|
||||
|
|
@ -49,7 +49,7 @@ char *rfgets(char *buffer, int maxCount, RFILE* stream)
|
|||
return filestream_gets(stream, buffer, maxCount);
|
||||
}
|
||||
|
||||
int rfgetc(RFILE* stream)
|
||||
extern "C" int rfgetc(RFILE* stream)
|
||||
{
|
||||
if (!stream)
|
||||
return EOF;
|
||||
|
|
@ -57,7 +57,7 @@ int rfgetc(RFILE* stream)
|
|||
return filestream_getc(stream);
|
||||
}
|
||||
|
||||
RFILE* rfopen(const char *path, const char *mode)
|
||||
extern "C" RFILE* rfopen(const char *path, const char *mode)
|
||||
{
|
||||
RFILE *output = NULL;
|
||||
unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ;
|
||||
|
|
@ -98,7 +98,7 @@ RFILE* rfopen(const char *path, const char *mode)
|
|||
return output;
|
||||
}
|
||||
|
||||
int rfclose(RFILE* stream)
|
||||
extern "C" int rfclose(RFILE* stream)
|
||||
{
|
||||
if (!stream)
|
||||
return EOF;
|
||||
|
|
@ -106,7 +106,7 @@ int rfclose(RFILE* stream)
|
|||
return filestream_close(stream);
|
||||
}
|
||||
|
||||
int64_t rftell(RFILE* stream)
|
||||
extern "C" int64_t rftell(RFILE* stream)
|
||||
{
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
|
@ -114,7 +114,7 @@ int64_t rftell(RFILE* stream)
|
|||
return filestream_tell(stream);
|
||||
}
|
||||
|
||||
int64_t rfread(void* buffer,
|
||||
extern "C" int64_t rfread(void* buffer,
|
||||
size_t elem_size, size_t elem_count, RFILE* stream)
|
||||
{
|
||||
if (!stream || (elem_size == 0) || (elem_count == 0))
|
||||
|
|
@ -123,7 +123,7 @@ int64_t rfread(void* buffer,
|
|||
return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size);
|
||||
}
|
||||
|
||||
int64_t rfseek(RFILE* stream, int64_t offset, int origin)
|
||||
extern "C" int64_t rfseek(RFILE* stream, int64_t offset, int origin)
|
||||
{
|
||||
int seek_position = -1;
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ int64_t rfseek(RFILE* stream, int64_t offset, int origin)
|
|||
return filestream_seek(stream, offset, seek_position);
|
||||
}
|
||||
|
||||
int64_t rfwrite(void const* buffer,
|
||||
extern "C" int64_t rfwrite(void const* buffer,
|
||||
size_t elem_size, size_t elem_count, RFILE* stream)
|
||||
{
|
||||
if (!stream || (elem_size == 0) || (elem_count == 0))
|
||||
|
|
|
|||
|
|
@ -117,6 +117,10 @@ std::optional<std::vector<u8>> ReadBinaryFile(RFILE* fp);
|
|||
|
||||
}; // namespace FileSystem
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *rfgets(char *buffer, int maxCount, RFILE* stream);
|
||||
int rfeof(RFILE* stream);
|
||||
int rferror(RFILE* stream);
|
||||
|
|
@ -129,3 +133,7 @@ int64_t rfwrite(void const* buffer,
|
|||
int64_t rfread(void* buffer,
|
||||
size_t elem_size, size_t elem_count, RFILE* stream);
|
||||
int rfgetc(RFILE* stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue