1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Command 05 - 02 WIP debug

This commit is contained in:
Sergey Lipskiy 2017-05-10 17:58:47 +07:00
parent 02e84b90f2
commit e56e45e2da
3 changed files with 158 additions and 92 deletions

View File

@ -14,6 +14,7 @@
#include "gSP.h"
#include "gDP.h"
#include "GBI.h"
#include "Log.h"
#include "DisplayWindow.h"
#define F3DSWRS_VTXCOLOR 0x02
@ -76,56 +77,161 @@ void F3DSWRS_Jump2(u32, u32)
}
static
void Jump3_2(u32 * _result) {
typedef std::array<s16, 4> Vector;
u32 params[10];
for (u32 i = 1; i < 10; ++i)
params[i] = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + i * 4];
Vector v0{ 0, 0, 0, 0 };
Vector v1{ 0, 0, 0, 0 };
Vector v2{ 0, 0, 0, 0 };
Vector v3{ 0, 0, 0, 0 };
s16 V0 = _SHIFTR(params[9], 0, 16);
s16 V1 = _SHIFTR(params[8], 0, 16);
V1 <<= 4;
v0[0] = _SHIFTR(params[8], 16, 16);
v0[1] = V1;
v0[2] = _SHIFTR(params[9], 16, 16);
v2[0] = V0;
v3[2] = V0;
v1[1] = _SHIFTR(params[2], 16, 16);
_result[0] = ((v0[0] + v1[0]) << 16) | (v0[1] + v1[1]);
_result[1] = ((v0[2] + v1[2]) << 16) | (v0[3] + v1[3]);
void F3DSWRS_PrepareVertices(const u32* _vert, const u8* _colorbase, const u32* _color, const u8* _texbase, bool _useTex, u32 _num)
{
const u32 sscale = _SHIFTR(gSP.textureCoordScale[0], 16, 16);
const u32 tscale = _SHIFTR(gSP.textureCoordScale[0], 0, 16);
const u32 sscale1 = _SHIFTR(gSP.textureCoordScale[1], 16, 16);
const u32 tscale1 = _SHIFTR(gSP.textureCoordScale[1], 0, 16);
GraphicsDrawer & drawer = dwnd().getDrawer();
for (u32 i = 0; i < _num; ++i) {
SPVertex & vtx = drawer.getVertex(_vert[i]);
const u8 *color = _colorbase + _color[i];
vtx.r = color[3] * 0.0039215689f;
vtx.g = color[2] * 0.0039215689f;
vtx.b = color[1] * 0.0039215689f;
vtx.a = color[0] * 0.0039215689f;
if (_useTex) {
const u32 st = *(u32*)&_texbase[4 * i];
u32 s = (s16)_SHIFTR(st, 16, 16);
u32 t = (s16)_SHIFTR(st, 0, 16);
if ((s & 0x8000) != 0)
s |= ~0xffff;
if ((t & 0x8000) != 0)
t |= ~0xffff;
const u32 VMUDN_S = s * sscale;
const u32 VMUDN_T = t * tscale;
const s16 low_acum_S = _SHIFTR(VMUDN_S, 16, 16);
const s16 low_acum_T = _SHIFTR(VMUDN_T, 16, 16);
const u32 VMADH_S = s * sscale1;
const u32 VMADH_T = t * tscale1;
const s16 hi_acum_S = _SHIFTR(VMADH_S, 0, 16);
const s16 hi_acum_T = _SHIFTR(VMADH_T, 0, 16);
const s16 scaledS = low_acum_S + hi_acum_S;
const s16 scaledT = low_acum_T + hi_acum_T;
if (gDP.otherMode.texturePersp == 0) {
vtx.s = _FIXED2FLOAT(scaledS, 4);
vtx.t = _FIXED2FLOAT(scaledT, 4);
}
else {
vtx.s = _FIXED2FLOAT(scaledS, 5);
vtx.t = _FIXED2FLOAT(scaledT, 5);
}
}
}
}
static
void Jump3_2(const u32 * _params, u32 * _result) {
if (_params[1] == 0xFDA00050 && _params[9] == 0xE2000200 && _params[8] == 0xF0000000)
int k = 0;
typedef std::array<s16, 4> Vector;
Vector v0 = { 0, 0, 0, 0 };
Vector v1 = { 0, 0, 0, 0 };
Vector v2 = { 0, 0, 0, 0 };
Vector v3 = { 0, 0, 0, 0 };
s16 V0 = _SHIFTR(_params[9], 0, 16);
s16 V1 = _SHIFTR(_params[8], 0, 16);
V1 <<= 4;
v0[0] = _SHIFTR(_params[8], 16, 16);
v0[1] = V1;
v0[2] = _SHIFTR(_params[9], 16, 16);
v2[0] = V0;
v3[2] = V0;
v1[1] = _SHIFTR(_params[1], 16, 16);
_result[0] = ((v0[0] + v1[0]) << 16) | ((v0[1] + v1[1]) & 0xFFFF);
_result[1] = ((v0[2] + v1[2]) << 16) | ((v0[3] + v1[3]) & 0xFFFF);
v1 = v2;
v1[1] = _SHIFTR(params[2], 0, 16);
_result[2] = ((v0[0] + v1[0]) << 16) | (v0[1] + v1[1]);
_result[3] = ((v0[2] + v1[2]) << 16) | (v0[3] + v1[3]);
v1[1] = _SHIFTR(_params[1], 0, 16);
_result[2] = ((v0[0] + v1[0]) << 16) | ((v0[1] + v1[1]) & 0xFFFF);
_result[3] = ((v0[2] + v1[2]) << 16) | ((v0[3] + v1[3]) & 0xFFFF);
v1 = v3;
v1[1] = _SHIFTR(params[1], 16, 16);
_result[4] = ((v0[0] + v1[0]) << 16) | (v0[1] + v1[1]);
_result[5] = ((v0[2] + v1[2]) << 16) | (v0[3] + v1[3]);
v1[1] = _SHIFTR(_params[2], 16, 16);
_result[4] = ((v0[0] + v1[0]) << 16) | ((v0[1] + v1[1]) & 0xFFFF);
_result[5] = ((v0[2] + v1[2]) << 16) | ((v0[3] + v1[3]) & 0xFFFF);
for (u32 i = 0; i < 4; ++i)
v1[i] = v2[i] + v3[i];
v1[1] = _SHIFTR(params[1], 0, 16);
_result[6] = ((v0[0] + v1[0]) << 16) | (v0[1] + v1[1]);
_result[7] = ((v0[2] + v1[2]) << 16) | (v0[3] + v1[3]);
v1[i] = v2[i] + v3[i];
v1[1] = _SHIFTR(_params[2], 0, 16);
_result[6] = ((v0[0] + v1[0]) << 16) | ((v0[1] + v1[1]) & 0xFFFF);
_result[7] = ((v0[2] + v1[2]) << 16) | ((v0[3] + v1[3]) & 0xFFFF);
}
bool _print = false;
void F3DSWRS_Jump3(u32 _w0, u32 _w1)
{
const u32 mode = _SHIFTR(_w0, 8, 8);
switch (mode) {
case 0x02: {
u32 vecdata[8];
Jump3_2(vecdata);
const SWVertex * vertex = (const SWVertex*)&vecdata[0];
gSPSWVertex(vertex, 4, 0);
}
break;
default:
break;
}
const u32 mode = _SHIFTR(_w0, 8, 8);
switch (mode) {
case 0x02:
{
/*
u32 params[10] = {
0x05050200,
0xFDA00050,
0xFDD00190,
0xF4F4F401,
0xE4E4E4FF,
0xFFFFFFFF,
0xFFFFFFFF,
0x000007E0,
0xF0000000,
0xE2000200 };
*/
u32 params[10];
for (u32 i = 1; i < 10; ++i)
params[i] = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + i * 4];
u32 vecdata[8];
Jump3_2(params, vecdata);
const SWVertex * vertex = (const SWVertex*)&vecdata[0];
gSPSWVertex(vertex, 4, 0);
GraphicsDrawer & drawer = dwnd().getDrawer();
if (_print) {
for (u32 i = 0; i < 4; ++i) {
SPVertex & v = drawer.getVertex(i);
f32 sx = v.x / v.w * gSP.viewport.vscale[0] + gSP.viewport.vtrans[0];
f32 sy = v.y / v.w * gSP.viewport.vscale[1] + gSP.viewport.vtrans[1];
f32 sz = v.z / v.w * gSP.viewport.vscale[2] + gSP.viewport.vtrans[2];
debugPrint("v[%d] x=%02f y=%02f z=%02f\n", i, sx, gDP.scissor.lry - sy, sz);
}
}
const u32 v1 = 0;
const u32 v2 = 1;
const u32 v3 = 2;
const u32 v4 = 3;
const u32 vert[4] = { v1, v2, v3, v4 };
const u32 colorbase[4] = { params[3] | 0xFF, params[4] | 0xFF, params[5] | 0xFF, params[6] | 0xFF };
const u32 color[4] = { 0, 4, 8, 12 };
const u32 tex = _SHIFTR(params[7], 0, 16);
const u32 texbase[4] = { tex, tex | (tex << 16), 0, (tex << 16) };
const bool useTex = true;// (_w0 & 2) != 0;
F3DSWRS_PrepareVertices(vert, (u8*)colorbase, color, (u8*)texbase, true, 4);
SPVertex & vtx2 = drawer.getVertex(v2);
SPVertex & vtx3 = drawer.getVertex(v3);
gSP.swrs_special = true;
if (vtx3.z / vtx3.w > vtx2.z / vtx2.w)
gSP2Triangles(v1, v2, v4, 0, v1, v4, v3, 0);
else
gSP2Triangles(v1, v4, v3, 0, v1, v2, v4, 0);
dwnd().getDrawer().drawTriangles();
gSP.swrs_special = false;
}
break;
default:
break;
}
RSP.PC[RSP.PCi] = RSP.swDL[RSP.PCi].SWOtherDL;
RSP.swDL[RSP.PCi].SWStartDL = _SHIFTR(*(u32*)&RDRAM[RSP.PC[RSP.PCi]], 0, 24);
RSP.swDL[RSP.PCi].SWOtherDL = _SHIFTR(*(u32*)&RDRAM[RSP.PC[RSP.PCi] + 4], 0, 24);
@ -141,54 +247,6 @@ void F3DSWRS_BranchDList(u32, u32 _w1)
gSPSWBranchList(_w1);
}
static
void F3DSWRS_PrepareVertices(const u32* _vert, const u32* _color, bool _useTex, u32 _num)
{
const u32 sscale0 = _SHIFTR(gSP.textureCoordScale[0], 16, 16);
const u32 tscale0 = _SHIFTR(gSP.textureCoordScale[0], 0, 16);
const u32 sscale1 = _SHIFTR(gSP.textureCoordScale[1], 16, 16);
const u32 tscale1 = _SHIFTR(gSP.textureCoordScale[1], 0, 16);
GraphicsDrawer & drawer = dwnd().getDrawer();
for (u32 i = 0; i < _num; ++i) {
SPVertex & vtx = drawer.getVertex(_vert[i]);
u8 *color = &RDRAM[gSP.vertexColorBase + _color[i]];
vtx.r = color[3] * 0.0039215689f;
vtx.g = color[2] * 0.0039215689f;
vtx.b = color[1] * 0.0039215689f;
vtx.a = color[0] * 0.0039215689f;
if (_useTex) {
const u32 st = *(u32*)&RDRAM[RSP.PC[RSP.PCi] + 16 + 4*i];
u32 s = (s16)_SHIFTR(st, 16, 16);
u32 t = (s16)_SHIFTR(st, 0, 16);
if ((s & 0x8000) != 0)
s |= ~0xffff;
if ((t & 0x8000) != 0)
t |= ~0xffff;
const u32 VMUDN_S = s * sscale0;
const u32 VMUDN_T = t * tscale0;
const s16 low_acum_S = _SHIFTR(VMUDN_S, 16, 16);
const s16 low_acum_T = _SHIFTR(VMUDN_T, 16, 16);
const u32 VMADH_S = s * sscale1;
const u32 VMADH_T = t * tscale1;
const s16 hi_acum_S = _SHIFTR(VMADH_S, 0, 16);
const s16 hi_acum_T = _SHIFTR(VMADH_T, 0, 16);
const s16 scaledS = low_acum_S + hi_acum_S;
const s16 scaledT = low_acum_T + hi_acum_T;
if (gDP.otherMode.texturePersp == 0) {
vtx.s = _FIXED2FLOAT(scaledS, 4);
vtx.t = _FIXED2FLOAT(scaledT, 4);
} else {
vtx.s = _FIXED2FLOAT(scaledS, 5);
vtx.t = _FIXED2FLOAT(scaledT, 5);
}
}
}
}
void F3DSWRS_Tri1(u32 _w0, u32 _w1)
{
const u32 v1 = (_SHIFTR( _w1, 13, 11 ) & 0x7F8) / 40;
@ -200,7 +258,8 @@ void F3DSWRS_Tri1(u32 _w0, u32 _w1)
const u32 color[3] = { _SHIFTR(nextCMD, 16, 8), _SHIFTR(nextCMD, 8, 8), _SHIFTR(nextCMD, 0, 8) };
const bool useTex = (_w0 & 2) != 0;
F3DSWRS_PrepareVertices(vert, color, useTex, 3);
const u8 * texbase = RDRAM + RSP.PC[RSP.PCi] + 16;
F3DSWRS_PrepareVertices(vert, RDRAM + gSP.vertexColorBase, color, texbase, useTex, 3);
if (useTex)
RSP.PC[RSP.PCi] += 16;
@ -222,7 +281,8 @@ void F3DSWRS_Tri2(u32 _w0, u32 _w1)
_SHIFTR(nextCMD, 0, 8), _SHIFTR(nextCMD, 24, 8) };
const bool useTex = (_w0 & 2) != 0;
F3DSWRS_PrepareVertices(vert, color, useTex, 4);
const u8 * texbase = RDRAM + RSP.PC[RSP.PCi] + 16;
F3DSWRS_PrepareVertices(vert, RDRAM + gSP.vertexColorBase, color, texbase, useTex, 4);
if (useTex)
RSP.PC[RSP.PCi] += 16;

View File

@ -666,6 +666,11 @@ void GraphicsDrawer::drawTriangles()
_prepareDrawTriangle();
if (gSP.swrs_special) {
CombinerInfo::get().setCombine(EncodeCombineMode(0, 0, 0, SHADE, 0, 0, 0, 1, 0, 0, 0, SHADE, 0, 0, 0, 1));
currentCombiner()->update(true);
}
Context::DrawTriangleParameters triParams;
triParams.mode = drawmode::TRIANGLES;
triParams.flatColors = m_bFlatColors;

View File

@ -140,6 +140,7 @@ struct gSPInfo
u32 textureCoordScaleOrg;
u32 textureCoordScale[2];
bool swrs_special;
};
extern gSPInfo gSP;