mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-09-01 16:29:55 -04:00
Reorganize library code into libs/ (#3119)
* Reorganize files into libs/{dolphin,JSystem,PowerPC_EABI_Support,revolution,TRK_MINNOW_DOLPHIN}
* Update configure.py and project.py for new libs structure
* Refactor `#include <dolphin/x.h>` -> `<x.h>`
* Remove `__REVOLUTION_SDK__` forwards from dolphin
* Fix dolphin/ references in revolution
* Wrap `#include <dolphin.h>` in `!__REVOLUTION_SDK__`
* Always build TRK against dolphin headers
* Resolve revolution SDK header resolution issues
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JSupport/JSUFileStream.h"
|
||||
#include "JSystem/JKernel/JKRFile.h"
|
||||
|
||||
JSUFileInputStream::JSUFileInputStream(JKRFile* pFile) {
|
||||
mFile = pFile;
|
||||
mPosition = 0;
|
||||
}
|
||||
|
||||
u32 JSUFileInputStream::readData(void* pBuffer, s32 length) {
|
||||
s32 lenRead = 0;
|
||||
if (mFile->isAvailable()) {
|
||||
if (mPosition + length > (u32)mFile->getFileSize()) {
|
||||
length = mFile->getFileSize() - mPosition;
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
lenRead = mFile->readData(pBuffer, length, mPosition);
|
||||
if (lenRead < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
mPosition += lenRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lenRead;
|
||||
}
|
||||
|
||||
s32 JSUFileInputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) {
|
||||
s32 oldPos = mPosition;
|
||||
|
||||
switch (seekFrom) {
|
||||
case JSUStreamSeekFrom_SET:
|
||||
mPosition = pos;
|
||||
break;
|
||||
case JSUStreamSeekFrom_END:
|
||||
mPosition = mFile->getFileSize() - pos;
|
||||
break;
|
||||
case JSUStreamSeekFrom_CUR:
|
||||
mPosition += pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mPosition < 0) {
|
||||
mPosition = 0;
|
||||
}
|
||||
|
||||
if (mPosition > mFile->getFileSize()) {
|
||||
mPosition = mFile->getFileSize();
|
||||
}
|
||||
|
||||
return mPosition - oldPos;
|
||||
}
|
||||
|
||||
s32 JSUFileInputStream::getLength() const {
|
||||
return mFile->getFileSize();
|
||||
}
|
||||
|
||||
s32 JSUFileInputStream::getPosition() const {
|
||||
return mPosition;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JSupport/JSUInputStream.h"
|
||||
#include "JSystem/JSupport/JSURandomInputStream.h"
|
||||
#ifdef __REVOLUTION_SDK__
|
||||
#include <revolution.h>
|
||||
#else
|
||||
#include <dolphin.h>
|
||||
#endif
|
||||
|
||||
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) {
|
||||
s32 skipCount;
|
||||
for (skipCount = 0; skipCount < count; skipCount++) {
|
||||
u8 buffer;
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JSupport/JSUList.h"
|
||||
|
||||
JSUPtrLink::JSUPtrLink(void* object) {
|
||||
mList = NULL;
|
||||
mObject = object;
|
||||
mPrev = NULL;
|
||||
mNext = NULL;
|
||||
}
|
||||
|
||||
JSUPtrLink::~JSUPtrLink() {
|
||||
if (mList != NULL) {
|
||||
mList->remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
JSUPtrList::JSUPtrList(bool init) {
|
||||
if (init) {
|
||||
initiate();
|
||||
}
|
||||
}
|
||||
|
||||
JSUPtrList::~JSUPtrList() {
|
||||
JSUPtrLink* node = mHead;
|
||||
for (int i = 0; i < mLength; i++) {
|
||||
node->mList = NULL;
|
||||
node = node->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
void JSUPtrList::initiate() {
|
||||
mHead = NULL;
|
||||
mTail = NULL;
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
void JSUPtrList::setFirst(JSUPtrLink* first) {
|
||||
first->mList = this;
|
||||
first->mPrev = NULL;
|
||||
first->mNext = NULL;
|
||||
mTail = first;
|
||||
mHead = first;
|
||||
mLength = 1;
|
||||
}
|
||||
|
||||
bool JSUPtrList::append(JSUPtrLink* ptr) {
|
||||
bool result = ptr->mList == NULL;
|
||||
if (!result) {
|
||||
result = ptr->mList->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (mLength == 0) {
|
||||
setFirst(ptr);
|
||||
} else {
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = mTail;
|
||||
ptr->mNext = NULL;
|
||||
mTail->mNext = ptr;
|
||||
mTail = ptr;
|
||||
mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JSUPtrList::prepend(JSUPtrLink* ptr) {
|
||||
bool result = ptr->mList == NULL;
|
||||
if (!result) {
|
||||
result = ptr->mList->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (mLength == 0) {
|
||||
setFirst(ptr);
|
||||
} else {
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = NULL;
|
||||
ptr->mNext = mHead;
|
||||
mHead->mPrev = ptr;
|
||||
mHead = ptr;
|
||||
mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
|
||||
if (before == mHead) {
|
||||
return prepend(ptr);
|
||||
} else if (before == NULL) {
|
||||
return append(ptr);
|
||||
}
|
||||
|
||||
if (before->mList != this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = ptr->mList == NULL;
|
||||
if (!result) {
|
||||
result = ptr->mList->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
JSUPtrLink* prev = before->mPrev;
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = prev;
|
||||
ptr->mNext = before;
|
||||
prev->mNext = ptr;
|
||||
before->mPrev = ptr;
|
||||
mLength++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool JSUPtrList::remove(JSUPtrLink* ptr) {
|
||||
bool is_parent = (ptr->mList == this);
|
||||
if (is_parent) {
|
||||
if (mLength == 1) {
|
||||
mHead = NULL;
|
||||
mTail = NULL;
|
||||
} else if (ptr == mHead) {
|
||||
ptr->mNext->mPrev = NULL;
|
||||
mHead = ptr->mNext;
|
||||
} else if (ptr == mTail) {
|
||||
ptr->mPrev->mNext = NULL;
|
||||
mTail = ptr->mPrev;
|
||||
} else {
|
||||
ptr->mPrev->mNext = ptr->mNext;
|
||||
ptr->mNext->mPrev = ptr->mPrev;
|
||||
}
|
||||
|
||||
ptr->mList = NULL;
|
||||
mLength--;
|
||||
}
|
||||
|
||||
return is_parent;
|
||||
}
|
||||
|
||||
JSUPtrLink* JSUPtrList::getNthLink(u32 index) const {
|
||||
if (index >= mLength) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSUPtrLink* node = mHead;
|
||||
for (u32 i = 0; i < index; i++) {
|
||||
node = node->mNext;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JSupport/JSUMemoryStream.h"
|
||||
#include <cstring>
|
||||
|
||||
void JSUMemoryInputStream::setBuffer(void const* pBuffer, s32 length) {
|
||||
mBuffer = pBuffer;
|
||||
mLength = length;
|
||||
mPosition = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
s32 JSUMemoryInputStream::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 JSUMemoryInputStream::getLength() const {
|
||||
return mLength;
|
||||
}
|
||||
|
||||
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,65 @@
|
||||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JSupport/JSUOutputStream.h"
|
||||
#include "JSystem/JSupport/JSURandomOutputStream.h"
|
||||
#ifdef __REVOLUTION_SDK__
|
||||
#include <revolution.h>
|
||||
#else
|
||||
#include <dolphin.h>
|
||||
#endif
|
||||
#include <cstring>
|
||||
|
||||
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