/*{IO.INC  -  I/O & timer routines }
{This version requires COM/QUAD BIOS resident!}
{Also DVTIMER!}
*/
#include <dos.h>
#define DESQ 0x15
	union REGS regs;
	char	comport;


DV_Nice()          /*Give time slice to next task*/
{
	regs.h.al = 0;
	regs.h.ah = 0x10;
	int86(DESQ, &regs, &regs);
};

DV_Crit()          /*hog time slice */
{
	regs.x.ax = 0x101B;
	int86(DESQ, &regs, &regs);
};

DV_Uncrit()          /*Give time slice to next task*/
{
	regs.x.ax = 0x101C;
	int86(DESQ, &regs, &regs);
};



char statusSIO()

/* Returns true if character is ready from the serial port */

{
    regs.x.ax = 0x0300;  /*get status*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
    return((regs.x.ax & 0x0100) != 0);
};


outSIO(char ch)

{
    regs.x.ax = 0x0100 + ch; /*send char*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
};



char inSIO()

{
    regs.x.ax = 0x0200;  /*get char*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
    return(regs.h.al);
};



char ckSIO()

  {
    regs.x.ax = 0x0800;  /*get char - leave in buffer*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
    return(regs.h.al);
  };



char DCD()        /*TRUE if CONNECTED*/

  {
    regs.x.ax = 0x0300;  /*get status*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
    return((regs.x.ax & 0x0080) != 0);
  };


send_breakSIO()

  {
    regs.x.ax = 0x0700;  /*send break*/
    regs.x.dx = comport;
    int86(0x14,&regs,&regs);
  };

dropdtr()
 {
    int i;
		for (i=0;i<8;i++){
			if(ports[1] == 1){
				regs.x.ax = 0x0500;  /* drop rts */
				regs.x.dx = i;
				int86(0x14,&regs,&regs);
			}
    }
 }

raisedtr()
 {
    int i;
		for (i=0;i<8;i++){
			if(ports[i] == 1){
				regs.x.ax = 0x0600;  /* raise rts */
				regs.x.dx = i;
				int86(0x14,&regs,&regs);
			}
    }
 }

setTIMER(int i)  /*Set # of seconds before timeout*/

  {
    regs.h.ah = 0x01;  /*set timer*/
    regs.x.cx = i;
    regs.x.dx = comport + 0xF0;    /*which timer*/
    int86(0x14,&regs,&regs);
  };


int getTIMER()

  {
    regs.h.ah = 0x00;  /*read timer*/
    regs.x.dx = comport + 0xF0;    /*which timer*/
    int86(0x14,&regs,&regs);
    return(regs.x.ax);
  };


char Timeout()  /*True if Timer = 0*/

  {
    return(getTIMER == 0);
  };


