JUtility / JSupport / misc cleanup

This commit is contained in:
TakaRikka
2023-02-26 22:18:40 -08:00
parent 090dcee012
commit eae9455a7d
27 changed files with 442 additions and 457 deletions
+6 -8
View File
@@ -4,12 +4,6 @@
//
#include "JSystem/JSupport/JSUFileStream.h"
#include "dol2asm.h"
#include "dolphin/types.h"
//
// Declarations:
//
/* 802DC638-802DC67C 2D6F78 0044+00 0/0 1/1 0/0 .text __ct__18JSUFileInputStreamFP7JKRFile */
JSUFileInputStream::JSUFileInputStream(JKRFile* pFile) {
@@ -22,11 +16,10 @@ JSUFileInputStream::JSUFileInputStream(JKRFile* pFile) {
u32 JSUFileInputStream::readData(void* pBuffer, s32 length) {
s32 lenRead = 0;
if (mFile->isAvailable()) {
// TODO: the function probably returns u32
// there are probably more functions that return u32 instead of s32
if (mPosition + length > (u32)mFile->getFileSize()) {
length = mFile->getFileSize() - mPosition;
}
if (length > 0) {
lenRead = mFile->readData(pBuffer, length, mPosition);
if (lenRead < 0) {
@@ -36,6 +29,7 @@ u32 JSUFileInputStream::readData(void* pBuffer, s32 length) {
}
}
}
return lenRead;
}
@@ -43,6 +37,7 @@ u32 JSUFileInputStream::readData(void* pBuffer, s32 length) {
* seekPos__18JSUFileInputStreamFl17JSUStreamSeekFrom */
s32 JSUFileInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
s32 oldPos = mPosition;
switch (seekFrom) {
case JSUStreamSeekFrom_SET:
mPosition = pos;
@@ -54,12 +49,15 @@ s32 JSUFileInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
mPosition += pos;
break;
}
if (mPosition < 0) {
mPosition = 0;
}
if (mPosition > mFile->getFileSize()) {
mPosition = mFile->getFileSize();
}
return mPosition - oldPos;
}
+14 -44
View File
@@ -5,37 +5,19 @@
#include "JSystem/JSupport/JSUInputStream.h"
#include "JSystem/JSupport/JSURandomInputStream.h"
#include "dol2asm.h"
#include "global.h"
//
// Types:
//
//
// Forward References:
//
extern "C" void __dt__14JSUInputStreamFv();
extern "C" void read__14JSUInputStreamFPvl();
extern "C" void skip__14JSUInputStreamFl();
extern "C" void align__20JSURandomInputStreamFl();
extern "C" void skip__20JSURandomInputStreamFl();
extern "C" void peek__20JSURandomInputStreamFPvl();
extern "C" void seek__20JSURandomInputStreamFl17JSUStreamSeekFrom();
//
// External References:
//
extern "C" void __dt__20JSURandomInputStreamFv();
extern "C" void __dl__FPv();
extern "C" void getAvailable__20JSURandomInputStreamCFv();
extern "C" void _savegpr_28();
extern "C" void _savegpr_29();
extern "C" void _restgpr_28();
extern "C" void _restgpr_29();
extern "C" extern void* __vt__10JSUIosBase[3];
//
// Declarations:
@@ -43,7 +25,7 @@ extern "C" extern void* __vt__10JSUIosBase[3];
/* ############################################################################################## */
/* 803CC4B0-803CC4D4 0295D0 0024+00 0/0 7/7 0/0 .data __vt__20JSURandomInputStream */
SECTION_DATA extern void* __vt__20JSURandomInputStream[9] = {
extern void* __vt__20JSURandomInputStream[9] = {
(void*)NULL /* RTTI */,
(void*)NULL,
(void*)__dt__20JSURandomInputStreamFv,
@@ -55,26 +37,14 @@ SECTION_DATA extern void* __vt__20JSURandomInputStream[9] = {
(void*)NULL,
};
/* 803CC4D4-803CC4F0 0295F4 0018+04 1/1 4/4 0/0 .data __vt__14JSUInputStream */
SECTION_DATA extern void* __vt__14JSUInputStream[6 + 1 /* padding */] = {
(void*)NULL /* RTTI */,
(void*)NULL,
(void*)__dt__14JSUInputStreamFv,
(void*)NULL,
(void*)skip__14JSUInputStreamFl,
(void*)NULL,
/* padding */
NULL,
};
/* 802DC23C-802DC298 2D6B7C 005C+00 1/0 6/6 0/0 .text __dt__14JSUInputStreamFv */
JSUInputStream::~JSUInputStream() {}
/* 802DC298-802DC2F0 2D6BD8 0058+00 1/1 20/20 0/0 .text read__14JSUInputStreamFPvl */
s32 JSUInputStream::read(void* buffer, s32 numBytes) {
s32 bytesRead = this->readData(buffer, numBytes);
s32 bytesRead = readData(buffer, numBytes);
if (bytesRead != numBytes) {
this->setState(IOS_STATE_1);
setState(IOS_STATE_1);
}
return bytesRead;
}
@@ -84,7 +54,7 @@ s32 JSUInputStream::skip(s32 count) {
s32 skipCount = 0;
u8 buffer[1];
while (count > skipCount) {
if (this->readData(&buffer, 1) != 1) {
if (readData(&buffer, 1) != 1) {
setState(IOS_STATE_1);
break;
}
@@ -95,15 +65,15 @@ s32 JSUInputStream::skip(s32 count) {
/* 802DC370-802DC3FC 2D6CB0 008C+00 0/0 1/1 0/0 .text align__20JSURandomInputStreamFl */
s32 JSURandomInputStream::align(s32 alignment) {
s32 currentPos = this->getPosition();
s32 currentPos = getPosition();
s32 offset = (alignment + currentPos);
offset -= 1;
offset &= ~(alignment - 1);
s32 alignmentOffset = offset - currentPos;
if (alignmentOffset != 0) {
s32 seekLen = this->seekPos(offset, JSUStreamSeekFrom_SET);
s32 seekLen = seekPos(offset, JSUStreamSeekFrom_SET);
if (seekLen != alignmentOffset) {
this->setState(IOS_STATE_1);
setState(IOS_STATE_1);
}
}
return alignmentOffset;
@@ -111,19 +81,19 @@ s32 JSURandomInputStream::align(s32 alignment) {
/* 802DC3FC-802DC458 2D6D3C 005C+00 1/0 2/0 0/0 .text skip__20JSURandomInputStreamFl */
s32 JSURandomInputStream::skip(s32 param_0) {
s32 val = this->seekPos(param_0, JSUStreamSeekFrom_CUR);
s32 val = seekPos(param_0, JSUStreamSeekFrom_CUR);
if (val != param_0) {
this->setState(IOS_STATE_1);
setState(IOS_STATE_1);
}
return val;
}
/* 802DC458-802DC4DC 2D6D98 0084+00 0/0 8/8 0/0 .text peek__20JSURandomInputStreamFPvl */
s32 JSURandomInputStream::peek(void* buffer, s32 numBytes) {
s32 oldPos = this->getPosition();
s32 bytesRead = this->read(buffer, numBytes);
s32 oldPos = getPosition();
s32 bytesRead = read(buffer, numBytes);
if (bytesRead != 0) {
this->seekPos(oldPos, JSUStreamSeekFrom_SET);
seekPos(oldPos, JSUStreamSeekFrom_SET);
}
return bytesRead;
}
@@ -131,7 +101,7 @@ s32 JSURandomInputStream::peek(void* buffer, s32 numBytes) {
/* 802DC4DC-802DC520 2D6E1C 0044+00 0/0 16/16 0/0 .text
* seek__20JSURandomInputStreamFl17JSUStreamSeekFrom */
s32 JSURandomInputStream::seek(s32 param_0, JSUStreamSeekFrom param_1) {
s32 seekResult = this->seekPos(param_0, param_1);
this->clrState(IOS_STATE_1);
s32 seekResult = seekPos(param_0, param_1);
clrState(IOS_STATE_1);
return seekResult;
}
+41 -43
View File
@@ -4,32 +4,30 @@
//
#include "JSystem/JSupport/JSUList.h"
#include "dol2asm.h"
#include "dolphin/types.h"
JSUPtrLink::JSUPtrLink(void* object) {
this->mList = NULL;
this->mObject = object;
this->mPrev = NULL;
this->mNext = NULL;
mList = NULL;
mObject = object;
mPrev = NULL;
mNext = NULL;
}
JSUPtrLink::~JSUPtrLink() {
if (this->mList != NULL) {
this->mList->remove(this);
if (mList != NULL) {
mList->remove(this);
}
}
JSUPtrList::JSUPtrList(bool init) {
if (init) {
this->initiate();
initiate();
}
}
JSUPtrList::~JSUPtrList() {
JSUPtrLink* node = this->mHead;
JSUPtrLink* node = mHead;
s32 removed = 0;
while (this->mLength > removed) {
while (mLength > removed) {
node->mList = NULL;
node = node->getNext();
removed += 1;
@@ -37,18 +35,18 @@ JSUPtrList::~JSUPtrList() {
}
void JSUPtrList::initiate() {
this->mHead = NULL;
this->mTail = NULL;
this->mLength = 0;
mHead = NULL;
mTail = NULL;
mLength = 0;
}
void JSUPtrList::setFirst(JSUPtrLink* first) {
first->mList = this;
first->mPrev = NULL;
first->mNext = NULL;
this->mTail = first;
this->mHead = first;
this->mLength = 1;
mTail = first;
mHead = first;
mLength = 1;
}
bool JSUPtrList::append(JSUPtrLink* ptr) {
@@ -59,15 +57,15 @@ bool JSUPtrList::append(JSUPtrLink* ptr) {
}
if (result) {
if (this->mLength == 0) {
this->setFirst(ptr);
if (mLength == 0) {
setFirst(ptr);
} else {
ptr->mList = this;
ptr->mPrev = this->mTail;
ptr->mPrev = mTail;
ptr->mNext = NULL;
this->mTail->mNext = ptr;
this->mTail = ptr;
this->mLength++;
mTail->mNext = ptr;
mTail = ptr;
mLength++;
}
}
@@ -82,15 +80,15 @@ bool JSUPtrList::prepend(JSUPtrLink* ptr) {
}
if (result) {
if (this->mLength == 0) {
this->setFirst(ptr);
if (mLength == 0) {
setFirst(ptr);
} else {
ptr->mList = this;
ptr->mPrev = NULL;
ptr->mNext = this->mHead;
this->mHead->mPrev = ptr;
this->mHead = ptr;
this->mLength++;
ptr->mNext = mHead;
mHead->mPrev = ptr;
mHead = ptr;
mLength++;
}
}
@@ -98,10 +96,10 @@ bool JSUPtrList::prepend(JSUPtrLink* ptr) {
}
bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
if (before == this->mHead) {
return this->prepend(ptr);
if (before == mHead) {
return prepend(ptr);
} else if (before == NULL) {
return this->append(ptr);
return append(ptr);
}
if (before->mList != this) {
@@ -120,7 +118,7 @@ bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
ptr->mNext = before;
prev->mNext = ptr;
before->mPrev = ptr;
this->mLength++;
mLength++;
}
return result;
@@ -129,33 +127,33 @@ bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
bool JSUPtrList::remove(JSUPtrLink* ptr) {
bool is_parent = (ptr->mList == this);
if (is_parent) {
if (this->mLength == 1) {
this->mHead = NULL;
this->mTail = NULL;
} else if (ptr == this->mHead) {
if (mLength == 1) {
mHead = NULL;
mTail = NULL;
} else if (ptr == mHead) {
ptr->mNext->mPrev = NULL;
this->mHead = ptr->mNext;
} else if (ptr == this->mTail) {
mHead = ptr->mNext;
} else if (ptr == mTail) {
ptr->mPrev->mNext = NULL;
this->mTail = ptr->mPrev;
mTail = ptr->mPrev;
} else {
ptr->mPrev->mNext = ptr->mNext;
ptr->mNext->mPrev = ptr->mPrev;
}
ptr->mList = NULL;
this->mLength--;
mLength--;
}
return is_parent;
}
JSUPtrLink* JSUPtrList::getNthLink(u32 index) const {
if (index >= this->mLength) {
if (index >= mLength) {
return NULL;
}
JSUPtrLink* node = this->mHead;
JSUPtrLink* node = mHead;
for (u32 i = 0; i < index; i++) {
node = node->getNext();
}
+6 -6
View File
@@ -5,12 +5,6 @@
#include "JSystem/JSupport/JSUMemoryStream.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
//
// Declarations:
//
/* 802DC520-802DC534 2D6E60 0014+00 0/0 3/3 0/0 .text setBuffer__20JSUMemoryInputStreamFPCvl */
void JSUMemoryInputStream::setBuffer(void const* pBuffer, s32 length) {
@@ -24,10 +18,12 @@ u32 JSUMemoryInputStream::readData(void* pData, s32 length) {
if (mPosition + length > mLength) {
length = mLength - mPosition;
}
if (length > 0) {
memcpy(pData, (void*)((s32)mBuffer + mPosition), length);
mPosition += length;
}
return length;
}
@@ -35,6 +31,7 @@ u32 JSUMemoryInputStream::readData(void* pData, s32 length) {
* seekPos__20JSUMemoryInputStreamFl17JSUStreamSeekFrom */
s32 JSUMemoryInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
s32 oldPos = mPosition;
switch (seekFrom) {
case JSUStreamSeekFrom_SET:
mPosition = pos;
@@ -46,12 +43,15 @@ s32 JSUMemoryInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
mPosition += pos;
break;
}
if (mPosition < 0) {
mPosition = 0;
}
if (mPosition > mLength) {
mPosition = mLength;
}
return mPosition - oldPos;
}