#include #include #include #include "pad.h" #include "pllut.h" #include "cstab.h" #include "tmd.h" #define OT_LENGTH 1 #define SCREEN_MODE MODE_PAL #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 256 #define PACKETMAX (48*48) /* Max GPU packets */ #define PI 3.14159265358979323846 #define TRUE 1 #define FALSE 0 static PACKET packetArea[4][PACKETMAX]; /* GPU PACKETS AREA */ static GsOT Wot[2]; static GsOT_TAG wtags[2][1<r = (_r), (c)->g = (_g), (c)->b = (_b) #define setVector(v,x,y,z) (v)->vx = (x), (v)->vy = (y), (v)->vz = (z) #define test1tim 0x80090300 #define box_w 160 #define box_h 100 int state=0; u_long *cylinder; GsDOBJ2 cylinderOBJ; MATRIX transformMatrix; int vertice[32][3] = { {0,390,-150 }, {120,390,-120}, {120,-90,-120}, {0,-90,-150 }, {120,390,-120}, {150,390,0 }, {150,-90,0 }, {120,-90,-120}, {150,390,0 }, {120,390,120 }, {120,-90,120 }, {150,-90,0 }, {120,390,120 }, {0,390,150 }, {0,-90,150 }, {120,-90,120 }, {0,390,150 }, {-120,390,120}, {-120,-90,120}, {0,-90,150 }, {-120,390,120}, {-150,390,0 }, {-150,-90,0 }, {-120,-90,120}, {-150,390,0 }, {-120,390,-120}, {-120,-90,-120}, {-150,-90,0 }, {-120,390,-120}, {0,390,-150 }, {0,-90,-150 }, {-120,-90,-120}}; int vertice2[32][3] = { {249,-90,-646}, {369,-90,-616}, {120,-90,-120}, {0,-90,-150 }, {616,-90,-368}, {646,-90,-248}, {150,-90,0 }, {120,-90,-120}, {646,-90,248 }, {616,-90,368 }, {120,-90,120 }, {150,-90,0 }, {369,-90,616 }, {249,-90,646 }, {0,-90,150 }, {120,-90,120 }, {-249,-90,646}, {-369,-90,616}, {-120,-90,120}, {0,-90,150 }, {-616,-90,368}, {-646,-90,248}, {-150,-90,0 }, {-120,-90,120}, {-646,-90,-248}, {-616,-90,-368}, {-120,-90,-120}, {-150,-90,0 }, {-369,-90,-616}, {-248,-90,-646}, {0,-90,-150 }, {-120,-90,-120}}; int vertice3[32][3] = { {0,-90,-726}, {555,-90,-552}, {120,-90,-120}, {0,-90,-150 }, {555,-90,-552}, {726,-90,-0}, {150,-90,0 }, {120,-90,-120}, {726,-90,0 }, {552,-90,555 }, {120,-90,120 }, {150,-90,0 }, {552,-90,555 }, {0,-90,726 }, {0,-90,150 }, {120,-90,120 }, {0,-90,726}, {-555,-90,552}, {-120,-90,120}, {0,-90,150 }, {-555,-90,552}, {-726,-90,0}, {-150,-90,0 }, {-120,-90,120}, {-726,-90,-0}, {-552,-90,-555}, {-120,-90,-120}, {-150,-90,0 }, {-552,-90,-555}, {0,-90,-726}, {0,-90,-150 }, {-120,-90,-120}}; int work_vertice[32][3] = { {0,390,-150 }, {120,390,-120}, {120,-90,-120}, {0,-90,-150 }, {120,390,-120}, {150,390,0 }, {150,-90,0 }, {120,-90,-120}, {150,390,0 }, {120,390,120 }, {120,-90,120 }, {150,-90,0 }, {120,390,120 }, {0,390,150 }, {0,-90,150 }, {120,-90,120 }, {0,390,150 }, {-120,390,120}, {-120,-90,120}, {0,-90,150 }, {-120,390,120}, {-150,390,0 }, {-150,-90,0 }, {-120,-90,120}, {-150,390,0 }, {-120,390,-120}, {-120,-90,-120}, {-150,-90,0 }, {-120,390,-120}, {0,390,-150 }, {0,-90,-150 }, {-120,-90,-120}}; void simple_morph(void); void create_cylinder(void); void initialiseTMD(u_long *tmdAddr, char objNum, GsDOBJ2 *obj); void drawObject(GsDOBJ2 *obj, MATRIX transformMatrix, GsCOORDINATE2 *super, GsOT *ot); extern DISPENV GsDISPENV; void run_effect(void); void CalcTab1(void); void CalcTab2(void); void Do_Effect(long x1,long y1,long x2,long y2,long x3,long y3,long x4,long y4,long roll); void main(void); void InitialiseView(void); void initialiseall(void); void LoadTIMData(u_long tMemAddress); void SetSpriteInfo(GsSPRITE *tSprite, u_long tMemAddress, long tX, long tY); int DealWithControllerPad (void); void load_tims(void); int InitialiseTexture(long addr); u_long P = 0x80090300; //float cos_table[11520]; //float sin_table[11520]; int clut[256]; void make_clut(void); int x,y; u_char col; void create_luts(void); int side; static GsRVIEW2 TheView; long savesp; void main(void) { FntLoad( 960, 256); FntOpen( 20, 20, 256, 200, 0, 512); initialiseall(); InitialiseView(); // create_luts(); // CalcTab1(); // CalcTab2(); load_tims(); make_clut(); create_cylinder(); __asm__ volatile ("sw $29,(savesp)"); __asm__ volatile ("la $29,0x1f8003f0" ); run_effect(); __asm__ volatile ("lw $29,(savesp)"); ResetGraph(3); } void make_clut(void) { int i=0; for(i=0;i<128;i+=32)//0/32/64/96 { clut[i] = i/4; } for(i=255;i>128;i-=32)//255/223/191/159 { clut[i] = (i-128)/4; } for(i=1;i<32;i++) { clut[i] = (i/4)+((i/8)<<10); } for(i=33;i<64;i++) { clut[i] = (i/4)+((i/16)<<10); } for(i=65;i<96;i++) { clut[i] = (i/4)+((i/24)<<10); } for(i=97;i<128;i++) { clut[i] = (i/4)+((i/32)<<10); } for(i=254;i>223;i--) { clut[i] = ((i-128)/4)+((i/32)<<10); } for(i=222;i>191;i--) { clut[i] = ((i-128)/4)+((i/24)<<10); } for(i=190;i>159;i--) { clut[i] = ((i-128)/4)+((i/16)<<10); } for(i=158;i>127;i--) { clut[i] = ((i-128)/4)+((i/8)<<10); } return; } void CalcTab1(void) // calculate table 1 for plasma { long i=0,j=0; while(i359) circle1=0; if(circle2>359) circle2=0; if(circle3>359) circle3=0; if(circle4>359) circle4=0; if(circle5>359) circle5=0; if(circle6>359) circle6=0; if(circle7>359) circle7=0; if(circle8>359) circle8=0; if(circle1<0) circle1=359; if(circle2<0) circle2=359; if(circle3<0) circle3=359; if(circle4<0) circle4=359; if(circle5<0) circle5=359; if(circle6<0) circle6=359; if(circle7<0) circle7=359; if(circle8<0) circle8=359; x2=(box_w/2)+(box_w/2)*sin_table[(int)(circle1*32)]; y2=(box_h/2)+(box_h/2)*cos_table[(int)(circle2*32)]; x1=(box_w/2)+(box_w/2)*cos_table[(int)(circle3*32)]; y1=(box_h/2)+(box_h/2)*sin_table[(int)(circle4*32)]; x3=(box_w/2)+(box_w/2)*cos_table[(int)(circle5*32)]; y3=(box_h/2)+(box_h/2)*sin_table[(int)(circle6*32)]; x4=(box_w/2)+(box_w/2)*cos_table[(int)(circle7*32)]; y4=(box_h/2)+(box_h/2)*sin_table[(int)(circle8*32)]; Do_Effect(x1,y1,x2,y2,x3,y3,x4,y4,roll+=4); InitialiseTexture(P); if(frame>150) { if(++state>4) state=0; frame=0; } transformMatrix = GsIDMATRIX; // move object setVector(&rotate, angle, Zangle, 0); RotMatrix(&rotate, &transformMatrix); angle+=8; if(angle>1024) { angle=1024; if(state!=1) Zangle+=64; } drawObject(&cylinderOBJ, transformMatrix, WORLD, &Wot[side]); simple_morph(); DrawSync(0); hsync = VSync(0); GsSwapDispBuff(); GsSortClear(0,0,0,&Wot[side]); GsDrawOt(&Wot[side]); side^=1; } } void Do_Effect(long x1,long y1,long x2,long y2,long x3,long y3,long x4,long y4,long roll) { long i=0,j=0,k=0; u_char a; u_long* pointer; u_long P = 0x80090314; int county=0,countx=0; pointer = (u_long *)P; while(i127) { j=160;pointer+=32; } } pointer+=160; i++; countx=0; } return; } void create_luts(void) { int i=0; float value=0; for(i=0;i<5760;i++) { value+=.0625; cos_table[i] = cos(value); sin_table[i] = sin(value); } } void load_tims(void) { return; } void initialiseall(void) { PadInit(); // init controller pad SetVideoMode( MODE_PAL ); GsInitGraph(SCREEN_WIDTH,SCREEN_HEIGHT,GsOFSGPU,0,0); GsDISPENV.screen.w=SCREEN_WIDTH; GsDISPENV.screen.h=SCREEN_HEIGHT; GsDefDispBuff(0,0,0,SCREEN_HEIGHT); /* Setup Double buffer */ GsInit3D(); Wot[0].length = OT_LENGTH; Wot[0].org = wtags[0]; Wot[1].length = OT_LENGTH; Wot[1].org = wtags[1]; GsClearOt(0, 0, &Wot[0]); GsClearOt(0, 0, &Wot[1]); } void InitialiseView(void) { GsSetProjection(900); TheView.vrx = 0; TheView.vry = 0; TheView.vrz = 0; TheView.vpx = 0; TheView.vpy = 0; //250 TheView.vpz = -6000;// 525 TheView.rz = 0; TheView.super = WORLD; GsSetRefView2(&TheView); } int DealWithControllerPad (void) { long pad_choice; int pad; int pad_2; pad_choice = PadRead(); pad = pad_choice & 0xffff; pad_2 = pad_choice >>16; if(pad & PADLup) { TheView.vpz+=50; } if(pad & PADLdown) { TheView.vpz-=50; } if(pad & PADLright) { } if(pad & PADLleft) { } if ((pad & PADselect)&&(pad & PADstart)) return -1; return 1; } void LoadTIMData(u_long tMemAddress) { RECT tRect; // rectangular area to be used for TIM GsIMAGE tTim; // TIM image information tMemAddress += 4; // advance memory pointer to data GsGetTimInfo((u_long *) tMemAddress, &tTim); // fill tTim with info from TIM tRect.x = tTim.px; // tell GPU where graphics data is tRect.y = tTim.py; tRect.w = tTim.pw; tRect.h = tTim.ph; LoadImage(&tRect, tTim.pixel); // load video memory with TIM data tRect.x = tTim.cx; // tell GPU where colour table is tRect.y = tTim.cy; tRect.w = tTim.cw; tRect.h = tTim.ch; LoadImage(&tRect, tTim.clut); // load video memory with CLUT data DrawSync(0); // force LoadImages to complete }; void SetSpriteInfo(GsSPRITE *tSprite, u_long tMemAddress, long tX, long tY) { u_long tTexturePageX, tTexturePageY; // four variables to clear up u_long tTexturePageXOffset, tTexturePageYOffset; // assignment of texture pages GsIMAGE tTim; // TIM image information u_long tCLUT; tMemAddress += 4; // advance memory pointer to data GsGetTimInfo((u_long *) tMemAddress, &tTim); // fill tTim with info from TIM tSprite->x = tX; // set sprites screen coordinates tSprite->y = tY; // based on values passed if (tTim.pmode& 0x01) { tSprite->attribute = (1<<24); // set up for 256 colour sprite tSprite->w = tTim.pw*2; tCLUT = 1; } else { tSprite->attribute = 0; // set up for 16 colour sprite tSprite->w = tTim.pw*4; tCLUT = 0; }; tSprite->h = tTim.ph; tTexturePageX = (tTim.px/64) *64; // calculate texture page tTexturePageY = (tTim.py/256) *256; tTexturePageXOffset = tTim.px % 64; tTexturePageYOffset = tTim.py % 256; tSprite->tpage = GetTPage(tCLUT, 0, tTim.px, tTim.py); // calculate correct texture page tSprite->u = tTexturePageXOffset*4; // offset for sprite from left of tpage tSprite->v = tTexturePageYOffset; // offset for sprite from top of tpage tSprite->cx = tTim.cx; // set sprite to use correct CLUT tSprite->cy = tTim.cy; tSprite->r = tSprite->g = tSprite->b = 128; // make sure the sprite is set to // normal colour intensity tSprite->mx = tSprite->w/2; // set handle of sprite to the center tSprite->my = tSprite->h/2; // (this does not need to be done if // you would rather move the objects // by their top left corner) tSprite->scalex = tSprite->scaley = ONE; // make sure the sprite isn't scaled tSprite->rotate = 0; // make sure its pointing up }; int InitialiseTexture(long addr) { RECT rect; GsIMAGE tim1; addr+=4; GsGetTimInfo((u_long *)addr,&tim1); rect.x=tim1.px; rect.y=tim1.py; rect.w=tim1.pw; rect.h=tim1.ph; LoadImage(&rect,tim1.pixel); DrawSync(0); return(0); } void simple_morph(void) { int i=0; int num=0; if(state==0) for(i=0;i<32;i++) { if(work_vertice[i][0]vertice2[i][0]+2) work_vertice[i][0]-=4; if(work_vertice[i][1]vertice2[i][1]+2) work_vertice[i][1]-=4; if(work_vertice[i][2]vertice2[i][2]+2) work_vertice[i][2]-=4; } if(state==1) for(i=0;i<32;i++) { if(work_vertice[i][0]vertice3[i][0]+2) work_vertice[i][0]-=4; if(work_vertice[i][1]vertice3[i][1]+2) work_vertice[i][1]-=4; if(work_vertice[i][2]vertice3[i][2]+2) work_vertice[i][2]-=4; } if(state==2) for(i=0;i<32;i++) { if(work_vertice[i][0]vertice2[i][0]+2) work_vertice[i][0]-=4; if(work_vertice[i][1]vertice2[i][1]+2) work_vertice[i][1]-=4; if(work_vertice[i][2]vertice2[i][2]+2) work_vertice[i][2]-=4; } if(state==3) for(i=0;i<32;i++) { if(work_vertice[i][0]vertice[i][0]+2) work_vertice[i][0]-=4; if(work_vertice[i][1]vertice[i][1]+2) work_vertice[i][1]-=4; if(work_vertice[i][2]vertice[i][2]+2) work_vertice[i][2]-=4; } if(state==4) for(i=0;i<32;i++) { if(work_vertice[i][0]vertice3[i][0]+2) work_vertice[i][0]-=4; if(work_vertice[i][1]vertice3[i][1]+2) work_vertice[i][1]-=4; if(work_vertice[i][2]vertice3[i][2]+2) work_vertice[i][2]-=4; } for(i=0;i<8;i++) { TMD_setVert0(cylinder,i,work_vertice[num][0],work_vertice[num][1],work_vertice[num][2]); TMD_setVert1(cylinder,i,work_vertice[num+3][0],work_vertice[num+3][1],work_vertice[3+num][2]); TMD_setVert2(cylinder,i,work_vertice[num+1][0],work_vertice[num+1][1],work_vertice[1+num][2]); TMD_setVert3(cylinder,i,work_vertice[num+2][0],work_vertice[num+2][1],work_vertice[2+num][2]); num+=4; } } void create_cylinder(void) { int i=0; int num=0; int xpos=0; cylinder = (u_long *)0x801a0000; TMD_start(cylinder); for(i=0;i<8;i++) TMD_addPolyFT4(); TMD_end(); for(i=0;i<8;i++) { if(i==0) TMD_setUV4(cylinder,i,xpos+4,199,xpos+4,0,xpos+31,199,xpos+31,0); else TMD_setUV4(cylinder,i,xpos,199,xpos,0,xpos+31,199,xpos+31,0); xpos+=32; TMD_setTPage(cylinder,i,GetTPage(2,1,640,0)); TMD_setRGB0(cylinder,i,128,128,128); TMD_setVert0(cylinder,i,vertice[num][0],vertice[num][1],vertice[num][2]); TMD_setVert1(cylinder,i,vertice[num+3][0],vertice[num+3][1],vertice[3+num][2]); TMD_setVert2(cylinder,i,vertice[num+1][0],vertice[num+1][1],vertice[1+num][2]); TMD_setVert3(cylinder,i,vertice[num+2][0],vertice[num+2][1],vertice[2+num][2]); TMD_setNorm0(cylinder,i,0,0,4096); num+=4; } initialiseTMD(cylinder, 0, &cylinderOBJ); } void initialiseTMD(u_long *tmdAddr, char objNum, GsDOBJ2 *obj) { GsMapModelingData((u_long *)(tmdAddr + 1)); GsLinkObject4((u_long)(tmdAddr + 3), obj, objNum); obj->coord2 = WORLD; } void drawObject(GsDOBJ2 *obj, MATRIX transformMatrix, GsCOORDINATE2 *super, GsOT *ot) { MATRIX tmplw,tmpls; obj->coord2->coord = transformMatrix; // perform transformation on object obj->coord2->super = super; // move relative to coord system super obj->coord2->flg = 0; // flag object as moved GsGetLws(obj->coord2, &tmplw, &tmpls); GsSetLightMatrix(&tmplw); GsSetLsMatrix(&tmpls); GsSortObject4(obj, ot, 14-OT_LENGTH, (u_long *)getScratchAddr(0)); }