home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / 4dser100 / serial.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-21  |  1.4 KB  |  71 lines

  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <4dlib.h>
  5. #include <4Dserial.h>
  6.  
  7. // Demonstration of a simple terminal for the 4D Serial Library.
  8.  
  9. // USEAGE SERIAL <base> <IRQ>          base of 1016 = 3f8, 760 = 2f8
  10. // Demo is designed for regular async mode, not fossil or digiboard.
  11.  
  12. void main(int, char *argv[]) {
  13.  
  14. unsigned        bas;
  15. char            ts[20];
  16. unsigned char    c;
  17. int             a = 0,b = 0,i;
  18.  
  19.     bas = atoi(argv[1]);
  20.     i = atoi(argv[2]);
  21.     if (SERIAL_OpenPort(SERIAL_ASYNC,bas,i,2400,'N',8,1) != 0) {
  22.         printf("\nINITILIZATION ERROR: [%d]\n",c);
  23.         exit(1);
  24.     }
  25.     clrscr();
  26.  
  27.     for(;;) {
  28.         if (SERIAL.Error) {
  29.             printf(">>>%d<<<",SERIAL.Error);
  30.             SERIAL.Error = 0;
  31.         }
  32.         if (kbhit()) {
  33.             c = getch();
  34.             if (c == 0x001B) {  // End program //
  35.                 SERIAL_ClosePort();
  36.                 break;
  37.             } else
  38.             if (c == '~') {
  39.                 SERIAL_TransmitStr("Jeff Jones\r");
  40.             } else
  41.             if (c == 0x00) {
  42.                 SERIAL_TransmitChar(c);
  43.                 c = getch();
  44.             }
  45.             SERIAL_TransmitChar(c);
  46.         }
  47.         if ((c = SERIAL_ReceiveChar())!=0) { // Received a char //
  48.             c = SERIAL_ReceiveChar();
  49.             if (c == '\n') {
  50.                 b++;
  51.             } else
  52.             if (c == '\r') {
  53.                 a = 0;
  54.             } else
  55.             if (c == 8) {
  56.                 if (a > 0) a--;
  57.             } else {
  58.                 fastprintchar(b, a, 14, 0, c);
  59.                 if (a++ > 79) {
  60.                     b++;
  61.                     a = 0;
  62.                 }
  63.             }
  64.             if (b>23) {
  65.                 fastscrollup(14, 0);
  66.                 b--;
  67.             }
  68.             gotoxy(a+1,b+1);
  69.         }
  70.     }
  71. }