home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / resources / potgo / read9n5.c < prev   
C/C++ Source or Header  |  1980-02-02  |  3KB  |  85 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* An example of using the potgo.resource to read pins 9 and 5 of
  23.  * port 1 (the non-mouse port).  This bypasses the gameport.device.
  24.  * When the right button on a mouse plugged into port 1 is pressed,
  25.  * the read value will change.
  26.  *
  27.  * Use of port 0 (mouse) is unaffected.
  28.  *
  29.  * Lattice use lc -b1 -cfist -v -y. Link with amiga.lib and lc.lib.
  30.  */
  31. #include <exec/types.h>
  32. #include <libraries/dos.h>
  33. #include <proto/all.h>
  34. #include <stdio.h>
  35.  
  36. #ifdef LATTICE
  37. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  38. int chkabort(void) { return(0); }  /* really */
  39. #endif
  40.  
  41. struct PotgoBase *PotgoBase;
  42. ULONG potbits;
  43. UWORD value;
  44.  
  45. #define UNLESS(x) if(!(x))
  46. #define UNTIL(x)  while(!(x))
  47.  
  48. #define OUTRY 1L<<15
  49. #define DATRY 1L<<14
  50. #define OUTRX 1L<<13
  51. #define DATRX 1L<<12
  52.  
  53. void main(int argc,char **argv)
  54. {
  55.         UNLESS(PotgoBase=(struct PotgoBase *)OpenResource("potgo.resource"))
  56.             return;
  57.         printf("PotgoBase is at $%lx\n",PotgoBase);
  58.  
  59.         potbits=AllocPotBits(OUTRY|DATRY|OUTRX|DATRX);
  60.         /* Get the bits for the right and middle mouse buttons
  61.            on the alternate mouse port. */
  62.  
  63.         if(potbits != (OUTRY|DATRY|OUTRX|DATRX))
  64.             {
  65.             printf("Pot bits are already allocated! %lx\n",potbits);
  66.             FreePotBits(potbits);
  67.             return;
  68.             }
  69.  
  70.         WritePotgo(0xFFFFFFFFL,potbits);
  71.         /* Set all ones in the register (masked by potbits) */
  72.  
  73.         UNTIL(SIGBREAKF_CTRL_C & SetSignal(0L,0L))
  74.             /* until CTRL-C is pressed */
  75.             {
  76.             value=*(UWORD *)0x00DFF016;
  77.             /* Read word at $DFF016 */
  78.             printf("POTINP = $%lx\n",value & potbits);
  79.             /* Show what was read (restricted to our allocated bits) */
  80.             }
  81.  
  82.         FreePotBits(potbits);
  83. }
  84.  
  85.