From ca5100faa1744dc291c95c1ae4fb5f5dbdc9d81b Mon Sep 17 00:00:00 2001 From: robojumper Date: Thu, 25 Apr 2024 15:17:31 +0200 Subject: [PATCH 1/3] 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 From d0a3b2b0a47f08c156a4b1c51a9949b3c9c8969d Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 26 Apr 2024 08:23:43 +0200 Subject: [PATCH 2/3] Match DrawStringLineToXfb_ (and add some symbols) --- config/SOUE01/symbols.txt | 16 ++++++++-------- src/nw4r/db/db_directPrint.cpp | 14 +++++--------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 01d5e532..d4d14801 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -22151,11 +22151,11 @@ VIWaitForRetrace = .text:0x803B4760; // type:function size:0x54 fn_803B47C0 = .text:0x803B47C0; // type:function size:0x2A8 fn_803B4A70 = .text:0x803B4A70; // type:function size:0xE0 fn_803B4B50 = .text:0x803B4B50; // type:function size:0x194 -fn_803B4CF0 = .text:0x803B4CF0; // type:function size:0x6CC +VIConfigure = .text:0x803B4CF0; // type:function size:0x6CC fn_803B53C0 = .text:0x803B53C0; // type:function size:0x354 -fn_803B5720 = .text:0x803B5720; // type:function size:0x114 -fn_803B5840 = .text:0x803B5840; // type:function size:0x6C -fn_803B58B0 = .text:0x803B58B0; // type:function size:0x8 +VIFlush = .text:0x803B5720; // type:function size:0x114 +VISetNextFrameBuffer = .text:0x803B5840; // type:function size:0x6C +VIGetCurrentFrameBuffer = .text:0x803B58B0; // type:function size:0x8 VISetBlack = .text:0x803B58C0; // type:function size:0x78 VIGetRetraceCount = .text:0x803B5940; // type:function size:0x8 fn_803B5950 = .text:0x803B5950; // type:function size:0x9C @@ -36497,11 +36497,11 @@ jumptable_8055FB08 = .data:0x8055FB08; // type:object size:0x44 scope:local lbl_8055FB4C = .data:0x8055FB4C; // type:object size:0x44 jumptable_8055FB90 = .data:0x8055FB90; // type:object size:0x44 scope:local jumptable_8055FBD4 = .data:0x8055FBD4; // type:object size:0x54 scope:local -lbl_8055FC28 = .data:0x8055FC28; // type:object size:0x3C +GXNtsc480IntDf = .data:0x8055FC28; // type:object size:0x3C lbl_8055FC64 = .data:0x8055FC64; // type:object size:0x3C -lbl_8055FCA0 = .data:0x8055FCA0; // type:object size:0x3C -lbl_8055FCDC = .data:0x8055FCDC; // type:object size:0x3C -lbl_8055FD18 = .data:0x8055FD18; // type:object size:0x40 +GXMpal480IntDf = .data:0x8055FCA0; // type:object size:0x3C +GXPal528IntDf = .data:0x8055FCDC; // type:object size:0x3C +GXEurgb60Hz480IntDf = .data:0x8055FD18; // type:object size:0x40 jumptable_8055FD58 = .data:0x8055FD58; // type:object size:0xF4 scope:local jumptable_8055FE4C = .data:0x8055FE4C; // type:object size:0xF4 scope:local jumptable_8055FF40 = .data:0x8055FF40; // type:object size:0x3C scope:local diff --git a/src/nw4r/db/db_directPrint.cpp b/src/nw4r/db/db_directPrint.cpp index 8a59f655..46c3667f 100644 --- a/src/nw4r/db/db_directPrint.cpp +++ b/src/nw4r/db/db_directPrint.cpp @@ -9,9 +9,6 @@ NOTE: This file does not match fully yet, Inlining + function ordering needs to still be addressed -Nonmatching functions: -DrawStringLineToXfb_ https://decomp.me/scratch/uqeZ6 - This worked for SS: as seen in egg stuff ive worked on, not sure if it works for others ¯\_(ツ)_/¯ - Especially with inlines. DWARF provides info of local vars and maps provide calls to functions, but outside of that I made some guesses. @@ -256,9 +253,7 @@ const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width) char c; int code, cnt, tab_size; - cnt = 0; - while (*str != '\0') { - c = *str; + for (cnt = 0; (c = *str) != '\0'; str++) { if (c == '\n' || c == '\0') { return str; } @@ -274,11 +269,12 @@ const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width) posh += 6; cnt++; } - if (cnt >= width && str[1] == '\n') { - str++; + if (cnt >= width) { + if (str[1] == '\n') { + str++; + } return str; } - str++; } return str; } From 6fe64af2c90d4b33641307e6c36b6c947809c7ab Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 26 Apr 2024 09:25:40 +0200 Subject: [PATCH 3/3] c/c_list.cpp --- config/SOUE01/splits.txt | 3 ++ config/SOUE01/symbols.txt | 2 +- configure.py | 1 + src/c/c_list.cpp | 73 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/c/c_list.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index dc15c545..0bad49bd 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -119,6 +119,9 @@ toBeSorted/unk_flag_stuff.cpp: toBeSorted/bitwise_flag_helper.cpp: .text start:0x800BF200 end:0x800BF264 +c/c_list.cpp: + .text start:0x802E08C0 end:0x802E0A10 + f/f_base.cpp: .text start:0x802E12F0 end:0x802E2680 .ctors start:0x804DB8C0 end:0x804DB8C4 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 01d5e532..c53498f4 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17278,7 +17278,7 @@ fn_802E0710 = .text:0x802E0710; // type:function size:0xD8 fn_802E07F0 = .text:0x802E07F0; // type:function size:0x24 fn_802E0820 = .text:0x802E0820; // type:function size:0x34 fn_802E0860 = .text:0x802E0860; // type:function size:0x60 -fn_802E08C0 = .text:0x802E08C0; // type:function size:0x40 +insertAfter__9cListMg_cFP9cListNd_cP9cListNd_c = .text:0x802E08C0; // type:function size:0x40 remove__9cListMg_cFP9cListNd_c = .text:0x802E0900; // type:function size:0xAC append__9cListMg_cFP9cListNd_c = .text:0x802E09B0; // type:function size:0x30 prepend__9cListMg_cFP9cListNd_c = .text:0x802E09E0; // type:function size:0x30 diff --git a/configure.py b/configure.py index 95335230..eca11983 100644 --- a/configure.py +++ b/configure.py @@ -274,6 +274,7 @@ config.libs = [ Object(Matching, "toBeSorted/sceneflag_manager.cpp"), Object(NonMatching, "toBeSorted/flag_space.cpp"), Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), + Object(Matching, "c/c_list.cpp"), Object(Matching, "d/d_base.cpp"), Object(NonMatching, "d/d_heap.cpp"), Object(NonMatching, "d/d_stage.cpp"), diff --git a/src/c/c_list.cpp b/src/c/c_list.cpp new file mode 100644 index 00000000..37d1c624 --- /dev/null +++ b/src/c/c_list.cpp @@ -0,0 +1,73 @@ +#include + + +bool cListMg_c::insertAfter(cListNd_c *node, cListNd_c *prevNode) { + if (prevNode == nullptr) { + return this->prepend(node); + } + if (node == nullptr) { + return; + } + node->mpNext = prevNode->mpNext; + node->mpPrev = prevNode; + prevNode->mpNext = node; + if (node->mpNext != nullptr) { + node->mpNext->mpPrev = node; + } else { + this->mpLast = node; + } +} + +bool cListMg_c::remove(cListNd_c *node) { + if (node == nullptr) { + return; + } + + if (node->mpPrev == nullptr && node->mpNext == nullptr) { + if (this->mpFirst == node && this->mpLast == node) { + this->mpFirst = nullptr; + this->mpLast = nullptr; + } + } else { + if (node->mpPrev != nullptr) { + node->mpPrev->mpNext = node->mpNext; + } else if (node == this->mpFirst) { + this->mpFirst = node->mpNext; + } + + if (node->mpNext != nullptr) { + node->mpNext->mpPrev = node->mpPrev; + } else if (node == this->mpLast) { + this->mpLast = node->mpPrev; + } + + node->mpPrev = nullptr; + node->mpNext = nullptr; + } +} + +bool cListMg_c::append(cListNd_c *node) { + if (node == nullptr) { + return; + } + if (this->mpLast != nullptr) { + this->mpLast->mpNext = node; + node->mpPrev = this->mpLast; + } else { + this->mpFirst = node; + } + this->mpLast = node; +} + +bool cListMg_c::prepend(cListNd_c *node) { + if (node == nullptr) { + return; + } + if (this->mpFirst != nullptr) { + this->mpFirst->mpPrev = node; + node->mpNext = this->mpFirst; + } else { + this->mpLast = node; + } + this->mpFirst = node; +}