/* * Glide64 - Glide video plugin for Nintendo 64 emulators. * Copyright (c) 2002 Dave2001 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //**************************************************************** // // Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64) // Project started on December 29th, 2001 // // To modify Glide64: // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me. // * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all. // // Official Glide64 development channel: #Glide64 on EFnet // // Original author: Dave2001 (Dave2999@hotmail.com) // Other authors: Gonetz, Gugaman // //**************************************************************** // // January 2004 Created by Gonetz (Gonetz@ngs.ru) //**************************************************************** DWORD uc8_uv_base = 0; static void uc8_vertex () { if (rdp.update & UPDATE_MULT_MAT) { rdp.update ^= UPDATE_MULT_MAT; for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { rdp.combined[j][i] = rdp.proj[0][i] * rdp.model[j][0] + rdp.proj[1][i] * rdp.model[j][1] + rdp.proj[2][i] * rdp.model[j][2] + rdp.proj[3][i] * rdp.model[j][3]; } } } DWORD 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; FRDP ("uc2:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr); if (v0 < 0) { RDP_E ("** ERROR: uc2:vertex v0 < 0\n"); RDP ("** 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 mat_3x3_inverse (rdp.inverse, rdp.model); #ifdef EXTREME_LOGGING RDP("inverse matrix:\n"); FRDP ("{%f,%f,%f,%f}\n", rdp.inverse[0][0], rdp.inverse[0][1], rdp.inverse[0][2], rdp.inverse[0][3]); FRDP ("{%f,%f,%f,%f}\n", rdp.inverse[1][0], rdp.inverse[1][1], rdp.inverse[1][2], rdp.inverse[1][3]); FRDP ("{%f,%f,%f,%f}\n", rdp.inverse[2][0], rdp.inverse[2][1], rdp.inverse[2][2], rdp.inverse[2][3]); FRDP ("{%f,%f,%f,%f}\n", rdp.inverse[3][0], rdp.inverse[3][1], rdp.inverse[3][2], rdp.inverse[3][3]); #endif for (DWORD l=0; l>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 = ((WORD*)gfx.RDRAM)[(((addr+i) >> 1) + 3)^1]; v->ou = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 4)^1] * rdp.tiles[rdp.cur_tile].s_scale; v->ov = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 5)^1] * rdp.tiles[rdp.cur_tile].t_scale; v->a = ((BYTE*)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]; #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 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_mods_allowed = 1; 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 = ((BYTE*)gfx.RDRAM)[(addr+i + 12)^3]; v->g = ((BYTE*)gfx.RDRAM)[(addr+i + 13)^3]; v->b = ((BYTE*)gfx.RDRAM)[(addr+i + 14)^3]; //*/ if (rdp.geom_mode & 0x00020000) { if (!(rdp.geom_mode & 0x800000)) { /* WORD w = ((WORD*)gfx.RDRAM)[(uc8_uv_base+(i>>4))^1]; v->vec[0] = (char)((w>>8)&0xff); v->vec[1] = (char)(w&0xff); v->vec[2] = 0; */ v->vec[0] = ((char*)gfx.RDRAM)[uc8_uv_base + ((i>>3) + 0)^3]; v->vec[1] = ((char*)gfx.RDRAM)[uc8_uv_base + ((i>>3) + 1)^3]; v->vec[2] = ((char*)gfx.RDRAM)[uc8_uv_base + ((i>>3) + 2)^3]; 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 } } } } } static void uc8_moveword () { BYTE index = (BYTE)((rdp.cmd0 >> 16) & 0xFF); WORD offset = (WORD)(rdp.cmd0 & 0xFFFF); DWORD 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 0x00: // moveword matrix { // do matrix pre-mult so it's re-updated next time if (rdp.update & UPDATE_MULT_MAT) { rdp.update ^= UPDATE_MULT_MAT; for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { rdp.combined[j][i] = rdp.proj[0][i] * rdp.model[j][0] + rdp.proj[1][i] * rdp.model[j][1] + rdp.proj[2][i] * rdp.model[j][2] + rdp.proj[3][i] * rdp.model[j][3]; } } } if (rdp.cmd0 & 0x20) // fractional part { int index_x = (rdp.cmd0 & 0x1F) >> 1; int index_y = index_x >> 2; index_x &= 3; float fpart = (rdp.cmd1>>16)/65536.0f; rdp.combined[index_y][index_x] = (float)(int)rdp.combined[index_y][index_x]; rdp.combined[index_y][index_x] += fpart; fpart = (rdp.cmd1&0xFFFF)/65536.0f; rdp.combined[index_y][index_x+1] = (float)(int)rdp.combined[index_y][index_x+1]; rdp.combined[index_y][index_x+1] += fpart; } else { int index_x = (rdp.cmd0 & 0x1F) >> 1; int index_y = index_x >> 2; index_x &= 3; float fpart = (float)fabs(rdp.combined[index_y][index_x] - (int)rdp.combined[index_y][index_x]); rdp.combined[index_y][index_x] = (short)(rdp.cmd1>>16); fpart = (float)fabs(rdp.combined[index_y][index_x+1] - (int)rdp.combined[index_y][index_x+1]); rdp.combined[index_y][index_x+1] = (short)(rdp.cmd1&0xFFFF); } RDP ("matrix\n"); } break; case 0x02: rdp.num_lights = (data / 48); rdp.update |= UPDATE_LIGHTS; FRDP ("numlights: %d\n", rdp.num_lights); break; case 0x04: 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.update |= UPDATE_FOG_ENABLED; } break; case 0x0a: // moveword LIGHTCOL { int n = offset >> 2; FRDP ("lightcol light:%d, %08lx\n", n, data); /* rdp.light[n].r = (float)((data >> 24) & 0xFF) / 255.0f; rdp.light[n].g = (float)((data >> 16) & 0xFF) / 255.0f; rdp.light[n].b = (float)((data >> 8) & 0xFF) / 255.0f; rdp.light[n].a = 255; */ } break; case 0x0c: RDP_E ("uc8:moveword forcemtx - IGNORED\n"); RDP ("forcemtx - IGNORED\n"); break; case 0x0e: RDP ("perspnorm - IGNORED\n"); break; case 0x10: // moveword LIGHT? { BYTE n = offset >> 2; FRDP ("unknown light:%d, %08lx\n", n, data); /* rdp.light[n].r = (float)((data >> 24) & 0xFF) / 255.0f; rdp.light[n].g = (float)((data >> 16) & 0xFF) / 255.0f; rdp.light[n].b = (float)((data >> 8) & 0xFF) / 255.0f; rdp.light[n].a = 255; //*/ /* // rdp.light[n].dir_x = (float)((char)((data>>24)&0xFF)) / 127.0f; // rdp.light[n].dir_y = (float)((char)((data>>16)&0xFF)) / 127.0f; // rdp.light[n].dir_z = (float)((char)((data>>8)&0xFF)) / 127.0f; //*/ } 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; DWORD addr = segoffset(rdp.cmd1); int ofs = (rdp.cmd0 >> 5) & 0x3FFF; FRDP ("uc8:movemem ofs:%d ", ofs); switch (idx) { case 0: case 2: uc6_obj_movemem (); break; case 8: // VIEWPORT { DWORD 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] = float(scale_z); rdp.view_trans[0] = trans_x * rdp.scale_x; rdp.view_trans[1] = trans_y * rdp.scale_y; rdp.view_trans[2] = float(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) - 2; //if (n > 7) return; // Get the data /* rdp.light[n].r = (float)(((BYTE*)gfx.RDRAM)[(addr+0)^3]) / 255.0f; rdp.light[n].g = (float)(((BYTE*)gfx.RDRAM)[(addr+1)^3]) / 255.0f; rdp.light[n].b = (float)(((BYTE*)gfx.RDRAM)[(addr+2)^3]) / 255.0f; 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; rdp.update |= UPDATE_LIGHTS; FRDP ("light: n: %d, r: %.3f, g: %.3f, b: %.3f, 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 ("light: n: %d\n",n); break; } break; case 14: //directions for auto generation of texture coordinates { uc8_uv_base = segoffset(rdp.cmd1); FRDP ("texmap - addr: %08lx\n", uc8_uv_base); //uc8_uv_base >>= 1; } break; default: FRDP ("uc2:matrix unknown (%d)\n", idx); FRDP ("** UNKNOWN %d\n", idx); } } static void uc8_tri4() //by Gugaman Apr 19 2002 { if (rdp.skip_drawing) { RDP("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)); 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] }; BOOL updated = 0; if (cull_tri(v)) rdp.tri_n ++; else { updated = 1; update (); DrawTri (v); rdp.tri_n ++; } if (cull_tri(v+3)) rdp.tri_n ++; else { if (!updated) { updated = 1; update (); } DrawTri (v+3); rdp.tri_n ++; } if (cull_tri(v+6)) rdp.tri_n ++; else { if (!updated) { updated = 1; update (); } DrawTri (v+6); rdp.tri_n ++; } if (cull_tri(v+9)) rdp.tri_n ++; else { if (!updated) { updated = 1; update (); } DrawTri (v+9); rdp.tri_n ++; } }