home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * si_handl.c - serial interface handler.
- *
- * Purpose: This file contains handlers for the com1 and com2 devices.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <dos.h>
- #include "blackstr.h"
- #include "si_head.h"
-
- char si_types_[4]; /* types (line or modem) for port #'s */
-
-
- /********
- *
- * si_init(port,parms) - initialize a serial port
- *
- **/
-
- int si_init(int port, struct SI_PARMS *parms)
- {
- union REGS inregs,outregs;
- char sbyte;
-
- sbyte = parms->wbits - 5; /* bits 0-1 are word length */
- sbyte |= (parms->stop-1) << 2; /* bit 2 is stop bits */
- sbyte |= (parms->parity) << 3; /* bits 3&4 are parity */
- sbyte |= (parms->baud) << 5; /* bits 5-7 are speed */
-
- inregs.x.dx = port;
- inregs.h.ah = 0; /* command to set port */
- inregs.h.al = sbyte; /* init byte for bios */
- int86(0x14,&inregs,&outregs);
- si_types_[port] = parms->type; /* save type of port */
- return(outregs.x.ax);
- }
-
-
- /********
- *
- * si_stat(port) - get port status
- *
- **/
-
- int si_stat(int port)
- {
- union REGS inregs,outregs;
-
- inregs.x.dx = port;
- inregs.h.ah = 3; /* command to get status */
- int86(0x14,&inregs,&outregs);
- return(outregs.x.ax);
- }
-
-
- /********
- *
- * si_out(port,c) - output byte to port
- *
- **/
-
- int si_out(int port, char c)
- {
- union REGS inregs,outregs;
-
- inregs.x.dx = port;
- inregs.h.ah = 1;
- inregs.h.al = c; /* output byte */
- int86( 0x14,&inregs,&outregs);
- return(outregs.x.ax);
- }
-
-
- /********
- *
- * si_inp(port) - input byte from port
- *
- **/
-
- int si_inp(int port)
- {
- union REGS inregs,outregs;
-
- inregs.x.dx = port;
- inregs.h.ah = 2;
- int86(0x14,&inregs,&outregs);
- if(outregs.h.ah)
- return(ERROR);
- else
- return((int)outregs.h.al);
- }
-
-
- /********
- *
- * si_putc(port,c) - put a character to the serial port
- *
- **/
-
- int si_putc(int port, char c)
- {
- while(!(si_stat(port)& 0x60)) ; /* wait for tx buff empty */
- return(si_out(port,c));
- }
-
-
- /********
- *
- * si_getc(port) - get character from a serial port
- *
- **/
-
- int si_getc(int port)
- {
- if (si_stat(port) & 0x0100) /* wait for data ready */
- return(si_inp(port));
- else
- return(0);
- }
-
-
-