diff --git a/asm/JSystem/JUtility/JUTGraphFifo/__ct__12JUTGraphFifoFUl.s b/asm/JSystem/JUtility/JUTGraphFifo/__ct__12JUTGraphFifoFUl.s deleted file mode 100644 index c96c2ca71a..0000000000 --- a/asm/JSystem/JUtility/JUTGraphFifo/__ct__12JUTGraphFifoFUl.s +++ /dev/null @@ -1,58 +0,0 @@ -lbl_802DEB58: -/* 802DEB58 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 802DEB5C 7C 08 02 A6 */ mflr r0 -/* 802DEB60 90 01 00 14 */ stw r0, 0x14(r1) -/* 802DEB64 93 E1 00 0C */ stw r31, 0xc(r1) -/* 802DEB68 7C 7F 1B 78 */ mr r31, r3 -/* 802DEB6C 3C 60 80 3D */ lis r3, __vt__12JUTGraphFifo@ha /* 0x803CC590@ha */ -/* 802DEB70 38 03 C5 90 */ addi r0, r3, __vt__12JUTGraphFifo@l /* 0x803CC590@l */ -/* 802DEB74 90 1F 00 00 */ stw r0, 0(r31) -/* 802DEB78 38 04 00 1F */ addi r0, r4, 0x1f -/* 802DEB7C 54 00 00 34 */ rlwinm r0, r0, 0, 0, 0x1a -/* 802DEB80 90 1F 00 0C */ stw r0, 0xc(r31) -/* 802DEB84 88 0D 8F 38 */ lbz r0, data_804514B8(r13) -/* 802DEB88 28 00 00 00 */ cmplwi r0, 0 -/* 802DEB8C 41 82 00 4C */ beq lbl_802DEBD8 -/* 802DEB90 80 6D 8D F0 */ lwz r3, sSystemHeap__7JKRHeap(r13) -/* 802DEB94 80 9F 00 0C */ lwz r4, 0xc(r31) -/* 802DEB98 38 84 00 80 */ addi r4, r4, 0x80 -/* 802DEB9C 38 A0 00 20 */ li r5, 0x20 -/* 802DEBA0 4B FE F9 35 */ bl alloc__7JKRHeapFUli -/* 802DEBA4 90 7F 00 04 */ stw r3, 4(r31) -/* 802DEBA8 80 7F 00 04 */ lwz r3, 4(r31) -/* 802DEBAC 38 03 00 80 */ addi r0, r3, 0x80 -/* 802DEBB0 90 1F 00 08 */ stw r0, 8(r31) -/* 802DEBB4 80 7F 00 04 */ lwz r3, 4(r31) -/* 802DEBB8 80 9F 00 08 */ lwz r4, 8(r31) -/* 802DEBBC 80 BF 00 0C */ lwz r5, 0xc(r31) -/* 802DEBC0 48 07 BB 1D */ bl GXInitFifoBase -/* 802DEBC4 80 9F 00 08 */ lwz r4, 8(r31) -/* 802DEBC8 80 7F 00 04 */ lwz r3, 4(r31) -/* 802DEBCC 7C 85 23 78 */ mr r5, r4 -/* 802DEBD0 48 07 BB 79 */ bl GXInitFifoPtrs -/* 802DEBD4 48 00 00 48 */ b lbl_802DEC1C -lbl_802DEBD8: -/* 802DEBD8 80 6D 8D F0 */ lwz r3, sSystemHeap__7JKRHeap(r13) -/* 802DEBDC 80 9F 00 0C */ lwz r4, 0xc(r31) -/* 802DEBE0 38 84 00 A0 */ addi r4, r4, 0xa0 -/* 802DEBE4 38 A0 00 20 */ li r5, 0x20 -/* 802DEBE8 4B FE F8 ED */ bl alloc__7JKRHeapFUli -/* 802DEBEC 90 7F 00 08 */ stw r3, 8(r31) -/* 802DEBF0 80 7F 00 08 */ lwz r3, 8(r31) -/* 802DEBF4 38 03 00 1F */ addi r0, r3, 0x1f -/* 802DEBF8 54 00 00 34 */ rlwinm r0, r0, 0, 0, 0x1a -/* 802DEBFC 90 1F 00 08 */ stw r0, 8(r31) -/* 802DEC00 80 7F 00 08 */ lwz r3, 8(r31) -/* 802DEC04 80 9F 00 0C */ lwz r4, 0xc(r31) -/* 802DEC08 48 07 AA 69 */ bl GXInit -/* 802DEC0C 90 7F 00 04 */ stw r3, 4(r31) -/* 802DEC10 38 00 00 01 */ li r0, 1 -/* 802DEC14 98 0D 8F 38 */ stb r0, data_804514B8(r13) -/* 802DEC18 93 ED 8F 3C */ stw r31, sCurrentFifo__12JUTGraphFifo(r13) -lbl_802DEC1C: -/* 802DEC1C 7F E3 FB 78 */ mr r3, r31 -/* 802DEC20 83 E1 00 0C */ lwz r31, 0xc(r1) -/* 802DEC24 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802DEC28 7C 08 03 A6 */ mtlr r0 -/* 802DEC2C 38 21 00 10 */ addi r1, r1, 0x10 -/* 802DEC30 4E 80 00 20 */ blr diff --git a/asm/JSystem/JUtility/JUTGraphFifo/__dt__12JUTGraphFifoFv.s b/asm/JSystem/JUtility/JUTGraphFifo/__dt__12JUTGraphFifoFv.s deleted file mode 100644 index c8da413345..0000000000 --- a/asm/JSystem/JUtility/JUTGraphFifo/__dt__12JUTGraphFifoFv.s +++ /dev/null @@ -1,53 +0,0 @@ -lbl_802DEC34: -/* 802DEC34 94 21 FF E0 */ stwu r1, -0x20(r1) -/* 802DEC38 7C 08 02 A6 */ mflr r0 -/* 802DEC3C 90 01 00 24 */ stw r0, 0x24(r1) -/* 802DEC40 39 61 00 20 */ addi r11, r1, 0x20 -/* 802DEC44 48 08 35 8D */ bl _savegpr_26 -/* 802DEC48 7C 7A 1B 79 */ or. r26, r3, r3 -/* 802DEC4C 7C 9B 23 78 */ mr r27, r4 -/* 802DEC50 41 82 00 8C */ beq lbl_802DECDC -/* 802DEC54 3C 60 80 3D */ lis r3, __vt__12JUTGraphFifo@ha /* 0x803CC590@ha */ -/* 802DEC58 38 03 C5 90 */ addi r0, r3, __vt__12JUTGraphFifo@l /* 0x803CC590@l */ -/* 802DEC5C 90 1A 00 00 */ stw r0, 0(r26) -/* 802DEC60 80 6D 8F 3C */ lwz r3, sCurrentFifo__12JUTGraphFifo(r13) -/* 802DEC64 80 63 00 04 */ lwz r3, 4(r3) -/* 802DEC68 48 07 BE 25 */ bl GXSaveCPUFifo -/* 802DEC6C 3B ED 8F 40 */ la r31, mGpStatus__12JUTGraphFifo(r13) /* 804514C0-_SDA_BASE_ */ -/* 802DEC70 7F FE FB 78 */ mr r30, r31 -/* 802DEC74 7F FD FB 78 */ mr r29, r31 -/* 802DEC78 3B 9F 00 01 */ addi r28, r31, 1 -/* 802DEC7C 3B FF 00 04 */ addi r31, r31, 4 -/* 802DEC80 3B DE 00 03 */ addi r30, r30, 3 -/* 802DEC84 3B BD 00 02 */ addi r29, r29, 2 -lbl_802DEC88: -/* 802DEC88 38 6D 8F 40 */ la r3, mGpStatus__12JUTGraphFifo(r13) /* 804514C0-_SDA_BASE_ */ -/* 802DEC8C 7F 84 E3 78 */ mr r4, r28 -/* 802DEC90 7F A5 EB 78 */ mr r5, r29 -/* 802DEC94 7F C6 F3 78 */ mr r6, r30 -/* 802DEC98 7F E7 FB 78 */ mr r7, r31 -/* 802DEC9C 48 07 BE ED */ bl GXGetGPStatus -/* 802DECA0 88 1D 00 00 */ lbz r0, 0(r29) -/* 802DECA4 28 00 00 00 */ cmplwi r0, 0 -/* 802DECA8 41 82 FF E0 */ beq lbl_802DEC88 -/* 802DECAC 80 0D 8F 3C */ lwz r0, sCurrentFifo__12JUTGraphFifo(r13) -/* 802DECB0 7C 00 D0 40 */ cmplw r0, r26 -/* 802DECB4 40 82 00 0C */ bne lbl_802DECC0 -/* 802DECB8 38 00 00 00 */ li r0, 0 -/* 802DECBC 90 0D 8F 3C */ stw r0, sCurrentFifo__12JUTGraphFifo(r13) -lbl_802DECC0: -/* 802DECC0 80 6D 8D F0 */ lwz r3, sSystemHeap__7JKRHeap(r13) -/* 802DECC4 80 9A 00 08 */ lwz r4, 8(r26) -/* 802DECC8 4B FE F8 81 */ bl free__7JKRHeapFPv -/* 802DECCC 7F 60 07 35 */ extsh. r0, r27 -/* 802DECD0 40 81 00 0C */ ble lbl_802DECDC -/* 802DECD4 7F 43 D3 78 */ mr r3, r26 -/* 802DECD8 4B FF 00 65 */ bl __dl__FPv -lbl_802DECDC: -/* 802DECDC 7F 43 D3 78 */ mr r3, r26 -/* 802DECE0 39 61 00 20 */ addi r11, r1, 0x20 -/* 802DECE4 48 08 35 39 */ bl _restgpr_26 -/* 802DECE8 80 01 00 24 */ lwz r0, 0x24(r1) -/* 802DECEC 7C 08 03 A6 */ mtlr r0 -/* 802DECF0 38 21 00 20 */ addi r1, r1, 0x20 -/* 802DECF4 4E 80 00 20 */ blr diff --git a/include/JSystem/JUtility/JUTGraphFifo.h b/include/JSystem/JUtility/JUTGraphFifo.h index 393b232adb..8dae2c7b90 100644 --- a/include/JSystem/JUtility/JUTGraphFifo.h +++ b/include/JSystem/JUtility/JUTGraphFifo.h @@ -1,6 +1,35 @@ #ifndef JUTGRAPHFIFO_H #define JUTGRAPHFIFO_H +#include "dolphin/gx/GX.h" #include "dolphin/types.h" +class JUTGraphFifo { +public: + /* 802DEB58 */ JUTGraphFifo(u32); + + /* 802DEC34 */ virtual ~JUTGraphFifo(); + + void getGpStatus() { + GXGetGPStatus((GXBool*)&mGpStatus[0], (GXBool*)&mGpStatus[1], (GXBool*)&mGpStatus[2], + (GXBool*)&mGpStatus[3], (GXBool*)&mGpStatus[4]); + } + + bool isGPActive() { + getGpStatus(); + return mGpStatus[2] == false; + } + + void save() { GXSaveCPUFifo(this->mFifo); } + + static JUTGraphFifo* sCurrentFifo; + static bool mGpStatus[5]; + +private: + /* 0x04 */ GXFifoObj* mFifo; + /* 0x08 */ void* mBase; + /* 0x0C */ u32 mSize; + /* 0x10 */ u8 field_0x10[0xC]; +}; + #endif /* JUTGRAPHFIFO_H */ diff --git a/include/dolphin/gx/GX.h b/include/dolphin/gx/GX.h index f1eca18856..d7aeb521c6 100644 --- a/include/dolphin/gx/GX.h +++ b/include/dolphin/gx/GX.h @@ -959,6 +959,9 @@ GXFifoObj* GXInit(void*, u32); GXFifoObj* GXGetCPUFifo(void); void GXGetGPStatus(GXBool*, GXBool*, GXBool*, GXBool*, GXBool*); void GXReadXfRasMetric(u32*, u32*, u32*, u32*); +void GXInitFifoBase(GXFifoObj*, void*, u32); +void GXInitFifoPtrs(GXFifoObj*, void*, void*); +void GXSaveCPUFifo(GXFifoObj*); #define GFX_FIFO(T) (*(volatile T*)0xCC008000) diff --git a/libs/JSystem/JFramework/JFWSystem.cpp b/libs/JSystem/JFramework/JFWSystem.cpp index 4405ffbf36..329a6f2356 100644 --- a/libs/JSystem/JFramework/JFWSystem.cpp +++ b/libs/JSystem/JFramework/JFWSystem.cpp @@ -9,20 +9,11 @@ #include "JSystem/JUtility/JUTDirectPrint.h" #include "JSystem/JUtility/JUTException.h" #include "JSystem/JUtility/JUTGamePad.h" +#include "JSystem/JUtility/JUTGraphFifo.h" #include "JSystem/JUtility/JUTVideo.h" #include "dol2asm.h" #include "dolphin/types.h" -// -// Types: -// - -struct JUTGraphFifo { - /* 802DEB58 */ JUTGraphFifo(u32); - - u8 field_0x0[0x1C]; -}; - // // Forward References: // diff --git a/libs/JSystem/JUtility/JUTGraphFifo.cpp b/libs/JSystem/JUtility/JUTGraphFifo.cpp index b32ebf1ddb..782708926b 100644 --- a/libs/JSystem/JUtility/JUTGraphFifo.cpp +++ b/libs/JSystem/JUtility/JUTGraphFifo.cpp @@ -4,93 +4,50 @@ // #include "JSystem/JUtility/JUTGraphFifo.h" +#include "JSystem/JKernel/JKRHeap.h" #include "dol2asm.h" #include "dolphin/types.h" -// -// Types: -// - -struct JUTGraphFifo { - /* 802DEB58 */ JUTGraphFifo(u32); - /* 802DEC34 */ ~JUTGraphFifo(); - - static u8 sCurrentFifo[4]; - static u8 mGpStatus[5 + 3 /* padding */]; -}; - -struct JKRHeap { - /* 802CE4D4 */ void alloc(u32, int); - /* 802CE548 */ void free(void*); - - static u8 sSystemHeap[4]; -}; - -// -// Forward References: -// - -extern "C" void __ct__12JUTGraphFifoFUl(); -extern "C" void __dt__12JUTGraphFifoFv(); -extern "C" u8 sCurrentFifo__12JUTGraphFifo[4]; -extern "C" u8 mGpStatus__12JUTGraphFifo[5 + 3 /* padding */]; - -// -// External References: -// - -extern "C" void alloc__7JKRHeapFUli(); -extern "C" void free__7JKRHeapFPv(); -extern "C" void __dl__FPv(); -extern "C" void GXInit(); -extern "C" void GXInitFifoBase(); -extern "C" void GXInitFifoPtrs(); -extern "C" void GXSaveCPUFifo(); -extern "C" void GXGetGPStatus(); -extern "C" void _savegpr_26(); -extern "C" void _restgpr_26(); -extern "C" u8 sSystemHeap__7JKRHeap[4]; - // // Declarations: // -/* ############################################################################################## */ -/* 803CC590-803CC5A0 0296B0 000C+04 2/2 0/0 0/0 .data __vt__12JUTGraphFifo */ -SECTION_DATA extern void* __vt__12JUTGraphFifo[3 + 1 /* padding */] = { - (void*)NULL /* RTTI */, - (void*)NULL, - (void*)__dt__12JUTGraphFifoFv, - /* padding */ - NULL, -}; - /* 804514B8-804514BC 0009B8 0004+00 1/1 0/0 0/0 .sbss None */ -static u8 data_804514B8[4]; +static bool data_804514B8; /* 804514BC-804514C0 0009BC 0004+00 2/2 0/0 0/0 .sbss sCurrentFifo__12JUTGraphFifo */ -u8 JUTGraphFifo::sCurrentFifo[4]; +JUTGraphFifo* JUTGraphFifo::sCurrentFifo; /* 802DEB58-802DEC34 2D9498 00DC+00 0/0 1/1 0/0 .text __ct__12JUTGraphFifoFUl */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm JUTGraphFifo::JUTGraphFifo(u32 param_0) { - nofralloc -#include "asm/JSystem/JUtility/JUTGraphFifo/__ct__12JUTGraphFifoFUl.s" +JUTGraphFifo::JUTGraphFifo(u32 size) { + mSize = size + 0x1F & ~0x1F; + if (data_804514B8) { + mFifo = (GXFifoObj*)JKRAllocFromSysHeap(mSize + 0x80, 32); + mBase = mFifo + 1; + GXInitFifoBase(mFifo, mBase, mSize); + GXInitFifoPtrs(mFifo, mBase, mBase); + } else { + mBase = JKRAllocFromSysHeap(mSize + 0xA0, 32); + mBase = (void*)((int)mBase + 0x1F & ~0x1F); + mFifo = GXInit(mBase, mSize); + data_804514B8 = true; + sCurrentFifo = this; + } } -#pragma pop /* ############################################################################################## */ /* 804514C0-804514C8 0009C0 0005+03 1/1 0/0 0/0 .sbss mGpStatus__12JUTGraphFifo */ -u8 JUTGraphFifo::mGpStatus[5 + 3 /* padding */]; +bool JUTGraphFifo::mGpStatus[5]; /* 802DEC34-802DECF8 2D9574 00C4+00 1/0 0/0 0/0 .text __dt__12JUTGraphFifoFv */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm JUTGraphFifo::~JUTGraphFifo() { - nofralloc -#include "asm/JSystem/JUtility/JUTGraphFifo/__dt__12JUTGraphFifoFv.s" +JUTGraphFifo::~JUTGraphFifo() { + sCurrentFifo->save(); + + do { + } while (isGPActive()); + + if (sCurrentFifo == this) { + sCurrentFifo = NULL; + } + JKRFreeToSysHeap(mBase); } -#pragma pop