home *** CD-ROM | disk | FTP | other *** search
- /*
- // CPORT.H
- //
- // Header file for Cport Communications Library
- //
- // Copyright (c) 1991 Bri Productions
- //
- */
-
- #if defined __TURBOC__
- #if __STDC__
- #define _Cdecl
- #else
- #define _Cdecl cdecl
- #endif
- #elif defined __ZTC__
- #define _Cdecl
- #elif defined M_I86 && !defined __ZTC__
- #if !defined NO_EXT_KEYS
- #define _Cdecl cdecl
- #else
- #define _Cdecl
- #endif
- #endif
-
-
-
- /*
- //-------------------------------------
- //
- // com ports
- //
- //-------------------------------------
- */
-
- #define PORT0 0x03F8
- #define PORT1 0x02F8
- #define PORT2 0x03E8
- #define PORT3 0x02E8
-
- #define IRQ2 0xA000
- #define IRQ3 0xB000
- #define IRQ4 0xC000
- #define IRQ5 0xD000
- #define IRQ6 0xE000
- #define IRQ7 0xF000
-
- #define COM1 (PORT0 | IRQ4)
- #define COM2 (PORT1 | IRQ3)
- #define COM3 (PORT2 | IRQ4)
- #define COM4 (PORT3 | IRQ3)
-
- #define BIOS0 (*(int far *)0x400000l)
- #define BIOS1 (*(int far *)0x400002l)
- #define BIOS2 (*(int far *)0x400004l)
- #define BIOS3 (*(int far *)0x400006l)
-
-
- /*
- //-------------------------------------
- //
- // baud rate divisors
- //
- //-------------------------------------
- */
-
- #define B115200 1
- #define B57600 2
- #define B38400 3
- #define B19200 6
- #define B9600 12
- #define B7200 16
- #define B4800 24
- #define B3600 32
- #define B2400 48
- #define B2000 58
- #define B1800 64
- #define B1200 96
- #define B600 192
- #define B300 384
- #define B150 768
- #define B110 1047
- #define B75 1536
- #define B50 2304
-
-
-
- /*
- //-------------------------------------
- //
- // word lengths
- //
- //-------------------------------------
- */
-
- #define W8 3
- #define W7 2
- #define W6 1
- #define W5 0
- #define WMASK 3
-
-
-
- /*
- //-------------------------------------
- //
- // stop bits
- //
- //-------------------------------------
- */
-
- #define S1 0
- #define S2 4
- #define SMASK 1
-
-
-
- /*
- //-------------------------------------
- //
- // parity
- //
- //-------------------------------------
- */
-
- #define NONE 0x00
- #define ODD 0x08
- #define EVEN 0x18
- #define MARK 0x28
- #define SPACE 0x38
- #define PMASK 0x38
-
-
-
- /*
- //-------------------------------------
- //
- // handshaking
- //
- //-------------------------------------
- */
-
- #define DTR 0x01
- #define RTS 0x02
- #define S_RX 0x04
- #define S_TX 0x08
- #define CTS 0x10
- #define DSR 0x20
- #define DCD 0x80
-
- #define SOFT ((S_RX) | (S_TX))
- #define HARD ((RTS)| (CTS))
- #define HARD1 ((DTR)| (DSR))
- #define HARD2 ((RTS)| (CTS))
-
-
-
- /*
- //-------------------------------------
- //
- // error codes
- //
- //-------------------------------------
- */
-
- #define OVERUN 0x002 /* overrun error */
- #define PARITY 0x004 /* parity error */
- #define FRAMING 0x008 /* framing error */
- #define BREAK 0x010 /* break detect */
- #define RX_FIFO 0x080 /* error in recieve fifo */
- #define TXFULL 0x100 /* transmit queue overflow */
- #define RXFULL 0x200 /* receive queue overflow */
-
-
-
- /*
- //-------------------------------------
- //
- // status codes
- //
- //-------------------------------------
- */
-
- #define DCTS 0x01 /* delta clear to send */
- #define DDSR 0x02 /* delta data set ready */
- #define TERI 0x04 /* trailing edge ring indicator */
- #define DDCD 0x08 /* delta data carrier detect */
- #define CTS 0x10 /* clear to send */
- #define DSR 0x20 /* data set ready */
- #define RI 0x40 /* ring indicator */
- #define DCD 0x80 /* data carrier detect */
-
-
-
- /*
- //-------------------------------------
- //
- // byte typedef and parameter structure
- //
- //-------------------------------------
- */
-
- #ifndef BYTE
- #define BYTE
- typedef unsigned char byte;
- #endif
-
- /** Do not change this structure **/
-
- struct C_param{
- unsigned com; /* com port */
- int baud; /* baud rate */
- byte mode; /* word length, stop bits, parity */
- unsigned rxQ; /* receive queue size */
- unsigned txQ; /* transmit queue size */
- byte htype; /* handshaking type */
- unsigned thresh; /* handshaking threshold (rx queue) */
- };
-
-
-
- /*
- //-------------------------------------
- //
- // some other constants
- //
- //-------------------------------------
- */
-
- #define ON 1
- #define OFF 0
-
-
-
- /*
- //-------------------------------------
- //
- // ComOpen return codes
- //
- //-------------------------------------
- */
-
- #define NO_ERR 0 /* no error */
- #define OPENED 1 /* port already opened */
- #define BAD_COM 2 /* bad 'com' parameter */
- #define NO_UART 3 /* no uart chip found */
- #define RCV_ALC 4 /* receive queue allocation error */
- #define TX_ALC 5 /* transmit queue allocation error */
- #define MAX_PORT 6 /* max number of com ports opened */
- #define IRQ_CTN 7 /* interrupt contention */
- #define NOT_OPEN 8 /* com not opened (ComActive) */
-
-
- /*
- //-------------------------------------
- //
- // function macros
- //
- //-------------------------------------
- */
-
- #define ComOut1(a) ComMcr(a, 0x04)
- #define ComRts(a) ComMcr(a, 0x02)
- #define ComDtr(a) ComMcr(a, 0x01)
-
-
-
- /*
- //-------------------------------------
- //
- // function prototypes
- //
- //-------------------------------------
- */
-
- /* control functions */
-
- int _Cdecl ComOpen (unsigned com, int baud, byte mode, unsigned rxQ, unsigned txQ);
- int _Cdecl ComOpenS (const struct C_param *param);
- void _Cdecl ComParam (const struct C_param *param);
- void _Cdecl ComClose (void);
- void _Cdecl ComBaud (int baud);
- void _Cdecl ComMode (byte mode);
- void _Cdecl ComHandshake (byte htype, unsigned thresh);
- void _Cdecl ComTx (byte on_off);
- int _Cdecl ComActive (unsigned com);
- void _Cdecl ComCloseAll (void);
-
- /* input functions */
-
- char _Cdecl ComGetc (void);
- char *_Cdecl ComGets (char *str, int max_c, char term_c);
- unsigned _Cdecl ComIn (void *abyte, unsigned n_byte);
- char _Cdecl ComPeek (void);
- unsigned _Cdecl ComLenRx (void);
- void _Cdecl ComFlushRx (void);
-
-
- /* output functions */
-
- int _Cdecl ComPutc (char c);
- int _Cdecl ComPuts (const char *str);
- unsigned _Cdecl ComOut (const void *abyte, unsigned n_byte);
- unsigned _Cdecl ComLenTx (void);
- void _Cdecl ComFlushTx (void);
-
-
- /* status functions */
-
- void _Cdecl ComMcr (byte on_off, byte bits);
- unsigned _Cdecl ComError (void);
- byte _Cdecl ComStatus (void);
-
-
- /* misc fuctions */
-
- void _Cdecl ComSetBreak (void);
- void _Cdecl ComClrBreak (void);
- void _Cdecl ComPutScrtch (byte abyte);
- byte _Cdecl ComGetScrtch (void);
-
-
- byte _Cdecl ComChecksum (const void *abyte, unsigned n_byte);
- unsigned _Cdecl ComCrc16 (const void *abyte, unsigned n_byte);
-