/*
	"Generic" Fido driver; all functions go
	through INT 14. 

	Provides serial services for your program as described
	in FOSSIL.DOC.

	27 Feb 91
	Tom Jennings
	This is now the "FOSSIL" interface.

	This is not a pretty source. Please refer to FOSSIL.DOC
	to make any sense of it.

*/

/* External variables. Defined within your program. */

extern int cd_bit;		/* BBS bit pattern for checking CD */

extern int iodev;		/* channel # */


/* Public string identifying which driver the program is linked to. */

char driver_id[] = "FOSSIL driver interface";

/* ---------------------------------------------------------------- */

/* Serial drivers follow. */

init() {
	int14(4,0x83,iodev);			/* set baud/init hardware, */
}

uninit() {
	int14(5,0,iodev);
}
/* Get a character from the modem. This just returns the character, no checking
for ready, etc. That is all done before this is called.  */

_mconin() {
	return(int14(2,0,iodev) & 0xff);	/* Call ROM BIOS, */
}

/* Return true if the output buffer is empty. */

_mbusy() {

	return(int14(3,0,iodev) & 0x0040);
}

/* Generate a line break. */

_mbreak() {
}

/* Flush the output buffer. */

_mflush() {

	int14(9,0,iodev);
}


/* Output a character to the modem. Just output, error checking, ready check,
etc is done before this is called. */

_mconout(c)
char c;
{
	int14(1,c,iodev);
}

/* Return true if the modem is ready to accept a character. */

_mconostat() {
	return(int14(3,0,iodev) & 0x2000);
}

/* Return true if the modem has a character to read. */

_mconstat() {
	return(int14(3,0,iodev) & 0x100);
}

/* Return true if the DSR, or modem ready, line is true. This should return
true whenever the modem is ready and has a carrier detect, and false otherwise.
 */

_cd() {

	return(int14(3,0,iodev) & cd_bit);
}

/* Set the baud rate. */

static int baudtbl[] = {
	300,0x43,
	1200,0x83,
	2400,0xa3,
	4800,0xc3,
	9600,0xe3,
	19200,0x03,
	38400,0x23,
	0,0
};
baud(r)
int r;
{
int i;

	for (i= 0; baudtbl[i]; i+= 2) 
		if (baudtbl[i] == r) break;
	if (baudtbl[i] == 0) return(0);
	int14(0,baudtbl[i + 1],iodev);
	return(r);
}
/* Raise DTR. Reinitializing the port does it. */

raise_dtr() {
	int14(6,1,iodev);
}
/* Lower DTR. Do the baud set trick to flush the
output buffer. */

lower_dtr() {
	int14(6,0,iodev);
}
