mirror of
https://github.com/zeldaret/tp
synced 2026-07-31 00:04:58 -04:00
JSUList.h templates and JKRHeap matches (#13)
* JSULink, JSUList, JSUTree and more matching in JKRHeap * Added JSUListIterator and decompiled JKRHeap::dispose_subroutine * more templates and JKRHeap functions * JKRDisposer! * only 4 functions not OK in JKRHeap * fixed: *this->getObject() Co-authored-by: Pheenoh <pheenoh@gmail.com>
This commit is contained in:
@@ -3,36 +3,17 @@
|
||||
#include "JSystem/JKernel/JKRHeap/JKRHeap.h"
|
||||
|
||||
// #include "JSystem/JKernel/asm/func_802D147C.s"
|
||||
JKRDisposer::JKRDisposer() : ptr_link(this) {
|
||||
this->heap = JKRHeap::findFromRoot(this);
|
||||
if (this->heap != 0) {
|
||||
this->heap->disposable_list.append(&this->ptr_link);
|
||||
JKRDisposer::JKRDisposer() : mLink(this) {
|
||||
this->mHeap = JKRHeap::findFromRoot(this);
|
||||
if (this->mHeap) {
|
||||
this->mHeap->appendDisposer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Super close.
|
||||
|
||||
This is what we expected: (from Ghidra)
|
||||
if (this != (JKRDisposer *)&DAT_fffffff8) {
|
||||
JSUPtrLink::~JSUPtrLink(&this->ptr_link,0);
|
||||
}
|
||||
|
||||
But the compiler generate code like this instead: (no if and -1 instead of 0)
|
||||
JSUPtrLink::~JSUPtrLink(&this->ptr_link,-1);
|
||||
|
||||
Maybe we are using the wrong compiler?
|
||||
*/
|
||||
#ifdef NONMATCHING
|
||||
// #include "JSystem/JKernel/JKRDisposer/asm/func_802D14E4.s"
|
||||
JKRDisposer::~JKRDisposer() {
|
||||
JKRHeap* heap = this->heap;
|
||||
if (heap != 0) {
|
||||
heap->disposable_list.remove(&this->ptr_link);
|
||||
}
|
||||
JKRHeap* heap = this->mHeap;
|
||||
if (heap) {
|
||||
heap->removeDisposer(this);
|
||||
}
|
||||
}
|
||||
#else
|
||||
asm JKRDisposer::~JKRDisposer() {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRDisposer/asm/func_802D14E4.s"
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,36 +1,20 @@
|
||||
#include "JSystem/JKernel/JKRHeap/JKRHeap.h"
|
||||
#include "global.h"
|
||||
|
||||
/*
|
||||
Very close! When initialzing child_list(true) it will use less register then the asm code.
|
||||
- 2cb0b0: 3b 5f 00 40 addi r26,r31,64
|
||||
- 2cb0b4: 7f 43 d3 78 mr r3,r26
|
||||
- 2cb0b8: 48 00 dd 9d bl 0x2d8e54
|
||||
- 2cb0bc: 38 7a 00 0c addi r3,r26,12
|
||||
|
||||
+ 2cb0b0: 38 7f 00 40 addi r3,r31,64
|
||||
+ 2cb0b4: 38 80 00 01 li r4,1
|
||||
+ 2cb0b8: 48 00 dd 01 bl 0x2d8db8
|
||||
+ 2cb0bc: 38 7f 00 4c addi r3,r31,76
|
||||
*/
|
||||
#ifdef NONMATCHING
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE138.s"
|
||||
JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool error_flag)
|
||||
: JKRDisposer(), child_list(true), heap_link(this), disposable_list(true) {
|
||||
: JKRDisposer(), mChildTree(this), mDisposerList() {
|
||||
OSInitMutex(this->mutex);
|
||||
this->size = size;
|
||||
this->begin = (u32)data;
|
||||
this->end = (u32)data + size;
|
||||
this->mSize = size;
|
||||
this->mBegin = (u32)data;
|
||||
this->mEnd = (u32)data + size;
|
||||
|
||||
if (parent == NULL) {
|
||||
this->becomeSystemHeap();
|
||||
this->becomeCurrentHeap();
|
||||
} else {
|
||||
JSUPtrLink* ptr = (JSUPtrLink*)&this->child_list;
|
||||
if (ptr != NULL) {
|
||||
ptr = &this->heap_link;
|
||||
}
|
||||
parent->mChildTree.appendChild(&this->mChildTree);
|
||||
|
||||
parent->child_list.append(ptr);
|
||||
if (lbl_80451370 == lbl_80451378) {
|
||||
this->becomeSystemHeap();
|
||||
}
|
||||
@@ -39,8 +23,8 @@ JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool error_flag)
|
||||
}
|
||||
}
|
||||
|
||||
this->error_flag = error_flag;
|
||||
if ((this->error_flag == true) && (lbl_8045137C == NULL)) {
|
||||
this->mErrorFlag = error_flag;
|
||||
if ((this->mErrorFlag == true) && (lbl_8045137C == NULL)) {
|
||||
lbl_8045137C = JKRHeap::JKRDefaultMemoryErrorRoutine;
|
||||
}
|
||||
|
||||
@@ -48,17 +32,43 @@ JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool error_flag)
|
||||
this->field_0x3d = lbl_80451380[0];
|
||||
this->field_0x69 = 0;
|
||||
}
|
||||
#else
|
||||
asm JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool error_flag) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE138.s"
|
||||
}
|
||||
#endif
|
||||
|
||||
// using the wrong register for storing the results
|
||||
// lbl_80451370 = systemHeap;
|
||||
#ifdef NONMATCHING
|
||||
JKRHeap::~JKRHeap() {
|
||||
JSUTree<JKRHeap>* parent = this->mChildTree.getParent();
|
||||
parent->removeChild(&this->mChildTree);
|
||||
|
||||
JSUTree<JKRHeap>* nextRootHeap = lbl_80451378->mChildTree.getFirstChild();
|
||||
|
||||
JKRHeap* rootHeap = lbl_80451378;
|
||||
JKRHeap* currentHeap = lbl_80451374;
|
||||
if (currentHeap == this) {
|
||||
if (!nextRootHeap) {
|
||||
currentHeap = rootHeap;
|
||||
} else {
|
||||
currentHeap = nextRootHeap->getObject();
|
||||
}
|
||||
}
|
||||
lbl_80451374 = currentHeap;
|
||||
|
||||
JKRHeap* systemHeap = lbl_80451370;
|
||||
if (systemHeap == this) {
|
||||
if (!nextRootHeap) {
|
||||
systemHeap = rootHeap;
|
||||
} else {
|
||||
systemHeap = nextRootHeap->getObject();
|
||||
}
|
||||
}
|
||||
lbl_80451370 = systemHeap;
|
||||
}
|
||||
#else
|
||||
asm JKRHeap::~JKRHeap() {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE264.s"
|
||||
}
|
||||
#endif
|
||||
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE378.s"
|
||||
bool JKRHeap::initArena(char** memory, u32* size, int param_3) {
|
||||
@@ -188,7 +198,7 @@ s32 JKRHeap::getFreeSize() {
|
||||
}
|
||||
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE758.s"
|
||||
s32 JKRHeap::getMaxFreeBlock() {
|
||||
void* JKRHeap::getMaxFreeBlock() {
|
||||
return this->do_getMaxFreeBlock();
|
||||
}
|
||||
|
||||
@@ -202,37 +212,105 @@ u8 JKRHeap::changeGroupID(u8 param_1) {
|
||||
return this->do_changeGroupID(param_1);
|
||||
}
|
||||
|
||||
asm s32 JKRHeap::getMaxAllocatableSize(int alignment) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE7DC.s"
|
||||
// "not/nor" instruction in the wrong place
|
||||
#ifdef NONMATCHING
|
||||
s32 JKRHeap::getMaxAllocatableSize(int alignment) {
|
||||
u32 maxFreeBlock = (u32)this->getMaxFreeBlock();
|
||||
s32 freeSize = this->getFreeSize();
|
||||
|
||||
u32 mask = alignment - 1U;
|
||||
s32 ptrOffset = mask & (alignment - (maxFreeBlock & 0xf));
|
||||
s32 alignedSize = (freeSize - ptrOffset) & ~(alignment - 1U);
|
||||
return alignedSize;
|
||||
}
|
||||
#else
|
||||
asm s32 JKRHeap::getMaxAllocatableSize(int alignment){
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE7DC.s"
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE83C.s"
|
||||
JKRHeap* JKRHeap::findFromRoot(void* ptr) {
|
||||
if (lbl_80451378 == NULL) {
|
||||
return (JKRHeap*)NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (((void*)lbl_80451378->begin <= ptr) && (ptr < (void*)lbl_80451378->end)) {
|
||||
if ((void*)lbl_80451378->mBegin <= ptr && ptr < (void*)lbl_80451378->mEnd) {
|
||||
return lbl_80451378->find(ptr);
|
||||
}
|
||||
|
||||
return lbl_80451378->findAllHeap(ptr);
|
||||
}
|
||||
|
||||
asm JKRHeap* JKRHeap::find(void* ptr) const {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE894.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE894.s"
|
||||
JKRHeap* JKRHeap::find(void* ptr) const {
|
||||
if ((void*)this->mBegin <= ptr && ptr < (void*)this->mEnd) {
|
||||
const JSUTree<JKRHeap>& tree = this->mChildTree;
|
||||
if (tree.getNumChildren() != 0) {
|
||||
JSUTreeIterator<JKRHeap> iterator;
|
||||
for (iterator = tree.getFirstChild(); iterator != tree.getEndChild(); iterator++) {
|
||||
JKRHeap* child = iterator.getObject();
|
||||
JKRHeap* result = child->find(ptr);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (JKRHeap*)this;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
asm JKRHeap* JKRHeap::findAllHeap(void* ptr) const {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE93C.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE93C.s"
|
||||
JKRHeap* JKRHeap::findAllHeap(void* ptr) const {
|
||||
const JSUTree<JKRHeap>& tree = this->mChildTree;
|
||||
if (tree.getNumChildren() != 0) {
|
||||
|
||||
JSUTreeIterator<JKRHeap> iterator;
|
||||
for (iterator = tree.getFirstChild(); iterator != tree.getEndChild(); iterator++) {
|
||||
JKRHeap* child = iterator.getObject();
|
||||
JKRHeap* result = child->findAllHeap(ptr);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((void*)this->mBegin <= ptr && ptr < (void*)this->mEnd) {
|
||||
// Cast away const
|
||||
return (JKRHeap*)this;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
asm void JKRHeap::dispose_subroutine(u32 begin, u32 end) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CE9E4.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CE9E4.s"
|
||||
void JKRHeap::dispose_subroutine(u32 begin, u32 end) {
|
||||
JSUListIterator<JKRDisposer> last_iterator;
|
||||
JSUListIterator<JKRDisposer> next_iterator;
|
||||
JSUListIterator<JKRDisposer> iterator;
|
||||
for (iterator = this->mDisposerList.getFirst(); iterator != this->mDisposerList.getEnd();
|
||||
iterator = next_iterator) {
|
||||
JKRDisposer* disposer = iterator.getObject();
|
||||
|
||||
if ((void*)begin <= disposer && disposer < (void*)end) {
|
||||
disposer->~JKRDisposer();
|
||||
if (last_iterator == NULL) {
|
||||
next_iterator = this->mDisposerList.getFirst();
|
||||
} else {
|
||||
next_iterator = last_iterator;
|
||||
next_iterator++;
|
||||
}
|
||||
} else {
|
||||
last_iterator = iterator;
|
||||
next_iterator = iterator;
|
||||
next_iterator++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEA78.s"
|
||||
@@ -248,13 +326,16 @@ void JKRHeap::dispose(void* begin, void* end) {
|
||||
this->dispose_subroutine((u32)begin, (u32)end);
|
||||
}
|
||||
|
||||
// missing stack variable?
|
||||
#ifdef NONMATCHING
|
||||
void JKRHeap::dispose() {
|
||||
JSUPtrLink* node;
|
||||
JKRDisposer* disposable;
|
||||
while (node = this->disposable_list.head, node != NULL) {
|
||||
disposable = (JKRDisposer*)node->owner;
|
||||
disposable->~JKRDisposer();
|
||||
JKRDisposer* disposer;
|
||||
JSUListIterator<JKRDisposer> iterator;
|
||||
|
||||
JSUList<JKRDisposer>* list = &this->mDisposerList;
|
||||
while (iterator = list->getFirst(), iterator != list->getEnd()) {
|
||||
disposer = iterator.getObject();
|
||||
disposer->~JKRDisposer();
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -278,24 +359,54 @@ void JKRHeap::copyMemory(void* dst, void* src, u32 size) {
|
||||
}
|
||||
}
|
||||
|
||||
asm void JKRHeap::JKRDefaultMemoryErrorRoutine(JKRHeap* heap, u32 size, int alignment) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CEB40.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEB40.s"
|
||||
void JKRHeap::JKRDefaultMemoryErrorRoutine(JKRHeap* heap, u32 size, int alignment) {
|
||||
const char* filename = lbl_8039CAD8; // "JKRHeap.cpp"
|
||||
const char* format = lbl_8039CAD8 + 12; // "%s"
|
||||
const char* arg1 = lbl_8039CAD8 + 15; // "abort\n"
|
||||
JUTException_NS_panic_f(filename, 0x33f, format, arg1);
|
||||
}
|
||||
|
||||
asm bool JKRHeap::setErrorFlag(bool param_1) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CEB78.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEB78.s"
|
||||
bool JKRHeap::setErrorFlag(bool error_flag) {
|
||||
bool prev = this->mErrorFlag;
|
||||
this->mErrorFlag = error_flag;
|
||||
return prev;
|
||||
}
|
||||
|
||||
asm JKRErrorHandler JKRHeap::setErrorHandler(JKRErrorHandler param_1) {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CEB88.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEB88.s"
|
||||
JKRErrorHandler JKRHeap::setErrorHandler(JKRErrorHandler error_handler) {
|
||||
JKRErrorHandler prev = (JKRErrorHandler)lbl_8045137C;
|
||||
|
||||
if (!error_handler) {
|
||||
error_handler = (JKRErrorHandler)JKRHeap::JKRDefaultMemoryErrorRoutine;
|
||||
}
|
||||
|
||||
lbl_8045137C = error_handler;
|
||||
return prev;
|
||||
}
|
||||
|
||||
asm bool JKRHeap::isSubHeap(JKRHeap* heap) const {
|
||||
nofralloc
|
||||
#include "JSystem/JKernel/JKRHeap/asm/func_802CEBA8.s"
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEBA8.s"
|
||||
bool JKRHeap::isSubHeap(JKRHeap* heap) const {
|
||||
if (!heap) return false;
|
||||
|
||||
const JSUTree<JKRHeap>& tree = this->mChildTree;
|
||||
if (tree.getNumChildren() != 0) {
|
||||
JSUTreeIterator<JKRHeap> iterator;
|
||||
for (iterator = tree.getFirstChild(); iterator != tree.getEndChild(); ++iterator) {
|
||||
JKRHeap* child = iterator.getObject();
|
||||
if (child == heap) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_sub_heap = child->isSubHeap(heap);
|
||||
if (is_sub_heap) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// #include "JSystem/JKernel/JKRHeap/asm/func_802CEC4C.s"
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
#include "global.h"
|
||||
|
||||
// #include "JSupport/asm/func_802DBDFC.s"
|
||||
JSUPtrLink::JSUPtrLink(void* owner) {
|
||||
this->list = NULL;
|
||||
this->owner = owner;
|
||||
this->prev = NULL;
|
||||
this->next = NULL;
|
||||
JSUPtrLink::JSUPtrLink(void* object) {
|
||||
this->mList = NULL;
|
||||
this->mObject = object;
|
||||
this->mPrev = NULL;
|
||||
this->mNext = NULL;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBE14.s"
|
||||
JSUPtrLink::~JSUPtrLink() {
|
||||
if (this->list != NULL) {
|
||||
this->list->remove(this);
|
||||
if (this->mList != NULL) {
|
||||
this->mList->remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,59 +21,59 @@ JSUPtrLink::~JSUPtrLink() {
|
||||
//
|
||||
|
||||
// #include "JSupport/asm/func_802DBE74.s"
|
||||
JSUPtrList::JSUPtrList(bool should_initiate) {
|
||||
if (should_initiate != false) {
|
||||
JSUPtrList::JSUPtrList(bool init) {
|
||||
if (init) {
|
||||
this->initiate();
|
||||
}
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBEAC.s"
|
||||
JSUPtrList::~JSUPtrList() {
|
||||
JSUPtrLink* node = this->head;
|
||||
JSUPtrLink* node = this->mHead;
|
||||
s32 removed = 0;
|
||||
while (this->length > removed) {
|
||||
node->list = NULL;
|
||||
node = node->next;
|
||||
while (this->mLength > removed) {
|
||||
node->mList = NULL;
|
||||
node = node->getNext();
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF14.s"
|
||||
void JSUPtrList::initiate() {
|
||||
this->head = NULL;
|
||||
this->tail = NULL;
|
||||
this->length = 0;
|
||||
this->mHead = NULL;
|
||||
this->mTail = NULL;
|
||||
this->mLength = 0;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF28.s"
|
||||
void JSUPtrList::setFirst(JSUPtrLink* first) {
|
||||
first->list = this;
|
||||
first->prev = NULL;
|
||||
first->next = NULL;
|
||||
this->tail = first;
|
||||
this->head = first;
|
||||
this->length = 1;
|
||||
first->mList = this;
|
||||
first->mPrev = NULL;
|
||||
first->mNext = NULL;
|
||||
this->mTail = first;
|
||||
this->mHead = first;
|
||||
this->mLength = 1;
|
||||
}
|
||||
|
||||
// #include "JSupport/asm/func_802DBF4C.s"
|
||||
bool JSUPtrList::append(JSUPtrLink* ptr) {
|
||||
JSUPtrList* list = ptr->list;
|
||||
bool result = (NULL == list);
|
||||
JSUPtrList* list = ptr->mList;
|
||||
bool result = (NULL == list);
|
||||
if (!result) {
|
||||
result = list->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (this->length == 0) {
|
||||
if (result) {
|
||||
if (this->mLength == 0) {
|
||||
this->setFirst(ptr);
|
||||
} else {
|
||||
ptr->list = this;
|
||||
ptr->prev = this->tail;
|
||||
ptr->next = NULL;
|
||||
this->tail->next = ptr;
|
||||
this->tail = ptr;
|
||||
this->length++;
|
||||
}
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = this->mTail;
|
||||
ptr->mNext = NULL;
|
||||
this->mTail->mNext = ptr;
|
||||
this->mTail = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -81,23 +81,23 @@ bool JSUPtrList::append(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DBFF0.s"
|
||||
bool JSUPtrList::prepend(JSUPtrLink* ptr) {
|
||||
JSUPtrList* list = ptr->list;
|
||||
bool result = (NULL == list);
|
||||
JSUPtrList* list = ptr->mList;
|
||||
bool result = (NULL == list);
|
||||
if (!result) {
|
||||
result = list->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (this->length == 0) {
|
||||
if (result) {
|
||||
if (this->mLength == 0) {
|
||||
this->setFirst(ptr);
|
||||
} else {
|
||||
ptr->list = this;
|
||||
ptr->prev = (JSUPtrLink*)NULL;
|
||||
ptr->next = this->head;
|
||||
this->head->prev = ptr;
|
||||
this->head = ptr;
|
||||
this->length++;
|
||||
}
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = NULL;
|
||||
ptr->mNext = this->mHead;
|
||||
this->mHead->mPrev = ptr;
|
||||
this->mHead = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -105,29 +105,29 @@ bool JSUPtrList::prepend(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC094.s"
|
||||
bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
|
||||
if (before == this->head) {
|
||||
return this->prepend(ptr);
|
||||
if (before == this->mHead) {
|
||||
return this->prepend(ptr);
|
||||
} else if (before == NULL) {
|
||||
return this->append(ptr);
|
||||
}
|
||||
|
||||
if (before->list != this) {
|
||||
|
||||
if (before->mList != this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = (NULL == ptr->list);
|
||||
|
||||
bool result = (NULL == ptr->mList);
|
||||
if (!result) {
|
||||
result = ptr->list->remove(ptr);
|
||||
result = ptr->mList->remove(ptr);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
JSUPtrLink* prev = before->prev;
|
||||
ptr->list = this;
|
||||
ptr->prev = prev;
|
||||
ptr->next = before;
|
||||
prev->next = ptr;
|
||||
before->prev = ptr;
|
||||
this->length++;
|
||||
JSUPtrLink* prev = before->mPrev;
|
||||
ptr->mList = this;
|
||||
ptr->mPrev = prev;
|
||||
ptr->mNext = before;
|
||||
prev->mNext = ptr;
|
||||
before->mPrev = ptr;
|
||||
this->mLength++;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -135,24 +135,24 @@ bool JSUPtrList::insert(JSUPtrLink* before, JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC15C.s"
|
||||
bool JSUPtrList::remove(JSUPtrLink* ptr) {
|
||||
bool is_parent = (ptr->list == this);
|
||||
bool is_parent = (ptr->mList == this);
|
||||
if (is_parent) {
|
||||
if (this->length == 1) {
|
||||
this->head = NULL;
|
||||
this->tail = NULL;
|
||||
} else if (ptr == this->head) {
|
||||
ptr->next->prev = NULL;
|
||||
this->head = ptr->next;
|
||||
} else if (ptr == this->tail) {
|
||||
ptr->prev->next = NULL;
|
||||
this->tail = ptr->prev;
|
||||
if (this->mLength == 1) {
|
||||
this->mHead = NULL;
|
||||
this->mTail = NULL;
|
||||
} else if (ptr == this->mHead) {
|
||||
ptr->mNext->mPrev = NULL;
|
||||
this->mHead = ptr->mNext;
|
||||
} else if (ptr == this->mTail) {
|
||||
ptr->mPrev->mNext = NULL;
|
||||
this->mTail = ptr->mPrev;
|
||||
} else {
|
||||
ptr->prev->next = ptr->next;
|
||||
ptr->next->prev = ptr->prev;
|
||||
ptr->mPrev->mNext = ptr->mNext;
|
||||
ptr->mNext->mPrev = ptr->mPrev;
|
||||
}
|
||||
|
||||
ptr->list = NULL;
|
||||
this->length--;
|
||||
ptr->mList = NULL;
|
||||
this->mLength--;
|
||||
}
|
||||
|
||||
return is_parent;
|
||||
@@ -160,15 +160,14 @@ bool JSUPtrList::remove(JSUPtrLink* ptr) {
|
||||
|
||||
// #include "JSupport/asm/func_802DC20C.s"
|
||||
JSUPtrLink* JSUPtrList::getNthLink(u32 index) const {
|
||||
if (index >= this->length) {
|
||||
if (index >= this->mLength) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSUPtrLink* node = this->head;
|
||||
for(u32 i = 0; i < index; i++) {
|
||||
node = node->next;
|
||||
JSUPtrLink* node = this->mHead;
|
||||
for (u32 i = 0; i < index; i++) {
|
||||
node = node->getNext();
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user