Files
tp/src/JSystem/JSupport/JSUInputStream.cpp
T
kipcode66 3b26aae532 Improving standard compiler compatibility (#2926)
* Adding explicit dolphin/ prefix & fix characters

* Rename ShiftJIS to SJIS

* Separate JASSeqReader read methods implementation between compilers.

* Fix pointer.h

* fix d_item_data typo

* fix gcn matching issue
2025-12-08 20:31:22 -08:00

88 lines
2.1 KiB
C++

#include "JSystem/JSystem.h" // IWYU pragma: keep
#include "JSystem/JSupport/JSUInputStream.h"
#include "JSystem/JSupport/JSURandomInputStream.h"
#include <dolphin/dolphin.h>
JSUInputStream::~JSUInputStream() {
if (!isGood()) {
OS_REPORT("JSUInputStream: occur error.\n");
}
}
s32 JSUInputStream::read(void* buffer, s32 numBytes) {
s32 bytesRead = readData(buffer, numBytes);
if (bytesRead != numBytes) {
setState(IOS_STATE_1);
}
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;
}
s32 JSUInputStream::skip(s32 count) {
u8 buffer;
s32 skipCount = 0;
for (; skipCount < count; skipCount++) {
if (readData(&buffer, sizeof(buffer)) != sizeof(buffer)) {
setState(IOS_STATE_1);
break;
}
}
return skipCount;
}
s32 JSURandomInputStream::align(s32 alignment) {
s32 seekLen = 0;
s32 currentPos = getPosition();
s32 offset = (alignment - 1 + currentPos) & ~(alignment - 1);
s32 alignmentOffset = offset - currentPos;
if (alignmentOffset != 0) {
seekLen = seekPos(offset, JSUStreamSeekFrom_SET);
if (seekLen != alignmentOffset) {
setState(IOS_STATE_1);
}
}
return alignmentOffset;
}
s32 JSURandomInputStream::skip(s32 param_0) {
s32 val = seekPos(param_0, JSUStreamSeekFrom_CUR);
if (val != param_0) {
setState(IOS_STATE_1);
}
return val;
}
s32 JSURandomInputStream::peek(void* buffer, s32 numBytes) {
s32 oldPos = getPosition();
s32 bytesRead = read(buffer, numBytes);
if (bytesRead != 0) {
seekPos(oldPos, JSUStreamSeekFrom_SET);
}
return bytesRead;
}
s32 JSURandomInputStream::seek(s32 param_0, JSUStreamSeekFrom param_1) {
s32 seekResult = seekPos(param_0, param_1);
clrState(IOS_STATE_1);
return seekResult;
}