home *** CD-ROM | disk | FTP | other *** search
- /* asgetc.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1985-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * int asgetc(port)
- * int port; - Port 0..MAX_PORT-1 to read
- *
- * DESCRIPTION
- * this function "gets" a character from the communications port
- * using polled mode.
- *
- * SIDE EFFECTS
- * none.
- *
- * RETURNS
- *
- * Value Meaning
- * ------ -------
- * 0 thru 255 Return value equals character received
- * ASINVPORT Requested port is out of range
- * ASNOTSETUP Requested port not setup with asifirst()
- * ASTIMEOUT Function timed out waiting for character
- * ASNOCD CD (Carrier detect) not active
- * ASNODSR DSR (Data set ready) not active
- *
- * MODIFICATIONS
- *
- * 11-01-85 Modified for release 2.0
- * 26-FEB-1987 17:35:50.00
- * Modified to use new _asgetc() function.
- */
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
-
- int GF_CONV asgetc(port)
- int port;
- {
- int retvalue,finished,timeout;
- unsigned prevenable=0;
- struct PORT_TABLE *p;
-
- if((p=_aschkcnl(port))==NULL)
- return(_aserror);
- if(p->chmode_bits.is_txint)
- prevenable|=ASOUT;
- if(p->chmode_bits.is_rxint) {
- prevenable|=ASIN;
- asihold(port,ASIN);
- }
- timeout=p->asrtime;
- for(finished=0;!finished;) {
- if(p->aswmodem) {
- if(!isdsr(port,DIRECT)) {
- retvalue= ASNODSR;
- ++finished;
- continue;
- }
- if(!iscd(port,DIRECT)) {
- retvalue= ASNOCD;
- ++finished;
- continue;
- }
- }
- if((retvalue=_asgetc(p->base_8250))!=ASTIMEOUT) {
- if(p->chmode_bits.is_ascii)
- retvalue&=0x007f;
- ++finished;
- continue;
- }
- if(!timeout) {
- retvalue= ASTIMEOUT;
- ++finished;
- continue;
- } else {
- timer(1);
- --timeout;
- }
- }
- if(prevenable)
- asiresume(port,prevenable);
- return(retvalue);
- }
-
-