[Glide64] Cleanup ucode .h files

This commit is contained in:
zilmar 2016-01-25 22:14:01 +11:00
parent b8cbfa30c4
commit 4fc4f921e9
13 changed files with 4920 additions and 4935 deletions

View File

@ -44,22 +44,22 @@
/******************Turbo3D microcode*************************/
struct t3dGlobState {
uint16_t pad0;
uint16_t perspNorm;
uint32_t flag;
uint32_t othermode0;
uint32_t othermode1;
uint32_t segBases[16];
/* the viewport to use */
short vsacle1;
short vsacle0;
short vsacle3;
short vsacle2;
short vtrans1;
short vtrans0;
short vtrans3;
short vtrans2;
uint32_t rdpCmds;
uint16_t pad0;
uint16_t perspNorm;
uint32_t flag;
uint32_t othermode0;
uint32_t othermode1;
uint32_t segBases[16];
/* the viewport to use */
short vsacle1;
short vsacle0;
short vsacle3;
short vsacle2;
short vtrans1;
short vtrans0;
short vtrans3;
short vtrans2;
uint32_t rdpCmds;
};
struct t3dState {
@ -74,65 +74,63 @@ struct t3dState {
uint32_t othermode1;
};
struct t3dTriN{
uint8_t flag, v2, v1, v0; /* flag is which one for flat shade */
uint8_t flag, v2, v1, v0; /* flag is which one for flat shade */
};
static void t3dProcessRDP(uint32_t a)
{
if (a)
{
rdp.LLE = 1;
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
while (rdp.cmd0 + rdp.cmd1) {
gfx_instruction[0][rdp.cmd0>>24] ();
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
uint32_t cmd = rdp.cmd0>>24;
if (cmd == 0xE4 || cmd == 0xE5)
{
rdp.cmd2 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd3 = ((uint32_t*)gfx.RDRAM)[a++];
}
if (a)
{
rdp.LLE = 1;
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
while (rdp.cmd0 + rdp.cmd1) {
gfx_instruction[0][rdp.cmd0 >> 24]();
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
uint32_t cmd = rdp.cmd0 >> 24;
if (cmd == 0xE4 || cmd == 0xE5)
{
rdp.cmd2 = ((uint32_t*)gfx.RDRAM)[a++];
rdp.cmd3 = ((uint32_t*)gfx.RDRAM)[a++];
}
}
rdp.LLE = 0;
}
rdp.LLE = 0;
}
}
static void t3dLoadGlobState(uint32_t pgstate)
{
t3dGlobState *gstate = (t3dGlobState*)&gfx.RDRAM[segoffset(pgstate)];
FRDP ("Global state. pad0: %04lx, perspNorm: %04lx, flag: %08lx\n", gstate->pad0, gstate->perspNorm, gstate->flag);
rdp.cmd0 = gstate->othermode0;
rdp.cmd1 = gstate->othermode1;
rdp_setothermode();
t3dGlobState *gstate = (t3dGlobState*)&gfx.RDRAM[segoffset(pgstate)];
FRDP("Global state. pad0: %04lx, perspNorm: %04lx, flag: %08lx\n", gstate->pad0, gstate->perspNorm, gstate->flag);
rdp.cmd0 = gstate->othermode0;
rdp.cmd1 = gstate->othermode1;
rdp_setothermode();
for (int s = 0; s < 16; s++)
{
rdp.segment[s] = gstate->segBases[s];
FRDP ("segment: %08lx -> seg%d\n", rdp.segment[s], s);
}
for (int s = 0; s < 16; s++)
{
rdp.segment[s] = gstate->segBases[s];
FRDP("segment: %08lx -> seg%d\n", rdp.segment[s], s);
}
short scale_x = gstate->vsacle0 / 4;
short scale_y = gstate->vsacle1 / 4;;
short scale_z = gstate->vsacle2;
short trans_x = gstate->vtrans0 / 4;
short trans_y = gstate->vtrans1 / 4;
short trans_z = gstate->vtrans2;
rdp.view_scale[0] = scale_x * rdp.scale_x;
rdp.view_scale[1] = -scale_y * rdp.scale_y;
rdp.view_scale[2] = 32.0f * scale_z;
rdp.view_trans[0] = trans_x * rdp.scale_x;
rdp.view_trans[1] = trans_y * rdp.scale_y;
rdp.view_trans[2] = 32.0f * trans_z;
rdp.update |= UPDATE_VIEWPORT;
FRDP ("viewport scale(%d, %d, %d), trans(%d, %d, %d)\n", scale_x, scale_y, scale_z,
trans_x, trans_y, trans_z);
short scale_x = gstate->vsacle0 / 4;
short scale_y = gstate->vsacle1 / 4;;
short scale_z = gstate->vsacle2;
short trans_x = gstate->vtrans0 / 4;
short trans_y = gstate->vtrans1 / 4;
short trans_z = gstate->vtrans2;
rdp.view_scale[0] = scale_x * rdp.scale_x;
rdp.view_scale[1] = -scale_y * rdp.scale_y;
rdp.view_scale[2] = 32.0f * scale_z;
rdp.view_trans[0] = trans_x * rdp.scale_x;
rdp.view_trans[1] = trans_y * rdp.scale_y;
rdp.view_trans[2] = 32.0f * trans_z;
rdp.update |= UPDATE_VIEWPORT;
FRDP("viewport scale(%d, %d, %d), trans(%d, %d, %d)\n", scale_x, scale_y, scale_z,
trans_x, trans_y, trans_z);
t3dProcessRDP(segoffset(gstate->rdpCmds) >> 2);
t3dProcessRDP(segoffset(gstate->rdpCmds) >> 2);
}
static void t3d_vertex(uint32_t addr, uint32_t v0, uint32_t n)
@ -143,134 +141,134 @@ static void t3d_vertex(uint32_t addr, uint32_t v0, uint32_t n)
rdp.vn = n; // Number of vertices to copy
n <<= 4;
for (uint32_t i=0; i < n; i+=16)
for (uint32_t i = 0; i < n; i += 16)
{
VERTEX *v = &rdp.vtx[v0 + (i>>4)];
x = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 0)^1];
y = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 1)^1];
z = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 2)^1];
v->flags = ((uint16_t*)gfx.RDRAM)[(((addr+i) >> 1) + 3)^1];
v->ou = 2.0f * (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 4)^1];
v->ov = 2.0f * (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 5)^1];
v->uv_scaled = 0;
v->r = ((uint8_t*)gfx.RDRAM)[(addr+i + 12)^3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr+i + 13)^3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr+i + 14)^3];
v->a = ((uint8_t*)gfx.RDRAM)[(addr+i + 15)^3];
VERTEX *v = &rdp.vtx[v0 + (i >> 4)];
x = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 0) ^ 1];
y = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 1) ^ 1];
z = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 2) ^ 1];
v->flags = ((uint16_t*)gfx.RDRAM)[(((addr + i) >> 1) + 3) ^ 1];
v->ou = 2.0f * (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 4) ^ 1];
v->ov = 2.0f * (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 5) ^ 1];
v->uv_scaled = 0;
v->r = ((uint8_t*)gfx.RDRAM)[(addr + i + 12) ^ 3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr + i + 13) ^ 3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr + i + 14) ^ 3];
v->a = ((uint8_t*)gfx.RDRAM)[(addr + i + 15) ^ 3];
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
#ifdef EXTREME_LOGGING
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f, f: %f, z_w: %f, r=%d, g=%d, b=%d, a=%d\n", i>>4, v->x, v->y, v->z, v->w, v->ou*rdp.tiles[rdp.cur_tile].s_scale, v->ov*rdp.tiles[rdp.cur_tile].t_scale, v->f, v->z_w, v->r, v->g, v->b, v->a);
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f, f: %f, z_w: %f, r=%d, g=%d, b=%d, a=%d\n", i>>4, v->x, v->y, v->z, v->w, v->ou*rdp.tiles[rdp.cur_tile].s_scale, v->ov*rdp.tiles[rdp.cur_tile].t_scale, v->f, v->z_w, v->r, v->g, v->b, v->a);
#endif
}
}
static void t3dLoadObject(uint32_t pstate, uint32_t pvtx, uint32_t ptri)
{
LRDP("Loading Turbo3D object\n");
t3dState *ostate = (t3dState*)&gfx.RDRAM[segoffset(pstate)];
rdp.cur_tile = (ostate->textureState)&7;
FRDP("tile: %d\n", rdp.cur_tile);
if (rdp.tiles[rdp.cur_tile].s_scale < 0.001f)
rdp.tiles[rdp.cur_tile].s_scale = 0.015625;
if (rdp.tiles[rdp.cur_tile].t_scale < 0.001f)
rdp.tiles[rdp.cur_tile].t_scale = 0.015625;
LRDP("Loading Turbo3D object\n");
t3dState *ostate = (t3dState*)&gfx.RDRAM[segoffset(pstate)];
rdp.cur_tile = (ostate->textureState) & 7;
FRDP("tile: %d\n", rdp.cur_tile);
if (rdp.tiles[rdp.cur_tile].s_scale < 0.001f)
rdp.tiles[rdp.cur_tile].s_scale = 0.015625;
if (rdp.tiles[rdp.cur_tile].t_scale < 0.001f)
rdp.tiles[rdp.cur_tile].t_scale = 0.015625;
#ifdef EXTREME_LOGGING
FRDP("renderState: %08lx, textureState: %08lx, othermode0: %08lx, othermode1: %08lx, rdpCmds: %08lx, triCount : %d, v0: %d, vn: %d\n", ostate->renderState, ostate->textureState,
ostate->othermode0, ostate->othermode1, ostate->rdpCmds, ostate->triCount, ostate->vtxV0, ostate->vtxCount);
FRDP("renderState: %08lx, textureState: %08lx, othermode0: %08lx, othermode1: %08lx, rdpCmds: %08lx, triCount : %d, v0: %d, vn: %d\n", ostate->renderState, ostate->textureState,
ostate->othermode0, ostate->othermode1, ostate->rdpCmds, ostate->triCount, ostate->vtxV0, ostate->vtxCount);
#endif
rdp.cmd0 = ostate->othermode0;
rdp.cmd1 = ostate->othermode1;
rdp_setothermode();
rdp.cmd0 = ostate->othermode0;
rdp.cmd1 = ostate->othermode1;
rdp_setothermode();
rdp.cmd1 = ostate->renderState;
uc0_setgeometrymode();
rdp.cmd1 = ostate->renderState;
uc0_setgeometrymode();
if (!(ostate->flag&1)) //load matrix
{
uint32_t addr = segoffset(pstate+sizeof(t3dState)) & BMASK;
load_matrix(rdp.combined, addr);
#ifdef EXTREME_LOGGING
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[0][0], rdp.combined[0][1], rdp.combined[0][2], rdp.combined[0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[1][0], rdp.combined[1][1], rdp.combined[1][2], rdp.combined[1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[2][0], rdp.combined[2][1], rdp.combined[2][2], rdp.combined[2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[3][0], rdp.combined[3][1], rdp.combined[3][2], rdp.combined[3][3]);
#endif
}
rdp.geom_mode &= ~0x00020000;
rdp.geom_mode |= 0x00000200;
if (pvtx) //load vtx
t3d_vertex(segoffset(pvtx) & BMASK, ostate->vtxV0, ostate->vtxCount);
t3dProcessRDP(segoffset(ostate->rdpCmds) >> 2);
if (ptri)
{
update ();
uint32_t a = segoffset(ptri);
for (int t=0; t < ostate->triCount; t++)
if (!(ostate->flag & 1)) //load matrix
{
t3dTriN * tri = (t3dTriN*)&gfx.RDRAM[a];
a += 4;
FRDP("tri #%d - %d, %d, %d\n", t, tri->v0, tri->v1, tri->v2);
VERTEX *v[3] = { &rdp.vtx[tri->v0], &rdp.vtx[tri->v1], &rdp.vtx[tri->v2] };
if (cull_tri(v))
rdp.tri_n ++;
else
{
draw_tri (v);
rdp.tri_n ++;
}
uint32_t addr = segoffset(pstate + sizeof(t3dState)) & BMASK;
load_matrix(rdp.combined, addr);
#ifdef EXTREME_LOGGING
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[0][0], rdp.combined[0][1], rdp.combined[0][2], rdp.combined[0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[1][0], rdp.combined[1][1], rdp.combined[1][2], rdp.combined[1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[2][0], rdp.combined[2][1], rdp.combined[2][2], rdp.combined[2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.combined[3][0], rdp.combined[3][1], rdp.combined[3][2], rdp.combined[3][3]);
#endif
}
rdp.geom_mode &= ~0x00020000;
rdp.geom_mode |= 0x00000200;
if (pvtx) //load vtx
t3d_vertex(segoffset(pvtx) & BMASK, ostate->vtxV0, ostate->vtxCount);
t3dProcessRDP(segoffset(ostate->rdpCmds) >> 2);
if (ptri)
{
update();
uint32_t a = segoffset(ptri);
for (int t = 0; t < ostate->triCount; t++)
{
t3dTriN * tri = (t3dTriN*)&gfx.RDRAM[a];
a += 4;
FRDP("tri #%d - %d, %d, %d\n", t, tri->v0, tri->v1, tri->v2);
VERTEX *v[3] = { &rdp.vtx[tri->v0], &rdp.vtx[tri->v1], &rdp.vtx[tri->v2] };
if (cull_tri(v))
rdp.tri_n++;
else
{
draw_tri(v);
rdp.tri_n++;
}
}
}
}
}
static void Turbo3D()
{
LRDP("Start Turbo3D microcode\n");
settings.ucode = ucode_Fast3D;
uint32_t a = 0, pgstate = 0, pstate = 0, pvtx = 0, ptri = 0;
do {
a = rdp.pc[rdp.pc_i] & BMASK;
pgstate = ((uint32_t*)gfx.RDRAM)[a>>2];
pstate = ((uint32_t*)gfx.RDRAM)[(a>>2)+1];
pvtx = ((uint32_t*)gfx.RDRAM)[(a>>2)+2];
ptri = ((uint32_t*)gfx.RDRAM)[(a>>2)+3];
FRDP("GlobalState: %08lx, Object: %08lx, Vertices: %08lx, Triangles: %08lx\n", pgstate, pstate, pvtx, ptri);
if (!pstate)
{
rdp.halt = 1;
break;
}
if (pgstate)
t3dLoadGlobState(pgstate);
t3dLoadObject(pstate, pvtx, ptri);
// Go to the next instruction
rdp.pc[rdp.pc_i] += 16;
} while (pstate);
// rdp_fullsync();
settings.ucode = ucode_Turbo3d;
LRDP("Start Turbo3D microcode\n");
settings.ucode = ucode_Fast3D;
uint32_t a = 0, pgstate = 0, pstate = 0, pvtx = 0, ptri = 0;
do {
a = rdp.pc[rdp.pc_i] & BMASK;
pgstate = ((uint32_t*)gfx.RDRAM)[a >> 2];
pstate = ((uint32_t*)gfx.RDRAM)[(a >> 2) + 1];
pvtx = ((uint32_t*)gfx.RDRAM)[(a >> 2) + 2];
ptri = ((uint32_t*)gfx.RDRAM)[(a >> 2) + 3];
FRDP("GlobalState: %08lx, Object: %08lx, Vertices: %08lx, Triangles: %08lx\n", pgstate, pstate, pvtx, ptri);
if (!pstate)
{
rdp.halt = 1;
break;
}
if (pgstate)
t3dLoadGlobState(pgstate);
t3dLoadObject(pstate, pvtx, ptri);
// Go to the next instruction
rdp.pc[rdp.pc_i] += 16;
} while (pstate);
// rdp_fullsync();
settings.ucode = ucode_Turbo3d;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,9 @@
static void uc1_vertex()
{
int v0 = (rdp.cmd0 >> 17) & 0x7F; // Current vertex
int n = (rdp.cmd0 >> 10) & 0x3F; // Number to copy
rsp_vertex(v0, n);
int v0 = (rdp.cmd0 >> 17) & 0x7F; // Current vertex
int n = (rdp.cmd0 >> 10) & 0x3F; // Number to copy
rsp_vertex(v0, n);
}
//
@ -54,110 +54,110 @@ static void uc1_vertex()
static void uc1_tri1()
{
if (rdp.skip_drawing)
{
LRDP("uc1:tri1. skipped\n");
return;
}
FRDP("uc1:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp.tri_n,
((rdp.cmd1 >> 17) & 0x7F),
((rdp.cmd1 >> 9) & 0x7F),
((rdp.cmd1 >> 1) & 0x7F), rdp.cmd0, rdp.cmd1);
VERTEX *v[3] = {
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
};
rsp_tri1(v);
if (rdp.skip_drawing)
{
LRDP("uc1:tri1. skipped\n");
return;
}
FRDP("uc1:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp.tri_n,
((rdp.cmd1 >> 17) & 0x7F),
((rdp.cmd1 >> 9) & 0x7F),
((rdp.cmd1 >> 1) & 0x7F), rdp.cmd0, rdp.cmd1);
VERTEX *v[3] = {
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
};
rsp_tri1(v);
}
static void uc1_tri2 ()
static void uc1_tri2()
{
if (rdp.skip_drawing)
{
LRDP("uc1:tri2. skipped\n");
return;
}
LRDP("uc1:tri2");
FRDP(" #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n+1,
((rdp.cmd0 >> 17) & 0x7F),
((rdp.cmd0 >> 9) & 0x7F),
((rdp.cmd0 >> 1) & 0x7F),
((rdp.cmd1 >> 17) & 0x7F),
((rdp.cmd1 >> 9) & 0x7F),
((rdp.cmd1 >> 1) & 0x7F));
VERTEX *v[6] = {
&rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd0 >> 1) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
};
rsp_tri2(v);
if (rdp.skip_drawing)
{
LRDP("uc1:tri2. skipped\n");
return;
}
LRDP("uc1:tri2");
FRDP(" #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n + 1,
((rdp.cmd0 >> 17) & 0x7F),
((rdp.cmd0 >> 9) & 0x7F),
((rdp.cmd0 >> 1) & 0x7F),
((rdp.cmd1 >> 17) & 0x7F),
((rdp.cmd1 >> 9) & 0x7F),
((rdp.cmd1 >> 1) & 0x7F));
VERTEX *v[6] = {
&rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd0 >> 1) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
};
rsp_tri2(v);
}
static void uc1_line3d()
{
if (!settings.force_quad3d && ((rdp.cmd1&0xFF000000) == 0) && ((rdp.cmd0&0x00FFFFFF) == 0))
{
uint16_t width = (uint16_t)(rdp.cmd1&0xFF) + 3;
FRDP("uc1:line3d width: %d #%d, #%d - %d, %d\n", width, rdp.tri_n, rdp.tri_n+1,
(rdp.cmd1 >> 17) & 0x7F,
(rdp.cmd1 >> 9) & 0x7F);
VERTEX *v[3] = {
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
};
uint32_t cull_mode = (rdp.flags & CULLMASK) >> CULLSHIFT;
rdp.flags |= CULLMASK;
rdp.update |= UPDATE_CULL_MODE;
rsp_tri1(v, width);
rdp.flags ^= CULLMASK;
rdp.flags |= cull_mode << CULLSHIFT;
rdp.update |= UPDATE_CULL_MODE;
}
else
{
FRDP("uc1:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n+1);
VERTEX *v[6] = {
&rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
};
rsp_tri2(v);
}
if (!settings.force_quad3d && ((rdp.cmd1 & 0xFF000000) == 0) && ((rdp.cmd0 & 0x00FFFFFF) == 0))
{
uint16_t width = (uint16_t)(rdp.cmd1 & 0xFF) + 3;
FRDP("uc1:line3d width: %d #%d, #%d - %d, %d\n", width, rdp.tri_n, rdp.tri_n + 1,
(rdp.cmd1 >> 17) & 0x7F,
(rdp.cmd1 >> 9) & 0x7F);
VERTEX *v[3] = {
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
};
uint32_t cull_mode = (rdp.flags & CULLMASK) >> CULLSHIFT;
rdp.flags |= CULLMASK;
rdp.update |= UPDATE_CULL_MODE;
rsp_tri1(v, width);
rdp.flags ^= CULLMASK;
rdp.flags |= cull_mode << CULLSHIFT;
rdp.update |= UPDATE_CULL_MODE;
}
else
{
FRDP("uc1:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n + 1);
VERTEX *v[6] = {
&rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 1) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
&rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
};
rsp_tri2(v);
}
}
uint32_t branch_dl = 0;
static void uc1_rdphalf_1()
{
LRDP("uc1:rdphalf_1\n");
branch_dl = rdp.cmd1;
rdphalf_1();
LRDP("uc1:rdphalf_1\n");
branch_dl = rdp.cmd1;
rdphalf_1();
}
static void uc1_branch_z()
{
uint32_t addr = segoffset(branch_dl);
FRDP ("uc1:branch_less_z, addr: %08lx\n", addr);
uint32_t vtx = (rdp.cmd0 & 0xFFF) >> 1;
if( fabs(rdp.vtx[vtx].z) <= (rdp.cmd1/*&0xFFFF*/) )
{
rdp.pc[rdp.pc_i] = addr;
}
uint32_t addr = segoffset(branch_dl);
FRDP("uc1:branch_less_z, addr: %08lx\n", addr);
uint32_t vtx = (rdp.cmd0 & 0xFFF) >> 1;
if (fabs(rdp.vtx[vtx].z) <= (rdp.cmd1/*&0xFFFF*/))
{
rdp.pc[rdp.pc_i] = addr;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -43,16 +43,16 @@
static void uc3_vertex()
{
int v0 = ((rdp.cmd0 >> 16) & 0xFF)/5; // Current vertex
int n = (uint16_t)((rdp.cmd0&0xFFFF) + 1)/0x210; // Number to copy
int v0 = ((rdp.cmd0 >> 16) & 0xFF) / 5; // Current vertex
int n = (uint16_t)((rdp.cmd0 & 0xFFFF) + 1) / 0x210; // Number to copy
if (v0 >= 32)
v0 = 31;
if (v0 >= 32)
v0 = 31;
if ((v0 + n) > 32)
n = 32 - v0;
if ((v0 + n) > 32)
n = 32 - v0;
rsp_vertex(v0, n);
rsp_vertex(v0, n);
}
//
@ -61,54 +61,54 @@ static void uc3_vertex()
static void uc3_tri1()
{
FRDP("uc3:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp.tri_n,
((rdp.cmd1 >> 16) & 0xFF)/5,
((rdp.cmd1 >> 8) & 0xFF)/5,
((rdp.cmd1 ) & 0xFF)/5, rdp.cmd0, rdp.cmd1);
VERTEX *v[3] = {
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF)/5],
&rdp.vtx[(rdp.cmd1 & 0xFF)/5]
};
FRDP("uc3:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp.tri_n,
((rdp.cmd1 >> 16) & 0xFF) / 5,
((rdp.cmd1 >> 8) & 0xFF) / 5,
((rdp.cmd1) & 0xFF) / 5, rdp.cmd0, rdp.cmd1);
rsp_tri1(v);
VERTEX *v[3] = {
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd1 & 0xFF) / 5]
};
rsp_tri1(v);
}
static void uc3_tri2 ()
static void uc3_tri2()
{
FRDP("uc3:tri2 #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n+1,
((rdp.cmd0 >> 16) & 0xFF)/5,
((rdp.cmd0 >> 8) & 0xFF)/5,
((rdp.cmd0 ) & 0xFF)/5,
((rdp.cmd1 >> 16) & 0xFF)/5,
((rdp.cmd1 >> 8) & 0xFF)/5,
((rdp.cmd1 ) & 0xFF)/5);
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd0 >> 16) & 0xFF)/5],
&rdp.vtx[((rdp.cmd0 >> 8) & 0xFF)/5],
&rdp.vtx[(rdp.cmd0 & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF)/5],
&rdp.vtx[(rdp.cmd1 & 0xFF)/5]
};
FRDP("uc3:tri2 #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n + 1,
((rdp.cmd0 >> 16) & 0xFF) / 5,
((rdp.cmd0 >> 8) & 0xFF) / 5,
((rdp.cmd0) & 0xFF) / 5,
((rdp.cmd1 >> 16) & 0xFF) / 5,
((rdp.cmd1 >> 8) & 0xFF) / 5,
((rdp.cmd1) & 0xFF) / 5);
rsp_tri2(v);
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd0 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd0 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd0 & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd1 & 0xFF) / 5]
};
rsp_tri2(v);
}
static void uc3_quad3d()
{
FRDP("uc3:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n+1);
FRDP("uc3:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n + 1);
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF)/5],
&rdp.vtx[(rdp.cmd1 & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF)/5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF)/5]
};
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd1 & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5]
};
rsp_tri2(v);
rsp_tri2(v);
}

View File

@ -43,40 +43,40 @@
static void uc4_vertex()
{
int v0 = 0; // Current vertex
int n = ((rdp.cmd0 >> 4) & 0xFFF) / 33 + 1; // Number of vertices to copy
rsp_vertex(v0, n);
int v0 = 0; // Current vertex
int n = ((rdp.cmd0 >> 4) & 0xFFF) / 33 + 1; // Number of vertices to copy
rsp_vertex(v0, n);
}
static void uc4_tri1()
{
int v1 = ((rdp.cmd1 >> 16) & 0xFF) / 5;
int v2 = ((rdp.cmd1 >> 8) & 0xFF) / 5;
int v3 = (rdp.cmd1 & 0xFF) / 5;
FRDP("uc4:tri1 #%d - %d, %d, %d\n", rdp.tri_n,
v1, v2, v3);
int v1 = ((rdp.cmd1 >> 16) & 0xFF) / 5;
int v2 = ((rdp.cmd1 >> 8) & 0xFF) / 5;
int v3 = (rdp.cmd1 & 0xFF) / 5;
FRDP("uc4:tri1 #%d - %d, %d, %d\n", rdp.tri_n,
v1, v2, v3);
VERTEX *v[3] = {
&rdp.vtx[v1],
&rdp.vtx[v2],
&rdp.vtx[v3]
};
VERTEX *v[3] = {
&rdp.vtx[v1],
&rdp.vtx[v2],
&rdp.vtx[v3]
};
rsp_tri1(v);
rsp_tri1(v);
}
static void uc4_quad3d()
{
FRDP("uc4:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n+1);
FRDP("uc4:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n + 1);
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd1 & 0xFF) / 5]
};
VERTEX *v[6] = {
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 16) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 24) & 0xFF) / 5],
&rdp.vtx[((rdp.cmd1 >> 8) & 0xFF) / 5],
&rdp.vtx[(rdp.cmd1 & 0xFF) / 5]
};
rsp_tri2(v);
rsp_tri2(v);
}

View File

@ -43,333 +43,333 @@ int vtx_last = 0;
uint32_t dma_offset_mtx = 0;
uint32_t dma_offset_vtx = 0;
static void uc5_dma_offsets ()
static void uc5_dma_offsets()
{
dma_offset_mtx = rdp.cmd0 & 0x00FFFFFF;
dma_offset_vtx = rdp.cmd1 & 0x00FFFFFF;
vtx_last = 0;
FRDP("uc5:dma_offsets - mtx: %08lx, vtx: %08lx\n", dma_offset_mtx, dma_offset_vtx);
}
static void uc5_matrix ()
{
// Use segment offset to get the address
uint32_t addr = dma_offset_mtx + (segoffset(rdp.cmd1) & BMASK);
uint8_t n = (uint8_t)((rdp.cmd0 >> 16) & 0xF);
uint8_t multiply;
if (n == 0) //DKR
{
n = (uint8_t)((rdp.cmd0 >> 22) & 0x3);
multiply = 0;
}
else //JF
{
multiply = (uint8_t)((rdp.cmd0 >> 23) & 0x1);
}
cur_mtx = n;
FRDP("uc5:matrix - #%d, addr: %08lx\n", n, addr);
if (multiply)
{
DECLAREALIGN16VAR(m[4][4]);
load_matrix(m, addr);
DECLAREALIGN16VAR(m_src[4][4]);
memcpy (m_src, rdp.dkrproj[0], 64);
MulMatrices(m, m_src, rdp.dkrproj[n]);
}
else
{
load_matrix(rdp.dkrproj[n], addr);
}
rdp.update |= UPDATE_MULT_MAT;
#ifdef EXTREME_LOGGING
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][0][0], rdp.dkrproj[n][0][1], rdp.dkrproj[n][0][2], rdp.dkrproj[n][0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][1][0], rdp.dkrproj[n][1][1], rdp.dkrproj[n][1][2], rdp.dkrproj[n][1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][2][0], rdp.dkrproj[n][2][1], rdp.dkrproj[n][2][2], rdp.dkrproj[n][2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][3][0], rdp.dkrproj[n][3][1], rdp.dkrproj[n][3][2], rdp.dkrproj[n][3][3]);
for (int i=0; i<3; i++)
{
FRDP ("proj %d\n", i);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][0][0], rdp.dkrproj[i][0][1], rdp.dkrproj[i][0][2], rdp.dkrproj[i][0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][1][0], rdp.dkrproj[i][1][1], rdp.dkrproj[i][1][2], rdp.dkrproj[i][1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][2][0], rdp.dkrproj[i][2][1], rdp.dkrproj[i][2][2], rdp.dkrproj[i][2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][3][0], rdp.dkrproj[i][3][1], rdp.dkrproj[i][3][2], rdp.dkrproj[i][3][3]);
}
#endif
}
static void uc5_vertex ()
{
uint32_t addr = dma_offset_vtx + (segoffset(rdp.cmd1) & BMASK);
// | cccc cccc 1111 1??? 0000 0002 2222 2222 | cmd1 = address |
// c = vtx command
// 1 = method #1 of getting count
// 2 = method #2 of getting count
// ? = unknown, but used
// 0 = unused
int n = ((rdp.cmd0 >> 19) & 0x1F);// + 1;
if (settings.hacks&hack_Diddy)
n++;
if (rdp.cmd0 & 0x00010000)
{
if (billboarding)
vtx_last = 1;
}
else
dma_offset_mtx = rdp.cmd0 & 0x00FFFFFF;
dma_offset_vtx = rdp.cmd1 & 0x00FFFFFF;
vtx_last = 0;
int first = ((rdp.cmd0 >> 9) & 0x1F) + vtx_last;
FRDP ("uc5:vertex - addr: %08lx, first: %d, count: %d, matrix: %08lx\n", addr, first, n, cur_mtx);
int prj = cur_mtx;
int start = 0;
float x, y, z;
for (int i=first; i<first+n; i++)
{
start = (i-first) * 10;
VERTEX *v = &rdp.vtx[i];
x = (float)((short*)gfx.RDRAM)[(((addr+start) >> 1) + 0)^1];
y = (float)((short*)gfx.RDRAM)[(((addr+start) >> 1) + 1)^1];
z = (float)((short*)gfx.RDRAM)[(((addr+start) >> 1) + 2)^1];
v->x = x*rdp.dkrproj[prj][0][0] + y*rdp.dkrproj[prj][1][0] + z*rdp.dkrproj[prj][2][0] + rdp.dkrproj[prj][3][0];
v->y = x*rdp.dkrproj[prj][0][1] + y*rdp.dkrproj[prj][1][1] + z*rdp.dkrproj[prj][2][1] + rdp.dkrproj[prj][3][1];
v->z = x*rdp.dkrproj[prj][0][2] + y*rdp.dkrproj[prj][1][2] + z*rdp.dkrproj[prj][2][2] + rdp.dkrproj[prj][3][2];
v->w = x*rdp.dkrproj[prj][0][3] + y*rdp.dkrproj[prj][1][3] + z*rdp.dkrproj[prj][2][3] + rdp.dkrproj[prj][3][3];
if (billboarding)
{
v->x += rdp.vtx[0].x;
v->y += rdp.vtx[0].y;
v->z += rdp.vtx[0].z;
v->w += rdp.vtx[0].w;
}
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
if (fabs(v->z_w) > 1.0) v->scr_off |= 32;
v->r = ((uint8_t*)gfx.RDRAM)[(addr+start + 6)^3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr+start + 7)^3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr+start + 8)^3];
v->a = ((uint8_t*)gfx.RDRAM)[(addr+start + 9)^3];
CalculateFog (v);
#ifdef EXTREME_LOGGING
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, z_w: %f, r=%d, g=%d, b=%d, a=%d\n", i, v->x, v->y, v->z, v->w, v->z_w, v->r, v->g, v->b, v->a);
#endif
}
vtx_last += n;
FRDP("uc5:dma_offsets - mtx: %08lx, vtx: %08lx\n", dma_offset_mtx, dma_offset_vtx);
}
static void uc5_tridma ()
static void uc5_matrix()
{
vtx_last = 0; // we've drawn something, so the vertex index needs resetting
if (rdp.skip_drawing)
return;
// Use segment offset to get the address
uint32_t addr = dma_offset_mtx + (segoffset(rdp.cmd1) & BMASK);
// | cccc cccc 2222 0000 1111 1111 1111 0000 | cmd1 = address |
// c = tridma command
// 1 = method #1 of getting count
// 2 = method #2 of getting count
// 0 = unused
uint8_t n = (uint8_t)((rdp.cmd0 >> 16) & 0xF);
uint8_t multiply;
uint32_t addr = segoffset(rdp.cmd1) & BMASK;
int num = (rdp.cmd0 & 0xFFF0) >> 4;
//int num = ((rdp.cmd0 & 0x00F00000) >> 20) + 1; // same thing!
FRDP("uc5:tridma #%d - addr: %08lx, count: %d\n", rdp.tri_n, addr, num);
int start, v0, v1, v2, flags;
for (int i=0; i<num; i++)
{
start = i << 4;
v0 = gfx.RDRAM[addr+start];
v1 = gfx.RDRAM[addr+start+1];
v2 = gfx.RDRAM[addr+start+2];
FRDP("tri #%d - %d, %d, %d\n", rdp.tri_n, v0, v1, v2);
VERTEX *v[3] = {
&rdp.vtx[v0],
&rdp.vtx[v1],
&rdp.vtx[v2]
};
flags = gfx.RDRAM[addr+start+3];
if (flags & 0x40) { // no cull
rdp.flags &= ~CULLMASK;
grCullMode (GR_CULL_DISABLE);
if (n == 0) //DKR
{
n = (uint8_t)((rdp.cmd0 >> 22) & 0x3);
multiply = 0;
}
else { // front cull
rdp.flags &= ~CULLMASK;
if (rdp.view_scale[0] < 0) {
rdp.flags |= CULL_BACK; // agh, backwards culling
grCullMode (GR_CULL_POSITIVE);
}
else {
rdp.flags |= CULL_FRONT;
grCullMode (GR_CULL_NEGATIVE);
}
else //JF
{
multiply = (uint8_t)((rdp.cmd0 >> 23) & 0x1);
}
start += 4;
v[0]->ou = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 5] / 32.0f;
v[0]->ov = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 4] / 32.0f;
v[1]->ou = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 3] / 32.0f;
v[1]->ov = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 2] / 32.0f;
v[2]->ou = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 1] / 32.0f;
v[2]->ov = (float)((short*)gfx.RDRAM)[((addr+start) >> 1) + 0] / 32.0f;
cur_mtx = n;
v[0]->uv_calculated = 0xFFFFFFFF;
v[1]->uv_calculated = 0xFFFFFFFF;
v[2]->uv_calculated = 0xFFFFFFFF;
FRDP("uc5:matrix - #%d, addr: %08lx\n", n, addr);
if (cull_tri(v))
rdp.tri_n ++;
if (multiply)
{
DECLAREALIGN16VAR(m[4][4]);
load_matrix(m, addr);
DECLAREALIGN16VAR(m_src[4][4]);
memcpy(m_src, rdp.dkrproj[0], 64);
MulMatrices(m, m_src, rdp.dkrproj[n]);
}
else
{
update ();
draw_tri (v);
rdp.tri_n ++;
load_matrix(rdp.dkrproj[n], addr);
}
}
rdp.update |= UPDATE_MULT_MAT;
#ifdef EXTREME_LOGGING
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][0][0], rdp.dkrproj[n][0][1], rdp.dkrproj[n][0][2], rdp.dkrproj[n][0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][1][0], rdp.dkrproj[n][1][1], rdp.dkrproj[n][1][2], rdp.dkrproj[n][1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][2][0], rdp.dkrproj[n][2][1], rdp.dkrproj[n][2][2], rdp.dkrproj[n][2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[n][3][0], rdp.dkrproj[n][3][1], rdp.dkrproj[n][3][2], rdp.dkrproj[n][3][3]);
for (int i=0; i<3; i++)
{
FRDP ("proj %d\n", i);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][0][0], rdp.dkrproj[i][0][1], rdp.dkrproj[i][0][2], rdp.dkrproj[i][0][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][1][0], rdp.dkrproj[i][1][1], rdp.dkrproj[i][1][2], rdp.dkrproj[i][1][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][2][0], rdp.dkrproj[i][2][1], rdp.dkrproj[i][2][2], rdp.dkrproj[i][2][3]);
FRDP ("{%f,%f,%f,%f}\n", rdp.dkrproj[i][3][0], rdp.dkrproj[i][3][1], rdp.dkrproj[i][3][2], rdp.dkrproj[i][3][3]);
}
#endif
}
static void uc5_dl_in_mem ()
static void uc5_vertex()
{
uint32_t addr = segoffset(rdp.cmd1) & BMASK;
int count = (rdp.cmd0 & 0x00FF0000) >> 16;
FRDP ("uc5:dl_in_mem - addr: %08lx, count: %d\n", addr, count);
uint32_t addr = dma_offset_vtx + (segoffset(rdp.cmd1) & BMASK);
if (rdp.pc_i >= 9) {
RDP_E ("** DL stack overflow **\n");
LRDP("** DL stack overflow **\n");
return;
}
rdp.pc_i ++; // go to the next PC in the stack
rdp.pc[rdp.pc_i] = addr; // jump to the address
rdp.dl_count = count + 1;
// | cccc cccc 1111 1??? 0000 0002 2222 2222 | cmd1 = address |
// c = vtx command
// 1 = method #1 of getting count
// 2 = method #2 of getting count
// ? = unknown, but used
// 0 = unused
int n = ((rdp.cmd0 >> 19) & 0x1F);// + 1;
if (settings.hacks&hack_Diddy)
n++;
if (rdp.cmd0 & 0x00010000)
{
if (billboarding)
vtx_last = 1;
}
else
vtx_last = 0;
int first = ((rdp.cmd0 >> 9) & 0x1F) + vtx_last;
FRDP("uc5:vertex - addr: %08lx, first: %d, count: %d, matrix: %08lx\n", addr, first, n, cur_mtx);
int prj = cur_mtx;
int start = 0;
float x, y, z;
for (int i = first; i < first + n; i++)
{
start = (i - first) * 10;
VERTEX *v = &rdp.vtx[i];
x = (float)((short*)gfx.RDRAM)[(((addr + start) >> 1) + 0) ^ 1];
y = (float)((short*)gfx.RDRAM)[(((addr + start) >> 1) + 1) ^ 1];
z = (float)((short*)gfx.RDRAM)[(((addr + start) >> 1) + 2) ^ 1];
v->x = x*rdp.dkrproj[prj][0][0] + y*rdp.dkrproj[prj][1][0] + z*rdp.dkrproj[prj][2][0] + rdp.dkrproj[prj][3][0];
v->y = x*rdp.dkrproj[prj][0][1] + y*rdp.dkrproj[prj][1][1] + z*rdp.dkrproj[prj][2][1] + rdp.dkrproj[prj][3][1];
v->z = x*rdp.dkrproj[prj][0][2] + y*rdp.dkrproj[prj][1][2] + z*rdp.dkrproj[prj][2][2] + rdp.dkrproj[prj][3][2];
v->w = x*rdp.dkrproj[prj][0][3] + y*rdp.dkrproj[prj][1][3] + z*rdp.dkrproj[prj][2][3] + rdp.dkrproj[prj][3][3];
if (billboarding)
{
v->x += rdp.vtx[0].x;
v->y += rdp.vtx[0].y;
v->z += rdp.vtx[0].z;
v->w += rdp.vtx[0].w;
}
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
if (fabs(v->z_w) > 1.0) v->scr_off |= 32;
v->r = ((uint8_t*)gfx.RDRAM)[(addr + start + 6) ^ 3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr + start + 7) ^ 3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr + start + 8) ^ 3];
v->a = ((uint8_t*)gfx.RDRAM)[(addr + start + 9) ^ 3];
CalculateFog(v);
#ifdef EXTREME_LOGGING
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, z_w: %f, r=%d, g=%d, b=%d, a=%d\n", i, v->x, v->y, v->z, v->w, v->z_w, v->r, v->g, v->b, v->a);
#endif
}
vtx_last += n;
}
static void uc5_tridma()
{
vtx_last = 0; // we've drawn something, so the vertex index needs resetting
if (rdp.skip_drawing)
return;
// | cccc cccc 2222 0000 1111 1111 1111 0000 | cmd1 = address |
// c = tridma command
// 1 = method #1 of getting count
// 2 = method #2 of getting count
// 0 = unused
uint32_t addr = segoffset(rdp.cmd1) & BMASK;
int num = (rdp.cmd0 & 0xFFF0) >> 4;
//int num = ((rdp.cmd0 & 0x00F00000) >> 20) + 1; // same thing!
FRDP("uc5:tridma #%d - addr: %08lx, count: %d\n", rdp.tri_n, addr, num);
int start, v0, v1, v2, flags;
for (int i = 0; i < num; i++)
{
start = i << 4;
v0 = gfx.RDRAM[addr + start];
v1 = gfx.RDRAM[addr + start + 1];
v2 = gfx.RDRAM[addr + start + 2];
FRDP("tri #%d - %d, %d, %d\n", rdp.tri_n, v0, v1, v2);
VERTEX *v[3] = {
&rdp.vtx[v0],
&rdp.vtx[v1],
&rdp.vtx[v2]
};
flags = gfx.RDRAM[addr + start + 3];
if (flags & 0x40) { // no cull
rdp.flags &= ~CULLMASK;
grCullMode(GR_CULL_DISABLE);
}
else { // front cull
rdp.flags &= ~CULLMASK;
if (rdp.view_scale[0] < 0) {
rdp.flags |= CULL_BACK; // agh, backwards culling
grCullMode(GR_CULL_POSITIVE);
}
else {
rdp.flags |= CULL_FRONT;
grCullMode(GR_CULL_NEGATIVE);
}
}
start += 4;
v[0]->ou = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 5] / 32.0f;
v[0]->ov = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 4] / 32.0f;
v[1]->ou = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 3] / 32.0f;
v[1]->ov = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 2] / 32.0f;
v[2]->ou = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 1] / 32.0f;
v[2]->ov = (float)((short*)gfx.RDRAM)[((addr + start) >> 1) + 0] / 32.0f;
v[0]->uv_calculated = 0xFFFFFFFF;
v[1]->uv_calculated = 0xFFFFFFFF;
v[2]->uv_calculated = 0xFFFFFFFF;
if (cull_tri(v))
rdp.tri_n++;
else
{
update();
draw_tri(v);
rdp.tri_n++;
}
}
}
static void uc5_dl_in_mem()
{
uint32_t addr = segoffset(rdp.cmd1) & BMASK;
int count = (rdp.cmd0 & 0x00FF0000) >> 16;
FRDP("uc5:dl_in_mem - addr: %08lx, count: %d\n", addr, count);
if (rdp.pc_i >= 9) {
RDP_E("** DL stack overflow **\n");
LRDP("** DL stack overflow **\n");
return;
}
rdp.pc_i++; // go to the next PC in the stack
rdp.pc[rdp.pc_i] = addr; // jump to the address
rdp.dl_count = count + 1;
}
static void uc5_moveword()
{
LRDP("uc5:moveword ");
LRDP("uc5:moveword ");
// Find which command this is (lowest byte of cmd0)
switch (rdp.cmd0 & 0xFF)
{
case 0x02: // moveword matrix 2 billboard
billboarding = (rdp.cmd1 & 1);
FRDP ("matrix billboard - %s\n", str_offon[billboarding]);
break;
case 0x04: // clip (verified same)
if (((rdp.cmd0>>8)&0xFFFF) == 0x04)
// Find which command this is (lowest byte of cmd0)
switch (rdp.cmd0 & 0xFF)
{
rdp.clip_ratio = sqrt((float)rdp.cmd1);
rdp.update |= UPDATE_VIEWPORT;
}
FRDP ("clip %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
break;
case 0x02: // moveword matrix 2 billboard
billboarding = (rdp.cmd1 & 1);
FRDP("matrix billboard - %s\n", str_offon[billboarding]);
break;
case 0x06: // segment (verified same)
FRDP ("segment: %08lx -> seg%d\n", rdp.cmd1, (rdp.cmd0 >> 10) & 0x0F);
rdp.segment[(rdp.cmd0 >> 10) & 0x0F] = rdp.cmd1;
break;
case 0x04: // clip (verified same)
if (((rdp.cmd0 >> 8) & 0xFFFF) == 0x04)
{
rdp.clip_ratio = sqrt((float)rdp.cmd1);
rdp.update |= UPDATE_VIEWPORT;
}
FRDP("clip %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
break;
case 0x08:
case 0x06: // segment (verified same)
FRDP("segment: %08lx -> seg%d\n", rdp.cmd1, (rdp.cmd0 >> 10) & 0x0F);
rdp.segment[(rdp.cmd0 >> 10) & 0x0F] = rdp.cmd1;
break;
case 0x08:
{
rdp.fog_multiplier = (short)(rdp.cmd1 >> 16);
rdp.fog_offset = (short)(rdp.cmd1 & 0x0000FFFF);
FRDP ("fog: multiplier: %f, offset: %f\n", rdp.fog_multiplier, rdp.fog_offset);
// rdp.update |= UPDATE_FOG_ENABLED;
rdp.fog_multiplier = (short)(rdp.cmd1 >> 16);
rdp.fog_offset = (short)(rdp.cmd1 & 0x0000FFFF);
FRDP("fog: multiplier: %f, offset: %f\n", rdp.fog_multiplier, rdp.fog_offset);
// rdp.update |= UPDATE_FOG_ENABLED;
}
break;
case 0x0a: // moveword matrix select
cur_mtx = (rdp.cmd1 >> 6) & 3;
FRDP ("matrix select - mtx: %d\n", cur_mtx);
break;
case 0x0a: // moveword matrix select
cur_mtx = (rdp.cmd1 >> 6) & 3;
FRDP("matrix select - mtx: %d\n", cur_mtx);
break;
default:
FRDP ("(unknown) %02lx - IGNORED\n", rdp.cmd0&0xFF);
}
default:
FRDP("(unknown) %02lx - IGNORED\n", rdp.cmd0 & 0xFF);
}
}
static void uc5_setgeometrymode()
{
FRDP("uc0:setgeometrymode %08lx\n", rdp.cmd1);
FRDP("uc0:setgeometrymode %08lx\n", rdp.cmd1);
rdp.geom_mode |= rdp.cmd1;
rdp.geom_mode |= rdp.cmd1;
if (rdp.cmd1 & 0x00000001) // Z-Buffer enable
{
if (!(rdp.flags & ZBUF_ENABLED))
if (rdp.cmd1 & 0x00000001) // Z-Buffer enable
{
rdp.flags |= ZBUF_ENABLED;
rdp.update |= UPDATE_ZBUF_ENABLED;
if (!(rdp.flags & ZBUF_ENABLED))
{
rdp.flags |= ZBUF_ENABLED;
rdp.update |= UPDATE_ZBUF_ENABLED;
}
}
}
//Added by Gonetz
if (rdp.cmd1 & 0x00010000) // Fog enable
{
if (!(rdp.flags & FOG_ENABLED))
//Added by Gonetz
if (rdp.cmd1 & 0x00010000) // Fog enable
{
rdp.flags |= FOG_ENABLED;
rdp.update |= UPDATE_FOG_ENABLED;
if (!(rdp.flags & FOG_ENABLED))
{
rdp.flags |= FOG_ENABLED;
rdp.update |= UPDATE_FOG_ENABLED;
}
}
}
}
static void uc5_cleargeometrymode()
{
FRDP("uc0:cleargeometrymode %08lx\n", rdp.cmd1);
FRDP("uc0:cleargeometrymode %08lx\n", rdp.cmd1);
rdp.geom_mode &= (~rdp.cmd1);
rdp.geom_mode &= (~rdp.cmd1);
if (rdp.cmd1 & 0x00000001) // Z-Buffer enable
{
if (rdp.flags & ZBUF_ENABLED)
if (rdp.cmd1 & 0x00000001) // Z-Buffer enable
{
rdp.flags ^= ZBUF_ENABLED;
rdp.update |= UPDATE_ZBUF_ENABLED;
if (rdp.flags & ZBUF_ENABLED)
{
rdp.flags ^= ZBUF_ENABLED;
rdp.update |= UPDATE_ZBUF_ENABLED;
}
}
}
//Added by Gonetz
if (rdp.cmd1 & 0x00010000) // Fog enable
{
if (rdp.flags & FOG_ENABLED)
//Added by Gonetz
if (rdp.cmd1 & 0x00010000) // Fog enable
{
rdp.flags ^= FOG_ENABLED;
rdp.update |= UPDATE_FOG_ENABLED;
if (rdp.flags & FOG_ENABLED)
{
rdp.flags ^= FOG_ENABLED;
rdp.update |= UPDATE_FOG_ENABLED;
}
}
}
}

View File

@ -45,135 +45,131 @@
uint32_t pd_col_addr = 0;
static void uc7_colorbase ()
static void uc7_colorbase()
{
LRDP("uc7_colorbase\n");
pd_col_addr = segoffset(rdp.cmd1);
LRDP("uc7_colorbase\n");
pd_col_addr = segoffset(rdp.cmd1);
}
typedef struct
typedef struct
{
short y;
short x;
uint16_t idx;
short y;
short x;
uint16_t idx;
short z;
short t;
short s;
short z;
short t;
short s;
} vtx_uc7;
static void uc7_vertex ()
static void uc7_vertex()
{
if (rdp.update & UPDATE_MULT_MAT)
{
rdp.update ^= UPDATE_MULT_MAT;
MulMatrices(rdp.model, rdp.proj, rdp.combined);
}
// This is special, not handled in update()
if (rdp.update & UPDATE_LIGHTS)
{
rdp.update ^= UPDATE_LIGHTS;
// Calculate light vectors
for (uint32_t l=0; l<rdp.num_lights; l++)
if (rdp.update & UPDATE_MULT_MAT)
{
InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
NormalizeVector (rdp.light_vector[l]);
rdp.update ^= UPDATE_MULT_MAT;
MulMatrices(rdp.model, rdp.proj, rdp.combined);
}
}
uint32_t addr = segoffset(rdp.cmd1);
uint32_t v0, i, n;
float x, y, z;
rdp.v0 = v0 = (rdp.cmd0 & 0x0F0000) >> 16;
rdp.vn = n = ((rdp.cmd0 & 0xF00000) >> 20) + 1;
FRDP ("uc7:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
vtx_uc7 *vertex = (vtx_uc7 *)&gfx.RDRAM[addr];
for(i = 0; i < n; i++)
{
VERTEX *v = &rdp.vtx[v0 + i];
x = (float)vertex->x;
y = (float)vertex->y;
z = (float)vertex->z;
v->flags = 0;
v->ou = (float)vertex->s;
v->ov = (float)vertex->t;
v->uv_scaled = 0;
#ifdef EXTREME_LOGGING
// FRDP ("before: v%d - x: %f, y: %f, z: %f, flags: %04lx, ou: %f, ov: %f\n", i>>4, x, y, z, v->flags, v->ou, v->ov);
#endif
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
uint8_t *color = &gfx.RDRAM[pd_col_addr + (vertex->idx & 0xff)];
v->a = color[0];
CalculateFog (v);
if (rdp.geom_mode & 0x00020000)
// This is special, not handled in update()
if (rdp.update & UPDATE_LIGHTS)
{
v->vec[0] = (char)color[3];
v->vec[1] = (char)color[2];
v->vec[2] = (char)color[1];
rdp.update ^= UPDATE_LIGHTS;
if (rdp.geom_mode & 0x80000)
{
calc_linear (v);
#ifdef EXTREME_LOGGING
FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
}
else if (rdp.geom_mode & 0x40000)
{
calc_sphere (v);
#ifdef EXTREME_LOGGING
FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
}
NormalizeVector (v->vec);
calc_light (v);
// Calculate light vectors
for (uint32_t l = 0; l < rdp.num_lights; l++)
{
InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
NormalizeVector(rdp.light_vector[l]);
}
}
else
uint32_t addr = segoffset(rdp.cmd1);
uint32_t v0, i, n;
float x, y, z;
rdp.v0 = v0 = (rdp.cmd0 & 0x0F0000) >> 16;
rdp.vn = n = ((rdp.cmd0 & 0xF00000) >> 20) + 1;
FRDP("uc7:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
vtx_uc7 *vertex = (vtx_uc7 *)&gfx.RDRAM[addr];
for (i = 0; i < n; i++)
{
v->r = color[3];
v->g = color[2];
v->b = color[1];
}
#ifdef EXTREME_LOGGING
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f\n", i>>4, v->x, v->y, v->z, v->w, v->ou, v->ov);
#endif
vertex++;
}
}
VERTEX *v = &rdp.vtx[v0 + i];
x = (float)vertex->x;
y = (float)vertex->y;
z = (float)vertex->z;
v->flags = 0;
v->ou = (float)vertex->s;
v->ov = (float)vertex->t;
v->uv_scaled = 0;
#ifdef EXTREME_LOGGING
// FRDP ("before: v%d - x: %f, y: %f, z: %f, flags: %04lx, ou: %f, ov: %f\n", i>>4, x, y, z, v->flags, v->ou, v->ov);
#endif
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
uint8_t *color = &gfx.RDRAM[pd_col_addr + (vertex->idx & 0xff)];
v->a = color[0];
CalculateFog(v);
if (rdp.geom_mode & 0x00020000)
{
v->vec[0] = (char)color[3];
v->vec[1] = (char)color[2];
v->vec[2] = (char)color[1];
if (rdp.geom_mode & 0x80000)
{
calc_linear(v);
#ifdef EXTREME_LOGGING
FRDP("calc linear: v%d - u: %f, v: %f\n", i >> 4, v->ou, v->ov);
#endif
}
else if (rdp.geom_mode & 0x40000)
{
calc_sphere(v);
#ifdef EXTREME_LOGGING
FRDP("calc sphere: v%d - u: %f, v: %f\n", i >> 4, v->ou, v->ov);
#endif
}
NormalizeVector(v->vec);
calc_light(v);
}
else
{
v->r = color[3];
v->g = color[2];
v->b = color[1];
}
#ifdef EXTREME_LOGGING
FRDP("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f\n", i >> 4, v->x, v->y, v->z, v->w, v->ou, v->ov);
#endif
vertex++;
}
}

View File

@ -44,503 +44,500 @@
uint32_t uc8_normale_addr = 0;
float uc8_coord_mod[16];
static void uc8_vertex ()
static void uc8_vertex()
{
if (rdp.update & UPDATE_MULT_MAT)
{
rdp.update ^= UPDATE_MULT_MAT;
MulMatrices(rdp.model, rdp.proj, rdp.combined);
}
if (rdp.update & UPDATE_MULT_MAT)
{
rdp.update ^= UPDATE_MULT_MAT;
MulMatrices(rdp.model, rdp.proj, rdp.combined);
}
uint32_t addr = segoffset(rdp.cmd1);
int v0, i, n;
float x, y, z;
uint32_t addr = segoffset(rdp.cmd1);
int v0, i, n;
float x, y, z;
rdp.vn = n = (rdp.cmd0 >> 12) & 0xFF;
rdp.v0 = v0 = ((rdp.cmd0 >> 1) & 0x7F) - n;
rdp.vn = n = (rdp.cmd0 >> 12) & 0xFF;
rdp.v0 = v0 = ((rdp.cmd0 >> 1) & 0x7F) - n;
FRDP ("uc8:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
FRDP("uc8:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
if (v0 < 0)
{
RDP_E ("** ERROR: uc2:vertex v0 < 0\n");
LRDP("** ERROR: uc2:vertex v0 < 0\n");
return;
}
//*
// This is special, not handled in update()
if (rdp.update & UPDATE_LIGHTS)
{
rdp.update ^= UPDATE_LIGHTS;
if (v0 < 0)
{
RDP_E("** ERROR: uc2:vertex v0 < 0\n");
LRDP("** ERROR: uc2:vertex v0 < 0\n");
return;
}
//*
// This is special, not handled in update()
if (rdp.update & UPDATE_LIGHTS)
{
rdp.update ^= UPDATE_LIGHTS;
// Calculate light vectors
for (uint32_t l=0; l<rdp.num_lights; l++)
{
InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
NormalizeVector (rdp.light_vector[l]);
// Calculate light vectors
for (uint32_t l = 0; l < rdp.num_lights; l++)
{
InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
NormalizeVector(rdp.light_vector[l]);
#ifdef EXTREME_LOGGING
FRDP("light_vector[%d] x: %f, y: %f, z: %f\n", l, rdp.light_vector[l][0], rdp.light_vector[l][1], rdp.light_vector[l][2]);
FRDP("light_vector[%d] x: %f, y: %f, z: %f\n", l, rdp.light_vector[l][0], rdp.light_vector[l][1], rdp.light_vector[l][2]);
#endif
}
}
//*/
for (i=0; i < (n<<4); i+=16)
{
VERTEX *v = &rdp.vtx[v0 + (i>>4)];
x = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 0)^1];
y = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 1)^1];
z = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 2)^1];
v->flags = ((uint16_t*)gfx.RDRAM)[(((addr+i) >> 1) + 3)^1];
v->ou = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 4)^1];
v->ov = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 5)^1];
}
}
//*/
for (i = 0; i < (n << 4); i += 16)
{
VERTEX *v = &rdp.vtx[v0 + (i >> 4)];
x = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 0) ^ 1];
y = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 1) ^ 1];
z = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 2) ^ 1];
v->flags = ((uint16_t*)gfx.RDRAM)[(((addr + i) >> 1) + 3) ^ 1];
v->ou = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 4) ^ 1];
v->ov = (float)((short*)gfx.RDRAM)[(((addr + i) >> 1) + 5) ^ 1];
v->uv_scaled = 0;
v->a = ((uint8_t*)gfx.RDRAM)[(addr+i + 15)^3];
v->a = ((uint8_t*)gfx.RDRAM)[(addr + i + 15) ^ 3];
#ifdef EXTREME_LOGGING
FRDP ("before v%d - x: %f, y: %f, z: %f\n", i>>4, x, y, z);
FRDP ("before v%d - x: %f, y: %f, z: %f\n", i>>4, x, y, z);
#endif
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
#ifdef EXTREME_LOGGING
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f, flags: %d\n", i>>4, v->x, v->y, v->z, v->w, v->ou, v->ov, v->flags);
FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f, flags: %d\n", i>>4, v->x, v->y, v->z, v->w, v->ou, v->ov, v->flags);
#endif
if (fabs(v->w) < 0.001) v->w = 0.001f;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->oow = 1.0f / v->w;
v->x_w = v->x * v->oow;
v->y_w = v->y * v->oow;
v->z_w = v->z * v->oow;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->uv_calculated = 0xFFFFFFFF;
v->screen_translated = 0;
v->shade_mod = 0;
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
///*
v->r = ((uint8_t*)gfx.RDRAM)[(addr+i + 12)^3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr+i + 13)^3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr+i + 14)^3];
v->scr_off = 0;
if (v->x < -v->w) v->scr_off |= 1;
if (v->x > v->w) v->scr_off |= 2;
if (v->y < -v->w) v->scr_off |= 4;
if (v->y > v->w) v->scr_off |= 8;
if (v->w < 0.1f) v->scr_off |= 16;
///*
v->r = ((uint8_t*)gfx.RDRAM)[(addr + i + 12) ^ 3];
v->g = ((uint8_t*)gfx.RDRAM)[(addr + i + 13) ^ 3];
v->b = ((uint8_t*)gfx.RDRAM)[(addr + i + 14) ^ 3];
#ifdef EXTREME_LOGGING
FRDP ("r: %02lx, g: %02lx, b: %02lx, a: %02lx\n", v->r, v->g, v->b, v->a);
FRDP ("r: %02lx, g: %02lx, b: %02lx, a: %02lx\n", v->r, v->g, v->b, v->a);
#endif
if ((rdp.geom_mode & 0x00020000))
{
uint32_t shift = v0 << 1;
v->vec[0] = ((char*)gfx.RDRAM)[(uc8_normale_addr + (i>>3) + shift + 0)^3];
v->vec[1] = ((char*)gfx.RDRAM)[(uc8_normale_addr + (i>>3) + shift + 1)^3];
v->vec[2] = (char)(v->flags&0xff);
if (rdp.geom_mode & 0x80000)
{
calc_linear (v);
#ifdef EXTREME_LOGGING
FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
}
else if (rdp.geom_mode & 0x40000)
{
calc_sphere (v);
#ifdef EXTREME_LOGGING
FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
}
// FRDP("calc light. r: 0x%02lx, g: 0x%02lx, b: 0x%02lx, nx: %.3f, ny: %.3f, nz: %.3f\n", v->r, v->g, v->b, v->vec[0], v->vec[1], v->vec[2]);
FRDP("v[%d] calc light. r: 0x%02lx, g: 0x%02lx, b: 0x%02lx\n", i>>4, v->r, v->g, v->b);
float color[3] = {rdp.light[rdp.num_lights].r, rdp.light[rdp.num_lights].g, rdp.light[rdp.num_lights].b};
FRDP("ambient light. r: %f, g: %f, b: %f\n", color[0], color[1], color[2]);
float light_intensity = 0.0f;
uint32_t l;
if (rdp.geom_mode & 0x00400000)
{
NormalizeVector (v->vec);
for (l = 0; l < rdp.num_lights-1; l++)
if ((rdp.geom_mode & 0x00020000))
{
if (!rdp.light[l].nonblack)
continue;
light_intensity = DotProduct (rdp.light_vector[l], v->vec);
FRDP("light %d, intensity : %f\n", l, light_intensity);
if (light_intensity < 0.0f)
continue;
//*
if (rdp.light[l].ca > 0.0f)
{
float vx = (v->x + uc8_coord_mod[8])*uc8_coord_mod[12] - rdp.light[l].x;
float vy = (v->y + uc8_coord_mod[9])*uc8_coord_mod[13] - rdp.light[l].y;
float vz = (v->z + uc8_coord_mod[10])*uc8_coord_mod[14] - rdp.light[l].z;
float vw = (v->w + uc8_coord_mod[11])*uc8_coord_mod[15] - rdp.light[l].w;
float len = (vx*vx+vy*vy+vz*vz+vw*vw)/65536.0f;
float p_i = rdp.light[l].ca / len;
if (p_i > 1.0f) p_i = 1.0f;
light_intensity *= p_i;
FRDP("light %d, len: %f, p_intensity : %f\n", l, len, p_i);
}
//*/
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
light_intensity = DotProduct (rdp.light_vector[l], v->vec);
FRDP("light %d, intensity : %f\n", l, light_intensity);
if (light_intensity > 0.0f)
{
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
}
FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
else
{
for (l = 0; l < rdp.num_lights; l++)
{
if (rdp.light[l].nonblack && rdp.light[l].nonzero)
{
float vx = (v->x + uc8_coord_mod[8])*uc8_coord_mod[12] - rdp.light[l].x;
float vy = (v->y + uc8_coord_mod[9])*uc8_coord_mod[13] - rdp.light[l].y;
float vz = (v->z + uc8_coord_mod[10])*uc8_coord_mod[14] - rdp.light[l].z;
float vw = (v->w + uc8_coord_mod[11])*uc8_coord_mod[15] - rdp.light[l].w;
float len = (vx*vx+vy*vy+vz*vz+vw*vw)/65536.0f;
light_intensity = rdp.light[l].ca / len;
if (light_intensity > 1.0f) light_intensity = 1.0f;
FRDP("light %d, p_intensity : %f\n", l, light_intensity);
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
//FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
}
}
if (color[0] > 1.0f) color[0] = 1.0f;
if (color[1] > 1.0f) color[1] = 1.0f;
if (color[2] > 1.0f) color[2] = 1.0f;
v->r = (uint8_t)(((float)v->r)*color[0]);
v->g = (uint8_t)(((float)v->g)*color[1]);
v->b = (uint8_t)(((float)v->b)*color[2]);
#ifdef EXTREME_LOGGING
FRDP("color after light: r: 0x%02lx, g: 0x%02lx, b: 0x%02lx\n", v->r, v->g, v->b);
#endif
}
}
}
uint32_t shift = v0 << 1;
v->vec[0] = ((char*)gfx.RDRAM)[(uc8_normale_addr + (i >> 3) + shift + 0) ^ 3];
v->vec[1] = ((char*)gfx.RDRAM)[(uc8_normale_addr + (i >> 3) + shift + 1) ^ 3];
v->vec[2] = (char)(v->flags & 0xff);
static void uc8_moveword ()
{
uint8_t index = (uint8_t)((rdp.cmd0 >> 16) & 0xFF);
uint16_t offset = (uint16_t)(rdp.cmd0 & 0xFFFF);
uint32_t data = rdp.cmd1;
FRDP ("uc8:moveword ");
switch (index)
{
// NOTE: right now it's assuming that it sets the integer part first. This could
// be easily fixed, but only if i had something to test with.
case 0x02:
rdp.num_lights = (data / 48);
rdp.update |= UPDATE_LIGHTS;
FRDP ("numlights: %d\n", rdp.num_lights);
break;
case 0x04:
if (offset == 0x04)
{
rdp.clip_ratio = sqrt((float)rdp.cmd1);
rdp.update |= UPDATE_VIEWPORT;
}
FRDP ("mw_clip %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
break;
case 0x06: // moveword SEGMENT
{
FRDP ("SEGMENT %08lx -> seg%d\n", data, offset >> 2);
rdp.segment[(offset >> 2) & 0xF] = data;
}
break;
case 0x08:
{
rdp.fog_multiplier = (short)(rdp.cmd1 >> 16);
rdp.fog_offset = (short)(rdp.cmd1 & 0x0000FFFF);
FRDP ("fog: multiplier: %f, offset: %f\n", rdp.fog_multiplier, rdp.fog_offset);
}
break;
case 0x0c:
RDP_E ("uc8:moveword forcemtx - IGNORED\n");
LRDP("forcemtx - IGNORED\n");
break;
case 0x0e:
LRDP("perspnorm - IGNORED\n");
break;
case 0x10: // moveword coord mod
{
uint8_t n = offset >> 2;
FRDP ("coord mod:%d, %08lx\n", n, data);
if (rdp.cmd0&8)
return;
uint32_t idx = (rdp.cmd0>>1)&3;
uint32_t pos = rdp.cmd0&0x30;
if (pos == 0)
{
uc8_coord_mod[0+idx] = (short)(rdp.cmd1>>16);
uc8_coord_mod[1+idx] = (short)(rdp.cmd1&0xffff);
}
else if (pos == 0x10)
{
uc8_coord_mod[4+idx] = (rdp.cmd1>>16)/65536.0f;
uc8_coord_mod[5+idx] = (rdp.cmd1&0xffff)/65536.0f;
uc8_coord_mod[12+idx] = uc8_coord_mod[0+idx] + uc8_coord_mod[4+idx];
uc8_coord_mod[13+idx] = uc8_coord_mod[1+idx] + uc8_coord_mod[5+idx];
}
else if (pos == 0x20)
{
uc8_coord_mod[8+idx] = (short)(rdp.cmd1>>16);
uc8_coord_mod[9+idx] = (short)(rdp.cmd1&0xffff);
#ifdef EXTREME_LOGGING
if (idx)
{
for (int k = 8; k < 16; k++)
{
FRDP("coord_mod[%d]=%f\n", k, uc8_coord_mod[k]);
}
}
#endif
}
}
break;
default:
FRDP_E("uc8:moveword unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
FRDP ("unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
}
}
static void uc8_movemem ()
{
int idx = rdp.cmd0 & 0xFF;
uint32_t addr = segoffset(rdp.cmd1);
int ofs = (rdp.cmd0 >> 5) & 0x3FFF;
FRDP ("uc8:movemem ofs:%d ", ofs);
switch (idx)
{
case 8: // VIEWPORT
{
uint32_t a = addr >> 1;
short scale_x = ((short*)gfx.RDRAM)[(a+0)^1] >> 2;
short scale_y = ((short*)gfx.RDRAM)[(a+1)^1] >> 2;
short scale_z = ((short*)gfx.RDRAM)[(a+2)^1];
short trans_x = ((short*)gfx.RDRAM)[(a+4)^1] >> 2;
short trans_y = ((short*)gfx.RDRAM)[(a+5)^1] >> 2;
short trans_z = ((short*)gfx.RDRAM)[(a+6)^1];
rdp.view_scale[0] = scale_x * rdp.scale_x;
rdp.view_scale[1] = -scale_y * rdp.scale_y;
rdp.view_scale[2] = 32.0f * scale_z;
rdp.view_trans[0] = trans_x * rdp.scale_x;
rdp.view_trans[1] = trans_y * rdp.scale_y;
rdp.view_trans[2] = 32.0f * trans_z;
rdp.update |= UPDATE_VIEWPORT;
FRDP ("viewport scale(%d, %d), trans(%d, %d), from:%08lx\n", scale_x, scale_y,
trans_x, trans_y, a);
}
break;
case 10: // LIGHT
{
int n = (ofs / 48);
if (n < 2)
if (rdp.geom_mode & 0x80000)
{
char dir_x = ((char*)gfx.RDRAM)[(addr+8)^3];
rdp.lookat[n][0] = (float)(dir_x) / 127.0f;
char dir_y = ((char*)gfx.RDRAM)[(addr+9)^3];
rdp.lookat[n][1] = (float)(dir_y) / 127.0f;
char dir_z = ((char*)gfx.RDRAM)[(addr+10)^3];
rdp.lookat[n][2] = (float)(dir_z) / 127.0f;
rdp.use_lookat = TRUE;
if (n == 1)
{
if (!dir_x && !dir_y)
rdp.use_lookat = FALSE;
}
FRDP("lookat_%d (%f, %f, %f)\n", n, rdp.lookat[n][0], rdp.lookat[n][1], rdp.lookat[n][2]);
return;
calc_linear(v);
#ifdef EXTREME_LOGGING
FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
}
n -= 2;
uint8_t col = gfx.RDRAM[(addr+0)^3];
rdp.light[n].r = (float)col / 255.0f;
rdp.light[n].nonblack = col;
col = gfx.RDRAM[(addr+1)^3];
rdp.light[n].g = (float)col / 255.0f;
rdp.light[n].nonblack += col;
col = gfx.RDRAM[(addr+2)^3];
rdp.light[n].b = (float)col / 255.0f;
rdp.light[n].nonblack += col;
rdp.light[n].a = 1.0f;
rdp.light[n].dir_x = (float)(((char*)gfx.RDRAM)[(addr+8)^3]) / 127.0f;
rdp.light[n].dir_y = (float)(((char*)gfx.RDRAM)[(addr+9)^3]) / 127.0f;
rdp.light[n].dir_z = (float)(((char*)gfx.RDRAM)[(addr+10)^3]) / 127.0f;
// **
uint32_t a = addr >> 1;
rdp.light[n].x = (float)(((short*)gfx.RDRAM)[(a+16)^1]);
rdp.light[n].y = (float)(((short*)gfx.RDRAM)[(a+17)^1]);
rdp.light[n].z = (float)(((short*)gfx.RDRAM)[(a+18)^1]);
rdp.light[n].w = (float)(((short*)gfx.RDRAM)[(a+19)^1]);
rdp.light[n].nonzero = gfx.RDRAM[(addr+12)^3];
rdp.light[n].ca = (float)rdp.light[n].nonzero / 16.0f;
//rdp.light[n].la = rdp.light[n].ca * 1.0f;
else if (rdp.geom_mode & 0x40000)
{
calc_sphere(v);
#ifdef EXTREME_LOGGING
FRDP ("light: n: %d, pos: x: %f, y: %f, z: %f, w: %f, ca: %f\n",
n, rdp.light[n].x, rdp.light[n].y, rdp.light[n].z, rdp.light[n].w, rdp.light[n].ca);
FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
#endif
FRDP ("light: n: %d, r: %f, g: %f, b: %f. dir: x: %.3f, y: %.3f, z: %.3f\n",
n, rdp.light[n].r, rdp.light[n].g, rdp.light[n].b,
rdp.light[n].dir_x, rdp.light[n].dir_y, rdp.light[n].dir_z);
}
// FRDP("calc light. r: 0x%02lx, g: 0x%02lx, b: 0x%02lx, nx: %.3f, ny: %.3f, nz: %.3f\n", v->r, v->g, v->b, v->vec[0], v->vec[1], v->vec[2]);
FRDP("v[%d] calc light. r: 0x%02lx, g: 0x%02lx, b: 0x%02lx\n", i >> 4, v->r, v->g, v->b);
float color[3] = { rdp.light[rdp.num_lights].r, rdp.light[rdp.num_lights].g, rdp.light[rdp.num_lights].b };
FRDP("ambient light. r: %f, g: %f, b: %f\n", color[0], color[1], color[2]);
float light_intensity = 0.0f;
uint32_t l;
if (rdp.geom_mode & 0x00400000)
{
NormalizeVector(v->vec);
for (l = 0; l < rdp.num_lights - 1; l++)
{
if (!rdp.light[l].nonblack)
continue;
light_intensity = DotProduct(rdp.light_vector[l], v->vec);
FRDP("light %d, intensity : %f\n", l, light_intensity);
if (light_intensity < 0.0f)
continue;
//*
if (rdp.light[l].ca > 0.0f)
{
float vx = (v->x + uc8_coord_mod[8])*uc8_coord_mod[12] - rdp.light[l].x;
float vy = (v->y + uc8_coord_mod[9])*uc8_coord_mod[13] - rdp.light[l].y;
float vz = (v->z + uc8_coord_mod[10])*uc8_coord_mod[14] - rdp.light[l].z;
float vw = (v->w + uc8_coord_mod[11])*uc8_coord_mod[15] - rdp.light[l].w;
float len = (vx*vx + vy*vy + vz*vz + vw*vw) / 65536.0f;
float p_i = rdp.light[l].ca / len;
if (p_i > 1.0f) p_i = 1.0f;
light_intensity *= p_i;
FRDP("light %d, len: %f, p_intensity : %f\n", l, len, p_i);
}
//*/
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
light_intensity = DotProduct(rdp.light_vector[l], v->vec);
FRDP("light %d, intensity : %f\n", l, light_intensity);
if (light_intensity > 0.0f)
{
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
}
FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
else
{
for (l = 0; l < rdp.num_lights; l++)
{
if (rdp.light[l].nonblack && rdp.light[l].nonzero)
{
float vx = (v->x + uc8_coord_mod[8])*uc8_coord_mod[12] - rdp.light[l].x;
float vy = (v->y + uc8_coord_mod[9])*uc8_coord_mod[13] - rdp.light[l].y;
float vz = (v->z + uc8_coord_mod[10])*uc8_coord_mod[14] - rdp.light[l].z;
float vw = (v->w + uc8_coord_mod[11])*uc8_coord_mod[15] - rdp.light[l].w;
float len = (vx*vx + vy*vy + vz*vz + vw*vw) / 65536.0f;
light_intensity = rdp.light[l].ca / len;
if (light_intensity > 1.0f) light_intensity = 1.0f;
FRDP("light %d, p_intensity : %f\n", l, light_intensity);
color[0] += rdp.light[l].r * light_intensity;
color[1] += rdp.light[l].g * light_intensity;
color[2] += rdp.light[l].b * light_intensity;
//FRDP("light %d r: %f, g: %f, b: %f\n", l, color[0], color[1], color[2]);
}
}
}
if (color[0] > 1.0f) color[0] = 1.0f;
if (color[1] > 1.0f) color[1] = 1.0f;
if (color[2] > 1.0f) color[2] = 1.0f;
v->r = (uint8_t)(((float)v->r)*color[0]);
v->g = (uint8_t)(((float)v->g)*color[1]);
v->b = (uint8_t)(((float)v->b)*color[2]);
#ifdef EXTREME_LOGGING
for (int t=0; t < 24; t++)
{
FRDP ("light[%d] = 0x%04lx \n", t, ((uint16_t*)gfx.RDRAM)[(a+t)^1]);
}
FRDP("color after light: r: 0x%02lx, g: 0x%02lx, b: 0x%02lx\n", v->r, v->g, v->b);
#endif
}
break;
case 14: //Normales
{
uc8_normale_addr = segoffset(rdp.cmd1);
FRDP ("Normale - addr: %08lx\n", uc8_normale_addr);
#ifdef EXTREME_LOGGING
int i;
for (i = 0; i < 32; i++)
{
char x = ((char*)gfx.RDRAM)[uc8_normale_addr + ((i<<1) + 0)^3];
char y = ((char*)gfx.RDRAM)[uc8_normale_addr + ((i<<1) + 1)^3];
FRDP("#%d x = %d, y = %d\n", i, x, y);
}
uint32_t a = uc8_normale_addr >> 1;
for (i = 0; i < 32; i++)
{
FRDP ("n[%d] = 0x%04lx \n", i, ((uint16_t*)gfx.RDRAM)[(a+i)^1]);
}
#endif
}
break;
default:
FRDP ("uc8:movemem unknown (%d)\n", idx);
}
}
}
}
static void uc8_moveword()
{
uint8_t index = (uint8_t)((rdp.cmd0 >> 16) & 0xFF);
uint16_t offset = (uint16_t)(rdp.cmd0 & 0xFFFF);
uint32_t data = rdp.cmd1;
FRDP("uc8:moveword ");
switch (index)
{
// NOTE: right now it's assuming that it sets the integer part first. This could
// be easily fixed, but only if i had something to test with.
case 0x02:
rdp.num_lights = (data / 48);
rdp.update |= UPDATE_LIGHTS;
FRDP("numlights: %d\n", rdp.num_lights);
break;
case 0x04:
if (offset == 0x04)
{
rdp.clip_ratio = sqrt((float)rdp.cmd1);
rdp.update |= UPDATE_VIEWPORT;
}
FRDP("mw_clip %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
break;
case 0x06: // moveword SEGMENT
{
FRDP("SEGMENT %08lx -> seg%d\n", data, offset >> 2);
rdp.segment[(offset >> 2) & 0xF] = data;
}
break;
case 0x08:
{
rdp.fog_multiplier = (short)(rdp.cmd1 >> 16);
rdp.fog_offset = (short)(rdp.cmd1 & 0x0000FFFF);
FRDP("fog: multiplier: %f, offset: %f\n", rdp.fog_multiplier, rdp.fog_offset);
}
break;
case 0x0c:
RDP_E("uc8:moveword forcemtx - IGNORED\n");
LRDP("forcemtx - IGNORED\n");
break;
case 0x0e:
LRDP("perspnorm - IGNORED\n");
break;
case 0x10: // moveword coord mod
{
uint8_t n = offset >> 2;
FRDP("coord mod:%d, %08lx\n", n, data);
if (rdp.cmd0 & 8)
return;
uint32_t idx = (rdp.cmd0 >> 1) & 3;
uint32_t pos = rdp.cmd0 & 0x30;
if (pos == 0)
{
uc8_coord_mod[0 + idx] = (short)(rdp.cmd1 >> 16);
uc8_coord_mod[1 + idx] = (short)(rdp.cmd1 & 0xffff);
}
else if (pos == 0x10)
{
uc8_coord_mod[4 + idx] = (rdp.cmd1 >> 16) / 65536.0f;
uc8_coord_mod[5 + idx] = (rdp.cmd1 & 0xffff) / 65536.0f;
uc8_coord_mod[12 + idx] = uc8_coord_mod[0 + idx] + uc8_coord_mod[4 + idx];
uc8_coord_mod[13 + idx] = uc8_coord_mod[1 + idx] + uc8_coord_mod[5 + idx];
}
else if (pos == 0x20)
{
uc8_coord_mod[8 + idx] = (short)(rdp.cmd1 >> 16);
uc8_coord_mod[9 + idx] = (short)(rdp.cmd1 & 0xffff);
#ifdef EXTREME_LOGGING
if (idx)
{
for (int k = 8; k < 16; k++)
{
FRDP("coord_mod[%d]=%f\n", k, uc8_coord_mod[k]);
}
}
#endif
}
}
break;
default:
FRDP_E("uc8:moveword unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
FRDP("unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
}
}
static void uc8_movemem()
{
int idx = rdp.cmd0 & 0xFF;
uint32_t addr = segoffset(rdp.cmd1);
int ofs = (rdp.cmd0 >> 5) & 0x3FFF;
FRDP("uc8:movemem ofs:%d ", ofs);
switch (idx)
{
case 8: // VIEWPORT
{
uint32_t a = addr >> 1;
short scale_x = ((short*)gfx.RDRAM)[(a + 0) ^ 1] >> 2;
short scale_y = ((short*)gfx.RDRAM)[(a + 1) ^ 1] >> 2;
short scale_z = ((short*)gfx.RDRAM)[(a + 2) ^ 1];
short trans_x = ((short*)gfx.RDRAM)[(a + 4) ^ 1] >> 2;
short trans_y = ((short*)gfx.RDRAM)[(a + 5) ^ 1] >> 2;
short trans_z = ((short*)gfx.RDRAM)[(a + 6) ^ 1];
rdp.view_scale[0] = scale_x * rdp.scale_x;
rdp.view_scale[1] = -scale_y * rdp.scale_y;
rdp.view_scale[2] = 32.0f * scale_z;
rdp.view_trans[0] = trans_x * rdp.scale_x;
rdp.view_trans[1] = trans_y * rdp.scale_y;
rdp.view_trans[2] = 32.0f * trans_z;
rdp.update |= UPDATE_VIEWPORT;
FRDP("viewport scale(%d, %d), trans(%d, %d), from:%08lx\n", scale_x, scale_y,
trans_x, trans_y, a);
}
break;
case 10: // LIGHT
{
int n = (ofs / 48);
if (n < 2)
{
char dir_x = ((char*)gfx.RDRAM)[(addr + 8) ^ 3];
rdp.lookat[n][0] = (float)(dir_x) / 127.0f;
char dir_y = ((char*)gfx.RDRAM)[(addr + 9) ^ 3];
rdp.lookat[n][1] = (float)(dir_y) / 127.0f;
char dir_z = ((char*)gfx.RDRAM)[(addr + 10) ^ 3];
rdp.lookat[n][2] = (float)(dir_z) / 127.0f;
rdp.use_lookat = TRUE;
if (n == 1)
{
if (!dir_x && !dir_y)
rdp.use_lookat = FALSE;
}
FRDP("lookat_%d (%f, %f, %f)\n", n, rdp.lookat[n][0], rdp.lookat[n][1], rdp.lookat[n][2]);
return;
}
n -= 2;
uint8_t col = gfx.RDRAM[(addr + 0) ^ 3];
rdp.light[n].r = (float)col / 255.0f;
rdp.light[n].nonblack = col;
col = gfx.RDRAM[(addr + 1) ^ 3];
rdp.light[n].g = (float)col / 255.0f;
rdp.light[n].nonblack += col;
col = gfx.RDRAM[(addr + 2) ^ 3];
rdp.light[n].b = (float)col / 255.0f;
rdp.light[n].nonblack += col;
rdp.light[n].a = 1.0f;
rdp.light[n].dir_x = (float)(((char*)gfx.RDRAM)[(addr + 8) ^ 3]) / 127.0f;
rdp.light[n].dir_y = (float)(((char*)gfx.RDRAM)[(addr + 9) ^ 3]) / 127.0f;
rdp.light[n].dir_z = (float)(((char*)gfx.RDRAM)[(addr + 10) ^ 3]) / 127.0f;
// **
uint32_t a = addr >> 1;
rdp.light[n].x = (float)(((short*)gfx.RDRAM)[(a + 16) ^ 1]);
rdp.light[n].y = (float)(((short*)gfx.RDRAM)[(a + 17) ^ 1]);
rdp.light[n].z = (float)(((short*)gfx.RDRAM)[(a + 18) ^ 1]);
rdp.light[n].w = (float)(((short*)gfx.RDRAM)[(a + 19) ^ 1]);
rdp.light[n].nonzero = gfx.RDRAM[(addr + 12) ^ 3];
rdp.light[n].ca = (float)rdp.light[n].nonzero / 16.0f;
//rdp.light[n].la = rdp.light[n].ca * 1.0f;
#ifdef EXTREME_LOGGING
FRDP("light: n: %d, pos: x: %f, y: %f, z: %f, w: %f, ca: %f\n",
n, rdp.light[n].x, rdp.light[n].y, rdp.light[n].z, rdp.light[n].w, rdp.light[n].ca);
#endif
FRDP("light: n: %d, r: %f, g: %f, b: %f. dir: x: %.3f, y: %.3f, z: %.3f\n",
n, rdp.light[n].r, rdp.light[n].g, rdp.light[n].b,
rdp.light[n].dir_x, rdp.light[n].dir_y, rdp.light[n].dir_z);
#ifdef EXTREME_LOGGING
for (int t = 0; t < 24; t++)
{
FRDP ("light[%d] = 0x%04lx \n", t, ((uint16_t*)gfx.RDRAM)[(a+t)^1]);
}
#endif
}
break;
case 14: //Normales
{
uc8_normale_addr = segoffset(rdp.cmd1);
FRDP("Normale - addr: %08lx\n", uc8_normale_addr);
#ifdef EXTREME_LOGGING
int i;
for (i = 0; i < 32; i++)
{
char x = ((char*)gfx.RDRAM)[uc8_normale_addr + ((i<<1) + 0)^3];
char y = ((char*)gfx.RDRAM)[uc8_normale_addr + ((i<<1) + 1)^3];
FRDP("#%d x = %d, y = %d\n", i, x, y);
}
uint32_t a = uc8_normale_addr >> 1;
for (i = 0; i < 32; i++)
{
FRDP ("n[%d] = 0x%04lx \n", i, ((uint16_t*)gfx.RDRAM)[(a+i)^1]);
}
#endif
}
break;
default:
FRDP("uc8:movemem unknown (%d)\n", idx);
}
}
static void uc8_tri4() //by Gugaman Apr 19 2002
{
if (rdp.skip_drawing)
{
LRDP("uc8:tri4. skipped\n");
return;
LRDP("uc8:tri4. skipped\n");
return;
}
FRDP("uc8:tri4 (#%d - #%d), %d-%d-%d, %d-%d-%d, %d-%d-%d, %d-%d-%d\n",
rdp.tri_n,
rdp.tri_n+3,
((rdp.cmd0 >> 23) & 0x1F),
((rdp.cmd0 >> 18) & 0x1F),
((((rdp.cmd0 >> 15) & 0x7) << 2) | ((rdp.cmd1 >> 30) &0x3)),
((rdp.cmd0 >> 10) & 0x1F),
((rdp.cmd0 >> 5) & 0x1F),
((rdp.cmd0 >> 0) & 0x1F),
((rdp.cmd1 >> 25) & 0x1F),
((rdp.cmd1 >> 20) & 0x1F),
((rdp.cmd1 >> 15) & 0x1F),
((rdp.cmd1 >> 10) & 0x1F),
((rdp.cmd1 >> 5) & 0x1F),
((rdp.cmd1 >> 0) & 0x1F));
FRDP("uc8:tri4 (#%d - #%d), %d-%d-%d, %d-%d-%d, %d-%d-%d, %d-%d-%d\n",
rdp.tri_n,
rdp.tri_n + 3,
((rdp.cmd0 >> 23) & 0x1F),
((rdp.cmd0 >> 18) & 0x1F),
((((rdp.cmd0 >> 15) & 0x7) << 2) | ((rdp.cmd1 >> 30) & 0x3)),
((rdp.cmd0 >> 10) & 0x1F),
((rdp.cmd0 >> 5) & 0x1F),
((rdp.cmd0 >> 0) & 0x1F),
((rdp.cmd1 >> 25) & 0x1F),
((rdp.cmd1 >> 20) & 0x1F),
((rdp.cmd1 >> 15) & 0x1F),
((rdp.cmd1 >> 10) & 0x1F),
((rdp.cmd1 >> 5) & 0x1F),
((rdp.cmd1 >> 0) & 0x1F));
VERTEX *v[12] = {
&rdp.vtx[(rdp.cmd0 >> 23) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 18) & 0x1F],
&rdp.vtx[((((rdp.cmd0 >> 15) & 0x7) << 2) | ((rdp.cmd1 >> 30) &0x3))],
&rdp.vtx[(rdp.cmd0 >> 10) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 5) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 0) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 25) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 20) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 15) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 10) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 5) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 0) & 0x1F]
};
VERTEX *v[12] = {
&rdp.vtx[(rdp.cmd0 >> 23) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 18) & 0x1F],
&rdp.vtx[((((rdp.cmd0 >> 15) & 0x7) << 2) | ((rdp.cmd1 >> 30) & 0x3))],
&rdp.vtx[(rdp.cmd0 >> 10) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 5) & 0x1F],
&rdp.vtx[(rdp.cmd0 >> 0) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 25) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 20) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 15) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 10) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 5) & 0x1F],
&rdp.vtx[(rdp.cmd1 >> 0) & 0x1F]
};
int updated = 0;
int updated = 0;
if (cull_tri(v))
rdp.tri_n ++;
else
{
updated = 1;
update ();
if (cull_tri(v))
rdp.tri_n++;
else
{
updated = 1;
update();
draw_tri (v);
rdp.tri_n ++;
}
draw_tri(v);
rdp.tri_n++;
}
if (cull_tri(v+3))
rdp.tri_n ++;
else
{
if (!updated)
{
updated = 1;
update ();
}
if (cull_tri(v + 3))
rdp.tri_n++;
else
{
if (!updated)
{
updated = 1;
update();
}
draw_tri (v+3);
rdp.tri_n ++;
}
draw_tri(v + 3);
rdp.tri_n++;
}
if (cull_tri(v+6))
rdp.tri_n ++;
else
{
if (!updated)
{
updated = 1;
update ();
}
if (cull_tri(v + 6))
rdp.tri_n++;
else
{
if (!updated)
{
updated = 1;
update();
}
draw_tri (v+6);
rdp.tri_n ++;
}
draw_tri(v + 6);
rdp.tri_n++;
}
if (cull_tri(v+9))
rdp.tri_n ++;
else
{
if (!updated)
{
updated = 1;
update ();
}
if (cull_tri(v + 9))
rdp.tri_n++;
else
{
if (!updated)
{
updated = 1;
update();
}
draw_tri (v+9);
rdp.tri_n ++;
}
draw_tri(v + 9);
rdp.tri_n++;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -41,30 +41,30 @@
//
//****************************************************************
void uc9_rpdcmd ()
void uc9_rpdcmd()
{
uint32_t a = segoffset(rdp.cmd1) >> 2;
FRDP ("uc9:rdpcmd addr: %08lx\n", a);
if (a)
{
rdp.LLE = 1;
uint32_t cmd = 0;
while(1)
uint32_t a = segoffset(rdp.cmd1) >> 2;
FRDP("uc9:rdpcmd addr: %08lx\n", a);
if (a)
{
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
cmd = rdp.cmd0>>24;
if (cmd == 0xDF)
break;
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
if (cmd == 0xE4 || cmd == 0xE5)
{
a++;
rdp.cmd2 = ((uint32_t*)gfx.RDRAM)[a++];
a++;
rdp.cmd3 = ((uint32_t*)gfx.RDRAM)[a++];
}
gfx_instruction[ucode_zSort][cmd] ();
};
rdp.LLE = 0;
}
rdp.LLE = 1;
uint32_t cmd = 0;
while (1)
{
rdp.cmd0 = ((uint32_t*)gfx.RDRAM)[a++];
cmd = rdp.cmd0 >> 24;
if (cmd == 0xDF)
break;
rdp.cmd1 = ((uint32_t*)gfx.RDRAM)[a++];
if (cmd == 0xE4 || cmd == 0xE5)
{
a++;
rdp.cmd2 = ((uint32_t*)gfx.RDRAM)[a++];
a++;
rdp.cmd3 = ((uint32_t*)gfx.RDRAM)[a++];
}
gfx_instruction[ucode_zSort][cmd]();
};
rdp.LLE = 0;
}
}

File diff suppressed because it is too large Load Diff