diff --git a/src/melee/mn/mndeflicker.c b/src/melee/mn/mndeflicker.c index 35277ae798..0feab5e4ea 100644 --- a/src/melee/mn/mndeflicker.c +++ b/src/melee/mn/mndeflicker.c @@ -58,10 +58,6 @@ typedef struct { void* x4; } gobj_user_data; -struct sislib_idk { - float idk[40]; -}; - extern struct { unsigned char x0; char x1; @@ -94,7 +90,6 @@ void gmMainLib_8015F588(u8); void lbAudioAx_80024030(int); int lb_80011E24(HSD_JObj*, HSD_JObj**, ...); void lb_8001CE00(void); -void HSD_SisLib_803A5CC4(void*); void lb_8001CE00(void); u8 gmMainLib_8015F4E8(void); @@ -198,16 +193,16 @@ void mnDeflicker_8024A3E8(HSD_GObj* gobj) #define GET_GOBJ_USER_DATA(gobj) ((gobj_user_data*) HSD_GObjGetUserData(gobj)) static inline void inline_test(void) { - struct sislib_idk* temp_r3_6; + sislib_UnkAllocReturn* temp_r3_6; gobj_user_data* user_data = GET_GOBJ_USER_DATA(mnDeflicker_804D6C38); if (user_data->x4) { HSD_SisLib_803A5CC4(user_data->x4); } - temp_r3_6 = (struct sislib_idk*) HSD_SisLib_803A5ACC( - 0, 1, -9.5F, 9.1F, 17.0F, 364.68332F, 38.38772F); + temp_r3_6 = + HSD_SisLib_803A5ACC(0, 1, -9.5F, 9.1F, 17.0F, 364.68332F, 38.38772F); user_data->x4 = temp_r3_6; - temp_r3_6->idk[9] = 0.0521F; - temp_r3_6->idk[10] = 0.0521F; + temp_r3_6->x24.x = 0.0521F; + temp_r3_6->x24.y = 0.0521F; HSD_SisLib_803A6368(temp_r3_6, 0xBD); } @@ -220,8 +215,8 @@ void mnDeflicker_8024A4BC(HSD_GObj* arg0) HSD_GObjProc* proc; HSD_JObj* jobj; u8 temp_r29; - struct sislib_idk* temp_r3_6; gobj_user_data* user_data; + PAD_STACK(4); gobj = GObj_Create(HSD_GOBJ_CLASS_ITEM, 7U, 0x80); mnDeflicker_804D6C38 = gobj; diff --git a/src/melee/mn/mnhyaku.c b/src/melee/mn/mnhyaku.c index 7fcdeab2ae..c2c8cd4368 100644 --- a/src/melee/mn/mnhyaku.c +++ b/src/melee/mn/mnhyaku.c @@ -26,7 +26,6 @@ void mnHyaku_8024CD64(u8); extern HSD_GObj* mnHyaku_804D6C58; -void HSD_SisLib_803A5CC4(void*); s32 mn_80229624(s32); s32 mn_80229894(s32, s32, s32); float mn_8022EC18(HSD_JObj*, float*, int); @@ -73,10 +72,6 @@ extern struct { char x11; } mn_804A04F0; -struct sislib_idk { - float idk[40]; -}; - static inline void mnHyaku_8024C68C_inline(HSD_JObj* jobj, s32 val) { f32 temp_f31 = mn_8022F298(jobj); @@ -89,6 +84,7 @@ static inline void mnHyaku_8024C68C_inline(HSD_JObj* jobj, s32 val) static u8 vals[] = { 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0x00, 0x00 }; +// @todo: this is a common inline in mn #define GET_GOBJ_USER_DATA(gobj) ((gobj_user_data*) HSD_GObjGetUserData(gobj)) static inline void mnHyaku_8024C68C_inline_2(HSD_GObj* gobj) { @@ -98,12 +94,11 @@ static inline void mnHyaku_8024C68C_inline_2(HSD_GObj* gobj) } { u8 val = vals[user_data->x0]; - struct sislib_idk* temp_r3_6 = - (struct sislib_idk*) HSD_SisLib_803A5ACC(0, 1, -9.5F, 9.1F, 17.0F, - 364.68332F, 38.38772F); + sislib_UnkAllocReturn* temp_r3_6 = HSD_SisLib_803A5ACC( + 0, 1, -9.5F, 9.1F, 17.0F, 364.68332F, 38.38772F); user_data->x4 = temp_r3_6; - temp_r3_6->idk[9] = 0.0521F; - temp_r3_6->idk[10] = 0.0521F; + temp_r3_6->x24.x = 0.0521F; + temp_r3_6->x24.y = 0.0521F; HSD_SisLib_803A6368(temp_r3_6, val); } } diff --git a/src/sysdolphin/baselib/gobj.h b/src/sysdolphin/baselib/gobj.h index 290358e507..3994d6548f 100644 --- a/src/sysdolphin/baselib/gobj.h +++ b/src/sysdolphin/baselib/gobj.h @@ -102,7 +102,7 @@ extern HSD_GObjProc* HSD_GObj_804D7838; extern HSD_GObjProc** HSD_GObj_804D7840; extern s32 HSD_GObj_804D7834; extern s32 HSD_GObj_804D783C; -extern HSD_GObj* HSD_SisLib_804D797C; +// extern HSD_GObj* HSD_SisLib_804D797C; @todo: is this actually correct? extern HSD_GObj** HSD_GObj_804D7820; extern HSD_GObj** HSD_GObj_804D7824; extern HSD_GObjLibInitDataType HSD_GObjLibInitData; diff --git a/src/sysdolphin/baselib/sislib.c b/src/sysdolphin/baselib/sislib.c index 8b13789179..ab7ba5b341 100644 --- a/src/sysdolphin/baselib/sislib.c +++ b/src/sysdolphin/baselib/sislib.c @@ -1 +1,2008 @@ +#include "sislib.h" +#include "cobj.h" +#include "gobj.h" +#include "gobjgxlink.h" +#include "gobjobject.h" +#include "gobjplink.h" +#include "gobjuserdata.h" +#include "memory.h" +#include "state.h" +#include "tev.h" + +#include "dolphin/gx/GXAttr.h" +#include "dolphin/gx/GXGeometry.h" +#include "dolphin/gx/GXLight.h" +#include "dolphin/gx/GXPixel.h" +#include "dolphin/gx/GXTev.h" +#include "dolphin/gx/GXTexture.h" +#include "dolphin/gx/GXTransform.h" +#include "dolphin/gx/GXVert.h" +#include "dolphin/mtx.h" + +#include +#include +#include + +HSD_CObjDesc HSD_SisLib_8040C4B8; +sislib_UnkAllocData* HSD_SisLib_804D7970; +sislib_UnkAllocData* HSD_SisLib_804D7974; +sislib_UnkAllocReturn* HSD_SisLib_804D7978; +sislib_UnkAlloc3* HSD_SisLib_804D797C; + +// extern ? *HSD_SisLib_804D796C; +// extern u8 *HSD_SisLib_804D7978; +// sislib_UnknownType001 HSD_SisLib_8040C490 = { 0, 1.0f }; + +static f32 + HSD_SisLib_8040CB00; /* unable to generate initializer: unknown type */ +static u8 + HSD_SisLib_8040CD40; /* unable to generate initializer: unknown type */ +HSD_Archive* HSD_SisLib_804D1110[5]; +SIS* HSD_SisLib_804D1124[5]; +s8 HSD_SisLib_804D6390[4] = { 0, 0, 0, 0 }; + +// a generic allocator used by multiple +// data types +void* HSD_SisLib_803A5798(s32 size) +{ + sislib_UnkAllocData* temp_r0_2; + sislib_UnkAllocData* temp_r25; + u8* temp_r26; + sislib_UnkAllocData* var_r26; + sislib_UnkAllocData* var_r27; + sislib_UnkAllocData* var_r30; + sislib_UnkAllocData* var_r31; + sislib_UnkAllocData* var_r4; + s32 temp_r0; + s32 temp_r27; + s32 var_r29; + + var_r31 = NULL; + var_r30 = NULL; + var_r27 = HSD_SisLib_804D7970; + var_r26 = HSD_SisLib_804D7974; + if (size == 0) { + OSReport("ZERO byte alloc"); + OSPanic("sislib.c", 0x3C, ""); + } + temp_r0 = size % 4; + if (temp_r0 != 0) { + size += 4 - temp_r0; + } + while (var_r26 != NULL) { + var_r30 = var_r26; + var_r26 = var_r26->data_0; + } + for (;;) { + if (var_r27->size == (u32) size) { + var_r31 = var_r27; + } else { + if (var_r27->size > (u32) size) { + if (var_r31 != NULL) { + if ((u32) var_r31->size > var_r27->size) { + var_r31 = var_r27; + } + } else { + var_r31 = var_r27; + } + } + var_r27 = var_r27->data_0; + if (var_r27 == NULL) { + break; + } + } + } + if (var_r31 == NULL) { + OSReport("Memory Empty"); + OSPanic("sislib.c", 0x56, ""); + } + + var_r4 = HSD_SisLib_804D7970; + if (var_r4 == var_r31) { + temp_r26 = (u8*) var_r4->data_1; + temp_r25 = var_r4->data_0; + temp_r27 = (var_r4->size - size) - 0xC; + if (temp_r27 < 0) { + OSReport("Memory Empty", var_r4); + OSPanic("sislib.c", 0x5F, ""); + } + + HSD_SisLib_804D7970 = (sislib_UnkAllocData*) (temp_r26 + size); + HSD_SisLib_804D7970->data_0 = temp_r25; + HSD_SisLib_804D7970->data_1 = + (sislib_UnkAllocReturn*) (HSD_SisLib_804D7970 + 1); + HSD_SisLib_804D7970->size = temp_r27; + var_r31->size = size; + } else { + while (var_r4->data_0 != var_r31) { + var_r4 = var_r4->data_0; + } + var_r4->data_0 = var_r31->data_0; + } + var_r31->data_0 = NULL; + if (var_r30 != NULL) { + var_r30->data_0 = var_r31; + } + if (HSD_SisLib_804D7974 == NULL) { + HSD_SisLib_804D7974 = var_r31; + } + return var_r31->data_1; +} + +void HSD_SisLib_803A594C(void* arg0) +{ + sislib_UnkAllocData* var_r4; + sislib_UnkAllocData* var_r5; + sislib_UnkAllocData* var_r6; + sislib_UnkAllocData* var_r7; + u32 temp_r3; + + var_r4 = HSD_SisLib_804D7970; + var_r5 = NULL; + var_r7 = HSD_SisLib_804D7974; + var_r6 = NULL; + while (var_r7 != NULL) { + if ((void*) var_r7->data_1 != (void*) arg0) { + var_r6 = var_r7; + var_r7 = var_r7->data_0; + } + } + if (var_r7 != NULL) { + if (var_r4 == (void*) ((u8*) var_r7->data_1 + var_r7->size)) { + s32 new_size = var_r4->size + (var_r7->size + 0xC); + if (var_r6 != NULL) { + var_r6->data_0 = var_r7->data_0; + } else { + HSD_SisLib_804D7974 = var_r7->data_0; + } + arg0 = var_r7; + HSD_SisLib_804D7970->data_0 = var_r4->data_0; + HSD_SisLib_804D7970->data_1 = + (sislib_UnkAllocReturn*) (HSD_SisLib_804D7970 + 1); + HSD_SisLib_804D7970->size = new_size; + return; + } + while (var_r4 != NULL) { + var_r5 = var_r4; + var_r4 = var_r4->data_0; + } + if (var_r5 != NULL) { + var_r5->data_0 = var_r7; + } + if (var_r6 != NULL) { + var_r6->data_0 = var_r7->data_0; + } else { + HSD_SisLib_804D7974 = var_r7->data_0; + } + var_r7->data_0 = NULL; + } +} + +void HSD_SisLib_803A5A2C(sislib_UnkAllocReturn* arg0) +{ + HSD_GObj* temp_r0; + sislib_UnkAllocData* temp_r3; + sislib_UnkAllocReturn* temp_r3_2; + sislib_UnkAllocReturn* temp_r3_3; + sislib_UnkAllocReturn* var_r31; + sislib_UnkAllocReturn* var_r4; + + var_r4 = NULL; + var_r31 = HSD_SisLib_804D7978; + while (var_r31 != NULL) { + temp_r0 = var_r31->x54; + if (var_r31 == arg0) { + if (var_r4 != NULL) { + var_r4->x54 = temp_r0; + } else { + HSD_SisLib_804D7978 = (sislib_UnkAllocReturn*) temp_r0; + } + temp_r3 = var_r31->x64; + if (temp_r3 != NULL) { + temp_r3_2 = temp_r3->data_1; + if (temp_r3_2 != NULL) { + HSD_SisLib_803A594C(temp_r3_2); + } + HSD_SisLib_803A594C(var_r31->x64); + } + temp_r3_3 = var_r31->x68; + if (temp_r3_3 != NULL) { + HSD_SisLib_803A594C(temp_r3_3); + } + HSD_SisLib_803A594C(var_r31); + return; + } + var_r4 = var_r31; + var_r31 = (sislib_UnkAllocReturn*) temp_r0; + } +} + +void HSD_SisLib_803A5CC4(sislib_UnkAllocReturn* arg0) +{ + HSD_GObj* temp_r3; + sislib_UnkAllocReturn* var_r31; + + var_r31 = HSD_SisLib_804D7978; + while (var_r31 != NULL) { + if (var_r31 == arg0) { + temp_r3 = var_r31->x54; + if (temp_r3 != NULL) { + HSD_GObjPLink_80390228(temp_r3); + var_r31->x54 = NULL; + return; + } + HSD_SisLib_803A5A2C(var_r31); + return; + } + var_r31 = (sislib_UnkAllocReturn*) var_r31->x54; + } +} + +void HSD_SisLib_803A5D30(void) +{ + HSD_GObj* temp_r3; + sislib_UnkAllocReturn* temp_r29; + sislib_UnkAllocReturn* var_r30; + + var_r30 = HSD_SisLib_804D7978; + while (var_r30 != NULL) { + temp_r3 = var_r30->x54; + temp_r29 = var_r30->x50; + if (temp_r3 != NULL) { + HSD_GObjPLink_80390228(temp_r3); + var_r30->x54 = NULL; + } else { + HSD_SisLib_803A5A2C(var_r30); + } + var_r30 = temp_r29; + } +} + +void HSD_SisLib_803A5DA0(s32 arg0) +{ + HSD_GObj* temp_r3; + s32 temp_r3_2; + sislib_UnkAlloc3* temp_r30_2; + sislib_UnkAlloc3* var_r28; + sislib_UnkAlloc3* var_r29_2; + sislib_UnkAllocReturn* temp_r30; + sislib_UnkAllocReturn* var_r29; + + var_r28 = NULL; + var_r29 = HSD_SisLib_804D7978; + while (var_r29 != NULL) { + temp_r30 = var_r29->x50; + if ((s32) var_r29->x4F == arg0) { + if (var_r29->x54 != NULL) { + HSD_GObjPLink_80390228(var_r29->x54); + var_r29->x54 = NULL; + } else { + HSD_SisLib_803A5A2C(var_r29); + } + } + var_r29 = temp_r30; + } + var_r29_2 = HSD_SisLib_804D797C; + while (var_r29_2 != NULL) { + temp_r30_2 = var_r29_2->x0; + if ((s32) var_r29_2->xA == arg0) { + if (var_r29_2->x4 != 0U) { + HSD_GObjPLink_80390228(var_r29_2->x4); + var_r29_2->x4 = 0; + } + if (var_r28 != NULL) { + var_r28->x0 = temp_r30_2; + } else { + HSD_SisLib_804D797C = temp_r30_2; + } + HSD_SisLib_803A594C(var_r29_2); + } + var_r28 = var_r29_2; + var_r29_2 = temp_r30_2; + } +} + +sislib_UnkAllocReturn* HSD_SisLib_803A5ACC(s8 arg0, s32 arg1, f32 arg2, + f32 arg3, f32 arg4, f32 arg5, + f32 arg6) +{ + HSD_GObj* temp_r3; + HSD_GObj* var_r27; + s32 var_r4; + sislib_UnkAllocReturn* temp_r30; + sislib_UnkAlloc3* var_r28; + sislib_UnkAllocReturn* var_r29; + sislib_UnkAllocReturn* var_r30; + + var_r4 = arg1; + var_r29 = NULL; + var_r28 = NULL; + var_r27 = NULL; + var_r30 = HSD_SisLib_804D7978; + if (var_r4 >= 0) { + var_r28 = HSD_SisLib_804D797C; + while (((s32) var_r28->xA != arg0) || + (var_r4 -= 1, ((var_r4 < 0) == 0))) + { + if (var_r28 == NULL) { + OSReport("unknow camera\n", var_r4); + return NULL; + } + var_r28 = var_r28->x0; + } + temp_r3 = GObj_Create(var_r28->x8, var_r28->xC, var_r28->xD); + var_r27 = temp_r3; + GObj_SetupGXLink(temp_r3, (void*) HSD_SisLib_803A84BC, var_r28->xE, + var_r28->xF); + } + while (var_r30 != NULL) { + var_r29 = var_r30; + var_r30 = var_r30->x50; + } + temp_r30 = HSD_SisLib_803A5798(0xA0); + if ((sislib_UnkAllocReturn*) HSD_SisLib_804D7978 == NULL) { + HSD_SisLib_804D7978 = temp_r30; + } + if (var_r29 != NULL) { + var_r29->x50 = temp_r30; + } + if (var_r27 != NULL) { + GObj_InitUserData(var_r27, (u8) var_r28->x8, + (void (*)(void*)) HSD_SisLib_803A5A2C, temp_r30); + } + temp_r30->x50 = NULL; + temp_r30->x54 = var_r27; + temp_r30->x0 = arg2; + temp_r30->x4 = arg3; + temp_r30->x8 = arg4; + temp_r30->xC = arg5; + temp_r30->x10 = arg6; + temp_r30->x14.w = 0.0f; + temp_r30->x14.z = 0.0f; + temp_r30->x14.y = 0.0f; + temp_r30->x14.x = 0.0f; + temp_r30->x24.y = 1.0f; + temp_r30->x24.x = 1.0f; + temp_r30->x64 = NULL; + temp_r30->x68 = 0; + temp_r30->x5C = 0; + temp_r30->x2C.w = 0; + temp_r30->x2C.z = 0; + temp_r30->x2C.y = 0; + temp_r30->x2C.x = 0; + temp_r30->x30.w = 0xFF; + temp_r30->x30.z = 0xFF; + temp_r30->x30.y = 0xFF; + temp_r30->x30.x = 0xFF; + temp_r30->x34.y = 1.0f; + temp_r30->x34.x = 1.0f; + temp_r30->x3C.y = 0.0f; + temp_r30->x3C.x = 0.0f; + temp_r30->x46 = 0; + temp_r30->x44 = 0; + temp_r30->x4A = 0; + temp_r30->x48 = 0; + temp_r30->x49 = 0; + temp_r30->x6E = 0; + temp_r30->x6C = 0; + temp_r30->x4E = 0; + temp_r30->x4D = 0; + temp_r30->x4C = 0; + temp_r30->x58 = 0; + temp_r30->x4F = arg0; + return temp_r30; +} + +extern sislib_UnkAllocData* HSD_SisLib_804D796C; + +void HSD_SisLib_803A5E70(void) +{ + HSD_GObj* temp_r3; + s32 temp_r3_2; + sislib_UnkAlloc3* temp_r30_2; + sislib_UnkAlloc3* var_r29_2; + sislib_UnkAllocReturn* temp_r30; + sislib_UnkAllocReturn* var_r29; + + var_r29 = HSD_SisLib_804D7978; + while (var_r29 != NULL) { + temp_r3 = var_r29->x54; + temp_r30 = var_r29->x50; + if (temp_r3 != NULL) { + HSD_GObjPLink_80390228(temp_r3); + var_r29->x54 = NULL; + } else { + HSD_SisLib_803A5A2C(var_r29); + } + var_r29 = temp_r30; + } + var_r29_2 = HSD_SisLib_804D797C; + while (var_r29_2 != NULL) { + temp_r30_2 = var_r29_2->x0; + if ((u32) var_r29_2->x4 != 0U) { + HSD_GObjPLink_80390228(var_r29_2->x4); + var_r29_2->x4 = 0; + } + HSD_SisLib_803A594C(var_r29_2); + var_r29_2 = temp_r30_2; + } + HSD_SisLib_804D797C = NULL; + HSD_SisLib_804D7970 = HSD_SisLib_804D796C; + HSD_SisLib_804D7974 = NULL; + HSD_SisLib_804D7970->data_0 = NULL; + HSD_SisLib_804D7970->data_1 = + (sislib_UnkAllocReturn*) (HSD_SisLib_804D7970 + 0xC); + HSD_SisLib_804D7970->size = HSD_SisLib_804D7968 - 0xC; +} + +void HSD_SisLib_803A5F50(s32 arg0) +{ + HSD_Archive** temp_r31; + + HSD_SisLib_803A5DA0(arg0); + temp_r31 = &HSD_SisLib_804D1110[arg0]; + if (*temp_r31 != NULL) { + HSD_SisLib_803A947C(*temp_r31); + *temp_r31 = NULL; + HSD_SisLib_804D1124[arg0] = NULL; + } +} + +void HSD_SisLib_803A5FBC(void) +{ + HSD_Archive** var_r30; + SIS** var_r29; + s32 var_r28; + + HSD_SisLib_803A5E70(); + var_r30 = HSD_SisLib_804D1110; + var_r29 = HSD_SisLib_804D1124; + for (var_r28 = 0; var_r28 < 5; var_r28++) { + if (*var_r30 != NULL) { + HSD_SisLib_803A947C(*var_r30); + *var_r30 = NULL; + *var_r29 = NULL; + } + var_r30++; + var_r29++; + } + HSD_Free(HSD_SisLib_804D796C); +} + +void HSD_SisLib_803A6048(u32 arg0) +{ + sislib_UnkAllocData* temp_r3; + HSD_Archive* archive; + + HSD_SisLib_804D7968 = arg0; + HSD_SisLib_804D7974 = NULL; + temp_r3 = (sislib_UnkAllocData*) HSD_MemAlloc((s32) HSD_SisLib_804D7968); + HSD_SisLib_804D7970 = temp_r3; + HSD_SisLib_804D796C = temp_r3; + HSD_SisLib_804D7970->data_0 = NULL; + HSD_SisLib_804D7970->data_1 = + (sislib_UnkAllocReturn*) ((u8*) HSD_SisLib_804D7970 + 0xC); + HSD_SisLib_804D7970->size = HSD_SisLib_804D7968 - 0xC; + HSD_SisLib_804D7978 = NULL; + HSD_SisLib_804D797C = NULL; + archive = HSD_SisLib_804D1110[0]; + archive->header.file_size = 0; + *(u32*) archive->header.version = 0; + HSD_SisLib_804D1110[1] = NULL; + archive->header.pad[0] = 0; + HSD_SisLib_804D1110[2] = NULL; + archive->header.pad[1] = 0; + HSD_SisLib_804D1110[3] = NULL; + archive->data = NULL; + HSD_SisLib_804D1110[4] = NULL; + archive->reloc_info = 0; +} + +void fn_803A60EC(void* arg0) +{ + sislib_UnkAlloc3* var_r4; + var_r4 = HSD_SisLib_804D797C; + while (var_r4 != NULL) { + if (var_r4->x4 == arg0) { + var_r4->x4 = 0U; + return; + } + var_r4 = var_r4->x0; + } +} + +s32 HSD_SisLib_803A611C(u16 arg0, u32 arg1, u16 arg2, u8 arg3, u8 arg4, + u8 arg5, u8 arg6, u32 arg7) +{ + HSD_CObj* temp_r3; + HSD_GObj* temp_r3_2; + HSD_GObj* temp_r6; + s32 var_r31; + sislib_UnkAlloc3* temp_r27; + sislib_UnkAlloc3* var_r11; + sislib_UnkAlloc3* var_r28; + u64 temp_ret; + + var_r28 = NULL; + var_r31 = 0; + var_r11 = HSD_SisLib_804D797C; + while (var_r11 != NULL) { + var_r28 = var_r11; + if (var_r11->xA == arg0) { + var_r31 += 1; + } + var_r11 = var_r11->x0; + } + temp_r27 = HSD_SisLib_803A5798(0x10); + if ((sislib_UnkAlloc3*) HSD_SisLib_804D797C == NULL) { + HSD_SisLib_804D797C = temp_r27; + } + if (var_r28 != NULL) { + var_r28->x0 = temp_r27; + } + temp_r27->x8 = arg2; + temp_r27->xC = arg3; + temp_r27->xD = arg4; + temp_r27->xE = arg5; + temp_r27->xF = arg6; + temp_r27->xA = arg0; + temp_r27->x0 = NULL; + if (arg1 != 0) { + temp_r27->x4 = NULL; + } else { + temp_r27->x4 = GObj_Create(arg2, arg3, arg4); + if (temp_r27->x4 != NULL) { + temp_r3 = HSD_CObjLoadDesc(&HSD_SisLib_8040C4B8); + if (temp_r3 != NULL) { + HSD_CObjSetOrtho(temp_r3, 0.0f, -480.0f, 0.0f, 640.0f); + HSD_GObjObject_80390A70(temp_r27->x4, *HSD_GObj_804D784B, + temp_r3); + GObj_SetupGXLinkMax( + temp_r27->x4, (void (*)(HSD_GObj*, int)) HSD_GObj_803910D8, + arg7); + temp_r27->x4->gxlink_prios = (u64) arg5 << 1; + GObj_InitUserData(temp_r27->x4, (u8) arg2, fn_803A60EC, + temp_r27->x4); + } else { + HSD_GObjPLink_80390228(temp_r27->x4); + temp_r27->x4 = NULL; + } + } + } + return var_r31; +} + +void HSD_SisLib_803A62A0(s32 arg0, HSD_Archive* arg1, char* arg2) +{ + HSD_Archive** temp_r30; + SIS* temp_r3; + SIS* temp_ret; + + HSD_SisLib_803A945C(); + temp_r30 = &HSD_SisLib_804D1110[arg0]; + *temp_r30 = arg1; + if (arg1 == 0U) { + OSReport("Cannot open archive %s", arg1); + OSPanic("sislib.c", 0x24A, ""); + } + temp_ret = HSD_ArchiveGetPublicAddress(*temp_r30, arg2); + temp_r3 = temp_ret; + HSD_SisLib_804D1124[arg0] = temp_r3; + if (temp_r3 == NULL) { + OSReport("Cannot find symbol %s", arg2); + OSPanic("sislib.c", 0x24F, ""); + } +} + +void HSD_SisLib_803A6368(sislib_UnkAllocReturn* arg0, s32 arg1) +{ + SIS** temp_r3; + s32 var_r5; + void* temp_r3_2; + + temp_r3 = (SIS**) HSD_SisLib_804D1124[arg0->x4F]; + if (temp_r3 != NULL) { + arg0->x5C = temp_r3[arg1]; + } + arg0->x60 = NULL; + arg0->x74 = 0.0f; + arg0->x70 = 0.0f; + arg0->x8C = arg0->x30; + arg0->x80.x = arg0->x34.x; + arg0->x80.y = arg0->x34.y; + arg0->x78.x = arg0->x3C.x; + arg0->x78.y = arg0->x3C.y; + arg0->x90 = arg0->x44; + arg0->x92 = arg0->x46; + arg0->x9E = arg0->x4A; + arg0->x9D = arg0->x49; + arg0->x9C = arg0->x48; + arg0->x6C = 0; + arg0->x98 = 0; + arg0->x94 = 0; + arg0->x4B = 0; + temp_r3_2 = arg0->x68; + if (temp_r3_2 != NULL) { + HSD_SisLib_803A594C(temp_r3_2); + } + arg0->x68 = HSD_SisLib_803A5798(0x10); + var_r5 = 0; + arg0->x6E = 0x10; + while (var_r5 < (s32) arg0->x6E) { + // *(arg0->x68 + var_r5) = 0; + var_r5 += 1; + } +} + +static inline void HSD_SisLib_803A6478_inline(u8* arg0, u8* arg1) +{ + u8* var_r3; + u8* var_r4; + u8 temp_r0; + u8 temp_r0_2; + u8 temp_r0_3; + u8 temp_r0_4; + u8 temp_r0_5; + u8 temp_r0_6; + + while (arg1[0] != 0) { + if (arg1[0] >= 0x20U) { + arg0[0] = arg1[0]; + temp_r0_2 = arg1[1]; + arg1 += 2; + arg0[1] = temp_r0_2; + arg0 += 2; + } else { + temp_r0_3 = (arg1++)[0]; + arg0[0] = temp_r0_3; + arg0++; + switch (temp_r0_3) { + case 14: + case 11: + temp_r0_4 = *arg1; + arg1 += 1; + *arg0 = temp_r0_4; + arg0 += 1; + /* fallthrough */ + case 12: + temp_r0_5 = *arg1; + arg1 += 1; + *arg0 = temp_r0_5; + arg0 += 1; + case 5: + arg0[0] = arg1[0]; + temp_r0_6 = arg1[1]; + arg1 += 2; + arg0[1] = temp_r0_6; + arg0 += 2; + } + } + } + arg0[0] = 0; +} + +void HSD_SisLib_803A6478(u8* arg0, u8* arg1) +{ + HSD_SisLib_803A6478_inline(arg0, arg1); +} + +void HSD_SisLib_803A6530(s32 arg0, s32 arg1, s32 arg2) +{ + SIS** temp_r6; + u8* var_r3; + u8* var_r4; + temp_r6 = (SIS**) HSD_SisLib_804D1124[arg0]; + var_r4 = (u8*) temp_r6[arg2]; + var_r3 = (u8*) temp_r6[arg1]; + HSD_SisLib_803A6478_inline(var_r3, var_r4); +} + +void HSD_SisLib_803A660C(s32 arg0, s32 arg1, s32 arg2) +{ + SIS** temp_r6; + u8* var_r3; + u8* var_r4; + u8 temp_r0; + u8 temp_r0_2; + u8 temp_r0_3; + u8 temp_r0_4; + u8 temp_r0_5; + u8 temp_r0_6; + u8 temp_r0_7; + + temp_r6 = (SIS**) HSD_SisLib_804D1124[arg0]; + var_r3 = (u8*) temp_r6[arg1]; + var_r4 = (u8*) temp_r6[arg2]; +#if 0 +loop_15: + temp_r0 = *var_r3; + if (temp_r0 != 0) { + if (temp_r0 >= 0x20U) { + var_r3 += 2; + } else if ((s32) temp_r0 != 0xC) { + if ((s32) temp_r0 < 0xC) { + if ((s32) temp_r0 != 5) { + if (((s32) temp_r0 >= 5) && ((s32) temp_r0 < 0xB)) { + goto block_11; + } + goto block_14; + } + var_r3 += 3; + } else if ((s32) temp_r0 != 0xE) { +block_14: + var_r3 += 1; + } else { +block_11: + var_r3 += 5; + } + } else { + var_r3 += 4; + } + goto loop_15; + } +#endif + HSD_SisLib_803A6478_inline(var_r3, var_r4); +} + +sislib_UnkAllocReturn* HSD_SisLib_803A6754(s8 arg0, s32 arg1) +{ + sislib_UnkAllocData* temp_r3; + sislib_UnkAllocReturn* temp_r30; + sislib_UnkAllocReturn* temp_r3_2; + + temp_r30 = + HSD_SisLib_803A5ACC(arg0, arg1, 0.0f, 0.0f, 0.0f, 640.0f, 480.0f); + temp_r3 = HSD_SisLib_803A5798(0x10); + temp_r30->x64 = temp_r3; + temp_r3_2 = HSD_SisLib_803A5798(0x80); + temp_r3->data_1 = temp_r3_2; + temp_r3->data_0 = (sislib_UnkAllocData*) temp_r3_2; + temp_r3->size = 0x80; + // @todo: This being a byte store means one of my assumptions is wrong; + // maybe this is a different struct. + *(u8*) &temp_r3->data_0->data_0 = 0; + // @todo: Do any other Data struct usages have a 0xC member? + *(&temp_r3->size + 1) = 0; + HSD_SisLib_803A6368(temp_r30, 0); + temp_r30->x5C = (SIS*) temp_r3->data_1; + return temp_r30; +} + +s32 HSD_SisLib_803A67EC(u8* data, u8* string) +{ + s32 sp10; + s32 temp_r10_2; + s32 temp_r10_3; + s32 temp_r10_4; + s32 temp_r8_2; + s32 temp_r9; + s32 temp_r9_10; + s32 temp_r9_2; + s32 temp_r9_3; + s32 temp_r9_4; + s32 temp_r9_5; + s32 temp_r9_6; + s32 temp_r9_7; + s32 temp_r9_8; + s32 temp_r9_9; + s32 var_ctr; + s32 var_r10; + s32 var_r10_3; + s32 var_r10_4; + s32 var_r10_5; + s32 var_r11; + s32 var_r31_2; + s32 var_r5; + s32 var_r9; + u8* temp_r8; + u8* var_r6; + u32* var_r12; + u8 temp_r10; + u8 var_r10_2; + u8 var_r31; + void* temp_r11; + + var_r6 = string; + sp10 = 0; + var_r9 = 0; + var_r5 = 0; +loop_42: + if (var_r5 < 0x80) { + temp_r8 = &string[var_r5]; + temp_r10 = (u8) *temp_r8; + if (temp_r10 == '\0') { + if (sp10 != 0) { + data[var_r9] = 0xB; + var_r9 += 1; + } + } else { + if (temp_r10 == ' ') { + var_r10 = sp10; + if (var_r10 == 0) { + data[var_r9++] = 0xA; + data[var_r9++] = 0xF4; + data[var_r9++] = 0x0; + var_r10_3 += 1; + data[var_r9++] = 0x0; + data[var_r9++] = 0x0; + var_r9++; + } + sp10 = var_r10; + var_r10_2 = 0x81; + var_r31 = 0x40; + } else if (temp_r10 == '"') { + data[var_r9] = 0xB; + var_r9 += 1; + sp10 = 0; + var_r10_2 = 0x81; + var_r31 = 0x68; + } else if (temp_r10 == '\'') { + data[var_r9] = 0xB; + var_r9 += 1; + sp10 = 0; + var_r10_2 = 0x81; + var_r31 = 0x66; + } else if (temp_r10 == ',') { + data[var_r9] = 0xB; + var_r9 += 1; + sp10 = 0; + var_r10_2 = 0x81; + var_r31 = 0x43; + } else if (temp_r10 == '-') { + data[var_r9] = 0xB; + var_r9 += 1; + sp10 = 0; + var_r10_2 = 0x81; + var_r31 = 0x7C; + } else if (temp_r10 == '.') { + var_r10_3 = sp10; + if (var_r10_3 == 0) { +#if 0 + data[var_r9] = 0xA; + temp_r9_4 = var_r9 + 1; + data[var_r9].unk1 = 0xF4; + temp_r9_5 = temp_r9_4 + 1; + data[temp_r9_4].unk1 = 0; + temp_r9_6 = temp_r9_5 + 1; + var_r10_3 += 1; + data[temp_r9_5].unk1 = 0; + data[temp_r9_6].unk1 = 0; + var_r9 = temp_r9_6 + 1 + 1; +#endif + } + sp10 = var_r10_3; + var_r10_2 = 0x81; + var_r31 = 0x44; + } else if ((temp_r10 >= '0') && (temp_r10 <= '9')) { + var_r11 = sp10; + var_r10_4 = var_r9; + if (var_r11 == 0) { +#if 0 + data[var_r10_4] = 0xA; + temp_r10_2 = var_r10_4 + 1; + data[var_r10_4].unk1 = 0xF4; + temp_r10_3 = temp_r10_2 + 1; + data[temp_r10_2].unk1 = 0; + temp_r10_4 = temp_r10_3 + 1; + var_r11 += 1; + data[temp_r10_3].unk1 = 0; + data[temp_r10_4].unk1 = 0; + var_r10_4 = temp_r10_4 + 1 + 1; +#endif + } + sp10 = var_r11; + var_r9 = var_r10_4; + var_r10_2 = 0x82; + var_r31 = (u8) *temp_r8 + 0x1F; + } else if (temp_r10 == ':') { + var_r10_5 = sp10; + if (var_r10_5 == 0) { +#if 0 + data[var_r9] = 0xA; + temp_r9_7 = var_r9 + 1; + data[var_r9].unk1 = 0xF4; + temp_r9_8 = temp_r9_7 + 1; + data[temp_r9_7].unk1 = 0; + temp_r9_9 = temp_r9_8 + 1; + var_r10_5 += 1; + data[temp_r9_8].unk1 = 0; + data[temp_r9_9].unk1 = 0; + var_r9 = temp_r9_9 + 1 + 1; +#endif + } + sp10 = var_r10_5; + var_r10_2 = 0x81; + var_r31 = 0x46; + } else if ((temp_r10 >= 'A') && (temp_r10 <= 'Z')) { + data[var_r9] = 0xB; + sp10 = 0; + var_r9 += 1; + var_r10_2 = 0x82; + var_r31 = (u8) *temp_r8 + 0x1F; + } else if ((temp_r10 >= 'a') && (temp_r10 <= 'z')) { + data[var_r9] = 0xB; + sp10 = 0; + var_r9 += 1; + var_r10_2 = 0x82; + var_r31 = (u8) *temp_r8 + 0x20; + } else { + data[var_r9] = 0xB; + var_r9 += 1; + sp10 = 0; + var_r10_2 = (u8) string[var_r5]; + var_r5 += 1; + var_r31 = var_r6[1]; + var_r6 += 1; + } + var_ctr = 0x11F; + var_r12 = lbl_8040C8C0; + var_r31_2 = 0; +#if 0 +loop_37: + if ((var_r10_2 == (u8) var_r12->unk0) && (var_r31 == (u8) var_r12->unk1)) { + temp_r11 = HSD_SisLib_8040C680 + (var_r31_2 * 2); + temp_r9_10 = var_r9 + 1; + data[var_r9] = temp_r11->unk0; + temp_r8_2 = temp_r9_10; + var_r9 = temp_r9_10 + 1; + data[temp_r8_2] = temp_r11->unk1; + } else { + var_r12 += 2; + var_r31_2 += 1; + var_ctr -= 1; + if (var_ctr != 0) { + goto loop_37; + } + } +#endif + var_r5 += 1; + var_r6 += 1; + goto loop_42; + } + } + data[var_r9] = 0; + return var_r9; +} + +void HSD_SisLib_803A6B98(sislib_UnkAllocReturn* arg0, void* arg1, ...) +{ + s8 sp10C; + sislib_UnkAllocReturn** sp88; + f64* sp84; + s32 sp80; + f64 sp60; + f64 sp58; + f64 sp50; + f64 sp48; + f64 sp40; + f64 sp38; + f64 sp30; + f64 sp28; + s32 sp24; + s32 sp20; + s32 sp1C; + s32 sp18; + s32 sp14; + s32 sp10; + void* spC; + sislib_UnkAllocReturn* sp8; + s16 temp_r0_3; + s16 temp_r7; + s32 temp_r3_16; + s32 var_ctr_2; + s32 var_r29; + s32 var_r4_2; + s32 var_r7; + sislib_UnkAllocData* temp_r30; + sislib_UnkAllocData* temp_r3_10; + sislib_UnkAllocData* temp_r3_11; + sislib_UnkAllocData* temp_r3_12; + sislib_UnkAllocData* temp_r3_13; + sislib_UnkAllocData* temp_r3_14; + sislib_UnkAllocData* temp_r3_15; + sislib_UnkAllocData* temp_r3_17; + sislib_UnkAllocData* temp_r3_18; + sislib_UnkAllocData* temp_r3_2; + sislib_UnkAllocData* temp_r3_3; + sislib_UnkAllocData* temp_r3_4; + sislib_UnkAllocData* temp_r3_5; + sislib_UnkAllocData* temp_r3_6; + sislib_UnkAllocData* temp_r3_7; + sislib_UnkAllocData* temp_r3_8; + sislib_UnkAllocData* temp_r3_9; + sislib_UnkAllocData* temp_r4_3; + sislib_UnkAllocData* temp_r5; + sislib_UnkAllocData* temp_r5_2; + sislib_UnkAllocData* temp_r5_3; + sislib_UnkAllocData* temp_r5_4; + sislib_UnkAllocData* temp_r5_5; + sislib_UnkAllocData* temp_r5_6; + sislib_UnkAllocData* temp_r5_7; + sislib_UnkAllocData* temp_r5_8; + sislib_UnkAllocReturn* temp_r31; + u8* temp_r3; + u8* var_r4; + u8* var_r5; + u32 temp_r0; + u32 temp_r4; + u32 var_ctr; + u8* var_r3; + u8* var_r5_2; + u8 temp_r0_2; + u8 temp_r4_2; + u8 temp_r6; + u8* playhead; + va_list args; + + // @todo: what size is this? + u8 sp8C; + + var_r29 = 0; // some type of size + temp_r30 = arg0->x64; + sp8C = 0; + if (arg1) { + // @todo: is this the correct usage of vaargs? + u8 buffer[256]; + va_start(args, arg1); + vsprintf((char*) buffer, (const char*) -1, args); + va_end(args); + var_r29 = HSD_SisLib_803A67EC(&sp8C, buffer); + } + + // some sort of copy of a dynamically-sized struct + { + // It would appear that data_1 is allocated right after data_0 in + // memory. + u8* temp_r31 = (u8*) temp_r30->data_1; + temp_r4 = temp_r30->size; + temp_r0 = var_r29 + (((u8*) temp_r30->data_0 - temp_r31) + 0x11); + if (temp_r4 < temp_r0) { + // make sure that this unsigned subtract doesn't overflow? + temp_r30->size = + temp_r4 + ((((u32) (temp_r0 - temp_r4) >> 7U) + 1) << 7); + temp_r3 = HSD_SisLib_803A5798((s32) temp_r30->size); + // clearly a handwritten memory copy + { + var_r5 = temp_r31; + var_r4 = temp_r3; + var_r7 = 0; + while (var_r7 < (s32) (((u8*) temp_r30->data_0 - + (u8*) temp_r30->data_1) + + 1)) + { + temp_r0_2 = *var_r5; + var_r7 += 1; + var_r5 += 1; + *var_r4 = temp_r0_2; + var_r4 += 1; + } + } + temp_r30->data_1 = (sislib_UnkAllocReturn*) temp_r3; + arg0->x5C = (SIS*) temp_r3; + temp_r30->data_0 = + (sislib_UnkAllocData*) (temp_r3 + + ((u8*) temp_r30->data_0 - temp_r31)); + HSD_SisLib_803A594C(temp_r31); + } + } + + playhead = (u8*) temp_r30; + *(playhead++) = 7; + var_r4_2 = 0; + + // @note: Is it just assuming these are always passed in? + temp_r7 = *((s16*) args + 8); + *((s16*) playhead++) = temp_r7 >> 8; + *playhead++ = temp_r7; + + temp_r0_3 = *((s16*) arg1 + 9); + // *((s16 *)playhead)++ = temp_r0_3 >> 8; + *playhead++ = temp_r0_3; + + *playhead++ = 0xC; + + *playhead++ = arg0->x30.x; + *playhead++ = arg0->x30.y; + *playhead++ = arg0->x30.z; + *playhead++ = 0xE; + *playhead++ = arg0->x30.w; + *playhead++ = (u8) (s32) (arg0->x34.x); + *playhead++ = (u8) (s32) (256.0f * arg0->x34.x); + *playhead++ = (u8) (s32) (arg0->x34.y); + *playhead++ = (u8) (s32) (256.0f * arg0->x34.y); + + if (var_r29 > 0) { + /* + This copies sets of 8 bytes individually, presumably from + whatever HSD_SisLib_803A67EC returned. The second part of + the loop copies any remaining bytes that aren't modulo 8. + Maybe they had intended for the first part to be a "fast" + copy, only for the compiler to output essentially the + same operations for both? + */ + temp_r3_16 = var_r29 - 8; + if (var_r29 > 8) { + var_ctr = (u32) (temp_r3_16 + 7) >> 3U; + var_r3 = &sp8C; + if (temp_r3_16 > 0) { + do { + int i; + var_r4_2 += 8; + for (i = 0; i < 8; i++) { + *playhead++ = var_r3[i]; + } + var_r3 += 8; + var_ctr -= 1; + } while (var_ctr != 0); + } + } + var_r5_2 = &sp8C + var_r4_2; + var_ctr_2 = var_r29 - var_r4_2; + if (var_r4_2 < var_r29) { + do { + *playhead++ = *var_r5_2++; + var_ctr_2 -= 1; + } while (var_ctr_2 != 0); + } + } + *playhead++ = 0xF; + *playhead++ = 0xD; + *playhead = 0; + *((s32*) playhead + 2) = *((s32*) playhead + 2) + 1; +} + +u8* fn_803A6FEC(u8* arg0, s32 arg1, s32* arg2) +{ + s32 var_r4; + u8 var_r4_2; + u8* var_r3; + u8* var_r6; + u8 temp_r0; + u8 temp_r0_2; + + for (;;) { + switch (*arg0) { + case 0: + return NULL; + case 12: + arg0 += 3; + case 11: + case 13: + case 15: + break; + case 7: + arg1 -= 1; + if (arg1 < 0) { + goto end; + } + /* fallthrough */ + case 10: + case 14: + arg0 += 4; + break; + default: + arg0 += 1; + break; + } + arg0 += 1; + } +end: + if (arg2 != NULL) { + *arg2 = 0; + var_r6 = arg0 + 0xE; + do { + var_r4_2 = 0; + if (*var_r6 >= 32) { + var_r4_2 = 2; + } else if (*var_r6 == 10) { + var_r4_2 = 5; + } else if (*var_r6 == 11) { + var_r4_2 = 1; + } + *arg2 += var_r4_2; + var_r6 += var_r4_2; + } while (var_r4_2 != 0); + } + return arg0; +} + +void HSD_SisLib_803A746C(sislib_UnkAllocReturn* arg0, s32 arg1, f32 arg2, + f32 arg3) +{ + s16 temp_r0; + s16 temp_r0_2; + u8* temp_r3; + u8* temp_r3_2; + + temp_r3 = fn_803A6FEC((u8*) arg0->x5C, arg1, NULL); + if (temp_r3 != NULL) { + temp_r0 = (s16) arg2; + temp_r0_2 = (s16) arg3; + temp_r3_2 = temp_r3 + 1; + temp_r3_2[0] = (u8) (temp_r0 >> 8); + temp_r3_2[1] = (u8) temp_r0; + temp_r3_2[2] = (u8) (temp_r0_2 >> 8); + temp_r3_2[3] = (u8) temp_r0_2; + } +} + +void HSD_SisLib_803A74F0(sislib_UnkAllocReturn* arg0, s32 arg1, u8* arg2) +{ + u8* temp_r3; + u8* temp_r3_2; + void* temp_r31; + + temp_r3 = fn_803A6FEC((u8*) arg0->x5C, arg1, NULL); + if (temp_r3 != NULL) { + temp_r3_2 = temp_r3 + 5; + temp_r3_2[1] = arg2[0]; + temp_r3_2[2] = arg2[1]; + temp_r3_2[3] = arg2[2]; + } +} + +void HSD_SisLib_803A8134(void* arg0, sislib_UnkAllocReturn* arg1, f32* arg2, + f32* arg3) +{ + SIS* temp_r4; + TextGlyphTexture* var_r29; + f32 temp_f0; + f32 temp_f0_2; + f32 temp_f24; + f32 temp_f25; + f32 temp_f26; + u16 temp_r0; + u16 temp_r27; + u16 temp_r3_3; + u16 var_r5; + u32 temp_r3_2; + u8* temp_r4_3; + u8 temp_r3; + u8 var_r28; + u8* temp_r4_2; + u8* var_r23; + PAD_STACK(8); + + var_r23 = arg0; + temp_f26 = arg1->x80.x; + temp_f25 = arg1->x80.y; + temp_f24 = arg1->x78.x; + var_r28 = arg1->x9D; + temp_r4 = HSD_SisLib_804D1124[arg1->x4F]; + temp_r27 = arg1->x6C; + if (temp_r4 != NULL) { + var_r29 = temp_r4->textures; + } + *arg2 = 0.0f; + *arg3 = 32.0f * arg1->x80.y; +loop_3: + temp_r3 = *var_r23; + switch (temp_r3) { + case 0: + temp_r3_2 = HSD_SisLib_803A7F0C(arg1, 0x85); + if (temp_r3_2 != 0U) { + *var_r23 = temp_r3_2 + 4; + block_33: + var_r23 += 1; + goto loop_3; + } + break; + case 9: + HSD_SisLib_803A7684(arg1, *var_r23, 0x85U); + /* fallthrough */ + case 8: + var_r23 = var_r23 - 1; + goto block_33; + case 14: + HSD_SisLib_803A7684(arg1, *var_r23, 0x83U); + arg1->x80.x = *((f32*) ((u16*) var_r23 + 1)) * 0.00390625f; + temp_r0 = *(u16*) (var_r23 + 3); + var_r23 += 4; + arg1->x80.y = (f32) temp_r0 * 0.00390625f; + goto block_33; + case 15: + HSD_SisLib_803A7F0C(arg1, 0x83); + goto block_33; + case 6: + var_r23 += 4; + goto block_33; + case 10: + if (((sislib_UnkAllocData*) arg1->x64 == NULL) || ((s16) var_r28 == 0)) + { + HSD_SisLib_803A7684(arg1, *var_r23, 0x81U); + arg1->x78.x = (f32) (s16) * (var_r23 + 1) * 0.00390625f; + } + var_r23 += 4; + goto block_33; + case 11: + if (((sislib_UnkAllocData*) arg1->x64 == NULL) || ((s16) var_r28 == 0)) + { + HSD_SisLib_803A7F0C(arg1, 0x81); + } + goto block_33; + case 12: + var_r23 += 3; + goto block_33; + case 5: + var_r23 += 2; + goto block_33; + case 22: + var_r28 = 1; + goto block_33; + case 23: + var_r28 = 0; + goto block_33; + case 26: + *arg2 += arg1->x80.x * (16.0f + arg1->x78.x); + temp_f0 = 32.0f * arg1->x80.y; + if (*arg3 < temp_f0) { + *arg3 = temp_f0; + } + goto block_33; + default: + if (temp_r3 >= 0x20U) { + *arg2 += arg1->x80.x * (32.0f + arg1->x78.x); + if ((s16) var_r28 != 0) { + temp_r3_3 = (u16) *var_r23; + if (temp_r3_3 < 0x4000U) { + temp_r4_2 = (u8*) &HSD_SisLib_8040CB00 + + (((temp_r3_3 - 0x2000) * 2) & 0x1FFFE); + *arg2 = -((arg1->x80.x * + (f32) (*temp_r4_2 + (temp_r4_2[1] - 2))) - + *arg2); + } else { + temp_r4_3 = + &var_r29->data[((temp_r3_3 - 0x4000) * 2) & 0x1FFFE]; + *arg2 = -((arg1->x80.x * + (f32) (*temp_r4_3 + (temp_r4_3[1] - 2))) - + *arg2); + } + } + temp_f0_2 = 32.0f * arg1->x80.y; + if (*arg3 < temp_f0_2) { + *arg3 = temp_f0_2; + } + var_r23 += 1; + } + goto block_33; + } + *arg2 -= arg1->x78.x; + arg1->x80.x = temp_f26; + arg1->x80.y = temp_f25; + arg1->x78.x = temp_f24; + arg1->x6C = temp_r27; + var_r5 = arg1->x6C; +loop_36: + if ((s32) var_r5 < (s32) arg1->x6E) { + *((u8*) arg1->x68 + var_r5) = 0; + var_r5 += 1; + goto loop_36; + } +} + +void static inline HSD_SisLib_803A7F0C_inline(sislib_UnkAllocReturn* arg0, + s32 arg1, s32* var_r4, + u32* var_r5, s32* var_r0) +{ + s32* temp_r8; + u8 temp_r7; + s32 temp_r6; + s32 temp_r10; + s32 temp_r11; + s32 temp_r9; + temp_r9 = arg1 & 0x80; + temp_r11 = arg1 & 0x7F; + while (*var_r5 >= 0) { + temp_r8 = (s32*) arg0->x68; + temp_r7 = *(temp_r8 + *var_r5); + temp_r6 = temp_r7 & 0x7F; + temp_r10 = temp_r7 & 0x80; + switch (temp_r6) { /* irregular */ + case 1: + *var_r5 -= 4; + if (temp_r11 == 1) { + arg0->x78.x = (f32) * (temp_r8 + *var_r5) * 0.00390625f; + arg0->x78.y = (f32) * (temp_r8 + (*var_r5 + 2)) * 0.00390625f; + if (temp_r9 == temp_r10) { + *var_r4 = 5; + } + } else { + break; + } + return; + case 2: + *var_r5 -= 3; + if (temp_r11 == 2) { + arg0->x8C.x = ((U8Vec4*) arg0->x68 + *var_r5)->x; + arg0->x8C.y = ((U8Vec4*) arg0->x68 + *var_r5)->y; + arg0->x8C.z = ((U8Vec4*) arg0->x68 + *var_r5)->z; + if (temp_r9 == temp_r10) { + *var_r4 = 4; + } + } else { + break; + } + return; + case 3: + *var_r5 -= 4; + if (temp_r11 == 3) { + arg0->x80.x = (f32) * (temp_r8 + *var_r5) * 0.00390625f; + arg0->x80.y = (f32) * (temp_r8 + (*var_r5 + 2)) * 0.00390625f; + if (temp_r9 == temp_r10) { + *var_r4 = 5; + } + } else { + break; + } + return; + case 4: + *var_r5 -= 1; + if (temp_r11 == 4) { + arg0->x9E = *(temp_r8 + *var_r5); + if (temp_r9 == temp_r10) { + *var_r4 = 2; + } + } else { + break; + } + return; + case 5: + *var_r5 -= 4; + if (temp_r11 == 5) { + *var_r0 = *(temp_r8 + *var_r5); + if (temp_r9 == temp_r10) { + *var_r4 = 5; + } + } else { + break; + } + return; + } + *var_r5 -= 1; + } +} + +s32 HSD_SisLib_803A7F0C(sislib_UnkAllocReturn* arg0, s32 arg1) +{ + s32 temp_r7_2; + s32 var_r0; + s32 var_r4; + u16 temp_r6_2; + u32 var_r5; + + var_r5 = arg0->x6C; + var_r0 = 0; + var_r4 = 0; + HSD_SisLib_803A7F0C_inline(arg0, arg1, &var_r4, &var_r5, &var_r0); + if (var_r4 != 0) { + while ((s32) (var_r5 + var_r4) < (s32) arg0->x6C) { + *((s32*) arg0->x68 + var_r5) = + *((s32*) arg0->x68 + var_r5 + var_r4); + var_r5 += 1; + } + while ((s32) var_r5 < (s32) arg0->x6C) { + *((s32*) arg0->x68 + var_r5) = 0; + var_r5 += 1; + } + arg0->x6C -= var_r4; + } + return var_r0; +} + +void HSD_SisLib_803A84BC(HSD_GObj* gobj, sislib_UnkAllocReturn* arg1) +{ + // clang-format off + sislib_UnkAllocReturn *var_r31; + Mtx m; + TextGlyphTexture *textures = NULL; + TextKerning *kerning = NULL; + + Vec2 min; + Vec2 max; + + u8 spB8; + u8 spB9; + u8 spBA; + u8 spBB; + u8 spBC; + f32 spC0; + Vec2 spC4; + Vec2 spCC; + u16 var_r23; + u16 var_r19; + u32 var_r28; + u16 temp_r14; + u8 temp_r22; + + u8 *data = &HSD_SisLib_8040CD40; + + + if (gobj != NULL) { + if ((void *)arg1 == (void *)2) { + var_r31 = gobj->user_data; + } else { + var_r31 = NULL; + } + } else { + var_r31 = arg1; + } + if (var_r31->x4D == 0 && var_r31->x5C != NULL) { + u8 *var_r30 = (u8 *)var_r31->x5C; + if (gobj != NULL) { + SIS *temp_r3 = HSD_SisLib_804D1124[var_r31->x4F]; + if (temp_r3 != NULL) { + kerning = temp_r3->kerning; + textures = temp_r3->textures; + } + } + if (gobj != NULL) { + if (var_r31->x4C != 0) { + HSD_StateSetZMode(GX_TRUE, GX_LEQUAL, GX_FALSE); + } else { + HSD_StateSetZMode(GX_FALSE, GX_NEVER, GX_FALSE); + } + HSD_CObjGetViewingMtx(HSD_CObjGetCurrent(), (MtxPtr)&m); + } else { + GXSetZMode(0U, 0U, 0U); + GXSetViewport(0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f); + GXSetScissor(0, 0, 0x280, 0x1E0); + C_MTXOrtho((MtxPtr)&m, 0.0f, -480.0f, 0.0f, 640.0f, 0.0f, 2.0f); + GXSetProjection((MtxPtr)&m, 0); + m[0][0] = 1.0f; + m[0][1] = 0.0f; + m[0][2] = 0.0f; + m[0][3] = 0.0f; + m[1][0] = 0.0f; + m[1][1] = 1.0f; + m[1][2] = 0.0f; + m[1][3] = 0.0f; + m[2][0] = 0.0f; + m[2][1] = 0.0f; + m[2][2] = 1.0f; + m[2][3] = -1.0f; + } + GXSetCurrentMtx(0); + GXLoadPosMtxImm((MtxPtr)&m, 0); + GXSetTexCoordGen2(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, GX_DISABLE, GX_PTIDENTITY); + if (gobj != NULL) { + HSD_StateSetNumChans(0); + } else { + GXSetNumChans(0U); + } + GXClearVtxDesc(); + GXSetCullMode(GX_CULL_NONE); + GXSetNumTexGens(1U); + GXSetNumTevStages(1U); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_RGBA6, 0); + GXSetVtxDesc(GX_VA_POS, GX_DIRECT); + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_POS_XYZ, GX_RGBA6, 0); + GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); + GXSetAlphaCompare(GX_GREATER, 0, GX_AOP_OR, GX_GREATER, GX_NEVER); + GXSetColorUpdate(GX_ENABLE); + GXSetAlphaUpdate(GX_DISABLE); + if (gobj != NULL) { + if (var_r31->x58 != NULL) { + var_r31->x58(gobj); + } + } + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); + GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_FALSE, GX_TEVPREV); + GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_FALSE, GX_TEVPREV); + // @todo: What is this first quad for? + if (var_r31->x2C.w != 0) { + f32 temp_f4 = var_r31->x0; + f32 temp_f5 = var_r31->x4; + min.x = temp_f4; + min.y = temp_f5; + max.x = (var_r31->xC * var_r31->x24.x) + temp_f4; + max.y = (var_r31->x10 * var_r31->x24.y) + temp_f5; + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0); + GXSetTevColor(GX_TEVREG0, *(GXColor *)&var_r31->x2C); + GXBegin(GX_QUADS, GX_VTXFMT0, 4U); + // @note: could be inlined + { + f32 temp_f2 = var_r31->x8; + f32 temp_f3 = -min.y; + f32 temp_f4_2 = -max.y; + GXPosition3f32(min.x, temp_f3, temp_f2); + GXTexCoord2f32(0.0F, 0.0F); + GXPosition3f32(max.x, temp_f3, temp_f2); + GXTexCoord2f32(1.0F, 0.0F); + GXPosition3f32(max.x, temp_f4_2, temp_f2); + GXTexCoord2f32(1.0F, 1.0F); + GXPosition3f32(min.x, temp_f4_2, temp_f2); + GXTexCoord2f32(1.0F, 1.0F); + } + } + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_A0, GX_CA_ZERO); + if (var_r31->x4E != 0) { + min.x = (var_r31->x14.z * var_r31->x24.x) + var_r31->x0; + max.x = (var_r31->x24.x * (var_r31->xC - var_r31->x14.w)) + var_r31->x0; + min.y = (var_r31->x14.x * var_r31->x24.y) + var_r31->x4; + max.y = (var_r31->x24.y * (var_r31->x10 - var_r31->x14.y)) + var_r31->x4; + } + if (var_r31->x64 != NULL) { + var_r31->x78.x = var_r31->x3C.x; + var_r31->x78.y = var_r31->x3C.y; + // interesting pattern... is there a U8Vec3? + var_r31->x9E = var_r31->x4A; + var_r31->x9D = var_r31->x49; + var_r31->x9C = var_r31->x48; + } + { + f32 sp60; + f32 sp64 = 0; + f64 spD8 = 16.0; + + u32 var_r26 = 0U; + temp_r22 = var_r31->x9D; + var_r31->x74 = 0.0f; + spCC = var_r31->x80; + spBC = var_r31->x8C.x; + spBB = var_r31->x8C.y; + spBA = var_r31->x8C.z; + spC4.y = var_r31->x80.y; + spC4.x = var_r31->x78.x; + spB8 = var_r31->x9E; + spC0 = var_r31->x78.y; + spB9 = var_r31->x9C; + var_r23 = var_r31->x90; + var_r19 = var_r31->x92; + var_r28 = var_r31->x98; + temp_r14 = var_r31->x6C; + // this is the compare for the loop + while ((var_r30 != var_r31->x60) || ((u8) var_r31->x4B == 0)) { + if ((var_r30 == var_r31->x60) && var_r31->x94) { + var_r31->x94--; + } else { + u32 temp_r3_4; + s32 var_r3; + f32 temp_f0; + s16 temp_r0_4; + u8 temp_r0_2 = *var_r30; + switch (*var_r30) { + case 0: + temp_r3_4 = HSD_SisLib_803A7F0C(var_r31, 5); + if (temp_r3_4 != 0U) { + *(u32 *)var_r30 = temp_r3_4 + 4; + } + break; + case 1: + var_r31->x60 = NULL; + var_r3 = 0; + var_r31->x8C = var_r31->x30; + var_r31->x80.x = var_r31->x34.x; + var_r31->x80.y = var_r31->x34.y; + var_r31->x78.x = var_r31->x3C.x; + var_r31->x78.y = var_r31->x3C.y; + var_r31->x90 = var_r31->x44; + var_r31->x92 = var_r31->x46; + var_r31->x9E = var_r31->x4A; + var_r31->x9D = var_r31->x49; + var_r31->x9C = var_r31->x48; + var_r31->x94 = 0U; + var_r31->x4B = 0U; + while (var_r3 < (s32) var_r31->x6E) { + *((u8 *)var_r31->x68 + var_r3) = 0; + var_r3 += 1; + } + var_r31->x6C = 0; + /* fallthrough */ + case 2: + var_r31->x98 = 0; + var_r30 += 1; + var_r31->x5C = (SIS *)var_r30; + break; + case 3: + if (var_r26 == 0U) { + sp60 = 32.0f * var_r31->x80.x; + } + var_r26 = 0U; + var_r31->x74 = (f32) ((var_r31->x24.x * ((var_r31->x80.x * var_r31->x78.y) + sp60)) + var_r31->x74); + if (var_r28 != 0U) { + var_r28 -= 1; + } else { + var_r31->x98 = (u32) (var_r31->x98 + 1); + var_r31->x94 = (u32) var_r19; + var_r31->x60 = (void *) (var_r30 + 1); + } + break; + case 4: + if (var_r28 != 0U) { + var_r28 -= 1; + } else { + var_r31->x98 = (u32) (var_r31->x98 + 1); + var_r31->x4B = 1U; + var_r31->x60 = (void *) (var_r30 + 1); + } + break; + case 5: + if (var_r28 != 0U) { + var_r28 -= 1; + } else { + var_r31->x98 = (u32) (var_r31->x98 + 1); + var_r31->x94 = *((u8 *)var_r30 + 1); + var_r31->x60 = (void *) (var_r30 + 3); + } + var_r30 += 2; + break; + case 6: + var_r23 = *((u8 *)var_r30 + 1); + var_r19 = *((u8 *)var_r30 + 3); + var_r30 += 4; + break; + case 7: + var_r26 = 1U; + // HSD_SisLib_803A8134(); + temp_f0 = (f32) *((u8 *)var_r30 + 1); + if (((u8) var_r31->x9C == 1) && (var_r31->xC < sp64) != 0) { + var_r31->x88 = (f32) (var_r31->xC / sp64); + } else { + var_r31->x88 = 1.0f; + } + switch ((s32) var_r31->x9E) { + case 1: + var_r31->x70 = (f32) -((0.5f * (sp64 * var_r31->x88)) - temp_f0); + break; + case 2: + var_r31->x70 = (f32) -((sp64 * var_r31->x88) - temp_f0); + break; + default: + var_r31->x70 = temp_f0; + break; + } + temp_r0_4 = *((u8 *)var_r30 + 3); + var_r30 += 4; + var_r31->x74 = (f32) ((f32) temp_r0_4 * var_r31->x24.y); + break; + case 9: + HSD_SisLib_803A7684(var_r31, *var_r30, 5U); + /* fallthrough */ + case 8: + var_r30 -= 4; + break; + case 10: + if (((u32) var_r31->x64 == 0U) || (temp_r22 == 0)) { + HSD_SisLib_803A7684(var_r31, *var_r30, 1U); + var_r31->x78.x = (f32) ((f32) (s16)var_r30[1] * 0.00390625f); + var_r31->x78.y = (f32) ((f32) (s16)var_r30[3] * 0.00390625f); + } + var_r30 += 4; + break; + case 11: + if (((u32) var_r31->x64 == 0U) || (temp_r22 == 0)) { + HSD_SisLib_803A7F0C(var_r31, 1); + } + break; + case 12: + HSD_SisLib_803A7684(var_r31, *var_r30, 2U); + var_r31->x8C.x = var_r30[1]; + var_r31->x8C.y = var_r30[2]; + var_r31->x8C.z = var_r30[3]; + var_r30 += 3; + break; + case 13: + HSD_SisLib_803A7F0C(var_r31, 2); + break; + case 14: + HSD_SisLib_803A7684(var_r31, *var_r30, 3U); + var_r31->x80.x = (f32) ((f32) (s16)var_r30[1] * 0.00390625f); + var_r31->x80.y = (f32) ((f32) (s16)var_r30[2] * 0.00390625f); + var_r30 += 4; + break; + case 15: + HSD_SisLib_803A7F0C(var_r31, 3); + break; + case 16: + HSD_SisLib_803A7684(var_r31, *var_r30, 4U); + var_r31->x9E = 1U; + break; + case 18: + HSD_SisLib_803A7684(var_r31, *var_r30, 4U); + var_r31->x9E = 0U; + break; + case 20: + HSD_SisLib_803A7684(var_r31, *var_r30, 4U); + var_r31->x9E = 2U; + break; + case 17: + case 19: + case 21: + HSD_SisLib_803A7F0C(var_r31, 4); + break; + case 22: + var_r31->x9D = 1U; + break; + case 23: + var_r31->x9D = 0U; + break; + case 24: + var_r31->x9C = 1U; + break; + case 25: + var_r31->x9C = 0U; + break; + case 26: + if (var_r26 == 0U) { + var_r26 += 1; + // HSD_SisLib_803A8134(); + if (((u8) var_r31->x9C == 1) && (var_r31->xC < sp64)) { + var_r31->x70 = 0.0f; + var_r31->x88 = (f32) (var_r31->xC / sp64); + } else { + var_r31->x88 = 1.0f; + switch ((s32) var_r31->x9E) { + case 1: + var_r31->x70 = (f32) (0.5f * (var_r31->xC - sp64)); + break; + case 2: + var_r31->x70 = (f32) (var_r31->xC - sp64); + break; + default: + var_r31->x70 = 0.0f; + break; + } + } + } + var_r31->x70 = (f32) (((f64) var_r31->x88 * ((f64) var_r31->x80.x * + (spD8 + (f64) var_r31->x78.x))) + (f64) var_r31->x70); + if (var_r28 != 0U) { + var_r28 -= 1; + } else { + var_r31->x98 = (u32) (var_r31->x98 + 1); + var_r31->x94 = (u32) var_r23; + var_r31->x60 = (void *) (var_r30 + 1); + } + break; + default: + if (temp_r0_2 >= 0x20U) { + u16 temp_r24; + s32 var_r25; + f32 temp_f2_3; + f32 var_f31; + if (var_r26 == 0U) { + var_r26 += 1; + // HSD_SisLib_803A8134(); + if (((u8) var_r31->x9C == 1) && (var_r31->xC < sp64)) { + var_r31->x70 = 0.0f; + var_r31->x88 = (f32) (var_r31->xC / sp64); + } else { + var_r31->x88 = 1.0f; + switch (var_r31->x9E) { + case 1: + var_r31->x70 = (f32) (0.5f * (var_r31->xC - sp64)); + break; + case 2: + var_r31->x70 = (f32) (var_r31->xC - sp64); + break; + default: + var_r31->x70 = 0.0f; + break; + } + } + } + temp_r24 = *(u16 *)var_r30; + if (temp_r24 < 0x4000U) { + var_r25 = temp_r24 - 0x2000; + } else { + var_r25 = temp_r24 - 0x4000; + } + temp_f2_3 = var_r31->x24.x; + var_f31 = (var_r31->x70 * temp_f2_3) + var_r31->x0; + if ((u8) var_r31->x9D != 0) { + if (temp_r24 < 0x4000U) { + var_f31 = -((temp_f2_3 * (var_r31->x80.x * (f32) (*(&HSD_SisLib_8040CB00 + ((var_r25 * 2) & 0x1FFFE)) - 1))) - var_f31); + } else { + var_f31 = -((temp_f2_3 * (var_r31->x80.x * (f32) (textures->data[(var_r25 * 2) & 0x1FFFE] - 1))) - var_f31); + } + } + { + GXTexObj sp98; + f32 temp_f4_4 = 32.0f * var_r31->x80.x; + f32 temp_f0_2 = var_r31->x24.y; + f32 var_f21 = 0.0f; + f32 temp_f1 = 32.0f * var_r31->x80.x * temp_f2_3; + f32 temp_f3_2 = (temp_f0_2 * (sp60 - temp_f4_4)) + (var_r31->x4 + var_r31->x74); + f32 temp_f0_3 = temp_f4_4 * temp_f0_2; + f32 var_f22 = 1.0f; + f32 var_f18 = 0.0f; + f32 var_f27 = temp_f3_2; + f32 var_f20 = 1.0f; + f32 var_f29 = (var_r31->x88 * temp_f1) + var_f31; + f32 var_f28 = temp_f3_2 + temp_f0_3; + if ((u8) var_r31->x4E != 0) { + if (!(min.x > var_f29) && !(max.x < var_f31) && !(min.y > var_f28) && !(max.y < var_f27)) { + if (min.x > var_f31) { + f32 temp_f2_4 = min.x - var_f31; + var_f18 = temp_f2_4 / temp_f1; + var_f31 += temp_f2_4; + } + if (max.x < var_f29) { + f32 temp_f2_5 = var_f29 - max.x; + var_f20 = 1.0f - (temp_f2_5 / temp_f1); + var_f29 -= temp_f2_5; + } + if (min.y > var_f27) { + f32 temp_f1_2 = min.y - var_f27; + var_f21 = temp_f1_2 / temp_f0_3; + var_f27 += temp_f1_2; + } + if (max.y < var_f28) { + f32 temp_f1_3 = var_f28 - max.y; + var_f22 = 1.0f - (temp_f1_3 / temp_f0_3); + var_f28 -= temp_f1_3; + } + } + } + if (temp_r24 < 0x4000U) { + GXInitTexObj(&sp98, &data + ((var_r25 << 9) & 0x01FFFE00), 0x20U, 0x20U, GX_TF_I4, GX_CLAMP, GX_CLAMP, 0U); + } else { + GXInitTexObj(&sp98, kerning + ((var_r25 << 9) & 0x01FFFE00), 0x20U, 0x20U, GX_TF_I4, GX_CLAMP, GX_CLAMP, 0U); + } + GXLoadTexObj(&sp98, GX_TEXMAP0); + GXSetTevColor(GX_TEVREG0, *(GXColor*)&var_r31->x8C); + GXBegin(GX_QUADS, GX_VTXFMT0, 4U); + { + f32 temp_f0_4 = var_r31->x8; + f32 temp_f1_4 = -var_f27; + f32 temp_f2_6 = -var_f28; + GXPosition3f32(var_f31, temp_f1_4, temp_f0_4); + GXTexCoord2f32(var_f18, var_f21); + GXPosition3f32(var_f29, temp_f1_4, temp_f0_4); + GXTexCoord2f32(var_f20, var_f21); + GXPosition3f32(var_f29, temp_f2_6, temp_f0_4); + GXTexCoord2f32(var_f20, var_f22); + GXPosition3f32(var_f31, temp_f2_6, temp_f0_4); + GXTexCoord2f32(var_f18, var_f22); + } + + var_r31->x70 = (f32) ((var_r31->x80.y * (var_r31->x80.x * (32.0f + var_r31->x78.x))) + var_r31->x70); + if ((u8) var_r31->x9D != 0) { + if (temp_r24 < 0x4000U) { + f32 *temp_r4 = &HSD_SisLib_8040CB00 + ((var_r25 * 2) & 0x1FFFE); + var_r31->x70 = (f32) -((var_r31->x88 * (var_r31->x80.x * (f32) (temp_r4[0] + (temp_r4[1] - 2)))) - var_r31->x70); + } else { + u8 *temp_r4 = &textures->data[(var_r25 * 2) & 0x1FFFE]; + var_r31->x70 = (f32) -((var_r31->x88 * (var_r31->x80.x * (f32) (temp_r4[0] + (temp_r4[1] - 2)))) - var_r31->x70); + } + } + if (var_r28 != 0U) { + var_r28 -= 1; + } else { + var_r31->x98 = (u32) (var_r31->x98 + 1); + var_r31->x94 = (u32) var_r23; + var_r31->x60 = (void *) (var_r30 + 2); + } + var_r30 += 1; + } + } + } + } + var_r30++; + } + HSD_StateInvalidate(-1); + var_r31->x8C.x = spBC; + var_r31->x8C.y = spBB; + var_r31->x8C.z = spBA; + var_r31->x80.x = spCC.x; + var_r31->x80.y = spCC.y; + var_r31->x78.x = spC4.x; + var_r31->x78.y = spC4.y; + var_r31->x9E = spB8; + var_r31->x9D = temp_r22; + var_r31->x9C = spB9; + var_r31->x6C = temp_r14; + { + s32 var_r5 = var_r31->x6C; + while ((s32) var_r5 < (s32) var_r31->x6E) { + *((u8 *)var_r31->x68 + var_r5) = 0; + var_r5 += 1; + } + } + } + } + // clang-format on +} diff --git a/src/sysdolphin/baselib/sislib.h b/src/sysdolphin/baselib/sislib.h index c1998ab202..83926af707 100644 --- a/src/sysdolphin/baselib/sislib.h +++ b/src/sysdolphin/baselib/sislib.h @@ -5,8 +5,14 @@ #include "baselib/forward.h" #include "baselib/archive.h" +#include "baselib/cobj.h" #include +#include + +typedef struct sislib_UnkAllocData sislib_UnkAllocData; +typedef struct sislib_UnkAllocReturn sislib_UnkAllocReturn; +typedef struct sislib_UnkAlloc3 sislib_UnkAlloc3; typedef struct { UNK_T x0; @@ -30,12 +36,85 @@ typedef struct SIS { /*0x04*/ TextGlyphTexture* textures; } SIS; +// @todo: give actual names? +struct sislib_UnkAllocData { + sislib_UnkAllocData* data_0; + sislib_UnkAllocReturn* data_1; + u32 size; +}; + +// @todo: this is probably what gets put in gobj user_data +struct sislib_UnkAllocReturn { + f32 x0; + f32 x4; + f32 x8; + f32 xC; + f32 x10; + Vec4 x14; + Vec2 x24; + U8Vec4 x2C; + U8Vec4 x30; + Vec2 x34; + Vec2 x3C; + u16 x44; + u16 x46; + u8 x48; + u8 x49; + u8 x4A; + u8 x4B; + u8 x4C; // whether to test for Z depth? + u8 x4D; + u8 x4E; + u8 x4F; // which font to select from the array HSD_SisLib_804D1124 + sislib_UnkAllocReturn* x50; + HSD_GObj* x54; + void (*x58)(void*); // callback in the text renderer (HSD_SisLib_803A84BC) + SIS* x5C; // could just be a byte pointer? + UNK_T x60; + sislib_UnkAllocData* x64; + void* x68; + u16 x6C; + u16 x6E; + f32 x70; + f32 x74; + Vec2 x78; + Vec2 x80; + f32 x88; + U8Vec4 x8C; + u16 x90; + u16 x92; + u32 x94; + u32 x98; + u8 x9C; + u8 x9D; + u8 x9E; + u8 x9F; +}; + +struct sislib_UnkAlloc3 { + sislib_UnkAlloc3* x0; + HSD_GObj* x4; + u16 x8; + u16 xA; + u8 xC; + u8 xD; + u8 xE; + u8 xF; +}; + extern s8 HSD_SisLib_804D6390[4]; extern SIS* HSD_SisLib_804D1124[5]; extern HSD_Archive* HSD_SisLib_804D1110[5]; extern u32 lbl_8040C8C0[144]; extern u32 HSD_SisLib_8040C680[144]; -extern UNK_T HSD_SisLib_8040C4B8; +extern HSD_CObjDesc HSD_SisLib_8040C4B8; + +extern u32 HSD_SisLib_804D7968; +extern sislib_UnkAllocData* HSD_SisLib_804D796C; +extern sislib_UnkAllocData* HSD_SisLib_804D7970; +extern sislib_UnkAllocData* HSD_SisLib_804D7974; +extern sislib_UnkAllocReturn* HSD_SisLib_804D7978; +extern sislib_UnkAlloc3* HSD_SisLib_804D797C; extern sislib_UnknownType001 HSD_SisLib_8040C4A4; extern sislib_UnknownType001 HSD_SisLib_8040C490; @@ -43,31 +122,41 @@ extern sislib_UnknownType001 HSD_SisLib_8040C490; void HSD_SisLib_803A6048(size_t); UNK_T func_804A70A0(UNK_T, s32, u32, s32, s32, s32, s32, s32, f64, f64, f64, f64, f64, f64, f64, f64); -void HSD_SisLib_803A947C(void); +void HSD_SisLib_803A947C(HSD_Archive*); void HSD_SisLib_803A945C(void); -void HSD_SisLib_803A84BC(void); -void HSD_SisLib_803A8134(void); -s32 HSD_SisLib_803A7F0C(UNK_T, s32); +void HSD_SisLib_803A84BC(HSD_GObj*, sislib_UnkAllocReturn*); +s32 HSD_SisLib_803A7F0C(sislib_UnkAllocReturn*, s32); +void HSD_SisLib_803A8134(void*, sislib_UnkAllocReturn*, f32*, f32*); void HSD_SisLib_803A7684(UNK_T, u8, u8); void HSD_SisLib_803A7664(UNK_T); void HSD_SisLib_803A75E0(UNK_T, s32); void HSD_SisLib_803A7548(UNK_T, f32, f32); -void HSD_SisLib_803A74F0(UNK_T, UNK_T); -void HSD_SisLib_803A746C(UNK_T, s32, f32, f32); +void HSD_SisLib_803A74F0(sislib_UnkAllocReturn*, s32 arg1, u8* arg2); +void HSD_SisLib_803A746C(sislib_UnkAllocReturn*, s32, f32, f32); s32 HSD_SisLib_803A70A0(s32, UNK_T, UNK_T); u32 lbl_803A6FEC(s32, s32, bool); -void HSD_SisLib_803A6B98(UNK_T, u32, s32, s32, s32, s32, s32, s32, f64, f64, - f64, f64, f64, f64, f64, f64); -s32 HSD_SisLib_803A67EC(UNK_T, UNK_T); -UNK_T HSD_SisLib_803A6754(void); +void HSD_SisLib_803A6B98(sislib_UnkAllocReturn* arg0, void* arg1, ...); +s32 HSD_SisLib_803A67EC(u8*, u8*); +sislib_UnkAllocReturn* HSD_SisLib_803A6754(s8 arg0, s32 arg1); void HSD_SisLib_803A660C(s32, s32, s32); void HSD_SisLib_803A6530(s32, s32, s32); void HSD_SisLib_803A6478(u8*, u8*); -void HSD_SisLib_803A6368(UNK_T, int); -void HSD_SisLib_803A62A0(s32, s32, s8*); -s32 HSD_SisLib_803A611C(s16, u32, s16, s8, s8, s8, s8, u32); +void HSD_SisLib_803A6368(sislib_UnkAllocReturn*, s32); +void HSD_SisLib_803A62A0(s32, HSD_Archive*, char*); +s32 HSD_SisLib_803A611C(u16, u32, u16, u8, u8, u8, u8, u32); void lbl_803A60EC(void); -UNK_T HSD_SisLib_803A5ACC(char, int, f32, f32, f32, f32, f32); -void HSD_SisLib_803A594C(u8*); +sislib_UnkAllocReturn* HSD_SisLib_803A5ACC(s8, s32, f32, f32, f32, f32, f32); +void* HSD_SisLib_803A5798(s32); +void HSD_SisLib_803A594C(void*); +void HSD_SisLib_803A5CC4(sislib_UnkAllocReturn*); +void HSD_SisLib_803A5A2C(sislib_UnkAllocReturn*); +void HSD_SisLib_803A5D30(void); +void HSD_SisLib_803A5DA0(s32); +void HSD_SisLib_803A5E70(void); +void HSD_SisLib_803A5F50(s32); +void HSD_SisLib_803A5FBC(void); +void fn_803A60EC(void*); +u8* fn_803A6FEC(u8*, s32, s32*); +// void *HSD_SisLib_803A84BC(HSD_GObj *, s32); #endif