Skip to content

Commit

Permalink
Merge pull request #1479 from nicolasnoble/gte-fixed-point
Browse files Browse the repository at this point in the history
Adding toggle to see GTE registers in fixed point format.
  • Loading branch information
nicolasnoble authored Dec 9, 2023
2 parents bd3b657 + 4f7ab52 commit 67179fa
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 37 deletions.
228 changes: 191 additions & 37 deletions src/gui/widgets/registers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include "gui/widgets/registers.h"

#include <cmath>
#include <numbers>

#include "core/disr3000a.h"
#include "core/r3000a.h"
#include "core/system.h"
Expand Down Expand Up @@ -98,77 +101,228 @@ void PCSX::Widgets::Registers::draw(PCSX::GUI* gui, PCSX::psxRegisters* register
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("CP2D")) {
ImGui::Checkbox(_("Show fixed point"), &m_showFixed);
auto v0 = registers->CP2D.n.v0;
ImGui::Text("v0 : {%i, %i, %i}", v0.x, v0.y, v0.z);
if (m_showFixed) {
ImGui::Text("v0 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v0.x), fixedToFloat(v0.y),
fixedToFloat(v0.z));
} else {
ImGui::Text("v0 : {%i, %i, %i}", v0.x, v0.y, v0.z);
}
auto v1 = registers->CP2D.n.v1;
ImGui::Text("v1 : {%i, %i, %i}", v1.x, v1.y, v1.z);
if (m_showFixed) {
ImGui::Text("v1 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v1.x), fixedToFloat(v1.y),
fixedToFloat(v1.z));
} else {
ImGui::Text("v1 : {%i, %i, %i}", v1.x, v1.y, v1.z);
}
auto v2 = registers->CP2D.n.v2;
ImGui::Text("v2 : {%i, %i, %i}", v2.x, v2.y, v2.z);
if (m_showFixed) {
ImGui::Text("v2 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v2.x), fixedToFloat(v2.y),
fixedToFloat(v2.z));
} else {
ImGui::Text("v2 : {%i, %i, %i}", v2.x, v2.y, v2.z);
}
auto rgb = registers->CP2D.n.rgb;
ImGui::Text("rgb : {%i, %i, %i, %i}", rgb.r, rgb.g, rgb.b, rgb.c);
ImGui::Text("otz : %i", registers->CP2D.n.otz);
ImGui::Text("ir0 : %i", registers->CP2D.n.ir0);
ImGui::Text("ir1 : %i", registers->CP2D.n.ir1);
ImGui::Text("ir2 : %i", registers->CP2D.n.ir2);
ImGui::Text("ir3 : %i", registers->CP2D.n.ir3);
if (m_showFixed) {
ImGui::Text("otz : % 3.5f", fixedToFloat(registers->CP2D.n.otz));
} else {
ImGui::Text("otz : %i", registers->CP2D.n.otz);
}
if (m_showFixed) {
ImGui::Text("ir0 : % 3.5f", fixedToFloat(registers->CP2D.n.ir0));
} else {
ImGui::Text("ir0 : %i", registers->CP2D.n.ir0);
}
if (m_showFixed) {
ImGui::Text("ir1 : % 3.5f", fixedToFloat(registers->CP2D.n.ir1));
} else {
ImGui::Text("ir1 : %i", registers->CP2D.n.ir1);
}
if (m_showFixed) {
ImGui::Text("ir2 : % 3.5f", fixedToFloat(registers->CP2D.n.ir2));
} else {
ImGui::Text("ir2 : %i", registers->CP2D.n.ir2);
}
if (m_showFixed) {
ImGui::Text("ir3 : % 3.5f", fixedToFloat(registers->CP2D.n.ir3));
} else {
ImGui::Text("ir3 : %i", registers->CP2D.n.ir3);
}
auto sxy0 = registers->CP2D.n.sxy0;
ImGui::Text("sxy0: {%i, %i}", sxy0.x, sxy0.y);
if (m_showFixed) {
ImGui::Text("sxy0: {% 3.5f, % 3.5f}", fixedToFloat(sxy0.x), fixedToFloat(sxy0.y));
} else {
ImGui::Text("sxy0: {%i, %i}", sxy0.x, sxy0.y);
}
auto sxy1 = registers->CP2D.n.sxy1;
ImGui::Text("sxy1: {%i, %i}", sxy1.x, sxy1.y);
if (m_showFixed) {
ImGui::Text("sxy1: {% 3.5f, % 3.5f}", fixedToFloat(sxy1.x), fixedToFloat(sxy1.y));
} else {
ImGui::Text("sxy1: {%i, %i}", sxy1.x, sxy1.y);
}
auto sxy2 = registers->CP2D.n.sxy2;
ImGui::Text("sxy2: {%i, %i}", sxy2.x, sxy2.y);
if (m_showFixed) {
ImGui::Text("sxy2: {% 3.5f, % 3.5f}", fixedToFloat(sxy2.x), fixedToFloat(sxy2.y));
} else {
ImGui::Text("sxy2: {%i, %i}", sxy2.x, sxy2.y);
}
auto sxyp = registers->CP2D.n.sxyp;
ImGui::Text("sxyp: {%i, %i}", sxyp.x, sxyp.y);
if (m_showFixed) {
ImGui::Text("sxyp: {% 3.5f, % 3.5f}", fixedToFloat(sxyp.x), fixedToFloat(sxyp.y));
} else {
ImGui::Text("sxyp: {%i, %i}", sxyp.x, sxyp.y);
}
auto sz0 = registers->CP2D.n.sz0;
ImGui::Text("sz0 : {%i, %i}", sz0.z, sz0.unused);
if (m_showFixed) {
ImGui::Text("sz0 : % 3.5f", fixedToFloat(sz0.z));
} else {
ImGui::Text("sz0 : %i", sz0.z);
}
auto sz1 = registers->CP2D.n.sz1;
ImGui::Text("sz1 : {%i, %i}", sz1.z, sz1.unused);
if (m_showFixed) {
ImGui::Text("sz1 : % 3.5f", fixedToFloat(sz1.z));
} else {
ImGui::Text("sz1 : %i", sz1.z);
}
auto sz2 = registers->CP2D.n.sz2;
ImGui::Text("sz2 : {%i, %i}", sz2.z, sz2.unused);
if (m_showFixed) {
ImGui::Text("sz2 : % 3.5f", fixedToFloat(sz2.z));
} else {
ImGui::Text("sz2 : %i", sz2.z);
}
auto sz3 = registers->CP2D.n.sz3;
ImGui::Text("sz3 : {%i, %i}", sz3.z, sz3.unused);
if (m_showFixed) {
ImGui::Text("sz3 : % 3.5f", fixedToFloat(sz3.z));
} else {
ImGui::Text("sz3 : %i", sz3.z);
}
auto rgb0 = registers->CP2D.n.rgb0;
ImGui::Text("rgb0: {%i, %i, %i, %i}", rgb0.r, rgb0.g, rgb0.b, rgb0.c);
auto rgb1 = registers->CP2D.n.rgb0;
ImGui::Text("rgb1: {%i, %i, %i, %i}", rgb1.r, rgb1.g, rgb1.b, rgb1.c);
auto rgb2 = registers->CP2D.n.rgb0;
ImGui::Text("rgb2: {%i, %i, %i, %i}", rgb2.r, rgb2.g, rgb2.b, rgb2.c);
ImGui::Text("mac0: %i", registers->CP2D.n.mac0);
ImGui::Text("mac1: %i", registers->CP2D.n.mac1);
ImGui::Text("mac2: %i", registers->CP2D.n.mac2);
ImGui::Text("mac3: %i", registers->CP2D.n.mac3);
if (m_showFixed) {
ImGui::Text("mac0: % 3.5f", fixedToFloat(registers->CP2D.n.mac0));
} else {
ImGui::Text("mac0: %i", registers->CP2D.n.mac0);
}
if (m_showFixed) {
ImGui::Text("mac1: % 3.5f", fixedToFloat(registers->CP2D.n.mac1));
} else {
ImGui::Text("mac1: %i", registers->CP2D.n.mac1);
}
if (m_showFixed) {
ImGui::Text("mac2: % 3.5f", fixedToFloat(registers->CP2D.n.mac2));
} else {
ImGui::Text("mac2: %i", registers->CP2D.n.mac2);
}
if (m_showFixed) {
ImGui::Text("mac3: % 3.5f", fixedToFloat(registers->CP2D.n.mac3));
} else {
ImGui::Text("mac3: %i", registers->CP2D.n.mac3);
}
ImGui::Text("irgb: %u", registers->CP2D.n.irgb);
ImGui::Text("orgb: %u", registers->CP2D.n.orgb);
ImGui::Text("lzcs: %i", registers->CP2D.n.lzcs);
ImGui::Text("lzcr: %i", registers->CP2D.n.lzcr);
if (m_showFixed) {
ImGui::Text("lzcs: % 3.5f", fixedToFloat(registers->CP2D.n.lzcs));
} else {
ImGui::Text("lzcs: %i", registers->CP2D.n.lzcs);
}
if (m_showFixed) {
ImGui::Text("lzcr: % 3.5f", fixedToFloat(registers->CP2D.n.lzcr));
} else {
ImGui::Text("lzcr: %i", registers->CP2D.n.lzcr);
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("CP2C")) {
auto displayMatrix = [](const SMatrix3D& matrix, const char* name) {
ImGui::Checkbox(_("Show fixed point"), &m_showFixed);
auto showFixed = m_showFixed;
auto displayMatrixPlain = [](SMatrix3D matrix, const char* name) {
ImGui::Text(" [%5i, %5i, %5i]", matrix.m11, matrix.m12, matrix.m13);
ImGui::Text("%s: [%5i, %5i, %5i]", name, matrix.m21, matrix.m22, matrix.m23);
ImGui::Text(" [%5i, %5i, %5i]", matrix.m31, matrix.m32, matrix.m33);
};
auto displayMatrixFixed = [](SMatrix3D matrix, const char* name) {
ImGui::Text(" [% 3.5f, % 3.5f, % 3.5f]", fixedToFloat(matrix.m11), fixedToFloat(matrix.m12),
fixedToFloat(matrix.m13));
ImGui::Text("%s: [% 3.5f, % 3.5f, % 3.5f]", name, fixedToFloat(matrix.m21), fixedToFloat(matrix.m22),
fixedToFloat(matrix.m23));
ImGui::Text(" [% 3.5f, % 3.5f, % 3.5f]", fixedToFloat(matrix.m31), fixedToFloat(matrix.m32),
fixedToFloat(matrix.m33));
};
auto displayMatrix = showFixed ? displayMatrixFixed : displayMatrixPlain;
displayMatrix(registers->CP2C.n.rMatrix, "R");
if (showFixed) {
float m11 = fixedToFloat(registers->CP2C.n.rMatrix.m11);
float m12 = fixedToFloat(registers->CP2C.n.rMatrix.m12);
float m13 = fixedToFloat(registers->CP2C.n.rMatrix.m13);
float m21 = fixedToFloat(registers->CP2C.n.rMatrix.m21);
float m22 = fixedToFloat(registers->CP2C.n.rMatrix.m22);
float m23 = fixedToFloat(registers->CP2C.n.rMatrix.m23);
float m31 = fixedToFloat(registers->CP2C.n.rMatrix.m31);
float m32 = fixedToFloat(registers->CP2C.n.rMatrix.m32);
float m33 = fixedToFloat(registers->CP2C.n.rMatrix.m33);
float c11 = m22 * m33 - m23 * m32;
float c12 = m23 * m31 - m21 * m33;
float c13 = m21 * m32 - m22 * m31;
auto trace = m11 + m22 + m33;
auto determinant = m11 * c11 + m12 * c12 + m13 * c13;
ImGui::Text(" :: deter: % 3.5f", determinant);
ImGui::Text(" :: trace: % 3.5f", trace);
auto angle = std::acos((trace - 1.0) / 2.0);
ImGui::Text(" :: angle: % 3.5f x Pi", angle / std::numbers::pi);
float f = 1.0f / (2.0f * std::sin(angle));
float x = (m32 - m23) * f;
float y = (m13 - m31) * f;
float z = (m21 - m12) * f;
float magnitude = std::sqrt(x * x + y * y + z * z);
x /= magnitude;
y /= magnitude;
z /= magnitude;
ImGui::Text(" :: axis : {%3.5f, %3.5f, %3.5f}", x, y, z);
}
ImGui::Text("trX : %i", registers->CP2C.n.trX);
ImGui::Text("trY : %i", registers->CP2C.n.trY);
ImGui::Text("trZ : %i", registers->CP2C.n.trZ);
displayMatrix(registers->CP2C.n.lMatrix, "L");
ImGui::Text("rbk : %i", registers->CP2C.n.rbk);
ImGui::Text("gbk : %i", registers->CP2C.n.gbk);
ImGui::Text("bbk : %i", registers->CP2C.n.bbk);
if (showFixed) {
ImGui::Text("rbk : % 3.5f", fixedToFloat(registers->CP2C.n.rbk));
ImGui::Text("gbk : % 3.5f", fixedToFloat(registers->CP2C.n.gbk));
ImGui::Text("bbk : % 3.5f", fixedToFloat(registers->CP2C.n.bbk));
} else {
ImGui::Text("rbk : %i", registers->CP2C.n.rbk);
ImGui::Text("gbk : %i", registers->CP2C.n.gbk);
ImGui::Text("bbk : %i", registers->CP2C.n.bbk);
}
displayMatrix(registers->CP2C.n.cMatrix, "C");
ImGui::Text("rfc : %i", registers->CP2C.n.rfc);
ImGui::Text("gfc : %i", registers->CP2C.n.gfc);
ImGui::Text("bfc : %i", registers->CP2C.n.bfc);
ImGui::Text("ofx : %i", registers->CP2C.n.ofx);
ImGui::Text("ofy : %i", registers->CP2C.n.ofy);
ImGui::Text("h : %i", registers->CP2C.n.h);
ImGui::Text("dqa : %i", registers->CP2C.n.dqa);
ImGui::Text("dqb : %i", registers->CP2C.n.dqb);
ImGui::Text("zsf3: %i", registers->CP2C.n.zsf3);
ImGui::Text("zsf4: %i", registers->CP2C.n.zsf4);
ImGui::Text("flag: %i", registers->CP2C.n.flag);
if (showFixed) {
ImGui::Text("rfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.rfc));
ImGui::Text("gfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.gfc));
ImGui::Text("bfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.bfc));
ImGui::Text("ofx : % 3.5f", fixedToFloat<15>(registers->CP2C.n.ofx));
ImGui::Text("ofy : % 3.5f", fixedToFloat<15>(registers->CP2C.n.ofy));
ImGui::Text("h : % i", registers->CP2C.n.h);
ImGui::Text("dqa : % 3.5f", fixedToFloat<8>(registers->CP2C.n.dqa));
ImGui::Text("dqb : % 3.5f", fixedToFloat<24>(registers->CP2C.n.dqb));
ImGui::Text("zsf3: % 3.5f", fixedToFloat(registers->CP2C.n.zsf3));
ImGui::Text("zsf4: % 3.5f", fixedToFloat(registers->CP2C.n.zsf4));
} else {
ImGui::Text("rfc : %i", registers->CP2C.n.rfc);
ImGui::Text("gfc : %i", registers->CP2C.n.gfc);
ImGui::Text("bfc : %i", registers->CP2C.n.bfc);
ImGui::Text("ofx : %i", registers->CP2C.n.ofx);
ImGui::Text("ofy : %i", registers->CP2C.n.ofy);
ImGui::Text("h : %i", registers->CP2C.n.h);
ImGui::Text("dqa : %i", registers->CP2C.n.dqa);
ImGui::Text("dqb : %i", registers->CP2C.n.dqb);
ImGui::Text("zsf3: %i", registers->CP2C.n.zsf3);
ImGui::Text("zsf4: %i", registers->CP2C.n.zsf4);
}
ImGui::Text("flag: 0x%08x", registers->CP2C.n.flag);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem(_("Misc"))) {
Expand Down
5 changes: 5 additions & 0 deletions src/gui/widgets/registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ class Registers {

private:
void makeEditableRegister(const char* name, uint32_t reg);
template <size_t Fract = 12>
static float fixedToFloat(int32_t value) {
return static_cast<float>(value) / static_cast<float>(1 << Fract);
}

unsigned m_selected = 0;
bool m_showFixed = false;
char m_registerEditor[20];
std::string m_editorToOpen;
};
Expand Down

0 comments on commit 67179fa

Please sign in to comment.