Implement all of emu64, mostly matching

This commit is contained in:
Cuyler36
2024-07-26 14:37:51 -04:00
parent c60b001aa2
commit 35089a48e4
11 changed files with 5951 additions and 750 deletions
File diff suppressed because it is too large Load Diff
+485
View File
@@ -0,0 +1,485 @@
#include "emu64.hpp"
#include "boot.h"
static const char kakko[] = "/\\/\\||||||||\\/\\/";
void emu64::disp_matrix(GC_Mtx mtx) {
for (int i = 0; i < 4; i++) {
if (mtx != nullptr) {
for (int x = 0; x < 4; x++) {
this->Printf("%10.3f", mtx[i][x]);
}
}
this->Printf("\n", kakko[3 + i * 4]);
}
}
const char* emu64::segchk(u32 segment) {
static char str[64];
char buf[30];
const char str0[] = "anime_4_txt+%4u";
const char str1[] = "anime_6_model+sizeof(Mtx)*%2u";
u32 partial_addr = (u32)seg2k0(segment);
u32 addr = convert_partial_address(partial_addr);
str[0] = '\0';
if (segment == partial_addr) {
if (addr == partial_addr) {
snprintf(str, sizeof(str), "0x%08x", segment);
} else {
snprintf(str, sizeof(str), "0x%08x /* PADDR=0x%08x */", segment, partial_addr);
}
} else {
const char* s;
if (SEG_EQUALS(segment, SOFTSPRITE_MTX_SEG)) {
s = "softsprite_mtx";
} else if (SEG_EQUALS(segment, ANIME_1_TXT_SEG)) {
s = "anime_1_txt";
} else if (SEG_EQUALS(segment, ANIME_2_TXT_SEG)) {
s = "anime_2_txt";
} else if (SEG_EQUALS(segment, ANIME_3_TXT_SEG)) {
s = "anime_3_txt";
} else if (SEG_EQUALS(segment, ANIME_4_TXT_SEG)) {
s = "anime_4_txt";
} else if (SEG_EQUALS(segment, ANIME_5_TXT_SEG)) {
s = "anime_5_txt";
} else if (SEG_EQUALS(segment, ANIME_6_TXT_SEG)) {
s = "anime_6_txt";
} else if (SEG_EQUALS(segment, ANIME_1_TXT_SEG)) {
s = "anime_1_model";
} else if (SEG_EQUALS(segment, ANIME_2_TXT_SEG)) {
s = "anime_2_model";
} else if (SEG_EQUALS(segment, ANIME_3_TXT_SEG)) {
s = "anime_3_model";
} else if (SEG_EQUALS(segment, ANIME_4_TXT_SEG)) {
s = "anime_4_model";
} else if (SEG_EQUALS(segment, ANIME_5_TXT_SEG)) {
s = "anime_5_model";
} else if (SEG_EQUALS(segment, ANIME_6_TXT_SEG)) {
s = "anime_6_model";
} else if (segment > SEG_2_SEGADDR(ANIME_4_TXT_SEG) && segment < (SEG_2_SEGADDR(ANIME_4_TXT_SEG) + 0x800)) {
snprintf(buf, sizeof(buf) - 1, str0, segment - SEG_2_SEGADDR(ANIME_4_TXT_SEG));
s = buf;
} else {
if (segment > 0xD000000 && segment < 0xD000408) {
int comb = segment - 0x0D000000;
snprintf(buf, sizeof(buf) - 1, str1, comb / (int)sizeof(Mtx));
s = buf;
} else {
s = nullptr;
}
}
if (addr == partial_addr) {
if (s != nullptr) {
snprintf(str, sizeof(str), "%s /* 0x%08x */", s, partial_addr);
} else {
snprintf(str, sizeof(str), "0x%08x /* ### 0x%08x */", segment, partial_addr);
}
} else {
if (s != nullptr) {
snprintf(str, sizeof(str), "%s /* 0x%08x PADDR=0x%08x */", s, partial_addr, addr);
} else {
snprintf(str, sizeof(str), "0x%08x /* ### 0x%08x PADDR=0x%08x */", segment, partial_addr, addr);
}
}
}
return str;
}
const char* emu64::combine_name(u32 param, u32 type) {
const char* ret;
switch (param) {
case 0:
ret = "COMBINED";
break;
case 1:
ret = "TEXEL0";
break;
case 2:
ret = "TEXEL1";
break;
case 3:
ret = "PRIMITIVE";
break;
case 4:
ret = "SHADE";
break;
case 5:
ret = "ENVIRONMENT";
break;
case 6:
ret = (type == COMBINER_PARAM_B) ? "CENTER" : ((type == COMBINER_PARAM_C) ? "SCALE" : "1");
break;
case 7:
ret = (type == COMBINER_PARAM_A)
? "NOISE"
: ((type == COMBINER_PARAM_B) ? "K4" : ((type == COMBINER_PARAM_C) ? "COMBINED_ALPHA" : "0"));
break;
default:
if (type == COMBINER_PARAM_C) {
switch (param) {
case 8:
ret = "TEXEL0_ALPHA";
break;
case 9:
ret = "TEXEL1_ALPHA";
break;
case 10:
ret = "PRIMITIVE_ALPHA";
break;
case 11:
ret = "SHADE_ALPHA";
break;
case 12:
ret = "ENV_ALPHA";
break;
case 13:
ret = "LOD_FRACTION";
break;
case 14:
ret = "PRIM_LOD_FRAC";
break;
case 15:
ret = "K5";
break;
default:
ret = "0";
break;
}
} else {
ret = "0";
}
break;
}
return ret;
}
const char* emu64::combine_alpha(int param, int type) {
const char* ret;
switch (param) {
case 0:
ret = (type == COMBINER_PARAM_C) ? "LOD_FRACTION" : "COMBINED";
break;
case 1:
ret = "TEXEL0";
break;
case 2:
ret = "TEXEL1";
break;
case 3:
ret = "PRIMITIVE";
break;
case 4:
ret = "SHADE";
break;
case 5:
ret = "ENVIRONMENT";
break;
case 6:
ret = (type == COMBINER_PARAM_C) ? "PRIM_LOD_FRAC" : "1";
break;
case 7:
ret = "0";
break;
/* There should be a default case here, but they forgot it. */
/* It returns a pointer to the emu64 class instead. */
#ifdef EMU64_FIX_COMBINE_NAME_RETURN_VALUES
default:
ret = "0";
break;
#endif
}
return ret;
}
const char* emu64::combine_tev_color_name(u32 color_param) {
const char* ret;
switch (color_param) {
case 0:
ret = "COMBINED";
break;
case 1:
ret = "COMBINED_ALPHA";
break;
case 2:
ret = "(FILL)";
break;
case 3:
ret = "PRIM_LOD_FRAC";
break;
case 4:
ret = "PRIMITIVE";
break;
case 5:
ret = "PRIMITIVE_ALPHA";
break;
case 6:
ret = "ENVIRONMENT";
break;
case 7:
ret = "ENV_ALPHA";
break;
case 8:
ret = "TEXEL0";
break;
case 9:
ret = "TEXEL0_ALPHA";
break;
case 10:
ret = "SHADE";
break;
case 11:
ret = "SHADE_ALPHA";
break;
case 12:
ret = "1";
break;
case 13:
ret = "(HALF)";
break;
case 14:
ret = "(KONST)";
break;
case 15:
ret = "0";
break;
/* There should be a default case here, but they forgot it. */
/* It returns a pointer to the emu64 class instead. */
#ifdef EMU64_FIX_COMBINE_NAME_RETURN_VALUES
default:
ret = "0";
break;
#endif
}
}
const char* emu64::combine_tev_alpha_name(u32 alpha_param) {
const char* ret;
switch (alpha_param) {
case 0:
ret = "COMBINED";
break;
case 1:
ret = "PRIM_LOD_FRAC";
break;
case 2:
ret = "PRIMITIVE";
break;
case 3:
ret = "ENVIRONMENT";
break;
case 4:
ret = "TEXEL0";
break;
case 5:
ret = "SHADE";
break;
case 6:
ret = "1";
break;
case 7:
ret = "0";
break;
/* There should be a default case here, but they forgot it. */
/* It returns a pointer to the emu64 class instead. */
#ifdef EMU64_FIX_COMBINE_NAME_RETURN_VALUES
default:
ret = "0";
break;
#endif
}
return ret;
}
typedef struct {
u32 value;
char* name;
u32 mask;
} GeometryModeParameterInfo;
#define NUM_GEOMETRYMODE_FLAGS 16
static const GeometryModeParameterInfo geomtbl[NUM_GEOMETRYMODE_FLAGS] = {
{ G_ZBUFFER, "G_ZBUFFER", G_ZBUFFER },
{ G_TEXTURE_ENABLE, "G_TEXTURE_ENABLE", G_TEXTURE_ENABLE },
{ G_SHADE, "G_SHADE", G_SHADE },
{ G_SHADING_SMOOTH, "G_SHADING_SMOOTH", G_SHADING_SMOOTH },
{ G_CULL_FRONT, "G_CULL_FRONT", G_CULL_FRONT },
{ G_CULL_BACK, "G_CULL_BACK", G_CULL_BACK },
{ G_FOG, "G_FOG", G_FOG },
{ G_LIGHTING, "G_LIGHTING", G_LIGHTING },
{ G_TEXTURE_GEN, "G_TEXTURE_GEN", G_TEXTURE_GEN },
{ G_TEXTURE_GEN_LINEAR, "G_TEXTURE_GEN_LINEAR", G_TEXTURE_GEN_LINEAR },
{ G_LOD, "G_LOD", G_LOD },
{ G_LIGHTING_POSITIONAL, "G_LIGHTING_POSITIONAL", G_LIGHTING_POSITIONAL },
{ G_DECAL_EQUAL, "G_DECAL_EQUAL", G_DECAL_ALWAYS },
{ G_DECAL_GEQUAL, "G_DECAL_GEQUAL", G_DECAL_ALWAYS },
{ G_DECAL_ALWAYS, "G_DECAL_ALWAYS", G_DECAL_ALWAYS },
{ G_DECAL_SPECIAL, "G_DECAL_SPECIAL", G_DECAL_SPECIAL }
};
void emu64::print_geomflags(u32 flags) {
u32 i;
int empty = TRUE;
for (i = 0; i < NUM_GEOMETRYMODE_FLAGS; i++) {
if ((flags & geomtbl[i].mask) == geomtbl[i].value) {
if (empty) {
empty = FALSE;
} else {
this->Printf("|");
}
this->Printf("%s", geomtbl[i].name);
}
}
if (empty) {
this->Printf("0");
}
}
typedef struct {
char* name;
u32 value;
u32 mask;
} RendermodeInfo;
void emu64::show_render(u32 data) {
static const RendermodeInfo flags[] = {
{ "AA_EN", AA_EN, AA_EN },
{ "Z_CMP", Z_CMP, Z_CMP },
{ "Z_UPD", Z_UPD, Z_UPD },
{ "IM_RD", IM_RD, IM_RD },
{ "CLR_ON_CVG", CLR_ON_CVG, CLR_ON_CVG },
{ "CVG_DST_CLAMP", CVG_DST_CLAMP, CVG_DST_SAVE },
{ "CVG_DST_WRAP", CVG_DST_WRAP, CVG_DST_SAVE },
{ "CVG_DST_FULL", CVG_DST_FULL, CVG_DST_SAVE },
{ "CVG_DST_SAVE", CVG_DST_SAVE, CVG_DST_SAVE },
{ "ZMODE_OPA", ZMODE_OPA, ZMODE_DEC },
{ "ZMODE_INTER", ZMODE_INTER, ZMODE_DEC },
{ "ZMODE_XLU", ZMODE_XLU, ZMODE_DEC },
{ "ZMODE_DEC", ZMODE_DEC, ZMODE_DEC },
{ "CVG_X_ALPHA", CVG_X_ALPHA, CVG_X_ALPHA },
{ "ALPHA_CVG_SEL", ALPHA_CVG_SEL, ALPHA_CVG_SEL },
{ "FORCE_BL", FORCE_BL, FORCE_BL },
};
static const char* const m[4][4] = {
{ "G_BL_CLR_IN", "G_BL_CLR_MEM", "G_BL_CLR_BL", "G_BL_CLR_FOG" },
{ "G_BL_A_SHADE", "G_BL_0", "G_BL_A_IN", "G_BL_A_FOG" },
{ "G_BL_CLR_IN", "G_BL_CLR_MEM", "G_BL_CLR_BL", "G_BL_CLR_FOG" },
{ "G_BL_A_MEM", "G_BL_0", "G_BL_1MA", "G_BL_1" },
};
EMU64_LOG("\ngsDPSetRenderBlender(\n");
u32 c1 = (data >> 18) & 0x3333;
u32 c2 = (data >> 16) & 0x3333;
for (u32 i = 0; i < ARRAY_COUNT(flags); i++) {
if ((data & flags[i].mask) == flags[i].value) {
this->Printf("%s|", flags[i].name);
}
}
this->Printf("\nGBL_c1(%s, %s, %s, %s)|", m[0][(c1 >> 12) & 3], m[1][(c1 >> 8) & 3], m[2][(c1 >> 4) & 3],
m[3][c1 & 3]);
this->Printf("\nGBL_c2(%s, %s, %s, %s)", m[0][(c2 >> 12) & 3], m[1][(c2 >> 8) & 3], m[2][(c2 >> 4) & 3],
m[3][c2 & 3]);
EMU64_LOG("\n),");
}
void emu64::show_vtx(Vtx* vtx, int count, int begin) {
for (int i = 0; i < count; i++, vtx++) {
if ((this->geometry_mode & G_LIGHTING) != 0) {
Vtx_tn* p_vtx = &vtx->n;
// clang-format off
this->Printf(
"\n{{%6d, %6d, %6d, %d, %6d, %6d, %4d, %4d, %4d, %3d}}, /* vc%02d */",
p_vtx->ob[0], p_vtx->ob[1], p_vtx->ob[2], /* Position */
p_vtx->flag, /* Flag */
p_vtx->tc[0], p_vtx->tc[1], /* Texture Coordinates */
p_vtx->n[0], p_vtx->n[1], p_vtx->n[2], /* Normal */
p_vtx->a, /* Alpha */
begin + i /* Vertex # */
);
// clang-format on
} else {
Vtx_t* p_vtx = &vtx->v;
// clang-format off
this->Printf(
"\n{{%6d, %6d, %6d, %d, %6d, %6d, %4d, %4d, %4d, %3d}}, /* vn%02d */",
p_vtx->ob[0], p_vtx->ob[1], p_vtx->ob[2], /* Position */
p_vtx->flag, /* Flag */
p_vtx->tc[0], p_vtx->tc[1], /* Texture Coordinates */
p_vtx->cn[0], p_vtx->cn[1], p_vtx->cn[2], p_vtx->cn[3], /* Color */
begin + i /* Vertex # */
);
// clang-format on
}
}
}
void emu64::print_combine(u64 cmd) {
Gsetcombine_new* combine = (Gsetcombine_new*)&cmd;
this->Printf0(
"gsDPSetCombineLERP(%s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s),",
this->combine_name(combine->a0, COMBINER_PARAM_A), this->combine_name(combine->b0, COMBINER_PARAM_B),
this->combine_name(combine->c0, COMBINER_PARAM_C), this->combine_name(combine->d0, COMBINER_PARAM_D),
this->combine_alpha(combine->Aa0, COMBINER_PARAM_A), this->combine_alpha(combine->Ab0, COMBINER_PARAM_B),
this->combine_alpha(combine->Ac0, COMBINER_PARAM_C), this->combine_alpha(combine->Ad0, COMBINER_PARAM_D),
this->combine_name(combine->a1, COMBINER_PARAM_A), this->combine_name(combine->b1, COMBINER_PARAM_B),
this->combine_name(combine->c1, COMBINER_PARAM_C), this->combine_name(combine->d1, COMBINER_PARAM_D),
this->combine_alpha(combine->Aa1, COMBINER_PARAM_A), this->combine_alpha(combine->Ab1, COMBINER_PARAM_B),
this->combine_alpha(combine->Ac1, COMBINER_PARAM_C), this->combine_alpha(combine->Ad1, COMBINER_PARAM_D));
}
void emu64::print_combine_tev(u64 combine_tev) {
Gsetcombine_tev* c_tev = (Gsetcombine_tev*)&combine_tev;
this->Printf0("gsDPSetCombineTev(%s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s),",
this->combine_tev_color_name(c_tev->a0), this->combine_tev_color_name(c_tev->b0),
this->combine_tev_color_name(c_tev->c0), this->combine_tev_color_name(c_tev->d0),
this->combine_tev_alpha_name(c_tev->Aa0), this->combine_tev_alpha_name(c_tev->Ab0),
this->combine_tev_alpha_name(c_tev->Ac0), this->combine_tev_alpha_name(c_tev->Ad0),
this->combine_tev_color_name(c_tev->a1), this->combine_tev_color_name(c_tev->b1),
this->combine_tev_color_name(c_tev->c1), this->combine_tev_color_name(c_tev->d1),
this->combine_tev_alpha_name(c_tev->Aa1), this->combine_tev_alpha_name(c_tev->Ab1),
this->combine_tev_alpha_name(c_tev->Ac1), this->combine_tev_alpha_name(c_tev->Ad1));
}
void emu64::print_guMtxXFM1F_dol2(MtxP mtx, GXProjectionType type, float x, float y, float z) {
if (type == GX_PERSPECTIVE) {
float s = -1.0f / z;
float x0 = mtx[0][0] * x * s - mtx[0][2];
float y0 = mtx[1][1] * y * s - mtx[1][2];
float z0 = mtx[2][3] * s - mtx[2][2];
EMU64_LOGF("%8.3f * %8.3f * %8.3f - %8.3f = %8.3f\n", mtx[0][0], x, s, mtx[0][2], x0);
EMU64_LOGF("%8.3f * %8.3f * %8.3f - %8.3f = %8.3f\n", mtx[1][1], y, s, mtx[1][2], y0);
EMU64_LOGF("%8.3f * %8.3f - %8.3f = %8.3f\n", mtx[2][3], s, mtx[2][2], z0);
} else {
float x0 = mtx[0][0] * x + mtx[0][3];
float y0 = mtx[1][1] * y + mtx[1][3];
float z0 = mtx[2][2] * z + mtx[2][3];
EMU64_LOGF("%8.3f * %8.3f + %8.3f = %8.3f\n", mtx[0][0], x, mtx[0][3], x0);
EMU64_LOGF("%8.3f * %8.3f + %8.3f = %8.3f\n", mtx[1][1], x, mtx[1][3], y0);
EMU64_LOGF("%8.3f * %8.3f + %8.3f = %8.3f\n", mtx[2][2], x, mtx[2][3], z0);
}
}
-105
View File
@@ -1,105 +0,0 @@
#include "emu64.hpp"
const char* emu64::combine_name(u32 param, u32 type) {
switch (param) {
case 0:
return "COMBINED";
case 1:
return "TEXEL0";
case 2:
return "TEXEL1";
case 3:
return "PRIMITIVE";
case 4:
return "SHADE";
case 5:
return "ENVIRONMENT";
case 6:
if (type == COMBINER_PARAM_B) {
return "CENTER";
} else if (type == COMBINER_PARAM_C) {
return "SCALE";
} else {
return "1";
}
case 7:
if (type == COMBINER_PARAM_A) {
return "NOISE";
} else if (type == COMBINER_PARAM_B) {
return "K4";
} else if (type == COMBINER_PARAM_C) {
return "COMBINED_ALPHA";
} else {
return "0";
}
}
if (type != COMBINER_PARAM_C) {
return "0";
}
switch (param) {
case 8:
return "TEXEL0_ALPHA";
case 9:
return "TEXEL1_ALPHA";
case 10:
return "PRIMITIVE_ALPHA";
case 11:
return "SHADE_ALPHA";
case 12:
return "ENV_ALPHA";
case 13:
return "LOD_FRACTION";
case 14:
return "PRIM_LOD_FRAC";
case 15:
return "K5";
default:
return "0";
}
}
const char* emu64::combine_alpha(int param, int type) {
switch (param) {
case 0:
return type == COMBINER_PARAM_C ? "LOD_FRACTION" : "COMBINED";
case 1:
return "TEXEL0";
case 2:
return "TEXEL1";
case 3:
return "PRIMITIVE";
case 4:
return "SHADE";
case 5:
return "ENVIRONMENT";
case 6:
return type == COMBINER_PARAM_C ? "PRIM_LOD_FRAC" : "1";
case 7:
return "0";
}
/* There should be a default case here, but they forgot it. */
/* It returns a pointer to the emu64 class instead. */
#ifdef EMU64_FIX_COMBINE_NAME_RETURN_VALUES
return "0";
#endif
}
void emu64::print_combine(u64 combine) {
Gsetcombine_new* setcombine = (Gsetcombine_new*)&combine;
this->Printf0(
"gsDPSetCombineLERP(%s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s),",
this->combine_name(setcombine->a0, COMBINER_PARAM_A), this->combine_name(setcombine->b0, COMBINER_PARAM_B),
this->combine_name(setcombine->c0, COMBINER_PARAM_C), this->combine_name(setcombine->d0, COMBINER_PARAM_D),
this->combine_alpha(setcombine->Aa0, COMBINER_PARAM_A), this->combine_alpha(setcombine->Ab0, COMBINER_PARAM_B),
this->combine_alpha(setcombine->Ac0, COMBINER_PARAM_C), this->combine_alpha(setcombine->Ad0, COMBINER_PARAM_D),
this->combine_name(setcombine->a1, COMBINER_PARAM_A), this->combine_name(setcombine->b1, COMBINER_PARAM_B),
this->combine_name(setcombine->c1, COMBINER_PARAM_C), this->combine_name(setcombine->d1, COMBINER_PARAM_D),
this->combine_alpha(setcombine->Aa1, COMBINER_PARAM_A), this->combine_alpha(setcombine->Ab1, COMBINER_PARAM_B),
this->combine_alpha(setcombine->Ac1, COMBINER_PARAM_C), this->combine_alpha(setcombine->Ad1, COMBINER_PARAM_D));
}
+181
View File
@@ -0,0 +1,181 @@
#include "libforest/emu64/emu64.hpp"
#include "boot.h"
#include "terminal.h"
#include "MSL_C/w_math.h"
u32 emu64::seg2k0(u32 segadr) {
u32 k0;
if ((segadr >> 28) == 0) {
if (segadr < 0x03000000) {
this->Printf0(VT_COL(RED, WHITE) "segadr=%08x" VT_RST "\n", segadr);
this->panic("segadr is over 0x03000000.", __FILE__, 20);
k0 = segadr + 0x80000000;
} else {
k0 = (u32)this->segments[(segadr >> 24) & 0xF] + (segadr & 0xFFFFFF);
}
this->resolved_addresses++;
} else {
k0 = segadr;
}
if ((k0 >> 31) == 0 || k0 < 0x80000000 || k0 >= 0x83000000) {
this->Printf0("異常なアドレスです。%08x -> %08x\n", segadr, k0);
this->panic("異常なアドレスです。", __FILE__, 77);
this->abnormal_addresses++;
}
return k0;
}
/* @unused void guMtxXFMWF(MtxP, float, float, float, float, float, float*, float*, float*, float*) */
/* @unused void guMtxXFM1F(MtxP, float, float, float, float, float*, float*, float*) */
void guMtxXFM1F_dol(MtxP mtx, float x, float y, float z, float* ox, float* oy, float* oz) {
*ox = mtx[0][0] * x + mtx[0][1] * y + mtx[0][2] * z + mtx[0][3];
*oy = mtx[1][0] * x + mtx[1][1] * y + mtx[1][2] * z + mtx[1][3];
*oz = mtx[2][0] * x + mtx[2][1] * y + mtx[2][2] * z + mtx[2][3];
}
void guMtxXFM1F_dol7(MtxP mtx, float x, float y, float z, float* ox, float* oy, float* oz) {
GC_Mtx inv;
PSMTXInverse(mtx, inv);
*ox = inv[0][0] * x + inv[0][1] * y + inv[0][2] * z + inv[0][3];
*oy = inv[1][0] * x + inv[1][1] * y + inv[1][2] * z + inv[1][3];
*oz = inv[2][0] * x + inv[2][1] * y + inv[2][2] * z + inv[2][3];
}
void guMtxXFM1F_dol2(MtxP mtx, GXProjectionType type, float x, float y, float z, float* ox, float* oy, float* oz) {
if (type == GX_PERSPECTIVE) {
f32 s = -1.0f / z;
*ox = mtx[0][0] * x * s - mtx[0][2];
*oy = mtx[1][1] * y * s - mtx[1][2];
*oz = mtx[2][3] * s - mtx[2][2];
} else {
*ox = mtx[0][0] * x + mtx[0][3];
*oy = mtx[1][1] * y + mtx[1][3];
*oz = mtx[2][2] * z + mtx[2][3];
}
}
void guMtxXFM1F_dol2w(MtxP mtx, GXProjectionType type, float x, float y, float z, float* ox, float* oy, float* oz,
float* ow) {
if (type == GX_PERSPECTIVE) {
*ox = mtx[0][0] * x + mtx[0][2] * z;
*oy = mtx[1][1] * y + mtx[1][2] * z;
*oz = mtx[2][3] + mtx[2][2] * z;
*ow = -z;
} else {
*ox = mtx[0][0] * x + mtx[0][3];
*oy = mtx[1][1] * y + mtx[1][3];
*oz = mtx[2][2] * z + mtx[2][3];
*ow = 1.0f;
}
}
float guMtxXFM1F_dol3(MtxP mtx, GXProjectionType type, float z) {
if (type == GX_PERSPECTIVE) {
return -mtx[2][3] / (z + mtx[2][2]);
} else {
return (z - mtx[2][3]) / mtx[2][2];
}
}
void guMtxXFM1F_dol6w(MtxP mtx, GXProjectionType type, float x, float y, float z, float w, float* ox, float* oy,
float* oz, float* ow) {
if (type == GX_PERSPECTIVE) {
float xScale = mtx[0][0];
float yScale = mtx[1][1];
float zScale = mtx[2][2];
float xRatioScaling = mtx[0][2];
float yRatioScaling = mtx[1][2];
float zSkew = mtx[2][3];
*ox = (yScale * zSkew * (x + xRatioScaling * w)) / (xScale * (yScale * zSkew));
*oy = (xScale * zSkew * (y + yRatioScaling * w)) / (xScale * (yScale * zSkew));
*oz = -w;
*ow = (xScale * yScale * (z + zScale * w)) / (xScale * (yScale * zSkew));
} else {
float xScale = mtx[0][0];
float xSkew = mtx[0][3];
float yScale = mtx[1][1];
float ySkew = mtx[1][3];
float zScale = mtx[2][2];
float zSkew = mtx[2][3];
float n = 1.0f / (xScale * yScale * zScale);
*ox = n * (yScale * zScale * (x - xSkew));
*oy = n * (zScale * xScale * (y - ySkew));
*oz = n * (xScale * yScale * (z - zSkew));
*ow = 1.0f;
}
}
void guMtxXFM1F_dol6w1(MtxP mtx, GXProjectionType type, float x, float y, float z, float w, float* ox, float* oy,
float* oz) {
if (type == GX_PERSPECTIVE) {
float xScale = mtx[0][0];
float yScale = mtx[1][1];
float zScale = mtx[2][2];
float xRatioScaling = mtx[0][2];
float yRatioScaling = mtx[1][2];
float zSkew = mtx[2][3];
float temp_f7 = 1.0f / (xScale * yScale * (z + (zScale * w)));
*ox = temp_f7 * (yScale * zSkew * (x + (xRatioScaling * w)));
*oy = temp_f7 * (xScale * zSkew * (y + (yRatioScaling * w)));
*oz = temp_f7 * (yScale * zSkew * xScale * -w);
} else {
float translateX = mtx[0][3];
float translateY = mtx[1][3];
float translateZ = mtx[2][3];
float scaleX = mtx[0][0];
float scaleY = mtx[1][1];
float scaleZ = mtx[2][2];
*ox = (x - translateX) / scaleX;
*oy = (y - translateY) / scaleY;
*oz = (z - translateZ) / scaleZ;
}
}
/* @unused void guMtxXFMWL(N64Mtx*, float, float, float, float, float*, float*, float*, float*) */
void guMtxNormalize(GC_Mtx mtx) {
for (int i = 0; i < 3; i++) {
float magnitude = sqrtf(mtx[i][0] * mtx[i][0] + mtx[i][1] * mtx[i][1] + mtx[i][2] * mtx[i][2]);
mtx[i][0] *= 1.0f / magnitude;
mtx[i][1] *= 1.0f / magnitude;
mtx[i][2] *= 1.0f / magnitude;
}
}
/* TODO: Mtx -> N64Mtx, GC_Mtx -> Mtx */
void N64Mtx_to_DOLMtx(const Mtx* n64, MtxP gc) {
s16* fixed = ((s16*)n64) + 0;
u16* frac = ((u16*)n64) + 16;
int i;
for (i = 0; i < 4; i++) {
gc[0][i] = fastcast_float(&fixed[0]) + fastcast_float(&frac[0]) * (1.0f / 65536.0f);
gc[1][i] = fastcast_float(&fixed[1]) + fastcast_float(&frac[1]) * (1.0f / 65536.0f);
gc[2][i] = fastcast_float(&fixed[2]) + fastcast_float(&frac[2]) * (1.0f / 65536.0f);
fixed += 4;
frac += 4;
}
}
/* @unused my_guMtxL2F(MtxP, const N64Mtx*) */