mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-04 11:19:58 -04:00
most of JHostIO / m_Do_hostIO done (#2288)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "JSystem/JSupport/JSUInputStream.h"
|
||||
#include "JSystem/JSupport/JSURandomInputStream.h"
|
||||
#include <dolphin.h>
|
||||
|
||||
//
|
||||
// Forward References:
|
||||
@@ -38,7 +39,11 @@ extern void* __vt__20JSURandomInputStream[9] = {
|
||||
};
|
||||
|
||||
/* 802DC23C-802DC298 2D6B7C 005C+00 1/0 6/6 0/0 .text __dt__14JSUInputStreamFv */
|
||||
JSUInputStream::~JSUInputStream() {}
|
||||
JSUInputStream::~JSUInputStream() {
|
||||
if (!isGood()) {
|
||||
OS_REPORT("JSUInputStream: occur error.\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* 802DC298-802DC2F0 2D6BD8 0058+00 1/1 20/20 0/0 .text read__14JSUInputStreamFPvl */
|
||||
s32 JSUInputStream::read(void* buffer, s32 numBytes) {
|
||||
@@ -49,29 +54,46 @@ s32 JSUInputStream::read(void* buffer, s32 numBytes) {
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
char* JSUInputStream::read(char* str) {
|
||||
u16 sp8;
|
||||
if (readData(&sp8, sizeof(sp8)) != sizeof(sp8)) {
|
||||
*str = 0;
|
||||
setState(IOS_STATE_1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 len = readData(str, sp8);
|
||||
str[len] = 0;
|
||||
if (len != sp8) {
|
||||
setState(IOS_STATE_1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/* 802DC2F0-802DC370 2D6C30 0080+00 1/0 0/0 0/0 .text skip__14JSUInputStreamFl */
|
||||
s32 JSUInputStream::skip(s32 count) {
|
||||
u8 buffer;
|
||||
s32 skipCount = 0;
|
||||
u8 buffer[1];
|
||||
while (count > skipCount) {
|
||||
if (readData(&buffer, 1) != 1) {
|
||||
for (; skipCount < count; skipCount++) {
|
||||
if (readData(&buffer, sizeof(buffer)) != sizeof(buffer)) {
|
||||
setState(IOS_STATE_1);
|
||||
break;
|
||||
}
|
||||
skipCount++;
|
||||
}
|
||||
|
||||
return skipCount;
|
||||
}
|
||||
|
||||
/* 802DC370-802DC3FC 2D6CB0 008C+00 0/0 1/1 0/0 .text align__20JSURandomInputStreamFl */
|
||||
s32 JSURandomInputStream::align(s32 alignment) {
|
||||
s32 seekLen = 0;
|
||||
s32 currentPos = getPosition();
|
||||
s32 offset = (alignment + currentPos);
|
||||
offset -= 1;
|
||||
offset &= ~(alignment - 1);
|
||||
|
||||
s32 offset = (alignment - 1 + currentPos) & ~(alignment - 1);
|
||||
s32 alignmentOffset = offset - currentPos;
|
||||
|
||||
if (alignmentOffset != 0) {
|
||||
s32 seekLen = seekPos(offset, JSUStreamSeekFrom_SET);
|
||||
seekLen = seekPos(offset, JSUStreamSeekFrom_SET);
|
||||
if (seekLen != alignmentOffset) {
|
||||
setState(IOS_STATE_1);
|
||||
}
|
||||
@@ -104,4 +126,4 @@ s32 JSURandomInputStream::seek(s32 param_0, JSUStreamSeekFrom param_1) {
|
||||
s32 seekResult = seekPos(param_0, param_1);
|
||||
clrState(IOS_STATE_1);
|
||||
return seekResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "JSystem/JSupport/JSUOutputStream.h"
|
||||
#include "JSystem/JSupport/JSURandomOutputStream.h"
|
||||
#include <dolphin.h>
|
||||
#include <cstring.h>
|
||||
|
||||
JSUOutputStream::~JSUOutputStream() {
|
||||
if (!isGood()) {
|
||||
OS_REPORT("JSUOutputStream: occur error.\n");
|
||||
}
|
||||
}
|
||||
|
||||
s32 JSUOutputStream::write(const void* buffer, s32 numBytes) {
|
||||
s32 bytesWrote = writeData(buffer, numBytes);
|
||||
if (bytesWrote != numBytes) {
|
||||
setState(IOS_STATE_1);
|
||||
}
|
||||
return bytesWrote;
|
||||
}
|
||||
|
||||
void JSUOutputStream::write(const char* str) {
|
||||
if (str == NULL) {
|
||||
u16 spA = 0;
|
||||
if (writeData(&spA, sizeof(spA)) != sizeof(spA)) {
|
||||
setState(IOS_STATE_1);
|
||||
}
|
||||
} else {
|
||||
int len = strlen(str);
|
||||
if (len >= 0x10000) {
|
||||
setState(IOS_STATE_2);
|
||||
} else {
|
||||
u16 sp8 = len;
|
||||
if (writeData(&sp8, sizeof(sp8)) != sizeof(sp8) || writeData(str, len) != len) {
|
||||
setState(IOS_STATE_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s32 JSUOutputStream::skip(s32 count, s8 param_1) {
|
||||
s32 skipCount = 0;
|
||||
for (; skipCount < count; skipCount++) {
|
||||
if (writeData(¶m_1, sizeof(param_1)) != sizeof(param_1)) {
|
||||
setState(IOS_STATE_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return skipCount;
|
||||
}
|
||||
|
||||
s32 JSURandomOutputStream::seek(s32 param_0, JSUStreamSeekFrom param_1) {
|
||||
s32 seekResult = seekPos(param_0, param_1);
|
||||
clrState(IOS_STATE_1);
|
||||
return seekResult;
|
||||
}
|
||||
|
||||
s32 JSURandomOutputStream::getAvailable() const {
|
||||
return getLength() - getPosition();
|
||||
}
|
||||
Reference in New Issue
Block a user