#ifdef sgi

/* program to test the xyd driver on SGI systems */

#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/file.h>

#include "../sys/rciext/xydreg.h"
#include "../sys/rciext/rciioctl.h"

int fd;

main()
{
	fd_set rfds;
	int qsize = 2;

	if ((fd = open("/dev/xyd0", O_RDWR)) < 0)
	 { perror ("/dev/xyd0:");
	   exit (1);
	 }
	if (ioctl (fd, RCIIOC_CONFIRM, 0) < 0)
	 { perror ("CONFIRM ioctl");
	   exit (1);
	 }
	if (ioctl (fd, RCIIOC_SET_INTRQ, qsize) < 0)
	 { perror ("SET INTRQ ioctl");
	   exit (1);
	 }
	if (ioctl (fd, RCIIOC_INTR_ENABLE, 1) < 0)
	 { perror ("INTR ENABLE ioctl");
	   exit (1);
	 }
	while (1)
	 { int n;
	   char ack;
	   FD_ZERO (&rfds);
	   FD_SET (fd, &rfds);
	   printf ("waiting ...\n");
	   n = select (FD_SETSIZE, &rfds, 0, 0, 0);
	   if (n < 0)
	    { perror ("select:");
	      exit (1);
	    }
	   else
	    { n = read (fd, &ack, 1);
	      if (n < 0)
	       { perror ("read:");
		 exit (1);
	       }
	      else if (n == 0)
	       { fprintf (stderr, "read returned 0\n");
		 exit (1);
	       }
	      else if (ack != 1)
	       { fprintf (stderr, "ack = 0x%x\n", ack);
		 exit (1);
	       }
	      else
	       { printf ("got interrupt\n");
	       }
	    }
	 }		
}

#endif
