#include // GPU packet space #define PACKETMAX 5000 #define PACKETMAX2 (PACKETMAX*24) #define lengthOT 8 #define setVector(v,x,y,z) (v)->vx = (x), (v)->vy = (y), (v)->vz = (z) #define setNormal(n,x,y,z) (n)->nx = (x), (n)->ny = (y), (n)->nz = (z) #define setColor(c,_r,_g,_b) (c)->r = (_r), (c)->g = (_g), (c)->b = (_b) #define copyVector(v0,v1) (v1)->vx = (v0)->vx, (v1)->vy = (v0)->vy, (v1)->vz = (v0)->vz #define addVector(v0,v1) (v0)->vx += (v1)->vx, (v0)->vy += (v1)->vy, (v0)->vz += (v1)->vz #define subVector(v0,v1) (v0)->vx -= (v1)->vx, (v0)->vy -= (v1)->vy, (v0)->vz -= (v1)->vz #define applyVector(v,x,y,z,op) (v)->vx op x, (v)->vy op y, (v)->vz op z #define dotProduct(v1,v2) ((v1)->vx * (v2)->vx / 4096 + (v1)->vy * (v2)->vy / 4096 + (v1)->vz * (v2)->vz / 4096) // ordering tables GsOT OT[2]; GsOT_TAG zTable[2][1 << lengthOT]; PACKET GpuOutputPacket[2][PACKETMAX2]; // GPU packet work area static int buffIdx; // current output buffer void display_init(void) { int i; ResetGraph(0); // reset the graphics if (GetVideoMode() == MODE_NTSC) GsInitGraph(320 ,240, GsOFSGPU, 1, 0); else GsInitGraph(320 ,256, GsOFSGPU, 1, 0); setRECT(&GsDRAWENV.tw,0,0,32,32); //--display buffers GsDefDispBuff(0, 0, 0, 256); //--initialise 3D GsInit3D(); //--ordering tables for (i = 0; i < 2; i++) { OT[i].length = lengthOT; OT[i].org = zTable[i]; OT[i].offset = 0; OT[i].point = 0; } } void display_setview(GsRVIEW2 *view) { GsSetRefView2(view); } void display_addobject(GsDOBJ2 *obj) { MATRIX coordMatrix; //--find local coords to screen coords matrix GsGetLs(obj->coord2, &coordMatrix); GsSetLsMatrix(&coordMatrix); //--add object to ordering table GsSortObject4(obj, &OT[buffIdx], 14 - OT[buffIdx].length, (u_long *)getScratchAddr(0)); } void display_swapbuffer(void) { buffIdx = GsGetActiveBuff(); GsSetWorkBase((PACKET*)GpuOutputPacket[buffIdx]); GsClearOt(0, 0, &OT[buffIdx]); } void display_draw2(void) { GsSortClear(0, 0, 0, &OT[buffIdx]); // add cls to ordering table GsDrawOt(&OT[buffIdx]); // draw DrawSync(0); GsClearOt(0, 0, &OT[buffIdx]); } void display_draw(void) { GsDrawOt(&OT[buffIdx]); // draw DrawSync(0); // finish any drawing VSync(0); GsSwapDispBuff(); // swap screens }