Update libretro-common

This commit is contained in:
twinaphex 2018-04-22 18:36:30 +02:00
parent 7bef8746a3
commit 8a1f2f5cf2
4 changed files with 55 additions and 57 deletions

View File

@ -52,6 +52,7 @@
#include <LzmaDec.h> #include <LzmaDec.h>
#include <retro_inline.h> #include <retro_inline.h>
#include <streams/file_stream.h>
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
@ -255,7 +256,7 @@ struct _chd_file
{ {
UINT32 cookie; /* cookie, should equal COOKIE_VALUE */ UINT32 cookie; /* cookie, should equal COOKIE_VALUE */
core_file * file; /* handle to the open core file */ RFILE * file; /* handle to the open core file */
UINT8 owns_file; /* flag indicating if this file should be closed on chd_close() */ UINT8 owns_file; /* flag indicating if this file should be closed on chd_close() */
chd_header header; /* header, extracted from file */ chd_header header; /* header, extracted from file */
@ -1150,8 +1151,8 @@ static chd_error decompress_v5_map(chd_file* chd, chd_header* header)
} }
/* read the reader */ /* read the reader */
core_fseek(chd->file, header->mapoffset, SEEK_SET); filestream_seek(chd->file, header->mapoffset, SEEK_SET);
core_fread(chd->file, rawbuf, sizeof(rawbuf)); filestream_read(chd->file, rawbuf, sizeof(rawbuf));
mapbytes = get_bigendian_uint32(&rawbuf[0]); mapbytes = get_bigendian_uint32(&rawbuf[0]);
firstoffs = get_bigendian_uint48(&rawbuf[4]); firstoffs = get_bigendian_uint48(&rawbuf[4]);
mapcrc = get_bigendian_uint16(&rawbuf[10]); mapcrc = get_bigendian_uint16(&rawbuf[10]);
@ -1164,8 +1165,8 @@ static chd_error decompress_v5_map(chd_file* chd, chd_header* header)
if (compressed == NULL) if (compressed == NULL)
return CHDERR_OUT_OF_MEMORY; return CHDERR_OUT_OF_MEMORY;
core_fseek(chd->file, header->mapoffset + 16, SEEK_SET); filestream_seek(chd->file, header->mapoffset + 16, SEEK_SET);
core_fread(chd->file, compressed, mapbytes); filestream_read(chd->file, compressed, mapbytes);
bitbuf = create_bitstream(compressed, sizeof(uint8_t) * mapbytes); bitbuf = create_bitstream(compressed, sizeof(uint8_t) * mapbytes);
if (bitbuf == NULL) if (bitbuf == NULL)
{ {
@ -1317,7 +1318,7 @@ static INLINE void map_extract_old(const UINT8 *base, map_entry *entry, UINT32 h
chd_open_file - open a CHD file for access chd_open_file - open a CHD file for access
-------------------------------------------------*/ -------------------------------------------------*/
chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd) chd_error chd_open_file(RFILE *file, int mode, chd_file *parent, chd_file **chd)
{ {
chd_file *newchd = NULL; chd_file *newchd = NULL;
chd_error err; chd_error err;
@ -1409,13 +1410,13 @@ chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **
/* find the codec interface */ /* find the codec interface */
if (newchd->header.version < 5) if (newchd->header.version < 5)
{ {
for (intfnum = 0; intfnum < ARRAY_LENGTH(codec_interfaces); intfnum++) for (intfnum = 0; intfnum < ARRAY_SIZE(codec_interfaces); intfnum++)
if (codec_interfaces[intfnum].compression == newchd->header.compression[0]) if (codec_interfaces[intfnum].compression == newchd->header.compression[0])
{ {
newchd->codecintf[0] = &codec_interfaces[intfnum]; newchd->codecintf[0] = &codec_interfaces[intfnum];
break; break;
} }
if (intfnum == ARRAY_LENGTH(codec_interfaces)) if (intfnum == ARRAY_SIZE(codec_interfaces))
EARLY_EXIT(err = CHDERR_UNSUPPORTED_FORMAT); EARLY_EXIT(err = CHDERR_UNSUPPORTED_FORMAT);
/* initialize the codec */ /* initialize the codec */
@ -1429,9 +1430,9 @@ chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **
{ {
int i, decompnum; int i, decompnum;
/* verify the compression types and initialize the codecs */ /* verify the compression types and initialize the codecs */
for (decompnum = 0; decompnum < ARRAY_LENGTH(newchd->header.compression); decompnum++) for (decompnum = 0; decompnum < ARRAY_SIZE(newchd->header.compression); decompnum++)
{ {
for (i = 0 ; i < ARRAY_LENGTH(codec_interfaces) ; i++) for (i = 0 ; i < ARRAY_SIZE(codec_interfaces) ; i++)
{ {
if (codec_interfaces[i].compression == newchd->header.compression[decompnum]) if (codec_interfaces[i].compression == newchd->header.compression[decompnum])
{ {
@ -1496,7 +1497,7 @@ cleanup:
chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd) chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd)
{ {
chd_error err; chd_error err;
core_file *file = NULL; RFILE *file = NULL;
/* choose the proper mode */ /* choose the proper mode */
switch(mode) switch(mode)
@ -1510,8 +1511,11 @@ chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **
} }
/* open the file */ /* open the file */
file = core_fopen(filename); file = filestream_open(filename,
if (file == 0) RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!file)
{ {
err = CHDERR_FILE_NOT_FOUND; err = CHDERR_FILE_NOT_FOUND;
goto cleanup; goto cleanup;
@ -1527,25 +1531,25 @@ chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **
cleanup: cleanup:
if ((err != CHDERR_NONE) && (file != NULL)) if ((err != CHDERR_NONE) && (file != NULL))
core_fclose(file); filestream_close(file);
return err; return err;
} }
chd_error chd_precache(chd_file *chd) chd_error chd_precache(chd_file *chd)
{ {
ssize_t size, count; int64_t size, count;
if (!chd->file_cache) if (!chd->file_cache)
{ {
core_fseek(chd->file, 0, SEEK_END); filestream_seek(chd->file, 0, SEEK_END);
size = core_ftell(chd->file); size = filestream_tell(chd->file);
if (size <= 0) if (size <= 0)
return CHDERR_INVALID_DATA; return CHDERR_INVALID_DATA;
chd->file_cache = malloc(size); chd->file_cache = malloc(size);
if (chd->file_cache == NULL) if (chd->file_cache == NULL)
return CHDERR_OUT_OF_MEMORY; return CHDERR_OUT_OF_MEMORY;
core_fseek(chd->file, 0, SEEK_SET); filestream_seek(chd->file, 0, SEEK_SET);
count = core_fread(chd->file, chd->file_cache, size); count = filestream_read(chd->file, chd->file_cache, size);
if (count != size) if (count != size)
{ {
free(chd->file_cache); free(chd->file_cache);
@ -1623,7 +1627,7 @@ void chd_close(chd_file *chd)
/* close the file */ /* close the file */
if (chd->owns_file && chd->file != NULL) if (chd->owns_file && chd->file != NULL)
core_fclose(chd->file); filestream_close(chd->file);
#ifdef NEED_CACHE_HUNK #ifdef NEED_CACHE_HUNK
if (PRINTF_MAX_HUNK) printf("Max hunk = %d/%d\n", chd->maxhunk, chd->header.totalhunks); if (PRINTF_MAX_HUNK) printf("Max hunk = %d/%d\n", chd->maxhunk, chd->header.totalhunks);
@ -1641,7 +1645,7 @@ void chd_close(chd_file *chd)
core_file core_file
-------------------------------------------------*/ -------------------------------------------------*/
core_file *chd_core_file(chd_file *chd) RFILE *chd_core_file(chd_file *chd)
{ {
return chd->file; return chd->file;
} }
@ -1768,8 +1772,8 @@ chd_error chd_get_metadata(chd_file *chd, UINT32 searchtag, UINT32 searchindex,
/* read the metadata */ /* read the metadata */
outputlen = MIN(outputlen, metaentry.length); outputlen = MIN(outputlen, metaentry.length);
core_fseek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET); filestream_seek(chd->file, metaentry.offset + METADATA_HEADER_SIZE, SEEK_SET);
count = core_fread(chd->file, output, outputlen); count = filestream_read(chd->file, output, outputlen);
if (count != outputlen) if (count != outputlen)
return CHDERR_READ_ERROR; return CHDERR_READ_ERROR;
@ -1840,11 +1844,11 @@ static chd_error header_validate(const chd_header *header)
return CHDERR_INVALID_PARAMETER; return CHDERR_INVALID_PARAMETER;
/* require a supported compression mechanism */ /* require a supported compression mechanism */
for (intfnum = 0; intfnum < ARRAY_LENGTH(codec_interfaces); intfnum++) for (intfnum = 0; intfnum < ARRAY_SIZE(codec_interfaces); intfnum++)
if (codec_interfaces[intfnum].compression == header->compression[0]) if (codec_interfaces[intfnum].compression == header->compression[0])
break; break;
if (intfnum == ARRAY_LENGTH(codec_interfaces)) if (intfnum == ARRAY_SIZE(codec_interfaces))
return CHDERR_INVALID_PARAMETER; return CHDERR_INVALID_PARAMETER;
/* require a valid hunksize */ /* require a valid hunksize */
@ -1919,8 +1923,8 @@ static chd_error header_read(chd_file *chd, chd_header *header)
return CHDERR_INVALID_FILE; return CHDERR_INVALID_FILE;
/* seek and read */ /* seek and read */
core_fseek(chd->file, 0, SEEK_SET); filestream_seek(chd->file, 0, SEEK_SET);
count = core_fread(chd->file, rawheader, sizeof(rawheader)); count = filestream_read(chd->file, rawheader, sizeof(rawheader));
if (count != sizeof(rawheader)) if (count != sizeof(rawheader))
return CHDERR_READ_ERROR; return CHDERR_READ_ERROR;
@ -2069,11 +2073,11 @@ static chd_error hunk_read_into_cache(chd_file *chd, UINT32 hunknum)
static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size) static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size)
{ {
ssize_t bytes; int64_t bytes;
if (chd->file_cache) if (chd->file_cache)
return chd->file_cache + offset; return chd->file_cache + offset;
core_fseek(chd->file, offset, SEEK_SET); filestream_seek(chd->file, offset, SEEK_SET);
bytes = core_fread(chd->file, chd->compressed, size); bytes = filestream_read(chd->file, chd->compressed, size);
if (bytes != size) if (bytes != size)
return NULL; return NULL;
return chd->compressed; return chd->compressed;
@ -2081,14 +2085,14 @@ static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size)
static chd_error read_uncompressed(chd_file *chd, UINT64 offset, size_t size, UINT8 *dest) static chd_error read_uncompressed(chd_file *chd, UINT64 offset, size_t size, UINT8 *dest)
{ {
ssize_t bytes; int64_t bytes;
if (chd->file_cache) if (chd->file_cache)
{ {
memcpy(dest, chd->file_cache + offset, size); memcpy(dest, chd->file_cache + offset, size);
return CHDERR_NONE; return CHDERR_NONE;
} }
core_fseek(chd->file, offset, SEEK_SET); filestream_seek(chd->file, offset, SEEK_SET);
bytes = core_fread(chd->file, dest, size); bytes = filestream_read(chd->file, dest, size);
if (bytes != size) if (bytes != size)
return CHDERR_READ_ERROR; return CHDERR_READ_ERROR;
return CHDERR_NONE; return CHDERR_NONE;
@ -2277,12 +2281,12 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
INTERNAL MAP ACCESS INTERNAL MAP ACCESS
***************************************************************************/ ***************************************************************************/
static size_t core_fsize(core_file *f) static size_t core_fsize(RFILE *f)
{ {
long rv,p = ftell(f); int64_t rv, p = filestream_tell(f);
fseek(f, 0, SEEK_END); filestream_seek(f, 0, SEEK_END);
rv = ftell(f); rv = filestream_tell(f);
fseek(f, p, SEEK_SET); filestream_seek(f, p, SEEK_SET);
return rv; return rv;
} }
@ -2315,8 +2319,8 @@ static chd_error map_read(chd_file *chd)
entries = MAP_STACK_ENTRIES; entries = MAP_STACK_ENTRIES;
/* read that many */ /* read that many */
core_fseek(chd->file, fileoffset, SEEK_SET); filestream_seek(chd->file, fileoffset, SEEK_SET);
count = core_fread(chd->file, raw_map_entries, entries * entrysize); count = filestream_read(chd->file, raw_map_entries, entries * entrysize);
if (count != entries * entrysize) if (count != entries * entrysize)
{ {
err = CHDERR_READ_ERROR; err = CHDERR_READ_ERROR;
@ -2344,8 +2348,8 @@ static chd_error map_read(chd_file *chd)
} }
/* verify the cookie */ /* verify the cookie */
core_fseek(chd->file, fileoffset, SEEK_SET); filestream_seek(chd->file, fileoffset, SEEK_SET);
count = core_fread(chd->file, &cookie, entrysize); count = filestream_read(chd->file, &cookie, entrysize);
if (count != entrysize || memcmp(&cookie, END_OF_LIST_COOKIE, entrysize)) if (count != entrysize || memcmp(&cookie, END_OF_LIST_COOKIE, entrysize))
{ {
err = CHDERR_INVALID_FILE; err = CHDERR_INVALID_FILE;
@ -2385,11 +2389,11 @@ static chd_error metadata_find_entry(chd_file *chd, UINT32 metatag, UINT32 metai
while (metaentry->offset != 0) while (metaentry->offset != 0)
{ {
UINT8 raw_meta_header[METADATA_HEADER_SIZE]; UINT8 raw_meta_header[METADATA_HEADER_SIZE];
UINT32 count; int64_t count;
/* read the raw header */ /* read the raw header */
core_fseek(chd->file, metaentry->offset, SEEK_SET); filestream_seek(chd->file, metaentry->offset, SEEK_SET);
count = core_fread(chd->file, raw_meta_header, sizeof(raw_meta_header)); count = filestream_read(chd->file, raw_meta_header, sizeof(raw_meta_header));
if (count != sizeof(raw_meta_header)) if (count != sizeof(raw_meta_header))
break; break;

View File

@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <libchdr/flac.h> #include <libchdr/flac.h>
#include <libchdr/minmax.h> #include <libchdr/minmax.h>
#include <retro_miscellaneous.h>
/*************************************************************************** /***************************************************************************
* FLAC DECODER * FLAC DECODER
@ -153,7 +154,7 @@ bool flac_decoder::decode(int16_t **samples, uint32_t num_samples, bool swap_end
{ {
/* make sure we don't have too many channels */ /* make sure we don't have too many channels */
int chans = channels(); int chans = channels();
if (chans > ARRAY_LENGTH(m_uncompressed_start)) if (chans > ARRAY_SIZE(m_uncompressed_start))
return false; return false;
/* configure the uncompressed buffer */ /* configure the uncompressed buffer */

View File

@ -47,6 +47,7 @@ extern "C" {
#endif #endif
#include "coretypes.h" #include "coretypes.h"
#include <streams/file_stream.h>
/*************************************************************************** /***************************************************************************
@ -347,7 +348,7 @@ struct _chd_verify_result
/* chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent); */ /* chd_error chd_create_file(core_file *file, UINT64 logicalbytes, UINT32 hunkbytes, UINT32 compression, chd_file *parent); */
/* open an existing CHD file */ /* open an existing CHD file */
chd_error chd_open_file(core_file *file, int mode, chd_file *parent, chd_file **chd); chd_error chd_open_file(RFILE *file, int mode, chd_file *parent, chd_file **chd);
chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd); chd_error chd_open(const char *filename, int mode, chd_file *parent, chd_file **chd);
@ -358,7 +359,7 @@ chd_error chd_precache(chd_file *chd);
void chd_close(chd_file *chd); void chd_close(chd_file *chd);
/* return the associated core_file */ /* return the associated core_file */
core_file *chd_core_file(chd_file *chd); RFILE *chd_core_file(chd_file *chd);
/* return an error string for the given CHD error */ /* return an error string for the given CHD error */
const char *chd_error_string(chd_error err); const char *chd_error_string(chd_error err);

View File

@ -3,8 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <retro_miscellaneous.h>
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
typedef uint64_t UINT64; typedef uint64_t UINT64;
#ifndef OSD_CPU_H #ifndef OSD_CPU_H
@ -20,11 +19,4 @@ typedef int16_t INT16;
typedef int8_t INT8; typedef int8_t INT8;
#endif #endif
#define core_file FILE
#define core_fopen(file) fopen(file, "rb")
#define core_fseek fseek
#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
#define core_fclose fclose
#define core_ftell ftell
#endif #endif