home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / CKPM5X_S.ZIP / CKOTEK.C < prev    next >
C/C++ Source or Header  |  1990-05-18  |  32KB  |  1,043 lines

  1. /******************************************************************************
  2. File name:  ckogra.c    Rev: 01  Date: 08-Dec-89 Programmer: C.P.Armstrong
  3.  
  4. File title: Contains the Tektronix emulation code
  5.  
  6. Contents:   
  7.  
  8. Modification History:
  9.     01  08-Dec-89   C.P.Armstrong   created
  10.  
  11. ******************************************************************************/
  12. #define INCL_DOS
  13. #define INCL_WIN
  14. #define INCL_GPIPRIMITIVES
  15. #define INCL_AVIO
  16. #include <OS2.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19.  
  20. #include "ckcasc.h"
  21. #include "ckcker.h"
  22. #include "ckopm.h"
  23. #include "ckotek.h"
  24. #include "ckokey.h"
  25.  
  26. #define POST_DELAY 100L     /* Duration of pause after failure to post a */
  27.                             /* graphics command */
  28.  
  29. void vt100(unsigned char);
  30. void ipadl25(void);
  31.  
  32.  
  33. int far Term_mode=VT100;    /* Default mode is VT100 */
  34. int far Alpha_mode=1;       /* Write at g cursor or t cursor position */
  35. char far process_mode=0;    /* Are we in the midst of processing ESC or */
  36.                             /* vector or nothing */
  37. char far last_process=0;    /* Escape commands don't exit FS or GS mode */
  38. char far first_vec=0;
  39. int far indx=0;             /* Index into character processing buffer */
  40. int far tekg_x=0;           /* Current tek coords of current graphics */
  41. int far tekg_y=0;           /* position */
  42. int far teka_x=0;
  43. int far teka_y=0;           /* Current tek alphanumeric coords */
  44.         
  45. int far dump_plot=1;        /* Dump file of any plotting for printing */
  46. int far dump_format=NODMP;  /* Default dump file format is HPGL */
  47.  
  48. SHORT   poly_plot_count;    /* Poly line plotting variables */
  49. PPOINTL poly_plot_array;
  50. char draw_mode;
  51.  
  52. char far gin_terminator=CR; /* Character send at end of GIN address */
  53. char far mouse_but1='C';
  54. char far mouse_but2=' ';
  55. char far mouse_but3='E';
  56.  
  57.  
  58. char process_buf[PROCBUFSIZE];   /* buffer for string being processed */
  59.  
  60. /******************************************************************************
  61. Function:       Tek_scrinit()
  62.  
  63. Description:    Initialises the system for doing Tektronix emulation.
  64.                 Does nothing for OS/2 PM
  65.  
  66. Syntax:         int Tek_scrinit(page)
  67.                     int page;  Clear screen if 1, don't if 0
  68.  
  69. Returns:        0 if can't do Tektronix
  70.                 1 if init was sucessful
  71.  
  72. Mods:           08-Dec-89 C.P.Armstrong created
  73.                 30-Jan-90 C.P.Armstrong Updates VT100 line 25
  74.  
  75. ******************************************************************************/
  76. int Tek_scrinit(page)
  77.     int page;
  78.     {
  79.     extern int dump_plot;
  80.     extern int tekg_x,tekg_y;
  81.     extern int teka_x,teka_y;
  82.     extern char *usertext;
  83.  
  84.     /* Under OS/2 a graphics card is virtually mandatory - and the PM window */
  85.     /* is already alive.  We could hide the VT100 screen though.             */
  86.  
  87.     /* Open up the plot dump file - if required */
  88.     if(dump_plot)
  89.         gfile_open();
  90.  
  91.  
  92.     if(page)
  93.         Tek_page();
  94.  
  95.     return(1);
  96.     }
  97.     
  98. /******************************************************************************
  99. Function:       Tek_finish()
  100.  
  101. Description:    Finishes Tek emulation mode. Closes the dump file if necessary.
  102.                 And any other Tek exiting things that are required.
  103.  
  104. Syntax:         void Tek_finish()
  105.  
  106. Returns:        nothing
  107.  
  108. Mods:           02-Mar-90 C.P.Armstrong created
  109.  
  110. ******************************************************************************/
  111. void Tek_finish()
  112.     {
  113.     extern int Term_mode;
  114.     extern int dump_plot;
  115.     
  116.     Term_mode = VT100;
  117.     
  118.     if(dump_plot)
  119.         gfile_close();
  120.  
  121.     }
  122.  
  123. /******************************************************************************
  124. Function:       Tek_process()
  125.  
  126. Description:    Processes characters sent from rdserwrtscr().
  127.  
  128. Syntax:         void Tek_process(c)
  129.                     unsigned c;  The character to be processed
  130.  
  131. Returns:        nothing
  132.  
  133. Mods:           08-Dec-89 C.P.Armstrong created
  134.  
  135. ******************************************************************************/
  136. void Tek_process(c)
  137.     unsigned c;  /* The character to be processed */
  138.     {
  139.     extern char first_vec;
  140.     extern char process_mode;
  141.     extern char last_process;
  142.     extern int indx;
  143.     extern HWND cdecl hwndGFrame;
  144.     
  145.     int rejected=0;
  146.  
  147.     do
  148.         {
  149.         switch(c)           /* Look for special characters first */
  150.             {
  151.             case (VK_SHPRINTSCRN<<8):  /* Shift printscreen button */
  152.                 gfile_dump();
  153.                 return;
  154.             case SYN:       /* Delay characters */
  155.             case NUL:
  156.                 return;
  157.             case RS:
  158.                 Tek_changemode(INCREMODE);
  159.                 return;
  160.             case FS:
  161.                 indx=0;
  162.                 first_vec=0;
  163.                 Tek_changemode(PVECTMODE);
  164.                 return;
  165.             case GS:
  166.                 first_vec=1;
  167.                 indx=0;
  168.                 Tek_changemode(VECTMODE);
  169.                 return;
  170.             case US:
  171.                 Tek_changemode(ALPHAGRA);
  172.                 indx=0;
  173.                 return;
  174.             case CR:
  175.                 if(process_mode==GINMODE)
  176.                     Tek_ginend();
  177.  
  178.                 if(process_mode!=ALPHANUM)
  179.                     {
  180.                     Tek_changemode(ALPHANUM);
  181.                     indx=0;
  182.                     return;
  183.                     }
  184.                  
  185.                  break;
  186.             case ESC:
  187.                 Tek_changemode(ESCMODE);
  188.                 indx=0;
  189.                 return;
  190.             default:
  191.                 break;
  192.             }
  193.  
  194.         switch(process_mode)                /* It's not a special character */
  195.             {
  196.             case VECTMODE:
  197.             case PVECTMODE:
  198.                 if(c & 0x60)  /* Vector mode is exited by sending a */
  199.                     rejected=Tek_gsprocess((char)c);/* non-Tek coord character*/
  200.                 else                                /* or if the process      */
  201.                     rejected=1;                     /* buffer is full.        */
  202.  
  203.                 if(rejected)               /* Enter default mode and reprocess*/
  204.                     {                      /* character.                      */
  205.                     indx=0;
  206.                     Tek_changemode(ALPHANUM); 
  207.                     }
  208.                 break;
  209.             case ESCMODE:
  210.                 rejected = Tek_escprocess((char) c);
  211.                 break;
  212.             case BYPASS:
  213.             case GINMODE:       /* Input is ignored if in GIN mode */
  214.                 break;
  215.             case INCREMODE:
  216.                 rejected = Tek_incmode((char)c);
  217.                 break;
  218.             case ALPHANUM:
  219.             case ALPHAGRA:
  220.             default:
  221.                 Tek_write((char)c);
  222.                 rejected = 0;   /* If all else fails print the character */
  223.             }       /* End of process_mode switch */
  224.         }while(rejected==1);    /* try reprocessing the character */
  225.     return;
  226.     }
  227.  
  228.  
  229. /******************************************************************************
  230. Function:       Tek_gsprocess()
  231.  
  232. Description:    Receives and decodes tektronix plot codes.
  233.                 Also handles the dot drawing mode.
  234.  
  235. Syntax:         int Tek_gsprocess(c)
  236.                     char c;  A component of a Tek plot code
  237.  
  238. Returns:        0 if no error, 1 if invalid character
  239.  
  240. Mods:           08-Dec-89 C.P.Armstrong created
  241.                 11-Feb-90 C.P.Armstrong FS mode handling added
  242.  
  243. ******************************************************************************/
  244.  
  245. int Tek_gsprocess(c)
  246.     char c;  /* A component of a Tek plot code */
  247.     {
  248.     extern char process_buf[];
  249.     extern char first_vec;
  250.     extern int indx;  /* Index into the process buf */
  251.  
  252.     int x,y;            /* New x and y coords to go to */
  253.  
  254.     /* Ignore spurious CRs and LFs */
  255.     if((c==CR) || (c==LF))
  256.         return(0);
  257.     else if(indx<PROCBUFSIZE)
  258.         process_buf[indx]=c;
  259.     else
  260.         return(1);
  261.  
  262.     /* Was it a LO_X */
  263.     if((process_buf[indx] & LO_Y_EX)!=LO_X)
  264.         {
  265.         indx++;
  266.         return(0);
  267.         }
  268.     Tek_vectdecode(&x,&y);
  269.  
  270.     if(process_mode == PVECTMODE)
  271.         {
  272.         Tek_gplot(x,y);
  273.         }
  274.     else
  275.         {
  276.         if(first_vec)        /* First vector after GS is address to move to */
  277.             {
  278.             Tek_gmove(x,y);
  279.             first_vec=0;
  280.             }
  281.         else
  282.             {
  283.             if(draw_mode!=1) /* Turn poly plotting on */
  284.                 Tek_poly(1);
  285.             Tek_gdraw(x,y);
  286.             }
  287.         }        
  288.     indx=0;
  289.     return(0);
  290.     }
  291.  
  292. /******************************************************************************
  293. Function:       Tek_vectdecode()
  294.  
  295. Description:    Converts the tek 4/5 characters into X and Y coordinates.
  296.  
  297. Syntax:         void Tek_vectdecode(x,y)
  298.                     int * x; Returned x coord
  299.                     int * y; Returned y coord
  300.  
  301. Returns:        nothing
  302.  
  303. Mods:           11-Dec-89 C.P.Armstrong
  304.  
  305. ******************************************************************************/
  306. void Tek_vectdecode(x,y)
  307.     int * x; /* Returned x coord */
  308.     int * y; /* Returned y coord */
  309.     {
  310.     extern char process_buf[];
  311.     static char hi_x=0;     /* These are statics as less than 4 bytes can be */
  312.     static char hi_y=0;     /* send.  Under these cricumstances the previous */
  313.     static char lo_x=0;     /* values for the unsent bytes must be used. I   */
  314.     static char lo_y=0;     /* think!                                        */
  315.     static char lsbxy=0;
  316.  
  317.     int had_y=0;
  318.     int had_lx=0;
  319.     int had_lsbxy=0;
  320.     int flag=0;
  321.     int hi_res_mode=0;
  322.     int pbi=0;
  323.     
  324.     /* Abbreviated address decoding regime ;
  325.         Only HI Y changes       Hi Y and Lo X sent
  326.         Only LO Y changes       Lo Y and Lo X sent
  327.         Only Hi X changes       Lo Y Hi X and Lo X sent
  328.         Only Lo X changes       Lo X sent
  329.  
  330.     There is no way of knowing whether the address mode is 1024 or 4096.  This
  331.     is a pity as the decoding methods are different.  One requires expanding
  332.     by 32, the other by 128.
  333.     */
  334.  
  335.     pbi=0;
  336.  
  337.     do                                              /* Whoever dreamed this */
  338.         {                                           /* up should be shot    */
  339.         flag = process_buf[pbi] & LO_Y_EX;
  340.         if(flag==HI_X_Y)
  341.             {
  342.             if(had_y)
  343.                 hi_x=process_buf[pbi];
  344.             else
  345.                 {
  346.                 hi_y=process_buf[pbi];
  347.                 had_y=1;
  348.                 }
  349.              }
  350.         else if(flag==LO_Y_EX)
  351.             {
  352.             if((process_buf[pbi+1] & LO_Y_EX)==LO_Y_EX)
  353.                 {
  354.                 lsbxy=process_buf[pbi];
  355.                 lo_y=process_buf[pbi+1];
  356.                 had_lsbxy=1;
  357.                 pbi++;
  358.                 }
  359.              else                       
  360.                 {                       
  361.                 lo_y=process_buf[pbi];
  362.                 }
  363.              had_y=1;
  364.              }
  365.         else if(flag==LO_X)
  366.             {
  367.             lo_x=process_buf[pbi];
  368.             had_lx=1;
  369.             }
  370.         pbi++;
  371.     }while((!had_lx) && pbi<PROCBUFSIZE);
  372.  
  373.     /* Convert the separate bytes to x,y coords */
  374.     *x = (hi_x-32)*32 + (lo_x-64);
  375.     *y = (hi_y-32)*32 + (lo_y-96);
  376.  
  377.     /* The hires mode bytes sent for 4096 by 4096 mode effectively ignored */
  378.     /* as they cause X and Y to multiplied by 4.  Since the max values used*/
  379.     /* by the emulator are 1024 X and Y would only have to be divided by   */
  380.     /* 4, thus losing the LSBXY bits.  However the code below could be used*/
  381.     /* to put all values into 4014 space, should 4096 by 4096 ever be      */
  382.     /* resolvable.                                                         */
  383. //    if(!had_lsbxy)      /* lsbxy is always received in 4014 mode.  So if it */
  384. //        lsbxy=0;        /* wasn't received make sure that it is zero.       */
  385. //    *x = (*x << 2) + (lsbxy&3);
  386. //    *y = (*y << 2) + ((lsbxy&12)>>2);
  387.  
  388.     return;
  389.     }
  390.  
  391. /******************************************************************************
  392. Function:       Tek_gmove()
  393.  
  394. Description:    Does a Tek graphics move
  395.  
  396. Syntax:         void Tek_gmove(x,y)
  397.                     int x,y;  Coords to move to
  398.  
  399. Returns:        nothing
  400.  
  401. Mods:           11-Dec-89 C.P.Armstrong created
  402.  
  403. ******************************************************************************/
  404.  
  405. void Tek_gmove(x,y)
  406.     int x,y;  /* Coords to move to */
  407.     {
  408.     extern int dump_plot;
  409.     extern int tekg_x,tekg_y;
  410.     extern HWND cdecl hwndGFrame;
  411.     while(!WinPostMsg(hwndGFrame,WM_USER,MPFROM2SHORT(x,y),MPFROMCHAR('m')))
  412.         {
  413.         DosSleep(POST_DELAY);
  414.         }
  415.     tekg_x = x;
  416.     tekg_y = y;
  417.     
  418.     if(dump_plot);
  419.         gfile_move(x,y);
  420.     }
  421.     
  422. /******************************************************************************
  423. Function:       Tek_gdraw()
  424.  
  425. Description:    Draws a line from the current graphics position to the
  426.                 point x,y.
  427.  
  428. Syntax:         void Tek_gdraw(x,y)
  429.                     int x,y;  Coord to draw line to
  430.  
  431. Returns:        nothing
  432.  
  433. Mods:           11-Dec-89 C.P.Armstrong created
  434.  
  435. ******************************************************************************/
  436. void Tek_gdraw(x,y)
  437.     int x,y;  /* Coord to draw line to */
  438.     {
  439.     extern int dump_plot;
  440.     extern int tekg_x,tekg_y;
  441.     extern HWND cdecl hwndGFrame;
  442.     extern char draw_mode;
  443.     extern SHORT poly_plot_count;
  444.     extern PPOINTL poly_plot_array;  /* Pointer to array of POINTLs */
  445.  
  446.     if(draw_mode==0)
  447.         {
  448.         while(!WinPostMsg(hwndGFrame,WM_USER,MPFROM2SHORT(x,y),
  449.           MPFROMCHAR('d')))
  450.             {
  451.             DosSleep(POST_DELAY);
  452.             }
  453.         }
  454.  
  455.     else
  456.         {
  457.         poly_plot_array = (PPOINTL) realloc(poly_plot_array,
  458.             sizeof(POINTL)*(poly_plot_count+1));
  459.         poly_plot_array[poly_plot_count].x=x;
  460.         poly_plot_array[poly_plot_count].y=y;
  461.         poly_plot_count++;
  462.         }
  463.         
  464.     tekg_x = x;
  465.     tekg_y = y;
  466.     if(dump_plot)
  467.         gfile_draw(x,y);
  468.     }
  469.  
  470. /******************************************************************************
  471. Function:       Tek_gplot()
  472.  
  473. Description:    Plot a point at position point x,y.
  474.  
  475. Syntax:         void Tek_gplot(x,y)
  476.                     int x,y;  Coord to draw line to
  477.  
  478. Returns:        nothing
  479.  
  480. Mods:           11-Dec-89 C.P.Armstrong created
  481.  
  482. ******************************************************************************/
  483. void Tek_gplot(x,y)
  484.     int x,y;  /* Coord to plot at */
  485.     {
  486.     extern int dump_plot;
  487.     extern int tekg_x,tekg_y;
  488.     extern HWND cdecl hwndGFrame;
  489.     while(!WinPostMsg(hwndGFrame,WM_USER,MPFROM2SHORT(x,y),MPFROMCHAR('d')))
  490.         {
  491.         DosSleep(POST_DELAY);
  492.         }
  493.     tekg_x = x;
  494.     tekg_y = y;
  495.     if(dump_plot)
  496.         gfile_plot(x,y);
  497.     }
  498.  
  499.  
  500.  
  501. /******************************************************************************
  502. Function:       Tek_page()
  503.  
  504. Description:    Clears the Tektronix emulation screen - the Gpi window - and
  505.                 homes the graphics cursor.
  506.  
  507. Syntax:         void Tek_page()
  508.  
  509. Returns:        nothing
  510.  
  511. Mods:           12-Dec-89 C.P.Armstrong created
  512.  
  513. ******************************************************************************/
  514. void Tek_page()
  515.     {
  516.     extern int dump_plot;
  517.     extern int tekg_x,tekg_y;
  518.     extern HWND cdecl hwndGFrame;
  519.     while(!WinPostMsg(hwndGFrame,WM_USER,0,MPFROMCHAR('c')))
  520.         {
  521.         DosSleep(POST_DELAY);
  522.         }
  523.  
  524.     Tek_gmove(0,0);
  525.     tekg_x = 0;
  526.     tekg_y = 0;
  527.  
  528.     if(dump_plot)
  529.         {
  530.         gfile_rewind();
  531.         gfile_move(0,0);
  532.         }
  533.  
  534.     }
  535.  
  536. /******************************************************************************
  537. Function:       Tek_escprocess()
  538.  
  539. Description:    Processes escape strings
  540.  
  541. Syntax:         int Tek_escprocess(c)
  542.                     char c;
  543.  
  544. Returns:        0 if no error, 1 if invalid character
  545.  
  546. Mods:           11-Dec-89 C.P.Armstrong dummy created
  547.                 01-Feb-90 C.P.Armstrong GIN processing added
  548.                 29-Apr-90 C.P.Armstrong Tek mode exit via esc sequence updates
  549.                                         status line.
  550. ******************************************************************************/
  551. int Tek_escprocess(c)
  552.     char c; 
  553.     {
  554.     extern char process_buf[];
  555.     extern char process_mode;
  556.     extern char last_process;
  557.     extern int indx;  /* Index into the process buf */
  558.     static char esctype;
  559.  
  560.     switch(c)
  561.         {
  562.         case 'a':
  563.         case 'b':
  564.         case 'c':
  565.         case 'd':
  566.         case 'e':
  567.         case '`':
  568.             Tek_setlinetype(c);
  569.             break;
  570.  
  571.         case 'E':
  572.             Tek_status();
  573.             break;
  574.         case 'Z':
  575.             Tek_termid();
  576.             break;
  577.         case CR:
  578.         case LF:
  579.             return(0);
  580.         case FF:
  581.             Tek_page();
  582.             break;
  583.         case SUB:                   /* Control-Z */
  584.             Tek_ginini();           /* Start gin mode */
  585.             return(0);              /* Do not resotor previous mode */
  586.         case '[':
  587.             esctype=SQBRA;
  588.             return(0);              /* Command incomplete - get the rest */
  589.         case '"':
  590.             esctype=QUOTE;
  591.             return(0);              /* command incomplete - get the rest */
  592.         default:
  593.             if(indx<PROCBUFSIZE)
  594.                 {
  595.                 process_buf[indx]=c;
  596.                 indx++;
  597.                 }
  598.             else    /* If buffer is full then quit escaping */
  599.                 break;
  600.  
  601.             switch(esctype)
  602.                 {
  603.                 case SQBRA:
  604.                     if(c>='a' && c<='z')  /* ESC [ commands end in a letter */
  605.                         {
  606.                         process_buf[min(indx,PROCBUFSIZE)]='\0';
  607.                         if(strcmp(process_buf,"?38l")==0)
  608.                             {
  609.                             Tek_finish();
  610.                             ipadl25();  /* Reset the status lines */
  611.                             esctype=0;
  612.                             }
  613.                         }       /* End of test for end of command received */
  614.                     else        /* Not got end of command so get the rest */
  615.                         return(0);
  616.                     break;
  617.                 case QUOTE:
  618.                     if(c=='g')
  619.                         {
  620.                         if(process_buf[indx-2]=='4' || 
  621.                             process_buf[indx-2]=='5')
  622.                             Tek_ginini();
  623.                         }
  624.                     else
  625.                         return(0);  /* Not got end of command so get the rest */
  626.                     break;
  627.                 default:
  628.                     break;
  629.                 }           /* End of multiple char interpretation */
  630.             break;
  631.             }               /* End of main esc process switch */
  632.  
  633.     /* Only completed ESC commands get here - so terminate escape processing */
  634.     /* and restore the previous mode.                                        */
  635.     Tek_endesc();
  636.     return(0);
  637.     }
  638.     
  639. /******************************************************************************
  640. Function:       Tek_write()
  641.  
  642. Description:    Prints a character in Tek alphanumeric mode and advances the
  643.                 alpha cursor to the next position.
  644.  
  645. Syntax:         void Tek_write(c)
  646.                     char c;  The character to display
  647.  
  648. Returns:        nothing
  649.  
  650. Mods:           11-Dec-89 C.P.Armstrong dummy created
  651.  
  652. ******************************************************************************/
  653. void Tek_write(c)
  654.     char c;  /* The character to display */
  655.     {
  656.     extern HWND cdecl hwndGFrame;
  657.     extern int tekg_x,tekg_y;
  658.     extern char process_mode;
  659.     MPARAM mp1;
  660.     char cell[2];
  661.     cell[1]=0;
  662.     cell[0]=c;
  663.  
  664.     switch(process_mode)
  665.         {
  666.         case ALPHAGRA:
  667.             mp1 = MPFROMP(cell);
  668.             while(!WinPostMsg(hwndGFrame,WM_USER,mp1,MPFROMCHAR('s')))
  669.                 {
  670.                 DosSleep(POST_DELAY);
  671.                 }
  672.             
  673.             if(dump_plot)
  674.                 gfile_print(cell);
  675.  
  676.             tekg_x+=MAXCHARWIDTH;  /* This depends on the character size in use */
  677.             Tek_gmove(tekg_x,tekg_y);
  678.             break;
  679.         case ALPHANUM:
  680.             /* For time being send it to Vio screen using vt100 write mode */
  681.             vt100(c);
  682.             break;
  683.         default:
  684.             break;
  685.         }
  686.     return;
  687.     }
  688.     
  689. /******************************************************************************
  690. Function:       Tek_endesc()
  691.  
  692. Description:    Terminates ESC sequence processing and returns to the previous
  693.                 processing mode.
  694.  
  695. Syntax:         void Tek_endesc()
  696.  
  697. Returns:        nothing
  698.  
  699. Mods:           11-Feb-90 C.P.Armstrong created
  700.  
  701. ******************************************************************************/
  702. void Tek_endesc()
  703.     {
  704.     extern char process_mode;
  705.     extern char last_process;
  706.     extern int indx;
  707.  
  708.     Tek_changemode(last_process);
  709.     indx=0;
  710.     return;
  711.     }
  712.  
  713.  
  714. /******************************************************************************
  715. Function:       Tek_ginini()
  716.  
  717. Description:    Puts the Tektronix emulator into GIN mode.  This causes a
  718.                 cross hair cursor to be displayed on the graphics screen.
  719.                 When the user presses a button or presses a key, the coords
  720.                 of the mouse are read and sent to the host.  The coords, if
  721.                 echoed by the host, or not printed on screen.  The reading and
  722.                 encoding of the coords are dealt with by the PM thread.  This
  723.                 inserts the values into the keyboard buffer where it is read
  724.                 and sent by the vt100read routine.
  725.  
  726. Syntax:         void Tek_ginini()
  727.  
  728. Returns:        nothing
  729.  
  730. Mods:           01-Feb-90 C.P.Armstrong created
  731.  
  732. ******************************************************************************/
  733. void Tek_ginini()
  734.     {
  735.     extern char process_mode;
  736.     extern int indx;
  737.     extern HWND cdecl hwndGFrame;
  738.     
  739.     if(process_mode == GINMODE)
  740.         return;
  741.     else
  742.         Tek_changemode(GINMODE);
  743.         
  744.     indx=0;
  745.     
  746.     /* Tell the PM thread to put to enter GIN mode */
  747.     SetGinMode(hwndGFrame,1);
  748.     
  749.     return;
  750.     }
  751.  
  752. /******************************************************************************
  753. Function:       Tek_ginend()
  754.  
  755. Description:    Puts the Tektronix emulator back into alphanumeric mode,
  756.                 removes the cross hair cursor and enables echoing of characters
  757.                 if necessary.
  758.  
  759. Syntax:         void Tek_ginend()
  760.  
  761. Returns:        nothing
  762.  
  763. Mods:           01-Feb-90 C.P.Armstrong created
  764.  
  765. ******************************************************************************/
  766. void Tek_ginend()
  767.     {
  768.     extern char process_mode;
  769.     extern int indx;
  770.     extern HWND cdecl hwndGFrame;
  771.  
  772.     if(process_mode != GINMODE)
  773.         return;
  774.  
  775.     indx=0;
  776.     
  777.     /* Tell the PM thread to enter GIN mode */
  778.     SetGinMode(hwndGFrame,0);
  779.     
  780.     return;
  781.     }
  782.  
  783. /******************************************************************************
  784. Function:       Tek_ginencode()
  785.  
  786. Description:    Encodes a graphics position into Tektronix coords for
  787.                 sending as a GIN response.
  788.                                                                 
  789.                 N.B. The buffer to receive the encoded coords must be at least
  790.                 7 characters long, 4 for the coords, 1 for the char and 1 for
  791.                 the GIN terminator and 1 for the NUL terminator.
  792.  
  793. Syntax:         Tek_ginencode(x,y,c,gin_term,buf)
  794.                     int x,y;    Coords to encode
  795.                     char c,gin_term ;    Character to be sent, GIN terminator
  796.                     char * buf; Buffer to receive encoded coords
  797.  
  798. Returns:        nothing
  799.  
  800. Mods:           01-Feb-90 C.P.Armstrong created
  801.  
  802. ******************************************************************************/
  803. void Tek_ginencode(x,y,c,gin_term,buf)
  804.     int x,y;    /* Coords to encode */
  805.     char c,gin_term ;    /* Character to be sent */
  806.     char * buf; /* Buffer to receive encoded coords */
  807.     {
  808.     buf[0] = c;
  809.     buf[1] = (char) ( (x / 32) + 32 );             /* Hi-X */
  810.     buf[2] = (char) ( (x % 32) + 32 );             /* Lo-X */
  811.     buf[3] = (char) ( (y / 32) + 32 );             /* Hi-Y */
  812.     buf[4] = (char) ( (y % 32) + 32 );             /* Lo-Y */
  813.     buf[5] = gin_term;
  814.     buf[6]=0;
  815.     return;
  816.     }
  817.     
  818. /******************************************************************************
  819. Function:       Tek_setlinetype()
  820.  
  821. Description:    Sets the line type used when drawing lines.
  822.                 The Tek line style characters are;
  823.                     a   fine dots
  824.                     b   short dashes
  825.                     c   dash dot
  826.                     d   long dash dot
  827.                     e   dash dot dot
  828.                     `   solid line
  829.                 By a stroke of luck these coincide almost exactly with the 
  830.                 Gpi line styles.
  831.  
  832. Syntax:         void Tek_setlinetype(c)
  833.                     char c;     Tek line type character
  834.  
  835. Returns:        nothing
  836.  
  837. Mods:           11-Feb-90 C.P.Armstrong created
  838.  
  839. ******************************************************************************/
  840. void Tek_setlinetype(c)
  841.     char c;     /* Tek line type character */
  842.     {
  843.     extern HWND cdecl hwndGFrame;
  844.     LONG gpi_linestyle;
  845.     switch(c)
  846.         {
  847.         case 'a' :  gpi_linestyle=LINETYPE_DOT;break;
  848.         case 'b' :  gpi_linestyle=LINETYPE_SHORTDASH;break;
  849.         case 'c' :  gpi_linestyle=LINETYPE_DASHDOT;break;
  850.         case 'd' :  gpi_linestyle=LINETYPE_LONGDASH;break;
  851.         case 'e' :  gpi_linestyle=LINETYPE_DASHDOUBLEDOT;break;
  852.         case '`' :  gpi_linestyle=LINETYPE_SOLID;break;
  853.         default  :  gpi_linestyle=LINETYPE_SOLID;break;
  854.         }
  855.  
  856.     while(!WinPostMsg(hwndGFrame,WM_USER,MPFROMLONG(gpi_linestyle),
  857.       MPFROMCHAR('l')))
  858.         {
  859.         DosSleep(POST_DELAY);
  860.         }
  861.     }
  862.  
  863. /******************************************************************************
  864. Function:       Tek_incmode()
  865.  
  866. Description:    Processes the Tek increment mode characters.
  867.  
  868. Syntax:         int Tek_incmode(c)
  869.                     char c;  Tek increment chartacters
  870.  
  871. Returns:        0 if a valid character, 1 otherwise
  872.  
  873. Mods:           11-Feb-90 C.P.Armstrong created
  874.  
  875. ******************************************************************************/
  876. int Tek_incmode(c)
  877.     char c;  /* Tek increment chartacters */
  878.     {
  879.     extern int dump_plot;
  880.     extern int tekg_x,tekg_y;
  881.     extern HWND cdecl hwndGFrame;
  882.  
  883.     static char pen=' ';
  884.     
  885.     switch(c)
  886.         {
  887.         case 'P':           /* The "Pen" commands */
  888.         case ' ':  pen=c;
  889.             return(0);
  890.         case 'A': tekg_x++;         break;
  891.         case 'E': tekg_x++;tekg_y++;break;
  892.         case 'D': tekg_y++;         break;
  893.         case 'F': tekg_x--;tekg_y++;break;
  894.         case 'B': tekg_x--;         break;
  895.         case 'J': tekg_x--;tekg_y--;break;
  896.         case 'H': tekg_y--;         break;
  897.         case 'I': tekg_x++;tekg_y--;break;
  898.         default:
  899.             return(1);
  900.         }    
  901.     if(pen==' ')
  902.         {
  903.         while(!WinPostMsg(hwndGFrame,WM_USER,MPFROM2SHORT(tekg_x,tekg_y),
  904.           MPFROMCHAR('m')))
  905.             {
  906.             DosSleep(POST_DELAY);
  907.             }
  908.         if(dump_plot)
  909.             gfile_move(tekg_x,tekg_y);
  910.         }
  911.     else
  912.         {
  913.         while(!WinPostMsg(hwndGFrame,WM_USER,MPFROM2SHORT(tekg_x,tekg_y),
  914.           MPFROMCHAR('p')))
  915.             {
  916.             DosSleep(POST_DELAY);
  917.             }
  918.         if(dump_plot)
  919.             gfile_plot(tekg_x,tekg_y);
  920.         }
  921.  
  922.     return(0);
  923.     }
  924.  
  925. /******************************************************************************
  926. Function:       Tek_status()
  927.  
  928. Description:    Not implimented yet
  929.  
  930. Syntax:         void Tek_status()
  931.  
  932. Returns:        
  933.  
  934. Mods:           
  935.  
  936. ******************************************************************************/
  937. void Tek_status()
  938.     {
  939.     return;
  940.     }
  941.  
  942. /******************************************************************************
  943. Function:       Tek_termid()
  944.  
  945. Description:    Not implimented yet
  946.  
  947. Syntax:         void Tek_termid()
  948.  
  949. Returns:        nothing
  950.  
  951. Mods:           
  952.  
  953. ******************************************************************************/
  954. void Tek_termid()
  955.     {
  956.     return;
  957.     }
  958.     
  959. /******************************************************************************
  960. Function:       Tek_poly()
  961.  
  962. Description:    Handles the starting and finishing of polyline drawing mode.
  963.                 In theory every Tek draw command can be a polyline.  Of course
  964.                 most of them are simple single line draws.
  965.  
  966. Syntax:         void Tek_poly(mode)
  967.                     int mode;  0 for end, 1 for start polyline drawing
  968.  
  969. Returns:        nothing
  970.  
  971. Mods:           14-Jan-90 C.P.Armstrong created
  972.                 13-Feb-90 C.P.Armstrong Modified for Kermit
  973. ******************************************************************************/
  974. void Tek_poly(mode)
  975.     int mode;  /* 0 for end, 1 for start polyline drawing */
  976.     {
  977.     extern PPOINTL poly_plot_array;  /* Pointer to array of POINTLs */
  978.     extern SHORT   poly_plot_count;  /* no. of POINTLs in array     */
  979.     extern char    draw_mode;        /* are we doing a poly line    */
  980.     extern HWND cdecl hwndGFrame;
  981.     
  982.     if(mode==1 && draw_mode==0)
  983.         {
  984.         poly_plot_count=0;
  985.         draw_mode=1;
  986.         poly_plot_array=(PPOINTL) malloc(0);  /* Set up a block */
  987.         }
  988.      else if(mode==0 && draw_mode==1)
  989.         {
  990.         draw_mode=0;            /* Don't bother doing a poly line for 1 point */
  991.         if(poly_plot_count==1)
  992.             {
  993.             Tek_gdraw((int)poly_plot_array[0].x,(int)poly_plot_array[0].y);
  994.             free(poly_plot_array);
  995.             }
  996.         else            
  997.             {
  998.             while(!WinPostMsg(hwndGFrame,WM_USER,
  999.               MPFROMP(poly_plot_array),
  1000.               MPFROM2SHORT((SHORT)'y',poly_plot_count)))
  1001.                 {
  1002.                 DosSleep(POST_DELAY);
  1003.                 }
  1004.             }
  1005.         }
  1006.      
  1007.      return;
  1008.      }
  1009.  
  1010.  
  1011. /******************************************************************************
  1012. Function:       Tek_changemode()
  1013.  
  1014. Description:    Changes the processing mode to the mode supplied.  This function
  1015.                 should be used as it checks to see if the current mode is the
  1016.                 Vector mode.  If it is then the polyline plotting buffer is
  1017.                 closed and sent to the PM for processing.
  1018.  
  1019. Syntax:         void Tek_changemode(new_mode)
  1020.                     int new_mode;  New mode to select
  1021.  
  1022. Returns:        nothing
  1023.  
  1024. Mods:           13-Feb-90 C.P.Armstrong created
  1025.  
  1026. ******************************************************************************/
  1027.  
  1028. void Tek_changemode(new_mode)
  1029.     char new_mode;  /* New mode to select */
  1030.     {
  1031.     extern char process_mode;
  1032.     extern char last_process;
  1033.     extern char draw_mode;
  1034.     
  1035.     if((process_mode==VECTMODE) && (draw_mode==1))
  1036.         Tek_poly(0);
  1037.         
  1038.     last_process = process_mode;
  1039.     process_mode=new_mode;
  1040.     }
  1041.     
  1042.     
  1043.