/*
  DIO-144      : Interrupt DEMO program

  Program 	:CN0 Port C0 IRQ test program.

  Description 	: This program generate the IRQ signal by CN0 Port C0.

  Hardware setting:  The IRQ Jumper should be set as following :

			======= IRQ 5  ======

		     The JP0 Jumper should be set to

			=======	DP     ======

		     I/O Base Address in : 0x2C0



  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>
#include        "dio144.h"


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



int irq_gen;

void interrupt ( *old_irq10)(__CPPARGS);

void interrupt irq10_isr(__CPPARGS)
{
    disable();
    irq_gen = 1;
    _DIO144_Output(CN0,Port_C,8);

				/* clear irq */
/*    outp(0xa0,0x20);		 re-enable 8259 */
    outp(0x20,0x20);
    enable();
}


void main(void)
{
  unsigned int i;

  clrscr();

  printf(" DIO-144 Interrupt demo program \n");
  printf(" I/O Address=0x220              \n");
  printf(" IRQ = 5         JP0 = DP       \n");
  printf("     Press <q> to Quit          \n");


  if(_DIO144_Init(0x2C0)) printf(" Can't Found DIO-144\n");

  _DIO144_Conf(CN0,0,0,0,0);

 /* _DIO144_Output(CN0,Port_C,9);*/
  _DIO144_Output(CN0,Port_C,0);		/* 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;
    _DIO144_Output(CN0,Port_C,9);	/* generate a irq*/


    for(i=0;i<1000;i++);
    if(irq_gen == 1)  printf("\n IRQ generate !!");
    else    printf("\n No IRQ generated !!");

  /*  _DIO144_Output(CN0,Port_C,0);*/
  } while(getch()!='q');
  setvect(0x0d, old_irq10);
  outp(0x21, inp(0x21) | 0x20);		/* disable irq 10 interrupt*/

  getch();
}