home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / INTERCOM.C < prev    next >
Text File  |  1992-01-20  |  4KB  |  170 lines

  1. /*
  2. **                ---  intercom.c ---
  3. **
  4. **  EXAMPLE CODE: This example is meant to be a simple 2 user intercom
  5. **  system. Run on two systems connected via modem or null modem cable.
  6. **
  7. **  This example program (not the PCL4C library) is donated to
  8. **  the Public Domain by MarshallSoft Computing, Inc. It is
  9. **  provided as an example of the use of the PCL4C.
  10. **
  11. */
  12.  
  13. #include <stdio.h>
  14. #include "pcl4c.h"
  15.  
  16. #define FALSE 0
  17. #define TRUE !FALSE
  18. #define ESC 0x1b
  19. #define EOL 0x0d
  20.  
  21. #define HOR 205
  22. #define VER 186
  23. #define URC 187
  24. #define LRC 188
  25. #define ULC 201
  26. #define LLC 200
  27. #define CLC 204
  28. #define CRC 185
  29.  
  30. #define NORMAL 0x07
  31.  
  32. /*** Global Variables ***/
  33.  
  34. int Port = 0;             /* COM port # 0 ( COM1 ) */
  35. int BaudCode = Baud2400;  /* Code for 2400 baud  */
  36. char RxBuf[64];           /* PCL4C receive buffer  */
  37. int SrcRow = 1;           /* cursor row for outgoing */
  38. int SrcCol = 1;           /* cursor column for outgoing */
  39. int DstRow = 13;          /* cursor row for incoming */
  40. int DstCol = 1;           /* cursor column for incoming */
  41.  
  42. /*** Main ***/
  43.  
  44. main(argc,argv)
  45. int argc;
  46. char *argv[];
  47. {int row;
  48.  char c;
  49.  int i, rc;
  50.  /* get port number */
  51.  if(argc!=2)
  52.      {printf("Usage: 'INTERCOM port ' -- example 'INTERCOM 1'\n");
  53.       exit(1);
  54.      }
  55.  /* get port number from command line */
  56.  Port = atoi(argv[1]) - 1;
  57.  if((Port<0) || (Port>3))
  58.      {printf("ERROR: Port must be 1 to 4\n");
  59.       exit(1);
  60.      }
  61.  /* setup receive buffer */
  62.  ErrorCheck( SioRxBuf(Port,RxBuf,Size64) );
  63.  /* set port parmameters */
  64.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  65.  /* reset the port */
  66.  ErrorCheck( SioReset(Port,BaudCode) );
  67.  /* clear screen */
  68.  Scroll(0,0,24,79,0,7);
  69.  /* draw top horizontal bar */
  70.  Position(0,0);
  71.  putchar(ULC);
  72.  Duplicate(HOR,22);
  73.  printf(" INTERCOM 1.0: Type <ESC> to exit ");
  74.  Duplicate(HOR,22);
  75.  putchar(URC);
  76.  /* draw vertical bars to reach middle horizontal bar */
  77.  for(row=1;row<=11;row++)
  78.    {Position(row,0);  AttrWrite(VER,NORMAL);
  79.     Position(row,79); AttrWrite(VER,NORMAL);
  80.    }
  81.  /* draw middle horizontal bar */
  82.  Position(12,0);
  83.  putchar(CLC);
  84.  Duplicate(HOR,78);
  85.  putchar(CRC);
  86.  /* draw vertical bars to reach bottom horizontal bar */
  87.  for(row=13;row<=23;row++)
  88.    {Position(row,0);  putchar(VER);
  89.     Position(row,79); putchar(VER);
  90.    }
  91.  /* draw bottom horizontal bar */
  92.  Position(24,0);
  93.  putchar(LLC);
  94.  Duplicate(HOR,78);
  95.  /* position cursor */
  96.  Position(SrcRow,SrcCol);
  97.  /* enter intercom loop */
  98.  while(TRUE)
  99.      {/* was key pressed ? */
  100.       if(SioKeyPress())
  101.           {i = SioKeyRead();
  102.            if((char)i==ESC)
  103.               {/* restore COM port status & exit */
  104.                SioDone(Port);
  105.                exit(1);
  106.               }
  107.            else
  108.               {/* send over serial line */
  109.                SioPutc(Port,i);
  110.                /* echo in our area */
  111.                DisplayChar(i,&SrcRow,&SrcCol,1);
  112.               }
  113.           } /* end if */
  114.       /* any incoming over serial port ? */
  115.       i = SioGetc(Port,0);
  116.       if(i>-1) DisplayChar(i,&DstRow,&DstCol,13);
  117.      } /* end while */
  118. } /* end main */
  119.  
  120. int DisplayChar(Ch,RowPtr,ColPtr,FirstRow)
  121. char Ch;
  122. int  *RowPtr;
  123. int  *ColPtr;
  124. int  FirstRow;
  125. {/* position cursor */
  126.  Position(*RowPtr,*ColPtr);
  127.  /* write character */
  128.  if(Ch==(char)EOL)
  129.     {/* next line */
  130.      *ColPtr = 78;
  131.     }
  132.  else AttrWrite(Ch,NORMAL);
  133.  /* advance cursor */
  134.  Advance(RowPtr,ColPtr,FirstRow);
  135. } /* end DisplayChar */
  136.  
  137. int Advance(RowPtr,ColPtr,FirstRow)
  138. int  *RowPtr;
  139. int  *ColPtr;
  140. int  FirstRow;
  141. {(*ColPtr)++;
  142.  if(*ColPtr==79)
  143.      {(*RowPtr)++;
  144.       if(*RowPtr==FirstRow+11)
  145.           {Scroll(FirstRow,1,FirstRow+10,78,1,7);
  146.            *RowPtr = FirstRow+10;
  147.            *ColPtr = 1;
  148.           }
  149.        else *ColPtr = 1;
  150.       }
  151.  /* position cursor */
  152.  Position(*RowPtr,*ColPtr);
  153. } /* end Advance */
  154.  
  155.  
  156. int ErrorCheck(Code)
  157. int Code;
  158. {/* trap PCL error codes */
  159.  if(Code<0)
  160.      {SioError(Code);
  161.       exit(1);
  162.      }
  163. } /* end ErrorCheck */
  164.  
  165. int Duplicate(Ch, Count)
  166. char Ch;
  167. int Count;
  168. {int i;
  169.  for(i=1;i<=Count;i++) putchar(Ch);
  170. } /* end Duplicate */