From cba64289a4440824e8ddad549dca562df2489edf Mon Sep 17 00:00:00 2001 From: Erin Moon Date: Tue, 29 Dec 2020 17:01:48 -0600 Subject: [PATCH] JUTXfb: decompile (#38) * m_Do_Reset: split and (some) decomp decompiles: - my_OSCancelAlarmAll() - destroyVideo() * mDoRst::reset(): decompile, plus some supporting code * split DVD* functions to dvd.h * mDoRst::resetCallBack(): decompile * JUTXfb: split * JUTXfb: decompile (except for almost-matching ctor) Elaborates JUTVideo and some related stuff. Decompiles the following functions: - JUTXfb::initiate() - JUTXfb::createManager() - JUTXfb::common_init() - JUTXfb::destroyManager() - JUTXfb::~JUTXfb() - JUTXfb::JUTXfb(): *almost* matching up to regalloc * clang-format and extern label modifications Co-authored-by: Pheenoh --- asm/JFramework/JFWDisplay.s | 4 +- include/JSystem/JUtility/JUTVideo/JUTVideo.h | 33 ++++++++ include/JSystem/JUtility/JUTXfb/JUTXfb.h | 13 +++ .../JUtility/JUTXfb/asm/func_802E5260.s | 44 ++++++++++ include/functions.h | 8 ++ include/gx/GX.h | 27 ++++++ include/m_Do/m_Do_Reset/m_Do_Reset.h | 1 + include/variables.h | 2 +- include/vi/VI.h | 8 ++ libs/JSystem/JUtility/JUTXfb.cpp | 84 +++++++++++++++++++ obj_files.mk | 1 - src/m_Do/m_Do_Reset.cpp | 1 - 12 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 include/JSystem/JUtility/JUTVideo/JUTVideo.h create mode 100644 include/JSystem/JUtility/JUTXfb/asm/func_802E5260.s create mode 100644 include/gx/GX.h create mode 100644 include/vi/VI.h diff --git a/asm/JFramework/JFWDisplay.s b/asm/JFramework/JFWDisplay.s index 476833c8525..58fa070d4c3 100644 --- a/asm/JFramework/JFWDisplay.s +++ b/asm/JFramework/JFWDisplay.s @@ -71,7 +71,7 @@ JFWDisplay: /* 80272130 0026F070 4B FF FF 11 */ bl JFWDisplay_NS_ctor_subroutine /* 80272134 0026F074 7F C3 F3 78 */ mr r3, r30 /* 80272138 0026F078 7F E4 FB 78 */ mr r4, r31 -/* 8027213C 0026F07C 48 07 32 7D */ bl JUTXfb_NS_createManager +/* 8027213C 0026F07C 48 07 32 7D */ bl createManager__6JUTXfbFP7JKRHeapl /* 80272140 0026F080 90 7D 00 10 */ stw r3, 0x10(r29) /* 80272144 0026F084 7F A3 EB 78 */ mr r3, r29 /* 80272148 0026F088 39 61 00 20 */ addi r11, r1, 0x20 @@ -98,7 +98,7 @@ JFWDisplay: /* 8027219C 0026F0DC 48 00 0A C5 */ bl JFWDisplay_NS_waitBlanking lbl_802721A0: /* 802721A0 0026F0E0 48 07 38 89 */ bl JUTProcBar_NS_destroy -/* 802721A4 0026F0E4 48 07 32 81 */ bl JUTXfb_NS_destroyManager +/* 802721A4 0026F0E4 48 07 32 81 */ bl destroyManager__6JUTXfbFv /* 802721A8 0026F0E8 38 00 00 00 */ li r0, 0 /* 802721AC 0026F0EC 90 1E 00 10 */ stw r0, 0x10(r30) /* 802721B0 0026F0F0 7F E0 07 35 */ extsh. r0, r31 diff --git a/include/JSystem/JUtility/JUTVideo/JUTVideo.h b/include/JSystem/JUtility/JUTVideo/JUTVideo.h new file mode 100644 index 00000000000..8c47e79dadb --- /dev/null +++ b/include/JSystem/JUtility/JUTVideo/JUTVideo.h @@ -0,0 +1,33 @@ +#ifndef __JUTILITY_JUTVIDEO_JUTVIDEO_H__ +#define __JUTILITY_JUTVIDEO_JUTVIDEO_H__ + +#include "gx/GX.h" +#include "os/OS.h" +#include "vi/VI.h" + +struct JUTVideo { + virtual ~JUTVideo(); + + typedef void (*CallbackFn)(void); + + // struct JUTVideo_vtable * vtable; + GXRenderModeObj* render_object; + u32 field_0x8; + u32 retrace_count; + u32 field_0x10; + u32 field_0x14; + u32 field_0x18; + VIRetraceCallback pre_retrace_callback; + VIRetraceCallback post_retrace_callback; + CallbackFn unknown_callback_1; + CallbackFn unknown_callback_2; + bool set_black; + u8 padding[3]; + s32 set_black_frame_counter; + OSMessage message; + OSMessageQueue message_queue; +}; + +extern JUTVideo* lbl_80451538; + +#endif diff --git a/include/JSystem/JUtility/JUTXfb/JUTXfb.h b/include/JSystem/JUtility/JUTXfb/JUTXfb.h index 0eaa499a782..fbfdb7156f2 100644 --- a/include/JSystem/JUtility/JUTXfb/JUTXfb.h +++ b/include/JSystem/JUtility/JUTXfb/JUTXfb.h @@ -1,11 +1,22 @@ #ifndef __JUTILITY_JUTXFB_JUTXFB_H__ #define __JUTILITY_JUTXFB_JUTXFB_H__ +#include "JSystem/JKernel/JKRHeap/JKRHeap.h" #include "dolphin/types.h" +#include "gx/GX.h" class JUTXfb { public: + typedef s32 EXfbNumber; + JUTXfb(GXRenderModeObj* obj, JKRHeap* heap, EXfbNumber xfb_number); + ~JUTXfb(); + void clearIndex(); + void common_init(s32 xfb_number); + void delXfb(s32 index); + static JUTXfb* createManager(JKRHeap* heap, EXfbNumber xfb_number); + static void destroyManager(); + void initiate(u16 width, u16 height, JKRHeap* heap, JUTXfb::EXfbNumber xfb_number); private: void* xfb_buffer[3]; @@ -19,4 +30,6 @@ private: s32 field_0x1c; }; +extern JUTXfb* lbl_80451550; + #endif \ No newline at end of file diff --git a/include/JSystem/JUtility/JUTXfb/asm/func_802E5260.s b/include/JSystem/JUtility/JUTXfb/asm/func_802E5260.s new file mode 100644 index 00000000000..e27f6b93463 --- /dev/null +++ b/include/JSystem/JUtility/JUTXfb/asm/func_802E5260.s @@ -0,0 +1,44 @@ +/* 802E5260 002E21A0 94 21 FF E0 */ stwu r1, -0x20(r1) +/* 802E5264 002E21A4 7C 08 02 A6 */ mflr r0 +/* 802E5268 002E21A8 90 01 00 24 */ stw r0, 0x24(r1) +/* 802E526C 002E21AC 39 61 00 20 */ addi r11, r1, 0x20 +/* 802E5270 002E21B0 48 07 CF 65 */ bl _savegpr_27 +/* 802E5274 002E21B4 7C 7B 1B 78 */ mr r27, r3 +/* 802E5278 002E21B8 7C 9E 23 78 */ mr r30, r4 +/* 802E527C 002E21BC 7C BC 2B 78 */ mr r28, r5 +/* 802E5280 002E21C0 7C DD 33 78 */ mr r29, r6 +/* 802E5284 002E21C4 7F A4 EB 78 */ mr r4, r29 +/* 802E5288 002E21C8 4B FF FF A1 */ bl common_init__6JUTXfbFl +/* 802E528C 002E21CC 28 1E 00 00 */ cmplwi r30, 0 +/* 802E5290 002E21D0 41 82 00 20 */ beq lbl_802E52B0 +/* 802E5294 002E21D4 7F 63 DB 78 */ mr r3, r27 +/* 802E5298 002E21D8 A0 9E 00 04 */ lhz r4, 4(r30) +/* 802E529C 002E21DC A0 BE 00 08 */ lhz r5, 8(r30) +/* 802E52A0 002E21E0 7F 86 E3 78 */ mr r6, r28 +/* 802E52A4 002E21E4 7F A7 EB 78 */ mr r7, r29 +/* 802E52A8 002E21E8 48 00 01 AD */ bl initiate__6JUTXfbFUsUsP7JKRHeapl +/* 802E52AC 002E21EC 48 00 00 40 */ b lbl_802E52EC +lbl_802E52B0: +/* 802E52B0 002E21F0 80 6D 8F B8 */ lwz r3, lbl_80451538-_SDA_BASE_(r13) +/* 802E52B4 002E21F4 80 83 00 04 */ lwz r4, 4(r3) +/* 802E52B8 002E21F8 A3 E4 00 04 */ lhz r31, 4(r4) +/* 802E52BC 002E21FC A0 64 00 06 */ lhz r3, 6(r4) +/* 802E52C0 002E2200 7C 7E 1B 78 */ mr r30, r3 +/* 802E52C4 002E2204 A0 84 00 08 */ lhz r4, 8(r4) +/* 802E52C8 002E2208 48 07 7A A5 */ bl GXGetYScaleFactor +/* 802E52CC 002E220C 7F C3 F3 78 */ mr r3, r30 +/* 802E52D0 002E2210 48 07 7A 0D */ bl GXGetNumXfbLines +/* 802E52D4 002E2214 7C 65 1B 78 */ mr r5, r3 +/* 802E52D8 002E2218 7F 63 DB 78 */ mr r3, r27 +/* 802E52DC 002E221C 7F E4 FB 78 */ mr r4, r31 +/* 802E52E0 002E2220 7F 86 E3 78 */ mr r6, r28 +/* 802E52E4 002E2224 7F A7 EB 78 */ mr r7, r29 +/* 802E52E8 002E2228 48 00 01 6D */ bl initiate__6JUTXfbFUsUsP7JKRHeapl +lbl_802E52EC: +/* 802E52EC 002E222C 7F 63 DB 78 */ mr r3, r27 +/* 802E52F0 002E2230 39 61 00 20 */ addi r11, r1, 0x20 +/* 802E52F4 002E2234 48 07 CF 2D */ bl _restgpr_27 +/* 802E52F8 002E2238 80 01 00 24 */ lwz r0, 0x24(r1) +/* 802E52FC 002E223C 7C 08 03 A6 */ mtlr r0 +/* 802E5300 002E2240 38 21 00 20 */ addi r1, r1, 0x20 +/* 802E5304 002E2244 4E 80 00 20 */ blr \ No newline at end of file diff --git a/include/functions.h b/include/functions.h index 9b26f6ba7c5..f9302f54d25 100644 --- a/include/functions.h +++ b/include/functions.h @@ -261,6 +261,8 @@ void __RAS_OSDisableInterrupts_begin(void); u8 dComIfGs_getBottleMax(void); void mDoDvdErr_ThdCleanup(void); +void initiate__6JUTXfbFUsUsP7JKRHeapl(void); +void common_init__6JUTXfbFl(void); } class mDoCPd_c; @@ -378,6 +380,12 @@ void VISetBlack(s32); void VIFlush(void); } +extern "C" { +void VIWaitForRetrace(void); +void VISetBlack(s32); +void VIFlush(void); +} + extern "C" { void JUTReport__FiiPCce(int, int, const char*, ...); void JUTReportConsole(const char*); diff --git a/include/gx/GX.h b/include/gx/GX.h new file mode 100644 index 00000000000..d7c5f80ca86 --- /dev/null +++ b/include/gx/GX.h @@ -0,0 +1,27 @@ +#ifndef __GX_H__ +#define __GX_H__ + +#include "dolphin/types.h" + +struct GXRenderModeObj { + s32 vi_tv_mode; + u16 fb_width; + u16 efb_height; + u16 xfb_height; + u16 vi_x_origin; + u16 vi_y_origin; + u16 vi_width; + u16 vi_height; + s32 xfb_mode; + u8 field_rendering; + u8 antialiasing; + u8 sample_pattern[12][2]; + u8 vfilter[7]; +}; + +extern "C" { +f32 GXGetYScaleFactor(u16 efb_height, u16 xfb_height); +u16 GXGetNumXfbLines(u32 efb_height, f32 y_scale); +} + +#endif \ No newline at end of file diff --git a/include/m_Do/m_Do_Reset/m_Do_Reset.h b/include/m_Do/m_Do_Reset/m_Do_Reset.h index 6603198b50d..b7786248502 100644 --- a/include/m_Do/m_Do_Reset/m_Do_Reset.h +++ b/include/m_Do/m_Do_Reset/m_Do_Reset.h @@ -1,6 +1,7 @@ #ifndef __M_DO_RESET_H__ #define __M_DO_RESET_H__ +#include "JSystem/JUtility/JUTXfb/JUTXfb.h" #include "dolphin/types.h" extern "C" { diff --git a/include/variables.h b/include/variables.h index 3a30de2643c..32b7b5e29c8 100644 --- a/include/variables.h +++ b/include/variables.h @@ -396,7 +396,7 @@ extern u32 lbl_80450DE4; // m_Do_Reset // func_80015614 #include "JSystem/JUtility/JUTXfb/JUTXfb.h" -extern JUTXfb* lbl_80451550; +// extern JUTXfb* lbl_80451550; extern u8 lbl_80450BB8; extern char lbl_80374198[16]; // func_8001574C diff --git a/include/vi/VI.h b/include/vi/VI.h new file mode 100644 index 00000000000..e284e538ae3 --- /dev/null +++ b/include/vi/VI.h @@ -0,0 +1,8 @@ +#ifndef __VI_H__ +#define __VI_H__ + +#include "dolphin/types.h" + +typedef void (*VIRetraceCallback)(u32); + +#endif \ No newline at end of file diff --git a/libs/JSystem/JUtility/JUTXfb.cpp b/libs/JSystem/JUtility/JUTXfb.cpp index f80f7723ac3..d37b26fc321 100644 --- a/libs/JSystem/JUtility/JUTXfb.cpp +++ b/libs/JSystem/JUtility/JUTXfb.cpp @@ -1,8 +1,92 @@ #include "JSystem/JUtility/JUTXfb/JUTXfb.h" +#include "JSystem/JUtility/JUTVideo/JUTVideo.h" +#include "global.h" void JUTXfb::clearIndex() { this->active_xfb_index = -1; this->last_drawn_xfb_index = -1; this->next_xfb_buffer = -1; return; +} + +void JUTXfb::common_init(s32 p1) { + this->num_xfbs = p1; + this->clearIndex(); + this->field_0x1c = 99; +} + +#ifdef NONMATCHING +JUTXfb::JUTXfb(GXRenderModeObj* obj, JKRHeap* heap, JUTXfb::EXfbNumber xfb_number) { + this->common_init(xfb_number); + if (obj != NULL) { + this->initiate(obj->fb_width, obj->xfb_height, heap, xfb_number); + } else { + GXRenderModeObj* render_obj = /* JUTVideo::sManager */ lbl_80451538->render_object; + u16 fb_width = render_obj->fb_width; + u16 efb_height = render_obj->efb_height; + u16 xfb_height = render_obj->xfb_height; + f32 scale_factor = GXGetYScaleFactor(efb_height, xfb_height); + this->initiate(fb_width, GXGetNumXfbLines(efb_height, scale_factor), heap, xfb_number); + } +} +#else +asm JUTXfb::JUTXfb(GXRenderModeObj* obj, JKRHeap* heap, JUTXfb::EXfbNumber xfb_number) { + nofralloc +#include "JSystem/JUtility/JUTXfb/asm/func_802E5260.s" +} +#endif + +JUTXfb::~JUTXfb() { + for (int i = 0; i < 3; i++) { + this->delXfb(i); + } + /* sManager */ lbl_80451550 = NULL; +} + +void JUTXfb::delXfb(s32 index) { + if ((this->is_xfb_allocated[index] != false) && (this->xfb_buffer[index] != NULL)) { + delete this->xfb_buffer[index]; + } +} + +JUTXfb* JUTXfb::createManager(JKRHeap* heap, JUTXfb::EXfbNumber xfb_number) { + if (/* sManager */ lbl_80451550 == NULL) { + lbl_80451550 = new JUTXfb(NULL, heap, xfb_number); + } + + return lbl_80451550; +} + +void JUTXfb::destroyManager() { + delete lbl_80451550; + lbl_80451550 = NULL; +} + +void JUTXfb::initiate(u16 width, u16 height, JKRHeap* heap, JUTXfb::EXfbNumber xfb_number) { + if (heap == NULL) { + heap = /* sSystemHeap */ lbl_80451370; + } + + int size = ((u32)width + 0xf & 0xfff0) * (u32)height * 2; + + void* pvVar1 = ::operator new[](size, heap, 0x20); + this->xfb_buffer[0] = pvVar1; + this->is_xfb_allocated[0] = true; + if (xfb_number >= 2) { + pvVar1 = ::operator new[](size, heap, 0x20); + this->xfb_buffer[1] = pvVar1; + this->is_xfb_allocated[1] = true; + } else { + this->xfb_buffer[1] = NULL; + this->is_xfb_allocated[1] = false; + } + + if (xfb_number >= 3) { + pvVar1 = ::operator new[](size, heap, 0x20); + this->xfb_buffer[2] = pvVar1; + this->is_xfb_allocated[2] = true; + } else { + this->xfb_buffer[2] = NULL; + this->is_xfb_allocated[2] = false; + } } \ No newline at end of file diff --git a/obj_files.mk b/obj_files.mk index 148337c8309..35f315db5e4 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -485,7 +485,6 @@ TEXT_O_FILES := \ $(BUILD_DIR)/asm/JUtility/JUTAssert.o \ $(BUILD_DIR)/asm/JUtility/JUTVideo.o \ $(BUILD_DIR)/libs/JSystem/JUtility/JUTXfb.o \ - $(BUILD_DIR)/asm/JUtility/JUTXfb.o \ $(BUILD_DIR)/asm/JUtility/JUTFader.o \ $(BUILD_DIR)/asm/JUtility/JUTProcBar.o \ $(BUILD_DIR)/asm/JUtility/JUTConsole.o \ diff --git a/src/m_Do/m_Do_Reset.cpp b/src/m_Do/m_Do_Reset.cpp index 0d22d1c4719..8122b32cbd4 100644 --- a/src/m_Do/m_Do_Reset.cpp +++ b/src/m_Do/m_Do_Reset.cpp @@ -64,7 +64,6 @@ void mDoRst::reset(s32 p1, u32 p2, s32 p3) { GXDrawDone(); OSRestoreInterrupts(enable); - destroyVideo(); // nb: probably fake match (i am not sure that it's actually attached to this label lol)