diff --git a/configure.py b/configure.py index 5bd9325e..9e9fd86c 100644 --- a/configure.py +++ b/configure.py @@ -657,9 +657,9 @@ config.libs = [ JSystemLib( "JSupport", [ - Object(NonMatching, "JSystem/JSupport/JSUFileStream.cpp"), + Object(Matching, "JSystem/JSupport/JSUFileStream.cpp"), Object(Matching, "JSystem/JSupport/JSUInputStream.cpp"), - Object(NonMatching, "JSystem/JSupport/JSUList.cpp"), + Object(Matching, "JSystem/JSupport/JSUList.cpp"), ], ), JSystemLib( diff --git a/include/JSystem/JKernel/JKRArchive.h b/include/JSystem/JKernel/JKRArchive.h index 0028b253..ad5b8138 100644 --- a/include/JSystem/JKernel/JKRArchive.h +++ b/include/JSystem/JKernel/JKRArchive.h @@ -130,17 +130,17 @@ public: JKRArchive(s32, EMountMode); virtual ~JKRArchive(); // _08 - virtual bool becomeCurrent(const char*); // _10 + virtual bool becomeCurrent(const char*); // _10 virtual void* getResource(const char* path); // _14 virtual void* getResource(u32 type, const char* name); // _18 virtual size_t readResource(void* resourceBuffer, u32 bufferSize, const char* path, JKRExpandSwitch expandSwitch); // _1C virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type, const char* name); // _20 virtual void removeResourceAll(); // _24 - virtual bool removeResource(void*); // _28 - virtual bool detachResource(void*); // _2C - virtual s32 getResSize(const void*) const; // _30 - virtual u32 countFile(const char*) const; // _34 - virtual JKRFileFinder* getFirstFile(const char*) const; // _38 + virtual bool removeResource(void*); // _28 + virtual bool detachResource(void*); // _2C + virtual s32 getResSize(const void*) const; // _30 + virtual u32 countFile(const char*) const; // _34 + virtual JKRFileFinder* getFirstFile(const char*) const; // _38 virtual void* fetchResource(SDIFileEntry* entry, u32* outSize) = 0; // _40 virtual void* fetchResource(void* resourceBuffer, u32 bufferSize, SDIFileEntry* entry, u32* resSize, JKRExpandSwitch expandSwitch) = 0; // _44 diff --git a/include/JSystem/JKernel/JKRFileLoader.h b/include/JSystem/JKernel/JKRFileLoader.h index aa69b0dc..ef46ff9b 100644 --- a/include/JSystem/JKernel/JKRFileLoader.h +++ b/include/JSystem/JKernel/JKRFileLoader.h @@ -56,7 +56,6 @@ protected: const char* mVolumeName; // 0x28 u32 mVolumeType; // 0x2C bool mIsMounted; // 0x30 - u8 field_0x31[3]; // 0x31 u32 mMountCount; // 0x34 }; diff --git a/include/JSystem/JSupport/JSUFileInputStream.h b/include/JSystem/JSupport/JSUFileInputStream.h index 254cd086..fbcc0915 100644 --- a/include/JSystem/JSupport/JSUFileInputStream.h +++ b/include/JSystem/JSupport/JSUFileInputStream.h @@ -23,6 +23,12 @@ protected: const void* mObject; s32 mPosition; }; + +class JSUFileOutputStream : public JSURandomOutputStream { +public: + JSUFileOutputStream(JKRFile *); +}; + #endif #endif diff --git a/include/JSystem/JSupport/JSUInputStream.h b/include/JSystem/JSupport/JSUInputStream.h index 5a0da358..6a6a4fd2 100644 --- a/include/JSystem/JSupport/JSUInputStream.h +++ b/include/JSystem/JSupport/JSUInputStream.h @@ -107,6 +107,15 @@ public: return *this; } }; + +class JSUOutputStream : protected JSUIosBase { +public: + virtual ~JSUOutputStream(); + virtual int getAvailable() const = 0; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 size) = 0; +}; + #endif #endif diff --git a/include/JSystem/JSupport/JSURandomInputStream.h b/include/JSystem/JSupport/JSURandomInputStream.h index 94ca235b..fb59ebb1 100644 --- a/include/JSystem/JSupport/JSURandomInputStream.h +++ b/include/JSystem/JSupport/JSURandomInputStream.h @@ -21,6 +21,23 @@ public: int peek(void* buf, s32 len); int seek(s32 offset, JSUStreamSeekFrom from); }; + +class JSURandomOutputStream : public JSUOutputStream { +public: + virtual ~JSURandomOutputStream() { } + + virtual int getAvailable() const; + virtual int skip(s32 amount); + virtual int readData(void* buf, s32 count) = 0; + virtual int getLength() const = 0; + virtual int getPosition() const = 0; + virtual int seekPos(s32 offset, JSUStreamSeekFrom from) = 0; + + int align(s32 alignment); + int peek(void* buf, s32 len); + int seek(s32 offset, JSUStreamSeekFrom from); +}; + #endif #endif diff --git a/src/static/JSystem/JKernel/JKRArchivePub.cpp b/src/static/JSystem/JKernel/JKRArchivePub.cpp index e7d41f92..c3fffbd0 100644 --- a/src/static/JSystem/JKernel/JKRArchivePub.cpp +++ b/src/static/JSystem/JKernel/JKRArchivePub.cpp @@ -18,9 +18,8 @@ JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* pHeap) { heap = JKRGetCurrentHeap(); } - JSUList& volumeList = JKRArchive::sVolumeList; JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); + for (iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) { if (iterator->getVolumeType() == 'RARC') { JKRArchive* archive = @@ -36,9 +35,7 @@ JKRArchive* JKRArchive::check_mount_already(s32 entryNum, JKRHeap* pHeap) { } JKRArchive* JKRArchive::check_mount_already(s32 entryNum) { - JSUList& volumeList = JKRArchive::sVolumeList; - JSUListIterator iterator; - for (iterator = volumeList.getFirst(); iterator != volumeList.getEnd(); + for (JSUListIterator iterator = sVolumeList.getFirst(); iterator != sVolumeList.getEnd(); ++iterator) { if (iterator->getVolumeType() == 'RARC') { JKRArchive* archive = diff --git a/src/static/JSystem/JSupport/JSUFileStream.cpp b/src/static/JSystem/JSupport/JSUFileStream.cpp index 6dfa820d..ae299a09 100644 --- a/src/static/JSystem/JSupport/JSUFileStream.cpp +++ b/src/static/JSystem/JSupport/JSUFileStream.cpp @@ -49,3 +49,7 @@ int JSUFileInputStream::seekPos(s32 offset, JSUStreamSeekFrom from) { return this->mPosition - pos; } + +JSUFileOutputStream::JSUFileOutputStream(JKRFile *file) { + +} \ No newline at end of file diff --git a/src/static/JSystem/JSupport/JSUList.cpp b/src/static/JSystem/JSupport/JSUList.cpp new file mode 100644 index 00000000..c1a8cf26 --- /dev/null +++ b/src/static/JSystem/JSupport/JSUList.cpp @@ -0,0 +1,166 @@ +#include "JSystem/JSupport/JSUList.h" + +JSUPtrLink::JSUPtrLink(void *pData) { + mPtrList = 0; + mData = pData; + mPrev = 0; + mNext = 0; +} + +JSUPtrLink::~JSUPtrLink() { + if (mPtrList) { + mPtrList->remove(this); + } +} + +JSUPtrList::JSUPtrList(bool doInitialize) { + if (doInitialize) { + initiate(); + } +} + +JSUPtrList::~JSUPtrList() { + JSUPtrLink* curHead = mHead; + + for (int i = 0; i < mLinkCount; i++) { + curHead->mPtrList = 0; + curHead = curHead->mNext; + } +} + +void JSUPtrList::initiate() { + mHead = 0; + mTail = 0; + mLinkCount = 0; +} + +void JSUPtrList::setFirst(JSUPtrLink *pLink) { + pLink->mPtrList = this; + pLink->mPrev = 0; + pLink->mNext = 0; + mTail = pLink; + mHead = pLink; + mLinkCount = 1; +} + +bool JSUPtrList::append(JSUPtrLink *pLink) { + bool validity = (pLink->mPtrList == 0); + + if (!validity) { + validity = pLink->mPtrList->remove(pLink); + } + + if (validity) { + if (!mLinkCount) { + setFirst(pLink); + } + else { + pLink->mPtrList = this; + pLink->mPrev = mTail; + pLink->mNext = 0; + mTail->mNext = pLink; + mTail = pLink; + mLinkCount = mLinkCount + 1; + } + } + + return validity; +} + +bool JSUPtrList::prepend(JSUPtrLink *pLink) { + bool validity = (pLink->mPtrList == 0); + + if (!validity) { + validity = pLink->mPtrList->remove(pLink); + } + + if (validity) { + if (!mLinkCount) { + setFirst(pLink); + } + else { + pLink->mPtrList = this; + pLink->mPrev = 0; + pLink->mNext = mHead; + mHead->mPrev = pLink; + mHead = pLink; + mLinkCount = mLinkCount + 1; + } + } + + return validity; +} + +bool JSUPtrList::insert(JSUPtrLink *pLink_1, JSUPtrLink *pLink_2) { + if (pLink_1 == mHead) { + return prepend(pLink_2); + } + if (!pLink_1) { + return append(pLink_2); + } + if (pLink_1->mPtrList != this) { + return false; + } + + JSUPtrList* link2PtrList = pLink_2->mPtrList; + + bool validity = (link2PtrList == 0); + + if (!validity) { + validity = link2PtrList->remove(pLink_2); + } + + if (validity) { + JSUPtrLink* prev = pLink_1->mPrev; + pLink_2->mPtrList = this; + pLink_2->mPrev = prev; + pLink_2->mNext = pLink_1; + prev->mNext = pLink_2; + pLink_1->mPrev = pLink_2; + mLinkCount++; + } + + return validity; +} + +bool JSUPtrList::remove(JSUPtrLink *pLink) { + bool isSameList = (pLink->mPtrList == this); + + if (isSameList) { + if (mLinkCount == 1) { + mHead = 0; + mTail = 0; + } + else if (pLink == mHead) { + pLink->mNext->mPrev = 0; + mHead = pLink->mNext; + } + else if (pLink == mTail) { + pLink->mPrev->mNext = 0; + mTail = pLink->mPrev; + } + else { + pLink->mPrev->mNext = pLink->mNext; + pLink->mNext->mPrev = pLink->mPrev; + } + + pLink->mPtrList = 0; + mLinkCount--; + } + + return isSameList; +} + +JSUPtrLink *JSUPtrList::getNthLink(u32 n) const +{ + if (n >= mLinkCount) + { + return nullptr; + } + JSUPtrLink *curHead = mHead; + for (int i = 0; i < n; i++) + { + curHead = curHead->mNext; + } + return curHead; +} \ No newline at end of file