mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
(libchdr) More rebases
This commit is contained in:
parent
88804a05de
commit
436f161cc3
@ -939,6 +939,38 @@ cleanup:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
chd_precache - precache underlying file in
|
||||||
|
memory
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
chd_error chd_precache(chd_file *chd)
|
||||||
|
{
|
||||||
|
int64_t size, count;
|
||||||
|
|
||||||
|
if (!chd->file_cache)
|
||||||
|
{
|
||||||
|
filestream_seek(chd->file, 0, SEEK_END);
|
||||||
|
size = filestream_tell(chd->file);
|
||||||
|
if (size <= 0)
|
||||||
|
return CHDERR_INVALID_DATA;
|
||||||
|
chd->file_cache = (UINT8*)malloc(size);
|
||||||
|
if (chd->file_cache == NULL)
|
||||||
|
return CHDERR_OUT_OF_MEMORY;
|
||||||
|
filestream_seek(chd->file, 0, SEEK_SET);
|
||||||
|
count = filestream_read(chd->file, chd->file_cache, size);
|
||||||
|
if (count != size)
|
||||||
|
{
|
||||||
|
free(chd->file_cache);
|
||||||
|
chd->file_cache = NULL;
|
||||||
|
return CHDERR_READ_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CHDERR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------
|
/*-------------------------------------------------
|
||||||
chd_open - open a CHD file by
|
chd_open - open a CHD file by
|
||||||
filename
|
filename
|
||||||
@ -985,32 +1017,6 @@ cleanup:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
chd_error chd_precache(chd_file *chd)
|
|
||||||
{
|
|
||||||
int64_t size, count;
|
|
||||||
|
|
||||||
if (!chd->file_cache)
|
|
||||||
{
|
|
||||||
filestream_seek(chd->file, 0, SEEK_END);
|
|
||||||
size = filestream_tell(chd->file);
|
|
||||||
if (size <= 0)
|
|
||||||
return CHDERR_INVALID_DATA;
|
|
||||||
chd->file_cache = (UINT8*)malloc(size);
|
|
||||||
if (chd->file_cache == NULL)
|
|
||||||
return CHDERR_OUT_OF_MEMORY;
|
|
||||||
filestream_seek(chd->file, 0, SEEK_SET);
|
|
||||||
count = filestream_read(chd->file, chd->file_cache, size);
|
|
||||||
if (count != size)
|
|
||||||
{
|
|
||||||
free(chd->file_cache);
|
|
||||||
chd->file_cache = NULL;
|
|
||||||
return CHDERR_READ_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return CHDERR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-------------------------------------------------
|
/*-------------------------------------------------
|
||||||
chd_close - close a CHD file for access
|
chd_close - close a CHD file for access
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
@ -1530,7 +1536,12 @@ static chd_error hunk_read_into_cache(chd_file *chd, UINT32 hunknum)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size)
|
/*-------------------------------------------------
|
||||||
|
hunk_read_compressed - read a compressed
|
||||||
|
hunk
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
static UINT8* hunk_read_compressed(chd_file *chd, UINT64 offset, size_t size)
|
||||||
{
|
{
|
||||||
int64_t bytes;
|
int64_t bytes;
|
||||||
if (chd->file_cache)
|
if (chd->file_cache)
|
||||||
@ -1542,7 +1553,12 @@ static UINT8* read_compressed(chd_file *chd, UINT64 offset, size_t size)
|
|||||||
return chd->compressed;
|
return chd->compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static chd_error read_uncompressed(chd_file *chd, UINT64 offset, size_t size, UINT8 *dest)
|
/*-------------------------------------------------
|
||||||
|
hunk_read_uncompressed - read an uncompressed
|
||||||
|
hunk
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
static chd_error hunk_read_uncompressed(chd_file *chd, UINT64 offset, size_t size, UINT8 *dest)
|
||||||
{
|
{
|
||||||
int64_t bytes;
|
int64_t bytes;
|
||||||
if (chd->file_cache)
|
if (chd->file_cache)
|
||||||
@ -1589,7 +1605,7 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
|
|||||||
case MAP_ENTRY_TYPE_COMPRESSED:
|
case MAP_ENTRY_TYPE_COMPRESSED:
|
||||||
{
|
{
|
||||||
void *codec;
|
void *codec;
|
||||||
UINT8 *bytes = read_compressed(chd, entry->offset,
|
UINT8 *bytes = hunk_read_compressed(chd, entry->offset,
|
||||||
entry->length);
|
entry->length);
|
||||||
if (bytes == NULL)
|
if (bytes == NULL)
|
||||||
return CHDERR_READ_ERROR;
|
return CHDERR_READ_ERROR;
|
||||||
@ -1608,7 +1624,7 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
|
|||||||
|
|
||||||
/* uncompressed data */
|
/* uncompressed data */
|
||||||
case MAP_ENTRY_TYPE_UNCOMPRESSED:
|
case MAP_ENTRY_TYPE_UNCOMPRESSED:
|
||||||
err = read_uncompressed(chd, entry->offset, chd->header.hunkbytes, dest);
|
err = hunk_read_uncompressed(chd, entry->offset, chd->header.hunkbytes, dest);
|
||||||
if (err != CHDERR_NONE)
|
if (err != CHDERR_NONE)
|
||||||
return err;
|
return err;
|
||||||
break;
|
break;
|
||||||
@ -1678,7 +1694,7 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
|
|||||||
case COMPRESSION_TYPE_1:
|
case COMPRESSION_TYPE_1:
|
||||||
case COMPRESSION_TYPE_2:
|
case COMPRESSION_TYPE_2:
|
||||||
case COMPRESSION_TYPE_3:
|
case COMPRESSION_TYPE_3:
|
||||||
bytes = read_compressed(chd, blockoffs, blocklen);
|
bytes = hunk_read_compressed(chd, blockoffs, blocklen);
|
||||||
if (bytes == NULL)
|
if (bytes == NULL)
|
||||||
return CHDERR_READ_ERROR;
|
return CHDERR_READ_ERROR;
|
||||||
if (!chd->codecintf[rawmap[0]])
|
if (!chd->codecintf[rawmap[0]])
|
||||||
@ -1715,7 +1731,7 @@ static chd_error hunk_read_into_memory(chd_file *chd, UINT32 hunknum, UINT8 *des
|
|||||||
return CHDERR_NONE;
|
return CHDERR_NONE;
|
||||||
|
|
||||||
case COMPRESSION_NONE:
|
case COMPRESSION_NONE:
|
||||||
err = read_uncompressed(chd, blockoffs, blocklen, dest);
|
err = hunk_read_uncompressed(chd, blockoffs, blocklen, dest);
|
||||||
if (err != CHDERR_NONE)
|
if (err != CHDERR_NONE)
|
||||||
return err;
|
return err;
|
||||||
#ifdef VERIFY_BLOCK_CRC
|
#ifdef VERIFY_BLOCK_CRC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user