home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ASYNCH13.ZIP / MYPROG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-28  |  3.1 KB  |  119 lines

  1. /////////////
  2. /////////////
  3. //// This program is intended to get you started using the ASYNC
  4. //// library. MYPROG is just a simple little dumb (stupid, actually)
  5. //// terminal emulator. It doesn't process ANSI codes, so, depending on
  6. //// what you talk to, you may seem some strange characters from time to
  7. //// time.
  8. ////
  9. //// The first thing to do is to make sure that ASYNCS.LIB (assuming
  10. //// that you'll be using the small memory model) and ASYNC.H are in
  11. //// your LIB and INCLUDE directories, respectively. Use CREASYNC.BAT to
  12. //// create the ASYNCx.LIB files if you haven't already done so.
  13. ////
  14. //// To compile MYPROG.C, just issue the command
  15. ////
  16. ////   tcc -ms myprog asyncs.lib
  17. ////
  18. //// This will compile MYPROG.C and link it with the functions it needs
  19. //// from ASYNCS.LIB to produce the executable file MYPROG.EXE.
  20. ////
  21. //// This program was originally intended to talk to a 2400 baud modem
  22. //// using no parity, 8 data bits, and 1 stop bit. Change the parameters
  23. //// to a_open in main() if you want to change these communication
  24. //// parameters.
  25. /////////////
  26. /////////////
  27.  
  28. #include <bios.h>
  29. #include <conio.h>
  30. #include <dos.h>
  31. #include <string.h>
  32.  
  33. #include <async.h>
  34.  
  35. void dumbterm(ASYNC *port);
  36.  
  37. int main(void)
  38. {ASYNC *com2;
  39.  //
  40.  // Open COM2 at 2400 buad for no parity, 8 data bits, 1 stop bit, using
  41.  // a 4096-byte input buffer and no output buffer.
  42.  // 
  43.  com2=a_open(2,2400,PAR_NONE,8,1,4096,0);
  44.  if (!com2)
  45.   {cputs("Cannot open COM2.\r\n");
  46.    return 1;
  47.   }
  48.  //
  49.  // Start the dumb terminal emulator.
  50.  //
  51.  dumbterm(com2);
  52.  //
  53.  // Close COM2. (Never forget to do this.)
  54.  //
  55.  a_close(com2,0);
  56.  return 0;
  57. } // end of void main().
  58.  
  59. void dumbterm(ASYNC *port)
  60. {int ch,x,y;
  61.  //
  62.  // Give the user some last-minute instructions.
  63.  //
  64.  textattr(7);
  65.  cputs("Your in terminal mode now. To return to DOS, press ALT-X.\r\n");
  66.  textattr(2);
  67.  //
  68.  // Keep acting like a terminal until Alt-X is pressed.
  69.  //
  70.  do
  71.   {// If a key has been pressed, read it from the keyboard.
  72.    if (bioskey(1))
  73.      ch=bioskey(0);
  74.    else
  75.      ch=0;
  76.    // If Alt-X was pressed, leave this loop.
  77.    if (ch==0x2d00)
  78.      break;
  79.    // If a key was pressed, the scan code off of ch and transmit it.
  80.    ch&=0xff;
  81.    if (ch)
  82.      a_putc(ch,port);
  83.  
  84.    // If a character has been received, display it.
  85.    ch=a_getc(port);
  86.    if (ch!=-1)
  87.      switch(ch)
  88.       {case 0: // Ignore null characters.
  89.          break;
  90.        case 7: // Beep for bell characters.
  91.          sound(2000);
  92.          delay(50);
  93.          nosound();
  94.          delay(25);
  95.        case 8: // Do back spaces manually.
  96.          x=wherex()-1;
  97.          y=wherey();
  98.          if (x<1)
  99.           {x=80;
  100.            y--;
  101.            if (y<1)
  102.              x=y=1;
  103.           }
  104.          gotoxy(x,y);
  105.          putch(' ');
  106.          gotoxy(x,y);
  107.          break;
  108.        case '\n': // Ignore linefeeds.
  109.          break;
  110.        case '\r': // Treat carriage returns as carriage return/line feeds.
  111.          cputs("\r\n");
  112.          break;
  113.        default:
  114.          putch(ch);
  115.       }
  116.   }
  117.  while(1);
  118. } // end of dumbterm(port).
  119.