/* inhand.c                                      MC404B
   C interrupt handler routine - sets PC speaker to a given frequency,
   turns on speaker for a few seconds (depends on your CPU speed)
   then turns off speaker and restores previous settings;
   adapted from www.ece.edy/~fjlooft/tc/intr.htm - Celio G. 22 Oct 2001
*/
#include <dos.h>
	void interrupt (* oldint)();
	void interrupt mybeep(unsigned bp, unsigned di, unsigned si,
					  unsigned ds, unsigned es, unsigned dx,
					  unsigned cx, unsigned bx, unsigned ax)

	{   unsigned i, j;
		char originalbits, bits;
		unsigned char bcount = ax >> 8;      /* Get port setting */
		outportb(0x43,182);                  /* set frequency to 261.63hz*/
		outportb(0x42,0xd0);                 /* code is 4560=0x 11d0 */
		outportb(0x42,0x11);
		bits = originalbits = inportb(0x61);
		outportb(0x61, bits | 3);            /* Turn on speaker */
		for (i = 0; i <= bcount*8; i++)      /*delay a few seconds*/
		{
		   for (j = 0; j < 65535; j++) ;
		}
		outportb(0x61, bits & 0xfc);         /* Turn off speaker */
		outportb(0x61, originalbits);        /* Restore port setting */
	}

void install(void interrupt (*faddr)(), int inum)
	{
	    setvect(inum, faddr);
	}

void testbeep(unsigned char bcount, int inum)
	{
	    _AH = bcount;
	    geninterrupt(inum);
	}

main()
	{   char ch;
	    oldint= getvect(250);
	    install(mybeep,250);
	    testbeep(255,250);
	    install(oldint,250);
	    /*  ch = getch();*/
	}
