2021-07-21 09:35:11 -04:00
|
|
|
#include "ChdStreamSupport.h"
|
|
|
|
#include <libchdr/chd.h>
|
2021-07-16 10:54:45 -04:00
|
|
|
#include "Stream.h"
|
|
|
|
|
2021-07-21 09:35:11 -04:00
|
|
|
static UINT64 stream_core_fread(void* file, void* buffer, UINT64 size)
|
2021-07-16 10:54:45 -04:00
|
|
|
{
|
|
|
|
auto stream = reinterpret_cast<Framework::CStream*>(file);
|
|
|
|
return stream->Read(buffer, size);
|
|
|
|
}
|
|
|
|
|
2021-07-21 09:35:11 -04:00
|
|
|
static void stream_core_fseek(void* file, INT64 position, int whence)
|
2021-07-16 10:54:45 -04:00
|
|
|
{
|
|
|
|
auto stream = reinterpret_cast<Framework::CStream*>(file);
|
|
|
|
stream->Seek(position, static_cast<Framework::STREAM_SEEK_DIRECTION>(whence));
|
|
|
|
}
|
|
|
|
|
2021-07-21 09:35:11 -04:00
|
|
|
static UINT64 stream_core_ftell(void* file)
|
2021-07-16 10:54:45 -04:00
|
|
|
{
|
|
|
|
auto stream = reinterpret_cast<Framework::CStream*>(file);
|
|
|
|
return stream->Tell();
|
|
|
|
}
|
2021-07-21 09:35:11 -04:00
|
|
|
|
|
|
|
core_file* ChdStreamSupport::CreateFileFromStream(Framework::CStream* stream)
|
|
|
|
{
|
|
|
|
auto result = core_falloc();
|
|
|
|
result->user_data = stream;
|
|
|
|
result->read_function = &stream_core_fread;
|
|
|
|
result->tell_function = &stream_core_ftell;
|
|
|
|
result->seek_function = &stream_core_fseek;
|
|
|
|
return result;
|
|
|
|
}
|