Listing 4 (intin.c)

/***    INTERRUPT TO HANDLE DATA RECEIVED    ***/

#include "serial.h"

extern  int portbase;

static  char  buf[SBUFSIZ];
static  int  bufptr   = 0;
static  int  byteptr  = 0;

extern void (interrupt far *oldvect)();

void interrupt far ReceiveData(void)
{
  
  if((inp(portbase + IIR) & RX_MASK) == RX_ID)
    {
     buf[bufptr++] = inp(portbase + RXR);
     
     if(bufptr >= SBUFSIZ)
       bufptr = 0;
    }

/***     Signal end of hardware interrupt    ***/
  
  outp(ICR,EOI);
  
  (*oldvect)();
}

/***         GRABS A BYTE FROM BUFFER        ***/

int IntSerialIn(void)
{
  int Char_Value;
  
  if (byteptr == bufptr)
    {
     return (-1);
    }
  
  Char_Value = (int)buf[byteptr++];
  
  if(byteptr >= SBUFSIZ)
    byteptr = 0;
  
  return (Char_Value);
}
/* End of File */