home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / ASGETC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  2.5 KB  |  87 lines

  1. /* asgetc.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asgetc(port)
  8. *  int port;            - Port 0..MAX_PORT-1 to read
  9. *
  10. * DESCRIPTION
  11. *  this function "gets" a character from the communications port
  12. *  using polled mode.
  13. *
  14. * SIDE EFFECTS
  15. *  none.
  16. *
  17. * RETURNS
  18. *
  19. *       Value           Meaning
  20. *       ------          -------
  21. *       0 thru 255      Return value equals character received
  22. *       ASINVPORT       Requested port is out of range
  23. *       ASNOTSETUP      Requested port not setup with asifirst()
  24. *       ASTIMEOUT       Function timed out waiting for character
  25. *       ASNOCD          CD (Carrier detect) not active
  26. *       ASNODSR         DSR (Data set ready) not active
  27. *
  28. * MODIFICATIONS
  29. *
  30. *  11-01-85    Modified for release 2.0
  31. *  26-FEB-1987  17:35:50.00
  32. *       Modified to use new _asgetc() function.
  33. */
  34. #include <stdio.h>
  35. #include "gf.h"
  36. #include "asiports.h"
  37.  
  38. int GF_CONV asgetc(port)
  39. int port;
  40. {
  41.         int retvalue,finished,timeout;
  42.         unsigned prevenable=0;
  43.         struct PORT_TABLE *p;
  44.  
  45.         if((p=_aschkcnl(port))==NULL)
  46.                 return(_aserror);
  47.         if(p->chmode_bits.is_txint)
  48.                 prevenable|=ASOUT;
  49.         if(p->chmode_bits.is_rxint) {
  50.                 prevenable|=ASIN;
  51.                 asihold(port,ASIN);
  52.         }
  53.         timeout=p->asrtime;
  54.         for(finished=0;!finished;) {
  55.                 if(p->aswmodem) {
  56.                         if(!isdsr(port,DIRECT)) {
  57.                                 retvalue= ASNODSR;
  58.                                 ++finished;
  59.                                 continue;
  60.                         }
  61.                         if(!iscd(port,DIRECT)) {
  62.                                 retvalue= ASNOCD;
  63.                                 ++finished;
  64.                                 continue;
  65.                         }
  66.                 }
  67.                 if((retvalue=_asgetc(p->base_8250))!=ASTIMEOUT) {
  68.                         if(p->chmode_bits.is_ascii)
  69.                                 retvalue&=0x007f;
  70.                         ++finished;
  71.                         continue;
  72.                 }
  73.                 if(!timeout) {
  74.                         retvalue= ASTIMEOUT;
  75.                         ++finished;
  76.                         continue;
  77.                 } else {
  78.                         timer(1);
  79.                         --timeout;
  80.                 }
  81.         }
  82.         if(prevenable)
  83.                 asiresume(port,prevenable);
  84.         return(retvalue);
  85. }
  86.  
  87.