From e0824a15908f4e6ad70d3d0f2364efe043a98c0f Mon Sep 17 00:00:00 2001 From: TakaRikka <38417346+TakaRikka@users.noreply.github.com> Date: Sun, 19 Jan 2025 21:05:53 -0800 Subject: most of JHostIO / m_Do_hostIO done (#2288) --- src/JSystem/JSupport/JSUMemoryStream.cpp | 51 +++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'src/JSystem/JSupport/JSUMemoryStream.cpp') diff --git a/src/JSystem/JSupport/JSUMemoryStream.cpp b/src/JSystem/JSupport/JSUMemoryStream.cpp index 0b5f1bc062..494c343313 100644 --- a/src/JSystem/JSupport/JSUMemoryStream.cpp +++ b/src/JSystem/JSupport/JSUMemoryStream.cpp @@ -63,4 +63,53 @@ s32 JSUMemoryInputStream::getLength() const { /* 802DC630-802DC638 2D6F70 0008+00 1/0 0/0 0/0 .text getPosition__20JSUMemoryInputStreamCFv */ s32 JSUMemoryInputStream::getPosition() const { return mPosition; -} \ No newline at end of file +} + +void JSUMemoryOutputStream::setBuffer(void* pBuffer, s32 length) { + mBuffer = pBuffer; + mLength = length; + mPosition = 0; +} + +s32 JSUMemoryOutputStream::writeData(const void* pData, s32 length) { + if (mPosition + length > mLength) { + length = mLength - mPosition; + } + + if (length > 0) { + memcpy((void*)((s32)mBuffer + mPosition), pData, length); + mPosition += length; + } + + return length; +} + +s32 JSUMemoryOutputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) { + s32 oldPos = mPosition; + + switch (seekFrom) { + case JSUStreamSeekFrom_SET: + mPosition = pos; + break; + case JSUStreamSeekFrom_END: + mPosition = mLength - pos; + break; + case JSUStreamSeekFrom_CUR: + mPosition += pos; + break; + } + + if (mPosition < 0) { + mPosition = 0; + } + + if (mPosition > mLength) { + mPosition = mLength; + } + + return mPosition - oldPos; +} + +s32 JSUMemoryOutputStream::getLength() const { + return mLength; +} -- cgit v1.2.3