home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / termp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  2.3 KB  |  66 lines

  1. /*                      Terminal Emulator Program with Printing
  2. */
  3.  
  4. #include "slib.h"
  5.  
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. /*      main()
  10.  
  11.         Function: Display data coming from COM1 on the screen, and send
  12.         keystrokes from the keyboard out to COM1. If F1 is pressed,
  13.         toggle into print-also mode, where each input is also sent to
  14.         the printer port.
  15.  
  16.         Algorithm: Loop, waiting for data from either side to appear.
  17.         Use keyChk to see if there's anything from the keyboard; if
  18.         there is, send it using serSend. Use serRecv to check if
  19.         there's anything from the serial port; if there is, display
  20.         it using putTty, and if we're in print mode, also print it
  21.         using prtPrint.
  22. */
  23.  
  24. main()
  25.  
  26. {
  27.         int ch;         /* Character to transfer. */
  28.         int printOn;    /* TRUE if printing is toggled on. */
  29.  
  30.         /* Initialize the printer. */
  31.         prtInit(0);
  32.         printOn = FALSE;
  33.  
  34.         /* Initialize the serial port. */
  35.         serInit(0,B1200+DB8+SB1+PNONE);
  36.  
  37.         /* Main loop. */
  38.         while (TRUE) {
  39.                 /* Check for keyboard input. */
  40.                 if (keyChk(&ch)) {
  41.                         /* If yes, clear the character from the queue. */
  42.                         keyRd();
  43.                         /* Check for non-ASCII. */
  44.                         if ((ch & 0xFF) == 0) {
  45.                                 /* Check for F1 key. */
  46.                                 if (((ch>>8) & 0xFF) == 59) 
  47.                                         /* If F1, toggle print mode. */
  48.                                         printOn = !printOn;
  49.                                 else break;
  50.                         };
  51.                         /* Send the character out the serial port. */
  52.                         serSend(0,ch);
  53.                 };
  54.                 /* Anything available from the serial port? */
  55.                 if (serStat(0) & RCVDRDY) {
  56.                         /* If so, read it in. */
  57.                         ch = serRecv(0);
  58.                         /* And put it on the screen. */
  59.                         putTty(0,ch,3);
  60.                         /* If we're in print mode, print it as well. */
  61.                         if (printOn) prtPrint(0,ch);
  62.                 };
  63.         };
  64. }
  65.  
  66.