Skip to content

Commit 67179fa

Browse files
authored
Merge pull request #1479 from nicolasnoble/gte-fixed-point
Adding toggle to see GTE registers in fixed point format.
2 parents bd3b657 + 4f7ab52 commit 67179fa

File tree

2 files changed

+196
-37
lines changed

2 files changed

+196
-37
lines changed

src/gui/widgets/registers.cc

Lines changed: 191 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include "gui/widgets/registers.h"
2121

22+
#include <cmath>
23+
#include <numbers>
24+
2225
#include "core/disr3000a.h"
2326
#include "core/r3000a.h"
2427
#include "core/system.h"
@@ -98,77 +101,228 @@ void PCSX::Widgets::Registers::draw(PCSX::GUI* gui, PCSX::psxRegisters* register
98101
ImGui::EndTabItem();
99102
}
100103
if (ImGui::BeginTabItem("CP2D")) {
104+
ImGui::Checkbox(_("Show fixed point"), &m_showFixed);
101105
auto v0 = registers->CP2D.n.v0;
102-
ImGui::Text("v0 : {%i, %i, %i}", v0.x, v0.y, v0.z);
106+
if (m_showFixed) {
107+
ImGui::Text("v0 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v0.x), fixedToFloat(v0.y),
108+
fixedToFloat(v0.z));
109+
} else {
110+
ImGui::Text("v0 : {%i, %i, %i}", v0.x, v0.y, v0.z);
111+
}
103112
auto v1 = registers->CP2D.n.v1;
104-
ImGui::Text("v1 : {%i, %i, %i}", v1.x, v1.y, v1.z);
113+
if (m_showFixed) {
114+
ImGui::Text("v1 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v1.x), fixedToFloat(v1.y),
115+
fixedToFloat(v1.z));
116+
} else {
117+
ImGui::Text("v1 : {%i, %i, %i}", v1.x, v1.y, v1.z);
118+
}
105119
auto v2 = registers->CP2D.n.v2;
106-
ImGui::Text("v2 : {%i, %i, %i}", v2.x, v2.y, v2.z);
120+
if (m_showFixed) {
121+
ImGui::Text("v2 : {% 3.5f, % 3.5f, % 3.5f}", fixedToFloat(v2.x), fixedToFloat(v2.y),
122+
fixedToFloat(v2.z));
123+
} else {
124+
ImGui::Text("v2 : {%i, %i, %i}", v2.x, v2.y, v2.z);
125+
}
107126
auto rgb = registers->CP2D.n.rgb;
108127
ImGui::Text("rgb : {%i, %i, %i, %i}", rgb.r, rgb.g, rgb.b, rgb.c);
109-
ImGui::Text("otz : %i", registers->CP2D.n.otz);
110-
ImGui::Text("ir0 : %i", registers->CP2D.n.ir0);
111-
ImGui::Text("ir1 : %i", registers->CP2D.n.ir1);
112-
ImGui::Text("ir2 : %i", registers->CP2D.n.ir2);
113-
ImGui::Text("ir3 : %i", registers->CP2D.n.ir3);
128+
if (m_showFixed) {
129+
ImGui::Text("otz : % 3.5f", fixedToFloat(registers->CP2D.n.otz));
130+
} else {
131+
ImGui::Text("otz : %i", registers->CP2D.n.otz);
132+
}
133+
if (m_showFixed) {
134+
ImGui::Text("ir0 : % 3.5f", fixedToFloat(registers->CP2D.n.ir0));
135+
} else {
136+
ImGui::Text("ir0 : %i", registers->CP2D.n.ir0);
137+
}
138+
if (m_showFixed) {
139+
ImGui::Text("ir1 : % 3.5f", fixedToFloat(registers->CP2D.n.ir1));
140+
} else {
141+
ImGui::Text("ir1 : %i", registers->CP2D.n.ir1);
142+
}
143+
if (m_showFixed) {
144+
ImGui::Text("ir2 : % 3.5f", fixedToFloat(registers->CP2D.n.ir2));
145+
} else {
146+
ImGui::Text("ir2 : %i", registers->CP2D.n.ir2);
147+
}
148+
if (m_showFixed) {
149+
ImGui::Text("ir3 : % 3.5f", fixedToFloat(registers->CP2D.n.ir3));
150+
} else {
151+
ImGui::Text("ir3 : %i", registers->CP2D.n.ir3);
152+
}
114153
auto sxy0 = registers->CP2D.n.sxy0;
115-
ImGui::Text("sxy0: {%i, %i}", sxy0.x, sxy0.y);
154+
if (m_showFixed) {
155+
ImGui::Text("sxy0: {% 3.5f, % 3.5f}", fixedToFloat(sxy0.x), fixedToFloat(sxy0.y));
156+
} else {
157+
ImGui::Text("sxy0: {%i, %i}", sxy0.x, sxy0.y);
158+
}
116159
auto sxy1 = registers->CP2D.n.sxy1;
117-
ImGui::Text("sxy1: {%i, %i}", sxy1.x, sxy1.y);
160+
if (m_showFixed) {
161+
ImGui::Text("sxy1: {% 3.5f, % 3.5f}", fixedToFloat(sxy1.x), fixedToFloat(sxy1.y));
162+
} else {
163+
ImGui::Text("sxy1: {%i, %i}", sxy1.x, sxy1.y);
164+
}
118165
auto sxy2 = registers->CP2D.n.sxy2;
119-
ImGui::Text("sxy2: {%i, %i}", sxy2.x, sxy2.y);
166+
if (m_showFixed) {
167+
ImGui::Text("sxy2: {% 3.5f, % 3.5f}", fixedToFloat(sxy2.x), fixedToFloat(sxy2.y));
168+
} else {
169+
ImGui::Text("sxy2: {%i, %i}", sxy2.x, sxy2.y);
170+
}
120171
auto sxyp = registers->CP2D.n.sxyp;
121-
ImGui::Text("sxyp: {%i, %i}", sxyp.x, sxyp.y);
172+
if (m_showFixed) {
173+
ImGui::Text("sxyp: {% 3.5f, % 3.5f}", fixedToFloat(sxyp.x), fixedToFloat(sxyp.y));
174+
} else {
175+
ImGui::Text("sxyp: {%i, %i}", sxyp.x, sxyp.y);
176+
}
122177
auto sz0 = registers->CP2D.n.sz0;
123-
ImGui::Text("sz0 : {%i, %i}", sz0.z, sz0.unused);
178+
if (m_showFixed) {
179+
ImGui::Text("sz0 : % 3.5f", fixedToFloat(sz0.z));
180+
} else {
181+
ImGui::Text("sz0 : %i", sz0.z);
182+
}
124183
auto sz1 = registers->CP2D.n.sz1;
125-
ImGui::Text("sz1 : {%i, %i}", sz1.z, sz1.unused);
184+
if (m_showFixed) {
185+
ImGui::Text("sz1 : % 3.5f", fixedToFloat(sz1.z));
186+
} else {
187+
ImGui::Text("sz1 : %i", sz1.z);
188+
}
126189
auto sz2 = registers->CP2D.n.sz2;
127-
ImGui::Text("sz2 : {%i, %i}", sz2.z, sz2.unused);
190+
if (m_showFixed) {
191+
ImGui::Text("sz2 : % 3.5f", fixedToFloat(sz2.z));
192+
} else {
193+
ImGui::Text("sz2 : %i", sz2.z);
194+
}
128195
auto sz3 = registers->CP2D.n.sz3;
129-
ImGui::Text("sz3 : {%i, %i}", sz3.z, sz3.unused);
196+
if (m_showFixed) {
197+
ImGui::Text("sz3 : % 3.5f", fixedToFloat(sz3.z));
198+
} else {
199+
ImGui::Text("sz3 : %i", sz3.z);
200+
}
130201
auto rgb0 = registers->CP2D.n.rgb0;
131202
ImGui::Text("rgb0: {%i, %i, %i, %i}", rgb0.r, rgb0.g, rgb0.b, rgb0.c);
132203
auto rgb1 = registers->CP2D.n.rgb0;
133204
ImGui::Text("rgb1: {%i, %i, %i, %i}", rgb1.r, rgb1.g, rgb1.b, rgb1.c);
134205
auto rgb2 = registers->CP2D.n.rgb0;
135206
ImGui::Text("rgb2: {%i, %i, %i, %i}", rgb2.r, rgb2.g, rgb2.b, rgb2.c);
136-
ImGui::Text("mac0: %i", registers->CP2D.n.mac0);
137-
ImGui::Text("mac1: %i", registers->CP2D.n.mac1);
138-
ImGui::Text("mac2: %i", registers->CP2D.n.mac2);
139-
ImGui::Text("mac3: %i", registers->CP2D.n.mac3);
207+
if (m_showFixed) {
208+
ImGui::Text("mac0: % 3.5f", fixedToFloat(registers->CP2D.n.mac0));
209+
} else {
210+
ImGui::Text("mac0: %i", registers->CP2D.n.mac0);
211+
}
212+
if (m_showFixed) {
213+
ImGui::Text("mac1: % 3.5f", fixedToFloat(registers->CP2D.n.mac1));
214+
} else {
215+
ImGui::Text("mac1: %i", registers->CP2D.n.mac1);
216+
}
217+
if (m_showFixed) {
218+
ImGui::Text("mac2: % 3.5f", fixedToFloat(registers->CP2D.n.mac2));
219+
} else {
220+
ImGui::Text("mac2: %i", registers->CP2D.n.mac2);
221+
}
222+
if (m_showFixed) {
223+
ImGui::Text("mac3: % 3.5f", fixedToFloat(registers->CP2D.n.mac3));
224+
} else {
225+
ImGui::Text("mac3: %i", registers->CP2D.n.mac3);
226+
}
140227
ImGui::Text("irgb: %u", registers->CP2D.n.irgb);
141228
ImGui::Text("orgb: %u", registers->CP2D.n.orgb);
142-
ImGui::Text("lzcs: %i", registers->CP2D.n.lzcs);
143-
ImGui::Text("lzcr: %i", registers->CP2D.n.lzcr);
229+
if (m_showFixed) {
230+
ImGui::Text("lzcs: % 3.5f", fixedToFloat(registers->CP2D.n.lzcs));
231+
} else {
232+
ImGui::Text("lzcs: %i", registers->CP2D.n.lzcs);
233+
}
234+
if (m_showFixed) {
235+
ImGui::Text("lzcr: % 3.5f", fixedToFloat(registers->CP2D.n.lzcr));
236+
} else {
237+
ImGui::Text("lzcr: %i", registers->CP2D.n.lzcr);
238+
}
144239
ImGui::EndTabItem();
145240
}
146241
if (ImGui::BeginTabItem("CP2C")) {
147-
auto displayMatrix = [](const SMatrix3D& matrix, const char* name) {
242+
ImGui::Checkbox(_("Show fixed point"), &m_showFixed);
243+
auto showFixed = m_showFixed;
244+
auto displayMatrixPlain = [](SMatrix3D matrix, const char* name) {
148245
ImGui::Text(" [%5i, %5i, %5i]", matrix.m11, matrix.m12, matrix.m13);
149246
ImGui::Text("%s: [%5i, %5i, %5i]", name, matrix.m21, matrix.m22, matrix.m23);
150247
ImGui::Text(" [%5i, %5i, %5i]", matrix.m31, matrix.m32, matrix.m33);
151248
};
249+
auto displayMatrixFixed = [](SMatrix3D matrix, const char* name) {
250+
ImGui::Text(" [% 3.5f, % 3.5f, % 3.5f]", fixedToFloat(matrix.m11), fixedToFloat(matrix.m12),
251+
fixedToFloat(matrix.m13));
252+
ImGui::Text("%s: [% 3.5f, % 3.5f, % 3.5f]", name, fixedToFloat(matrix.m21), fixedToFloat(matrix.m22),
253+
fixedToFloat(matrix.m23));
254+
ImGui::Text(" [% 3.5f, % 3.5f, % 3.5f]", fixedToFloat(matrix.m31), fixedToFloat(matrix.m32),
255+
fixedToFloat(matrix.m33));
256+
};
257+
auto displayMatrix = showFixed ? displayMatrixFixed : displayMatrixPlain;
152258
displayMatrix(registers->CP2C.n.rMatrix, "R");
259+
if (showFixed) {
260+
float m11 = fixedToFloat(registers->CP2C.n.rMatrix.m11);
261+
float m12 = fixedToFloat(registers->CP2C.n.rMatrix.m12);
262+
float m13 = fixedToFloat(registers->CP2C.n.rMatrix.m13);
263+
float m21 = fixedToFloat(registers->CP2C.n.rMatrix.m21);
264+
float m22 = fixedToFloat(registers->CP2C.n.rMatrix.m22);
265+
float m23 = fixedToFloat(registers->CP2C.n.rMatrix.m23);
266+
float m31 = fixedToFloat(registers->CP2C.n.rMatrix.m31);
267+
float m32 = fixedToFloat(registers->CP2C.n.rMatrix.m32);
268+
float m33 = fixedToFloat(registers->CP2C.n.rMatrix.m33);
269+
float c11 = m22 * m33 - m23 * m32;
270+
float c12 = m23 * m31 - m21 * m33;
271+
float c13 = m21 * m32 - m22 * m31;
272+
auto trace = m11 + m22 + m33;
273+
auto determinant = m11 * c11 + m12 * c12 + m13 * c13;
274+
ImGui::Text(" :: deter: % 3.5f", determinant);
275+
ImGui::Text(" :: trace: % 3.5f", trace);
276+
auto angle = std::acos((trace - 1.0) / 2.0);
277+
ImGui::Text(" :: angle: % 3.5f x Pi", angle / std::numbers::pi);
278+
float f = 1.0f / (2.0f * std::sin(angle));
279+
float x = (m32 - m23) * f;
280+
float y = (m13 - m31) * f;
281+
float z = (m21 - m12) * f;
282+
float magnitude = std::sqrt(x * x + y * y + z * z);
283+
x /= magnitude;
284+
y /= magnitude;
285+
z /= magnitude;
286+
ImGui::Text(" :: axis : {%3.5f, %3.5f, %3.5f}", x, y, z);
287+
}
153288
ImGui::Text("trX : %i", registers->CP2C.n.trX);
154289
ImGui::Text("trY : %i", registers->CP2C.n.trY);
155290
ImGui::Text("trZ : %i", registers->CP2C.n.trZ);
156291
displayMatrix(registers->CP2C.n.lMatrix, "L");
157-
ImGui::Text("rbk : %i", registers->CP2C.n.rbk);
158-
ImGui::Text("gbk : %i", registers->CP2C.n.gbk);
159-
ImGui::Text("bbk : %i", registers->CP2C.n.bbk);
292+
if (showFixed) {
293+
ImGui::Text("rbk : % 3.5f", fixedToFloat(registers->CP2C.n.rbk));
294+
ImGui::Text("gbk : % 3.5f", fixedToFloat(registers->CP2C.n.gbk));
295+
ImGui::Text("bbk : % 3.5f", fixedToFloat(registers->CP2C.n.bbk));
296+
} else {
297+
ImGui::Text("rbk : %i", registers->CP2C.n.rbk);
298+
ImGui::Text("gbk : %i", registers->CP2C.n.gbk);
299+
ImGui::Text("bbk : %i", registers->CP2C.n.bbk);
300+
}
160301
displayMatrix(registers->CP2C.n.cMatrix, "C");
161-
ImGui::Text("rfc : %i", registers->CP2C.n.rfc);
162-
ImGui::Text("gfc : %i", registers->CP2C.n.gfc);
163-
ImGui::Text("bfc : %i", registers->CP2C.n.bfc);
164-
ImGui::Text("ofx : %i", registers->CP2C.n.ofx);
165-
ImGui::Text("ofy : %i", registers->CP2C.n.ofy);
166-
ImGui::Text("h : %i", registers->CP2C.n.h);
167-
ImGui::Text("dqa : %i", registers->CP2C.n.dqa);
168-
ImGui::Text("dqb : %i", registers->CP2C.n.dqb);
169-
ImGui::Text("zsf3: %i", registers->CP2C.n.zsf3);
170-
ImGui::Text("zsf4: %i", registers->CP2C.n.zsf4);
171-
ImGui::Text("flag: %i", registers->CP2C.n.flag);
302+
if (showFixed) {
303+
ImGui::Text("rfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.rfc));
304+
ImGui::Text("gfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.gfc));
305+
ImGui::Text("bfc : % 3.5f", fixedToFloat<4>(registers->CP2C.n.bfc));
306+
ImGui::Text("ofx : % 3.5f", fixedToFloat<15>(registers->CP2C.n.ofx));
307+
ImGui::Text("ofy : % 3.5f", fixedToFloat<15>(registers->CP2C.n.ofy));
308+
ImGui::Text("h : % i", registers->CP2C.n.h);
309+
ImGui::Text("dqa : % 3.5f", fixedToFloat<8>(registers->CP2C.n.dqa));
310+
ImGui::Text("dqb : % 3.5f", fixedToFloat<24>(registers->CP2C.n.dqb));
311+
ImGui::Text("zsf3: % 3.5f", fixedToFloat(registers->CP2C.n.zsf3));
312+
ImGui::Text("zsf4: % 3.5f", fixedToFloat(registers->CP2C.n.zsf4));
313+
} else {
314+
ImGui::Text("rfc : %i", registers->CP2C.n.rfc);
315+
ImGui::Text("gfc : %i", registers->CP2C.n.gfc);
316+
ImGui::Text("bfc : %i", registers->CP2C.n.bfc);
317+
ImGui::Text("ofx : %i", registers->CP2C.n.ofx);
318+
ImGui::Text("ofy : %i", registers->CP2C.n.ofy);
319+
ImGui::Text("h : %i", registers->CP2C.n.h);
320+
ImGui::Text("dqa : %i", registers->CP2C.n.dqa);
321+
ImGui::Text("dqb : %i", registers->CP2C.n.dqb);
322+
ImGui::Text("zsf3: %i", registers->CP2C.n.zsf3);
323+
ImGui::Text("zsf4: %i", registers->CP2C.n.zsf4);
324+
}
325+
ImGui::Text("flag: 0x%08x", registers->CP2C.n.flag);
172326
ImGui::EndTabItem();
173327
}
174328
if (ImGui::BeginTabItem(_("Misc"))) {

src/gui/widgets/registers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ class Registers {
3737

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

4145
unsigned m_selected = 0;
46+
bool m_showFixed = false;
4247
char m_registerEditor[20];
4348
std::string m_editorToOpen;
4449
};

0 commit comments

Comments
 (0)