home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_04 / v6n4069a.txt < prev    next >
Text File  |  1989-09-28  |  2KB  |  50 lines

  1. /* trsifm.mxc */      /**********************************************/
  2. #define BASAD 0xe8    /* Trs-80 serial port number.                 */
  3. #define CTRL_C 3      /* Ascii code for CTRL-C.                     */
  4. #define BAUD 0x55     /* For 300 baud.                              */
  5. #define COMBITS 0x6f  /* 8 data, 1 stop, no parity.                 */
  6. int comerror ;        /* Framing, parity, overrun, error flag.      */
  7.  
  8. void cleanup() {}     /* Dummy routine for compatibility.           */
  9.  
  10. void setcom()          /******* Initialize communications.  *********/
  11. { outp(BASAD,0x02) ;            /* Reset TR1602 UART.               */
  12.   outp(BASAD+2,COMBITS) ;       /* Set data, stop, parity.          */
  13.   outp(BASAD+1,BAUD) ;          /* Set baud rate.                   */
  14.   outp(BASAD,0) ;               /* Set UART for action.             */
  15.   comerror = 0 ;                /* Clear error flag.                */
  16. }
  17.  
  18. static int status()  /****** Read UART status and update  ***********/
  19. { int b ;             /* comerror for framing, parity, and          */
  20.   b = inp(BASAD+2) ;  /* overrun errors.                            */
  21.   comerror |= (((b & 32) >> 5) | ((b & 16) >> 3) | ((b & 8) >> 1)) ;
  22.   return(b) ;
  23. }
  24.  
  25. int rxready() { return( status() & 0x80 ) ; } /* Rx byte available? */
  26.  
  27. int rxbyte()  { return( inp(BASAD+3) ) ; }    /* Get rx byte.  ******/
  28.  
  29. int txready() { return( status() & 0x40) ; }  /* Tx register empty? */
  30.  
  31. void txbyte(b) int b ; { outp(BASAD+3,b) ; }  /* Send tx byte.  *****/
  32.  
  33. static int kbuf=0 ;                           /* Byte buffer.       */
  34. static int kbflag=0 ;                         /* Byte flag.         */
  35. int kbhit()            /************ Kb byte available? *************/
  36. { if( kbflag ) return(1) ;                    /* Byte is waiting.   */
  37.   kbuf = getkey() ;                           /* Get something.     */
  38.   if( kbuf == CTRL_C ) exit(1) ;              /* If CTRL-C, exit.   */
  39.   if( kbuf == EOF )  return(0) ;              /* No byte available. */
  40.   kbflag = 1 ;                                /* Byte waiting.      */
  41.   return(1) ;                                 /* Byte available.    */
  42. }
  43.  
  44. int getch()                  /******** Get Kb byte. *****************/
  45. { while( !kbhit() )   ;                       /* Wait for byte.     */
  46.   kbflag = 0 ;                                /* Remove, clear flag,*/
  47.   return( kbuf ) ;                            /* & return byte.     */
  48. }
  49.  
  50.