diff --git a/config/us/sym/symbol_addrs_libultra.txt b/config/us/sym/symbol_addrs_libultra.txt index e02afe7..d39e777 100644 --- a/config/us/sym/symbol_addrs_libultra.txt +++ b/config/us/sym/symbol_addrs_libultra.txt @@ -274,7 +274,6 @@ __osSetCompare = 0x80245480; __osSiDeviceBusy = 0x80245490; __osGetCause = 0x802454C0; __osAtomicDec = 0x802454D0; -__additional_scanline = 0x80248DD8; alGlobals = 0x8024B780; aisetnextbuf_data_0000 = 0x8024B790; sprite_data_0004 = 0x8024B7A4; diff --git a/include/uv_dobj.h b/include/uv_dobj.h index d55aa97..60a5e0e 100644 --- a/include/uv_dobj.h +++ b/include/uv_dobj.h @@ -9,7 +9,7 @@ typedef struct { u16 unk0; u16 unk2[1]; // unknown size, might take up everything till unk34 u8 pad4[0x34-0x4]; - s8 unk34; + u8 unk34; f32 unk38; s32 unk3C; } Unk80263780; diff --git a/include/uv_graphics.h b/include/uv_graphics.h index bb2554b..6d6a8f8 100644 --- a/include/uv_graphics.h +++ b/include/uv_graphics.h @@ -47,6 +47,31 @@ typedef struct { void* unk54; } UnkStruct_uvGfxInit; // size: 0x58 +typedef struct UnkTileStruct40 { + u8 pad0[0x10]; + struct UnkSobjDraw* unk10; +} UnkTileStruct40; + +typedef struct uvUnkTileStruct { + u8 pad0[0x40]; + UnkTileStruct40* unk40; + u8 pad44[0x4]; +} uvUnkTileStruct; + +typedef struct uvGfxUnkStructTerra { + f32 unk0; + f32 unk4; + u8 pad8[0x4]; + f32 unkC; + f32 unk10; + u8 pad14[0x4]; + u8 unk18; + f32 unk1C; + f32 unk20; + u8 pad24[0x4]; + uvUnkTileStruct* unk28; +} uvGfxUnkStructTerra; + typedef struct { void* unk0; Gfx *unk4; @@ -61,13 +86,38 @@ typedef struct { struct unk_UVTX_1C* unk1C; u8 pad20[0x2]; u8 unk22; -} uvGfxUnkStruct2; +} uvGfxUnkStructTexture; + +typedef struct uvGfxUnkStruct10 { + uvGfxState_t* unk0; + u8 unk4; + u8 pad5[0x1]; + u8 unk6; + u8 pad7[0x6]; + u8 unkD; + u8 padE[0x2]; +} uvGfxUnkStruct10; + +typedef struct uvGfxUnkStruct8 { + uvGfxUnkStruct10* unk0; + u8 unk4; + u8 unk5; + u8 pad6[0x2]; +} uvGfxUnkStruct8; typedef struct { - u8 pad0[0x1C]; + u8 pad0[0x8]; + uvGfxUnkStruct8* unk8; + f32* unkC; + u8 unk10; + u8 unk11; + u8 pad12[0x2]; + void* unk14; + u8 unk18; + u8 pad19[0x3]; f32 unk1C; f32 unk20; -} uvGfxUnkStructC8; +} uvGfxUnkStructModel; typedef struct { u8 pad0[0x2]; @@ -80,23 +130,25 @@ typedef struct { s16 nbitmaps; u8 pad10[0x4]; Bitmap* bitmap; -} uvGfxUnkStruct1410; +} uvGfxUnkStructBlit; typedef struct { u8 pad0[0x4]; - void *unk4[1]; + uvGfxUnkStructTerra *unk4[1]; u8 pad8[0x28]; void *unk30[1]; u8 pad34[0x10]; void *unk44[1]; u8 pad48[0x80]; - uvGfxUnkStructC8 *unkC8[1]; + uvGfxUnkStructModel *unkC8[1]; u8 padCC[0x844]; - uvGfxUnkStruct2 *unk910[1]; + uvGfxUnkStructTexture *unk910[1]; u8 pad914[0x7D0]; void *unk10E4[1]; u8 pad10E8[0x328]; - uvGfxUnkStruct1410* unk1410[1]; + uvGfxUnkStructBlit* unk1410[1]; + u8 pad1414[0x1F4]; + f32 unk1608; } uvGfxUnkStruct; extern Gfx* gGfxDisplayListHead; @@ -187,7 +239,7 @@ typedef struct { /* 1FC */ f32 unk1FC; /* 200 */ f32 unk200; /* 204 */ f32 unk204; -/* 208 */ u8 pad208[0x2E0 - 0x208]; +/* 208 */ u8 pad208[0xD8]; /* 2E0 */ u8 unk2E0[0x90]; /* 370 */ s32 unk370; /* 374 */ s32 unk374; diff --git a/include/uv_matrix.h b/include/uv_matrix.h index c046ca9..b177247 100644 --- a/include/uv_matrix.h +++ b/include/uv_matrix.h @@ -15,6 +15,20 @@ typedef union { }; } Mtx4F; +typedef struct Mtx_u { + u16 i[4][4]; + u16 f[4][4]; +} Mtx_u; + +typedef union { + Mtx_t m; + Mtx_u u; + long long int force_structure_alignment; +} uvMtx; + +#define MTX_TO_PART(mtx) (*(Mtx_u*)&(mtx)) +#define L2F(mtx, i1, i2) ((((s16)MTX_TO_PART(mtx).i[(i1)][(i2)] << 0x10) | ((s16)MTX_TO_PART(mtx).f[(i1)][(i2)] & 0xFFFF)) / 65536.0f) + void _uvDbMstackReset(void); Mtx4F* _uvDbMstackTop(void); void _uvDbMstackPush(Mtx4F* src); diff --git a/include/uv_model.h b/include/uv_model.h index 8401122..5b75fcf 100644 --- a/include/uv_model.h +++ b/include/uv_model.h @@ -4,7 +4,7 @@ #include s32 uvModelGet(s32, s32); -void uvModelGetProps(u16, s32, void*, s32); +void uvModelGetProps(s32, s32, void*, s32); void uvModelGetPosm(s32 model, s32 part, Mtx4F*); #endif // UV_MODEL_H diff --git a/include/uv_sched.h b/include/uv_sched.h index 91d78cb..5d3f199 100644 --- a/include/uv_sched.h +++ b/include/uv_sched.h @@ -3,12 +3,20 @@ #include #include +#include #include #define UV_MESG_DMA 0 #define UV_MESG_SCHED 2 #define UV_MESG_GFX 4 +typedef struct Unk8022B0A0 { + f32 unk0; + f32 unk4; + f32 unk8; + f32 unkC; +} Unk8022B0A0; // size: 0x10 + void uvWaitForMesg(char msg_type); void _uvScDoneGfx(void); @@ -26,8 +34,9 @@ void _uvScHandleRDP(void); void _uvScHandleNMI(void); void _uvScLogCpuEvent(s32 ring); void _uvScLogIntoRing(void); -void func_8022C34C(void); +void func_8022B0A0(Unk8022B0A0* arg0, Mtx4F* arg1); void func_8022BEB8(s32 arg0); +void func_8022C34C(void); void func_8022C3C0(u8 arg0, s32 arg1); #endif // PILOTWINGS64_UV_SCHED diff --git a/include/uv_sobj.h b/include/uv_sobj.h new file mode 100644 index 0000000..1567f7a --- /dev/null +++ b/include/uv_sobj.h @@ -0,0 +1,20 @@ +#ifndef UV_SOBJ_H +#define UV_SOBJ_H + +#include +#include + +typedef struct UnkSobjDraw { + u16 unk0; + Mtx* unk4; + f32 unk8; + f32 unkC; + f32 unk10; + u16 unk14; +} UnkSobjDraw; + +u8 func_8022C7B8(uvGfxUnkStructModel* arg0, f32 arg1); +void func_8022C8D0(UnkSobjDraw* arg0, uvGfxUnkStructModel* arg1, u8 arg2, Mtx4F* arg3); +void func_8022CC28(UnkSobjDraw* arg0, uvGfxUnkStructModel* arg1, u8 arg2, f32 arg3, f32 arg4); + +#endif // UV_SOBJ_H diff --git a/include/uv_sprite.h b/include/uv_sprite.h index c75ec8a..feec581 100644 --- a/include/uv_sprite.h +++ b/include/uv_sprite.h @@ -62,8 +62,8 @@ typedef struct { void uvSprt_80230130(void); void uvSprt_802301A4(void); void _uvTxtDraw(s32 arg0); -void uvSprtFromBitmap(uvSprite_t* arg0, uvGfxUnkStruct2* arg1); -void uvSprt_80230750(uvSprite_t* arg0, uvGfxUnkStruct2* arg1); +void uvSprtFromBitmap(uvSprite_t* arg0, uvGfxUnkStructTexture* arg1); +void uvSprt_80230750(uvSprite_t* arg0, uvGfxUnkStructTexture* arg1); s32 uvSprt_80230898(void); void uvSprtInit(void); void uvSprtDisplayList(uvSprite_t* arg0); diff --git a/src/kernel/code_58E0.c b/src/kernel/code_58E0.c index f9bd2a5..65403f0 100644 --- a/src/kernel/code_58E0.c +++ b/src/kernel/code_58E0.c @@ -1,5 +1,23 @@ #include #include +#include + +typedef struct UnkSortAdd { + s8 unk0; + s8 unk1; + s8 unk2; + f32 unk4; + f32 unk8; + f32 unkC; + void* unk10; + u16 unk14; + s32 unk18; +} UnkSortAdd; + +extern UnkSortAdd D_80261ED8[]; +extern UnkSortAdd D_802629C8[]; +extern s32 D_80263058; +extern s32 D_8026305C; // from kernel/code_7150 void func_802061A0(void*); @@ -147,7 +165,71 @@ void func_802057F4(Mtx4F* arg0, Mtx4F* arg1) { uvMat4UnkOp4(arg0, arg1); } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/code_58E0/_uvSortAdd.s") +void _uvSortAdd(s32 arg0, f32 arg1, void* arg2, UnkStruct_80204D94* arg3, f32 arg4, f32 arg5, ...) { + UnkSortAdd* var_a1; + uvGfxUnkStructTerra* var_v0; + s32 var_v1; + s32 var_a0; + va_list args; + + if (arg0 > 0) { + if (D_80263058 >= 100) { + _uvDebugPrintf("_uvSortAdd: sort list full %d\n", 100); + return; + } + var_a1 = &D_80261ED8[D_80263058]; + D_80263058++; + } else { + if (D_8026305C >= 60) { + _uvDebugPrintf("_uvSortAdd: dobj list full for %d\n", 60); + return; + } + + var_a1 = &D_802629C8[D_8026305C]; + D_8026305C++; + arg0 = -arg0; + } + var_a1->unk0 = arg0; + var_a1->unk4 = arg1; + var_a1->unk10 = arg2; + if (arg3->unk0 & 2) { + var_v0 = gGfxUnkPtrs->unk4[arg3->unk4]; + } else { + var_v0 = NULL; + } + if (var_v0 != NULL) { + if ((arg4 < var_v0->unk0) || (var_v0->unkC <= arg4) || (arg5 < var_v0->unk4) || (var_v0->unk10 <= arg5)) { + var_a1->unk14 = 0xFFFF; + } else { + var_v1 = (s32)(arg4 - var_v0->unk0) / (s32)var_v0->unk1C; + var_a0 = (s32)(arg5 - var_v0->unk4) / (s32)var_v0->unk20; + var_a1->unk14 = var_v1 + var_v0->unk18 * var_a0; + } + } else { + var_a1->unk14 = 0xFFFF; + } + + va_start(args, arg5); + switch (arg0) { + case 1: + break; + case 2: + var_a1->unk1 = va_arg(args, s32); + break; + case 3: + var_a1->unk1 = va_arg(args, s32); + var_a1->unk8 = va_arg(args, f64); + var_a1->unkC = va_arg(args, f64); + break; + case 4: + var_a1->unk8 = va_arg(args, f64); + var_a1->unkC = va_arg(args, f64); + var_a1->unk18 = va_arg(args, s32); + var_a1->unk2 = va_arg(args, s32); + var_a1->unk1 = va_arg(args, s32); + break; + } +} #pragma GLOBAL_ASM("asm/nonmatchings/kernel/code_58E0/func_80205BFC.s") diff --git a/src/kernel/code_8170.c b/src/kernel/code_8170.c index c1bf640..0b26619 100644 --- a/src/kernel/code_8170.c +++ b/src/kernel/code_8170.c @@ -3,7 +3,7 @@ uvGfxUnkStruct* gGfxUnkPtrs = NULL; s32 D_80248DD4 = 0xFFFFFFFF; -s32 __additional_scanline[] = { 0x00000000, 0x00000000 }; +s32 D_80248DD8 = 0x00000000; #pragma GLOBAL_ASM("asm/nonmatchings/kernel/code_8170/osViExtendVStart.s") diff --git a/src/kernel/dobj.c b/src/kernel/dobj.c index 0bda1eb..acb6562 100644 --- a/src/kernel/dobj.c +++ b/src/kernel/dobj.c @@ -1,14 +1,143 @@ #include "common.h" #include +#include +#include +#include #include #include #include +// TODO FIXME fix for gSPPerspNormalize, due to older f3d ucode +#undef gSPPerspNormalize +#define gSPPerspNormalize(pkt, s) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ + _g->words.w1 = (s); \ + } + +typedef struct Unk80371120 { + Unk8022B0A0 unk0[1]; + u8 pad10[0x180]; + u8 unk190[1]; + u8 pad191[0x1B]; + s32 unk1AC; +} Unk80371120; // size: 0x1B0 + +void _uvSortAdd(s32, f32, void*, UnkStruct_80204D94*, f32, f32, ...); +u8 func_80217AB4(uvGfxUnkStructModel*, f32); +void func_80217B4C(Unk80263780*, uvGfxUnkStructModel*, u8); +void func_80217E24(Unk80263780*, uvGfxUnkStructModel*, u8, f32, f32); +s32 func_80206F64(void*, f32, f32, f32, f32); +void func_80215E7C(uvGfxUnkStructModel*); + +extern u8 D_80269B80[300]; extern u16 D_80269CB0[100]; +extern u16 D_80269F08; extern u16 D_80269F0A; extern Mtx4F D_80265080[300]; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/uvDobjModel.s") +void uvDobjModel(s32 objId, s32 arg1) { + uvGfxUnkStructModel** temp_a3; + Unk80263780* var_t2; + s32 var_v0_3; + s32 i; + s32 j; + u8 temp_t0; + u8 var_a3_2; + + var_t2 = &D_80263780[objId]; + temp_a3 = gGfxUnkPtrs->unkC8; + + if (arg1 == var_t2->unk0) { + return; + } + + if (objId >= 100) { + _uvDebugPrintf("uvDobjModel - invalid object id number [%d]\n", objId); + return; + } + if (arg1 == 0xFFFF) { + temp_t0 = temp_a3[var_t2->unk0]->unk18; + + for (i = 0; i < temp_t0; i++) { + D_80269B80[var_t2->unk2[i]] = 0; + } + + var_t2->unk0 = 0xFFFF; + for (i = 0; i < D_80269F0A; i++) { + if (objId == D_80269CB0[i]) { + for (j = i; j < D_80269F0A; j++) { + D_80269CB0[j] = D_80269CB0[j + 1]; + } + D_80269F0A--; + } + } + } else { + if (gGfxUnkPtrs->unkC8[arg1] == NULL) { + _uvDebugPrintf("uvDobjModel ( %d, %d ) -- model does not exist in level\n", objId, arg1); + return; + } + var_t2->unk3C = 0; + var_t2->unk38 = temp_a3[arg1]->unk1C; + + if (var_t2->unk0 == 0xFFFF) { + temp_t0 = 0; + } else { + if (temp_a3[var_t2->unk0] != NULL) { + temp_t0 = temp_a3[var_t2->unk0]->unk18; + } else { + temp_t0 = 0; + j = -1; + for (i = 0; i < 25; i++) { + if (j >= var_t2->unk2[i]) { + break; + } + j = var_t2->unk2[i]; + D_80269B80[j] = 0; + if (j) { } + } + } + } + + var_a3_2 = temp_a3[arg1]->unk18; + + if (var_a3_2 < temp_t0) { + for (i = temp_t0 - 1; i >= var_a3_2; i--) { + D_80269B80[var_t2->unk2[i]] = 0; + } + } else { + if (temp_t0 < var_a3_2) { + var_v0_3 = 0; + for (i = temp_t0; i < var_a3_2; i++) { + for (j = var_v0_3; j < 300; j++) { + if (D_80269B80[j] == 0) { + break; + } + } + + if (j == 300) { + _uvDebugPrintf("uvDobjModel : WARNING not enough DL part transforms\n"); + return; + } + + D_80269B80[j] = 1; + var_t2->unk2[i] = j; + var_v0_3 = j + 1; + } + } + } + + var_t2->unk2[var_a3_2] = 0; + + for (i = 0; i < var_a3_2; i++) { + uvMat4Copy(&D_80265080[var_t2->unk2[i]], (u32)temp_a3[arg1]->unk14 + i * sizeof(Mtx4F)); + } + var_t2->unk0 = arg1; + var_t2->unk34 = 3; + } +} void uvDobjProps(s32 arg0, ...) { s16 a1; @@ -55,19 +184,55 @@ void uvDobjProps(s32 arg0, ...) { va_end(args); } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/uvDobjPosm.s") +void uvDobjPosm(s32 objId, s32 part, Mtx4F* arg2) { + uvGfxUnkStructModel* temp_v1; + Unk80263780* temp_v0; + f32 temp_fv0; + + if (objId >= 0x65) { + _uvDebugPrintf("uvDobjPosm - invalid object id number [%d]\n", objId); + return; + } + temp_v0 = &D_80263780[objId]; + if (temp_v0->unk0 >= 0x190) { + _uvDebugPrintf("uvDobjPosm: null object id %d\n", objId); + return; + } -void uvDobjGetPosm(s32 arg0, s32 arg1, Mtx4F* arg2) { + uvMat4Copy(&D_80265080[temp_v0->unk2[part]], arg2); + + temp_v1 = gGfxUnkPtrs->unkC8[temp_v0->unk0]; + if (temp_v1 == NULL) { + _uvDebugPrintf("uvDobjPosm: model %d not in level\n", temp_v0->unk0); + return; + } + if (part >= temp_v1->unk8->unk4) { + _uvDebugPrintf("uvDobjPosm: part %d not defined for model %d in obj %d\n", part, temp_v0->unk0, objId); + return; + } + if (part == 0) { + if (temp_v1->unk20 != 1.0f) { + temp_fv0 = 1.0f / temp_v1->unk20; + uvMat4UnkOp3(&D_80265080[temp_v0->unk2[part]], temp_fv0, temp_fv0, temp_fv0); + } + } else { + D_80265080[temp_v0->unk2[part]].m[3][0] *= temp_v1->unk20; + D_80265080[temp_v0->unk2[part]].m[3][1] *= temp_v1->unk20; + D_80265080[temp_v0->unk2[part]].m[3][2] *= temp_v1->unk20; + } +} + +void uvDobjGetPosm(s32 objId, s32 arg1, Mtx4F* arg2) { Unk80263780* sp24; - uvGfxUnkStructC8* temp_v0; + uvGfxUnkStructModel* temp_v0; - if (arg0 >= 0x65) { - _uvDebugPrintf("uvDobjPosm - invalid object id number [%d]\n", arg0); + if (objId >= 0x65) { + _uvDebugPrintf("uvDobjPosm - invalid object id number [%d]\n", objId); return; } - sp24 = &D_80263780[arg0]; + sp24 = &D_80263780[objId]; if (sp24->unk0 >= 0x190) { - _uvDebugPrintf("uvDobjGetPosm: null object id %d\n", arg0); + _uvDebugPrintf("uvDobjGetPosm: null object id %d\n", objId); return; } uvMat4Copy(arg2, &D_80265080[sp24->unk2[arg1]]); @@ -83,27 +248,27 @@ void uvDobjGetPosm(s32 arg0, s32 arg1, Mtx4F* arg2) { } } -void uvDobjState(s32 arg0, s32 arg1) { +void uvDobjState(s32 objId, s32 arg1) { s32 i; s32 j; - if (arg0 >= 0x65) { - _uvDebugPrintf("uvDobjState - invalid object id number [%d]\n", arg0); + if (objId >= 0x65) { + _uvDebugPrintf("uvDobjState - invalid object id number [%d]\n", objId); return; } if (arg1 & 4) { for (i = 0; i < D_80269F0A; i++) { - if (arg0 == D_80269CB0[i]) { + if (objId == D_80269CB0[i]) { break; } } if (i == D_80269F0A) { - D_80269CB0[i] = arg0; + D_80269CB0[i] = objId; D_80269F0A++; } } else { for (i = 0; i < D_80269F0A; i++) { - if (arg0 == D_80269CB0[i]) { + if (objId == D_80269CB0[i]) { for (j = i; j < D_80269F0A; j++) { D_80269CB0[j] = D_80269CB0[j + 1]; } @@ -111,27 +276,383 @@ void uvDobjState(s32 arg0, s32 arg1) { } } } - D_80263780[arg0].unk34 = arg1; + D_80263780[objId].unk34 = arg1; +} + +void uvDobjSetState(s32 objId, s32 arg1) { + if (objId >= 0x65) { + _uvDebugPrintf("uvDobjSetState: no dobj %d\n", objId); + return; + } + + D_80263780[objId].unk34 |= arg1; +} + +void uvDobjSetState2(s32 objId, s32 arg1) { + if (objId >= 0x65) { + _uvDebugPrintf("uvDobjSetState: no dobj %d\n", objId); + return; + } + + D_80263780[objId].unk34 &= ~arg1; +} + +s32 func_8021731C(void) { + s32 i; + + for (i = 0; i < 100; i++) { + if (D_80263780[i].unk0 == 0xFFFF) { + return i; + } + } + return 0xFFFF; +} + +void func_80217398(void) { + s32 i; + + for (i = 0; i < 100; i++) { + D_80263780[i].unk0 = 0xFFFF; + } + + for (i = 0; i < 100; i++) { + D_80269CB0[i] = 0xFFFF; + } + + for (i = 0; i < 300; i++) { + D_80269B80[i] = 0; + } + + for (i = 0; i < 300; i++) { + uvMat4SetIdentity(&D_80265080[i]); + } + D_80269F0A = 0; +} + +void _uvDobjsDraw(UnkStruct_80204D94* arg0, s32 arg1) { + Unk80263780* var_s2; + s32 i; + f32 temp_fv0_2; + f32 temp_fv1; + s32 var_v1; + s32 var_a0; + u8 spBF; + f32 temp_fv0; + f32 temp_fs5; + s32 pad; + f32 temp_fs1; + f32 temp_fs2; + f32 temp_fs0; + f32 spA0; + f32 sp9C; + f32 sp98; + uvGfxUnkStructModel* temp_s1; + Mtx4F* temp_v0_2; + + D_80269F08 = 0; + spA0 = arg0->unk110.m[3][0]; + sp9C = arg0->unk110.m[3][1]; + sp98 = arg0->unk110.m[3][2]; + + for (i = 0; i < 100; i++) { + var_s2 = &D_80263780[i]; + if (var_s2->unk0 == 0xFFFF) { + continue; + } + if (!(var_s2->unk34 & 2) || (var_s2->unk34 & 4)) { + continue; + } + temp_s1 = gGfxUnkPtrs->unkC8[var_s2->unk0]; + if (temp_s1 == NULL) { + _uvDebugPrintf("_uvDobjsDraw: model %d not in level\n", var_s2->unk0); + continue; + } + uvModelGetProps(var_s2->unk0, 5, &spBF, 0); + if (spBF - arg1 != 0) { + continue; + } + temp_v0_2 = &D_80265080[var_s2->unk2[0]]; + temp_fv0 = temp_v0_2->m[3][0]; + temp_fs5 = temp_v0_2->m[3][1]; + + temp_fs1 = temp_v0_2->m[3][0] - spA0; + temp_fs2 = temp_v0_2->m[3][1] - sp9C; + temp_fs0 = temp_v0_2->m[3][2] - sp98; + temp_fv0_2 = uvSqrtF(SQ(temp_fs1) + SQ(temp_fs2) + SQ(temp_fs0)); + temp_fv1 = var_s2->unk38; + if ((temp_fv0_2 < (arg0->unk1FC + temp_fv1)) && (func_80206F64(arg0->unk2E0, temp_fs1, temp_fs2, temp_fs0, temp_fv1) != 0)) { + if (arg0->unk204 == 1.0f) { + var_v1 = func_80217AB4(temp_s1, temp_fv0_2); + } else { + var_v1 = func_80217AB4(temp_s1, arg0->unk204 * temp_fv0_2); + } + if (var_v1 == 0xFF) { + continue; + } + if (arg1 != 0) { + func_80217B4C(var_s2, temp_s1, var_v1); + } else if (temp_s1->unk8[var_v1].unk5 != 0) { + if (temp_s1->unk11 & 1) { + var_a0 = 3; + } else { + var_a0 = -3; + } + _uvSortAdd(var_a0, temp_fv0_2, var_s2, arg0, temp_fv0, temp_fs5, var_v1, temp_fs1, temp_fs2); + } else { + if (temp_s1->unk11 & 1) { + var_a0 = 2; + } else { + var_a0 = -2; + } + _uvSortAdd(var_a0, temp_fv0_2, var_s2, arg0, temp_fv0, temp_fs5, var_v1); + } + } + } } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/uvDobjSetState.s") +void func_8021771C(UnkStruct_80204D94* arg0) { + uvGfxUnkStructModel* temp_s0; + Unk80263780* temp_s1; + s32 i; + s32 pad; + Mtx4F sp128; + Mtx spE8; + f32 temp_fs2; + f32 temp_fs3; + f32 temp_fs4; + f32 temp_fv0; + f32 temp_fv0_2; + f32 temp_fa0; + f32 var_fs0; + f32 temp_fv1_x; + f32 temp_fa0_x; + f32 temp_fa1_x; + f32 temp_ft4_x; + u8 var_v0; + + if (D_80269F0A == 0) { + return; + } + uvGfx_80222A98(); + uvGfxEnableZBuffer(TRUE); + for (i = 0; i < D_80269F0A; i++) { + temp_s1 = &D_80263780[D_80269CB0[i]]; + if (temp_s1->unk0 == 0xFFFF) { + continue; + } + if (!(temp_s1->unk34 & 2)) { + continue; + } + temp_s0 = gGfxUnkPtrs->unkC8[temp_s1->unk0]; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/uvDobjSetState2.s") + temp_fs3 = D_80265080[temp_s1->unk2[0]].m[3][0] - arg0->unk110.m[3][0]; + temp_fs4 = D_80265080[temp_s1->unk2[0]].m[3][1] - arg0->unk110.m[3][1]; + temp_fv0 = D_80265080[temp_s1->unk2[0]].m[3][2] - arg0->unk110.m[3][2]; + temp_fv0_2 = uvSqrtF(SQ(temp_fs3) + SQ(temp_fs4) + SQ(temp_fv0)); -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_8021731C.s") + temp_fa0 = temp_fv0_2 - temp_s1->unk38; + temp_fs2 = temp_s1->unk38 + temp_fv0_2; + if (temp_fa0 > 0.1f) { + var_fs0 = temp_fa0; + } else { + var_fs0 = 0.1f; + } + temp_fv1_x = arg0->unk1E8 * (var_fs0 / arg0->unk1F8); + temp_fa0_x = arg0->unk1EC * (var_fs0 / arg0->unk1F8); + temp_ft4_x = arg0->unk1F4 * (var_fs0 / arg0->unk1F8); + temp_fa1_x = arg0->unk1F0 * (var_fs0 / arg0->unk1F8); + uvMat4SetUnk2(&sp128, temp_fv1_x, temp_fa0_x, temp_fa1_x, temp_ft4_x, var_fs0, temp_fs2); + uvMat4CopyF2L(&spE8, &sp128); + uvGfxMtxProj(spE8); + gSPPerspNormalize(gGfxDisplayListHead++, (s16)(131072.0f / (temp_fs2 + var_fs0))); -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_80217398.s") + if (arg0->unk204 == 1.0f) { + var_v0 = func_80217AB4(temp_s0, temp_fv0_2); + } else { + var_v0 = func_80217AB4(temp_s0, arg0->unk204 * temp_fv0_2); + } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/_uvDobjsDraw.s") + if (var_v0 == 0xFF) { + continue; + } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_8021771C.s") + if (temp_s0->unk8[var_v0].unk5 != 0) { + func_80217E24(temp_s1, temp_s0, var_v0, temp_fs3, temp_fs4); + } else { + func_80217B4C(temp_s1, temp_s0, var_v0); + } + gSPPopMatrix(gGfxDisplayListHead++, G_MTX_PROJECTION); + } +} + +u8 func_80217AB4(uvGfxUnkStructModel* arg0, f32 arg1) { + u8 temp_v1; + u8 i; + f32* temp_v0; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_80217AB4.s") + temp_v0 = arg0->unkC; + temp_v1 = arg0->unk10; + if (temp_v0[temp_v1 - 1] <= arg1) { + return 0xFF; + } + + for (i = temp_v1; i > 0; i--) { + if (temp_v0[i - 1] < arg1) { + return i; + } + } + return 0; +} -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_80217B34.s") +extern s32 D_80269D78[]; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_80217B4C.s") +s32 func_80217B34(s32** arg0) { + *arg0 = D_80269D78; + return D_80269F08; +} -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_80217E24.s") +extern s32 D_80248DD8; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/dobj/func_802180DC.s") +void func_80217B4C(Unk80263780* arg0, uvGfxUnkStructModel* arg1, u8 arg2) { + uvGfxUnkStruct10* temp_s2; + uvGfxUnkStruct8* temp_s7; + s32 i; + s32 j; + s32 temp_s3; + s32 temp_v1; + Mtx4F sp50; + + D_80269D78[D_80269F08] = arg0 - D_80263780; + D_80269F08++; + if (arg0->unk34 & 8) { + uvGfx_80223C00(); + } + + temp_s7 = &arg1->unk8[arg2]; + for (i = 0; i < temp_s7->unk4; i++) { + temp_s2 = &temp_s7->unk0[i]; + if (i == 0) { + uvGfx_802236CC(&D_80265080[arg0->unk2[0]]); + } else { + uvGfxMtxViewMul(&D_80265080[arg0->unk2[i]], 1); + } + if (temp_s2->unkD != 0) { + uvGfxLookAt(&D_80265080[arg0->unk2[i]]); + } + if (!(arg0->unk3C & (1 << i))) { + for (j = 0; j < temp_s2->unk4; j++) { + if (arg0->unk34 & 0x20) { + temp_s3 = temp_s2->unk0[j].unk0; + temp_s2->unk0[j].unk0 |= 0x10000000; + uvGfxStateDraw(&temp_s2->unk0[j]); + temp_s2->unk0[j].unk0 = temp_s3; + } else { + uvGfxStateDraw(&temp_s2->unk0[j]); + } + } + } + if (i == temp_s7->unk4 - 1) { + break; + } + temp_v1 = temp_s7->unk0[i].unk6 - temp_s7->unk0[i + 1].unk6; + for (j = 0; j <= temp_v1; j++) { + uvGfxMtxViewPop(); + } + } + temp_v1 = temp_s7->unk0[temp_s7->unk4 - 1].unk6; + for (i = 0; i <= temp_v1; i++) { + uvGfxMtxViewPop(); + } + if (D_80248DD8 != 0) { + uvMat4Copy(&sp50, &D_80265080[arg0->unk2[0]]); + uvMat4UnkOp3(&sp50, arg1->unk20, arg1->unk20, arg1->unk20); + uvGfx_802236CC(&sp50); + func_80215E7C(arg1); + uvGfxMtxViewPop(); + } +} + +void func_80217E24(Unk80263780* arg0, uvGfxUnkStructModel* arg1, u8 arg2, f32 arg3, f32 arg4) { + uvGfxUnkStruct10* temp_s2; + uvGfxUnkStruct8* temp_s5; + Mtx4F* temp_s7; + s32 i; + s32 j; + s32 temp_v1; + f32 sp54; + f32 sp50; + f32 sp4C; + f32 sp48; + f32 sp44; + f32 var_fv1; + + sp54 = arg1->unk20; + D_80269D78[D_80269F08] = arg0 - D_80263780; + D_80269F08++; + temp_s5 = &arg1->unk8[arg2]; + temp_s7 = &D_80265080[arg0->unk2[0]]; + sp50 = temp_s7->m[0][0]; + sp4C = temp_s7->m[0][1]; + sp48 = temp_s7->m[1][0]; + sp44 = temp_s7->m[1][1]; + + var_fv1 = MAX(1.0f, uvSqrtF(SQ(arg3) + SQ(arg4))); + + arg3 /= var_fv1; + arg4 /= var_fv1; + + temp_s7->m[0][0] = -arg4 / sp54; + temp_s7->m[0][1] = arg3 / sp54; + temp_s7->m[1][1] = -arg4 / sp54; + temp_s7->m[1][0] = -arg3 / sp54; + + for (i = 0; i < temp_s5->unk4; i++) { + temp_s2 = &temp_s5->unk0[i]; + if (i == 0) { + uvGfx_802236CC(&D_80265080[arg0->unk2[i]]); + } else { + uvGfxMtxViewMul(&D_80265080[arg0->unk2[i]], 1); + } + + for (j = 0; j < temp_s2->unk4; j++) { + uvGfxStateDraw(&temp_s2->unk0[j]); + } + if (i == temp_s5->unk4 - 1) { + break; + } + temp_v1 = temp_s5->unk0[i].unk6 - temp_s5->unk0[i + 1].unk6; + for (j = 0; j <= temp_v1; j++) { + uvGfxMtxViewPop(); + } + } + temp_v1 = temp_s5->unk0[temp_s5->unk4 - 1].unk6; + for (i = 0; i <= temp_v1; i++) { + uvGfxMtxViewPop(); + } + temp_s7->m[0][0] = sp50; + temp_s7->m[0][1] = sp4C; + temp_s7->m[1][0] = sp48; + temp_s7->m[1][1] = sp44; +} + +void func_802180DC(s32 arg0, Unk80371120* arg1) { + Unk80263780* var_s2; + s32 i; + uvGfxUnkStructModel* temp_v0; + Unk8022B0A0* var_s3; + + var_s2 = &D_80263780[arg0]; + temp_v0 = gGfxUnkPtrs->unkC8[var_s2->unk0]; + var_s3 = arg1->unk0; + + if (temp_v0->unk18 > 1) { + arg1->unk1AC = temp_v0->unk18 - 1; + } else { + arg1->unk1AC = 0; + } + + for (i = 0; i < arg1->unk1AC; i++, var_s3++) { + func_8022B0A0(var_s3, &D_80265080[var_s2->unk2[i + 1]]); + arg1->unk190[i] = i + 1; + } +} diff --git a/src/kernel/graphics.c b/src/kernel/graphics.c index 72e9267..728eb92 100644 --- a/src/kernel/graphics.c +++ b/src/kernel/graphics.c @@ -259,7 +259,7 @@ void uvGfxStateDraw(uvGfxState_t* arg0) { u32 clearMode; u32 setMode; u16 var_t2; - uvGfxUnkStruct2* sp68; + uvGfxUnkStructTexture* sp68; u16 var_t1; s32 sp60; u32 var_a1_2; diff --git a/src/kernel/matrix.c b/src/kernel/matrix.c index 2eecf91..a141d15 100644 --- a/src/kernel/matrix.c +++ b/src/kernel/matrix.c @@ -88,13 +88,6 @@ void uvMat4CopyL(Mtx* dst, Mtx src) { dst->m[3][3] = src.m[3][3]; } -typedef struct Mtx_u { - u16 i[4][4]; - u16 f[4][4]; -} Mtx_u; -#define MTX_TO_PART(mtx) (*(Mtx_u*)&(mtx)) -#define L2F(mtx, i1, i2) ((((s16)MTX_TO_PART(mtx).i[(i1)][(i2)] << 0x10) | ((s16)MTX_TO_PART(mtx).f[(i1)][(i2)] & 0xFFFF)) / 65536.0f) - void uvMat4CopyL2F(Mtx4F* dst, Mtx src) { Mtx4F* dst2 = dst; s32 pad; diff --git a/src/kernel/sched.c b/src/kernel/sched.c index 21d3df2..fd98840 100644 --- a/src/kernel/sched.c +++ b/src/kernel/sched.c @@ -1,4 +1,5 @@ #include +#include #include #define VIDEO_MSG 666 @@ -31,7 +32,57 @@ extern s32 D_802B9C7C; extern s32 D_802B9C84; extern s32 D_802B9C88; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sched/func_8022B0A0.s") +void func_8022B0A0(Unk8022B0A0* arg0, Mtx4F* arg1) { + f32 temp_fa1; + f32 temp_fv0; + f32 temp_fv1; + s32 var_v0; + + temp_fa1 = arg1->m[0][0] + arg1->m[1][1] + arg1->m[2][2]; + + if (temp_fa1 >= 0.0f) { + temp_fv0 = uvSqrtF(temp_fa1 + 1.0f); + temp_fv1 = 0.5f / temp_fv0; + arg0->unkC = temp_fv0 * 0.5f; + arg0->unk0 = (arg1->m[2][1] - arg1->m[1][2]) * temp_fv1; + arg0->unk4 = (arg1->m[0][2] - arg1->m[2][0]) * temp_fv1; + arg0->unk8 = (arg1->m[1][0] - arg1->m[0][1]) * temp_fv1; + return; + } + var_v0 = 0; + if (arg1->m[0][0] < arg1->m[1][1]) { + var_v0 = 1; + } + if (arg1->m[var_v0][var_v0] < arg1->m[2][2]) { + var_v0 = 2; + } + switch (var_v0) { + case 0: + temp_fv0 = uvSqrtF((arg1->m[0][0] - (arg1->m[1][1] + arg1->m[2][2])) + 1.0f); + temp_fv1 = 0.5f / temp_fv0; + arg0->unk0 = temp_fv0 * 0.5f; + arg0->unk4 = (arg1->m[0][1] + arg1->m[1][0]) * temp_fv1; + arg0->unk8 = (arg1->m[2][0] + arg1->m[0][2]) * temp_fv1; + arg0->unkC = (arg1->m[2][1] - arg1->m[1][2]) * temp_fv1; + break; + case 1: + temp_fv0 = uvSqrtF((arg1->m[1][1] - (arg1->m[2][2] + arg1->m[0][0])) + 1.0f); + temp_fv1 = 0.5f / temp_fv0; + arg0->unk4 = temp_fv0 * 0.5f; + arg0->unk8 = (arg1->m[1][2] + arg1->m[2][1]) * temp_fv1; + arg0->unk0 = (arg1->m[0][1] + arg1->m[1][0]) * temp_fv1; + arg0->unkC = (arg1->m[0][2] - arg1->m[2][0]) * temp_fv1; + break; + case 2: + temp_fv0 = uvSqrtF((arg1->m[2][2] - (arg1->m[0][0] + arg1->m[1][1])) + 1.0f); + temp_fv1 = 0.5f / temp_fv0; + arg0->unk8 = temp_fv0 * 0.5f; + arg0->unk0 = (arg1->m[2][0] + arg1->m[0][2]) * temp_fv1; + arg0->unk4 = (arg1->m[1][2] + arg1->m[2][1]) * temp_fv1; + arg0->unkC = (arg1->m[1][0] - arg1->m[0][1]) * temp_fv1; + break; + } +} void _uvScDoneGfx(void) { OSScTask* scTask = D_802B9C60[D_802B9C6E]; diff --git a/src/kernel/sobj.c b/src/kernel/sobj.c index eb2191a..e833618 100644 --- a/src/kernel/sobj.c +++ b/src/kernel/sobj.c @@ -1,19 +1,303 @@ #include "common.h" +#include +#include +#include +#include -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/uvSobjsDraw.s") +extern s32 D_80248DD8; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/func_8022C7B8.s") +void func_80215E7C(uvGfxUnkStructModel*); +void func_80214840(s16, f32*, f32*); +s32 func_80206F64(void*, f32, f32, f32, f32); +void _uvSortAdd(s32, f32, void*, UnkStruct_80204D94*, f32, f32, ...); -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/func_8022C8D0.s") +void uvSobjsDraw(UnkStruct_80204D94* arg0, Mtx4F* arg1, u16 arg2, u16 arg3, UnkSobjDraw* arg4, u16 arg5, u8 arg6, s32 arg7) { + UnkSobjDraw* var_s2; + f32 temp_fs0; + f32 temp_fs1; + f32 temp_fs2; + f32 temp_fv0; + u32 var_v0; + u8 var_s1; + uvGfxUnkStructModel* temp_s0; + uvGfxUnkStructModel** temp_fp; + f32 spB8; + f32 spB4; + f32 spB0; + f32 spAC; + f32 spA8; + s32 i; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/func_8022CC28.s") + spB0 = arg0->unk1D0 - arg1->m[3][0]; + spAC = arg0->unk1D4 - arg1->m[3][1]; + spA8 = arg0->unk1D8 - arg1->m[3][2]; + func_80214840(arg6, &spB0, &spAC); -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/uvSobjLoadTerra.s") + temp_fp = gGfxUnkPtrs->unkC8; + for (i = 0; i < arg5; i++) { + var_s2 = &arg4[i]; -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/uvSobjPosm.s") + if (var_s2->unk0 == 0xFFFF) { + continue; + } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/func_8022D168.s") + if (!(var_s2->unk14 & arg2)) { + continue; + } + temp_s0 = temp_fp[var_s2->unk0]; + if (temp_s0 == NULL) { + _uvDebugPrintf("uvSobjsDraw: model %d not in level\n"); + continue; + } -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/func_8022D1E4.s") + temp_fs1 = var_s2->unk8 - spB0; + temp_fs2 = var_s2->unkC - spAC; + temp_fs0 = var_s2->unk10 - spA8; + if (!(var_s2->unk14 & arg3)) { + spB8 = temp_fs1; + spB4 = temp_fs2; + func_80214840(arg6 * -1, &spB8, &spB4); + if (func_80206F64(arg0->unk2E0, spB8, spB4, temp_fs0, temp_s0->unk1C) == 0) { + continue; + } + } + temp_fv0 = uvSqrtF(SQ(temp_fs1) + SQ(temp_fs2) + SQ(temp_fs0)); + if (arg0->unk200 == 1.0f) { + var_s1 = var_v0 = func_8022C7B8(temp_s0, temp_fv0); + } else { + var_s1 = var_v0 = func_8022C7B8(temp_s0, arg0->unk200 * temp_fv0); + } + if (var_v0 == 0xFF) { + continue; + } + if (temp_s0->unk11 & 1) { + _uvSortAdd(4, temp_fv0, var_s2, arg0, arg1->m[3][0], arg1->m[3][1], temp_fs1, temp_fs2, arg1, arg7, var_s1); + } else if (temp_s0->unk8[var_v0].unk5 != 0) { + func_8022CC28(var_s2, temp_s0, var_s1, temp_fs1, temp_fs2); + } else { + func_8022C8D0(var_s2, temp_s0, var_s1, arg1); + } + } +} -#pragma GLOBAL_ASM("asm/nonmatchings/kernel/sobj/uvSobjModel.s") +u8 func_8022C7B8(uvGfxUnkStructModel* arg0, f32 arg1) { + s32 temp_v1; + s32 i; + f32* temp_v0; + + temp_v0 = arg0->unkC; + temp_v1 = arg0->unk10; + if (temp_v0[temp_v1 - 1] <= arg1) { + return 0xFF; + } + + for (i = temp_v1; i > 0; i--) { + if (temp_v0[i - 1] < arg1) { + return i; + } + } + return 0; +} + +void func_8022C8D0(UnkSobjDraw* arg0, uvGfxUnkStructModel* arg1, u8 arg2, Mtx4F* arg3) { + uvGfxUnkStruct8* temp_s3; + uvGfxUnkStruct10* temp_s2; + s32 temp_v0; + s32 i; + s32 j; + Mtx4F sp114; + Mtx4F spD4; + s32 pad; + Mtx sp90; + + temp_s3 = &arg1->unk8[arg2]; + + for (i = 0; i < temp_s3->unk4; i++) { + temp_s2 = &temp_s3->unk0[i]; + uvGfx_802235A4(arg0->unk4[i], 1); + if (temp_s2->unkD != 0) { + uvMat4CopyL2F(&sp114, arg0->unk4[i]); + sp114.m[3][0] += arg3->m[3][0]; + sp114.m[3][1] += arg3->m[3][1]; + sp114.m[3][2] += arg3->m[3][2]; + uvGfxLookAt(&sp114); + } + + for (j = 0; j < temp_s2->unk4; j++) { + uvGfxStateDraw(&temp_s2->unk0[j]); + } + if (i == temp_s3->unk4 - 1) { + break; + } + + for (j = 0; j <= temp_s3->unk0[i].unk6 - temp_s3->unk0[i + 1].unk6; j++) { + uvGfxMtxViewPop(); + } + } + temp_v0 = temp_s3->unk0[temp_s3->unk4 - 1].unk6; + for (i = 0; i <= temp_v0; i++) { + uvGfxMtxViewPop(); + } + if (D_80248DD8 != 0) { + uvMat4CopyL2F(&spD4, arg0->unk4[0]); + + uvMat4UnkOp3(&spD4, arg1->unk20, arg1->unk20, arg1->unk20); + uvMat4CopyF2L(&sp90, &spD4); + uvGfx_802235A4(sp90, 1); + func_80215E7C(arg1); + uvGfxMtxViewPop(); + } +} + +void func_8022CC28(UnkSobjDraw* arg0, uvGfxUnkStructModel* arg1, u8 arg2, f32 arg3, f32 arg4) { + uvMtx* temp_s6; + s32 temp_v1; + s32 i; + s32 j; + Mtx sp88; + f32 temp_fv0; + uvGfxUnkStruct10* temp_s2; + uvGfxUnkStruct10* temp_v0; + uvGfxUnkStruct8* temp_s4; + s32 pad; + f32 sp70; + + sp70 = arg1->unk20 / gGfxUnkPtrs->unk1608; + temp_s4 = &arg1->unk8[arg2]; + temp_s6 = (uvMtx*)arg0->unk4; + sp88.m[0][0] = temp_s6->m[0][0]; + sp88.m[0][2] = temp_s6->m[0][2]; + sp88.m[2][0] = temp_s6->m[2][0]; + sp88.m[2][2] = temp_s6->m[2][2]; + temp_fv0 = uvSqrtF(SQ(arg3) + SQ(arg4)); + + if (temp_fv0 != 0.0f) { + arg3 /= temp_fv0; + arg4 /= temp_fv0; + } + + temp_s6->u.i[0][0] = (s32)(((-arg4 / sp70) * 65536.0f) + 0.5f) >> 0x10; + temp_s6->u.i[0][1] = (s32)(((arg3 / sp70) * 65536.0f) + 0.5f) >> 0x10; + temp_s6->u.f[0][0] = (s32)(((-arg4 / sp70) * 65536.0f) + 0.5f) & 0xFFFF; + temp_s6->u.f[0][1] = (s32)(((arg3 / sp70) * 65536.0f) + 0.5f) & 0xFFFF; + temp_s6->u.i[1][1] = (s32)(((-arg4 / sp70) * 65536.0f) + 0.5f) >> 0x10; + temp_s6->u.i[1][0] = (s32)(((-arg3 / sp70) * 65536.0f) + 0.5f) >> 0x10; + temp_s6->u.f[1][1] = (s32)(((-arg4 / sp70) * 65536.0f) + 0.5f) & 0xFFFF; + temp_s6->u.f[1][0] = (s32)(((-arg3 / sp70) * 65536.0f) + 0.5f) & 0xFFFF; + + for (i = 0; i < temp_s4->unk4; i++) { + temp_s2 = &temp_s4->unk0[i]; + + uvGfx_802235A4(arg0->unk4[i], 1); + + for (j = 0; j < temp_s2->unk4; j++) { + uvGfxStateDraw(&temp_s2->unk0[j]); + } + // FAKE + if (temp_s4) { } + if (i == temp_s4->unk4 - 1) { + break; + } + + temp_v1 = temp_s4->unk0[i].unk6 - temp_s4->unk0[i + 1].unk6; + for (j = 0; j <= temp_v1; j++) { + uvGfxMtxViewPop(); + } + } + temp_v1 = temp_s4->unk0[temp_s4->unk4 - 1].unk6; + for (i = 0; i <= temp_v1; i++) { + uvGfxMtxViewPop(); + } + temp_s6->m[0][0] = sp88.m[0][0]; + temp_s6->m[0][2] = sp88.m[0][2]; + temp_s6->m[2][0] = sp88.m[2][0]; + temp_s6->m[2][2] = sp88.m[2][2]; +} + +UnkSobjDraw* uvSobjLoadTerra(u32 arg0) { + UnkSobjDraw* temp_a0; + uvGfxUnkStructTerra* temp_v0; + uvUnkTileStruct* temp_v1; + + temp_v0 = gGfxUnkPtrs->unk4[(arg0 >> 0x18) & 0xFF]; + if (temp_v0 == NULL) { + _uvDebugPrintf("Sobj: terra %d not in level\n", (arg0 >> 0x18) & 0xFF); + return NULL; + } + + temp_v1 = &temp_v0->unk28[(arg0 >> 0xC) & 0xFFF]; + if (temp_v1 == NULL) { + _uvDebugPrintf("Sobj: bad soid 0x%x, tile not found in terra\n", arg0); + return NULL; + } + + temp_a0 = &temp_v1->unk40->unk10[arg0 & 0xFFF]; + if (temp_a0 == NULL) { + _uvDebugPrintf("Sobj: bad soid, sobj %d not in terra %d, tile %d\n", (arg0 >> 0x18) & 0xFF, (arg0 >> 0xC) & 0xFFF, arg0 & 0xFFF); + return NULL; + } + return temp_a0; +} + +void uvSobjPosm(u32 arg0, s32 arg1, Mtx4F* arg2) { + UnkSobjDraw* temp_v0; + f32 temp_fa0; + f32 temp_fa1; + f32 temp_ft4; + + temp_v0 = uvSobjLoadTerra(arg0); + if (temp_v0 == NULL) { + return; + } + + temp_fa0 = arg2->m[3][0] / gGfxUnkPtrs->unk1608; + temp_fa1 = arg2->m[3][1] / gGfxUnkPtrs->unk1608; + temp_ft4 = arg2->m[3][2] / gGfxUnkPtrs->unk1608; + + if (arg1 == 0 && (FABS(temp_fa0 - temp_v0->unk8) > 0.01f || FABS(temp_fa1 - temp_v0->unkC) > 0.01f || FABS(temp_ft4 - temp_v0->unk10) > 0.01f)) { + _uvDebugPrintf("uvSobjPosm: warning, trying to translate part 0\n"); + _uvDebugPrintf(" new %f , %f , %f\n", temp_fa0, temp_fa1, temp_ft4); + _uvDebugPrintf(" old %f , %f , %f\n", temp_v0->unk8, temp_v0->unkC, temp_v0->unk10); + } else { + uvMat4CopyF2L(&temp_v0->unk4[arg1], arg2); + } +} + +void func_8022D168(u32 arg0, s32 arg1, Mtx4F* arg2) { + UnkSobjDraw* temp_v0; + + temp_v0 = uvSobjLoadTerra(arg0); + if (temp_v0 != NULL) { + uvMat4CopyL2F(arg2, temp_v0->unk4[arg1]); + } +} + +u16 func_8022D1E4(u32 arg0) { + UnkSobjDraw* temp_v0; + + temp_v0 = uvSobjLoadTerra(arg0); + if (temp_v0 == NULL) { + return 0xFFFF; + } + return temp_v0->unk0; +} + +void uvSobjModel(u32 arg0, s32 arg1) { + UnkSobjDraw* temp_v0; + uvGfxUnkStructModel* temp_v1; + + temp_v0 = uvSobjLoadTerra(arg0); + if (temp_v0 == NULL) { + return; + } + temp_v1 = gGfxUnkPtrs->unkC8[arg1]; + if (temp_v1 == NULL) { + _uvDebugPrintf("uvSobjModel: model %d not in level\n", arg1); + return; + } + if (temp_v1->unk8->unk4 != gGfxUnkPtrs->unkC8[temp_v0->unk0]->unk8->unk4) { + _uvDebugPrintf("uvSobjModel: new model %d had different heirarchy\n", arg1); + return; + } + temp_v0->unk0 = arg1; +} diff --git a/src/kernel/sprite.c b/src/kernel/sprite.c index 8f78cad..8b306a0 100644 --- a/src/kernel/sprite.c +++ b/src/kernel/sprite.c @@ -76,7 +76,7 @@ void uvSprt_802301A4(void) { void _uvTxtDraw(s32 textureId) { unk_UVTX_1C* temp_a1; - uvGfxUnkStruct2* temp_a2; + uvGfxUnkStructTexture* temp_a2; s32 temp_a3; s32 temp_t1; s32 temp_ft1; @@ -123,7 +123,7 @@ void _uvTxtDraw(s32 textureId) { } } -void uvSprtFromBitmap(uvSprite_t* arg0, uvGfxUnkStruct2* arg1) { +void uvSprtFromBitmap(uvSprite_t* arg0, uvGfxUnkStructTexture* arg1) { if (arg0->textureId == 0xFFFF) { _uvDebugPrintf("Warning: Bitmap sprite switched to texture sprite w/o uvMemReset\n"); arg0->bitmap = NULL; @@ -144,7 +144,7 @@ void uvSprtFromBitmap(uvSprite_t* arg0, uvGfxUnkStruct2* arg1) { arg0->bitmap->LUToffset = 0; } -void uvSprt_80230750(uvSprite_t* arg0, uvGfxUnkStruct2* arg1) { +void uvSprt_80230750(uvSprite_t* arg0, uvGfxUnkStructTexture* arg1) { Sprite* sprite = &arg0->sprite; if (arg1 != NULL) { @@ -293,7 +293,7 @@ void uvSprtDraw(s32 sprite_id) { } void uvSprtSetBlit(uvSprite_t* arg0, s32 arg1) { - uvGfxUnkStruct1410* var_v1; + uvGfxUnkStructBlit* var_v1; Sprite* sprite = &arg0->sprite; var_v1 = gGfxUnkPtrs->unk1410[arg1]; @@ -385,7 +385,7 @@ s16 uvSprtGetHeight(s32 sprite_id) { } void uvSprtProps(s32 sprite_id, ...) { - uvGfxUnkStruct2* temp_s2; + uvGfxUnkStructTexture* temp_s2; uvSprite_t* temp_s1; va_list args; s32 token;