2022-01-09 15:02:45 -05:00
|
|
|
#include "Js_DiscImageDeviceStream.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <cassert>
|
|
|
|
#include <emscripten.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
void CJsDiscImageDeviceStream::Seek(int64 position, Framework::STREAM_SEEK_DIRECTION whence)
|
|
|
|
{
|
|
|
|
switch(whence)
|
|
|
|
{
|
|
|
|
case Framework::STREAM_SEEK_SET:
|
|
|
|
m_position = position;
|
|
|
|
break;
|
|
|
|
case Framework::STREAM_SEEK_CUR:
|
|
|
|
m_position += position;
|
|
|
|
break;
|
|
|
|
case Framework::STREAM_SEEK_END:
|
2024-08-26 10:34:21 -04:00
|
|
|
{
|
|
|
|
uint32 positionLo = MAIN_THREAD_EM_ASM_INT({return Module.discImageDevice.getFileSize()});
|
|
|
|
uint32 positionHi = MAIN_THREAD_EM_ASM_INT({return Module.discImageDevice.getFileSize() / 4294967296});
|
|
|
|
m_position = static_cast<uint64>(positionLo) | (static_cast<uint64>(positionHi) << 32);
|
|
|
|
}
|
|
|
|
break;
|
2022-01-09 15:02:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 CJsDiscImageDeviceStream::Tell()
|
|
|
|
{
|
|
|
|
return m_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 CJsDiscImageDeviceStream::Read(void* buffer, uint64 size)
|
|
|
|
{
|
|
|
|
if(size == 0) return 0;
|
|
|
|
|
|
|
|
assert(size <= std::numeric_limits<uint32>::max());
|
|
|
|
|
|
|
|
uint32 positionLow = static_cast<uint32>(m_position);
|
|
|
|
uint32 positionHigh = static_cast<uint32>(m_position >> 32);
|
|
|
|
|
|
|
|
MAIN_THREAD_EM_ASM({
|
2022-02-01 19:38:52 -05:00
|
|
|
let posLow = $1 >>> 0;
|
|
|
|
let posHigh = $2 >>> 0;
|
|
|
|
let position = posLow + (posHigh * 4294967296);
|
2022-01-09 15:02:45 -05:00
|
|
|
Module.discImageDevice.read($0, position, $3);
|
2022-01-09 15:12:17 -05:00
|
|
|
},
|
|
|
|
buffer, positionLow, positionHigh, static_cast<uint32>(size));
|
2022-01-09 15:02:45 -05:00
|
|
|
while(!MAIN_THREAD_EM_ASM_INT({return Module.discImageDevice.isDone()}))
|
|
|
|
{
|
|
|
|
usleep(100);
|
|
|
|
}
|
|
|
|
m_position += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 CJsDiscImageDeviceStream::Write(const void*, uint64)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Not supported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CJsDiscImageDeviceStream::IsEOF()
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Not supported.");
|
|
|
|
}
|
|
|
|
|
2022-01-09 15:12:17 -05:00
|
|
|
void CJsDiscImageDeviceStream::Flush()
|
2022-01-09 15:02:45 -05:00
|
|
|
{
|
|
|
|
}
|