/**************************************************************************************/ /* Misc.c, Libcyc source file */ /* Miscellaneous functions */ /* Copyright(C)1999 Peter Armstrong */ /* Release 2.0 */ /**************************************************************************************/ /* includes */ #include #include "stdlib.h" #include "sys\ioctl.h" #include "sys\file.h" #include "pad.h" #include "misc.h" #include "sendrec.h" #include "cycfcntl.h" #include "packets.h" /* externs */ extern long _gp; struct link_info link; /* globals */ int time[TIME_NUM]; /* pal/ntsc timer values */ void (*vs_func)(); /* pointer to application's VSyncCallback function */ volatile u_int vs_timer = 0; /* timer updated every vertical interrupt */ int port_fd; /* port file descriptor */ int vs_cmd = 1; /* callback command processing enabled when set */ /*------------------------------------------------------------------------------------*/ /* Flush serial port buffer (on read error) */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void Sio_Flush(void) { ioctl(port_fd,FIOCSCAN,1); ioctl(port_fd,TIOCFLUSH,1); } /**************************************************************************************/ /* Open serial port,initialize callback function, test connection type, sort time vals*/ /* Arguments: */ /* none */ /* Return value: */ /* 1 - port opened */ /* 0 - cannot open port */ /**************************************************************************************/ int sio_open(void) { int i,fps; if((port_fd = open("tty:",O_RDWR | O_NBLOCK)) >= 0) { close(1); /* close standard i/o streams */ close(0); ioctl(port_fd,TIOCRTS,1); /* RTS line dropped when above closed, set high again */ ioctl(port_fd,TIOCRAW,0); /* disable software flow control */ /* sort timing values depending on video mode */ fps = (GetVideoMode()) ? 50 : 60; /* pal/ntsc */ time[HALF_SEC] = fps>>1; for(i = 1; i < TIME_NUM;i++) { time[i] = fps * i; } VSyncCallback(vs_Callback); /* init library callback function */ /* if not connected to PC, increase port baud rate */ if(cyc_ping() != PNG_PC) ioctl(port_fd,TIOCBAUD,960000); /* not right, but speeds things up */ return OK; } return NG; /* couldn't get port fd */ } /**************************************************************************************/ /* Close serial port, clear callback function */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /**************************************************************************************/ void sio_close(void) { VSyncCallback(NULL); close(port_fd); } /*------------------------------------------------------------------------------------*/ /* VSyncCallback function; scan port, process cmds, execute app's callback function */ /* Arguments: */ /* none */ /* Return value: */ /* none */ /*------------------------------------------------------------------------------------*/ void vs_Callback(void) { __asm__ volatile ("la $28, _gp"); vs_timer++; /* 50/60th sec counter */ ioctl(port_fd,FIOCSCAN,1); /* shift port data to internal buffer */ if(vs_cmd) vs_PsxCmds(); /* read/write commands */ if(vs_func) vs_func(); /* execute applications VSyncCallback function if there is one */ } /**************************************************************************************/ /* Chain application's callback function */ /* Arguments: */ /* *f - address of application function */ /* Return value: */ /* none */ /**************************************************************************************/ void chain_callback(void (*f)()) { vs_func = f; }