From f289f08e49b45f8220bdf5f9624d3b8d7428f4ea Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 18:48:52 +0200 Subject: [PATCH 01/11] eggExpHeap matching --- config/SOUE01/symbols.txt | 30 ++++---- configure.py | 2 +- include/egg/core/eggExpHeap.h | 7 +- include/egg/core/eggHeap.h | 20 ++--- include/rvl/MEM/mem_expHeap.h | 7 +- src/egg/core/eggExpHeap.cpp | 140 ++++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 src/egg/core/eggExpHeap.cpp diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 97c2c8d9..ac6ef721 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -22567,16 +22567,16 @@ fn_803CC940 = .text:0x803CC940; // type:function size:0x22C fn_803CCB70 = .text:0x803CCB70; // type:function size:0xDC fn_803CCC50 = .text:0x803CCC50; // type:function size:0xC8 fn_803CCD20 = .text:0x803CCD20; // type:function size:0x168 -fn_803CCE90 = .text:0x803CCE90; // type:function size:0xB0 -fn_803CCF40 = .text:0x803CCF40; // type:function size:0x30 -fn_803CCF70 = .text:0x803CCF70; // type:function size:0xB0 -fn_803CD020 = .text:0x803CD020; // type:function size:0x1FC -fn_803CD220 = .text:0x803CD220; // type:function size:0xC4 -fn_803CD2F0 = .text:0x803CD2F0; // type:function size:0x7C -fn_803CD370 = .text:0x803CD370; // type:function size:0xD8 -fn_803CD450 = .text:0x803CD450; // type:function size:0x58 +MEMCreateExpHeapEx = .text:0x803CCE90; // type:function size:0xB0 +MEMDestroyExpHeap = .text:0x803CCF40; // type:function size:0x30 +MEMAllocFromExpHeapEx = .text:0x803CCF70; // type:function size:0xB0 +MEMResizeForMBlockExpHeap = .text:0x803CD020; // type:function size:0x1FC +MEMFreeToExpHeap = .text:0x803CD220; // type:function size:0xC4 +MEMGetAllocatableSizeForExpHeap = .text:0x803CD2F0; // type:function size:0x7C +MEMGetAllocatableSizeForExpHeapEx = .text:0x803CD370; // type:function size:0xD8 +MEMSetGroupIdForExpHeap = .text:0x803CD450; // type:function size:0x58 fn_803CD4B0 = .text:0x803CD4B0; // type:function size:0x8 -fn_803CD4C0 = .text:0x803CD4C0; // type:function size:0xD8 +MEMAdjustExpHeap = .text:0x803CD4C0; // type:function size:0xD8 fn_803CD5A0 = .text:0x803CD5A0; // type:function size:0x84 fn_803CD630 = .text:0x803CD630; // type:function size:0x30 fn_803CD660 = .text:0x803CD660; // type:function size:0x120 @@ -26215,11 +26215,11 @@ __dt__Q23EGG7ExpHeapFv = .text:0x80495AF0; // type:function size:0x74 create__Q23EGG7ExpHeapFPvUlUs = .text:0x80495B70; // type:function size:0xB8 create__Q23EGG7ExpHeapFUlPQ23EGG4HeapUs = .text:0x80495C30; // type:function size:0xCC destroy__Q23EGG7ExpHeapFv = .text:0x80495D00; // type:function size:0x88 -alloc__Q23EGG7ExpHeapFUll = .text:0x80495D90; // type:function size:0xB8 +alloc__Q23EGG7ExpHeapFUii = .text:0x80495D90; // type:function size:0xB8 free__Q23EGG7ExpHeapFPv = .text:0x80495E50; // type:function size:0x68 -resizeForMBlock__Q23EGG7ExpHeapFPvUl = .text:0x80495EC0; // type:function size:0x8 +resizeForMBlock__Q23EGG7ExpHeapFPvUi = .text:0x80495EC0; // type:function size:0x8 getTotalFreeSize__Q23EGG7ExpHeapFv = .text:0x80495ED0; // type:function size:0x8 -getAllocatableSize__Q23EGG7ExpHeapFl = .text:0x80495EE0; // type:function size:0x8 +getAllocatableSize__Q23EGG7ExpHeapFi = .text:0x80495EE0; // type:function size:0x8 setGroupID__Q23EGG7ExpHeapFUs = .text:0x80495EF0; // type:function size:0x8 adjust__Q23EGG7ExpHeapFv = .text:0x80495F00; // type:function size:0x78 getSizeForMBlock__Q23EGG7ExpHeapFPCv = .text:0x80495F80; // type:function size:0x4 @@ -37097,9 +37097,9 @@ lbl_8056E8B8 = .data:0x8056E8B8; // type:object size:0x18 __vt__Q23EGG9Allocator = .data:0x8056E8D0; // type:object size:0x14 lbl_8056E8E8 = .data:0x8056E8E8; // type:object size:0x68 __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 +lbl_8056E980 = .data:0x8056E980; // type:object size:0xF data:string +lbl_8056E990 = .data:0x8056E990; // type:object size:0xB data:string +__vt__Q23EGG7ExpHeap = .data:0x8056E9A0; // type:object size:0x30 lbl_8056E9D0 = .data:0x8056E9D0; // type:object size:0x30 lbl_8056EA00 = .data:0x8056EA00; // type:object size:0x30 lbl_8056EA30 = .data:0x8056EA30; // type:object size:0x10 diff --git a/configure.py b/configure.py index 6c05b404..234f5627 100644 --- a/configure.py +++ b/configure.py @@ -355,7 +355,7 @@ config.libs = [ Object(NonMatching, "egg/core/eggStream.cpp"), Object(Matching, "egg/core/eggAllocator.cpp"), Object(NonMatching, "egg/core/eggHeap.cpp"), - Object(NonMatching, "egg/core/eggExpHeap.cpp"), + Object(Matching, "egg/core/eggExpHeap.cpp"), Object(NonMatching, "egg/core/eggFrmHeap.cpp"), Object(NonMatching, "egg/core/eggAssertHeap.cpp"), Object(NonMatching, "egg/core/eggDisposer.cpp"), diff --git a/include/egg/core/eggExpHeap.h b/include/egg/core/eggExpHeap.h index 2cfc534d..69b35128 100644 --- a/include/egg/core/eggExpHeap.h +++ b/include/egg/core/eggExpHeap.h @@ -24,7 +24,12 @@ public: /* 80495b70 */ static ExpHeap *create(void *block, size_t size, u16 attr); /* 80495c30 */ static ExpHeap *create(size_t size, Heap *heap, u16 attr); /* 80495d00 */ void setGroupID(u16 groupId); - /* 80495f80 */ u32 getSizeForMBlock(const void *block); + /* 80495f80 */ static u32 getSizeForMBlock(const void *block); + + // Placement new for ::create + inline void *operator new(size_t size, void *ptr) { + return ptr; + } }; } // namespace EGG diff --git a/include/egg/core/eggHeap.h b/include/egg/core/eggHeap.h index 969fc229..8d9ce935 100644 --- a/include/egg/core/eggHeap.h +++ b/include/egg/core/eggHeap.h @@ -18,12 +18,12 @@ class Allocator; struct HeapAllocArg { void *userArg; // 00 - u32 size; // 04 - int align; // 08 - Heap *heap; // 0C heap to allocate in - int another; // 10 + u32 size; // 04 + int align; // 08 + void *ptr; // 0C the allocated ptr + Heap *heap; // 10 heap to allocate in - inline HeapAllocArg() : userArg(0), size(0), align(0), heap(nullptr) {} + inline HeapAllocArg() : userArg(0), size(0), align(0), heap(nullptr), ptr(nullptr) {} }; typedef void (*HeapAllocCallback)(HeapAllocArg *arg); @@ -37,8 +37,8 @@ typedef void (*ErrorCallback)(HeapErrorArg *); struct HeapFreeArg { void *userArg; - int arg1; - int arg2; + void *ptr; + Heap *heap; }; typedef void (*HeapFreeCallback)(HeapFreeArg *); @@ -57,14 +57,14 @@ public: // vtable at 0x0 | 8056e950 /* vt 0x08 | 804954c0 */ virtual ~Heap(); /* vt 0x0C | 00000000 */ virtual eHeapKind getHeapKind() const = 0; - /* vt 0x10 | 80495a40 */ virtual void initAllocator(Allocator *allocator, s32 align) = 0; + /* vt 0x10 | 80495a40 */ virtual void initAllocator(Allocator *allocator, s32 align); /* vt 0x14 | 00000000 */ virtual void *alloc(u32 size, s32 align) = 0; /* vt 0x18 | 00000000 */ virtual void free(void *block) = 0; /* vt 0x1C | 00000000 */ virtual void destroy() = 0; /* vt 0x20 | 00000000 */ virtual u32 resizeForMBlock(void *block, u32 size) = 0; /* vt 0x24 | 00000000 */ virtual u32 getTotalFreeSize() = 0; - /* vt 0x24 | 00000000 */ virtual u32 getAllocatableSize(s32 align) = 0; - /* vt 0x28 | 00000000 */ virtual u32 adjust() = 0; + /* vt 0x28 | 00000000 */ virtual u32 getAllocatableSize(s32 align) = 0; + /* vt 0x2C | 00000000 */ virtual u32 adjust() = 0; public: void setName(const char *name) { diff --git a/include/rvl/MEM/mem_expHeap.h b/include/rvl/MEM/mem_expHeap.h index 2a8cbe88..db3ebdc1 100644 --- a/include/rvl/MEM/mem_expHeap.h +++ b/include/rvl/MEM/mem_expHeap.h @@ -53,7 +53,9 @@ struct MEMiHeapHead *MEMDestroyExpHeap(struct MEMiHeapHead *heap); void *MEMAllocFromExpHeapEx(struct MEMiHeapHead *heap, u32 size, s32 align); u32 MEMResizeForMBlockExpHeap(struct MEMiHeapHead *heap, void *memBlock, u32 size); void MEMFreeToExpHeap(struct MEMiHeapHead *heap, void *memBlock); +u32 MEMGetAllocatableSizeForExpHeap(struct MEMiHeapHead *heap); u32 MEMGetAllocatableSizeForExpHeapEx(struct MEMiHeapHead *heap, s32 align); +void MEMSetGroupIdForExpHeap(MEMiHeapHead *mHeapHandle, u16 groupId); u32 MEMAdjustExpHeap(struct MEMiHeapHead *heap); static inline struct MEMiHeapHead *MEMCreateExpHeap(void *start, u32 size) { @@ -63,10 +65,11 @@ static inline struct MEMiHeapHead *MEMCreateExpHeap(void *start, u32 size) { static inline void *MEMAllocFromExpHeap(struct MEMiHeapHead *heap, u32 size) { return MEMAllocFromExpHeapEx(heap, size, 4); } - +// This doesn't appear to be inline in SS yet +/* static inline u32 MEMGetAllocatableSizeForExpHeap(struct MEMiHeapHead *heap) { return MEMGetAllocatableSizeForExpHeapEx(heap, 4); -} +}*/ #ifdef __cplusplus } diff --git a/src/egg/core/eggExpHeap.cpp b/src/egg/core/eggExpHeap.cpp new file mode 100644 index 00000000..97e9c9a9 --- /dev/null +++ b/src/egg/core/eggExpHeap.cpp @@ -0,0 +1,140 @@ +#include + +namespace EGG { + +/* 80495ab0 */ ExpHeap::ExpHeap(MEMiHeapHead *heapHandle): Heap(heapHandle) {} + +/* 80495af0 */ ExpHeap::~ExpHeap() { + dispose(); + MEMDestroyExpHeap(mHeapHandle); +} + +/* 80495b70 */ ExpHeap* ExpHeap::create(void *heapStart, size_t size, u16 attr) { + ExpHeap *heap = nullptr; + void *startAddr = heapStart; + void *heapEnd = ROUND_DOWN_PTR((u8*)heapStart + size, 0x04); + heapStart = ROUND_UP_PTR(heapStart, 0x04); + + + if (heapStart > heapEnd || ((u8*)heapEnd - (u8*)heapStart) < 0x38u) { + return nullptr; + } + + MEMiHeapHead *head = MEMCreateExpHeapEx(((ExpHeap*)heapStart) + 1, ((u8*)heapEnd - (u8*)heapStart) - 0x34, attr); + if (head != nullptr) { + heap = new(heapStart) ExpHeap(head); + heap->mParentBlock = startAddr; + if (sCreateCallback != nullptr) { + (sCreateCallback)(heap); + } + } + + return heap; +} + +/* 80495c30 */ ExpHeap* ExpHeap::create(size_t size, Heap *heap, u16 attr) { + ExpHeap *newHeap = nullptr; + if (heap == nullptr) { + heap = sCurrentHeap; + } + + if (size == -1) { + size = heap->getAllocatableSize(0x04); + } + + void *block = heap->alloc(size, 0x04); + if (block != nullptr) { + newHeap = ExpHeap::create(block, size, attr); + if (newHeap == nullptr) { + heap->free(block); + } + } + + return newHeap; +} + +/* 80495d00 */ void ExpHeap::destroy() { + if (sDestroyCallback != nullptr) { + sDestroyCallback(this); + } + + Heap *parentHeap = findParentHeap(); + this->~ExpHeap(); + if (parentHeap != nullptr) { + parentHeap->free(this); + } +} + +/* 80495d90 */ void *ExpHeap::alloc(u32 size, s32 align) { + if (mFlag.onBit(0)) { + #line 182 + OSError("DAME DAME\n"); + } + + void *ptr = MEMAllocFromExpHeapEx(mHeapHandle, size, align); + if (sAllocCallback != nullptr) { + HeapAllocArg arg; + arg.userArg = sAllocCallbackArg; + arg.ptr = ptr; + arg.size = size; + arg.align = align; + arg.heap = this; + (sAllocCallback)(&arg); + } + + return ptr; +} + +/* 80495e50 */ void ExpHeap::free(void *ptr) { + if (sFreeCallback != nullptr) { + HeapFreeArg arg; + arg.userArg = sFreeCallbackArg; + arg.ptr = ptr; + arg.heap = this; + (sFreeCallback)(&arg); + } + MEMFreeToExpHeap(mHeapHandle, ptr); +} + +/* 80495ec0 */ u32 ExpHeap::resizeForMBlock(void *block, u32 size) { + return MEMResizeForMBlockExpHeap(mHeapHandle, block, size); +} + +/* 80495ed0 */ u32 ExpHeap::getTotalFreeSize() { + return MEMGetAllocatableSizeForExpHeap(mHeapHandle); +} + +/* 80495ee0 */ u32 ExpHeap::getAllocatableSize(s32 align) { + return MEMGetAllocatableSizeForExpHeapEx(mHeapHandle, align); +} + +/* 80495d00 */ void ExpHeap::setGroupID(u16 groupId) { + MEMSetGroupIdForExpHeap(mHeapHandle, groupId); +} + +/* 80495f00 */ u32 ExpHeap::adjust() { + u32 adjustedSize = MEMAdjustExpHeap(mHeapHandle); + u32 totalSize = adjustedSize + 0x34; + if (totalSize > 0x34) { + Heap *parent = findParentHeap(); + if (parent != nullptr) { + parent->resizeForMBlock(mParentBlock, totalSize); + return totalSize; + } + } + return 0; +} + +// TODO marked as "idk" in Ghidra +extern "C" u32 fn_803CD4B0(const void *block); + +/* 80495f80 */ u32 ExpHeap::getSizeForMBlock(const void *block) { + return fn_803CD4B0(block); +} + +/* 80495f90 */ Heap::eHeapKind ExpHeap::getHeapKind() const { + return HEAP_KIND_EXPANDED; +} + + +} // namespace EGG From 944a5315c6735ac88e437755e7137a6d1d154135 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 5 May 2024 13:07:51 -0400 Subject: [PATCH 02/11] added MEMGetSizeForMBlockExpHeap symbol --- config/SOUE01/symbols.txt | 2 +- include/rvl/MEM/mem_expHeap.h | 1 + src/egg/core/eggExpHeap.cpp | 27 +++++++++++---------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index ac6ef721..f3114665 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -22575,7 +22575,7 @@ MEMFreeToExpHeap = .text:0x803CD220; // type:function size:0xC4 MEMGetAllocatableSizeForExpHeap = .text:0x803CD2F0; // type:function size:0x7C MEMGetAllocatableSizeForExpHeapEx = .text:0x803CD370; // type:function size:0xD8 MEMSetGroupIdForExpHeap = .text:0x803CD450; // type:function size:0x58 -fn_803CD4B0 = .text:0x803CD4B0; // type:function size:0x8 +MEMGetSizeForMBlockExpHeap = .text:0x803CD4B0; // type:function size:0x8 MEMAdjustExpHeap = .text:0x803CD4C0; // type:function size:0xD8 fn_803CD5A0 = .text:0x803CD5A0; // type:function size:0x84 fn_803CD630 = .text:0x803CD630; // type:function size:0x30 diff --git a/include/rvl/MEM/mem_expHeap.h b/include/rvl/MEM/mem_expHeap.h index db3ebdc1..bdf9e79a 100644 --- a/include/rvl/MEM/mem_expHeap.h +++ b/include/rvl/MEM/mem_expHeap.h @@ -57,6 +57,7 @@ u32 MEMGetAllocatableSizeForExpHeap(struct MEMiHeapHead *heap); u32 MEMGetAllocatableSizeForExpHeapEx(struct MEMiHeapHead *heap, s32 align); void MEMSetGroupIdForExpHeap(MEMiHeapHead *mHeapHandle, u16 groupId); u32 MEMAdjustExpHeap(struct MEMiHeapHead *heap); +u32 MEMGetSizeForMBlockExpHeap(const void *block); static inline struct MEMiHeapHead *MEMCreateExpHeap(void *start, u32 size) { return MEMCreateExpHeapEx(start, size, 0); diff --git a/src/egg/core/eggExpHeap.cpp b/src/egg/core/eggExpHeap.cpp index 97e9c9a9..4c7c72c4 100644 --- a/src/egg/core/eggExpHeap.cpp +++ b/src/egg/core/eggExpHeap.cpp @@ -2,27 +2,26 @@ namespace EGG { -/* 80495ab0 */ ExpHeap::ExpHeap(MEMiHeapHead *heapHandle): Heap(heapHandle) {} +/* 80495ab0 */ ExpHeap::ExpHeap(MEMiHeapHead *heapHandle) : Heap(heapHandle) {} /* 80495af0 */ ExpHeap::~ExpHeap() { dispose(); MEMDestroyExpHeap(mHeapHandle); } -/* 80495b70 */ ExpHeap* ExpHeap::create(void *heapStart, size_t size, u16 attr) { +/* 80495b70 */ ExpHeap *ExpHeap::create(void *heapStart, size_t size, u16 attr) { ExpHeap *heap = nullptr; void *startAddr = heapStart; - void *heapEnd = ROUND_DOWN_PTR((u8*)heapStart + size, 0x04); + void *heapEnd = ROUND_DOWN_PTR((u8 *)heapStart + size, 0x04); heapStart = ROUND_UP_PTR(heapStart, 0x04); - - if (heapStart > heapEnd || ((u8*)heapEnd - (u8*)heapStart) < 0x38u) { + if (heapStart > heapEnd || ((u8 *)heapEnd - (u8 *)heapStart) < 0x38u) { return nullptr; } - MEMiHeapHead *head = MEMCreateExpHeapEx(((ExpHeap*)heapStart) + 1, ((u8*)heapEnd - (u8*)heapStart) - 0x34, attr); + MEMiHeapHead *head = MEMCreateExpHeapEx(((ExpHeap *)heapStart) + 1, ((u8 *)heapEnd - (u8 *)heapStart) - 0x34, attr); if (head != nullptr) { - heap = new(heapStart) ExpHeap(head); + heap = new (heapStart) ExpHeap(head); heap->mParentBlock = startAddr; if (sCreateCallback != nullptr) { (sCreateCallback)(heap); @@ -32,12 +31,12 @@ namespace EGG { return heap; } -/* 80495c30 */ ExpHeap* ExpHeap::create(size_t size, Heap *heap, u16 attr) { +/* 80495c30 */ ExpHeap *ExpHeap::create(size_t size, Heap *heap, u16 attr) { ExpHeap *newHeap = nullptr; if (heap == nullptr) { heap = sCurrentHeap; } - + if (size == -1) { size = heap->getAllocatableSize(0x04); } @@ -67,7 +66,7 @@ namespace EGG { /* 80495d90 */ void *ExpHeap::alloc(u32 size, s32 align) { if (mFlag.onBit(0)) { - #line 182 +#line 182 OSError("DAME DAME\n"); } @@ -119,22 +118,18 @@ namespace EGG { Heap *parent = findParentHeap(); if (parent != nullptr) { parent->resizeForMBlock(mParentBlock, totalSize); - return totalSize; + return totalSize; } } return 0; } -// TODO marked as "idk" in Ghidra -extern "C" u32 fn_803CD4B0(const void *block); - /* 80495f80 */ u32 ExpHeap::getSizeForMBlock(const void *block) { - return fn_803CD4B0(block); + return MEMGetSizeForMBlockExpHeap(block); } /* 80495f90 */ Heap::eHeapKind ExpHeap::getHeapKind() const { return HEAP_KIND_EXPANDED; } - } // namespace EGG From 9da8f877e177906d8f51415996d542e41b622fd8 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 21:03:17 +0200 Subject: [PATCH 03/11] eggGraphicsFifo matching --- config/SOUE01/splits.txt | 3 ++- config/SOUE01/symbols.txt | 10 ++++----- configure.py | 2 +- include/egg/core/eggGraphicsFifo.h | 2 +- src/egg/core/eggGraphicsFifo.cpp | 35 ++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 src/egg/core/eggGraphicsFifo.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 4973c05f..d6826e69 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -385,7 +385,8 @@ egg/core/eggXfbManager.cpp: egg/core/eggGraphicsFifo.cpp: .text start:0x80498E20 end:0x80498F90 - .sbss start:0x80576798 end:0x805767A8 + .data start:0x8056EB80 end:0x8056EB90 + .sbss start:0x80576798 end:0x805767A4 egg/core/eggController.cpp: .text start:0x80498F90 end:0x8049AB58 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f3114665..fe00db82 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26309,9 +26309,9 @@ isRegisterd__Q23EGG10XfbManagerCFRQ23EGG3Xfb = .text:0x80498AF0; // type:functio attach__Q23EGG10XfbManagerFPQ23EGG3Xfb = .text:0x80498B30; // type:function size:0xE0 copyEFB__Q23EGG10XfbManagerFb = .text:0x80498C10; // type:function size:0xE8 setNextFrameBuffer__Q23EGG10XfbManagerFv = .text:0x80498D00; // type:function size:0x120 -create__Q23EGG12GraphicsFifoFUlPQ23EGG4Heap = .text:0x80498E20; // type:function size:0x68 +create__Q23EGG12GraphicsFifoFUiPQ23EGG4Heap = .text:0x80498E20; // type:function size:0x68 __dt__Q23EGG12GraphicsFifoFv = .text:0x80498E90; // type:function size:0x98 -__ct__Q23EGG12GraphicsFifoFUlPQ23EGG4Heap = .text:0x80498F30; // type:function size:0x60 +__ct__Q23EGG12GraphicsFifoFUiPQ23EGG4Heap = .text:0x80498F30; // type:function size:0x60 init__Q23EGG10CoreStatusFv = .text:0x80498F90; // type:function size:0xC getFSStickButton__Q23EGG10CoreStatusCFv = .text:0x80498FA0; // type:function size:0xAC __ct__Q23EGG14CoreControllerFv = .text:0x80499050; // type:function size:0x60 @@ -37109,7 +37109,7 @@ __vt__Q23EGG7Display = .data:0x8056EAC8; // type:object size:0x20 __vt__Q23EGG10ColorFader = .data:0x8056EAE8; // type:object size:0x24 clear_z_TX__29@unnamed@eggAsyncDisplay_cpp@ = .data:0x8056EB20; // type:object size:0x40 scope:local __vt__Q23EGG12AsyncDisplay = .data:0x8056EB60; // type:object size:0x20 -lbl_8056EB80 = .data:0x8056EB80; // type:object size:0x10 +__vt__Q23EGG12GraphicsFifo = .data:0x8056EB80; // type:object size:0xC lbl_8056EB90 = .data:0x8056EB90; // type:object size:0x18 lbl_8056EBA8 = .data:0x8056EBA8; // type:object size:0xC lbl_8056EBB4 = .data:0x8056EBB4; // type:object size:0xC @@ -40895,8 +40895,8 @@ lbl_80576778 = .sbss:0x80576778; // type:object size:0x8 data:4byte mConfigData__Q23EGG10BaseSystem = .sbss:0x80576780; // type:object size:0x4 data:4byte sTickPeriod__Q23EGG7Display = .sbss:0x80576788; // type:object size:0x4 data:4byte spSelector = .sbss:0x80576790; // type:object size:0x4 data:4byte -lbl_80576798 = .sbss:0x80576798; // type:object size:0x4 data:4byte -lbl_8057679C = .sbss:0x8057679C; // type:object size:0xC +sGraphicsFifo__Q23EGG12GraphicsFifo = .sbss:0x80576798; // type:object size:0x4 data:4byte +sGpStatus__Q23EGG12GraphicsFifo = .sbss:0x8057679C; // type:object size:0x5 data:byte lbl_805767A8 = .sbss:0x805767A8; // type:object size:0x4 data:4byte lbl_805767AC = .sbss:0x805767AC; // type:object size:0x4 data:4byte lbl_805767B0 = .sbss:0x805767B0; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 3123135c..45c34be9 100644 --- a/configure.py +++ b/configure.py @@ -369,7 +369,7 @@ config.libs = [ Object(Matching, "egg/core/eggVideo.cpp"), Object(Matching, "egg/core/eggXfb.cpp"), Object(NonMatching, "egg/core/eggXfbManager.cpp"), - Object(NonMatching, "egg/core/eggGraphicsFifo.cpp"), + Object(Matching, "egg/core/eggGraphicsFifo.cpp"), Object(NonMatching, "egg/core/eggController.cpp"), ], ), diff --git a/include/egg/core/eggGraphicsFifo.h b/include/egg/core/eggGraphicsFifo.h index 0e060401..8226aa90 100644 --- a/include/egg/core/eggGraphicsFifo.h +++ b/include/egg/core/eggGraphicsFifo.h @@ -22,7 +22,7 @@ public: public: /* 80576798 */ static GraphicsFifo *sGraphicsFifo; - /* 8057679c */ static bool sGpStatus[4]; + /* 8057679c */ static u8 sGpStatus[5]; }; } // namespace EGG diff --git a/src/egg/core/eggGraphicsFifo.cpp b/src/egg/core/eggGraphicsFifo.cpp new file mode 100644 index 00000000..bb937d13 --- /dev/null +++ b/src/egg/core/eggGraphicsFifo.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + + +extern "C" void *GXInit(void *buf, u32 bufSize); +extern "C" void GXGetGPStatus(GXBool *overhi, GXBool *underlow, GXBool *readIdle, GXBool *cmdIdle, GXBool *brkpt); + +namespace EGG { + + +GraphicsFifo *GraphicsFifo::sGraphicsFifo; +u8 GraphicsFifo::sGpStatus[]; + +void GraphicsFifo::create(u32 size, Heap *heap) { + if (heap == nullptr) { + heap = Heap::sCurrentHeap; + } + sGraphicsFifo = new(heap, 0x04) GraphicsFifo(size, heap); +} + +GraphicsFifo::~GraphicsFifo() { + do { + GXGetGPStatus(&sGpStatus[0], &sGpStatus[1], &sGpStatus[2], &sGpStatus[3], &sGpStatus[4]); + } while (sGpStatus[2] == false); + Heap::free(mBuffBase, nullptr); +} + +GraphicsFifo::GraphicsFifo(u32 size, Heap *heap) { + mBufSize = ROUND_UP(size, 0x20); + mBuffBase = Heap::alloc(mBufSize, 0x20, heap); + mGxInitData = GXInit(mBuffBase, mBufSize); +} + +} // namespace EGG From defdaca00d3ebad32680a51828c19c9b2aaa484c Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 00:12:56 +0200 Subject: [PATCH 04/11] Most of eggAssert --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 26 ++-- include/Runtime.PPCEABI.H/__va_arg.h | 1 + include/egg/prim/eggAssert.h | 13 +- include/rvl/OS/OSError.h | 1 + src/egg/prim/eggAssert.cpp | 205 +++++++++++++++++++++++++++ 6 files changed, 229 insertions(+), 18 deletions(-) create mode 100644 src/egg/prim/eggAssert.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 4973c05f..f798c940 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -420,6 +420,7 @@ egg/prim/eggAssert.cpp: .text start:0x8049BF90 end:0x8049C5BC .data start:0x8056EC88 end:0x8056ED00 .sbss start:0x805767F8 end:0x80576808 + .bss start:0x80674C60 end:0x80674D68 egg/gfx/eggCamera.cpp: .text start:0x8049C5C0 end:0x8049CAC8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f3114665..a7406ec4 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17227,7 +17227,7 @@ fn_802DEF80 = .text:0x802DEF80; // type:function size:0x8 fn_802DEF90 = .text:0x802DEF90; // type:function size:0x4C fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 OSReport = .text:0x802DF060; // type:function size:0x80 scope:weak -vprintf = .text:0x802DF0E0; // type:function size:0x4 scope:global +OSVReport = .text:0x802DF0E0; // type:function size:0x4 scope:global fn_802DF0F0 = .text:0x802DF0F0; // type:function size:0x10 fn_802DF100 = .text:0x802DF100; // type:function size:0xA0 fn_802DF1A0 = .text:0x802DF1A0; // type:function size:0x48 @@ -22143,7 +22143,7 @@ fn_803B3490 = .text:0x803B3490; // type:function size:0x8 fn_803B34A0 = .text:0x803B34A0; // type:function size:0x198 fn_803B3640 = .text:0x803B3640; // type:function size:0x80C VISetPreRetraceCallback = .text:0x803B3E50; // type:function size:0x44 -fn_803B3EA0 = .text:0x803B3EA0; // type:function size:0x44 +VISetPostRetraceCallback = .text:0x803B3EA0; // type:function size:0x44 fn_803B3EF0 = .text:0x803B3EF0; // type:function size:0x118 fn_803B4010 = .text:0x803B4010; // type:function size:0x200 VIInit = .text:0x803B4210; // type:function size:0x548 @@ -24182,7 +24182,7 @@ XStrToU32___Q24nw4r2dbFPCUc = .text:0x80436D20; // type:function size:0xCC CopySymbol___Q24nw4r2dbFPCUcPUcUlUc = .text:0x80436DF0; // type:function size:0x2DC QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl = .text:0x804370D0; // type:function size:0xD8 QuerySymbolToSingleMapFile___Q24nw4r2dbFPQ34nw4r2db7MapFileUlPUcUl = .text:0x804371B0; // type:function size:0xF8 -MapFile_QuerySymbol__Q24nw4r2dbFUlPUcUl = .text:0x804372B0; // type:function size:0x104 +MapFile_QuerySymbol__Q24nw4r2dbFPvPcUi = .text:0x804372B0; // type:function size:0x104 Assertion_SetConsole__Q24nw4r2dbFPQ44nw4r2db6detail11ConsoleHead = .text:0x804373C0; // type:function size:0x10 FExp__Q34nw4r4math6detailFf = .text:0x804373D0; // type:function size:0xAC FLog__Q34nw4r4math6detailFf = .text:0x80437480; // type:function size:0xA4 @@ -26394,15 +26394,15 @@ normalise__Q23EGG8Vector3fFv = .text:0x8049BCC0; // type:function size:0x84 setLength__Q23EGG8Vector3fFRCQ23EGG8Vector3ff = .text:0x8049BD50; // type:function size:0xB8 setLength__Q23EGG8Vector3fFf = .text:0x8049BE10; // type:function size:0xA0 __sinit_\eggVector_cpp = .text:0x8049BEB0; // type:function size:0xE0 scope:local -egg_assert_waittime = .text:0x8049BF90; // type:function size:0x78 -egg_assert_vreport = .text:0x8049C010; // type:function size:0x4 -egg_assert_report = .text:0x8049C020; // type:function size:0x80 -egg_assert_get_file_name = .text:0x8049C0A0; // type:function size:0x54 -egg_assert_querySymbol = .text:0x8049C100; // type:function size:0x44 -egg_assert_isOutsideMEM1 = .text:0x8049C150; // type:function size:0x2C -egg_assert_set_callback = .text:0x8049C180; // type:function size:0x10 -egg_assert_halt = .text:0x8049C190; // type:function size:0x398 -egg_assert_assert = .text:0x8049C530; // type:function size:0x8C +wait__Q23EGG6AssertFUi = .text:0x8049BF90; // type:function size:0x78 +system_vreport__Q23EGG6AssertFPCcP16__va_list_struct = .text:0x8049C010; // type:function size:0x4 +system_report__Q23EGG6AssertFPCce = .text:0x8049C020; // type:function size:0x80 +getPeriodPos__Q23EGG6AssertFPCc = .text:0x8049C0A0; // type:function size:0x54 +getMapSymbol__Q23EGG6AssertFPv = .text:0x8049C100; // type:function size:0x44 +isOutsideMEM1__Q23EGG6AssertFUi = .text:0x8049C150; // type:function size:0x2C +setAssertCallback__Q23EGG6AssertFPFv_v = .text:0x8049C180; // type:function size:0x10 +system_halt__Q23EGG6AssertFPCcUiPCcP16__va_list_struct = .text:0x8049C190; // type:function size:0x398 +assert__Q23EGG6AssertFPCcUiPCce = .text:0x8049C530; // type:function size:0x8C FUN_8049c5c0 = .text:0x8049C5C0; // type:function size:0x10 FUN_8049c5d0 = .text:0x8049C5D0; // type:function size:0x50 FUN_8049c620 = .text:0x8049C620; // type:function size:0x44 @@ -40910,7 +40910,7 @@ zero__Q23EGG8Vector3s = .sbss:0x805767D8; // type:object size:0x6 data:2byte ex__Q23EGG8Vector3s = .sbss:0x805767E0; // type:object size:0x6 data:2byte ey__Q23EGG8Vector3s = .sbss:0x805767E8; // type:object size:0x6 data:2byte ez__Q23EGG8Vector3s = .sbss:0x805767F0; // type:object size:0x6 data:2byte -lbl_805767F8 = .sbss:0x805767F8; // type:object size:0x4 data:4byte +sAssertCallback__Q23EGG6Assert = .sbss:0x805767F8; // type:object size:0x4 data:4byte lbl_805767FC = .sbss:0x805767FC; // type:object size:0x4 data:4byte lbl_80576800 = .sbss:0x80576800; // type:object size:0x4 data:4byte lbl_80576804 = .sbss:0x80576804; // type:object size:0x1 data:byte diff --git a/include/Runtime.PPCEABI.H/__va_arg.h b/include/Runtime.PPCEABI.H/__va_arg.h index d3600d51..445bb985 100644 --- a/include/Runtime.PPCEABI.H/__va_arg.h +++ b/include/Runtime.PPCEABI.H/__va_arg.h @@ -36,5 +36,6 @@ void *__va_arg(_va_list_struct *, int); #define __va_end(list) ((void)0) #define __va_copy(a, b) (*(a) = *(b)) +#define va_copy __va_copy #endif /* __VA_ARG_H */ diff --git a/include/egg/prim/eggAssert.h b/include/egg/prim/eggAssert.h index 0910f203..147847b9 100644 --- a/include/egg/prim/eggAssert.h +++ b/include/egg/prim/eggAssert.h @@ -8,14 +8,17 @@ namespace EGG { // TODO: Fixup funtions namespace Assert { +typedef void (*AssertCallback)(); + /* 8049bf90 */ void wait(u32 time); -/* 8049c010 */ void system_print(); -/* 8049c010 */ void system_report(); -/* 8049c0a0 */ s32 getPeriodPos(char *); +/* 8049c010 */ void system_vreport(const char *str, va_list list); +/* 8049c010 */ void system_report(const char *str, ...); +/* 8049c0a0 */ s32 getPeriodPos(const char *); /* 8049c100 */ char *getMapSymbol(); /* 8049c150 */ bool isOutsideMEM1(u32 addr); -/* 8049c190 */ void system_halt(); -/* 8049c530 */ void assert(); +/* 8049c180 */ AssertCallback setAssertCallback(AssertCallback cb); +/* 8049c190 */ void system_halt(const char *file, u32 line, const char *msg, va_list list); +/* 8049c530 */ void assert(const char *file, u32 line, const char *msg, ...); } // namespace Assert diff --git a/include/rvl/OS/OSError.h b/include/rvl/OS/OSError.h index 64ce47e1..aa57db79 100644 --- a/include/rvl/OS/OSError.h +++ b/include/rvl/OS/OSError.h @@ -41,6 +41,7 @@ extern OSErrorHandler __OSErrorTable[OS_ERR_MAX]; extern u32 __OSFpscrEnableBits; DECL_WEAK void OSReport(const char *msg, ...); +DECL_WEAK void OSVReport(const char *msg, va_list args); DECL_WEAK void OSPanic(const char *file, int line, const char *msg, ...); OSErrorHandler OSSetErrorHandler(u16 error, OSErrorHandler handler); diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp new file mode 100644 index 00000000..25c45a3d --- /dev/null +++ b/src/egg/prim/eggAssert.cpp @@ -0,0 +1,205 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace nw4r { +namespace db { +// TODO +extern s32 MapFile_QuerySymbol(void *arg, char *buf, u32 buf_size); +} // namespace db +} // namespace nw4r + +namespace EGG { + +namespace Assert { + +AssertCallback sAssertCallback; +AssertCallback sAssertCallback2; +u32 sPtrOverride; +bool sInstantHalt; +bool sAssertOccurred; + +/* 8049bf90 */ void wait(u32 time) { + u32 tick = OSGetTick(); + u32 tick2; + do { + tick2 = OSGetTick(); + } while ((tick2 - tick) / (OS_BUS_CLOCK_SPEED / 4 / 1000) < time); +} + +// extern "C" void OSVReport(const char *str, va_list list); + +/* 8049c010 */ void system_vreport(const char *str, va_list list) { + OSVReport(str, list); +} +/* 8049c010 */ void system_report(const char *str, ...) { + va_list l; + va_start(l, str); + system_vreport(str, l); + va_end(l); +} +/* 8049c0a0 */ s32 getPeriodPos(const char *str) { + char *b = strchr(str, '.'); + s32 len; + if (b == nullptr) { + len = strlen(str); + } else { + len = b - str; + } + + if (len > 0xff) { + return 0xff; + } + return len; +} + +/* 80674c60 */ char buf[260]; + +/* 8049c100 */ const char *getMapSymbol(void *arg) { + u32 success = nw4r::db::MapFile_QuerySymbol(arg, buf, sizeof(buf)); + return success ? buf : nullptr; +} + +/* 8049c150 */ bool isOutsideMEM1(u32 addr) { + // TODO + if (0x80000000 <= addr) { + if (addr <= 0x83000000 - 1) { + return false; + } + } + + return true; +} + +/* 8049c180 */ AssertCallback setAssertCallback(AssertCallback cb) { + AssertCallback old = sAssertCallback; + sAssertCallback = cb; + return old; +} + +/* 8049c190 */ void system_halt(const char *file, u32 line, const char *msg, va_list list) { + if (sAssertOccurred) { +#line 152 + OSError("Recursive assertioned"); + } + + sAssertOccurred = true; + if (sAssertCallback != nullptr) { + sAssertCallback(); + } + VISetPreRetraceCallback(nullptr); + VISetPostRetraceCallback(nullptr); + system_report("\n---------- HALT -------------\n"); + s32 pos = getPeriodPos(file); + system_report("%.*s(%d):", pos, file, line); + va_list args; + va_copy(args, list); + system_vreport(msg, args); + system_report("\n"); + u32 *stackp = (u32 *)OSGetStackPointer(); + if (sPtrOverride != 0) { + stackp = (u32*)((u32*)sPtrOverride)[1]; + } + u32 *stack = stackp; + + s32 num = 0; + for (s32 num = 0; num < 0x1e; num++) { + if (isOutsideMEM1((u32)stack)) { + break; + } + const char *sym = getMapSymbol((void *)stack[1]); + if (sym != nullptr) { + system_report("%d: %s", num, sym); + } else { + system_report("%d: %p", num, stack[1]); + } + stack = (u32*)stack[0]; + if (isOutsideMEM1((u32)stack)) { + break; + } + } + + if (sInstantHalt == 0) { + VISetBlack(false); + VIFlush(); + nw4r::db::DirectPrint_Init(); + nw4r::db::detail::DirectPrint_SetupFB(0); + Xfb *fb = BaseSystem::mConfigData->getXfbMgr()->mToShowXfb; + if (fb == nullptr) { + fb = BaseSystem::mConfigData->getXfbMgr()->mNextXfb; + } + + if (fb == nullptr) { +#line 239 + OSError("Program Halt"); + } + + // TODO this isn't optimized out? + void *buf = (void *)0x43300000; + nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight); + nw4r::db::DirectPrint_StoreCache(); + OSDisableInterrupts(); + OSDisableScheduler(); + OSEnableInterrupts(); + while (true) { + nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight); + nw4r::db::DirectPrint_StoreCache(); + nw4r::db::DirectPrint_Printf(2, 2, "%.*s:%d", pos, file, line); + va_list args; + va_copy(args, list); + nw4r::db::DirectPrint_printfsub(2, 0xe, msg, args); + nw4r::db::DirectPrint_StoreCache(); + + // TODO instshuffle + s32 line = 0x1a; + u32 *stack = stackp; + + for (s32 counter = 0; counter < 0x10; counter++) { + if (isOutsideMEM1((u32)stack)) { + break; + } + const char *sym = getMapSymbol((void*)stack[1]); + if (sym != nullptr) { + nw4r::db::DirectPrint_Printf(2, line, "%d:%s\n", counter, sym); + } else { + nw4r::db::DirectPrint_Printf(2, line, "LR Save[%d]:%p\n", counter, (void*)stack[1]); + } + nw4r::db::DirectPrint_StoreCache(); + stack = (u32*)*stack; + if (isOutsideMEM1((u32)stack)) { + break; + } + line += 0xc; + } + nw4r::db::DirectPrint_StoreCache(); + wait(4000); + if (sAssertCallback2 == nullptr) { + goto end; + } + nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight); + (sAssertCallback2)(); + nw4r::db::DirectPrint_StoreCache(); + wait(4000); + } + } +end: +#line 315 + OSError("Program Halt"); + return; +} +/* 8049c530 */ void assert(const char *file, u32 line, const char *msg, ...) { + va_list l; + va_start(l, msg); + system_halt(file, line, msg, l); + va_end(l); +} + +} // namespace Assert + +} // namespace EGG From 0b2695b30a9819e4fa037c3a91c7cd0fe3fb8f30 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 00:21:45 +0200 Subject: [PATCH 05/11] .sdata --- config/SOUE01/splits.txt | 1 + src/egg/prim/eggAssert.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index f798c940..95d053ff 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -419,6 +419,7 @@ egg/math/eggVector.cpp: egg/prim/eggAssert.cpp: .text start:0x8049BF90 end:0x8049C5BC .data start:0x8056EC88 end:0x8056ED00 + .sdata start:0x80574EF0 end:0x80574F18 .sbss start:0x805767F8 end:0x80576808 .bss start:0x80674C60 end:0x80674D68 diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp index 25c45a3d..aceee618 100644 --- a/src/egg/prim/eggAssert.cpp +++ b/src/egg/prim/eggAssert.cpp @@ -115,9 +115,9 @@ bool sAssertOccurred; } const char *sym = getMapSymbol((void *)stack[1]); if (sym != nullptr) { - system_report("%d: %s", num, sym); + system_report("%d: %s\n", num, sym); } else { - system_report("%d: %p", num, stack[1]); + system_report("%d: %p\n", num, stack[1]); } stack = (u32*)stack[0]; if (isOutsideMEM1((u32)stack)) { From 3801ad8bb15f64308fc73c38cbbf5107806ba131 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 00:25:39 +0200 Subject: [PATCH 06/11] Fix build --- include/rvl/OS/OSError.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rvl/OS/OSError.h b/include/rvl/OS/OSError.h index aa57db79..ac9ece4b 100644 --- a/include/rvl/OS/OSError.h +++ b/include/rvl/OS/OSError.h @@ -1,6 +1,7 @@ #ifndef RVL_SDK_OS_ERROR_H #define RVL_SDK_OS_ERROR_H #include +#include #ifdef __cplusplus extern "C" { #endif From 6515359fac56649501250de3287dde0d5907b3b2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 00:33:21 +0200 Subject: [PATCH 07/11] Identify float conversion --- src/egg/prim/eggAssert.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp index aceee618..2afd3b96 100644 --- a/src/egg/prim/eggAssert.cpp +++ b/src/egg/prim/eggAssert.cpp @@ -140,8 +140,8 @@ bool sAssertOccurred; OSError("Program Halt"); } - // TODO this isn't optimized out? - void *buf = (void *)0x43300000; + // Random float conversion here for no reason + f32 wid = fb->mWidth; nw4r::db::DirectPrint_EraseXfb(0, 0, fb->mWidth, fb->mHeight); nw4r::db::DirectPrint_StoreCache(); OSDisableInterrupts(); From 141fd65621ecf76136b97a60f7abdeb13c2a89aa Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 00:43:30 +0200 Subject: [PATCH 08/11] Solve instshuffle --- src/egg/prim/eggAssert.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp index 2afd3b96..e6bbe277 100644 --- a/src/egg/prim/eggAssert.cpp +++ b/src/egg/prim/eggAssert.cpp @@ -156,11 +156,11 @@ bool sAssertOccurred; nw4r::db::DirectPrint_printfsub(2, 0xe, msg, args); nw4r::db::DirectPrint_StoreCache(); - // TODO instshuffle - s32 line = 0x1a; + s32 line; u32 *stack = stackp; + s32 counter; - for (s32 counter = 0; counter < 0x10; counter++) { + for (counter = 0, line = 0x1a; counter < 0x10; counter++) { if (isOutsideMEM1((u32)stack)) { break; } From 025bcfa4bbb72edfa5afa8383c3521fcc64ab0a4 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 6 May 2024 01:08:02 +0200 Subject: [PATCH 09/11] Final match --- config/SOUE01/symbols.txt | 13 +++++++++---- configure.py | 2 +- src/egg/prim/eggAssert.cpp | 9 +++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index a7406ec4..5e276c51 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -37119,7 +37119,12 @@ lbl_8056EC08 = .data:0x8056EC08; // type:object size:0x1C lbl_8056EC24 = .data:0x8056EC24; // type:object size:0x1C lbl_8056EC40 = .data:0x8056EC40; // type:object size:0x10 lbl_8056EC50 = .data:0x8056EC50; // type:object size:0x38 -lbl_8056EC88 = .data:0x8056EC88; // type:object size:0x78 +lbl_8056EC88 = .data:0x8056EC88; // type:object size:0xE data:string +lbl_8056EC98 = .data:0x8056EC98; // type:object size:0x16 data:string +lbl_8056ECB0 = .data:0x8056ECB0; // type:object size:0x20 data:string +lbl_8056ECD0 = .data:0x8056ECD0; // type:object size:0xA data:string +lbl_8056ECDC = .data:0x8056ECDC; // type:object size:0xD data:string +lbl_8056ECF0 = .data:0x8056ECF0; // type:object size:0x10 data:string lbl_8056ED00 = .data:0x8056ED00; // type:object size:0x30 lbl_8056ED30 = .data:0x8056ED30; // type:object size:0x30 lbl_8056ED60 = .data:0x8056ED60; // type:object size:0x10 @@ -39587,11 +39592,11 @@ lbl_80574ED0 = .sdata:0x80574ED0; // type:object size:0x8 data:byte lbl_80574ED8 = .sdata:0x80574ED8; // type:object size:0x8 lbl_80574EE0 = .sdata:0x80574EE0; // type:object size:0x8 lbl_80574EE8 = .sdata:0x80574EE8; // type:object size:0x8 data:4byte -lbl_80574EF0 = .sdata:0x80574EF0; // type:object size:0x8 +lbl_80574EF0 = .sdata:0x80574EF0; // type:object size:0x2 data:string lbl_80574EF8 = .sdata:0x80574EF8; // type:object size:0x8 data:string lbl_80574F00 = .sdata:0x80574F00; // type:object size:0x8 data:string lbl_80574F08 = .sdata:0x80574F08; // type:object size:0x8 data:string -lbl_80574F10 = .sdata:0x80574F10; // type:object size:0x8 +lbl_80574F10 = .sdata:0x80574F10; // type:object size:0x7 data:string lbl_80574F18 = .sdata:0x80574F18; // type:object size:0x8 data:4byte lbl_80574F20 = .sdata:0x80574F20; // type:object size:0x8 lbl_80574F28 = .sdata:0x80574F28; // type:object size:0x4 @@ -49355,7 +49360,7 @@ zero__Q23EGG8Vector3f = .bss:0x80674C30; // type:object size:0xC data:float ex__Q23EGG8Vector3f = .bss:0x80674C3C; // type:object size:0xC data:float ey__Q23EGG8Vector3f = .bss:0x80674C48; // type:object size:0xC data:float ez__Q23EGG8Vector3f = .bss:0x80674C54; // type:object size:0xC data:float -lbl_80674C60 = .bss:0x80674C60; // type:object size:0x108 +buf__Q23EGG6Assert = .bss:0x80674C60; // type:object size:0x108 lbl_80674D68 = .bss:0x80674D68; // type:object size:0x90 lbl_80674DF8 = .bss:0x80674DF8; // type:object size:0x30 data:float lbl_80674E28 = .bss:0x80674E28; // type:object size:0x20 diff --git a/configure.py b/configure.py index 3123135c..8de8e3e1 100644 --- a/configure.py +++ b/configure.py @@ -385,7 +385,7 @@ config.libs = [ EGGLib( "prim", [ - Object(NonMatching, "egg/prim/eggAssert.cpp"), + Object(Matching, "egg/prim/eggAssert.cpp"), ], ), # { diff --git a/src/egg/prim/eggAssert.cpp b/src/egg/prim/eggAssert.cpp index e6bbe277..dc9e44a3 100644 --- a/src/egg/prim/eggAssert.cpp +++ b/src/egg/prim/eggAssert.cpp @@ -67,14 +67,11 @@ bool sAssertOccurred; } /* 8049c150 */ bool isOutsideMEM1(u32 addr) { - // TODO - if (0x80000000 <= addr) { - if (addr <= 0x83000000 - 1) { - return false; - } + if (!(0x80000000 <= addr) || !(addr <= 0x83000000 - 1)) { + return true; } - return true; + return false; } /* 8049c180 */ AssertCallback setAssertCallback(AssertCallback cb) { From 727482b4d64b53d4a272909e5695693875c4e887 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 12 May 2024 12:23:22 +0200 Subject: [PATCH 10/11] m_angle --- config/SOUE01/splits.txt | 5 +++++ config/SOUE01/symbols.txt | 6 +++--- configure.py | 1 + include/m/m_angle.h | 11 +++++++++-- src/m/m_angle.cpp | 30 ++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/m/m_angle.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 4973c05f..09ef2ec0 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -208,6 +208,11 @@ f/f_manager.cpp: .sbss start:0x80575BB8 end:0x80575BC0 .bss start:0x805B84D8 end:0x805B8588 +m/m_angle.cpp: + .text start:0x802EE5F0 end:0x802EE6B8 + .ctors start:0x804DB8CC end:0x804DB8D0 + .sbss start:0x80575C08 end:0x80575C10 + m/m_heap.cpp: .text start:0x802F0F00 end:0x802F1660 .rodata start:0x804F0570 end:0x804F0580 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index f3114665..3fc7ae62 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17710,8 +17710,8 @@ fn_802EE4A0 = .text:0x802EE4A0; // type:function size:0x70 fn_802EE510 = .text:0x802EE510; // type:function size:0x4C adjustFrmHeapRestoreCurrent__16mHeapAllocator_cFv = .text:0x802EE560; // type:function size:0x64 fn_802EE5D0 = .text:0x802EE5D0; // type:function size:0x1C -fn_802EE5F0 = .text:0x802EE5F0; // type:function size:0xA4 -fn_802EE6A0 = .text:0x802EE6A0; // type:function size:0x18 +step__4mAngFsiss = .text:0x802EE5F0; // type:function size:0xA4 +__sinit_\m_angle_cpp = .text:0x802EE6A0; // type:function size:0x18 scope:local fn_802EE6C0 = .text:0x802EE6C0; // type:function size:0x114 fn_802EE7E0 = .text:0x802EE7E0; // type:function size:0x44 fn_802EE830 = .text:0x802EE830; // type:function size:0x58 @@ -40251,7 +40251,7 @@ lbl_80575BF4 = .sbss:0x80575BF4; // type:object size:0x4 data:4byte lbl_80575BF8 = .sbss:0x80575BF8; // type:object size:0x4 data:4byte lbl_80575BFC = .sbss:0x80575BFC; // type:object size:0x1 data:byte lbl_80575C00 = .sbss:0x80575C00; // type:object size:0x8 data:4byte -lbl_80575C08 = .sbss:0x80575C08; // type:object size:0x8 data:2byte +ZERO__7mAng3_c = .sbss:0x80575C08; // type:object size:0x6 data:2byte lbl_80575C10 = .sbss:0x80575C10; // type:object size:0x4 data:4byte lbl_80575C14 = .sbss:0x80575C14; // type:object size:0x4 data:4byte lbl_80575C18 = .sbss:0x80575C18; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 3123135c..01492c45 100644 --- a/configure.py +++ b/configure.py @@ -300,6 +300,7 @@ config.libs = [ Object(NonMatching, "f/f_base.cpp"), Object(Matching, "f/f_list.cpp"), Object(Matching, "f/f_manager.cpp"), + Object(Matching, "m/m_angle.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), # framework (f_name) diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 29a20d18..7b3a8ea1 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -5,18 +5,25 @@ struct mAng { mAng() {} - mAng(s16 s) : val(s) {} - s16 val; + mAng(s16 s) : mVal(s) {} + + s32 step(s16 target, s32 steps, s16 max, s16 min); + + s16 mVal; }; class mAng3_c { public: s16 x, y, z; + mAng3_c(s16 fx, s16 fy, s16 fz): x(fx), y(fy), z(fz) {} + void set(s16 fx, s16 fy, s16 fz) { x = fx; y = fy; z = fz; } + + static mAng3_c ZERO; }; #endif diff --git a/src/m/m_angle.cpp b/src/m/m_angle.cpp new file mode 100644 index 00000000..2940ed9f --- /dev/null +++ b/src/m/m_angle.cpp @@ -0,0 +1,30 @@ +#include + +/** 80575c08 */ +mAng3_c mAng3_c::ZERO = mAng3_c::mAng3_c(0, 0, 0); + +/** 802ee5f0 */ +s32 mAng::step(s16 target, s32 steps, s16 max, s16 min) { + if (mVal != target) { + int stepSize; + int diff = target - mVal; + stepSize = diff / steps; + if (stepSize > min || stepSize < -min) { + mVal += stepSize < -max ? -max : stepSize > max ? max : stepSize; + } else if (diff >= 0) { + if (mVal + min >= target) { + mVal = target; + } else { + mVal += min; + } + } else { + if (mVal - min <= target) { + mVal = target; + } else { + mVal -= min; + } + } + } + + return target - mVal; +} From 3e76db8b16a3034f0cbe3290ed0f2d42ef44f472 Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 12 May 2024 12:45:45 -0400 Subject: [PATCH 11/11] mAng3_c Zero symbol known from NSMBW --- config/SOUE01/symbols.txt | 2 +- include/m/m_angle.h | 4 ++-- src/m/m_angle.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 3fc7ae62..f5a96a71 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -40251,7 +40251,7 @@ lbl_80575BF4 = .sbss:0x80575BF4; // type:object size:0x4 data:4byte lbl_80575BF8 = .sbss:0x80575BF8; // type:object size:0x4 data:4byte lbl_80575BFC = .sbss:0x80575BFC; // type:object size:0x1 data:byte lbl_80575C00 = .sbss:0x80575C00; // type:object size:0x8 data:4byte -ZERO__7mAng3_c = .sbss:0x80575C08; // type:object size:0x6 data:2byte +Zero__7mAng3_c = .sbss:0x80575C08; // type:object size:0x6 data:2byte lbl_80575C10 = .sbss:0x80575C10; // type:object size:0x4 data:4byte lbl_80575C14 = .sbss:0x80575C14; // type:object size:0x4 data:4byte lbl_80575C18 = .sbss:0x80575C18; // type:object size:0x4 data:4byte diff --git a/include/m/m_angle.h b/include/m/m_angle.h index 7b3a8ea1..37fca394 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -15,7 +15,7 @@ struct mAng { class mAng3_c { public: s16 x, y, z; - mAng3_c(s16 fx, s16 fy, s16 fz): x(fx), y(fy), z(fz) {} + mAng3_c(s16 fx, s16 fy, s16 fz) : x(fx), y(fy), z(fz) {} void set(s16 fx, s16 fy, s16 fz) { x = fx; @@ -23,7 +23,7 @@ public: z = fz; } - static mAng3_c ZERO; + static mAng3_c Zero; }; #endif diff --git a/src/m/m_angle.cpp b/src/m/m_angle.cpp index 2940ed9f..a9e9474f 100644 --- a/src/m/m_angle.cpp +++ b/src/m/m_angle.cpp @@ -1,7 +1,7 @@ #include /** 80575c08 */ -mAng3_c mAng3_c::ZERO = mAng3_c::mAng3_c(0, 0, 0); +mAng3_c mAng3_c::Zero = mAng3_c::mAng3_c(0, 0, 0); /** 802ee5f0 */ s32 mAng::step(s16 target, s32 steps, s16 max, s16 min) {