From f61be959cc405a1843b6dbf5b8380aa2c98f3059 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 12:37:38 +0200 Subject: [PATCH 1/2] Match db_directPrint --- config/SOUE01/splits.txt | 6 +- config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- src/nw4r/db/db_directPrint.cpp | 139 +++++++++++++++++---------------- 4 files changed, 77 insertions(+), 72 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1f79f5f6..fb0d5609 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -171,10 +171,10 @@ 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 + .text start:0x804342A0 end:0x80434E9C + .rodata start:0x804F5D28 end:0x804F5FDC .data start:0x8056C000 end:0x8056C010 - .sbss start:0x805765E8 end:0x805765F0 + .sbss start:0x805765E8 end:0x805765EC .bss start:0x80636B80 end:0x80636BA4 egg/core/eggArchive.cpp: diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index dfd2e61c..fb87d17e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -29084,7 +29084,7 @@ lbl_804F5CD8 = .rodata:0x804F5CD8; // type:object size:0x10 lbl_804F5CE8 = .rodata:0x804F5CE8; // type:object size:0x40 data:4byte sAsciiTable__Q24nw4r2db = .rodata:0x804F5D28; // type:object size:0x80 scope:local sFontData__Q24nw4r2db = .rodata:0x804F5DA8; // type:object size:0x100 scope:local -sFontData2__Q24nw4r2db = .rodata:0x804F5EA8; // type:object size:0x138 scope:local +sFontData2__Q24nw4r2db = .rodata:0x804F5EA8; // type:object size:0x134 scope:local lbl_804F5FE0 = .rodata:0x804F5FE0; // type:object size:0x1010 lbl_804F6FF0 = .rodata:0x804F6FF0; // type:object size:0x20 lbl_804F7010 = .rodata:0x804F7010; // type:object size:0x40 diff --git a/configure.py b/configure.py index 87235f4a..f25db4a4 100644 --- a/configure.py +++ b/configure.py @@ -310,7 +310,7 @@ config.libs = [ nw4rLib( "db", [ - Object(NonMatching, "nw4r/db/db_directPrint.cpp"), + Object(Matching, "nw4r/db/db_directPrint.cpp", extra_cflags=["-inline smart, -ipa file"]), ], ), nw4rLib( diff --git a/src/nw4r/db/db_directPrint.cpp b/src/nw4r/db/db_directPrint.cpp index 46c3667f..643456b8 100644 --- a/src/nw4r/db/db_directPrint.cpp +++ b/src/nw4r/db/db_directPrint.cpp @@ -40,7 +40,7 @@ static const u32 sFontData[64] = { 0xF2EF8808, 0x82288888, 0x82288888, 0x81C89C70, 0x8A08A270, 0x920DA288, 0xA20AB288, 0xC20AAA88, 0xA208A688, 0x9208A288, 0x8BE8A270, 0xF1CF1CF8, 0x8A28A220, 0x8A28A020, 0xF22F1C20, 0x82AA0220, 0x82492220, 0x81A89C20, 0x8A28A288, 0x8A28A288, 0x8A289488, 0x8A2A8850, 0x894A9420, 0x894AA220, - 0x70852220, 0xF8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400, 0x00000000, 0xF8011000, + 0x70852220, 0xF8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400, 0x80020800, 0xF8011000, 0x70800000, 0x88822200, 0x08820400, 0x108F8800, 0x20821000, 0x00022200, 0x20800020, 0x00000000, }; @@ -52,7 +52,7 @@ static const u32 sFontData2[77] = { 0x100FBE1C, 0x10089008, 0x60070808, 0x00000000, 0x02000200, 0x7A078270, 0x8BC81E88, 0x8A2822F8, 0x9A282280, 0x6BC79E78, 0x30000000, 0x48080810, 0x41E80000, 0x422F1830, 0xFBE88810, 0x40288890, 0x43C89C60, 0x81000000, 0x81000000, 0x990F3C70, 0xA10AA288, 0xE10AA288, 0xA10AA288, 0x98CAA270, - 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x00000000, 0x00000000, + 0x00000000, 0x00000020, 0xF1EF1E20, 0x8A28A0F8, 0x8A281C20, 0xF1E80220, 0x80283C38, 0x00000000, 0x00000000, 0x8A28B688, 0x8A2A8888, 0x8A2A8878, 0x894A8808, 0x788536F0, 0x00000000, 0x00000000, 0xF8000000, 0x10000000, 0x20000000, 0x40000000, 0xF8000000, }; @@ -177,7 +177,7 @@ void DirectPrint_DrawString(int posh, int posv, bool turnOver, const char *forma va_end(list); } -int StrLineWidth_(const char *str) { +static int StrLineWidth_(const char *str) { int len = 0; do { int c = *str++; @@ -195,7 +195,75 @@ int StrLineWidth_(const char *str) { return len; } -void DrawCharToXfb_(int posh, int posv, int code) { +static void DrawCharToXfb_(int posh, int posv, int code); +static void DrawStringToXfb_(int posh, int posv, const char *str, bool turnOver, bool backErase); +static const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width); + +static void DrawStringToXfb_(int posh, int posv, const char *str, bool turnOver, bool backErase) { + int basePosH = posh; + int frameWidth = sFrameBufferInfo.frameWidth; + int width = frameWidth / GetDotWidth_(); + + while (*str != '\0') { + if (backErase) { + int len = StrLineWidth_(str); + DirectPrint_EraseXfb(posh - 6, posv - 3, (len + 2) * 6, 13); + } + str = DrawStringLineToXfb_(posh, posv, str, (width - posh) / 6); + posv += 10; + + if (*str == '\n') { + str++; + posh = basePosH; + } else if (*str != '\0') { + str++; + if (!turnOver) { + str = strchr(str, '\n'); + if (str == NULL) { + break; + } + str++; + posh = basePosH; + } else { + posh = 0; + } + } + } +} + + +static const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width) { + // Vars from DWARF info + char c; + int code, cnt, tab_size; + + for (cnt = 0; (c = *str) != '\0'; str++) { + if (c == '\n' || c == '\0') { + return str; + } + code = sAsciiTable[c & 0x7f]; + if (code == 0xfd) { + tab_size = 4 - (cnt & 3); + cnt += tab_size; + posh += tab_size * 6; + } else { + if (code != 0xFF) { + DrawCharToXfb_(posh, posv, code); + } + posh += 6; + cnt++; + } + if (cnt >= width) { + if (str[1] == '\n') { + str++; + } + return str; + } + } + return str; +} + +static void DrawCharToXfb_(int posh, int posv, int code) { int ncode = (100 <= code) ? code - 100 : code; int fontv = (ncode % 5) * 6; int fonth = (ncode / 5) * 7; @@ -248,69 +316,6 @@ void DrawCharToXfb_(int posh, int posv, int code) { } } -const char *DrawStringLineToXfb_(int posh, int posv, const char *str, int width) { - // Vars from DWARF info - char c; - int code, cnt, tab_size; - - for (cnt = 0; (c = *str) != '\0'; str++) { - if (c == '\n' || c == '\0') { - return str; - } - code = sAsciiTable[c & 0x7f]; - if (code == 0xfd) { - tab_size = 4 - (cnt & 3); - cnt += tab_size; - posh += tab_size * 6; - } else { - if (code != 0xFF) { - DrawCharToXfb_(posh, posv, code); - } - posh += 6; - cnt++; - } - if (cnt >= width) { - if (str[1] == '\n') { - str++; - } - return str; - } - } - return str; -} - -void DrawStringToXfb_(int posh, int posv, const char *str, bool turnOver, bool backErase) { - int basePosH = posh; - int frameWidth = sFrameBufferInfo.frameWidth; - int width = frameWidth / GetDotWidth_(); - - while (*str != '\0') { - if (backErase) { - int len = StrLineWidth_(str); - DirectPrint_EraseXfb(posh - 6, posv - 3, (len + 2) * 6, 13); - } - str = DrawStringLineToXfb_(posh, posv, str, (width - posh) / 6); - posv += 10; - - if (*str == '\n') { - str++; - posh = basePosH; - } else if (*str != '\0') { - str++; - if (!turnOver) { - str = strchr(str, '\n'); - if (str == NULL) { - break; - } - str++; - posh = basePosH; - } else { - posh = 0; - } - } - } -} - void detail::DirectPrint_DrawStringToXfb(int posh, int posv, const char *format, __va_list_struct *args, bool turnOver, bool backErase) { // Vars from dwarf info From 3fe496f111f5c89ecb91ceac70f042e53e598fe3 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 14:30:58 +0200 Subject: [PATCH 2/2] I guess nw4r used -ipa file --- configure.py | 4 +- src/nw4r/ut/ut_list.cpp | 141 ++++++++++++++++++++-------------------- 2 files changed, 72 insertions(+), 73 deletions(-) diff --git a/configure.py b/configure.py index f25db4a4..121f802d 100644 --- a/configure.py +++ b/configure.py @@ -199,7 +199,7 @@ cflags_egg = [ # nw4r flags cflags_nw4r = [ *cflags_base, - "-inline deferred", + "-ipa file", ] # REL flags @@ -310,7 +310,7 @@ config.libs = [ nw4rLib( "db", [ - Object(Matching, "nw4r/db/db_directPrint.cpp", extra_cflags=["-inline smart, -ipa file"]), + Object(Matching, "nw4r/db/db_directPrint.cpp"), ], ), nw4rLib( diff --git a/src/nw4r/ut/ut_list.cpp b/src/nw4r/ut/ut_list.cpp index 4fab51c8..5addeda8 100644 --- a/src/nw4r/ut/ut_list.cpp +++ b/src/nw4r/ut/ut_list.cpp @@ -3,38 +3,69 @@ namespace nw4r { namespace ut { -#define NODE_PTR(list, object) ((Node*)(((char*)object) + list->offset)) +#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_Init(List *list, u16 offset) { + list->first = nullptr; + list->last = nullptr; + list->size = 0; + list->offset = offset; } -void* List_GetPrev(const List* list, const void* object) { - if (object == nullptr) { - return list->last; +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 { - return NODE_PTR(list, object)->prev; + 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_GetNext(const List* list, const void* object) { - if (object == nullptr) { - return list->first; +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 { - return NODE_PTR(list, object)->next; + 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_Remove(List* list, void* object) { +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_Remove(List *list, void *object) { Node *node = NODE_PTR(list, object); if (node->prev == nullptr) { list->first = node->next; @@ -53,65 +84,33 @@ void List_Remove(List* list, void* object) { 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); +void *List_GetNext(const List *list, const void *object) { + if (object == nullptr) { + return list->first; } 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++; + return NODE_PTR(list, object)->next; } } - -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++; +void *List_GetPrev(const List *list, const void *object) { + if (object == nullptr) { + return list->last; } 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++; + return NODE_PTR(list, object)->prev; } } -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_GetNth(const List *list, u16 n) { + void *object; + int c; -void List_Init(List* list, u16 offset) { - list->first = nullptr; - list->last = nullptr; - list->size = 0; - list->offset = offset; + for (c = 0, object = nullptr; object = List_GetNext(list, object); c++) { + if (n == c) { + return object; + } + } + + return nullptr; } } // namespace ut