1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-15 04:14:34 +00:00

Decompile z_play.c and Match/Document some of z_view.c (#74)

* Decompile z_play.c and Match/Document some of z_view.c

Also fix the last non matching in z_sample.c and update some game state functions.

* Suggestions from PR #74

* Fix undefined reference to Gameplay_DrawOverlay

* Suggestion from PR #74 (2)

* Fix a fake argument in func_800BC450
This commit is contained in:
Roman971 2020-04-16 23:36:12 +02:00 committed by GitHub
parent 9ac1f8130d
commit 262f6c507c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
278 changed files with 5139 additions and 5939 deletions

View file

@ -2,154 +2,165 @@
#include <global.h>
#include <vt.h>
volatile u32 D_8012ABF0 = 1;
volatile u32 D_8012ABF0 = true;
// TODO replace UnkViewStruct with Viewport and match with that instead
void func_800AA190(UnkViewStruct* arg0, Viewport* viewport) {
s32 xLen;
s32 yLen;
void View_ViewportToVp(Vp* dest, Viewport* src) {
s32 width = src->rightX - src->leftX;
s32 height = src->bottomY - src->topY;
xLen = viewport->rightX - viewport->leftX;
yLen = viewport->bottomY - viewport->topY;
arg0->unk_0 = (xLen * 2);
arg0->unk_2 = (yLen * 2);
arg0->unk_4 = 0x01FF;
arg0->unk_6 = 0;
arg0->unk_8 = (((viewport->leftX * 2) + xLen) * 2);
arg0->unk_A = (((viewport->topY * 2) + yLen) * 2);
arg0->unk_C = 0x01FF;
arg0->unk_E = 0;
dest->vp.vscale[0] = width * 2;
dest->vp.vscale[1] = height * 2;
dest->vp.vscale[2] = 0x01FF;
dest->vp.vscale[3] = 0;
dest->vp.vtrans[0] = ((src->leftX * 2) + width) * 2;
dest->vp.vtrans[1] = ((src->topY * 2) + height) * 2;
dest->vp.vtrans[2] = 0x01FF;
dest->vp.vtrans[3] = 0;
}
View* func_800AA1F8(GraphicsContext* gfxCtx) {
View* View_New(GraphicsContext* gfxCtx) {
View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285);
if (view != NULL) {
func_80106860(view, 0, sizeof(View)); // TODO prototype this
func_800AA278(view, gfxCtx);
func_80106860(view, 0, sizeof(View)); // memset
View_Init(view, gfxCtx);
}
return view;
}
void func_800AA250(View* view) {
void View_Free(View* view) {
SystemArena_FreeDebug(view, "../z_view.c", 297);
}
void func_800AA278(View* view, GraphicsContext* gfxCtx) {
void View_Init(View* view, GraphicsContext* gfxCtx) {
view->gfxCtx = gfxCtx;
view->viewport.topY = 0;
view->viewport.bottomY = 240;
view->viewport.bottomY = SCREEN_HEIGHT;
view->viewport.leftX = 0;
view->viewport.rightX = 320;
view->magic = 0x56494557; //"VIEW"
view->viewport.rightX = SCREEN_WIDTH;
view->magic = 0x56494557; // "VIEW"
view->eye.x = 0.0f;
view->eye.y = 0.0f;
view->unk_24 = 1.0f;
view->fieldOfView = 60.0f;
view->fogDistance = 10.0f;
view->zDepth = 12800.0f;
view->scale = 1.0f;
view->fovy = 60.0f;
view->near = 10.0f;
view->far = 12800.0f;
view->unk_34.x = 0.0f;
view->unk_40.x = 0.0f;
view->unk_40.y = 1.0f;
view->unk_40.z = 0.0f;
view->eye.z = -1.0f;
if (D_8012ABF0 != 0) {
if (D_8012ABF0) {
if (&D_8012ABF0) {}
osSyncPrintf("\nview: initialize ---\n", gfxCtx, view);
D_8012ABF0 = 0;
osSyncPrintf("\nview: initialize ---\n");
D_8012ABF0 = false;
}
view->unk_124 = 0;
view->unk_120 = 7;
view->flags = 1 | 2 | 4;
func_800AA7B8(view);
}
void func_800AA358(View* view, Vec3f* vec1, Vec3f* vec2, Vec3f* vec3) {
if (vec1->x == vec2->x && vec1->z == vec2->z) {
vec1->x += 0.1f;
void func_800AA358(View* view, Vec3f* eye, Vec3f* vec2, Vec3f* vec3) {
if (eye->x == vec2->x && eye->z == vec2->z) {
eye->x += 0.1f;
}
view->eye = *vec1;
view->eye = *eye;
view->unk_34 = *vec2;
view->unk_40 = *vec3;
view->unk_120 |= 1;
view->flags |= 1;
}
void func_800AA3F0(View* view, Vec3f* vec1, Vec3f* vec2, Vec3f* vec3) {
view->eye = *vec1;
void func_800AA3F0(View* view, Vec3f* eye, Vec3f* vec2, Vec3f* vec3) {
view->eye = *eye;
view->unk_34 = *vec2;
view->unk_40 = *vec3;
}
void func_800AA43C(View* view, f32 arg1) {
view->unk_120 |= 4;
view->unk_24 = arg1;
void View_SetScale(View* view, f32 scale) {
view->flags |= 4;
view->scale = scale;
}
void func_800AA454(View* view, f32* arg1) {
*arg1 = view->unk_24;
void View_GetScale(View* view, f32* scale) {
*scale = view->scale;
}
void func_800AA460(View* view, f32 fieldOfView, f32 fogDistance, f32 zDepth) {
view->fieldOfView = fieldOfView;
view->fogDistance = fogDistance;
view->zDepth = zDepth;
view->unk_120 |= 4;
void func_800AA460(View* view, f32 fovy, f32 near, f32 far) {
view->fovy = fovy;
view->near = near;
view->far = far;
view->flags |= 4;
}
void func_800AA48C(View* view, f32* fieldOfView, f32* fogDistance, f32* zDepth) {
*fieldOfView = view->fieldOfView;
*fogDistance = view->fogDistance;
*zDepth = view->zDepth;
void func_800AA48C(View* view, f32* fovy, f32* near, f32* far) {
*fovy = view->fovy;
*near = view->near;
*far = view->far;
}
void func_800AA4A8(View* view, f32 fieldOfView, f32 fogDistance, f32 zDepth) {
view->fieldOfView = fieldOfView;
view->fogDistance = fogDistance;
view->zDepth = zDepth;
view->unk_120 |= 8;
view->unk_24 = 1.0f;
void func_800AA4A8(View* view, f32 fovy, f32 near, f32 far) {
view->fovy = fovy;
view->near = near;
view->far = far;
view->flags |= 8;
view->scale = 1.0f;
}
void func_800AA4E0(View* view, f32* fieldOfView, f32* fogDistance, f32* zDepth) {
*fieldOfView = view->fieldOfView;
*fogDistance = view->fogDistance;
*zDepth = view->zDepth;
void func_800AA4E0(View* view, f32* fovy, f32* near, f32* far) {
*fovy = view->fovy;
*near = view->near;
*far = view->far;
}
void func_800AA4FC(View* view, Viewport* viewport) {
void View_SetViewport(View* view, Viewport* viewport) {
view->viewport = *viewport;
view->unk_120 |= 2;
view->flags |= 2;
}
void func_800AA52C(View* view, Viewport* viewport) {
void View_GetViewport(View* view, Viewport* viewport) {
*viewport = view->viewport;
}
#ifdef NON_MATCHING
// regalloc, zeros optimised out
void func_800AA550(View* view) {
s32 phi_v1;
s32 phi_v1_2;
s32 varY;
s32 varX;
s32 pad;
s32 ulx;
s32 uly;
s32 lrx;
s32 lry;
GraphicsContext* gfxCtx;
s32 temp_a0;
Gfx* dispRefs[4];
Gfx* dispRefs[5];
gfxCtx = view->gfxCtx;
phi_v1 = func_800B38FC();
if (phi_v1 < 0) {
phi_v1 = 0;
varY = func_800B38FC();
varX = -1; // The following is optimized to varX = 0 but affects codegen
if (varX < 0) {
varX = 0;
}
if (phi_v1 >= 0x79) {
phi_v1 = 0x78;
if (varX > SCREEN_WIDTH / 2) {
varX = SCREEN_WIDTH / 2;
}
ulx = view->viewport.leftX + 0;
uly = view->viewport.topY + phi_v1;
lrx = view->viewport.rightX - 0;
lry = view->viewport.bottomY - phi_v1;
if (varY < 0) {
varY = 0;
}
if (varY > SCREEN_HEIGHT / 2) {
varY = SCREEN_HEIGHT / 2;
}
ulx = view->viewport.leftX + varX;
uly = view->viewport.topY + varY;
lrx = view->viewport.rightX - varX;
lry = view->viewport.bottomY - varY;
if (ulx < 0) {
__assert("ulx >= 0", "../z_view.c", 454);
}
@ -162,27 +173,27 @@ void func_800AA550(View* view) {
if (lry > SCREEN_HEIGHT) {
__assert("lry <= SCREEN_HT", "../z_view.c", 457);
}
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 459);
gDPPipeSync(gfxCtx->polyOpa.p++);
gDPSetScissor(gfxCtx->polyOpa.p++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
gDPPipeSync(gfxCtx->polyXlu.p++);
gDPSetScissor(gfxCtx->polyXlu.p++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 472);
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AA550.s")
#endif
void func_800AA76C(View* view, f32 arg1, f32 arg2, f32 arg3) {
view->unk_E8.x = arg1;
view->unk_E8.y = arg2;
view->unk_E8.z = arg3;
void func_800AA76C(View* view, f32 x, f32 y, f32 z) {
view->unk_E8.x = x;
view->unk_E8.y = y;
view->unk_E8.z = z;
}
void func_800AA78C(View* view, f32 arg1, f32 arg2, f32 arg3) {
view->unk_F4.x = arg1;
view->unk_F4.y = arg2;
view->unk_F4.z = arg3;
void func_800AA78C(View* view, f32 x, f32 y, f32 z) {
view->unk_F4.x = x;
view->unk_F4.y = y;
view->unk_F4.z = z;
}
void func_800AA7AC(View* view, f32 arg1) {
@ -218,7 +229,7 @@ void func_800AA840(View* view, Vec3f vec1, Vec3f vec2, f32 arg3) {
}
s32 func_800AA890(View* view, Mtx* mtx) {
MtxF mtxF;
MtxF mf;
if (view->unk_100 == 0.0f) {
return 0;
@ -235,21 +246,24 @@ s32 func_800AA890(View* view, Mtx* mtx) {
view->unk_110.y += ((view->unk_F4.y - view->unk_110.y) * view->unk_100);
view->unk_110.z += ((view->unk_F4.z - view->unk_110.z) * view->unk_100);
}
Matrix_MtxToMtxF(mtx, &mtxF);
Matrix_Put(&mtxF);
Matrix_RotateX(view->unk_104.x, 1);
Matrix_RotateY(view->unk_104.y, 1);
Matrix_RotateZ(view->unk_104.z, 1);
Matrix_MtxToMtxF(mtx, &mf);
Matrix_Put(&mf);
Matrix_RotateX(view->unk_104.x, MTXMODE_APPLY);
Matrix_RotateY(view->unk_104.y, MTXMODE_APPLY);
Matrix_RotateZ(view->unk_104.z, MTXMODE_APPLY);
Matrix_Scale(view->unk_110.x, view->unk_110.y, view->unk_110.z, MTXMODE_APPLY);
Matrix_RotateZ(-view->unk_104.z, 1);
Matrix_RotateY(-view->unk_104.y, 1);
Matrix_RotateX(-view->unk_104.x, 1);
Matrix_RotateZ(-view->unk_104.z, MTXMODE_APPLY);
Matrix_RotateY(-view->unk_104.y, MTXMODE_APPLY);
Matrix_RotateX(-view->unk_104.x, MTXMODE_APPLY);
Matrix_ToMtx(mtx, "../z_view.c", 566);
return 1;
}
void func_800AAA50(View* view, s32 arg1) {
arg1 = (view->unk_120 & arg1) | arg1 >> 4;
arg1 = (view->flags & arg1) | arg1 >> 4;
if (arg1 & 8) {
func_800AB0A8(view);
} else {
@ -257,91 +271,99 @@ void func_800AAA50(View* view, s32 arg1) {
}
}
#ifdef NON_MATCHING
// Just one stack var
s32 func_800AAA9C(View* view) {
s32 pad;
s32 pad1;
s32 ylen;
Viewport* viewport;
f32 aspect;
s32 width;
s32 height;
Vp* vp;
Mtx* projection;
MtxF* viewing;
Gfx* dispRefs[6];
s32 xlen;
Mtx* viewing;
GraphicsContext* gfxCtx;
s32 i;
MtxF mtxF;
MtxF mtxFv;
Gfx* dispRefs[5];
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 596);
viewport = Graph_Alloc(gfxCtx, sizeof(Viewport));
LogUtils_CheckNullPointer("vp", viewport, "../z_view.c", 601);
func_800AA190(viewport, &view->viewport);
view->unk_50 = *viewport;
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 601);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
func_800AA550(view);
gSPViewport(gfxCtx->polyOpa.p++, viewport);
gSPViewport(gfxCtx->polyXlu.p++, viewport);
gSPViewport(gfxCtx->polyOpa.p++, vp);
gSPViewport(gfxCtx->polyXlu.p++, vp);
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 616);
view->unk_E0 = projection;
xlen = view->viewport.rightX - view->viewport.leftX;
ylen = view->viewport.bottomY - view->viewport.topY;
if (HREG(80) == 0xB) {
if (HREG(94) != 0xB) {
HREG(94) = 0xB;
HREG(83) = 0x3C;
HREG(84) = 0x3415;
HREG(85) = 0xA;
HREG(86) = 0x3200;
HREG(87) = 0x64;
view->projectionPtr = projection;
width = view->viewport.rightX - view->viewport.leftX;
height = view->viewport.bottomY - view->viewport.topY;
aspect = (f32)width / (f32)height;
if (HREG(80) == 11) {
if (HREG(94) != 11) {
HREG(94) = 11;
HREG(83) = 60;
HREG(84) = 13333;
HREG(85) = 10;
HREG(86) = 12800;
HREG(87) = 100;
}
guPerspective(projection, &view->unk_11C, HREG(83), HREG(84) / 10000.0f, HREG(85), HREG(86), HREG(87) / 100.0f);
guPerspective(projection, &view->normal, HREG(83), HREG(84) / 10000.0f, HREG(85), HREG(86), HREG(87) / 100.0f);
} else {
guPerspective(projection, &view->unk_11C, view->fieldOfView, (f32)xlen / (f32)ylen, view->fogDistance,
view->zDepth, view->unk_24);
guPerspective(projection, &view->normal, view->fovy, aspect, view->near, view->far, view->scale);
}
if (QREG(88) & 1) {
osSyncPrintf("fovy %f near %f far %f scale %f aspect %f normal %08x\n", view->fieldOfView, view->fogDistance,
view->zDepth, view->unk_24, (f32)xlen / (f32)ylen, view->unk_11C);
Matrix_MtxToMtxF(projection, &mtxF);
s32 i;
MtxF mf;
osSyncPrintf("fovy %f near %f far %f scale %f aspect %f normal %08x\n", view->fovy, view->near, view->far,
view->scale, aspect, view->normal);
Matrix_MtxToMtxF(projection, &mf);
osSyncPrintf("projection\n");
for (i = 0; i < 4; i++) {
osSyncPrintf(" %f %f %f %f\n", mtxF.mf[i][0], mtxF.mf[i][1], mtxF.mf[i][2],
mtxF.mf[i][3]);
osSyncPrintf(" %f %f %f %f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]);
}
osSyncPrintf("\n");
}
view->unk_60 = *projection;
view->projection = *projection;
func_800AA890(view, projection);
gSPPerspNormalize(gfxCtx->polyOpa.p++, view->unk_11C);
gSPPerspNormalize(gfxCtx->polyOpa.p++, view->normal);
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPPerspNormalize(gfxCtx->polyXlu.p++, view->unk_11C);
gSPPerspNormalize(gfxCtx->polyXlu.p++, view->normal);
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
viewing = Graph_Alloc(gfxCtx, sizeof(MtxF));
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 667);
view->unk_E4 = viewing;
view->viewingPtr = viewing;
if (view->eye.x == view->unk_34.x && view->eye.y == view->unk_34.y && view->eye.z == view->unk_34.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
func_80101E34(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
view->unk_A0 = *viewing;
view->viewing = *viewing;
if (QREG(88) & 2) {
Matrix_MtxToMtxF(view->unk_E4, &mtxFv);
s32 i;
MtxF mf;
Matrix_MtxToMtxF(view->viewingPtr, &mf);
osSyncPrintf("viewing\n");
for (i = 0; i < 4; i++) {
osSyncPrintf(" %f %f %f %f\n", mtxFv.mf[i][0], mtxFv.mf[i][1], mtxFv.mf[i][2],
mtxFv.mf[i][3]);
osSyncPrintf(" %f %f %f %f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]);
}
osSyncPrintf("\n");
}
@ -350,224 +372,227 @@ s32 func_800AAA9C(View* view) {
gSPMatrix(gfxCtx->polyXlu.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 711);
return 1;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AAA9C.s")
#endif
s32 func_800AB0A8(View* view) {
Viewport* viewport;
Vp* vp;
Mtx* projection;
s32 pad;
s32 pad1;
GraphicsContext* gfxCtx;
Gfx* dispRefs[3];
Gfx* dispRefs[5];
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 726);
viewport = Graph_Alloc(gfxCtx, sizeof(Viewport));
LogUtils_CheckNullPointer("vp", viewport, "../z_view.c", 730);
func_800AA190(viewport, &view->viewport);
view->unk_50 = *viewport;
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 730);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
func_800AA550(view);
gSPViewport(gfxCtx->polyOpa.p++, viewport);
gSPViewport(gfxCtx->polyXlu.p++, viewport);
gSPViewport(gfxCtx->overlay.p++, viewport);
gSPViewport(gfxCtx->polyOpa.p++, vp);
gSPViewport(gfxCtx->polyXlu.p++, vp);
gSPViewport(gfxCtx->overlay.p++, vp);
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 744);
view->unk_E0 = projection;
func_801045A4(projection, -(f32)(s32)gScreenWidth * 0.5f, (f32)(s32)gScreenWidth * 0.5f,
-(f32)(s32)gScreenHeight * 0.5f, (f32)(s32)gScreenHeight * 0.5f, view->fogDistance, view->zDepth,
view->unk_24);
view->projectionPtr = projection;
view->unk_60 = *projection;
func_801045A4(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
(f32)gScreenHeight * 0.5f, view->near, view->far, view->scale);
view->projection = *projection;
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 762);
return 1;
}
#ifdef NON_MATCHING
// saved registers allocated differently, everything else is OK
s32 func_800AB2C4(View* view) {
Vp* vp;
Mtx* projection;
f32 pad;
f32 pad1;
Viewport* viewport;
Gfx* dispRefs[4];
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
if (1) {} // Necessary to match
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 777);
viewport = Graph_Alloc(gfxCtx, sizeof(Viewport));
LogUtils_CheckNullPointer("vp", viewport, "../z_view.c", 781);
func_800AA190(viewport, &view->viewport);
view->unk_50 = *viewport;
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 781);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
gDPPipeSync(gfxCtx->overlay.p++);
gDPSetScissor(gfxCtx->overlay.p++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY,
view->viewport.rightX, view->viewport.bottomY);
gSPViewport(gfxCtx->overlay.p++, viewport);
gSPViewport(gfxCtx->overlay.p++, vp);
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 791);
view->unk_E0 = projection;
func_801045A4(projection, -(f32)(s32)gScreenWidth * 0.5f, (f32)(s32)gScreenWidth * 0.5f,
-(f32)(s32)gScreenHeight * 0.5f, (f32)(s32)gScreenHeight * 0.5f, view->fogDistance, view->zDepth,
view->unk_24);
view->unk_60 = *projection;
view->projectionPtr = projection;
func_801045A4(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
(f32)gScreenHeight * 0.5f, view->near, view->far, view->scale);
view->projection = *projection;
gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 801);
return 1;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AB2C4.s")
#endif
#ifdef NON_MATCHING
// regalloc
s32 func_800AB560(View* view) {
s32 pad;
s32 pad1;
s32 pad2;
s32 pad3;
GraphicsContext* gfxCtx;
Viewport* viewport;
Mtx* projection;
MtxF* viewing;
Gfx* dispRefs[6];
s32 pad[2];
f32 aspect;
s32 width;
s32 height;
Vp* vp;
Mtx* projection;
Mtx* viewing;
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 816);
viewport = Graph_Alloc(gfxCtx, sizeof(Viewport));
LogUtils_CheckNullPointer("vp", viewport, "../z_view.c", 821);
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 821);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
func_800AA190(viewport, &view->viewport);
view->unk_50 = *viewport;
gDPPipeSync(gfxCtx->overlay.p++);
gDPSetScissor(gfxCtx->overlay.p++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY,
view->viewport.rightX, view->viewport.bottomY);
gSPViewport(gfxCtx->overlay.p++, viewport);
gSPViewport(gfxCtx->overlay.p++, vp);
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 833);
view->projectionPtr = projection;
view->unk_E0 = projection;
guPerspective(projection, &view->unk_11C, view->fieldOfView,
(f32)(view->viewport.rightX - view->viewport.leftX) /
(f32)(view->viewport.bottomY - view->viewport.topY),
view->fogDistance, view->zDepth, view->unk_24);
view->unk_60 = *projection;
gSPPerspNormalize(gfxCtx->overlay.p++, view->unk_11C);
width = view->viewport.rightX - view->viewport.leftX;
height = view->viewport.bottomY - view->viewport.topY;
aspect = (f32)width / (f32)height;
guPerspective(projection, &view->normal, view->fovy, aspect, view->near, view->far, view->scale);
view->projection = *projection;
gSPPerspNormalize(gfxCtx->overlay.p++, view->normal);
gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
viewing = Graph_Alloc(gfxCtx, sizeof(MtxF));
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 848);
view->viewingPtr = viewing;
view->unk_E4 = viewing;
if (view->eye.x == view->unk_34.x && view->eye.y == view->unk_34.y && view->eye.z == view->unk_34.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
func_80101E34(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
view->unk_A0 = *viewing;
view->viewing = *viewing;
gSPMatrix(gfxCtx->overlay.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 871);
return 1;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AB560.s")
#endif
s32 func_800AB944(View* view) {
Gfx* dispRefs[5];
Graph_OpenDisps(dispRefs, view->gfxCtx, "../z_view.c", 878);
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
func_80101E34(view->unk_E4, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
func_80101E34(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y,
view->unk_34.z, view->unk_40.x, view->unk_40.y, view->unk_40.z);
Graph_CloseDisps(dispRefs, view->gfxCtx, "../z_view.c", 886);
return 1;
}
#ifdef NON_MATCHING
// saved register usage is wrong, relatively minor reorderings, regalloc
s32 func_800AB9EC(View* view, s32 arg1, Gfx** p) {
Viewport* viewport;
Mtx* projection;
Mtx* projection2;
MtxF* viewing;
GraphicsContext* gfxCtx;
Gfx* pLocal;
s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
GraphicsContext* gfxCtx = view->gfxCtx;
Gfx* gfx = *gfxp;
arg1 = (view->flags & arg1) | arg1 >> 4;
gfxCtx = view->gfxCtx;
pLocal = *p;
arg1 = (view->unk_120 & arg1) | arg1 >> 4;
if (arg1 & 2) {
viewport = Graph_Alloc(view->gfxCtx, sizeof(Viewport));
LogUtils_CheckNullPointer("vp", viewport, "../z_view.c", 910);
func_800AA190(viewport, &view->viewport);
Vp* vp = Graph_Alloc(view->gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 910);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
view->unk_50 = *viewport;
gDPPipeSync(pLocal++);
gDPSetScissor(pLocal++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
gDPPipeSync(gfx++);
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
view->viewport.bottomY);
gSPViewport(pLocal++, viewport);
gSPViewport(gfx++, vp);
}
if (arg1 & 8) {
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
Mtx* projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 921);
view->unk_E0 = projection;
func_801045A4(projection, -(f32)(s32)gScreenWidth * 0.5f, (f32)(s32)gScreenWidth * 0.5f,
-(f32)(s32)gScreenHeight * 0.5f, (f32)(s32)gScreenHeight * 0.5f, view->fogDistance, view->zDepth,
view->unk_24);
view->projectionPtr = projection;
view->unk_60 = *projection;
func_801045A4(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
(f32)gScreenHeight * 0.5f, view->near, view->far, view->scale);
gSPMatrix(pLocal++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
view->projection = *projection;
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
} else if (arg1 & 6) {
projection2 = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection2, "../z_view.c", 932);
view->unk_E0 = projection2;
guPerspective(projection2, &view->unk_11C, view->fieldOfView,
(f32)(view->viewport.rightX - view->viewport.leftX) /
(f32)(view->viewport.bottomY - view->viewport.topY),
view->fogDistance, view->zDepth, view->unk_24);
s32 width;
s32 height;
Mtx* projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 932);
view->projectionPtr = projection;
view->unk_60 = *projection2;
width = view->viewport.rightX - view->viewport.leftX;
height = view->viewport.bottomY - view->viewport.topY;
gSPPerspNormalize(pLocal++, view->unk_11C);
gSPMatrix(pLocal++, projection2, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
guPerspective(projection, &view->normal, view->fovy, (f32)width / (f32)height, view->near, view->far,
view->scale);
view->projection = *projection;
gSPPerspNormalize(gfx++, view->normal);
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
}
if (arg1 & 1) {
viewing = Graph_Alloc(gfxCtx, sizeof(MtxF));
Mtx* viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 948);
view->unk_E4 = viewing;
view->viewingPtr = viewing;
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
func_80101E34(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
view->unk_A0 = *viewing;
view->viewing = *viewing;
gSPMatrix(pLocal++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
gSPMatrix(gfx++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
}
view->unk_120 = 0;
*p = pLocal;
view->flags = 0;
*gfxp = gfx;
return 1;
}
#else
@ -575,28 +600,28 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** p) {
#endif
s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ) {
s32 errorCode = 0;
s32 error = 0;
if ((eyeX * eyeX) + (eyeY * eyeY) + (eyeZ * eyeZ) > 1073676288.0f) {
errorCode = 3;
if (SQ(eyeX) + SQ(eyeY) + SQ(eyeZ) > SQ(32767.0f)) {
error = 3;
} else {
f32 absEyeX;
f32 absEyeY;
f32 absEyeZ;
absEyeX = ABS(eyeX);
absEyeY = ABS(eyeY);
absEyeZ = ABS(eyeZ);
f32 absEyeX = ABS(eyeX);
f32 absEyeY = ABS(eyeY);
f32 absEyeZ = ABS(eyeZ);
if (((18900.0f < absEyeX) || (18900.0f < absEyeY)) || (18900.0f < absEyeZ)) {
errorCode = 2;
error = 2;
} else if (((16000.0f < absEyeX) || (16000.0f < absEyeY)) || (16000.0f < absEyeZ)) {
errorCode = 1;
error = 1;
}
}
if (errorCode != 0) {
if (error != 0) {
osSyncPrintf(VT_FGCOL(RED));
// Is too large
osSyncPrintf("eye が大きすぎます eye=[%8.3f %8.3f %8.3f] error=%d\n", eyeX, eyeY, eyeZ, errorCode);
// "Is too large"
osSyncPrintf("eye が大きすぎます eye=[%8.3f %8.3f %8.3f] error=%d\n", eyeX, eyeY, eyeZ, error);
osSyncPrintf(VT_RST);
}
return errorCode;
return error;
}