home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4608 / en160 / start.c < prev    next >
Text File  |  1994-05-01  |  5KB  |  149 lines

  1. /****************************************************************************/
  2. /* START.C                                                                  */
  3. /*                                                                          */
  4. /* This little program shows how easy it is to begin using EnCom!  If you   */
  5. /* have ANSI.SYS loaded, this program becomes a nice ANSI terminal -- and   */
  6. /* all in only a few lines of code!                                         */
  7. /*                                                                          */
  8. /* We also have included some sample code (#define GRAPHICS 1) that shows   */
  9. /* how to use the SOURCE_TRACE version of the library when in graphics mode.*/
  10. /* all you need to do is supply a function that outputs one character to    */
  11. /* the graphics screen and we do the rest for you!  If you are not using    */
  12. /* the SOURCE_TRACE version of the library, or are working in text mode,    */
  13. /* then this is not necessary.                                              */
  14. /****************************************************************************/
  15. /* #define SOURCE_TRACE 1 */              /* uncomment for source trace!    */
  16. /* #define GRAPHICS     1 */              /* uncomment if using graphics!   */
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #ifdef __TURBOC__
  20. #include <graphics.h>
  21. #endif
  22. #include "encom.h"
  23. #include "start.h"                        /* for taking over keyboard       */
  24.  
  25. /*--------------------------- global variables -----------------------------*/
  26. PORT Port;
  27. uchar Encrypt_char, End_flag;
  28. void graphics_outc(int x, int y, int att, char c);
  29. void output_ch( int c );
  30.  
  31. /*********/
  32. /* ~main */
  33. /*       ********************************************************************/
  34. /****************************************************************************/
  35. main( int argc, char *argv[] )
  36. {
  37.   int port = COM2;
  38.   long baud = 9600L;
  39.   int c, end_flag = 0, echo = 0;
  40.  
  41. #ifdef GRAPHICS
  42.   int gdriver = DETECT, gmode;
  43.   initgraph(&gdriver, &gmode, "");
  44.   set_dbg_gchar(myoutc);
  45.   setcolor(YELLOW);
  46.   line(0,0,639,479);
  47.   line(0,479,639,0);
  48. #endif
  49.   if( argc >= 2 )
  50.   {
  51.     switch(argv[1][0])
  52.     {
  53.       case '1': port = COM1; break;
  54.       case '2': port = COM2; break;
  55.       case '3': port = COM3; break;
  56.       case '4': port = COM4; break;
  57.     }
  58.   }
  59.   if( argc >= 3 )
  60.     baud = atol(argv[2]);
  61.   if( com_port_create(port, baud,'N',8,1, 2048, 2048, &Port) < 0 )
  62.   {
  63.     printf("Cannot create COM port");
  64.     return(0);
  65.   }
  66.   init_clock(0x3333);
  67.   init_ctrlc_hdlr();
  68.  
  69.   /*--------- take over 0x23 and 0x1B to suppress CTRL-C and Break ---------*/
  70.   old_vect23 = getvect(0x23);
  71.   old_vect1b = getvect(0x1b);
  72.   setvect(0x23, en_ctrl_c);
  73.   setvect(0x1b, en_ctrl_brk);
  74.   
  75.   printf("\r\nCOM%d at %ld baud\r\n", port + 1, baud);
  76.   printf("ESC to quit - Ctrl-E to toggle Echo\r\n");
  77.   printf("To use another port, type: start [1-4] [baud_rate]\r\n");
  78.   printf("If ANSI.SYS is loaded, this will work as an ANSI terminal\r\n");
  79.   com_232_ctrl(ON, DTR | RTS | OUT2, &Port);
  80.   while( !end_flag )
  81.   {
  82.     if( (c = com_getc(&Port)) != -1 )               /* get any characters   */
  83.       output_ch(c);
  84.     if( kbhit() )
  85.     {
  86.       c = getch();
  87.       switch(c)                                     /* get the character    */
  88.       {
  89.         case 27: end_flag = 1; break;               /* esc to quit          */
  90.         case  5: echo = !echo; break;               /* ctrl-e is echo       */
  91.         case 30:                                    /* translate ctrl-c     */
  92.           if ( echo )
  93.             output_ch(3);
  94.           com_putc(3, &Port);
  95.           break;
  96.         default:
  97.           if( echo )
  98.             output_ch(c);
  99.           com_putc(c, &Port);
  100.           break;
  101.       }
  102.     }
  103.   }
  104.   setvect(0x23, old_vect23);                    /* restore ^C, ^Break     */
  105.   setvect(0x1b, old_vect1b);
  106.   end_ctrlc_hdlr();
  107.   end_clock();
  108.   com_port_destroy(&Port);
  109. #ifdef GRAPHICS
  110.   closegraph();
  111. #endif
  112.   return(1);
  113. }
  114. /*** end of main ***/
  115.  
  116. /**************/
  117. /* ~output_ch */
  118. /*            ***************************************************************/
  119. /* This simple routine outputs a character to the display using good old    */
  120. /* standard output!                                                         */
  121. /****************************************************************************/
  122. void output_ch( int c )
  123. {
  124.   fputc(c, stdout), fflush(stdout);
  125. }
  126. /*** end of output_ch ***/
  127.  
  128.  
  129. #ifdef GRAPHICS
  130. /******************/
  131. /* ~graphics_outc */
  132. /*                ***********************************************************/
  133. /* This is a little function that the library will use if in graphics mode. */
  134. /* If we are in text mode then this is not necessary!                       */
  135. /****************************************************************************/
  136. void graphics_outc(int x, int y, int att, char c)
  137. {
  138.   char buff[2];
  139.   buff[0] = c, buff[1] = '\0';
  140.   setcolor(att & 0x0f);
  141.   setfillstyle(SOLID_FILL,(att & 0xf0) >> 4);
  142.   bar(x * 8, y * 16, (x * 8) + 7, (y * 16) + 15);
  143.   outtextxy( x * 8, y * 16, buff);
  144. }
  145. /*** end of graphics_outc ***/
  146. #endif
  147.  
  148. /**** END OF FILE ****/
  149.