From 586a144bddfaefca5909a09f2863e9fadebf4abc Mon Sep 17 00:00:00 2001 From: entriphy <1747088+entriphy@users.noreply.github.com> Date: Thu, 20 Jul 2023 00:16:48 -0700 Subject: [PATCH] harada: Decompile h_vpm2.c --- include/harada.h | 39 +++++++++++++++-- src/harada/h_vpm2.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 src/harada/h_vpm2.c diff --git a/include/harada.h b/include/harada.h index 853702b..dae9223 100644 --- a/include/harada.h +++ b/include/harada.h @@ -4,7 +4,9 @@ #include "types.h" #include "take.h" -// Structs +#define HR_DUMB_STUPID_NULL_CHECK(x) ((s32)x != -1) + +#pragma region Structs typedef enum { PTOPENING, @@ -198,7 +200,29 @@ typedef struct { // 0x10 /* 0xc */ f32 spdt; } HRSCRST; -// Functions +typedef struct { + sceVu0FVECTOR cmin; + sceVu0FVECTOR cmax; + sceVu0FVECTOR hmin; + sceVu0FVECTOR hmax; + sceVu0FVECTOR hami; + sceVu0FVECTOR zmax; + sceVu0FVECTOR zmin; + sceVu0FVECTOR xmax; + sceVu0FVECTOR xmin; + sceVu0FVECTOR ymax; + sceVu0FVECTOR ymin; +} VPCLIP; + +#pragma endregion Structs + +#pragma region Functions + +// h_vpm2.c +extern void h_vp_init(VPCLIP *vpc, f32 proj, f32 near, f32 far, f32 hamix, f32 hamiy, f32 hamiz, s32 fg); +extern s32 hm_vpclip(sceVu0FMATRIX rtm, sceVu0FVECTOR zure, sceVu0FVECTOR cmax, sceVu0FVECTOR cmin, sceVu0FVECTOR hmax, sceVu0FVECTOR hmin, sceVu0FVECTOR *out); +extern s32 h_vpm_bclip(VPCLIP *vpc, s32 *bhead, sceVu0FMATRIX world_view); +extern s32 h_vpo_vclip(VPCLIP *vpc, sceVu0FVECTOR pos, sceVu0FMATRIX world_view); // hr_main.c extern void hr_cold_start(); @@ -216,7 +240,14 @@ extern void hr_pflag_initSt(); extern void hr_pflag_init(); extern PT hr_pflag_get_id(); -// Data +#pragma endregion Functions + +#pragma region Data + +// h_vpm2.c +extern VPCLIP cvpm; +extern VPCLIP cvbg; +extern VPCLIP cvpo; // hr_bgwk.c extern BGWK *hrbgbuff; @@ -291,4 +322,6 @@ extern PT hrpt_id; extern s32 hrptm_res; extern s32 hrpt_sbgm; +#pragma endregion Data + #endif diff --git a/src/harada/h_vpm2.c b/src/harada/h_vpm2.c new file mode 100644 index 0000000..6d083f3 --- /dev/null +++ b/src/harada/h_vpm2.c @@ -0,0 +1,104 @@ +#include "common.h" + +VPCLIP cvpm = {}; +VPCLIP cvbg = {}; +VPCLIP cvpo = {}; + +void h_vp_init(VPCLIP *vpc, f32 proj, f32 near, f32 far, f32 hamix, f32 hamiy, f32 hamiz, s32 fg) { + vpc->cmax[0] = 320.0f / proj; + vpc->cmax[1] = 240.0f / proj; + vpc->cmax[2] = 0.0f; + vpc->cmax[3] = 0.0f; + vpc->cmin[0] = -vpc->cmax[0]; + vpc->cmin[1] = -vpc->cmax[1]; + vpc->cmin[2] = 0.0f; + vpc->cmin[3] = 0.0f; + + if (fg == 0) { + hamix = hamiy = hamiz = sqrtf(hamix * hamix + hamiy * hamiy + hamiz * hamiz);; + if (proj < 320.0f) { + hamix += ((320.0f - proj) * hamix) / proj + 724.0f; + if (proj < 240.0f) { + hamiy += ((240.0f - proj) * hamiy) / proj + 724.0f; + } + } + if (GameGbl.vision != 0x1101) { + vpc->hmax[0] = hamix; + goto LAB_00101788; + } + hamix *= 2; + hamiy *= 2; + hamiz *= 1.5f; + } + vpc->hmax[0] = hamix; + +LAB_00101788: + vpc->hmax[1] = hamiy; + vpc->hmax[2] = far + hamiz; + vpc->hmax[3] = 0.0f; + vpc->hmin[0] = -hamix; + vpc->hmin[1] = -hamiy; + vpc->hmin[2] = near - hamiz; + vpc->hmin[3] = 0.0f; +} + +s32 hm_vpclip(sceVu0FMATRIX rtm, sceVu0FVECTOR zure, sceVu0FVECTOR cmax, sceVu0FVECTOR cmin, sceVu0FVECTOR hmax, sceVu0FVECTOR hmin, sceVu0FVECTOR *out) { + asm __volatile__( + "lqc2 $vf4, 0x0(%0)\n" + "lqc2 $vf5, 0x10(%0)\n" + "lqc2 $vf6, 0x20(%0)\n" + "lqc2 $vf7, 0x30(%0)\n" + "lqc2 $vf8, 0x0(%1)\n" + "lqc2 $vf9, 0x0(%2)\n" + "lqc2 $vf10, 0x0(%3)\n" + "lqc2 $vf11, 0x0(%4)\n" + "lqc2 $vf12, 0x0(%5)\n" + "vmulax.xyzw ACC, $vf4, $vf8x\n" + "vmadday.xyzw ACC, $vf5, $vf8y\n" + "vmaddaz.xyzw ACC, $vf6, $vf8z\n" + "vmaddw.xyzw $vf13, $vf7, $vf8w\n" + "vnop\n" + "vnop\n" + "vadda.xy ACC, $vf0, $vf11\n" + "vmaddz.xy $vf11, $vf9, $vf13z\n" + "vadda.xy ACC, $vf0, $vf12\n" + "vmaddz.xy $vf12, $vf10, $vf13z\n" + "vnop\n" + "vnop\n" + "vnop\n" + "ctc2 $0, $vi16\n" + "vsub.xyz $vf20, $vf11, $vf13\n" + "vsub.xyz $vf21, $vf13, $vf12\n" + "vnop\n" + "vnop\n" + "vnop\n" + "sqc2 $vf20, 0x0(%6)\n" + "sqc2 $vf21, 0x10(%6)\n" + "vnop\n" + "vnop\n" + "vnop\n" + "cfc2 $2, $vi16\n" + "andi $2, $2, 0xC0\n" + : : "r" (rtm), "r" (zure), "r" (cmax), "r" (cmin), "r" (hmax), "r" (hmin), "r" (out)); +} + +s32 h_vpm_bclip(VPCLIP *vpc, s32 *bhead, sceVu0FMATRIX world_view) { + sceVu0FVECTOR v; + + bhead += 2; + v[0] = ((f32 *)bhead)[0]; + v[1] = ((f32 *)bhead)[1]; + v[2] = ((f32 *)bhead)[2]; + v[3] = 1.0f; + return hm_vpclip(world_view, v, vpc->cmax, vpc->cmin, vpc->hmax, vpc->hmin, &vpc->zmax); +} + +s32 h_vpo_vclip(VPCLIP *vpc, sceVu0FVECTOR pos, sceVu0FMATRIX world_view) { + sceVu0FVECTOR v; + + v[0] = pos[0]; + v[1] = pos[1]; + v[2] = pos[2]; + v[3] = 1.0f; + return hm_vpclip(world_view, v, vpc->cmax, vpc->cmin, vpc->hmax, vpc->hmin, &vpc->zmax); +}