From 7a50a4511a870ff22baece3f2792e1b268e1bab5 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Fri, 5 May 2023 10:41:30 +0000 Subject: [PATCH] implement fade and wipe transitions --- config/assets.yml | 9 ++- config/rel_slices.yml | 8 +++ include/libu64/u64types.h | 7 +++ include/libultra/libultra.h | 3 + include/libultra/ultratypes.h | 9 +-- include/m_common_data.h | 5 +- include/m_fbdemo_fade.h | 26 ++++++++ include/m_fbdemo_wipe1.h | 29 +++++++++ include/m_rcp.h | 2 + rel/m_fbdemo_fade.c | 100 +++++++++++++++++++++++++++++++ rel/m_fbdemo_wipe1.c | 110 ++++++++++++++++++++++++++++++++++ 11 files changed, 300 insertions(+), 8 deletions(-) create mode 100644 include/m_fbdemo_fade.h create mode 100644 include/m_fbdemo_wipe1.h create mode 100644 rel/m_fbdemo_fade.c create mode 100644 rel/m_fbdemo_wipe1.c diff --git a/config/assets.yml b/config/assets.yml index adde1d2d..5d145f88 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -4,4 +4,11 @@ config/dol.yml: __DateTime__: addrs: [0x800b05f4, 0x800b0608] nintendo_hi_0.aw: - addrs: [0x800c3140, 0x800cca40] \ No newline at end of file + addrs: [0x800c3140, 0x800cca40] +config/rel.yml: + wipe1_v: + addrs: [0x80652AD0, 0x80652C60] + g_wipe1_txt: + addrs: [0x80652C60, 0x80653460] + wipe1_modelT: + addrs: [0x80653460, 0x80653558] \ No newline at end of file diff --git a/config/rel_slices.yml b/config/rel_slices.yml index aea07383..a0ed46cf 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -10,6 +10,14 @@ m_fbdemo.c: .text: [0x803A0350, 0x803A0ABC] .rodata: [0x80641F40, 0x80641F60] .data: [0x80652AA0, 0x80652AD0] +#m_fbdemo_wipe1.c: some rodata is 8 bytes long, when it should be 4 +# .text: [0x803A0F00, 0x803A12F8] +# .rodata: [0x80641FA0, 0x80641FC0] +# .data: [0x80652AD0, 0x80653558] +#m_fbdemo_fade.c: data content mismatch +# .text: [0x803A12F8, 0x803A1508] +# .rodata: [0x80641FC0, 0x80641FD8] +# .data: [0x80653558, 0x806535A0] m_huusui_room.c: .text: [0x803B1908, 0x803B1968] m_home.c: diff --git a/include/libu64/u64types.h b/include/libu64/u64types.h index a7aa5a10..98749408 100644 --- a/include/libu64/u64types.h +++ b/include/libu64/u64types.h @@ -19,6 +19,13 @@ typedef union { rgba8888_t c; } rgba8888; +typedef union { + struct { + u8 r, g, b, a; + }; + u32 rgba; +} Color_RGBA8_u32; + #ifdef __cplusplus } #endif diff --git a/include/libultra/libultra.h b/include/libultra/libultra.h index 69d4814b..422426db 100644 --- a/include/libultra/libultra.h +++ b/include/libultra/libultra.h @@ -5,6 +5,9 @@ #include "dolphin/os/OSTime.h" #include "dolphin/os/OSCache.h" +#define N64_SCREEN_HEIGHT 240 +#define N64_SCREEN_WIDTH 320 + int bcmp (void *v1, void *v2, u32 size); void bcopy(void *src, void *dst, size_t n); void bzero(void *ptr, size_t size); diff --git a/include/libultra/ultratypes.h b/include/libultra/ultratypes.h index ccb05f87..2a1900a1 100644 --- a/include/libultra/ultratypes.h +++ b/include/libultra/ultratypes.h @@ -3,13 +3,10 @@ #include "types.h" -/* -typedef struct { - float m[4][4]; -} Mtx; -*/ - typedef float MtxF_t[4][4]; + + + typedef union { struct { diff --git a/include/m_common_data.h b/include/m_common_data.h index 537efb3e..622895c9 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -110,7 +110,10 @@ typedef struct common_data_s { /* 0x026110 */ Time_c time; /* 0x02613C */ Private_c* now_private; /* 0x026140 */ mHm_hs_c* now_home; - /* 0x026144 */ u8 tmp0[0x23E8]; + /* 0x026144 */ u8 tmp0[0x2614D - 0x26144]; + /* 0x02614D */ u8 transFadeDuration; + /* 0x02614E */ u8 transWipeSpeed; + /* 0x02614F */ u8 tmp34[0x2852C - 0x2614F]; /* 0x02852C */ s16 money_power; /* 0x02852E */ s16 goods_power; /* 0x028530 */ u8 tmp1[0x5680]; diff --git a/include/m_fbdemo_fade.h b/include/m_fbdemo_fade.h new file mode 100644 index 00000000..eeb38638 --- /dev/null +++ b/include/m_fbdemo_fade.h @@ -0,0 +1,26 @@ +#ifndef M_FBDEMO_FADE_H +#define M_FBDEMO_FADE_H + +#include "types.h" +#include "PR/mbi.h" +#include "libu64/u64types.h" + +typedef struct { + /* 0x000 */ u8 type; + /* 0x001 */ u8 isDone; + /* 0x002 */ u8 direction; + /* 0x004 */ Color_RGBA8_u32 color; + /* 0x008 */ s16 frame; + /* 0x00A */ u16 unkA; + /* 0x00C */ u16 timer; +} TransitionFade; // size = 0x10 + + +extern TransitionFade* fbdemo_fade_init(TransitionFade*); +extern void fbdemo_fade_move(TransitionFade*, int); +extern void fbdemo_fade_startup(TransitionFade*); +extern void fbdemo_fade_settype(TransitionFade*, int); +extern void fbdemo_fade_setcolor_rgba8888(TransitionFade*, u32); +extern void fbdemo_fade_is_finish(TransitionFade*); + +#endif \ No newline at end of file diff --git a/include/m_fbdemo_wipe1.h b/include/m_fbdemo_wipe1.h new file mode 100644 index 00000000..3cf45f7a --- /dev/null +++ b/include/m_fbdemo_wipe1.h @@ -0,0 +1,29 @@ +#ifndef FBDEMO_WIPE_H +#define FBDEMO_WIPE_H +#include "types.h" +#include "PR/mbi.h" +#include "libu64/u64types.h" + +typedef struct { + /* 0x000 */ Color_RGBA8_u32 color; + /* 0x004 */ Color_RGBA8_u32 unkColor; + /* 0x008 */ u8 direction; + /* 0x009 */ u8 frame; + /* 0x00A */ u8 finished; + /* 0x00C */ u16 texX; + /* 0x00E */ u16 texY; + /* 0x010 */ u16 normal; + /* 0x018 */ Mtx projection; + /* 0x058 */ Mtx lookAt; + /* 0x098 */ Mtx modelView[2][3]; +} TransitionWipe; // size = 0x218 + + +extern TransitionWipe* fbdemo_wipe1_init(TransitionWipe*); +extern void fbdemo_wipe1_move(TransitionWipe*, int); +extern void fbdemo_wipe1_draw(TransitionWipe* Gfx**); +extern void fbdemo_wipe1_startup(TransitionWipe*); +extern void fbdemo_wipe1_settype(TransitionWipe*, int); +extern void fbdemo_wipe1_setcolor_rgba8888(TransitionWipe*, u32); +extern void fbdemo_wipe1_is_finish(TransitionWipe*); +#endif \ No newline at end of file diff --git a/include/m_rcp.h b/include/m_rcp.h index f9064b82..fe22dcdd 100644 --- a/include/m_rcp.h +++ b/include/m_rcp.h @@ -11,6 +11,8 @@ extern "C" { extern Gfx* gfx_gSPTextureRectangle1(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry, int tile, int s, int t, int dsdx, int dtdy); extern Gfx* gfx_gDPFillRectangle1(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry); extern Gfx* gfx_gDPFillRectangleF(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry); +extern Gfx* gfx_tex_scroll2(Gfx** gfxpp, u32 x, u32 y, s32 width, s32 height); + #ifdef __cplusplus } diff --git a/rel/m_fbdemo_fade.c b/rel/m_fbdemo_fade.c new file mode 100644 index 00000000..d3bf507d --- /dev/null +++ b/rel/m_fbdemo_fade.c @@ -0,0 +1,100 @@ +#include "m_fbdemo_fade.h" +#include "libultra/libultra.h" +#include "libultra/gu.h" +#include "m_common_data.h" + + +Gfx fbdemo_fade_gfx_init[] = { + + gsDPPipeSync(), + gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_1PRIMITIVE, G_AC_DITHER | G_ZS_PRIM | AA_EN | Z_CMP | Z_UPD | IM_RD | CLR_ON_CVG | CVG_DST_SAVE | ZMODE_DEC | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | GBL_c1(G_BL_CLR_FOG, G_BL_0, G_BL_CLR_FOG, G_BL_0) | GBL_c2(G_BL_CLR_FOG, G_BL_A_IN, G_BL_CLR_FOG, G_BL_0)), + gsDPSetColorImage(7, G_IM_SIZ_32b, 1788, 0xDF000000), +}; + + +TransitionFade* fbdemo_fade_init(TransitionFade* this){ + + bzero(this, sizeof(TransitionFade)); + return this; +} + +void fbdemo_fade_move(TransitionFade* this, int rate){ + + f32 ftimer; + int alpha; + + if(this->timer != 0){ + this->timer -= 1; + return; + } + + if(this->type != 7){ + this->frame += rate; + if( this->frame >= Common_Get(transFadeDuration)){ + this->frame = Common_Get(transFadeDuration); + this->isDone = 1; + } + ftimer = (f32) this->frame; + if(ftimer < 0.0f){ + ftimer = 0.0f; + } + + alpha = (255.0f * ftimer) / Common_Get(transFadeDuration); + if (this->type == 1) { + this->color.a = 255 - alpha; + } + else { + this->color.a = alpha; + } + } + } + +void fbdemo_fade_draw(TransitionFade* this, Gfx** gfxP){ + + Gfx* gfx; + if (this->color.a != 0) { + gfx = *gfxP; + gSPDisplayList(gfx++, fbdemo_fade_gfx_init); + gDPSetPrimColor(gfx++, 0, 0, this->color.r, this->color.g, this->color.b, this->color.a); + gDPFillRectangle(gfx++, 0, 0, N64_SCREEN_WIDTH * 2, N64_SCREEN_HEIGHT * 2); + gDPPipeSync(gfx++); + *gfxP = gfx; + } +} + +void fbdemo_fade_startup(TransitionFade* this){ + static u8 start_color[] = {0x00, 0xFF, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + + static s8 start_frame[] = {0x00, 0xFA, 0x00, 0x00, + 0x00, 0x00, 0xAB, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00}; + + + this->color.a = start_color[this->type]; + this->frame = start_frame[this->type]; + this->isDone = 0; + if (this->type == 1){ + + this->timer = 10; + } +} + +void fbdemo_fade_settype(TransitionFade* this, int type){ + + this->type = type; +} + +void fbdemo_fade_setcolor_rgba8888(TransitionFade* this, u32 color){ + + this->color.rgba = color; +} + +int fbdemo_fade_is_finish(TransitionFade* this){ + + return this->isDone; +} \ No newline at end of file diff --git a/rel/m_fbdemo_wipe1.c b/rel/m_fbdemo_wipe1.c new file mode 100644 index 00000000..37276a13 --- /dev/null +++ b/rel/m_fbdemo_wipe1.c @@ -0,0 +1,110 @@ +#include "m_fbdemo_wipe1.h" +#include "m_common_data.h" +#include "libultra/libultra.h" +#include "libultra/gu.h" +#include "m_rcp.h" + +//This should be a DL!! but gfx commands fail ig lol +u8 wipe1_v[] = { +#include "assets/wipe1_v.inc" +}; + +u8 g_wipe1_txt[] = { + #include "assets/g_wipe1_txt.inc" +}; + +u8 wipe1_modelT[] = { + #include "assets/wipe1_modelT.inc" +}; + +TransitionWipe* fbdemo_wipe1_init(TransitionWipe* this){ + + bzero(this, sizeof(TransitionWipe)); + return this; +} + +void fbdemo_wipe1_move(TransitionWipe* this, int rate){ + + if (this->direction != 0) { + + this->texY += (((void)0, Common_Get(transWipeSpeed)) * 3) / rate; + if (this->texY >= (int)(153.0f * (1 << 2))) { + this->texY = (int)(153.0f * (1 << 2)); + this->finished = 1; + } + } else { + this->texY -= (((void)0, Common_Get(transWipeSpeed)) * 3) / rate; + if (this->texY <= (int)(83.25f * (1 << 2))) { + this->texY = (int)(83.25f * (1 << 2)); + this->finished = 1; + } + } +} + +void fbdemo_wipe1_draw(TransitionWipe* this, Gfx** gfxP){ + + Gfx* gfx = *gfxP; + Mtx* modelView; + int pad[4]; + Gfx* texScroll; + + modelView = this->modelView[this->frame]; + this->frame ^= 1; + + guScale(&modelView[0], 0.56f, 0.56f, 1.0f); + guRotate(&modelView[1], 0.0f, 0.0f, 0.0f, 1.0f); + guTranslate(&modelView[2], 0.0f, 0.0f, 0.0f); + gDPPipeSync(gfx++); + + + texScroll = gfx_tex_scroll2(&gfx, this->texX, this->texY, 0, 0); + gSPSegment(gfx++, 8, texScroll); + + gDPSetPrimColor(gfx++, 0, 0x80, this->color.r, this->color.g, this->color.b, 255); + + gSPMatrix(gfx++, &this->projection, G_MTX_LOAD | G_MTX_PROJECTION); + gSPPerspNormalize(gfx++, this->normal); + + gSPMatrix(gfx++, &this->lookAt, G_MTX_MUL | G_MTX_PROJECTION); + gSPMatrix(gfx++, &modelView[0], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(gfx++, &modelView[1], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); + gSPMatrix(gfx++, &modelView[2], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW); + + gSPDisplayList(gfx++, wipe1_modelT); + gDPPipeSync(gfx++); + *gfxP = gfx; +} + +void fbdemo_wipe1_startup(TransitionWipe* this) { + + this->finished = 0; + + if (this->direction != 0) { + this->texY = (s32)(83.25f * (1 << 2)); + } else { + this->texY = (s32)(153.0f * (1 << 2)); + } + + guPerspective(&this->projection, &this->normal, 60.0f, (4.0f / 3.0f), 10.0f, 12800.0f, 1.0f); + guLookAt(&this->lookAt, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); +} + +void fbdemo_wipe1_settype(TransitionWipe* this, int type) { + + if(type == 1){ + this->direction = 1; + this->texY = 0x14D; + return; + } + this->direction = 0; + this->texY = 0x264; +} + +void fbdemo_wipe1_setcolor_rgba8888(TransitionWipe* this, u32 color){ + + this->color.rgba = color; +} + +u8 fbdemo_wipe1_is_finish(TransitionWipe* this){ + return this->finished; +} \ No newline at end of file