
#include "dos.h"
#include "conio.h"

/**** interrupt occurred flag				****/
int	time_out;

/**** Start the event wait flag routine		****/
void setup_flag_wait( void);

/**** Stop the event wait flag routine		****/
void clear_flag_wait( void);

void main( void)

	{/* test program to check out flag wait	   */

	/**** clear the screen					****/
	clrscr();						

	/**** start initial flag event			****/
	setup_flag_wait();

	/**** until a keypress happens			****/
	while ( !kbhit())							
		{ 
								
		/**** timer interrupt ?				****/
		 if ( time_out) 
			{
			 setup_flag_wait();
			 putch('T');	
			}
		}
			
	/**** Stop the last event wait 			****/
	clear_flag_wait();

}


void setup_flag_wait( void)

	{/* Start set flag after delay function.	*/
	 /* Call interrupt 0x15 with ah = 0x83 and	*/
	 /* al = 0.  Registers CX, DX is the delay	*/
	 /* time in microseconds. And BX,ES is a 	*/
	 /* pointer to the flag byte.				*/

	 /**** Structures for the interrupt call ****/
	union REGS inregs, outregs;
	struct SREGS sregs;

	/**** Pointer to the flag byte			 ****/
	char far* temp = (char far*)&time_out;

	/**** Clear the flag byte				 ****/
	time_out = 0;

	/**** Load registers for interrupt call	 ****/
	inregs.h.ah = 0x83;
	inregs.h.al = 0;

	sregs.es = FP_SEG( temp);
	inregs.x.bx = FP_OFF( temp);
	inregs.x.cx = 0;
	inregs.x.dx = (unsigned)50000L;

	/**** Call set flag after delay function ****/
	int86x( 0x15, &inregs, &outregs, &sregs);
   }


void clear_flag_wait( void)

	{/* Stop the flag wiat function by calling	*/
	/* the interrupt 0x15 with ah = 0x83 and	*/
	/* al = 1									*/

	 /**** Structures for the interrupt call	*/
	union REGS inregs, outregs;
	struct SREGS sregs;
	char far* temp = (char far*)&time_out;

	/**** Load registers for interrupt call	 ****/
	inregs.h.ah = 0x83;
	inregs.h.al = 1;

	sregs.es = FP_SEG( temp);
	inregs.x.bx = FP_OFF( temp);

	/**** Call set flag after delay function ****/
	int86x( 0x15, &inregs, &outregs, &sregs);
   }
	