/* functions for demo2.c */ /* includes */ #include #include "libcyc.h" #include "stdio.h" #include "stdlib.h" #include "pad.h" #include "func.h" /* externs */ extern volatile u_char *bb0,*bb1; extern GsBOXF box[BOX_NUM]; extern struct link_info *link_p; extern u_long padd; extern int triangle,circle,cross,square; extern int started; /*------------------------------------------------------------------------------------*/ /* display PC connection options, read controller values */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void PC_Connection(void) { FntPrint("\t\t~c090 PC Connection~c999\n\n"); if(!link_p->connected) { FntPrint("Disconnected\n"); FntPrint("Press Circle to connect\n"); FntPrint("Press X to run a test transfer\n"); } else { FntPrint("*Connected*\n"); FntPrint("Press X to start transfer\n"); FntPrint("Press Square to disconnect\n"); } if((circle) && (!link_p->connected)) { FntPrint("\nAttempting to connect\nplease wait....\n"); Update_Gfx(0); link_p = link_connect(NULL); } if(cross) { FntPrint("\nStarting transfer..\n"); Update_Gfx(0); if(link_p->connected) started = pkt_start(SIZE,P_TFR_REAL); else started = pkt_start(SIZE,P_TFR_TEST); } if(square) { link_disconnect(); } } /*------------------------------------------------------------------------------------*/ /* display PSX connection options, read controller values */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void PSX_Connection(void) { FntPrint("\t\t~c499 PSX Connection~c999\n\n"); if(!link_p->connected) { FntPrint("Disconnected\n"); FntPrint("Press Circle to connect\n"); } else { FntPrint("*Connected*\n"); FntPrint("Press X to start transfer\n"); FntPrint("Press Square to disconnect\n"); } if((circle) && (!link_p->connected)) { FntPrint("Connecting...\nPress Triangle to cancel\n"); Update_Gfx(0); link_p = link_connect(bb0); } if((cross) && (link_p->connected)) { FntPrint("Ready to start,\nwaiting for other playstation..\n"); Update_Gfx(0); started = pkt_start(SIZE,P_TFR_REAL); } if(square) { link_disconnect(); } } /*------------------------------------------------------------------------------------*/ /* enter initial position and colour values in box structures */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void Init_Boxes(void) { int i; for(i = 0; i < BOX_NUM;i++) { box[i].attribute = 0x00000000; box[i].x = 40*i; box[i].y = 30*i; box[i].w = 30; box[i].h = 30; box[i].r = box[i].g = box[i].b = 0; /* reset colours */ } box[0].r = box[0].g = box[0].b = 0; /* p1 black */ box[1].r = box[1].g = box[1].b = 255; /* p2 white */ box[2].r = box[2].g = 255; /* p3 yellow */ box[3].b = 255; /* p4 blue */ } /*------------------------------------------------------------------------------------*/ /* adjust box position and colour values using pad data from all controllers */ /* Arguments: */ /* *pad - array of u_short controller values */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void Update_Boxes(u_short *pad) { int i; for(i = 0; i < BOX_NUM; i++) { /* move boxes */ if(pad[i] & PADLup) box[i].y -= 5; if(pad[i] & PADLdown) box[i].y += 5; if(pad[i] & PADLleft) box[i].x -= 5; if(pad[i] & PADLright) box[i].x += 5; /* change colours */ if(pad[i] & PADRup) box[i].r -= 5; if(pad[i] & PADRdown) box[i].r += 5; if(pad[i] & PADRleft) box[i].g -= 5; if(pad[i] & PADRright) box[i].g += 5; if(pad[i] & PADR2) box[i].b -= 5; if(pad[i] & PADR1) box[i].b += 5; /* change box size */ if(pad[i] & PADL2) box[i].w = box[i].h -= 5; if(pad[i] & PADL1) box[i].w = box[i].h += 5; } } /*------------------------------------------------------------------------------------*/ /* main loop, transfer data, update box data and draw boxes on screen */ /* Arguments: */ /* none */ /* Return value: */ /* end transfer status */ /* -1 transfer session ended okay */ /* -2 timeout */ /*------------------------------------------------------------------------------------*/ int Move_Boxes(void) { int i,tfr_rtn; int count = 0; int timer = 0,timerhigh = 0; u_char act_diff; u_short pad[BOX_NUM]; u_char *local_p,*remote_p; Init_Boxes(); /* init box values */ /* master psx controls first two boxes on both machines */ /* slave controls last two boxes */ if(link_p->m_state == MASTER) /* local psx is master */ { local_p = (u_char *)pad; remote_p = (u_char *)&pad[2]; } else /* remote master, local is slave */ { local_p = (u_char *)&pad[2]; remote_p = (u_char *)pad; } while(Read_Pad() != 2) { count++; VSync(1); tfr_rtn = pkt_transfer((u_char *)&padd); /* send pad data to remote */ timer = VSync(1); if(tfr_rtn == T_DATA_AVAIL) { /* data received, copy to pad array store */ for(i = 0; i < SIZE; i++) { local_p[i] = link_p->loc_data[i]; remote_p[i] = link_p->rem_data[i]; } Update_Boxes(pad); /* update box struct info by pad data */ } else { if(tfr_rtn < 0) /* test for end transfer/timeout */ break; } /* freeze timerhigh value */ if(!(count%100)) timerhigh = 0; if(timer > timerhigh) timerhigh = timer; if(link_p->connected) { if(link_p->m_state == MASTER) FntPrint("\t\tMaster playstation\n"); else FntPrint("\t\tSlave playstation\n"); } /* frame difference, between the last local frame data stored and remote received */ act_diff = (link_p->info[L_STORED] - link_p->info[R_STORED]) & 0x0F; FntPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n~c777timer %d high %d count %d\n",timer, timerhigh,count); FntPrint("Max Diff %d Actual Diff %d\n",link_p->max_diff,act_diff); FntPrint("loc %2x %2x %2x %2x\n",link_p->loc_data[0],link_p->loc_data[1],link_p->loc_data[2], link_p->loc_data[3]); FntPrint("rem %2x %2x %2x %2x\n",link_p->rem_data[0],link_p->rem_data[1],link_p->rem_data[2], link_p->rem_data[3]); FntPrint("~c000P1 box.x%3d box.y%3d padd %04x\n",box[0].x,box[0].y,pad[0]); FntPrint("~c999P2 box.x%3d box.y%3d padd %04x\n",box[1].x,box[1].y,pad[1]); FntPrint("~c990P3 box.x%3d box.y%3d padd %04x\n",box[2].x,box[2].y,pad[2]); FntPrint("~c009P4 box.x%3d box.y%3d padd %04x\n",box[3].x,box[3].y,pad[3]); FntPrint("~c999Press ~c090select~c999 to stop transfer\n"); Update_Gfx(1); /* draw boxes */ } pkt_end(); /* end transfer and return to main */ return link_p->rem_status; }