/* EXAMPLE IN MICROSOFT C */

#define PORT 0x330                  /* base of the 4 ports */
#define RADIX 10                    /* for decimal counters */
#define FLAG (inp(PORT) & 0x80)     /* test for switch flag */

main()
      {
      long x,y,z,rctr();
      int i;
      outp(PORT,0);                 /* clear the counters */
      outp(PORT+3,0);               /* select status */
      if(inp(PORT) & 0x30)          /* (bits should be zero) */
            {
            printf("No board found at port %x\n",PORT);
            exit(1);
            }
      puts("Please press digitizing switch ten times.");
      for(i=0; i<10; i++)           /* main loop: read & display */
            {
            inp(PORT+3);            /* clear flag */
            outp(PORT+3,0);         /* select status */
            while(!FLAG)
                  ;                 /* hang waiting for switch */
            if(inp(PORT) & 0x40)
                  {
                  printf("***THERE HAS BEEN A RATE ERROR***\n");
                  exit(1);
                  }
            outp(PORT,1);            /* copy to holding reg */
            inp(PORT+3);            /* clear flag */
            x = rctr(1);
            y = rctr(2);
            z = rctr(3);
            printf("Data point %2d:  x=%8ld,  y=%8ld,  z=%8ld\n",
                    i,x,y,z);
            }
      printf("Ten values read, all done\n");
      }

long rctr(c)                        /* read one counter */
int c;
      {
      long v;
      outp(PORT+3,c);               /* select a counter */
      v = inp(PORT);
      v = v*RADIX + inp(PORT);
      v = v*RADIX + inp(PORT);
      v = v*RADIX + inp(PORT);
      v = v*RADIX + inp(PORT);
      v = v*RADIX + inp(PORT);
      return(v);
      }


