/*
  Program 	: External-trigger ( PORTF.3 * /PORTF.7 ) IRQ test program.

  Description 	: This program generate the IRQ signal by the boolean function
		 f = ( PORTF.3 * /PORTF.7 ).

  Hardware setting: The DIP switch SW1 should be set as following :
		1 : OFF    2 : ON   3 : OFF   4 : ON    5,6 : DON'T CARE
		CN1 and CN2 should be connected together.

  Note		: This program can be compiled both in Turbo C 2.0 or
		  or Turbo C++ 3.0 and running under DOS environment.
*/

#include	<stdio.h>
#include	<conio.h>
#include	<dos.h>

#ifdef __cplusplus
  #define __CPPARGS		...
#else
  #define __CPPARGS
#endif

#define	BASE			0x2C0

int irq_gen;

void interrupt ( *old_irq10)(__CPPARGS);

void interrupt irq10_isr(__CPPARGS)
{
    disable();
    irq_gen = 1;
    inp(BASE+3);		// clear irq
//    outp(0xa0,0x20);	// re-enable 8259
    outp(0x20,0x20);
    enable();
}

void main(void)
{
  unsigned int i;

  outp(BASE+7,0x9B);		// port a,b,c as output
  outp(BASE+3,0x80);		// port d,e,f as input
  inp(BASE+3);			// clear previous irq
  old_irq10 = getvect(0x0d);
  setvect(0x0d, irq10_isr);
  outp(0x21, inp(0x21) & 0xdf);		// enable 8259
//  outp(0xa1, inp(0xa1) & 0xfb);
  do {
    irq_gen = 0;
    outp(BASE+2,0x08);			// !pc7 & pc3  == 1
    outp(BASE+2,0x88);			// !pc7 & pc3  == 0
    for(i=0;i<200;i++);		        // delay for a while
    if(irq_gen == 1)  printf("\n following edge  IRQ generate !!");
    else    printf("\n No IRQ generated !!");
  } while(getch()!='q');
  setvect(0x0d, old_irq10);
  outp(0x21, inp(0x21) | 0x20);		// disable irq 10 interrupt
  getch();
}