diff --git a/data/objects.txt b/data/objects.txt index d15b3ee4..35893d06 100644 --- a/data/objects.txt +++ b/data/objects.txt @@ -26,6 +26,8 @@ build/obj/donut/app/System.o build/obj/15.o build/obj/donut/gfx/GXFifoMemoryManager.o build/obj/16.o -build/obj/donut/mem/Memory.o +build/obj/donut/gfx/XFBManager.o build/obj/17.o +build/obj/donut/mem/Memory.o build/obj/18.o +build/obj/19.o diff --git a/data/ranges.csv b/data/ranges.csv index a7b5fd82..da0d46f3 100644 --- a/data/ranges.csv +++ b/data/ranges.csv @@ -14,7 +14,8 @@ ,,,,,,801776bc,80177810,,,,,,,80452cf7,80452d18,,,,,8055d13c,8055d141,,,,,donut/app/EntryPoint.o ,,,,,,801778d8,8017793c,,,,,,,,,,,,,,,,,,,donut/app/EntryPoint2.o ,,,,,,8017bbdc,8017bd88,,,,,,,,,,,,,,,,,,,donut/app/System.o -,,,,,,8019607c,80196168,,,,,,,,,,,,,8055d1b1,8055d1b9,,,,,donut/gfx/GXFifoMemoryManager.o +,,,,,,8019607c,801961fc,,,,,,,,,,,,,8055d1b1,8055d1b9,,,,,donut/gfx/GXFifoMemoryManager.o +,,,,,,80197d50,80197ef4,,,,,,,,,,,,,,,,,,,donut/gfx/XFBManager.o ,,,,,,801bf250,801bf2bc,,,,,,,,,80545bf8,80545ed0,,,8055d2a0,8055d2a1,,,,,donut/mem/Memory.o 80006684,80006728,,,,,,,8040652c,80406530,80406548,8040654c,,,,,,,,,,,,,,,Linker generated symbol file 80006728,80006728,800068cc,800068cc,800069e4,800069e4,80406244,80406244,80406530,80406530,8040654c,8040654c,80421030,80421030,804966fc,804966fc,8055640c,8055640c,8055c6d0,8055c6d0,8055df74,8055df74,805643b0,805643b0,805643fc,805643fc,End of File \ No newline at end of file diff --git a/data/symbols.csv b/data/symbols.csv index 29cc10f5..cd4522f4 100644 --- a/data/symbols.csv +++ b/data/symbols.csv @@ -21,6 +21,8 @@ Address,SymbolName 80028530,__init_user 800285a0,exit 8002c840,VIInit +8002cd90,VIWaitForRetrace +8002de70,VISetNextFrameBuffer 80031fe0,GXInit 80038940,GXSetDither 8003a210,DVDInit @@ -30,26 +32,25 @@ Address,SymbolName 80075730,size__Q23gfx19GXFifoMemoryManagerCFv 800dc470,SetTMemLayout__Q34nw4r3g3d4tmemFQ44nw4r3g3d4tmem10TMemLayout 800f16b0,G3dInit__Q24nw4r3g3dFb +801007e0,startAddress__Q23mem8MemBlockCFv 80175b68,__dt__Q33hel6common11NonCopyableFv 80176268,Run__Q23app11ApplicationFRQ23app6Systembbb 80177810,__dt__Q26freeze13FreezeManagerFv 8017786c,__dt__Q23gfx10XFBManagerFv 8018a900,__ct__Q26freeze13FreezeManagerFPUcPUc -80196168,__dt__Q23gfx19GXFifoMemoryManagerFv -801961e0,data__Q23gfx19GXFifoMemoryManagerFv 801962dc,__ct__Q23gfx13RenderSettingFv 80196404,__dt__Q23gfx13RenderSettingFv 801979ac,__ct__Q23gfx9VISettingFv 80197a04,__dt__Q23gfx9VISettingFv 80197b90,set__Q23gfx9VISettingFUl -80197d50,__ct__Q23gfx10XFBManagerFRCQ23gfx9VISetting -80197e8c,target1__Q23gfx10XFBManagerFv -80197ec0,target2__Q23gfx10XFBManagerFv 801a38b0,__ct__Q23hid14LibInitializerFv 801a39f8,__dt__Q23hid14LibInitializerFv +801bd2a4,__ct__Q23mem9DataBlockFUllRQ23mem10IAllocator +801be5a0,free__Q23mem7HeapExpFPv 801bf2bc,__ct__Q23mem6MemoryFv 801bf520,__dt__Q23mem6MemoryFv 801bf5e8,mem1FixHeap__Q23mem6MemoryFv +801bf5f8,mem2FixHeap__Q23mem6MemoryFv 801bf714,__dl__FPv 80402ee8,__ct__Q23snd12SoundManagerFv 80403150,__dt__Q23snd12SoundManagerFv diff --git a/donut/gfx/GXFifoMemoryManager.cpp b/donut/gfx/GXFifoMemoryManager.cpp index 5fea29cf..c942a2e2 100644 --- a/donut/gfx/GXFifoMemoryManager.cpp +++ b/donut/gfx/GXFifoMemoryManager.cpp @@ -18,4 +18,17 @@ PrivateSingleton::~PrivateSingleton() { } bool PrivateSingleton::isExist_; } // namespace common -} // namespace hel \ No newline at end of file +} // namespace hel + +namespace gfx { +GXFifoMemoryManager::~GXFifoMemoryManager() { + MEMORY_OBJ->mem1FixHeap().free(fifo_); + fifo_ = 0; +} + +void *GXFifoMemoryManager::data() { + return (void *)(((u32)fifo_ + 0x3ff) & ~0x3ff); +} + +void GXFifoMemoryManager::setWriteEnable() { writeEnable_ = true; } +} // namespace gfx \ No newline at end of file diff --git a/donut/gfx/XFBManager.cpp b/donut/gfx/XFBManager.cpp new file mode 100644 index 00000000..6c03f56a --- /dev/null +++ b/donut/gfx/XFBManager.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +namespace gfx { +XFBManager::XFBManager(const VISetting &vi) + : fb1_(vi.fbSize(), 0x20, MEMORY_OBJ->mem2FixHeap()), + fb2_(vi.fbSize(), 0x20, MEMORY_OBJ->mem2FixHeap()), oddFb_(false) { + VISetNextFrameBuffer(drawTargetXFB()); + VIWaitForRetrace(); + changeDrawTargetXFB(); +} +unsigned char *XFBManager::drawTargetXFB() { + if (oddFb_) { + mem::MemBlock block = fb1_.block_; + return (unsigned char *)block.startAddress(); + } else { + mem::MemBlock block = fb2_.block_; + return (unsigned char *)block.startAddress(); + } +} +void XFBManager::changeDrawTargetXFB() { oddFb_ = !oddFb_; } +unsigned char *XFBManager::target1() { + mem::MemBlock block = fb1_.block_; + return (unsigned char *)block.startAddress(); +} +unsigned char *XFBManager::target2() { + mem::MemBlock block = fb2_.block_; + return (unsigned char *)block.startAddress(); +} +} // namespace gfx \ No newline at end of file diff --git a/include/gfx/GXFifoMemoryManager.hpp b/include/gfx/GXFifoMemoryManager.hpp index 5d9f966b..44564d7d 100644 --- a/include/gfx/GXFifoMemoryManager.hpp +++ b/include/gfx/GXFifoMemoryManager.hpp @@ -17,5 +17,6 @@ struct GXFifoMemoryManager u32 size() const; void *data(); + void setWriteEnable(); }; } // namespace gfx \ No newline at end of file diff --git a/include/gfx/VISetting.hpp b/include/gfx/VISetting.hpp index b711f54c..b56d002a 100644 --- a/include/gfx/VISetting.hpp +++ b/include/gfx/VISetting.hpp @@ -1,10 +1,17 @@ #pragma once +#include +#include + namespace gfx { struct VISetting { - int unk[5]; + GXRenderModeObject *rmode_; + int unk[4]; VISetting(); ~VISetting(); void set(unsigned long); + u32 fbSize() const { + return (u16)((rmode_->fbWidth + 15) & ~15) * (u32)rmode_->xfbHeight * 2; + } }; } // namespace gfx \ No newline at end of file diff --git a/include/gfx/XFBManager.hpp b/include/gfx/XFBManager.hpp index 992a6275..5be2e978 100644 --- a/include/gfx/XFBManager.hpp +++ b/include/gfx/XFBManager.hpp @@ -1,13 +1,18 @@ #pragma once #include +#include namespace gfx { struct XFBManager { - int unk[7]; + mem::DataBlock fb1_; + mem::DataBlock fb2_; + bool oddFb_; XFBManager(const VISetting &); ~XFBManager(); unsigned char *target1(); unsigned char *target2(); + unsigned char *drawTargetXFB(); + void changeDrawTargetXFB(); }; } // namespace gfx \ No newline at end of file diff --git a/include/gx.h b/include/gx.h index c402c8e9..3ec8d101 100644 --- a/include/gx.h +++ b/include/gx.h @@ -9,6 +9,22 @@ extern "C" { void GXInit(void *fifoBase, u32 size); void GXSetDither(BOOL enabled); +typedef struct { + u32 viTVMode; + u16 fbWidth; + u16 efbHeight; + u16 xfbHeight; + u16 viXOrigin; + u16 viYOrigin; + u16 viWidth; + u16 viHeight; + u32 xfbMode; + u8 field_rendering; + u8 aa; + u8 sample_pattern[12][2]; + u8 vfilter[7]; +} GXRenderModeObject; + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/include/mem/DataBlock.hpp b/include/mem/DataBlock.hpp new file mode 100644 index 00000000..e368f4f2 --- /dev/null +++ b/include/mem/DataBlock.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace mem { +struct DataBlock { + IAllocator &alloc_; + MemBlock block_; + + DataBlock(u32 size, s32 align, IAllocator &alloc); + ~DataBlock(); +}; +} // namespace mem \ No newline at end of file diff --git a/include/mem/HeapExp.hpp b/include/mem/HeapExp.hpp index 4b050c74..8e2173c0 100644 --- a/include/mem/HeapExp.hpp +++ b/include/mem/HeapExp.hpp @@ -12,5 +12,7 @@ struct HeapExp : public IHeap { virtual const MemBlock heapMemBlock() const; virtual u32 heapUsingBlockCount() const; virtual void heapDump() const; + + void free(void *ptr); }; } // namespace mem \ No newline at end of file diff --git a/include/mem/MemBlock.hpp b/include/mem/MemBlock.hpp index 590dc0a1..f0340cfd 100644 --- a/include/mem/MemBlock.hpp +++ b/include/mem/MemBlock.hpp @@ -6,5 +6,7 @@ namespace mem { struct MemBlock { u32 size; void *ptr; + + void *startAddress() const; }; } // namespace mem \ No newline at end of file diff --git a/include/mem/Memory.hpp b/include/mem/Memory.hpp index fd432134..4942b14e 100644 --- a/include/mem/Memory.hpp +++ b/include/mem/Memory.hpp @@ -21,6 +21,7 @@ struct Memory : hel::common::ExplicitSingleton { ~Memory(); HeapExp &mem1FixHeap(); + HeapExp &mem2FixHeap(); }; } // namespace mem diff --git a/include/vi.h b/include/vi.h index 0a1c1278..4e6f0d8d 100644 --- a/include/vi.h +++ b/include/vi.h @@ -5,6 +5,8 @@ extern "C" { #endif void VIInit(void); +void VISetNextFrameBuffer(void *fb); +void VIWaitForRetrace(); #ifdef __cplusplus } diff --git a/src/bin/buildgen.rs b/src/bin/buildgen.rs index bb8362ca..d63f8a31 100644 --- a/src/bin/buildgen.rs +++ b/src/bin/buildgen.rs @@ -26,6 +26,7 @@ const SOURCES: &[(&str, &str)] = &[ ("donut/app/EntryPoint2.cpp", "donut"), ("donut/app/System.cpp", "donut"), ("donut/gfx/GXFifoMemoryManager.cpp", "donut"), + ("donut/gfx/XFBManager.cpp", "donut"), ("donut/mem/Memory.cpp", "donut"), ];