/*
  DIO-24      : Interrupt DEMO program

  Program       :Port C0 IRQ test program.

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

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

			======= J1 : IRQ 5  ======

		     The J2 Jumper should be set to

			======= PGM    ======

		     The J3 Jumper should be set to

			======= 1 2    ======


		     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        "dio24.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;
    _DIO24_Output(Port_C,8);

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


void main(void)
{
  unsigned int i;

  clrscr();

  printf(" DIO-24 Interrupt demo program \n");
  printf(" I/O Address=0x220              \n");
  printf(" J1 :IRQ 5     J2 : PGM    J3 : 1 2   \n");
  printf("     Press <q> to Quit          \n");


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

  _DIO24_Conf(0,0,0,0);

 
  _DIO24_Output(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;
    _DIO24_Output(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 !!");
 
  } while(getch()!='q');
  setvect(0x0d, old_irq10);
  outp(0x21, inp(0x21) | 0x20);         /* disable irq 10 interrupt*/

  getch();
}