From fa4b2862fd54925affe5ce9fa64dc6c37a71fb28 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 00:39:30 +0200 Subject: [PATCH 01/13] dHeap(Allocator) work --- config/SOUE01/splits.txt | 4 +- config/SOUE01/symbols.txt | 44 ++++++++++---------- include/d/d_heap_alloc.h | 82 ++++++++++++++++++++++++++++++++++++++ include/egg/core/eggHeap.h | 26 ++++++------ src/d/d_heap.cpp | 66 +++++++++++++++++++++++++----- 5 files changed, 178 insertions(+), 44 deletions(-) create mode 100644 include/d/d_heap_alloc.h diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f84fec00..5e1ad335 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -72,7 +72,9 @@ d/d_heap.cpp: .text start:0x80054B00 end:0x80054F30 .ctors start:0x804DB680 end:0x804DB684 .rodata start:0x804DE008 end:0x804DE188 - .sbss start:0x805751A8 end:0x805751D0 + .data start:0x8050D440 end:0x8050D458 + .sbss start:0x805751A8 end:0x805751CC + .bss start:0x80597740 end:0x80597758 d/d_main.cpp: .text start:0x80054F30 end:0x80055170 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 195dcdc3..b345728e 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2212,8 +2212,8 @@ fn_80054550 = .text:0x80054550; // type:function size:0x31C fn_80054870 = .text:0x80054870; // type:function size:0x25C fn_80054AD0 = .text:0x80054AD0; // type:function size:0x10 fn_80054AE0 = .text:0x80054AE0; // type:function size:0x14 -fn_80054B00 = .text:0x80054B00; // type:function size:0x40 -fn_80054B40 = .text:0x80054B40; // type:function size:0x20 +__dt__14dHeapAllocatorFv = .text:0x80054B00; // type:function size:0x40 +onAlloc__14dHeapAllocatorFPQ23EGG12HeapAllocArg = .text:0x80054B40; // type:function size:0x20 init__5dHeapFPCcUlPQ23EGG4Heap = .text:0x80054B60; // type:function size:0x64 createWork1Heap__5dHeapFUlPQ23EGG4Heap = .text:0x80054BD0; // type:function size:0x18 createWork2Heap__5dHeapFUlPQ23EGG4Heap = .text:0x80054BF0; // type:function size:0x18 @@ -2224,15 +2224,15 @@ createLayoutEx2Heap__5dHeapFUlPQ23EGG4Heap = .text:0x80054C70; // type:function createLayoutResHeap__5dHeapFUlPQ23EGG4Heap = .text:0x80054C90; // type:function size:0x18 createFontHeap__5dHeapFUlPQ23EGG4Heap = .text:0x80054CB0; // type:function size:0x18 createHBMHeap__5dHeapFUlPQ23EGG4Heap = .text:0x80054CD0; // type:function size:0x18 -fn_80054CF0 = .text:0x80054CF0; // type:function size:0x88 -fn_80054D80 = .text:0x80054D80; // type:function size:0x98 -fn_80054E20 = .text:0x80054E20; // type:function size:0x88 -fn_80054EB0 = .text:0x80054EB0; // type:function size:0x4 -fn_80054EC0 = .text:0x80054EC0; // type:function size:0xC -fn_80054ED0 = .text:0x80054ED0; // type:function size:0xC +initCallbacks__14dHeapAllocatorFv = .text:0x80054CF0; // type:function size:0x88 +allocCallback__18dHeapAllocatorBaseFPQ23EGG12HeapAllocArg = .text:0x80054D80; // type:function size:0x98 +freeCallback__18dHeapAllocatorBaseFPQ23EGG11HeapFreeArg = .text:0x80054E20; // type:function size:0x88 +onFree__18dHeapAllocatorBaseFPQ23EGG11HeapFreeArg = .text:0x80054EB0; // type:function size:0x4 +__nw__FUl = .text:0x80054EC0; // type:function size:0xC +__nwa__FUl = .text:0x80054ED0; // type:function size:0xC __dl__FPv = .text:0x80054EE0; // type:function size:0x8 -fn_80054EF0 = .text:0x80054EF0; // type:function size:0x8 -fn_80054F00 = .text:0x80054F00; // type:function size:0x30 +__dla__FPv = .text:0x80054EF0; // type:function size:0x8 +__sinit_\d_heap_cpp = .text:0x80054F00; // type:function size:0x30 fn_80054F30 = .text:0x80054F30; // type:function size:0x4 fn_80054F40 = .text:0x80054F40; // type:function size:0x4 fn_80054F50 = .text:0x80054F50; // type:function size:0x38 @@ -26205,11 +26205,11 @@ dumpAll__Q23EGG4HeapFv = .text:0x804958B0; // type:function size:0xEC becomeCurrentHeap__Q23EGG4HeapFv = .text:0x804959A0; // type:function size:0x58 _becomeCurrentHeapWithoutLock__Q23EGG4HeapFv = .text:0x80495A00; // type:function size:0x3C initAllocator__Q23EGG4HeapFPQ23EGG9Allocatorl = .text:0x80495A40; // type:function size:0x14 -__nw__FUlPv = .text:0x80495A60; // type:function size:0x8 -__nw__FUlPQ23EGG4Heapi = .text:0x80495A70; // type:function size:0x10 -__nwa__FUl = .text:0x80495A80; // type:function size:0x10 -__nwa__FUli = .text:0x80495A90; // type:function size:0x8 -__nwa__FUlPQ23EGG4Heapi = .text:0x80495AA0; // type:function size:0x10 +0x80495A60 = .text:0x80495A60; // type:function size:0x8 +0x80495A70 = .text:0x80495A70; // type:function size:0x10 +0x80495A80 = .text:0x80495A80; // type:function size:0x10 +0x80495A90 = .text:0x80495A90; // type:function size:0x8 +0x80495AA0 = .text:0x80495AA0; // type:function size:0x10 __ct__Q23EGG7ExpHeapFP12MEMiHeapHead = .text:0x80495AB0; // type:function size:0x3C __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 create__Q23EGG7ExpHeapFPvUlUs = .text:0x80495B70; // type:function size:0xB8 @@ -30707,7 +30707,7 @@ lbl_8050D37C = .data:0x8050D37C; // type:object size:0x24 lbl_8050D3A0 = .data:0x8050D3A0; // type:object size:0x10 data:string lbl_8050D3B0 = .data:0x8050D3B0; // type:object size:0x14 lbl_8050D3C4 = .data:0x8050D3C4; // type:object size:0x7C -lbl_8050D440 = .data:0x8050D440; // type:object size:0x18 +__vt__14dHeapAllocator = .data:0x8050D440; // type:object size:0x18 lbl_8050D458 = .data:0x8050D458; // type:object size:0xC data:string lbl_8050D464 = .data:0x8050D464; // type:object size:0x10 lbl_8050D474 = .data:0x8050D474; // type:object size:0x10 @@ -39735,7 +39735,7 @@ layoutExHeap__5dHeap = .sbss:0x805751B8; // type:object size:0x4 data:4byte layoutEx2Heap__5dHeap = .sbss:0x805751BC; // type:object size:0x4 data:4byte layoutResHeap__5dHeap = .sbss:0x805751C0; // type:object size:0x4 data:4byte fontHeap__5dHeap = .sbss:0x805751C4; // type:object size:0x4 data:4byte -HBMHeap__5dHeap = .sbss:0x805751C8; // type:object size:0x8 data:4byte +HBMHeap__5dHeap = .sbss:0x805751C8; // type:object size:0x4 data:4byte lbl_805751D0 = .sbss:0x805751D0; // type:object size:0x8 data:4byte lbl_805751D8 = .sbss:0x805751D8; // type:object size:0x4 data:4byte lbl_805751DC = .sbss:0x805751DC; // type:object size:0x4 data:4byte @@ -40883,11 +40883,11 @@ sCurrentHeap__Q23EGG4Heap = .sbss:0x80576740; // type:object size:0x4 data:4byte lbl_80576744 = .sbss:0x80576744; // type:object size:0x4 data:4byte lbl_80576748 = .sbss:0x80576748; // type:object size:0x4 data:4byte lbl_8057674C = .sbss:0x8057674C; // type:object size:0x4 data:4byte -lbl_80576750 = .sbss:0x80576750; // type:object size:0x4 data:4byte -lbl_80576754 = .sbss:0x80576754; // type:object size:0x4 data:4byte +sAllocCallback__Q23EGG4Heap = .sbss:0x80576750; // type:object size:0x4 data:4byte +sFreeCallback__Q23EGG4Heap = .sbss:0x80576754; // type:object size:0x4 data:4byte lbl_80576758 = .sbss:0x80576758; // type:object size:0x4 data:4byte -lbl_8057675C = .sbss:0x8057675C; // type:object size:0x4 data:4byte -lbl_80576760 = .sbss:0x80576760; // type:object size:0x4 data:4byte +sAllocCallbackArg__Q23EGG4Heap = .sbss:0x8057675C; // type:object size:0x4 data:4byte +sFreeCallbackArg__Q23EGG4Heap = .sbss:0x80576760; // type:object size:0x4 data:4byte lbl_80576764 = .sbss:0x80576764; // type:object size:0x4 data:4byte lbl_80576768 = .sbss:0x80576768; // type:object size:0x8 data:4byte lbl_80576770 = .sbss:0x80576770; // type:object size:0x8 data:4byte @@ -48129,7 +48129,7 @@ lbl_805975C0 = .bss:0x805975C0; // type:object size:0x48 lbl_80597608 = .bss:0x80597608; // type:object size:0x10 lbl_80597618 = .bss:0x80597618; // type:object size:0xA8 lbl_805976C0 = .bss:0x805976C0; // type:object size:0x80 data:byte -lbl_80597740 = .bss:0x80597740; // type:object size:0x18 data:4byte +sAllocator__14dHeapAllocator = .bss:0x80597740; // type:object size:0x18 data:4byte lbl_80597758 = .bss:0x80597758; // type:object size:0x318 lbl_80597A70 = .bss:0x80597A70; // type:object size:0x10 lbl_80597A80 = .bss:0x80597A80; // type:object size:0x8B70 data:float diff --git a/include/d/d_heap_alloc.h b/include/d/d_heap_alloc.h new file mode 100644 index 00000000..726a997d --- /dev/null +++ b/include/d/d_heap_alloc.h @@ -0,0 +1,82 @@ +#ifndef D_HEAP_ALLOC +#define D_HEAP_ALLOC + +#include + +class dHeapAllocatorBase { +public: + /* vtable at 0x00 */ + dHeapAllocatorBase() + : mCallbacksInitialized(0), mPreviousAllocCallback(nullptr), mPreviousAllocCallbackArg(nullptr), + mPreviousFreeCallback(nullptr), mPreviousFreeCallbackArg(nullptr) {} + inline void doInitCallbacks() { + if (!mCallbacksInitialized) { + mCallbacksInitialized = 1; + + void *oldAllocCallbackArg = EGG::Heap::sAllocCallbackArg; + void *oldFreeCallbackArg = EGG::Heap::sFreeCallbackArg; + EGG::HeapAllocCallback oldAllocCallback = EGG::Heap::sAllocCallback; + EGG::HeapFreeCallback oldFreeCallback = EGG::Heap::sFreeCallback; + + EGG::HeapFreeCallback freeThunk = &freeCallback; + EGG::HeapAllocCallback allocThunk = &allocCallback; + + EGG::Heap::sAllocCallback = allocThunk; + EGG::Heap::sAllocCallbackArg = this; + mPreviousAllocCallback = oldAllocCallback; + mPreviousAllocCallbackArg = oldAllocCallbackArg; + + EGG::Heap::sFreeCallback = freeThunk; + EGG::Heap::sFreeCallbackArg = this; + mPreviousFreeCallback = oldFreeCallback; + mPreviousFreeCallbackArg = oldFreeCallbackArg; + } + } + static void allocCallback(EGG::HeapAllocArg *arg) { + dHeapAllocatorBase *allocator = (dHeapAllocatorBase *)(arg->userArg); + allocator->onAlloc(arg); + if (allocator->mPreviousAllocCallback) { + EGG::HeapAllocArg chainArg = *arg; + chainArg.userArg = allocator->mPreviousAllocCallbackArg; + (allocator->mPreviousAllocCallback)(&chainArg); + } + }; + static void freeCallback(EGG::HeapFreeArg *arg) { + dHeapAllocatorBase *allocator = (dHeapAllocatorBase *)(arg->userArg); + EGG::HeapFreeArg chainArg; + allocator->onFree(arg); + if (allocator->mPreviousFreeCallback) { + chainArg = *arg; + chainArg.userArg = allocator->mPreviousFreeCallbackArg; + (allocator->mPreviousFreeCallback)(&chainArg); + } + } + + virtual ~dHeapAllocatorBase() {} + virtual void onAlloc(EGG::HeapAllocArg *arg) {}; + virtual void onFree(EGG::HeapFreeArg *arg) {}; + + /* 0x04 */ bool mCallbacksInitialized; + /* 0x08 */ EGG::HeapAllocCallback mPreviousAllocCallback; + /* 0x0C */ void *mPreviousAllocCallbackArg; + /* 0x10 */ EGG::HeapFreeCallback mPreviousFreeCallback; + /* 0x14 */ void *mPreviousFreeCallbackArg; +}; + +void *operator new(size_t size); +void *operator new[](size_t size); +void operator delete(void *ptr); +void operator delete[](void *ptr); + +class dHeapAllocator : public dHeapAllocatorBase { +public: + dHeapAllocator() {} + virtual ~dHeapAllocator() {} + virtual void onAlloc(EGG::HeapAllocArg *arg); + + static void initCallbacks(); + + static dHeapAllocator sAllocator; +}; + +#endif diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 10b114e9..0bd0b508 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -17,14 +17,15 @@ namespace EGG { class Allocator; struct HeapAllocArg { - int userArg; // 00 + void *userArg; // 00 u32 size; // 04 int align; // 08 Heap *heap; // 0C heap to allocate in + int another; // 10 inline HeapAllocArg() : userArg(0), size(0), align(0), heap(nullptr) {} }; -typedef void (*HeapAllocCallback)(HeapAllocArg &arg); +typedef void (*HeapAllocCallback)(HeapAllocArg *arg); struct HeapErrorArg { const char *msg; @@ -32,13 +33,14 @@ struct HeapErrorArg { inline HeapErrorArg() {} }; -typedef void (*ErrorCallback)(void *); +typedef void (*ErrorCallback)(HeapErrorArg *); struct HeapFreeArg { - u32 arg1; // Idk the args - u32 arg2; + void *userArg; + int arg1; + int arg2; }; -typedef void (*HeapFreeCallback)(void *); +typedef void (*HeapFreeCallback)(HeapFreeArg *); typedef void (*HeapCreateCallback)(void *); typedef void (*HeapDestroyCallback)(void *); @@ -151,14 +153,14 @@ public: /* 80576760 */ static void *sFreeCallbackArg; /* 80576764 */ static HeapCreateCallback sCreateCallback; /* 80576764 */ static HeapDestroyCallback sDestroyCallback; + + /* 80495a60 */ void *operator new(size_t, void *p); + /* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align); + /* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); + /* 80495a90 */ void *operator new[](size_t size, u32 align); + /* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align); }; } // namespace EGG -/* 80495a60 */ void *operator new(size_t, void *p); -/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align); -/* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); -/* 80495a90 */ void *operator new[](size_t size, u32 align); -/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align); - #endif diff --git a/src/d/d_heap.cpp b/src/d/d_heap.cpp index 4bfa5e52..2e9c3198 100644 --- a/src/d/d_heap.cpp +++ b/src/d/d_heap.cpp @@ -1,4 +1,5 @@ #include +#include dHeap dHeap::work1Heap; dHeap dHeap::work2Heap; @@ -9,6 +10,22 @@ dHeap dHeap::layoutEx2Heap; dHeap dHeap::layoutResHeap; dHeap dHeap::fontHeap; dHeap dHeap::HBMHeap; +dHeapAllocator dHeapAllocator::sAllocator; + +extern u8 lbl_80571C58; +extern "C" void fn_802de710(); + +// TODO TU splits? + +void dHeapAllocator::onAlloc(EGG::HeapAllocArg *arg) { + if (arg->heap != nullptr) { + return; + } + if (lbl_80571C58 == 0) { + return; + } + fn_802de710(); +} EGG::ExpHeap *dHeap::init(const char *name, size_t size, EGG::Heap *parent) { heap = EGG::ExpHeap::create(size, parent, 4); @@ -18,30 +35,61 @@ EGG::ExpHeap *dHeap::init(const char *name, size_t size, EGG::Heap *parent) { } return heap; } + void dHeap::createWork1Heap(size_t size, EGG::Heap *parent) { - work1Heap.init("ゲーム用作業用ヒープ(dHeap::work1Heap)", size, parent); + static const char name[] = "ゲーム用作業用ヒープ(dHeap::work1Heap)"; + work1Heap.init(name, size, parent); } void dHeap::createWork2Heap(size_t size, EGG::Heap *parent) { - work2Heap.init("ゲーム用作業用ヒープ(dHeap::work2Heap)", size, parent); + static const char name[] = "ゲーム用作業用ヒープ(dHeap::work2Heap)"; + work2Heap.init(name, size, parent); } void dHeap::createWorkExHeap(size_t size, EGG::Heap *parent) { - workExHeap.init("ゲーム用拡張作業用ヒープ(dHeap::workExHeap)", size, parent); + static const char name[] = "ゲーム用拡張作業用ヒープ(dHeap::workExHeap)"; + workExHeap.init(name, size, parent); } void dHeap::createLayoutHeap(size_t size, EGG::Heap *parent) { - layoutHeap.init("レイアウト作業用ヒープ(dHeap::layoutHeap)", size, parent); + static const char name[] = "レイアウト作業用ヒープ(dHeap::layoutHeap)"; + layoutHeap.init(name, size, parent); } void dHeap::createLayoutExHeap(size_t size, EGG::Heap *parent) { - layoutExHeap.init("レイアウト拡張作業用ヒープ(dHeap::layoutExHeap)", size, parent); + static const char name[] = "レイアウト拡張作業用ヒープ(dHeap::layoutExHeap)"; + layoutExHeap.init(name, size, parent); } void dHeap::createLayoutEx2Heap(size_t size, EGG::Heap *parent) { - layoutEx2Heap.init("レイアウト拡張作業用ヒープ2(dHeap::layoutEx2Heap)", size, parent); + static const char name[] = "レイアウト拡張作業用ヒープ2(dHeap::layoutEx2Heap)"; + layoutEx2Heap.init(name, size, parent); } void dHeap::createLayoutResHeap(size_t size, EGG::Heap *parent) { - layoutResHeap.init("レイアウトリソース用ヒープ(dHeap::layoutResHeap)", size, parent); + static const char name[] = "レイアウトリソース用ヒープ(dHeap::layoutResHeap)"; + layoutResHeap.init(name, size, parent); } void dHeap::createFontHeap(size_t size, EGG::Heap *parent) { - fontHeap.init("フォント用ヒープ(dHeap::fontHeap)", size, parent); + static const char name[] = "フォント用ヒープ(dHeap::fontHeap)"; + fontHeap.init(name, size, parent); } void dHeap::createHBMHeap(size_t size, EGG::Heap *parent) { - HBMHeap.init("HBM用ヒープ(dHeap::HBMHeap)", size, parent); + static const char name[] = "HBM用ヒープ(dHeap::HBMHeap)"; + HBMHeap.init(name, size, parent); +} + +// TODO this doesn't match (many more stack stores) +void dHeapAllocator::initCallbacks() { + sAllocator.doInitCallbacks(); +} + +void *operator new(size_t size) { + return EGG::Heap::alloc(size, 0x04, nullptr); +} + +void *operator new[](size_t size) { + return EGG::Heap::alloc(size, 0x04, nullptr); +} + +void operator delete(void *ptr) { + return EGG::Heap::free(ptr, nullptr); +} + +void operator delete[](void *ptr) { + return EGG::Heap::free(ptr, nullptr); } From 927a2ad4f715ae410246648cf5a0b05c4521cebc Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 11:57:22 +0200 Subject: [PATCH 02/13] comment --- include/d/d_heap_alloc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/d/d_heap_alloc.h b/include/d/d_heap_alloc.h index 726a997d..dec77133 100644 --- a/include/d/d_heap_alloc.h +++ b/include/d/d_heap_alloc.h @@ -18,6 +18,8 @@ public: EGG::HeapAllocCallback oldAllocCallback = EGG::Heap::sAllocCallback; EGG::HeapFreeCallback oldFreeCallback = EGG::Heap::sFreeCallback; + // first mention free, then alloc so that the + //inline thunks are emitted in the right order EGG::HeapFreeCallback freeThunk = &freeCallback; EGG::HeapAllocCallback allocThunk = &allocCallback; From c98342a9d5c0bdb5fb8c9d23bcb15810daf0f219 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 4 May 2024 20:10:59 +0200 Subject: [PATCH 03/13] Update for -ipa file --- include/d/d_heap_alloc.h | 9 ++------- src/d/d_heap.cpp | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/d/d_heap_alloc.h b/include/d/d_heap_alloc.h index dec77133..4fd3a47a 100644 --- a/include/d/d_heap_alloc.h +++ b/include/d/d_heap_alloc.h @@ -18,17 +18,12 @@ public: EGG::HeapAllocCallback oldAllocCallback = EGG::Heap::sAllocCallback; EGG::HeapFreeCallback oldFreeCallback = EGG::Heap::sFreeCallback; - // first mention free, then alloc so that the - //inline thunks are emitted in the right order - EGG::HeapFreeCallback freeThunk = &freeCallback; - EGG::HeapAllocCallback allocThunk = &allocCallback; - - EGG::Heap::sAllocCallback = allocThunk; + EGG::Heap::sAllocCallback = &allocCallback; EGG::Heap::sAllocCallbackArg = this; mPreviousAllocCallback = oldAllocCallback; mPreviousAllocCallbackArg = oldAllocCallbackArg; - EGG::Heap::sFreeCallback = freeThunk; + EGG::Heap::sFreeCallback = &freeCallback; EGG::Heap::sFreeCallbackArg = this; mPreviousFreeCallback = oldFreeCallback; mPreviousFreeCallbackArg = oldFreeCallbackArg; diff --git a/src/d/d_heap.cpp b/src/d/d_heap.cpp index 2e9c3198..a29ba328 100644 --- a/src/d/d_heap.cpp +++ b/src/d/d_heap.cpp @@ -13,7 +13,7 @@ dHeap dHeap::HBMHeap; dHeapAllocator dHeapAllocator::sAllocator; extern u8 lbl_80571C58; -extern "C" void fn_802de710(); +extern "C" void fn_802DE710(); // TODO TU splits? @@ -24,7 +24,7 @@ void dHeapAllocator::onAlloc(EGG::HeapAllocArg *arg) { if (lbl_80571C58 == 0) { return; } - fn_802de710(); + fn_802DE710(); } EGG::ExpHeap *dHeap::init(const char *name, size_t size, EGG::Heap *parent) { From 88df5e430bf5f29dd52202c9ee84079e92c3a04e Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sat, 4 May 2024 23:11:25 -0400 Subject: [PATCH 04/13] Update ut_CharStrmReader.cpp --- src/nw4r/ut/ut_CharStrmReader.cpp | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index e69de29b..647875de 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -0,0 +1,61 @@ +#include + +namespace nw4r { +namespace ut { +namespace { + +bool IsSJISLeadByte(u8 c) { + // Idk how to force the comparison correctly + return ((c >= 0x81) && (c < 0xA0)) || c >= 0xe0; +} + +} // namespace + +u16 CharStrmReader::ReadNextCharUTF8() { + u16 code; + + if (!(GetChar(0) & 0x80)) { + code = GetChar(0); + StepStrm(1); + } else if ((GetChar(0) & 0xe0) == 0xC0) { + code = ((GetChar(0) & 0x1F) << 6) | GetChar(1) & 0x3F; + StepStrm(2); + } else { + code = ((GetChar(0) & 0x1F) << 12) | ((GetChar(1) & 0x3F) << 6) | (GetChar(2) & 0x3F); + StepStrm(3); + } + return code; +} + +u16 CharStrmReader::ReadNextCharUTF16() { + u16 code = GetChar(0); + StepStrm(1); + return code; +} +u16 CharStrmReader::ReadNextCharCP1252() { + u16 code = GetChar(0); + StepStrm(1); + return code; +} +u16 CharStrmReader::ReadNextCharSJIS() { + u16 code = GetChar(0); + + bool isLead = false; + + if ((((u8)GetChar(0) >= 0x81) && ((u8)GetChar(0) <= 0xA0)) || (u8)GetChar(0) >= 0xe0) { + isLead = true; + } + + if (isLead) { + code = GetChar(1) | (GetChar(0) << 8); + StepStrm(2); + } else { + code = GetChar(0); + StepStrm(1); + } + return code; +} + +} // namespace ut + +} // namespace nw4r From 282402ff85bb22480933ffa810bed022172adb8d Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 09:25:21 +0200 Subject: [PATCH 05/13] Match ut_CharStreamReader --- configure.py | 2 +- src/nw4r/ut/ut_CharStrmReader.cpp | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/configure.py b/configure.py index 5336a084..547c57d3 100644 --- a/configure.py +++ b/configure.py @@ -320,7 +320,7 @@ config.libs = [ Object(Matching, "nw4r/ut/ut_list.cpp"), Object(Matching, "nw4r/ut/ut_LinkList.cpp"), Object(Matching, "nw4r/ut/ut_binaryFileFormat.cpp"), - Object(NonMatching, "nw4r/ut/ut_CharStrmReader.cpp"), + Object(Matching, "nw4r/ut/ut_CharStrmReader.cpp"), Object(NonMatching, "nw4r/ut/ut_TagProcessorBase.cpp"), Object(NonMatching, "nw4r/ut/ut_IOStream.cpp"), Object(NonMatching, "nw4r/ut/ut_FileStream.cpp"), diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index 647875de..b8f96984 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -40,13 +40,7 @@ u16 CharStrmReader::ReadNextCharCP1252() { u16 CharStrmReader::ReadNextCharSJIS() { u16 code = GetChar(0); - bool isLead = false; - - if ((((u8)GetChar(0) >= 0x81) && ((u8)GetChar(0) <= 0xA0)) || (u8)GetChar(0) >= 0xe0) { - isLead = true; - } - - if (isLead) { + if (IsSJISLeadByte((u8)code)) { code = GetChar(1) | (GetChar(0) << 8); StepStrm(2); } else { From bb65dd55186cf631b473f53b141fa418bb08cd3c Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 09:30:54 +0200 Subject: [PATCH 06/13] Drop comment --- src/nw4r/ut/ut_CharStrmReader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nw4r/ut/ut_CharStrmReader.cpp b/src/nw4r/ut/ut_CharStrmReader.cpp index b8f96984..81bb80fa 100644 --- a/src/nw4r/ut/ut_CharStrmReader.cpp +++ b/src/nw4r/ut/ut_CharStrmReader.cpp @@ -5,7 +5,6 @@ namespace ut { namespace { bool IsSJISLeadByte(u8 c) { - // Idk how to force the comparison correctly return ((c >= 0x81) && (c < 0xA0)) || c >= 0xe0; } From 4909f805ba6f533777cabb4a29ad25ff668c0bb2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 10:20:28 +0200 Subject: [PATCH 07/13] eggHeap almost matching --- config/SOUE01/splits.txt | 3 +- config/SOUE01/symbols.txt | 50 ++++---- include/egg/core/eggHeap.h | 7 +- include/egg/prim/eggBitFlag.h | 5 +- src/egg/core/eggColorFader.cpp | 2 +- src/egg/core/eggDisplay.cpp | 6 +- src/egg/core/eggHeap.cpp | 207 +++++++++++++++++++++++++++++++++ 7 files changed, 246 insertions(+), 34 deletions(-) create mode 100644 src/egg/core/eggHeap.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 7fefadea..30a5435f 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -261,7 +261,8 @@ egg/core/eggAllocator.cpp: egg/core/eggHeap.cpp: .text start:0x804953F0 end:0x80495AB0 .data start:0x8056E8E8 end:0x8056E980 - .sbss start:0x80576740 end:0x80576770 + .sdata start:0x80574ED8 end:0x80574EE8 + .sbss start:0x80576740 end:0x8057676C .bss start:0x80673AE8 end:0x80673B10 egg/core/eggExpHeap.cpp: diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 669414f7..b04afa94 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2212,7 +2212,7 @@ fn_80054550 = .text:0x80054550; // type:function size:0x31C fn_80054870 = .text:0x80054870; // type:function size:0x25C fn_80054AD0 = .text:0x80054AD0; // type:function size:0x10 fn_80054AE0 = .text:0x80054AE0; // type:function size:0x14 -fn_80054B00 = .text:0x80054B00; // type:function size:0x40 +__dt__5dHeapFv = .text:0x80054B00; // type:function size:0x40 fn_80054B40 = .text:0x80054B40; // type:function size:0x20 init__5dHeapFPCcUlPQ23EGG4Heap = .text:0x80054B60; // type:function size:0x64 createWork1Heap__5dHeapFUlPQ23EGG4Heap = .text:0x80054BD0; // type:function size:0x18 @@ -21996,9 +21996,9 @@ fn_803AA830 = .text:0x803AA830; // type:function size:0x18 BATConfig = .text:0x803AA850; // type:function size:0x120 scope:local fn_803AA970 = .text:0x803AA970; // type:function size:0x44 __OSInitMemoryProtection = .text:0x803AA9C0; // type:function size:0xCC scope:global -fn_803AAA90 = .text:0x803AAA90; // type:function size:0x38 -fn_803AAAD0 = .text:0x803AAAD0; // type:function size:0xDC -fn_803AABB0 = .text:0x803AABB0; // type:function size:0xC8 +OSInitMutex = .text:0x803AAA90; // type:function size:0x38 +OSLockMutex = .text:0x803AAAD0; // type:function size:0xDC +OSUnlockMutex = .text:0x803AABB0; // type:function size:0xC8 fn_803AAC80 = .text:0x803AAC80; // type:function size:0x6C fn_803AACF0 = .text:0x803AACF0; // type:function size:0xBC fn_803AADB0 = .text:0x803AADB0; // type:function size:0x6C @@ -22033,7 +22033,7 @@ fn_803AC380 = .text:0x803AC380; // type:function size:0x4 fn_803AC390 = .text:0x803AC390; // type:function size:0x70 __OSThreadInit = .text:0x803AC400; // type:function size:0x284 scope:global OSInitThreadQueue = .text:0x803AC690; // type:function size:0x10 scope:global -fn_803AC6A0 = .text:0x803AC6A0; // type:function size:0xC +OSGetCurrentThread = .text:0x803AC6A0; // type:function size:0xC fn_803AC6B0 = .text:0x803AC6B0; // type:function size:0x2C OSDisableScheduler = .text:0x803AC6E0; // type:function size:0x3C scope:global OSEnableScheduler = .text:0x803AC720; // type:function size:0x3C scope:global @@ -22562,7 +22562,7 @@ fn_803CC1F0 = .text:0x803CC1F0; // type:function size:0x14C fn_803CC340 = .text:0x803CC340; // type:function size:0x1C0 fn_803CC500 = .text:0x803CC500; // type:function size:0x16C fn_803CC670 = .text:0x803CC670; // type:function size:0x140 -fn_803CC7B0 = .text:0x803CC7B0; // type:function size:0x18C +MEMFindContainHeap = .text:0x803CC7B0; // type:function size:0x18C fn_803CC940 = .text:0x803CC940; // type:function size:0x22C fn_803CCB70 = .text:0x803CCB70; // type:function size:0xDC fn_803CCC50 = .text:0x803CCC50; // type:function size:0xC8 @@ -22588,7 +22588,7 @@ fn_803CDA40 = .text:0x803CDA40; // type:function size:0x84 fn_803CDAD0 = .text:0x803CDAD0; // type:function size:0xD0 fn_803CDBA0 = .text:0x803CDBA0; // type:function size:0x10 fn_803CDBB0 = .text:0x803CDBB0; // type:function size:0x8 -fn_803CDBC0 = .text:0x803CDBC0; // type:function size:0x10 +MEMAllocFromAllocator = .text:0x803CDBC0; // type:function size:0x10 fn_803CDBD0 = .text:0x803CDBD0; // type:function size:0x10 fn_803CDBE0 = .text:0x803CDBE0; // type:function size:0x1C fn_803CDC00 = .text:0x803CDC00; // type:function size:0x18 @@ -26204,11 +26204,11 @@ dump__Q23EGG4HeapFv = .text:0x804958A0; // type:function size:0x4 dumpAll__Q23EGG4HeapFv = .text:0x804958B0; // type:function size:0xEC becomeCurrentHeap__Q23EGG4HeapFv = .text:0x804959A0; // type:function size:0x58 _becomeCurrentHeapWithoutLock__Q23EGG4HeapFv = .text:0x80495A00; // type:function size:0x3C -initAllocator__Q23EGG4HeapFPQ23EGG9Allocatorl = .text:0x80495A40; // type:function size:0x14 +initAllocator__Q23EGG4HeapFPQ23EGG9Allocatori = .text:0x80495A40; // type:function size:0x14 __nw__FUlPv = .text:0x80495A60; // type:function size:0x8 -__nw__FUlPQ23EGG4Heapi = .text:0x80495A70; // type:function size:0x10 -__nwa__FUl = .text:0x80495A80; // type:function size:0x10 -__nwa__FUli = .text:0x80495A90; // type:function size:0x8 +__nw__FUlPQ23EGG4HeapUi = .text:0x80495A70; // type:function size:0x10 +__nw__FUlPQ23EGG9Allocator = .text:0x80495A80; // type:function size:0x10 +__nwa__FUlUi = .text:0x80495A90; // type:function size:0x8 __nwa__FUlPQ23EGG4Heapi = .text:0x80495AA0; // type:function size:0x10 __ct__Q23EGG7ExpHeapFP12MEMiHeapHead = .text:0x80495AB0; // type:function size:0x3C __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 @@ -37096,7 +37096,7 @@ lbl_8056E8A0 = .data:0x8056E8A0; // type:object size:0x18 lbl_8056E8B8 = .data:0x8056E8B8; // type:object size:0x18 lbl_8056E8D0 = .data:0x8056E8D0; // type:object size:0x18 lbl_8056E8E8 = .data:0x8056E8E8; // type:object size:0x68 -lbl_8056E950 = .data:0x8056E950; // type:object size:0x30 +__vt__Q23EGG4Heap = .data:0x8056E950; // type:object size:0x30 lbl_8056E980 = .data:0x8056E980; // type:object size:0x10 lbl_8056E990 = .data:0x8056E990; // type:object size:0x10 lbl_8056E9A0 = .data:0x8056E9A0; // type:object size:0x30 @@ -39735,7 +39735,7 @@ layoutExHeap__5dHeap = .sbss:0x805751B8; // type:object size:0x4 data:4byte layoutEx2Heap__5dHeap = .sbss:0x805751BC; // type:object size:0x4 data:4byte layoutResHeap__5dHeap = .sbss:0x805751C0; // type:object size:0x4 data:4byte fontHeap__5dHeap = .sbss:0x805751C4; // type:object size:0x4 data:4byte -HBMHeap__5dHeap = .sbss:0x805751C8; // type:object size:0x8 data:4byte +HBMHeap__5dHeap = .sbss:0x805751C8; // type:object size:0x4 data:4byte lbl_805751D0 = .sbss:0x805751D0; // type:object size:0x8 data:4byte lbl_805751D8 = .sbss:0x805751D8; // type:object size:0x4 data:4byte lbl_805751DC = .sbss:0x805751DC; // type:object size:0x4 data:4byte @@ -40880,16 +40880,16 @@ lbl_80576728 = .sbss:0x80576728; // type:object size:0x8 data:byte lbl_80576730 = .sbss:0x80576730; // type:object size:0x8 data:byte lbl_80576738 = .sbss:0x80576738; // type:object size:0x8 data:4byte sCurrentHeap__Q23EGG4Heap = .sbss:0x80576740; // type:object size:0x4 data:4byte -lbl_80576744 = .sbss:0x80576744; // type:object size:0x4 data:4byte -lbl_80576748 = .sbss:0x80576748; // type:object size:0x4 data:4byte -lbl_8057674C = .sbss:0x8057674C; // type:object size:0x4 data:4byte -lbl_80576750 = .sbss:0x80576750; // type:object size:0x4 data:4byte -lbl_80576754 = .sbss:0x80576754; // type:object size:0x4 data:4byte -lbl_80576758 = .sbss:0x80576758; // type:object size:0x4 data:4byte -lbl_8057675C = .sbss:0x8057675C; // type:object size:0x4 data:4byte -lbl_80576760 = .sbss:0x80576760; // type:object size:0x4 data:4byte -lbl_80576764 = .sbss:0x80576764; // type:object size:0x4 data:4byte -lbl_80576768 = .sbss:0x80576768; // type:object size:0x8 data:4byte +sIsHeapListInitialized__Q23EGG4Heap = .sbss:0x80576744; // type:object size:0x4 data:4byte +sAllocatableHeap__Q23EGG4Heap = .sbss:0x80576748; // type:object size:0x4 data:4byte +sErrorCallback__Q23EGG4Heap = .sbss:0x8057674C; // type:object size:0x4 data:4byte +sAllocCallback__Q23EGG4Heap = .sbss:0x80576750; // type:object size:0x4 data:4byte +sFreeCallback__Q23EGG4Heap = .sbss:0x80576754; // type:object size:0x4 data:4byte +sErrorCallbackArg__Q23EGG4Heap = .sbss:0x80576758; // type:object size:0x4 data:4byte +sAllocCallbackArg__Q23EGG4Heap = .sbss:0x8057675C; // type:object size:0x4 data:4byte +sFreeCallbackArg__Q23EGG4Heap = .sbss:0x80576760; // type:object size:0x4 data:4byte +sCreateCallback__Q23EGG4Heap = .sbss:0x80576764; // type:object size:0x4 data:4byte +sDestroyCallback__Q23EGG4Heap = .sbss:0x80576768; // type:object size:0x4 data:4byte lbl_80576770 = .sbss:0x80576770; // type:object size:0x8 data:4byte lbl_80576778 = .sbss:0x80576778; // type:object size:0x8 data:4byte mConfigData__Q23EGG10BaseSystem = .sbss:0x80576780; // type:object size:0x4 data:4byte @@ -49345,8 +49345,8 @@ lbl_80673A8C = .bss:0x80673A8C; // type:object size:0x1C data:byte lbl_80673AA8 = .bss:0x80673AA8; // type:object size:0x20 data:float lbl_80673AC8 = .bss:0x80673AC8; // type:object size:0x10 lbl_80673AD8 = .bss:0x80673AD8; // type:object size:0x10 -lbl_80673AE8 = .bss:0x80673AE8; // type:object size:0x10 -lbl_80673AF8 = .bss:0x80673AF8; // type:object size:0x18 +sHeapList__Q23EGG4Heap = .bss:0x80673AE8; // type:object size:0xC +sRootMutex__Q23EGG4Heap = .bss:0x80673AF8; // type:object size:0x18 lbl_80673B10 = .bss:0x80673B10; // type:object size:0x10 clear_z_tobj__29@unnamed@eggAsyncDisplay_cpp@ = .bss:0x80673B20; // type:object size:0x20 scope:local lbl_80673B40 = .bss:0x80673B40; // type:object size:0x10C0 data:4byte diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 10b114e9..4d61a44a 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -101,7 +101,7 @@ public: /* 804957c0 */ static void free(void *memBlock, Heap *heap); /* 80495830 */ void dispose(); /* 804958a0 */ void dump(); - /* 804958b0 */ void dumpAll(); + /* 804958b0 */ static void dumpAll(); /* 804959a0 */ Heap *becomeCurrentHeap(); /* 80495a00 */ Heap *_becomeCurrentHeapWithoutLock(); @@ -138,6 +138,11 @@ public: inline int getArenaEnd() { return (int)mHeapHandle->end; } + + inline const char *getName() { + return mName; + } + /* 80673ae8 */ static nw4r::ut::List sHeapList; /* 80673af8 */ static OSMutex sRootMutex; /* 80576740 */ static Heap *sCurrentHeap; diff --git a/include/egg/prim/eggBitFlag.h b/include/egg/prim/eggBitFlag.h index 13e6c5f9..f9a9a4ae 100644 --- a/include/egg/prim/eggBitFlag.h +++ b/include/egg/prim/eggBitFlag.h @@ -14,9 +14,8 @@ public: inline void makeAllZero() { value = T(); } - inline TBitFlag() { - makeAllZero(); - } + inline TBitFlag() {} + inline TBitFlag(T value): value(value) {} inline T makeMask(u8 bit) const { return 1 << bit; } diff --git a/src/egg/core/eggColorFader.cpp b/src/egg/core/eggColorFader.cpp index f4207cf5..a0f9863b 100644 --- a/src/egg/core/eggColorFader.cpp +++ b/src/egg/core/eggColorFader.cpp @@ -6,7 +6,7 @@ /* 80497930 */ EGG::ColorFader::ColorFader(float startX, float startY, float lengthX, float lengthY, nw4r::ut::Color color, Fader::EStatus initialStatus) - : mStartX(startX), mStartY(startY), mEndX(startX + lengthX), mEndY(startY + lengthY), mFrame(0x14), mFadeTimer(0) { + : mStartX(startX), mStartY(startY), mEndX(startX + lengthX), mEndY(startY + lengthY), mFrame(0x14), mFadeTimer(0), mFlags(0) { setColor(color); setStatus(initialStatus); mFlags.setBit(1); diff --git a/src/egg/core/eggDisplay.cpp b/src/egg/core/eggDisplay.cpp index 16031605..6fb5b0f5 100644 --- a/src/egg/core/eggDisplay.cpp +++ b/src/egg/core/eggDisplay.cpp @@ -16,13 +16,13 @@ u32 Display::sTickPeriod = ((OS_BUS_CLOCK_SPEED >> 2)/125000)*300 >> 3; /* 80497570 */ Display::Display(u8 maxRetrace) : mMaxRetraces(maxRetrace), - mScreenStateFlag(), + mScreenStateFlag(0), mRetraceCount(0), mFrameCount(0), mClearColor(0x808080ff), mClearZ(0xFFFFFF), mBeginTick(0), - mFlag() + mFlag(0) { mFlag.setBit(mFlag_SetClear); mFlag.setBit(mFlag_WaitForRetrace); @@ -99,4 +99,4 @@ void Display::calcFrequency() { mBeginTick = endTick; } -} // namespace EGG \ No newline at end of file +} // namespace EGG diff --git a/src/egg/core/eggHeap.cpp b/src/egg/core/eggHeap.cpp new file mode 100644 index 00000000..620b9e95 --- /dev/null +++ b/src/egg/core/eggHeap.cpp @@ -0,0 +1,207 @@ +#include +#include +#include + +namespace EGG { + +/* 80673ae8 */ nw4r::ut::List Heap::sHeapList; +/* 80673af8 */ OSMutex Heap::sRootMutex; +/* 80576740 */ Heap *Heap::sCurrentHeap; +/* 80576744 */ int Heap::sIsHeapListInitialized; +/* 80576748 */ Heap *Heap::sAllocatableHeap; +/* 8057674c */ ErrorCallback Heap::sErrorCallback; +/* 80576750 */ HeapAllocCallback Heap::sAllocCallback; +/* 80576754 */ HeapFreeCallback Heap::sFreeCallback; +/* 80576758 */ void *Heap::sErrorCallbackArg; +/* 8057675c */ void *Heap::sAllocCallbackArg; +/* 80576760 */ void *Heap::sFreeCallbackArg; +/* 80576764 */ HeapCreateCallback Heap::sCreateCallback; +/* 80576764 */ HeapDestroyCallback Heap::sDestroyCallback; + +/* 804953f0 */ void Heap::initialize() { + nw4r::ut::List_Init(&sHeapList, 0x1c /* todo offsetof() */); + OSInitMutex(&sRootMutex); + sIsHeapListInitialized = true; +} + +/* 80495430 */ Heap::Heap(MEMiHeapHead *head) : mHeapHandle(head), mParentBlock(nullptr), mName("NoName"), mFlag() { + mFlag.value = 0; + nw4r::ut::List_Init(&mChildren, 0x8 /* todo offsetof() */); + OSLockMutex(&sRootMutex); + nw4r::ut::List_Append(&sHeapList, this); + OSUnlockMutex(&sRootMutex); +} + +/* 804954c0 */ Heap::~Heap() { + OSLockMutex(&sRootMutex); + nw4r::ut::List_Remove(&sHeapList, this); + OSUnlockMutex(&sRootMutex); +} + +/* 80495560 */ void *Heap::alloc(size_t size, s32 align, Heap *heap) { + Heap *currentHeap = sCurrentHeap; + Thread *thread = Thread::findThread(OSGetCurrentThread()); + Heap *threadHeap = nullptr; + + if (thread != nullptr && (threadHeap = thread->mAllocatableHeap, threadHeap != nullptr)) { + heap = threadHeap; + } + if (sAllocatableHeap != nullptr) { + if (heap == nullptr) { + heap = currentHeap; + } + if (heap != sAllocatableHeap) { + // TODO small instshuffle here, related to regshuffle problems + OSReport("cannot allocate from heap %x(%s) : allocatable heap is %x(%s)\n", heap, heap->getName(), + sAllocatableHeap, sAllocatableHeap->getName()); + OSReport("\tthread heap=%x(%s)\n", threadHeap, + threadHeap != nullptr ? threadHeap->getName() : "none"); + if (sErrorCallback != nullptr) { + HeapErrorArg arg; + arg.msg = "disable_but"; + arg.userdata = sErrorCallbackArg; + sErrorCallback(&arg); + } + dumpAll(); + return nullptr; + } + } + + if (heap == nullptr) { + heap = currentHeap; + } + void *ptr = nullptr; + if (heap) { + ptr = heap->alloc(size, align); + } + return ptr; +} + +/* 80495690 */ Heap *Heap::findHeap(MEMiHeapHead *head) { + Heap *heap = nullptr; + OSLockMutex(&sRootMutex); + if (sIsHeapListInitialized) { + Heap *heap2 = nullptr; + while ((heap2 = (Heap *)nw4r::ut::List_GetNext(&sHeapList, heap2))) { + if (heap2->mHeapHandle == head) { + heap = heap2; + break; + } + } + } + OSUnlockMutex(&sRootMutex); + return heap; +} + +/* 80495730 */ Heap *Heap::findParentHeap() { + Heap *retHeap = nullptr; + MEMiHeapHead *heap = MEMFindContainHeap(mHeapHandle); + if (heap) { + retHeap = findHeap(heap); + } + + return retHeap; +} + +extern "C" MEMiHeapHead *fn_803CC670(const void *memBlock); + +/* 80495780 */ Heap *Heap::findContainHeap(const void *memBlock) { + Heap *retHeap = nullptr; + MEMiHeapHead *heap = fn_803CC670(memBlock); + if (heap) { + retHeap = findHeap(heap); + } + + return retHeap; +} + +/* 804957c0 */ void Heap::free(void *ptr, Heap *heap) { + if (heap == nullptr) { + MEMiHeapHead *iheap = fn_803CC670(ptr); + if (iheap == nullptr) { + return; + } + heap = findHeap(iheap); + if (heap == nullptr) { + return; + } + } + + heap->free(ptr); +} + +/* 80495830 */ void Heap::dispose() { + mFlag.setBit(1); + Heap *heap; + while ((heap = (Heap *)nw4r::ut::List_GetFirst(&mChildren)) != nullptr) { + heap->~Heap(); + } + mFlag.resetBit(1); +} + +/* 804958a0 */ void Heap::dump() {} + +// TODO: This debugging function with stripped out error reports doesn't match yet +/* 804958b0 */ void Heap::dumpAll() { + u32 mem[2] = {0, 0}; + + OSLockMutex(&sRootMutex); + for (Heap *heap = nullptr; heap != nullptr; heap = (Heap *)nw4r::ut::List_GetNext(&sHeapList, &heap)) { + Heap *childHeap = nullptr; + Heap *parentHeap = heap->findParentHeap(); + if ((u32)heap < 0x90000000) { + mem[0] += heap->getAllocatableSize(4); + } else { + mem[1] += heap->getAllocatableSize(4); + } + + while ((childHeap = (Heap *)nw4r::ut::List_GetNext(&sHeapList, childHeap)) != nullptr) { + if (parentHeap == childHeap) { + break; + } + } + } + OSUnlockMutex(&sRootMutex); +} + +/* 804959a0 */ Heap *Heap::becomeCurrentHeap() { + OSLockMutex(&sRootMutex); + Heap *h = sCurrentHeap; + sCurrentHeap = this; + OSUnlockMutex(&sRootMutex); + return h; +} + +/* 80495a00 */ Heap *Heap::_becomeCurrentHeapWithoutLock() { + Heap *h = sCurrentHeap; + sCurrentHeap = this; + DCStoreRange(&sCurrentHeap, sizeof(sCurrentHeap)); + return h; +} + +// TODO +extern "C" void MEMInitAllocatorForHeap(Allocator *alloc, s32 align, Heap *heap); + +// TODO this could be an inline virtual function +/* 80495a40 */ void Heap::initAllocator(Allocator *alloc, s32 align) { + MEMInitAllocatorForHeap(alloc, align, this); +} + +} // namespace EGG + +/* 80495a60 */ void *operator new(size_t, void *p) { + return p; +} +/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align) { + return EGG::Heap::alloc(size, align, heap); +} + +/* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc) { + return MEMAllocFromAllocator(alloc->getHandle(), size); +} +/* 80495a90 */ void *operator new[](size_t size, u32 align) { + return EGG::Heap::alloc(size, align, nullptr); +} +/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align) { + return EGG::Heap::alloc(size, align, heap); +} From c931922bde1094e5b205a49a77bb951032cac115 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 16:34:04 +0200 Subject: [PATCH 08/13] eggVideo matching --- config/SOUE01/symbols.txt | 12 +- configure.py | 2 +- include/egg/core/eggVideo.h | 8 +- src/egg/core/eggVideo.cpp | 408 ++++++++++++++++++++++++++++++++++++ 4 files changed, 419 insertions(+), 11 deletions(-) create mode 100644 src/egg/core/eggVideo.cpp diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 669414f7..b4bdf168 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -22146,7 +22146,7 @@ VISetPreRetraceCallback = .text:0x803B3E50; // type:function size:0x44 fn_803B3EA0 = .text:0x803B3EA0; // type:function size:0x44 fn_803B3EF0 = .text:0x803B3EF0; // type:function size:0x118 fn_803B4010 = .text:0x803B4010; // type:function size:0x200 -fn_803B4210 = .text:0x803B4210; // type:function size:0x548 +VIInit = .text:0x803B4210; // type:function size:0x548 VIWaitForRetrace = .text:0x803B4760; // type:function size:0x54 fn_803B47C0 = .text:0x803B47C0; // type:function size:0x2A8 fn_803B4A70 = .text:0x803B4A70; // type:function size:0xE0 @@ -22161,7 +22161,7 @@ VIGetRetraceCount = .text:0x803B5940; // type:function size:0x8 fn_803B5950 = .text:0x803B5950; // type:function size:0x9C fn_803B59F0 = .text:0x803B59F0; // type:function size:0x90 VIGetTvFormat = .text:0x803B5A80; // type:function size:0x60 scope:global -fn_803B5AE0 = .text:0x803B5AE0; // type:function size:0x3C +VIGetDTVStatus = .text:0x803B5AE0; // type:function size:0x3C fn_803B5B20 = .text:0x803B5B20; // type:function size:0x234 fn_803B5D60 = .text:0x803B5D60; // type:function size:0x54 fn_803B5DC0 = .text:0x803B5DC0; // type:function size:0xF8 @@ -22731,12 +22731,12 @@ fn_803D5E60 = .text:0x803D5E60; // type:function size:0x104 fn_803D5F70 = .text:0x803D5F70; // type:function size:0xC fn_803D5F80 = .text:0x803D5F80; // type:function size:0x21C fn_803D61A0 = .text:0x803D61A0; // type:function size:0x338 -fn_803D64E0 = .text:0x803D64E0; // type:function size:0x54 +SCGetAspectRatio = .text:0x803D64E0; // type:function size:0x54 fn_803D6540 = .text:0x803D6540; // type:function size:0x74 -fn_803D65C0 = .text:0x803D65C0; // type:function size:0x54 +SCGetEuRgb60Mode = .text:0x803D65C0; // type:function size:0x54 fn_803D6620 = .text:0x803D6620; // type:function size:0xC SCGetLanguage = .text:0x803D6630; // type:function size:0x6C scope:global -fn_803D66A0 = .text:0x803D66A0; // type:function size:0x54 +SCGetProgressiveMode = .text:0x803D66A0; // type:function size:0x54 fn_803D6700 = .text:0x803D6700; // type:function size:0x54 fn_803D6760 = .text:0x803D6760; // type:function size:0x54 fn_803D67C0 = .text:0x803D67C0; // type:function size:0x40 @@ -26301,7 +26301,7 @@ initialize__Q23EGG5VideoFP16_GXRenderModeObjPCQ33EGG5Video16RenderModeObjSet = . configure__Q23EGG5VideoFP16_GXRenderModeObjPCQ33EGG5Video16RenderModeObjSet = .text:0x804986F0; // type:function size:0x104 getTickPerVRetrace__Q23EGG5VideoFUi = .text:0x80498800; // type:function size:0x60 getTickPerVRetrace__Q23EGG5VideoFv = .text:0x80498860; // type:function size:0x24 -getStandardRenderModeObj__Q23EGG5VideoFv = .text:0x80498890; // type:function size:0x148 +getStandardRenderModeObj__Q23EGG5VideoFPCQ33EGG5Video16RenderModeObjSet = .text:0x80498890; // type:function size:0x148 init__Q23EGG3XfbFUsUsPQ23EGG4Heap = .text:0x804989E0; // type:function size:0x74 __ct__Q23EGG3XfbFPQ23EGG4Heap = .text:0x80498A60; // type:function size:0x64 calcBufferSize__Q23EGG3XfbFUsUs = .text:0x80498AD0; // type:function size:0x14 diff --git a/configure.py b/configure.py index 830c0c10..b99cb472 100644 --- a/configure.py +++ b/configure.py @@ -356,7 +356,7 @@ config.libs = [ Object(Matching, "egg/core/eggDisplay.cpp"), Object(Matching, "egg/core/eggColorFader.cpp"), Object(Matching, "egg/core/eggAsyncDisplay.cpp"), - Object(NonMatching, "egg/core/eggVideo.cpp"), + Object(Matching, "egg/core/eggVideo.cpp"), Object(NonMatching, "egg/core/eggXfb.cpp"), Object(NonMatching, "egg/core/eggXfbManager.cpp"), Object(NonMatching, "egg/core/eggGraphicsFifo.cpp"), diff --git a/include/egg/core/eggVideo.h b/include/egg/core/eggVideo.h index fb56d66f..0a282516 100644 --- a/include/egg/core/eggVideo.h +++ b/include/egg/core/eggVideo.h @@ -11,21 +11,21 @@ namespace EGG { class Video { public: struct RenderModeObjSet { - GXRenderModeObj *table[10]; + const GXRenderModeObj *table[10]; }; public: - /* 0x00 */ GXRenderModeObj const *pRenderMode; + /* 0x00 */ GXRenderModeObj *pRenderMode; /* 0x04 */ TBitFlag mFlag; /* 0x08 */ u32 mConfiguredTime; public: /* inline */ Video() : pRenderMode(0), mFlag(), mConfiguredTime(){}; /* 80498690 */ void initialize(GXRenderModeObj *, const RenderModeObjSet *); - /* 804986f0 */ void configure(GXRenderModeObj *, const RenderModeObjSet *); + /* 804986f0 */ GXRenderModeObj *configure(GXRenderModeObj *, const RenderModeObjSet *); /* 80498800 */ static u32 getTickPerVRetrace(u32 tvFormat); /* 80498860 */ static u32 getTickPerVRetrace(); - /* 80498890 */ static GXRenderModeObj *getStandardRenderModeObj(RenderModeObjSet *); + /* 80498890 */ static const GXRenderModeObj *getStandardRenderModeObj(const RenderModeObjSet *); public: /* inline */ void setBlack(bool b) { diff --git a/src/egg/core/eggVideo.cpp b/src/egg/core/eggVideo.cpp new file mode 100644 index 00000000..9d0bd8cc --- /dev/null +++ b/src/egg/core/eggVideo.cpp @@ -0,0 +1,408 @@ +#include +#include +#include +#include + +namespace EGG { + +// TODO give these proper names + +const GXRenderModeObj renderMode0 = { + 0, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 25, // viXOrigin + 12, // viYOrigin + 670, // viWidth + 456, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode1 = { + 2, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 25, // viXOrigin + 12, // viYOrigin + 670, // viWidth + 456, // viHeight + 0, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {0, 0, 21, 22, 21, 0, 0} // vFilter +}; + +const GXRenderModeObj renderMode2 = { + 4, // tvInfo + 640, // fbWidth + 456, // efbHeight + 542, // xfbHeight + 27, // viXOrigin + 16, // viYOrigin + 666, // viWidth + 542, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode3 = { + 20, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 25, // viXOrigin + 12, // viYOrigin + 670, // viWidth + 456, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode4 = { + 22, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 25, // viXOrigin + 12, // viYOrigin + 670, // viWidth + 456, // viHeight + 0, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {0, 0, 21, 22, 21, 0, 0} // vFilter +}; + +const GXRenderModeObj renderMode5 = { + 0, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 17, // viXOrigin + 12, // viYOrigin + 686, // viWidth + 456, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode6 = { + 2, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 17, // viXOrigin + 12, // viYOrigin + 686, // viWidth + 456, // viHeight + 0, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {0, 0, 21, 22, 21, 0, 0} // vFilter +}; + +const GXRenderModeObj renderMode7 = { + 4, // tvInfo + 640, // fbWidth + 456, // efbHeight + 542, // xfbHeight + 19, // viXOrigin + 16, // viYOrigin + 682, // viWidth + 542, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode8 = { + 20, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 17, // viXOrigin + 12, // viYOrigin + 686, // viWidth + 456, // viHeight + 1, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {7, 7, 12, 12, 12, 7, 7} // vFilter +}; + +const GXRenderModeObj renderMode9 = { + 22, // tvInfo + 640, // fbWidth + 456, // efbHeight + 456, // xfbHeight + 17, // viXOrigin + 12, // viYOrigin + 686, // viWidth + 456, // viHeight + 0, // xfbMode + 0, // field_rendering + 0, // aa + { + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + {6, 6}, + }, // sample_pattern + {0, 0, 21, 22, 21, 0, 0} // vFilter +}; + +const EGG::Video::RenderModeObjSet renderModes = {{&renderMode0, &renderMode1, &renderMode2, &renderMode3, + &renderMode4, &renderMode5, &renderMode6, &renderMode7, &renderMode8, &renderMode9}}; + + +/* 80498690 */ void Video::initialize(GXRenderModeObj *obj, const RenderModeObjSet *set) { + VIInit(); + configure(obj, set); +} + +extern "C" f32 GXGetYScaleFactor(u16 height, u16 width); +extern "C" u16 GXGetNumXfbLines(u16 height, f32 scale); +extern "C" void GXSetDispCopyDst(u16 width, u16 height); +extern "C" u32 GXSetDispCopyYScale(f32 scale); + +/* 804986f0 */ GXRenderModeObj *Video::configure(GXRenderModeObj *obj, const RenderModeObjSet *set) { + GXRenderModeObj *oldMode = pRenderMode; + if (set == nullptr) { + set = &renderModes; + } + if (obj == nullptr) { + // Cast away constness. In an incredibly cursed way, adding proper + // const correctness to this class changes regalloc + obj = (GXRenderModeObj *)getStandardRenderModeObj(set); + } + if (pRenderMode != obj) { + pRenderMode = obj; + VISetBlack(true); + VIConfigure(obj); + VIFlush(); + mConfiguredTime = OSGetTick(); + mFlag.setBit(0); + u16 efbWidth = obj->fbWidth; + u16 efbHeight = obj->efbHeight; + f32 factor = GXGetYScaleFactor(efbHeight, obj->xfbHeight); + u16 lines = GXGetNumXfbLines(efbHeight, factor); + GXSetDispCopySrc(0, 0, efbWidth, efbHeight); + GXSetDispCopyDst(efbWidth, lines); + GXSetDispCopyYScale(factor); + VIWaitForRetrace(); + VIWaitForRetrace(); + } + + return oldMode; +} + +// Random function that pretends to do an int to float +// cast here, for float ordering issues +f32 itof(u32 n) { + return n; +} +// TODO VITvFormat +/* 80498800 */ u32 Video::getTickPerVRetrace(u32 tvFormat) { + f32 val = tvFormat - 1 <= VI_TV_FMT_PAL ? 50.0f : 59.94f; + return (u32)((OS_BUS_CLOCK_SPEED >> 2) / val); +} +/* 80498860 */ u32 Video::getTickPerVRetrace() { + return getTickPerVRetrace(VIGetTvFormat()); +} +/* 80498890 */ const GXRenderModeObj *Video::getStandardRenderModeObj(const RenderModeObjSet *set) { + bool pmode = SCGetProgressiveMode() == 1; + bool rbg60mode = SCGetEuRgb60Mode() == 1; + bool aspect = SCGetAspectRatio() == 0; + bool dtvstatus = VIGetDTVStatus() == 1; + u32 tvFormat = VIGetTvFormat(); + + bool isNtscLike; + switch (tvFormat) { + case VI_TV_FMT_NTSC: + isNtscLike = true; + break; + case VI_TV_FMT_PAL: + case VI_TV_FMT_EURGB60: + isNtscLike = false; + break; + default: + isNtscLike = true; + } + + if (dtvstatus && pmode) { + if (isNtscLike) { + if (aspect) { + return set->table[1]; + } else { + return set->table[6]; + } + } else if (aspect) { + return set->table[4]; + } else { + return set->table[9]; + } + } else if (isNtscLike) { + if (aspect) { + return set->table[0]; + } else { + return set->table[5]; + } + } else if (rbg60mode) { + if (aspect) { + return set->table[3]; + } else { + return set->table[8]; + } + } else if (aspect) { + return set->table[2]; + } + return set->table[7]; +} + +} // namespace EGG From e7915d58a42c3a8091f46ed0032718c10a00d1e8 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 16:37:27 +0200 Subject: [PATCH 09/13] Cleanup --- include/rvl/GX/GXFrameBuf.h | 4 ++++ src/egg/core/eggVideo.cpp | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/rvl/GX/GXFrameBuf.h b/include/rvl/GX/GXFrameBuf.h index 376007e5..f21de91f 100644 --- a/include/rvl/GX/GXFrameBuf.h +++ b/include/rvl/GX/GXFrameBuf.h @@ -24,6 +24,10 @@ typedef struct _GXRenderModeObj { void GXSetCopyFilter(u8, const u8[12][2], u8, const u8[7]); void GXSetCopyClear(GXColor, u32 zClear); void GXSetDispCopySrc(u16 left, u16 top, u16 width, u16 height); +f32 GXGetYScaleFactor(u16 height, u16 width); +u16 GXGetNumXfbLines(u16 height, f32 scale); +void GXSetDispCopyDst(u16 width, u16 height); +u32 GXSetDispCopyYScale(f32 scale); extern GXRenderModeObj GXNtsc480IntDf; extern GXRenderModeObj GXMpal480IntDf; diff --git a/src/egg/core/eggVideo.cpp b/src/egg/core/eggVideo.cpp index 9d0bd8cc..74b893d6 100644 --- a/src/egg/core/eggVideo.cpp +++ b/src/egg/core/eggVideo.cpp @@ -306,11 +306,6 @@ const EGG::Video::RenderModeObjSet renderModes = {{&renderMode0, &renderMode1, & configure(obj, set); } -extern "C" f32 GXGetYScaleFactor(u16 height, u16 width); -extern "C" u16 GXGetNumXfbLines(u16 height, f32 scale); -extern "C" void GXSetDispCopyDst(u16 width, u16 height); -extern "C" u32 GXSetDispCopyYScale(f32 scale); - /* 804986f0 */ GXRenderModeObj *Video::configure(GXRenderModeObj *obj, const RenderModeObjSet *set) { GXRenderModeObj *oldMode = pRenderMode; if (set == nullptr) { From 9944a5bfb9fc4b8d4e5894c190ed80a48f73b663 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 17:12:28 +0200 Subject: [PATCH 10/13] eggAllocator matching --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 14 +++++------ configure.py | 2 +- include/egg/core/eggAllocator.h | 5 ++-- include/rvl/MEM/mem_allocator.h | 2 +- src/egg/core/eggAllocator.cpp | 42 +++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 src/egg/core/eggAllocator.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 7fefadea..b372f9ee 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -257,6 +257,7 @@ egg/core/eggStream.cpp: egg/core/eggAllocator.cpp: .text start:0x804952D0 end:0x804953F0 .data start:0x8056E8D0 end:0x8056E8E8 + .sdata2 start:0x8057F2F0 end:0x8057F2F8 egg/core/eggHeap.cpp: .text start:0x804953F0 end:0x80495AB0 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 669414f7..976825e5 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26184,12 +26184,12 @@ getUncompressedSize__Q23EGG14StreamDecompRLFPCv = .text:0x80495290; // type:func getHeaderSize__Q23EGG14StreamDecompRLFv = .text:0x804952A0; // type:function size:0x8 getUncompressedSize__Q23EGG14StreamDecompLZFPCv = .text:0x804952B0; // type:function size:0x8 getHeaderSize__Q23EGG14StreamDecompLZFv = .text:0x804952C0; // type:function size:0x8 -egg_allocator_pfAlloc = .text:0x804952D0; // type:function size:0x1C -egg_allocator_pfFree = .text:0x804952F0; // type:function size:0x14 -MEMInitAllocatorForHeap = .text:0x80495310; // type:function size:0x1C -__ct__Q23EGG9AllocatorFPQ23EGG4Heapl = .text:0x80495330; // type:function size:0x50 +MEM_AllocFor_Heap__FP12MEMAllocatorUi = .text:0x804952D0; // type:function size:0x1C scope:local +MEM_FreeFor_Heap__FP12MEMAllocatorPv = .text:0x804952F0; // type:function size:0x14 scope:local +MEMInitAllocatorFor_Heap__FP12MEMAllocatoriPv = .text:0x80495310; // type:function size:0x1C +__ct__Q23EGG9AllocatorFPQ23EGG4Heapi = .text:0x80495330; // type:function size:0x50 __dt__Q23EGG9AllocatorFv = .text:0x80495380; // type:function size:0x40 -alloc__Q23EGG9AllocatorFUl = .text:0x804953C0; // type:function size:0x14 +alloc__Q23EGG9AllocatorFUi = .text:0x804953C0; // type:function size:0x14 free__Q23EGG9AllocatorFPv = .text:0x804953E0; // type:function size:0x10 initialize__Q23EGG4HeapFv = .text:0x804953F0; // type:function size:0x40 __ct__Q23EGG4HeapFP12MEMiHeapHead = .text:0x80495430; // type:function size:0x90 @@ -37094,7 +37094,7 @@ lbl_8056E870 = .data:0x8056E870; // type:object size:0x18 lbl_8056E888 = .data:0x8056E888; // type:object size:0x18 lbl_8056E8A0 = .data:0x8056E8A0; // type:object size:0x18 lbl_8056E8B8 = .data:0x8056E8B8; // type:object size:0x18 -lbl_8056E8D0 = .data:0x8056E8D0; // type:object size:0x18 +__vt__Q23EGG9Allocator = .data:0x8056E8D0; // type:object size:0x14 lbl_8056E8E8 = .data:0x8056E8E8; // type:object size:0x68 lbl_8056E950 = .data:0x8056E950; // type:object size:0x30 lbl_8056E980 = .data:0x8056E980; // type:object size:0x10 @@ -47590,7 +47590,7 @@ lbl_8057F2DC = .sdata2:0x8057F2DC; // type:object size:0x4 data:float lbl_8057F2E0 = .sdata2:0x8057F2E0; // type:object size:0x4 data:float lbl_8057F2E4 = .sdata2:0x8057F2E4; // type:object size:0x4 data:float lbl_8057F2E8 = .sdata2:0x8057F2E8; // type:object size:0x8 data:float -lbl_8057F2F0 = .sdata2:0x8057F2F0; // type:object size:0x8 +eggAllocatorFuncs = .sdata2:0x8057F2F0; // type:object size:0x8 scope:local lbl_8057F2F8 = .sdata2:0x8057F2F8; // type:object size:0x4 data:float lbl_8057F300 = .sdata2:0x8057F300; // type:object size:0x8 data:double lbl_8057F308 = .sdata2:0x8057F308; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 830c0c10..2385c5bd 100644 --- a/configure.py +++ b/configure.py @@ -344,7 +344,7 @@ config.libs = [ Object(NonMatching, "egg/core/eggDvdFile.cpp"), Object(NonMatching, "egg/core/eggDvdRipper.cpp"), Object(NonMatching, "egg/core/eggStream.cpp"), - Object(NonMatching, "egg/core/eggAllocator.cpp"), + Object(Matching, "egg/core/eggAllocator.cpp"), Object(NonMatching, "egg/core/eggHeap.cpp"), Object(NonMatching, "egg/core/eggExpHeap.cpp"), Object(NonMatching, "egg/core/eggFrmHeap.cpp"), diff --git a/include/egg/core/eggAllocator.h b/include/egg/core/eggAllocator.h index 454539fe..6a4e32de 100644 --- a/include/egg/core/eggAllocator.h +++ b/include/egg/core/eggAllocator.h @@ -3,9 +3,8 @@ #include "rvl/MEM.h" #include -// /* 80495310 */ MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap); -// /* 804952f0 */ MEM_AllocFor_Heap(MEMAllocator* alloc, void* block); -// /* 804952d0 */ MEM_AllocFor_Heap(MEMAllocator* alloc, u32 size, s32 align); +/* 80495310 */ void MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap); + namespace EGG { class Heap; class Allocator : public MEMAllocator { diff --git a/include/rvl/MEM/mem_allocator.h b/include/rvl/MEM/mem_allocator.h index 3146fe87..c29054c4 100644 --- a/include/rvl/MEM/mem_allocator.h +++ b/include/rvl/MEM/mem_allocator.h @@ -19,7 +19,7 @@ typedef struct MEMAllocatorFuncs { typedef struct MEMAllocator { const MEMAllocatorFuncs *funcs; // at 0x0 - struct MEMiHeapHead *heap; // at 0x4 + void *heap; // at 0x4 u32 heapParam1; // at 0x8 u32 heapParam2; // at 0xC } MEMAllocator; diff --git a/src/egg/core/eggAllocator.cpp b/src/egg/core/eggAllocator.cpp new file mode 100644 index 00000000..b8ce55f2 --- /dev/null +++ b/src/egg/core/eggAllocator.cpp @@ -0,0 +1,42 @@ +#include +#include + +/* 804952d0 */ static void *MEM_AllocFor_Heap(MEMAllocator* alloc, u32 size) { + return static_cast(static_cast(alloc)->heap)->alloc(size, alloc->heapParam1); +} +/* 804952f0 */ static void MEM_FreeFor_Heap(MEMAllocator* alloc, void* block) { + return static_cast(static_cast(alloc)->heap)->free(block); +} + +const MEMAllocatorFuncs eggAllocatorFuncs = { + &MEM_AllocFor_Heap, + &MEM_FreeFor_Heap, +}; + +// TODO this is used from eggHeap for some reason. Figure out +// the correct privacy boundary later. +/* 80495310 */ void MEMInitAllocatorFor_Heap(MEMAllocator* alloc, s32 align, void* heap) { + alloc->funcs = &eggAllocatorFuncs; + alloc->heap = heap; + alloc->heapParam1 = align; + alloc->heapParam2 = 0; +} + + +namespace EGG { + +/* 80495330 */ Allocator::Allocator(Heap *heap, s32 align) : mHeap(heap), align(align) { + MEMInitAllocatorFor_Heap(this, align, heap); +} + +/* 80495380 */ Allocator::~Allocator() {} + +/* 804953c0 */ void *Allocator::alloc(u32 size) { + return Heap::alloc(size, align, mHeap); +} + +/* 804953e0 */ void Allocator::free(void *block) { + Heap::free(block, mHeap); +} + +} // namespace EGG From 9aeb8c1697731a1c117ce1ef14141ad7e0a84731 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 17:24:51 +0200 Subject: [PATCH 11/13] Use correct names --- src/egg/core/eggVideo.cpp | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/egg/core/eggVideo.cpp b/src/egg/core/eggVideo.cpp index 74b893d6..76479432 100644 --- a/src/egg/core/eggVideo.cpp +++ b/src/egg/core/eggVideo.cpp @@ -3,11 +3,9 @@ #include #include -namespace EGG { +namespace { -// TODO give these proper names - -const GXRenderModeObj renderMode0 = { +const GXRenderModeObj gRMO_Pal60_640x456Prog_16x9 = { 0, // tvInfo 640, // fbWidth 456, // efbHeight @@ -36,7 +34,7 @@ const GXRenderModeObj renderMode0 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode1 = { +const GXRenderModeObj gRMO_Pal60_640x456IntDf_16x9 = { 2, // tvInfo 640, // fbWidth 456, // efbHeight @@ -65,7 +63,7 @@ const GXRenderModeObj renderMode1 = { {0, 0, 21, 22, 21, 0, 0} // vFilter }; -const GXRenderModeObj renderMode2 = { +const GXRenderModeObj gRMO_Pal50_640x456IntDf_16x9 = { 4, // tvInfo 640, // fbWidth 456, // efbHeight @@ -94,7 +92,7 @@ const GXRenderModeObj renderMode2 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode3 = { +const GXRenderModeObj gRMO_Ntsc_640x456Prog_16x9 = { 20, // tvInfo 640, // fbWidth 456, // efbHeight @@ -123,7 +121,7 @@ const GXRenderModeObj renderMode3 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode4 = { +const GXRenderModeObj gRMO_Ntsc_640x456IntDf_16x9 = { 22, // tvInfo 640, // fbWidth 456, // efbHeight @@ -152,7 +150,7 @@ const GXRenderModeObj renderMode4 = { {0, 0, 21, 22, 21, 0, 0} // vFilter }; -const GXRenderModeObj renderMode5 = { +const GXRenderModeObj gRMO_Pal60_640x456Prog_4x3 = { 0, // tvInfo 640, // fbWidth 456, // efbHeight @@ -181,7 +179,7 @@ const GXRenderModeObj renderMode5 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode6 = { +const GXRenderModeObj gRMO_Pal60_640x456IntDf_4x3 = { 2, // tvInfo 640, // fbWidth 456, // efbHeight @@ -210,7 +208,7 @@ const GXRenderModeObj renderMode6 = { {0, 0, 21, 22, 21, 0, 0} // vFilter }; -const GXRenderModeObj renderMode7 = { +const GXRenderModeObj gRMO_Pal50_640x456IntDf_4x3 = { 4, // tvInfo 640, // fbWidth 456, // efbHeight @@ -239,7 +237,7 @@ const GXRenderModeObj renderMode7 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode8 = { +const GXRenderModeObj gRMO_Ntsc_640x456Prog_4x3 = { 20, // tvInfo 640, // fbWidth 456, // efbHeight @@ -268,7 +266,7 @@ const GXRenderModeObj renderMode8 = { {7, 7, 12, 12, 12, 7, 7} // vFilter }; -const GXRenderModeObj renderMode9 = { +const GXRenderModeObj gRMO_Ntsc_640x456IntDf_4x3 = { 22, // tvInfo 640, // fbWidth 456, // efbHeight @@ -297,9 +295,14 @@ const GXRenderModeObj renderMode9 = { {0, 0, 21, 22, 21, 0, 0} // vFilter }; -const EGG::Video::RenderModeObjSet renderModes = {{&renderMode0, &renderMode1, &renderMode2, &renderMode3, - &renderMode4, &renderMode5, &renderMode6, &renderMode7, &renderMode8, &renderMode9}}; +} // namespace +namespace EGG { + +const EGG::Video::RenderModeObjSet renderModes = {{&gRMO_Pal60_640x456Prog_16x9, &gRMO_Pal60_640x456IntDf_16x9, + &gRMO_Pal50_640x456IntDf_16x9, &gRMO_Ntsc_640x456Prog_16x9, &gRMO_Ntsc_640x456IntDf_16x9, + &gRMO_Pal60_640x456Prog_4x3, &gRMO_Pal60_640x456IntDf_4x3, &gRMO_Pal50_640x456IntDf_4x3, + &gRMO_Ntsc_640x456Prog_4x3, &gRMO_Ntsc_640x456IntDf_4x3}}; /* 80498690 */ void Video::initialize(GXRenderModeObj *obj, const RenderModeObjSet *set) { VIInit(); @@ -356,18 +359,18 @@ f32 itof(u32 n) { bool aspect = SCGetAspectRatio() == 0; bool dtvstatus = VIGetDTVStatus() == 1; u32 tvFormat = VIGetTvFormat(); - + bool isNtscLike; switch (tvFormat) { - case VI_TV_FMT_NTSC: - isNtscLike = true; - break; - case VI_TV_FMT_PAL: - case VI_TV_FMT_EURGB60: - isNtscLike = false; - break; - default: - isNtscLike = true; + case VI_TV_FMT_NTSC: + isNtscLike = true; + break; + case VI_TV_FMT_PAL: + case VI_TV_FMT_EURGB60: + isNtscLike = false; + break; + default: + isNtscLike = true; } if (dtvstatus && pmode) { From 759c5b5a94d551ad1b86ddbd2d78de609f4b776a Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 5 May 2024 12:22:37 -0400 Subject: [PATCH 12/13] Prepping merge --- config/SOUE01/symbols.txt | 8 ++++---- include/d/d_heap_alloc.h | 4 ++-- include/egg/core/eggHeap.h | 12 +++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a405ceb1..80468d2b 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26206,10 +26206,10 @@ becomeCurrentHeap__Q23EGG4HeapFv = .text:0x804959A0; // type:function size:0x58 _becomeCurrentHeapWithoutLock__Q23EGG4HeapFv = .text:0x80495A00; // type:function size:0x3C initAllocator__Q23EGG4HeapFPQ23EGG9Allocatorl = .text:0x80495A40; // type:function size:0x14 __nw__FUlPv = .text:0x80495A60; // type:function size:0x8 -__nw__FUlPQ23EGG4HeapUi = .text:0x80495A70; // type:function size:0x10 -__nwa__FUl = .text:0x80495A80; // type:function size:0x10 -__nwa__FUlUi = .text:0x80495A90; // type:function size:0x8 -__nwa__FUlPQ23EGG4HeapUi = .text:0x80495AA0; // type:function size:0x10 +__nw__FUlPQ23EGG4Heapi = .text:0x80495A70; // type:function size:0x10 +__nw__FUlPQ23EGG9Allocator = .text:0x80495A80; // type:function size:0x10 +__nwa__FUli = .text:0x80495A90; // type:function size:0x8 +__nwa__FUlPQ23EGG4Heapi = .text:0x80495AA0; // type:function size:0x10 __ct__Q23EGG7ExpHeapFP12MEMiHeapHead = .text:0x80495AB0; // type:function size:0x3C __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 create__Q23EGG7ExpHeapFPvUlUs = .text:0x80495B70; // type:function size:0xB8 diff --git a/include/d/d_heap_alloc.h b/include/d/d_heap_alloc.h index 4fd3a47a..cbf43c5a 100644 --- a/include/d/d_heap_alloc.h +++ b/include/d/d_heap_alloc.h @@ -50,8 +50,8 @@ public: } virtual ~dHeapAllocatorBase() {} - virtual void onAlloc(EGG::HeapAllocArg *arg) {}; - virtual void onFree(EGG::HeapFreeArg *arg) {}; + virtual void onAlloc(EGG::HeapAllocArg *arg){}; + virtual void onFree(EGG::HeapFreeArg *arg){}; /* 0x04 */ bool mCallbacksInitialized; /* 0x08 */ EGG::HeapAllocCallback mPreviousAllocCallback; diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 1740a1e4..24faec83 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -153,11 +153,13 @@ public: /* 80576760 */ static void *sFreeCallbackArg; /* 80576764 */ static HeapCreateCallback sCreateCallback; /* 80576764 */ static HeapDestroyCallback sDestroyCallback; +}; +} // namespace EGG - /* 80495a60 */ void *operator new(size_t, void *p); - /* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align); - /* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); - /* 80495a90 */ void *operator new[](size_t size, u32 align); - /* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, u32 align); +/* 80495a60 */ void *operator new(size_t, void *p); +/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, int align); +/* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); +/* 80495a90 */ void *operator new[](size_t size, int align); +/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align); #endif From af59a51db3a6959561cc91d90fef4fa27f57956c Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 5 May 2024 12:27:34 -0400 Subject: [PATCH 13/13] fix up align type (Ui -> i) --- config/SOUE01/symbols.txt | 4 ++-- include/egg/core/eggHeap.h | 6 +++--- src/egg/core/eggHeap.cpp | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a1226acc..d3a1ee7f 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26206,9 +26206,9 @@ becomeCurrentHeap__Q23EGG4HeapFv = .text:0x804959A0; // type:function size:0x58 _becomeCurrentHeapWithoutLock__Q23EGG4HeapFv = .text:0x80495A00; // type:function size:0x3C initAllocator__Q23EGG4HeapFPQ23EGG9Allocatori = .text:0x80495A40; // type:function size:0x14 __nw__FUlPv = .text:0x80495A60; // type:function size:0x8 -__nw__FUlPQ23EGG4HeapUi = .text:0x80495A70; // type:function size:0x10 +__nw__FUlPQ23EGG4Heapi = .text:0x80495A70; // type:function size:0x10 __nw__FUlPQ23EGG9Allocator = .text:0x80495A80; // type:function size:0x10 -__nwa__FUlUi = .text:0x80495A90; // type:function size:0x8 +__nwa__FUli = .text:0x80495A90; // type:function size:0x8 __nwa__FUlPQ23EGG4Heapi = .text:0x80495AA0; // type:function size:0x10 __ct__Q23EGG7ExpHeapFP12MEMiHeapHead = .text:0x80495AB0; // type:function size:0x3C __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 6043c60d..2e33d8a7 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -161,9 +161,9 @@ public: } // namespace EGG /* 80495a60 */ void *operator new(size_t, void *p); -/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align); +/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, int align); /* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc); -/* 80495a90 */ void *operator new[](size_t size, u32 align); -/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, u32 align); +/* 80495a90 */ void *operator new[](size_t size, int align); +/* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align); #endif diff --git a/src/egg/core/eggHeap.cpp b/src/egg/core/eggHeap.cpp index 620b9e95..a7a0dc7a 100644 --- a/src/egg/core/eggHeap.cpp +++ b/src/egg/core/eggHeap.cpp @@ -54,8 +54,7 @@ namespace EGG { // TODO small instshuffle here, related to regshuffle problems OSReport("cannot allocate from heap %x(%s) : allocatable heap is %x(%s)\n", heap, heap->getName(), sAllocatableHeap, sAllocatableHeap->getName()); - OSReport("\tthread heap=%x(%s)\n", threadHeap, - threadHeap != nullptr ? threadHeap->getName() : "none"); + OSReport("\tthread heap=%x(%s)\n", threadHeap, threadHeap != nullptr ? threadHeap->getName() : "none"); if (sErrorCallback != nullptr) { HeapErrorArg arg; arg.msg = "disable_but"; @@ -192,14 +191,14 @@ extern "C" void MEMInitAllocatorForHeap(Allocator *alloc, s32 align, Heap *heap) /* 80495a60 */ void *operator new(size_t, void *p) { return p; } -/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, u32 align) { +/* 80495a70 */ void *operator new(size_t size, EGG::Heap *heap, int align) { return EGG::Heap::alloc(size, align, heap); } /* 80495a80 */ void *operator new(size_t size, EGG::Allocator *alloc) { return MEMAllocFromAllocator(alloc->getHandle(), size); } -/* 80495a90 */ void *operator new[](size_t size, u32 align) { +/* 80495a90 */ void *operator new[](size_t size, int align) { return EGG::Heap::alloc(size, align, nullptr); } /* 80495aa0 */ void *operator new[](size_t size, EGG::Heap *heap, int align) {