//------------------------------------ // Adapted from programs written by // R.Swan who edited them from code // that is (C) Sony Computer // Entertainment. Origional author // S. Ashley 7th Aug 97 //------------------------------------ #include #include "tmd.h" //------------------------------------ // Globals //------------------------------------ static u_long *TMD_MEM_START; static u_long *TMD_MEM_CURRENT; OBJECT *TMD_MEM_OBJECT; static u_long *VERTEX_START; static u_long *NORMAL_START; static u_long *PRIMITIVE_START; static u_long VERTEX_QUANTITY; static u_long NORMAL_QUANTITY; static u_long PRIMITIVE_QUANTITY; VERTEX *VERTEX_LUT; COLOUR *COLOUR_LUT; TEXTURE *TEXTURE_LUT; //------------------------------------ // Function definitions //------------------------------------ // Prepare for the creation of a new tmd void PrepareTMD(u_long address, VERTEX *vertex, COLOUR *colour, TEXTURE *texture) { VERTEX_LUT = vertex; COLOUR_LUT = colour; TEXTURE_LUT = texture; if (address != 0) TMD_MEM_START = TMD_MEM_CURRENT = (u_long *)address; else TMD_MEM_START = TMD_MEM_CURRENT; VERTEX_QUANTITY = NORMAL_QUANTITY = PRIMITIVE_QUANTITY = 0; SetTmdHeader((HEADER *)TMD_MEM_CURRENT); TMD_MEM_CURRENT = (u_long *)((HEADER *)TMD_MEM_CURRENT + 1); TMD_MEM_OBJECT = (OBJECT *)TMD_MEM_CURRENT; TMD_MEM_CURRENT = (u_long *)((OBJECT *)TMD_MEM_CURRENT + 1); PRIMITIVE_START = TMD_MEM_CURRENT; } // Finish a tmd u_long *FinishTMD(void) { u_long i; VERTEX *temp; VERTEX_QUANTITY++; VERTEX_START = TMD_MEM_CURRENT; temp = (VERTEX *)VERTEX_START; NORMAL_START = (u_long *)((VERTEX *)VERTEX_START + VERTEX_QUANTITY); SetObjectData(TMD_MEM_OBJECT); for (i=0; ivx = (VERTEX_LUT + i)->vx; temp->vy = (VERTEX_LUT + i)->vy; temp->vz = (VERTEX_LUT + i)->vz; temp++; } // Skip normals TMD_MEM_CURRENT = (u_long *)((NORMAL *)NORMAL_START + NORMAL_QUANTITY); // printf("Vertices = %d\n",(int)VERTEX_QUANTITY); // printf("Normals = %d\n",(int)NORMAL_QUANTITY); // printf("Primitives = %d\n",(int)PRIMITIVE_QUANTITY); return TMD_MEM_START; } // Add a textured-gradiated-tinted quad to tmd void SetTX_NS_GP_QUAD(u_short v0, u_short v1, u_short v2, u_short v3, u_long c0, u_long c1, u_long c2, u_long c3, u_long t0) { TX_NS_GP_QUAD_FACE *newPoly = (TX_NS_GP_QUAD_FACE *)TMD_MEM_CURRENT; SetPrimitiveHeader(newPoly, TX_NS_GP_QUAD, 1, 10, 12); newPoly->vert0 = v0; newPoly->vert1 = v1; newPoly->vert2 = v2; newPoly->vert3 = v3; SetColour0(); SetColour1(); SetColour2(); SetColour3(); SetTextureQuad((TX_NS_GP_QUAD_FACE *)newPoly, t0); if (v0>VERTEX_QUANTITY) VERTEX_QUANTITY = v0; if (v1>VERTEX_QUANTITY) VERTEX_QUANTITY = v1; if (v2>VERTEX_QUANTITY) VERTEX_QUANTITY = v2; if (v3>VERTEX_QUANTITY) VERTEX_QUANTITY = v3; PRIMITIVE_QUANTITY++; TMD_MEM_CURRENT = (u_long *)(newPoly + 1); } // Set texture information for a quad void SetTextureQuad(TX_NS_GP_QUAD_FACE *newPoly, u_long textureNum) { TEXTURE *texture = TEXTURE_LUT + textureNum; u_short tPage; int tPageX = 1024, tPageY = 512; if (tPageX > (texture->x0)) tPageX = texture->x0; if (tPageX > (texture->x1)) tPageX = texture->x1; if (tPageX > (texture->x2)) tPageX = texture->x2; if (tPageX > (texture->x3)) tPageX = texture->x3; if (tPageY > (texture->y0)) tPageY = texture->y0; if (tPageY > (texture->y1)) tPageY = texture->y1; if (tPageY > (texture->y2)) tPageY = texture->y2; if (tPageY > (texture->y3)) tPageY = texture->y3; tPageX = tPageX>>6; tPageX = tPageX<<6; tPageY = tPageY>>8; tPageY = tPageY<<8; tPage = GetTPage((int )texture->pmode, 0, tPageX, tPageY); newPoly->u0 = (u_char )(texture->x0 - tPageX); newPoly->v0 = (u_char )(texture->y0 - tPageY); newPoly->u1 = (u_char )(texture->x1 - tPageX); newPoly->v1 = (u_char )(texture->y1 - tPageY); newPoly->u2 = (u_char )(texture->x2 - tPageX); newPoly->v2 = (u_char )(texture->y2 - tPageY); newPoly->u3 = (u_char )(texture->x3 - tPageX); newPoly->v3 = (u_char )(texture->y3 - tPageY); newPoly->tsb = (u_short )tPage; newPoly->cba = ((texture->cx)>>4) + ((texture->cy)<<6); }