/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

/* This is a program that sends interrupts to the VAX */

#include <stdio.h>
#include "lsi11_73.h"

int interval = 0;
unsigned short *csr = (unsigned short *)0175770;
unsigned short ibit = 0x1;

sendInterrupt()
{
	int k;

	if (interval)
	 { *csr &= ~ibit;
	   for (k=0; k<10; k++)		/* give VAX chance to see it */
	      ;
	   *csr |= ibit;
	   clkast (sendInterrupt, 0, interval);
	 }
}

main()
{
	char cmd = '\0';

	*csr = 0;

	do
	 { printf (">> ");
	   if ((cmd = getchar()) != '\n')
	    { while (getchar() != '\n')
		 ;
	    }
	   switch (cmd)
	    { case '?':
	       { printf (" 'q' : quit\n");
		 printf (" 'r' : set interrupt rate\n");
		 printf (" 'o' : turn interrupts off\n");
		 break;
	       }
	      case 'o':
	       { interval = 0;
		 clkast (NULL, 0, 0);
		 break;
	       }
	      case 'r':
	       { int newrate;
		 int status;

		 printf ("new rate> ");
		 status = scanf ("%d", &newrate);
		 while (getchar() != '\n')
		    ;
		 if (status != 1)
		  { printf ("Error radeing value\n");
		    continue;
		  }
		 if (interval == 0)
		  { interval = newrate/7;
		    clkast (sendInterrupt, 0, interval);
		  }
		 else
		  { interval = newrate/7;
		  }
		 break;
	       }
	      default:
	       { printf ("unknown command. Type '?' for help\n");
	       }
	    }
	 }
	while (cmd != 'q');
}
