/* 14/6/99 - playstation link-up demo program */ #include #include "libcyc.h" #include "stdio.h" #include "stdlib.h" #include "pad.h" #include "func.h" /* externs */ extern struct link_info link; volatile struct cmds *cd = &link.cmd_info; /* system stuff */ GsOT WorldOT[2]; GsOT_TAG OTTags[2][1<<1]; PACKET GpuPacketArea[2][4*24]; volatile u_char *bb0,*bb1; /* ptrs to hold pad buffer addrs */ int activeBuff; /* our globals */ GsBOXF box[BOX_NUM]; struct link_info *link_p = &link; u_long padd; int triangle = 0, circle = 0,cross = 0, square = 0; int started = 0; void main() { Init_Psx(); /* setup display, get pad buffers */ if(!sio_open()) /* open serial port, init callback function */ exit(1); /* main program loop */ while((Read_Pad() != 3) && (!cd->exit)) { FntPrint(" PlayStation Link Demonstration\n"); FntPrint(" To quit press start+select\n\n"); if(link_p->ping == PNG_PC) PC_Connection(); else PSX_Connection(); /* transfer data, move boxes around screen */ if(started == S_READY) { started = 0; Move_Boxes(); } triangle = circle = cross = square = 0; Update_Gfx(0); } cyc_exit(); sio_close(); /* close serial port */ } /*------------------------------------------------------------------------------------*/ /* General initialization; graphics, pad buffers, debug font pattern */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void Init_Psx(void) { int i; GetPadBuf(&bb0,&bb1); /* get controller buffers */ VSync(0); /* PAL default video mode, NTSC if user holds down start button at start */ if(Read_Pad() == 1) SetVideoMode(MODE_NTSC); else SetVideoMode(MODE_PAL); /* set up drawing and display enviroment */ GsInitGraph(320, 240, 4, 0, 0); GsDefDispBuff(0, 0, 0, 240); /* set up the ordering table */ for(i = 0; i < 2; i++) { WorldOT[i].length = 1; WorldOT[i].org = OTTags[i]; } FntLoad(960,256); /* loads basic font pattern into frame buffer */ FntOpen(16,16,256,200,0,512); /* display area for text */ } /*------------------------------------------------------------------------------------*/ /* Read and store controller values */ /* Arguments: */ /* none */ /* Return value: */ /* start/select button combination */ /*------------------------------------------------------------------------------------*/ int Read_Pad(void) { int end = 0; padd = (~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); if(padd & PADRup) triangle = 1; if(padd & PADRright) circle = 1; if(padd & PADRdown) cross = 1; if(padd & PADRleft) square = 1; if(padd & PADselect) end += 2; if(padd & PADstart) end += 1; return end; } /*------------------------------------------------------------------------------------*/ /* Update screen display, display text/boxes */ /* Arguments: */ /* draw_boxes - if set, register boxes and display */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void Update_Gfx(int draw_boxes) { int i; activeBuff = GsGetActiveBuff(); GsSetWorkBase((PACKET *)GpuPacketArea[activeBuff]); /* ordering table clear */ GsClearOt(0, 0, &WorldOT[activeBuff]); FntFlush(-1); if(draw_boxes) { /* register each box in OT */ for(i = 0; i < BOX_NUM; i++) { GsSortBoxFill(&box[i],&WorldOT[activeBuff],0); } } DrawSync(0); VSync(0); GsSwapDispBuff(); GsSortClear(60, 120, 120, &WorldOT[activeBuff]); GsDrawOt(&WorldOT[activeBuff]); /* draw gfx in buffer */ }