From ca5100faa1744dc291c95c1ae4fb5f5dbdc9d81b Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 25 Apr 2024 15:17:31 +0200 Subject: [PATCH] ut_list --- config/SOUE01/splits.txt | 3 + config/SOUE01/symbols.txt | 16 +++--- configure.py | 6 ++ src/nw4r/ut/ut_list.cpp | 118 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 src/nw4r/ut/ut_list.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index dc15c545..45d5e7ba 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -153,6 +153,9 @@ m/m_mtx.cpp: rvl/CX/cx.c: .text start:0x803CEE90 end:0x803D0B20 +nw4r/ut/ut_list.cpp: + .text start:0x8042A530 end:0x8042A850 + nw4r/db/db_directPrint.cpp: .text start:0x804342A0 end:0x80434EA0 .rodata start:0x804F5D28 end:0x804F5FE0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 01d5e532..af0f10cc 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23926,14 +23926,14 @@ fn_8042A148 = .text:0x8042A148; // type:function size:0x124 fn_8042A26C = .text:0x8042A26C; // type:function size:0x104 fn_8042A370 = .text:0x8042A370; // type:function size:0xE0 fn_8042A450 = .text:0x8042A450; // type:function size:0xE0 -fn_8042A530 = .text:0x8042A530; // type:function size:0x18 -fn_8042A550 = .text:0x8042A550; // type:function size:0x70 -fn_8042A5C0 = .text:0x8042A5C0; // type:function size:0x6C -fn_8042A630 = .text:0x8042A630; // type:function size:0x120 -fn_8042A750 = .text:0x8042A750; // type:function size:0x6C -fn_8042A7C0 = .text:0x8042A7C0; // type:function size:0x20 -fn_8042A7E0 = .text:0x8042A7E0; // type:function size:0x1C -fn_8042A800 = .text:0x8042A800; // type:function size:0x50 +List_Init__Q24nw4r2utFPQ34nw4r2ut4ListUs = .text:0x8042A530; // type:function size:0x18 +List_Append__Q24nw4r2utFPQ34nw4r2ut4ListPv = .text:0x8042A550; // type:function size:0x70 +List_Prepend__Q24nw4r2utFPQ34nw4r2ut4ListPv = .text:0x8042A5C0; // type:function size:0x6C +List_Insert__Q24nw4r2utFPQ34nw4r2ut4ListPvPv = .text:0x8042A630; // type:function size:0x120 +List_Remove__Q24nw4r2utFPQ34nw4r2ut4ListPv = .text:0x8042A750; // type:function size:0x6C +List_GetNext__Q24nw4r2utFPCQ34nw4r2ut4ListPCv = .text:0x8042A7C0; // type:function size:0x20 +List_GetPrev__Q24nw4r2utFPCQ34nw4r2ut4ListPCv = .text:0x8042A7E0; // type:function size:0x1C +List_GetNth__Q24nw4r2utFPCQ34nw4r2ut4ListUs = .text:0x8042A800; // type:function size:0x50 fn_8042A850 = .text:0x8042A850; // type:function size:0x84 fn_8042A8E0 = .text:0x8042A8E0; // type:function size:0x48 fn_8042A930 = .text:0x8042A930; // type:function size:0x44 diff --git a/configure.py b/configure.py index 95335230..a287cead 100644 --- a/configure.py +++ b/configure.py @@ -310,6 +310,12 @@ config.libs = [ Object(NonMatching, "nw4r/db/db_directPrint.cpp"), ], ), + nw4rLib( + "ut", + [ + Object(Matching, "nw4r/ut/ut_list.cpp"), + ], + ), # EGG EGGLib( "core", diff --git a/src/nw4r/ut/ut_list.cpp b/src/nw4r/ut/ut_list.cpp new file mode 100644 index 00000000..4fab51c8 --- /dev/null +++ b/src/nw4r/ut/ut_list.cpp @@ -0,0 +1,118 @@ +#include + +namespace nw4r { +namespace ut { + +#define NODE_PTR(list, object) ((Node*)(((char*)object) + list->offset)) + +void* List_GetNth(const List* list, u16 n) { + void *object; + int c; + + for (c = 0, object = nullptr; object = List_GetNext(list, object); c++) { + if (n == c) { + return object; + } + } + + return nullptr; +} + +void* List_GetPrev(const List* list, const void* object) { + if (object == nullptr) { + return list->last; + } else { + return NODE_PTR(list, object)->prev; + } +} + +void* List_GetNext(const List* list, const void* object) { + if (object == nullptr) { + return list->first; + } else { + return NODE_PTR(list, object)->next; + } +} + +void List_Remove(List* list, void* object) { + Node *node = NODE_PTR(list, object); + if (node->prev == nullptr) { + list->first = node->next; + } else { + NODE_PTR(list, node->prev)->next = node->next; + } + + if (node->next == nullptr) { + list->last = node->prev; + } else { + NODE_PTR(list, node->next)->prev = node->prev; + } + + node->prev = nullptr; + node->next = nullptr; + list->size--; +} + +void List_Insert(List* list, void* next, void* object) { + if (next == nullptr) { + List_Append(list, object); + } else if (next == list->first) { + List_Prepend(list, object); + } else { + Node *newNode = NODE_PTR(list, object); + void *prevObj = NODE_PTR(list, next)->prev; + Node *prevNode = NODE_PTR(list, prevObj); + newNode->prev = prevObj; + newNode->next = next; + prevNode->next = object; + NODE_PTR(list, next)->prev = object; + list->size++; + } +} + + +void List_Prepend(List* list, void* object) { + if (list->first == nullptr) { + Node *node = NODE_PTR(list, object); + node->next = nullptr; + node->prev = nullptr; + list->first = object; + list->last = object; + list->size++; + } else { + Node *node = NODE_PTR(list, object); + node->prev = nullptr; + node->next = list->first; + NODE_PTR(list, list->first)->prev = object; + list->first = object; + list->size++; + } +} + +void List_Append(List* list, void* object) { + if (list->first == nullptr) { + Node *node = NODE_PTR(list, object); + node->next = nullptr; + node->prev = nullptr; + list->first = object; + list->last = object; + list->size++; + } else { + Node *node = NODE_PTR(list, object); + node->prev = list->last; + node->next = nullptr; + NODE_PTR(list, list->last)->next = object; + list->last = object; + list->size++; + } +} + +void List_Init(List* list, u16 offset) { + list->first = nullptr; + list->last = nullptr; + list->size = 0; + list->offset = offset; +} + +} // namespace ut +} // namespace nw4r