mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2024-12-28 12:11:50 +01:00
Using filestream
This commit is contained in:
parent
f47c7749ff
commit
6652a76f30
@ -74,6 +74,7 @@
|
|||||||
#include "libretro.h"
|
#include "libretro.h"
|
||||||
#include "md_ntsc.h"
|
#include "md_ntsc.h"
|
||||||
#include "sms_ntsc.h"
|
#include "sms_ntsc.h"
|
||||||
|
#include "streams/file_stream.h"
|
||||||
|
|
||||||
sms_ntsc_t *sms_ntsc;
|
sms_ntsc_t *sms_ntsc;
|
||||||
md_ntsc_t *md_ntsc;
|
md_ntsc_t *md_ntsc;
|
||||||
@ -169,7 +170,7 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
|||||||
int size, left;
|
int size, left;
|
||||||
|
|
||||||
/* Open file */
|
/* Open file */
|
||||||
FILE *fd = fopen(filename, "rb");
|
RFILE *fd = filestream_open(filename, RFILE_MODE_READ, -1);
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
@ -193,13 +194,13 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get file size */
|
/* Get file size */
|
||||||
fseek(fd, 0, SEEK_END);
|
filestream_seek(fd, 0, SEEK_END);
|
||||||
size = ftell(fd);
|
size = filestream_tell(fd);
|
||||||
|
|
||||||
/* size limit */
|
/* size limit */
|
||||||
if (size > MAXROMSIZE)
|
if (size > MAXROMSIZE)
|
||||||
{
|
{
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
if (log_cb)
|
if (log_cb)
|
||||||
log_cb(RETRO_LOG_ERROR, "File is too large.\n");
|
log_cb(RETRO_LOG_ERROR, "File is too large.\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -221,19 +222,19 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
|||||||
|
|
||||||
/* Read into buffer */
|
/* Read into buffer */
|
||||||
left = size;
|
left = size;
|
||||||
fseek(fd, 0, SEEK_SET);
|
filestream_seek(fd, 0, SEEK_SET);
|
||||||
while (left > CHUNKSIZE)
|
while (left > CHUNKSIZE)
|
||||||
{
|
{
|
||||||
fread(buffer, CHUNKSIZE, 1, fd);
|
filestream_read(fd, buffer, CHUNKSIZE);
|
||||||
buffer += CHUNKSIZE;
|
buffer += CHUNKSIZE;
|
||||||
left -= CHUNKSIZE;
|
left -= CHUNKSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read remaining bytes */
|
/* Read remaining bytes */
|
||||||
fread(buffer, left, 1, fd);
|
filestream_read(fd, buffer, left);
|
||||||
|
|
||||||
/* Close file */
|
/* Close file */
|
||||||
fclose(fd);
|
filestream_close(fd);
|
||||||
|
|
||||||
/* Return loaded ROM size */
|
/* Return loaded ROM size */
|
||||||
return size;
|
return size;
|
||||||
|
Loading…
Reference in New Issue
Block a user