From 46f664de1a73624453a3c233242c5938cee6c89c Mon Sep 17 00:00:00 2001 From: robojumper Date: Sun, 5 May 2024 20:13:43 +0200 Subject: [PATCH 1/2] eggXfbManager match --- config/SOUE01/symbols.txt | 2 +- configure.py | 2 +- include/rvl/GX/GXFrameBuf.h | 1 + src/egg/core/eggXfbManager.cpp | 108 +++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/egg/core/eggXfbManager.cpp diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 97c2c8d9..9c639652 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26305,7 +26305,7 @@ getStandardRenderModeObj__Q23EGG5VideoFPCQ33EGG5Video16RenderModeObjSet = .text: init__Q23EGG3XfbFUsUsPQ23EGG4Heap = .text:0x804989E0; // type:function size:0x74 __ct__Q23EGG3XfbFPQ23EGG4Heap = .text:0x80498A60; // type:function size:0x64 calcBufferSize__Q23EGG3XfbFUsUs = .text:0x80498AD0; // type:function size:0x14 -isRegisterd__Q23EGG10XfbManagerCFRQ23EGG3Xfb = .text:0x80498AF0; // type:function size:0x34 +isRegisterd__Q23EGG10XfbManagerCFPQ23EGG3Xfb = .text:0x80498AF0; // type:function size:0x34 attach__Q23EGG10XfbManagerFPQ23EGG3Xfb = .text:0x80498B30; // type:function size:0xE0 copyEFB__Q23EGG10XfbManagerFb = .text:0x80498C10; // type:function size:0xE8 setNextFrameBuffer__Q23EGG10XfbManagerFv = .text:0x80498D00; // type:function size:0x120 diff --git a/configure.py b/configure.py index 0b81b4bf..43f4fc56 100644 --- a/configure.py +++ b/configure.py @@ -368,7 +368,7 @@ config.libs = [ Object(Matching, "egg/core/eggXfb.cpp"), Object(Matching, "egg/core/eggVideo.cpp"), Object(Matching, "egg/core/eggXfb.cpp"), - Object(NonMatching, "egg/core/eggXfbManager.cpp"), + Object(Matching, "egg/core/eggXfbManager.cpp"), Object(NonMatching, "egg/core/eggGraphicsFifo.cpp"), Object(NonMatching, "egg/core/eggController.cpp"), ], diff --git a/include/rvl/GX/GXFrameBuf.h b/include/rvl/GX/GXFrameBuf.h index f21de91f..7e8592b5 100644 --- a/include/rvl/GX/GXFrameBuf.h +++ b/include/rvl/GX/GXFrameBuf.h @@ -28,6 +28,7 @@ f32 GXGetYScaleFactor(u16 height, u16 width); u16 GXGetNumXfbLines(u16 height, f32 scale); void GXSetDispCopyDst(u16 width, u16 height); u32 GXSetDispCopyYScale(f32 scale); +void GXCopyDisp(void *data, GXBool bUpdate); extern GXRenderModeObj GXNtsc480IntDf; extern GXRenderModeObj GXMpal480IntDf; diff --git a/src/egg/core/eggXfbManager.cpp b/src/egg/core/eggXfbManager.cpp new file mode 100644 index 00000000..70e1e8a2 --- /dev/null +++ b/src/egg/core/eggXfbManager.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +namespace EGG { + +/* 80498af0 */ bool XfbManager::isRegisterd(Xfb *xfb) const { + Xfb *x = mNextXfb; + Xfb *iter = x; + + if (mNextXfb != nullptr) { + do { + if (iter == xfb) { + return true; + } + iter = iter->mNext; + } while (iter != x); + } + return false; +} + +/* 80498b30 */ bool XfbManager::attach(Xfb *xfb) { + int interrupts = OSDisableInterrupts(); + bool u3 = 0; + + if (xfb != nullptr && !isRegisterd(xfb)) { + xfb->mState = Xfb::XFB_UNPROCESSED; + if (mNextXfb == nullptr) { + mNextXfb = xfb; + mToCopyXfb = xfb; + xfb->mNext = xfb; + xfb->mPrev = xfb; + } else { + mNextXfb->mPrev->mNext = xfb; + xfb->mPrev = mNextXfb->mPrev; + mNextXfb->mPrev = xfb; + xfb->mNext = mNextXfb; + } + u3 = 1; + mNumXfbs += 1; + mNumXfbs_Copy += 1; + } + OSRestoreInterrupts(interrupts); + return u3; +} +/* 80498c10 */ void XfbManager::copyEFB(bool bUpdate) { + if (mNumXfbs == 1 && mToCopyXfb == nullptr) { + mToCopyXfb = mNextXfb; + } + + if (mToCopyXfb != nullptr) { + if (bUpdate) { + GXSetZMode(true, GX_ALWAYS, true); + GXSetAlphaUpdate(true); + GXSetColorUpdate(true); + } + + GXCopyDisp(mToCopyXfb->mBuffer, bUpdate); + + GXFlush(); + GXDrawDone(); + u32 interrupts = OSDisableInterrupts(); + mToCopyXfb->mState = Xfb::XFB_COPIED; + if (mToShowXfb == nullptr) { + mToShowXfb = mToCopyXfb; + } + + Xfb *next = mToCopyXfb->mNext->mState == Xfb::XFB_UNPROCESSED ? mToCopyXfb->mNext : nullptr; + mToCopyXfb = next; + OSRestoreInterrupts(interrupts); + } +} + +/* 80498d00 */ void XfbManager::setNextFrameBuffer() { + if (mToShowXfb != nullptr) { + if (mNumXfbs_Copy > 2) { + mNumXfbs_Copy -= 1; + } else { + VISetNextFrameBuffer(mToShowXfb->mBuffer); + VIFlush(); + nw4r::db::DirectPrint_ChangeXfb(mToShowXfb->mBuffer, mToShowXfb->mWidth, mToShowXfb->mHeight); + if (mNumXfbs > 1) { + mNextXfb->mState = Xfb::XFB_UNPROCESSED; + if (mToCopyXfb == nullptr) { + mToCopyXfb = mNextXfb; + } + mToShowXfb->mState = Xfb::XFB_SHOWN; + mNextXfb = mToShowXfb; + mToShowXfb = mToShowXfb->mNext->mState == Xfb::XFB_COPIED ? mToShowXfb->mNext : nullptr; + } else { + mToShowXfb->mState = Xfb::XFB_UNPROCESSED; + if (mToCopyXfb == nullptr) { + mToCopyXfb = mToShowXfb; + } + mToShowXfb = nullptr; + } + } + } else { + if (mNumXfbs == 1 && mNextXfb != nullptr) { + mNextXfb->mState = Xfb::XFB_UNPROCESSED; + mToCopyXfb = mNextXfb; + } + } +} + +} // namespace EGG From 477f6da6cdd5051fc2d1be98cbe0ef366c33822d Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 12 May 2024 12:58:59 -0400 Subject: [PATCH 2/2] Fix symbol for isRegisterd. (from NSMBW map) --- config/SOUE01/symbols.txt | 2 +- include/egg/core/eggXfbManager.h | 2 +- src/egg/core/eggXfbManager.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 9c639652..97c2c8d9 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -26305,7 +26305,7 @@ getStandardRenderModeObj__Q23EGG5VideoFPCQ33EGG5Video16RenderModeObjSet = .text: init__Q23EGG3XfbFUsUsPQ23EGG4Heap = .text:0x804989E0; // type:function size:0x74 __ct__Q23EGG3XfbFPQ23EGG4Heap = .text:0x80498A60; // type:function size:0x64 calcBufferSize__Q23EGG3XfbFUsUs = .text:0x80498AD0; // type:function size:0x14 -isRegisterd__Q23EGG10XfbManagerCFPQ23EGG3Xfb = .text:0x80498AF0; // type:function size:0x34 +isRegisterd__Q23EGG10XfbManagerCFRQ23EGG3Xfb = .text:0x80498AF0; // type:function size:0x34 attach__Q23EGG10XfbManagerFPQ23EGG3Xfb = .text:0x80498B30; // type:function size:0xE0 copyEFB__Q23EGG10XfbManagerFb = .text:0x80498C10; // type:function size:0xE8 setNextFrameBuffer__Q23EGG10XfbManagerFv = .text:0x80498D00; // type:function size:0x120 diff --git a/include/egg/core/eggXfbManager.h b/include/egg/core/eggXfbManager.h index a0895d85..948b0349 100644 --- a/include/egg/core/eggXfbManager.h +++ b/include/egg/core/eggXfbManager.h @@ -14,7 +14,7 @@ public: /* 0xC */ u8 mNumXfbs; // Total number of Xfbs ever attached /* 0xD */ u8 mNumXfbs_Copy; // Unsure of purpose yet, but showing wont proceed until its under 3 public: - /* 80498af0 */ bool isRegisterd(Xfb *xfb) const; // yes. this is correct spelling + /* 80498af0 */ bool isRegisterd(Xfb &xfb) const; // yes. this is correct spelling /* 80498b30 */ bool attach(Xfb *xfb); /* 80498c10 */ void copyEFB(bool); /* 80498d00 */ void setNextFrameBuffer(); diff --git a/src/egg/core/eggXfbManager.cpp b/src/egg/core/eggXfbManager.cpp index 70e1e8a2..46ab8d2a 100644 --- a/src/egg/core/eggXfbManager.cpp +++ b/src/egg/core/eggXfbManager.cpp @@ -6,13 +6,13 @@ namespace EGG { -/* 80498af0 */ bool XfbManager::isRegisterd(Xfb *xfb) const { +/* 80498af0 */ bool XfbManager::isRegisterd(Xfb &xfb) const { Xfb *x = mNextXfb; Xfb *iter = x; if (mNextXfb != nullptr) { do { - if (iter == xfb) { + if (iter == &xfb) { return true; } iter = iter->mNext; @@ -25,7 +25,7 @@ namespace EGG { int interrupts = OSDisableInterrupts(); bool u3 = 0; - if (xfb != nullptr && !isRegisterd(xfb)) { + if (xfb != nullptr && !isRegisterd(*xfb)) { xfb->mState = Xfb::XFB_UNPROCESSED; if (mNextXfb == nullptr) { mNextXfb = xfb;