home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / ix-1 / 4play.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  2KB  |  81 lines

  1. /*
  2.  * 4play.c
  3.  */
  4.  
  5. #include    <exec/types.h>
  6. #include    <libraries/dos.h>
  7.  
  8. #include    <stdlib.h>
  9. #include    <stdio.h>
  10.  
  11. #include    <clib/exec_protos.h>
  12.  
  13. UBYTE portdata;
  14. UBYTE *portptr = &portdata;
  15.  
  16. UBYTE firedata;
  17. UBYTE *fireptr = &firedata;
  18.  
  19. extern int getport(void);
  20. extern void read34(void);
  21. extern void freeport(void);
  22.  
  23.  
  24. /*
  25.  * Lattice control-c stop...
  26.  */
  27. int CXBRK(void) { return(0); }      /* Disable Lattice CTRL/C handling */
  28. int chkabort(void) { return(0); }   /* really */
  29.  
  30.  
  31. void Quit(char whytext[], LONG return_code)
  32. {
  33.     if(return_code==0) freeport();  /* Assembly routine to
  34.                                        de-allocate parallel port */
  35.  
  36.     printf("%s\n",whytext);
  37.  
  38.     exit(return_code);              /* returning non-zero
  39.                                        terminates the program */
  40. }
  41.  
  42.  
  43. void main(void)
  44. {
  45.     BOOL done=FALSE;
  46.     UBYTE error;
  47.  
  48.     /* getport() is an assembly routine that allocates the parallel port
  49.      * and makes all the lines we're interested in "read" lines.
  50.      */
  51.     if(error=getport()) Quit("Parallel port in use",25);
  52.     /* WARNING:
  53.      * This example continuously reads the ports and checks for CTRL_C,
  54.      * thereby eating a lot of CPU time.  Actual applications that expect
  55.      * to be even more system friendly might want to set up some interrupts
  56.      * on the fire button lines, such that the game can read the ports less
  57.      * often, but never miss a "fire" press.
  58.      */
  59.  
  60.     while(!done)
  61.     {
  62.         read34();       /* read34() is the assembly routine that copies the
  63.                          * relavent data from the port into our variables.
  64.                          */
  65.  
  66.         /* We'll just print the raw bytes from the read, and leave it as an
  67.          * exercise for the reader to mask out the relevant bits.
  68.          * (Check the pinouts to find which bits the switches appear at.)
  69.          */
  70.         printf("portdata = %u, firedata = %u\n",portdata,firedata);
  71.  
  72.         /* Check CTRL_C */
  73.         if(SetSignal(0L,0L) & SIGBREAKF_CTRL_C) /* Hit since last check? */
  74.         {
  75.             SetSignal(0L,SIGBREAKF_CTRL_C); /* Clear old status */
  76.             done=TRUE;
  77.         }
  78.     }
  79.     Quit("Ctrl-C was pressed.",0);
  80. }
  81.