home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckoi31.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  80KB  |  2,229 lines

  1. /*  C K O I 3 1 . C  --  IBM 31x1 Emulation  */
  2.  
  3. /*
  4.   Author: Jeffrey Altman <jaltman@secure-endpoints.com>,
  5.             Secure Endpoints Inc., New York City.
  6.  
  7.   Copyright (C) 1985, 2004, Trustees of Columbia University in the City of New
  8.   York.
  9. */
  10.  
  11. #include "ckcdeb.h"
  12. #ifndef NOTERM
  13. #ifdef NT
  14. #include <windows.h>
  15. #else /* NT */
  16. #include <os2.h>
  17. #undef COMMENT
  18. #endif /* NT */
  19.  
  20. #include "ckcker.h"
  21. #include "ckcasc.h"
  22. #include "ckcuni.h"
  23. #include "ckuusr.h"
  24. #include "ckocon.h"
  25. #include "ckoi31.h"
  26.  
  27. extern bool keyclick ;
  28. extern int  cursorena[], keylock, duplex, duplex_sav, screenon ;
  29. extern int  printon, aprint, uprint, xprint, cprint, seslog ;
  30. extern int  insertmode, tnlm ;
  31. extern int  escstate, debses, decscnm, tt_cursor ;
  32. extern int  tt_type, tt_type_mode, tt_max, tt_answer, tt_status[VNUM], tt_szchng[] ;
  33. extern int  tt_cols[], tt_rows[], tt_wrap ;
  34. extern int  wherex[], wherey[], margintop, marginbot ;
  35. extern int  marginbell, marginbellcol ;
  36. extern char answerback[], htab[] ;
  37. extern struct tt_info_rec tt_info[] ;
  38. extern vtattrib attrib ;
  39. extern unsigned char attribute;
  40. extern char termessage[] ;
  41. extern int autoscroll, protect ;
  42. extern struct _vtG G[4];
  43. extern struct _vtG *GL, *SSGL;          /* GL and single shift GL */
  44. extern struct _vtG *GR;                 /* GR */
  45. extern int tcsl;
  46.  
  47. int i31_monitor = FALSE ;
  48. int i31_xprint  = 0;
  49. int i31_lta     = CR;
  50.  
  51. int
  52. i31inc(void)
  53. {
  54.     extern int pmask, cmask;
  55.     extern int tt_utf8;
  56.     int ch;
  57.  
  58.   loop:
  59.     ch = ttinc(0);
  60.     if ( ch < 0 )
  61.         return ch;
  62.  
  63.     if ( seslog )
  64.         logchar(ch);
  65.  
  66.     /* Handle the UTF8 conversion if we are in that mode */
  67.     if ( tt_utf8 ) {
  68.         USHORT * ucs2 = NULL;
  69.         int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
  70.         if ( rc > 0 )
  71.             goto loop;
  72.         else if ( rc < 0 )
  73.             ch = 0xfffd;
  74.         else
  75.             ch = *ucs2;
  76.     }
  77.  
  78.     if ( !xprint ) {
  79. #ifndef NOXFER
  80.         autodown(ch);
  81. #endif /* NOXFER */
  82.         autoexitchk(ch);
  83.     }
  84.     ch = ch & pmask & cmask;
  85.     debugses(ch);
  86.     if (printon && (is_xprint() || is_uprint()))
  87.         prtchar(ch);
  88.     return ch;
  89. }
  90.  
  91. /* i31rdctrl - is used to read Set Control command sequences */
  92. /* returns a bit flag of which parameters were received      */
  93. #define IBM_PA1 1
  94. #define IBM_PA2 2
  95. #define IBM_PA3 4
  96. #define IBM_PA4 8
  97. #define IBM_OP  16
  98.  
  99. #define GOT_PA1(x) (x & IBM_PA1)
  100. #define GOT_PA2(x) (x & IBM_PA2)
  101. #define GOT_PA3(x) (x & IBM_PA3)
  102. #define GOT_PA4(x) (x & IBM_PA4)
  103. #define GOT_OP(x)  (x & IBM_OP)
  104.  
  105. #define BIT1 0x01
  106. #define BIT2 0x02
  107. #define BIT3 0x04
  108. #define BIT4 0x08
  109. #define BIT5 0x10
  110. #define BIT6 0x20
  111. #define BIT7 0x40
  112. #define BIT8 0x80
  113.  
  114. int
  115. i31rdctrl( int m, int * pa1, int * pa2, int * pa3, int * pa4, int * op )
  116. {
  117.     int n=0;
  118.     int *p=NULL;
  119.  
  120.     if ( m >= 1 ) {
  121.         *pa1 = i31inc();
  122.         if ( (*pa1) < 0 )
  123.             return(n);
  124.         n += IBM_PA1;
  125.  
  126.         if ( m >= 2 ) {
  127.             if ( (*pa1 & 0x60) == 0x20 ) {
  128.                 *pa2 = i31inc();
  129.                 if ( (*pa2) < 0 )
  130.                     return(n);
  131.                 n += IBM_PA2;
  132.             }
  133.             if ( m >= 3 ) {
  134.                 if ( (*pa2 & 0x60) == 0x20 ) {
  135.                     *pa3 = i31inc();
  136.                     if ( (*pa3) < 0 )
  137.                         return(n);
  138.                     n += IBM_PA3;
  139.                 }
  140.                 if ( m >= 4 ) {
  141.                     if ( (*pa3 & 0x60) == 0x20 ) {
  142.                         *pa4 = i31inc();
  143.                         if ( (*pa4) < 0 )
  144.                             return(n);
  145.                         n += IBM_PA4;
  146.                     }
  147.                 }
  148.  
  149.             }
  150.         }
  151.  
  152.         /* Now take care of op */
  153.         switch ( m ) {
  154.         case 1:
  155.             p = pa1;
  156.             break;
  157.         case 2:
  158.             p = pa2;
  159.             break;
  160.         case 3:
  161.             p = pa3;
  162.             break;
  163.         case 4:
  164.             p = pa4;
  165.             break;
  166.         }
  167.         if ( (*p & 0x60) == 0x20 ) {
  168.             *op  = i31inc();
  169.             if ( (*op) < 0 )
  170.                 return(n);
  171.             n += IBM_OP;
  172.         }
  173.     }
  174.     return(n);
  175. }
  176.  
  177. void
  178. i31ctrl( int ch )
  179. {
  180.     int i,j;
  181.  
  182.     if ( !cprint && xprint ) {
  183.         switch ( ch ) {
  184.         case DLE: {
  185.             int nextch = i31inc() ;
  186.             switch ( nextch ) {
  187.             case DC2:       /* Begin Transparent Print */
  188.                 if ( debses )
  189.                     break;
  190.                 i31_xprint++;
  191.                 if ( i31_xprint > 0 ) {
  192.                     xprint = TRUE;
  193.                     if ( !printon )
  194.                         printeron();
  195.                 }
  196.                 /* Now that we have increased our counter, pass it on */
  197.                 prtchar(ch);
  198.                 prtchar(nextch);
  199.                 break;
  200.             case DC4:       /* End Transparent Print */
  201.                 if ( debses )
  202.                     break;
  203.                 if ( i31_xprint > 0 )
  204.                     i31_xprint--;
  205.                 if ( !i31_xprint ) {
  206.                     xprint = FALSE ;
  207.                     if ( !uprint && !xprint && !cprint && !aprint && printon )
  208.                         printeroff();
  209.                 }
  210.                 if ( i31_xprint > 0 ) {
  211.                     /* we are not done yet, pass it on */
  212.                     prtchar(ch);
  213.                     prtchar(nextch) ;
  214.                 }
  215.                 break;
  216.             default:
  217.                 prtchar(ch);
  218.                 prtchar(nextch) ;
  219.                 break;
  220.             }
  221.             break;
  222.         }
  223.         default:
  224.             prtchar(ch);
  225.             break;
  226.         }
  227.     } else {
  228.         switch ( ch ) {
  229.         case SOH:
  230.             break;
  231.         case STX:
  232.             break;
  233.         case ETX:
  234.             break;
  235.         case EOT:
  236.             break;
  237.         case ENQ: {
  238.             break;
  239.         }
  240.         case ACK:
  241.             break;
  242.         case BEL:       /* Sound bell */
  243.             if ( debses )
  244.                 break;
  245.             bleep(BP_BEL);
  246.             break;
  247.         case BS:
  248.             /* cursor left (backspace) */
  249.             if ( debses )
  250.                 break;
  251.             cursorleft(0) ;
  252.             break;
  253.         case HT:
  254.             /* Tabulate cursor */
  255.             if ( debses )
  256.                 break;
  257.             i = wherex[VTERM];
  258.             if (i < VscrnGetWidth(VTERM))
  259.             {
  260.                 do {
  261.                     i++;
  262.                     cursorright(0);
  263.                 } while ((htab[i] != 'T') &&
  264.                           (i <= VscrnGetWidth(VTERM)-1));
  265.                 VscrnIsDirty(VTERM);
  266.             }
  267.             break;
  268.         case LF:
  269.             /* cursor down; scroll */
  270.             if ( debses )
  271.                 break;
  272.             wrtch(LF);
  273.             break;
  274.         case VT:
  275.             break;
  276.         case FF:
  277.             break;
  278.         case CR:
  279.             /* cursor to start of line */
  280.             if ( debses )
  281.                 break;
  282.             wrtch(CR);
  283.             break;
  284.         case SO:
  285.             /* 3161- Select primary character set */
  286.             if ( debses )
  287.                 break;
  288.             GL = &G[0] ;
  289.             break;
  290.         case SI:
  291.             /* 3161 - Select secondary character set */
  292.             if ( debses )
  293.                 break;
  294.             GL = &G[1] ;
  295.             break;
  296.         case DLE: {
  297.             int nextch = i31inc() ;
  298.             switch ( nextch ) {
  299.             case STX:
  300.                 if ( debses || i31_monitor )
  301.                     break;
  302.                 i31_monitor = TRUE ;
  303.                 setdebses(TRUE);
  304.                 break;
  305.             case ETX:
  306.                 if ( !i31_monitor )
  307.                     break;
  308.                 i31_monitor = FALSE ;
  309.                 setdebses(FALSE);
  310.                 break;
  311.             case EOT:
  312.                 if ( debses )
  313.                     break;
  314.                 strcpy( termessage, "Disconnected by host" ) ;
  315.                 ttclos(0);
  316.                 break;
  317.             case DC2:       /* Begin Transparent Print */
  318.                 if ( debses )
  319.                     break;
  320.                 i31_xprint++;
  321.                 if ( i31_xprint > 0 ) {
  322.                     xprint = TRUE;
  323.                     if ( !printon )
  324.                         printeron();
  325.                 }
  326.                 break;
  327.             case DC4:       /* End Transparent Print */
  328.                 if ( debses )
  329.                     break;
  330.                 if ( i31_xprint > 0 )
  331.                     i31_xprint--;
  332.                 if ( !i31_xprint ) {
  333.                     xprint = FALSE ;
  334.                     if ( !uprint && !xprint && !cprint && !aprint && printon )
  335.                         printeroff();
  336.                 }
  337.                 break;
  338.             default:
  339.                 i31ascii(nextch) ;
  340.                 break;
  341.             }
  342.             break;
  343.         }
  344.         case DC1:
  345.             break;
  346.         case DC2:
  347.             break;
  348.         case DC3:
  349.             break;
  350.         case DC4:
  351.             break;
  352.         case NAK:
  353.             break;
  354.         case SYN:
  355.             break;
  356.         case ETB:
  357.             break;
  358.         case CAN:
  359.             break;
  360.         case XEM:
  361.             break;
  362.         case SUB:
  363.             break;
  364.         case ESC:
  365.             /* initiate escape sequence */
  366.             escstate = ES_GOTESC ;
  367.             break;
  368.         case XFS:
  369.             break;
  370.         case XGS:
  371.             break;
  372.         case XRS:
  373.             break;
  374.         case US:
  375.             break;
  376.         }
  377.     } /* xprint */
  378. }
  379.  
  380. void
  381. i31ascii( int ch )
  382. {
  383.     int i,j,k,n,x,y,z;
  384.     vtattrib attr ;
  385.     viocell blankvcell;
  386.     int ch2=0, ch3=0, pa=0, pa1=0, pa2=0, pa3=0, pa4=0, op=0;
  387.     char response[32]="";
  388.  
  389.     if ( escstate == ES_GOTESC )/* Process character as part of an escstate sequence */
  390.     {
  391.         /* should never be able to get here if xprint is active */
  392.  
  393.         if ( ch < SP ) {
  394.             escstate = ES_NORMAL ;
  395.             i31ctrl(ch) ;
  396.         }
  397.         else
  398.         {
  399.             escstate = ES_ESCSEQ ;
  400.             switch ( ch ) {
  401.             case '!': {
  402.                 ch2 = i31inc() ;
  403.                 switch ( ch2 ) {
  404.                 case '6':
  405.                     /* 3161 - Send terminal ID */
  406.                     if ( debses )
  407.                         break;
  408.                     /* send ESC ! 6 pa ESC 6 LTA */
  409.                     break;
  410.                 case '7':
  411.                     /* 3161 - Read Control 2 */
  412.                     /* Machine Status of the 3151 */
  413.                     if ( debses )
  414.                         break;
  415.                     break;
  416.                 case '8':
  417.                     /* 3161 - Send cursor line */
  418.                     if ( debses )
  419.                         break;
  420.                     break;
  421.                 case '9': {
  422.                     /* 3161 - Set Control 2 */
  423.                     /* Machine Status of the 3151 */
  424.                     if ( debses )
  425.                         break;
  426.                     n = i31rdctrl( 2, &pa1, &pa2, &pa3, &pa4, &op );
  427.                     if ( debses || n == 0 )
  428.                         break;
  429.  
  430.                     if ( GOT_OP(n) ) {
  431.                         if ( (op & BIT7|BIT6) == 0x60 )
  432.                         switch ( (op & 0x1F) ) {
  433.                         case 0x00:      /* Replacement (default) */
  434.                             break;
  435.                         case 0x01:      /* Logical OR */
  436.                             break;
  437.                         case 0x02:      /* Logical AND */
  438.                             break;
  439.                         case 0x1F:      /* Interpreted as the DEL character */
  440.                             break;
  441.                         }
  442.                     }
  443.  
  444.                     /* The following lines must be merged in to the above */
  445.                     /* switch to enable the replace|and|or functionality  */
  446.                     if ( GOT_PA1(n) ) {
  447.                         /* Forcing Insert Line */
  448.                         if ( pa1 & 0x10 )
  449.                             ;   /* Enabled */
  450.                         else
  451.                             ;   /* Disabled (default) */
  452.  
  453.                         /* Enter Key */
  454.                         if ( pa1 & 0x08 )
  455.                             ;   /* Works as the Return key (default) */
  456.                         else
  457.                             ;   /* Works as the Send key */
  458.  
  459.                         /* CRT Saver */
  460.                         if ( pa1 & 0x03 )
  461.                             ;   /* 15 minutes */
  462.                         else
  463.                             ;   /* No saver (default) */
  464.                     }
  465.                     if ( GOT_PA2(n) ) {
  466.                         /* Forcing Insert Character */
  467.                         if ( pa2 & 0x10 )
  468.                             ;   /* Enabled */
  469.                         else
  470.                             ;   /* Disabled (default) */
  471.  
  472.                         /* Set Field Attribute (pa2 & 0x08) */
  473.                         /* should always be 1               */
  474.  
  475.                         /* Operator Initiated Transparent Mode */
  476.                         if ( pa2 & 0x03 )
  477.                             ;   /* Disabled */
  478.                         else
  479.                             ;   /* Enabled (default) */
  480.  
  481.                         /* New Line */
  482.                         if ( pa2 & 0x02 )
  483.                             ;   /* Return key generates CR (default) */
  484.                         else
  485.                             ;   /* Return key generates CR/LF */
  486.  
  487.                     }
  488.                     break;
  489.                 }
  490.                 case 'L':
  491.                     /* 3161 - Clear all */
  492.                     if ( debses )
  493.                         break;
  494.                     clrscreen( VTERM, NUL );
  495.                     lgotoxy(VTERM,1,1);       /* and home the cursor */
  496.                     break;
  497.                 case 'M':
  498.                     /* Reverse Index command */
  499.                     if ( debses )
  500.                         break;
  501.                     break;
  502.                 case 'q':
  503.                     /* 3161 - Select active partition */
  504.                     /* Affects the viewport which local operator */
  505.                     /* commands affect.  Cursor moves to active partition */
  506.                     pa = i31inc();
  507.                     if ( debses )
  508.                         break;
  509.                     switch ( pa ) {
  510.                     case 'A':   /* viewport 1 */
  511.                         break;
  512.                     case 'B':   /* viewport 2 */
  513.                         break;
  514.                     case 'C':   /* viewport 3 */
  515.                         break;
  516.                     }
  517.                     break;
  518.                 case 's':
  519.                     /* 3161 - Reset keyboard and clear modified */
  520.                     /*        data tag                          */
  521.                     if ( debses )
  522.                         break;
  523.                     break;
  524.                 case 'S':
  525.                     /* Reset Keyboard Lock and MDT Bit Command */
  526.                     if ( debses )
  527.                         break;
  528.                     break;
  529.                 case '=': {
  530.                     /* 3161 - Program function key definition */
  531.                     int fn=0,fnx=0,ff=0;
  532.                     char fp[128]="";
  533.                     fn = i31inc();
  534.                     if ( fn & (BIT5|BIT4|BIT3|BIT2|BIT1) == 0x00 )
  535.                         fnx = i31inc();
  536.                     ff = i31inc();
  537.                     i = 0;
  538.                     fp[i] = i31inc();
  539.                     do {
  540.                         fp[++i] = i31inc();
  541.                     } while ( fp[i-1] != ESC && fp[i] != '=' && i<65 );
  542.                     fp[i-1] = NUL;
  543.                     if ( debses )
  544.                         break;
  545.                     /* The function key to be assigned is equal to      */
  546.                     /* (fn & (BIT5|BIT4|BIT3|BIT2|BIT1)) ||             */
  547.                     /* (32 + (fnx & (BIT5|BIT4|BIT3|BIT2|BIT1)))        */
  548.                     /* (ff & BIT1) specifies whether the string is      */
  549.                     /* for local display (1) or remote transmission (0) */
  550.                     break;
  551.                 }
  552.                 default:
  553.                     escstate = ES_NORMAL ;
  554.                     i31ascii(ch);
  555.                 }
  556.                 break;
  557.             }
  558.             case SP: {
  559.                 ch2 = i31inc() ;
  560.                 switch ( ch2 ) {
  561.                 case ':':
  562.                     /* Begin Outbound Trace mode */
  563.                     if ( debses )
  564.                         break;
  565.                     cprint = TRUE;
  566.                     if ( !printon )
  567.                         printeron();
  568.                     break;
  569.                 case ';':
  570.                     /* End Outbound Trace mode */
  571.                     if ( debses || !cprint )
  572.                         break;
  573.                     cprint = FALSE;
  574.                     if ( !uprint && !xprint && !cprint && !aprint && printon )
  575.                         printeroff();
  576.                     break;
  577.                 case '1':
  578.                     /* 3161 - Clear all tab stops */
  579.                     if ( debses )
  580.                         break;
  581.                     for (j = 1; j <=MAXTERMCOL; ++j)
  582.                         htab[j] = '0';
  583.                     break;
  584.                 case '6':
  585.                     /* 3161 - Send model */
  586.                     if ( debses )
  587.                         break;
  588.                     /* send ESC SP 6 pa LTA */
  589.                     break;
  590.                 case '7':
  591.                     /* 3161 - Read Control 1 (6-15) */
  592.                     /* Machine and Operating Modes */
  593.                     if ( debses )
  594.                         break;
  595.                     pa1 = 0x81; /* 3151 and Character */
  596.                     sprintf(response,"%c 7%c%c",
  597.                              ESC,pa1,i31_lta);
  598.                     ttol(response,strlen(response));
  599.                     break;
  600.                 case '8':
  601.                     /* 3161 - Send message */
  602.                     if ( debses )
  603.                         break;
  604.                     break;
  605.                 case '9':
  606.                     /* 3161 - Set Control 1 (6-15) */
  607.                     /* Machine and Operating Modes */
  608.                     n = i31rdctrl( 2, &pa1, &pa2, &pa3, &pa4, &op );
  609.                     if ( debses || n == 0 )
  610.                         break;
  611.  
  612.                     if ( GOT_OP(n) ) {
  613.                         if ( (op & BIT7|BIT6) == 0x60 )
  614.                         switch ( (op & 0x1F) ) {
  615.                         case 0x00:      /* Replacement (default) */
  616.                             break;
  617.                         case 0x01:      /* Logical OR */
  618.                             break;
  619.                         case 0x02:      /* Logical AND */
  620.                             break;
  621.                         case 0x1F:      /* Interpreted as the DEL character */
  622.                             break;
  623.                         }
  624.                     }
  625.                     /* The following lines must be merged in to the above */
  626.                     /* switch to enable the replace|and|or functionality  */
  627.                     if ( GOT_PA1(n) ) {
  628.                         /* Machine Mode */
  629.                         switch ( (pa1 & 0x1C) ) {
  630.                         case 0x00:  /* IBM 3151 (default) */
  631.                             break;
  632.                         case 0x04:  /* IBM 3101 */
  633.                             break;
  634.                         case 0x08:  /* ADM-3A */
  635.                             break;
  636.                         case 0x0C:  /* ADM-5 */
  637.                             break;
  638.                         case 0x10:  /* ADDS VP A2 */
  639.                             break;
  640.                         case 0x14:  /* HZ-1500 */
  641.                             break;
  642.                         case 0x18:  /* TVI-910+ */
  643.                             break;
  644.                         case 0x1C:  /* use pa2 */
  645.                             if ( GOT_PA2(n) ) {
  646.                                 switch ( (pa2 & 0x0F) ) {
  647.                                 case 0x00:      /* TVI-925E */
  648.                                     break;
  649.                                 case 0x01:      /* TVI-920/912 */
  650.                                     break;
  651.                                 }
  652.                             }
  653.                             break;
  654.                         }
  655.  
  656.                         /* Operating Mode */
  657.                         switch ( (pa1 & 0x03) ) {
  658.                         case 0x00:  /* Echo */
  659.                             break;
  660.                         case 0x01:  /* Character */
  661.                             break;
  662.                         case 0x02:  /* Block (default) */
  663.                             break;
  664.                         case 0x03:  /* Reserved */
  665.                             break;
  666.                         }
  667.                     }
  668.                     break;
  669.                 case 'M':
  670.                     /* Index command */
  671.                     if ( debses )
  672.                         break;
  673.                     break;
  674.                 case 'q':
  675.                     /* 3161 - Select host partition */
  676.                     /* Specifies partition that host data is written to */
  677.                     pa = i31inc();
  678.                     if ( debses )
  679.                         break;
  680.                     switch ( pa ) {
  681.                     case 'A':   /* viewport 1 */
  682.                         break;
  683.                     case 'B':   /* viewport 2 */
  684.                         break;
  685.                     case 'C':   /* viewport 3 */
  686.                         break;
  687.                     }
  688.                     break;
  689.                 case 'r': {
  690.                     /* 3161 - Create Viewport */
  691.                     char cmd[16]="";
  692.                     ch3 = i31inc();
  693.                     switch ( ch3 ) {
  694.                     case '!':   /* one viewport */
  695.                         for ( i=0;i<5;i++ )
  696.                             cmd[i] = i31inc();
  697.                         cmd[i] = NUL;
  698.                         break;
  699.                     case '"':   /* two viewports */
  700.                         for ( i=0;i<10;i++ )
  701.                             cmd[i] = i31inc();
  702.                         cmd[i] = NUL;
  703.                         break;
  704.                     case '#':   /* three viewports */
  705.                         for ( i=0;i<15;i++ )
  706.                             cmd[i] = i31inc();
  707.                         cmd[i] = NUL;
  708.                         break;
  709.                     }
  710.                     if ( debses )
  711.                         break;
  712.                     switch ( ch3 ) {
  713.                     case '!':   /* one viewport */
  714.                         if ( !strcmp(cmd,"! 8\"P") ) {
  715.                             ;   /* 24 lines, 80 cols */
  716.                         }
  717.                         else if ( !strcmp(cmd,"! 9\"P" ) ) {
  718.                             ;   /* 25 lines, 80 cols */
  719.                         }
  720.                         else if ( !strcmp(cmd,"! 8$D" ) ) {
  721.                             ;   /* 24 lines, 132 cols */
  722.                         }
  723.                         else if ( !strcmp(cmd,"! 9$D" ) ) {
  724.                             ;   /* 25 lines, 132 cols */
  725.                         }
  726.                         break;
  727.                     case '"':   /* two viewports */
  728.                         if ( cmd[3] == '"' && cmd[4] == '0' &&
  729.                              cmd[8] == '"' && cmd[9] == 'P') {
  730.                             /* 80 columns */
  731.                             /* height of viewport 1 is (cmd[2]-'!'+1) */
  732.                             /* height of viewport 2 is (cmd[7]-'!'+1) */
  733.                             /* sum of heights must equal 24 or 25 */
  734.                         }
  735.                         else if ( cmd[3] == '$' && cmd[4] == '$' &&
  736.                                   cmd[8] == '$' && cmd[9] == 'D') {
  737.                             /* 132 columns */
  738.                             /* height of viewport 1 is (cmd[2]-'!'+1) */
  739.                             /* height of viewport 2 is (cmd[7]-'!'+1) */
  740.                             /* sum of heights must equal 24 or 25 */
  741.                         }
  742.                         break;
  743.                     case '#':   /* three viewports */
  744.                         if ( cmd[3] == '"' && cmd[4] == '0' &&
  745.                              cmd[8] == '"' && cmd[9] == '0' &&
  746.                              cmd[13] == '"' && cmd[14] == 'P') {
  747.                             /* 80 columns */
  748.                             /* height of viewport 1 is (cmd[2]-'!'+1) */
  749.                             /* height of viewport 2 is (cmd[7]-'!'+1) */
  750.                             /* height of viewport 3 is (cmd[12]-'!'+1) */
  751.                             /* sum of heights must equal 24 or 25 */
  752.                         }
  753.                         else if ( cmd[3] == '$' && cmd[4] == '$' &&
  754.                                   cmd[8] == '$' && cmd[9] == '$' &&
  755.                                   cmd[13] == '$' && cmd[14] == 'D') {
  756.                             /* 132 columns */
  757.                             /* height of viewport 1 is (cmd[2]-'!'+1) */
  758.                             /* height of viewport 2 is (cmd[7]-'!'+1) */
  759.                             /* height of viewport 3 is (cmd[12]-'!'+1) */
  760.                             /* sum of heights must equal 24 or 25 */
  761.                         }
  762.                         break;
  763.                     }
  764.                     break;
  765.                 }
  766.                 case 'S':
  767.                     /* 3161 - Reset to initial state */
  768.                     if ( debses )
  769.                         break;
  770.                     doreset(1) ;
  771.                     break;
  772.                 case 't':
  773.                     /* 3161 - Default all function keys */
  774.                     if ( debses )
  775.                         break;
  776.                     udkreset() ;
  777.                     break;
  778.                 case 'W':
  779.                     /* 3161 - Print screen */
  780.                     if ( debses )
  781.                         break;
  782.                     break;
  783.                 case 'Z':
  784.                     /* 3161 - Reset buffer address mode to cursor addr mode */
  785.                     if ( debses )
  786.                         break;
  787.                     break;
  788.                 default:
  789.                     escstate = ES_NORMAL ;
  790.                     i31ascii(ch);
  791.                 }
  792.                 break;
  793.             }
  794.             case '"': {
  795.                 ch2 = i31inc() ;
  796.                 switch ( ch2 ) {
  797.                 case ':':
  798.                     /* Enable Write Null */
  799.                     if ( debses )
  800.                         break;
  801.                     break;
  802.                 case ';':
  803.                     /* Disable Write Null */
  804.                     if ( debses )
  805.                         break;
  806.                     break;
  807.                 case '6':
  808.                     /* Extended Read Model Command */
  809.                     if ( debses )
  810.                         break;
  811.                     /* send ESC " 6 pa1 pa2 pa3 pa4 pa5 LTA */
  812.                     break;
  813.                 case '7':
  814.                     /* 3161 - Read Control 3 */
  815.                     /* Display functions of the 3151 */
  816.                     if ( debses )
  817.                         break;
  818.                     break;
  819.                 case '9':
  820.                     /* 3161 - Set Control 3 */
  821.                     /* Display functions of the 3151 */
  822.                     n = i31rdctrl( 2, &pa1, &pa2, &pa3, &pa4, &op );
  823.                     if ( debses || n == 0 )
  824.                         break;
  825.  
  826.                     if ( GOT_OP(n) ) {
  827.                         if ( (op & BIT7|BIT6) == 0x60 )
  828.                         switch ( (op & 0x1F) ) {
  829.                         case 0x00:      /* Replacement (default) */
  830.                             break;
  831.                         case 0x01:      /* Logical OR */
  832.                             break;
  833.                         case 0x02:      /* Logical AND */
  834.                             break;
  835.                         case 0x1F:      /* Interpreted as the DEL character */
  836.                             break;
  837.                         }
  838.                     }
  839.  
  840.                     /* The following lines must be merged in to the above */
  841.                     /* switch to enable the replace|and|or functionality  */
  842.                     if ( GOT_PA1(n) ) {
  843.                         /* Scroll (temporary) */
  844.                         switch ( pa1 & 0x18 ) {
  845.                         case 0x00:      /* No scroll */
  846.                             break;
  847.                         case 0x08:      /* Jump scroll (default) */
  848.                             break;
  849.                         case 0x10:      /* Smooth scroll */
  850.                             break;
  851.                         case 0x11:      /* Reserved */
  852.                             break;
  853.                         }
  854.  
  855.                         /* Line Wrap */
  856.                         if ( pa1 & 0x04 )
  857.                             ;   /* On (default) */
  858.                         else
  859.                             ;   /* Off */
  860.  
  861.                         /* Auto LF */
  862.                         if ( pa1 & 0x02 )
  863.                             ;   /* On (default) */
  864.                         else
  865.                             ;   /* Off */
  866.  
  867.                         /* ASCII LF Character */
  868.                         if ( pa1 & 0x01 )
  869.                             ;   /* New line */
  870.                         else
  871.                             ;   /* Line feed (default) */
  872.                     }
  873.  
  874.                     if ( GOT_PA2(n) ) {
  875.                         /* Scroll (permanently) */
  876.                         switch ( pa2 & 0x18 ) {
  877.                         case 0x00:      /* No scroll */
  878.                             break;
  879.                         case 0x08:      /* Jump scroll (default) */
  880.                             break;
  881.                         case 0x10:      /* Smooth scroll */
  882.                             break;
  883.                         case 0x11:      /* Reserved */
  884.                             break;
  885.                         }
  886.  
  887.                         /* Insert Character */
  888.                         if ( pa2 & 0x04 )
  889.                             ;   /* Inserts a space character */
  890.                         else
  891.                             ;   /* Sets insert mode (default) */
  892.  
  893.                         /* Tab */
  894.                         if ( pa2 & 0x02 )
  895.                             ;   /* Column Tab */
  896.                         else
  897.                             ;   /* Field Tab (default) */
  898.  
  899.                         /* Return Key */
  900.                         if ( pa1 & 0x01 )
  901.                             ;   /* New Line */
  902.                         else
  903.                             ;   /* Field (default) */
  904.  
  905.                     }
  906.                     break;
  907.                 case 'A':
  908.                     /* 3161 - Jump partition */
  909.                     /* Selects next viewport as active partition */
  910.                     if ( debses )
  911.                         break;
  912.                     break;
  913.                 default:
  914.                     escstate = ES_NORMAL ;
  915.                     i31ascii(ch);
  916.                 }
  917.                 break;
  918.             }
  919.             case '#': {
  920.                 ch2 = i31inc() ;
  921.                 switch ( ch2 ) {
  922.                 case ';':
  923.                     /* Display Host Message stored in OIA buffer */
  924.                     if ( debses )
  925.                         break;
  926.                     break;
  927.                 case ':':
  928.                     /* Display Machine Status */
  929.                     if ( debses )
  930.                         break;
  931.                     break;
  932.                 case '7':
  933.                     /* 3161 - Read Control 4 */
  934.                     /* Send parameters of the 3151 */
  935.                     if ( debses )
  936.                         break;
  937.                     break;
  938.                 case '8':
  939.                     /* 3161 - Send all */
  940.                     if ( debses )
  941.                         break;
  942.                     break;
  943.                 case '9':
  944.                     /* 3161 - Set Control 4 */
  945.                     /* Send parameters of the 3151 */
  946.                     n = i31rdctrl( 1, &pa1, &pa2, &pa3, &pa4, &op );
  947.  
  948.                     if ( debses || n == 0 )
  949.                         break;
  950.  
  951.                     if ( GOT_OP(n) ) {
  952.                         if ( (op & BIT7|BIT6) == 0x60 )
  953.                         switch ( (op & 0x1F) ) {
  954.                         case 0x00:      /* Replacement (default) */
  955.                             break;
  956.                         case 0x01:      /* Logical OR */
  957.                             break;
  958.                         case 0x02:      /* Logical AND */
  959.                             break;
  960.                         case 0x1F:      /* Interpreted as the DEL character */
  961.                             break;
  962.                         }
  963.                     }
  964.  
  965.                     /* The following lines must be merged in to the above */
  966.                     /* switch to enable the replace|and|or functionality  */
  967.                     if ( GOT_PA1(n) ) {
  968.                         /* Send Line */
  969.                         if ( pa1 & 0x08 )
  970.                             ;   /* Send key works as Send Line key */
  971.                                 /* and Send Line key works as Send key */
  972.                         else
  973.                             ;   /* Send key works as Send key and */
  974.                                 /* Send Line key works as Send Line key */
  975.                                 /* (default) */
  976.  
  977.                         /* Send Null Suppress */
  978.                         if ( pa1 & 0x04 )
  979.                             ;   /* On (default) */
  980.                         else
  981.                             ;   /* Off */
  982.  
  983.                         /* Lock Keyboard and Keep MDT Bit */
  984.                         if ( pa1 & 0x02 )
  985.                             ;   /* On */
  986.                         else
  987.                             ;   /* Off (default) */
  988.  
  989.                         /* Send Data Format */
  990.                         if ( pa1 & 0x01 )
  991.                             ;   /* AID LTA */
  992.                         else
  993.                             ;   /* Text LTA (default) */
  994.                     }
  995.                     break;
  996.                 default:
  997.                     escstate = ES_NORMAL ;
  998.                     i31ascii(ch);
  999.                 }
  1000.                 break;
  1001.             }
  1002.             case '$': {
  1003.                 ch2 = i31inc() ;
  1004.                 switch ( ch2 ) {
  1005.                 case '7':
  1006.                     /* 3161 - Read Control 5 */
  1007.                     /* Communication values on the main port */
  1008.                     if ( debses )
  1009.                         break;
  1010.                     break;
  1011.                 case '9':
  1012.                     /* 3161 - Set Control 5 */
  1013.                     /* Communication values on the main port */
  1014.                     n = i31rdctrl( 4, &pa1, &pa2, &pa3, &pa4, &op );
  1015.  
  1016.                     if ( debses || n == 0 )
  1017.                         break;
  1018.  
  1019.                     if ( GOT_OP(n) ) {
  1020.                         if ( (op & BIT7|BIT6) == 0x60 )
  1021.                         switch ( (op & 0x1F) ) {
  1022.                         case 0x00:      /* Replacement (default) */
  1023.                             break;
  1024.                         case 0x01:      /* Logical OR */
  1025.                             break;
  1026.                         case 0x02:      /* Logical AND */
  1027.                             break;
  1028.                         case 0x1F:      /* Interpreted as the DEL character */
  1029.                             break;
  1030.                         }
  1031.                     }
  1032.  
  1033.                     /* The following lines must be merged in to the above */
  1034.                     /* switch to enable the replace|and|or functionality  */
  1035.                     if ( GOT_PA1(n) ) {
  1036.                         /* Stop Bits */
  1037.                         if ( pa1 & 0x10 )
  1038.                             ;   /* 2 */
  1039.                         else
  1040.                             ;   /* 1 (default) */
  1041.  
  1042.                         /* Line Speed */
  1043.                         switch ( pa1 & 0x0F ) {
  1044.                         case 0x00:      /* 50 or 38400 */
  1045.                             if ( pa3 & 0x04 )
  1046.                                 ;       /* 38400 */
  1047.                             else
  1048.                                 ;       /* 50 */
  1049.                             break;
  1050.                         case 0x01:      /* 75 bps */
  1051.                             break;
  1052.                         case 0x02:      /* 110 bps */
  1053.                             break;
  1054.                         case 0x03:      /* 134.5 bps */
  1055.                             break;
  1056.                         case 0x04:      /* 150 bps */
  1057.                             break;
  1058.                         case 0x05:      /* 200 bps */
  1059.                             break;
  1060.                         case 0x06:      /* 300 bps */
  1061.                             break;
  1062.                         case 0x07:      /* 600 bps */
  1063.                             break;
  1064.                         case 0x08:      /* 1200 bps */
  1065.                             break;
  1066.                         case 0x09:      /* 1800 bps */
  1067.                             break;
  1068.                         case 0x0A:      /* 2400 bps */
  1069.                             break;
  1070.                         case 0x0B:      /* 3600 bps */
  1071.                             break;
  1072.                         case 0x0C:      /* 4800 bps */
  1073.                             break;
  1074.                         case 0x0D:      /* Reserved */
  1075.                             break;
  1076.                         case 0x0E:      /* 9600 bps */
  1077.                             break;
  1078.                         case 0x0F:      /* 19200 bps */
  1079.                             break;
  1080.                         }
  1081.                     }
  1082.                     if ( GOT_PA2(n) ) {
  1083.                         /* Interface */
  1084.                         if ( pa2 & 0x10 )
  1085.                             ;   /* EIA RS-232C (always) */
  1086.                         else
  1087.                             ;   /* illegal value */
  1088.  
  1089.                         /* Word Length */
  1090.                         if ( pa2 & 0x08 )
  1091.                             ;   /* 8-bit */
  1092.                         else
  1093.                             ;   /* 7-bit (default) */
  1094.  
  1095.                         /* Parity */
  1096.                         switch ( pa2 & 0x07 ) {
  1097.                         case 0x00:      /* None */
  1098.                             break;
  1099.                         case 0x01:      /* Space */
  1100.                             break;
  1101.                         case 0x02:      /* Mark */
  1102.                             break;
  1103.                         case 0x03:      /* Odd (default) */
  1104.                             break;
  1105.                         case 0x04:      /* Even */
  1106.                             break;
  1107.                         }
  1108.                     }
  1109.  
  1110.                     if ( GOT_PA3(n) ) {
  1111.                         /* no name */
  1112.                         if ( pa3 & 0x10 )
  1113.                             ;   /* 100 ms response delay is returned in */
  1114.                                 /* response to the Read Control 5 command */
  1115.                         else
  1116.                             ;   /* Reserved */
  1117.  
  1118.                         /* Reserved */
  1119.                         if ( pa3 & 0x08 )
  1120.                             ;   /* illegal value */
  1121.                         else
  1122.                             ;   /* Reserved (always) */
  1123.  
  1124.                         /* Line Speed Extension (used in pa1 above) */
  1125.                         if ( pa3 & 0x04 )
  1126.                             ;   /* Extended */
  1127.                         else
  1128.                             ;   /* Not extended (default) */
  1129.  
  1130.                         /* Line Control */
  1131.                         switch ( pa3 & 0x03 ) {
  1132.                         case 0x00:      /* CRTS */
  1133.                             break;
  1134.                         case 0x01:      /* PRTS (default) */
  1135.                             break;
  1136.                         case 0x02:      /* IPRTS */
  1137.                             break;
  1138.                         case 0x03:      /* Reserved */
  1139.                             break;
  1140.                         }
  1141.                     }
  1142.  
  1143.                     if ( GOT_PA4(n) ) {
  1144.                         /* Reserved */
  1145.                         if ( pa4 & 0x10 )
  1146.                             ;   /* Enable outbound pacing is returned in */
  1147.                                 /* response to the Read Control 5 command */
  1148.                         else
  1149.                             ;   /* Reserved */
  1150.  
  1151.                         /* Reserved */
  1152.                         if ( pa4 & 0x08 )
  1153.                             ;   /* Enable inbound pacing is returned in */
  1154.                                 /* response to the Read Control 5 command */
  1155.                         else
  1156.                             ;   /* Reserved */
  1157.  
  1158.                         /* Break Signal */
  1159.                         if ( pa4 & 0x04 )
  1160.                             ;   /* 500 ms (default) */
  1161.                         else
  1162.                             ;   /* 170 ms */
  1163.  
  1164.                         /* Turnaround Character */
  1165.                         switch ( pa4 & 0x03 ) {
  1166.                         case 0x00:      /* ETX (default) */
  1167.                             break;
  1168.                         case 0x01:      /* CR */
  1169.                             break;
  1170.                         case 0x02:      /* EOT */
  1171.                             break;
  1172.                         case 0x03:      /* DC3 (also disable inbound/outbound */
  1173.                                         /* pacing) */
  1174.                             break;
  1175.                         }
  1176.                     }
  1177.                     break;
  1178.                 default:
  1179.                     escstate = ES_NORMAL ;
  1180.                     i31ascii(ch);
  1181.                 }
  1182.                 break;
  1183.             }
  1184.             case '%': {
  1185.                 ch2 = i31inc() ;
  1186.                 switch ( ch2 ) {
  1187.                 case ':':
  1188.                     /* Enable Read Unprotected Field */
  1189.                     if ( debses )
  1190.                         break;
  1191.                     break;
  1192.                 case ';':
  1193.                     /* Disable Read Unprotected Field */
  1194.                     if ( debses )
  1195.                         break;
  1196.                     break;
  1197.                 case '7':
  1198.                     /* 3161 - Read Control 6 */
  1199.                     /* Communication values on the auxiliary port */
  1200.                     if ( debses )
  1201.                         break;
  1202.                     break;
  1203.                 case '9':
  1204.                     /* 3161 - Set Control 6 */
  1205.                     /* Communication values on the auxiliary port */
  1206.                     n = i31rdctrl( 4, &pa1, &pa2, &pa3, &pa4, &op );
  1207.  
  1208.                     if ( debses || n == 0 )
  1209.                         break;
  1210.  
  1211.                     if ( GOT_OP(n) ) {
  1212.                         if ( (op & BIT7|BIT6) == 0x60 )
  1213.                         switch ( (op & 0x1F) ) {
  1214.                         case 0x00:      /* Replacement (default) */
  1215.                             break;
  1216.                         case 0x01:      /* Logical OR */
  1217.                             break;
  1218.                         case 0x02:      /* Logical AND */
  1219.                             break;
  1220.                         case 0x1F:      /* Interpreted as the DEL character */
  1221.                             break;
  1222.                         }
  1223.                     }
  1224.  
  1225.                     /* The following lines must be merged in to the above */
  1226.                     /* switch to enable the replace|and|or functionality  */
  1227.                     if ( GOT_PA1(n) ) {
  1228.                         /* Stop Bits */
  1229.                         if ( pa1 & 0x10 )
  1230.                             ;   /* 2 */
  1231.                         else
  1232.                             ;   /* 1 (default) */
  1233.  
  1234.                         /* Line Speed */
  1235.                         switch ( pa1 & 0x0F ) {
  1236.                         case 0x00:      /* 50 bps */
  1237.                             break;
  1238.                         case 0x01:      /* 75 bps */
  1239.                             break;
  1240.                         case 0x02:      /* 110 bps */
  1241.                             break;
  1242.                         case 0x03:      /* 134.5 bps */
  1243.                             break;
  1244.                         case 0x04:      /* 150 bps */
  1245.                             break;
  1246.                         case 0x05:      /* 200 bps */
  1247.                             break;
  1248.                         case 0x06:      /* 300 bps */
  1249.                             break;
  1250.                         case 0x07:      /* 600 bps */
  1251.                             break;
  1252.                         case 0x08:      /* 1200 bps */
  1253.                             break;
  1254.                         case 0x09:      /* 1800 bps */
  1255.                             break;
  1256.                         case 0x0A:      /* 2400 bps */
  1257.                             break;
  1258.                         case 0x0B:      /* 3600 bps */
  1259.                             break;
  1260.                         case 0x0C:      /* 4800 bps */
  1261.                             break;
  1262.                         case 0x0D:      /* Reserved */
  1263.                             break;
  1264.                         case 0x0E:      /* 9600 bps */
  1265.                             break;
  1266.                         case 0x0F:      /* 19200 bps */
  1267.                             break;
  1268.                         }
  1269.                     }
  1270.                     if ( GOT_PA2(n) ) {
  1271.                         /* Interface */
  1272.                         if ( pa2 & 0x10 )
  1273.                             ;   /* EIA RS-232C (always) */
  1274.                         else
  1275.                             ;   /* illegal value */
  1276.  
  1277.                         /* Word Length */
  1278.                         if ( pa2 & 0x08 )
  1279.                             ;   /* 8-bit */
  1280.                         else
  1281.                             ;   /* 7-bit (default) */
  1282.  
  1283.                         /* Parity */
  1284.                         switch ( pa2 & 0x07 ) {
  1285.                         case 0x00:      /* None */
  1286.                             break;
  1287.                         case 0x01:      /* Space */
  1288.                             break;
  1289.                         case 0x02:      /* Mark */
  1290.                             break;
  1291.                         case 0x03:      /* Odd (default) */
  1292.                             break;
  1293.                         case 0x04:      /* Even */
  1294.                             break;
  1295.                         }
  1296.                     }
  1297.  
  1298.                     if ( GOT_PA3(n) ) {
  1299.                         /* Reserved */
  1300.                         if ( pa3 & 0x10 )
  1301.                             ;   /* Reserved */
  1302.                         else
  1303.                             ;   /* Reserved (always) */
  1304.  
  1305.                         /* Reserved */
  1306.                         if ( pa3 & 0x08 )
  1307.                             ;   /* illegal value */
  1308.                         else
  1309.                             ;   /* Reserved (always) */
  1310.  
  1311.                         /* Reserved */
  1312.                         if ( pa3 & 0x04 )
  1313.                             ;   /* Reserved */
  1314.                         else
  1315.                             ;   /* Reserved (always) */
  1316.  
  1317.                         if ( pa3 & 0x02 )
  1318.                             ;   /* Enable outbound pacing is returned in */
  1319.                                 /* response to the Read Control 6 command */
  1320.                         else
  1321.                             ;   /* Reserved */
  1322.  
  1323.                         /* Reserved */
  1324.                         if ( pa3 & 0x01 )
  1325.                             ;   /* Enable inbound pacing is returned in */
  1326.                                 /* response to the Read Control 6 command */
  1327.                         else
  1328.                             ;   /* Reserved */
  1329.  
  1330.                     }
  1331.  
  1332.                     if ( GOT_PA4(n) ) {
  1333.                         /* Reserved */
  1334.                         /* Bits 5 and 4 are always 0 */
  1335.  
  1336.                         /* Inbound Pass-through */
  1337.                         if ( pa4 & 0x04 )
  1338.                             ;   /* Enabled */
  1339.                         else
  1340.                             ;   /* Disabled (default) */
  1341.  
  1342.                         /* ... */
  1343.                         switch ( pa4 & 0x03 ) {
  1344.                         case 0x00:      /* Reserved */
  1345.                             break;
  1346.                         case 0x01:      /* Enable outbound trace is returned */
  1347.                                         /* in response to the Read Control 6 */
  1348.                                         /* command.                          */
  1349.                             break;
  1350.                         }
  1351.                     }
  1352.                     break;
  1353.  
  1354.                 default:
  1355.                     escstate = ES_NORMAL ;
  1356.                     i31ascii(ch);
  1357.                 }
  1358.                 break;
  1359.             }
  1360.             case '&': {
  1361.                 ch2 = i31inc() ;
  1362.                 switch ( ch2 ) {
  1363.                 case ':':
  1364.                     /* Enable Host Protect */
  1365.                     if ( debses )
  1366.                         break;
  1367.                     break;
  1368.                 case ';':
  1369.                     /* Disable Host Protect */
  1370.                     if ( debses )
  1371.                         break;
  1372.                     break;
  1373.                 case '7':
  1374.                     /* 3161 - Read Control 7 */
  1375.                     /* Information used for print operations */
  1376.                     if ( debses )
  1377.                         break;
  1378.                     break;
  1379.                 case '9':
  1380.                     /* 3161 - Set Control 7 */
  1381.                     /* Information used for print operations */
  1382.                     n = i31rdctrl( 3, &pa1, &pa2, &pa3, &pa4, &op );
  1383.  
  1384.                     if ( debses || n == 0 )
  1385.                         break;
  1386.  
  1387.                     if ( GOT_OP(n) ) {
  1388.                         if ( (op & BIT7|BIT6) == 0x60 )
  1389.                         switch ( (op & 0x1F) ) {
  1390.                         case 0x00:      /* Replacement (default) */
  1391.                             break;
  1392.                         case 0x01:      /* Logical OR */
  1393.                             break;
  1394.                         case 0x02:      /* Logical AND */
  1395.                             break;
  1396.                         case 0x1F:      /* Interpreted as the DEL character */
  1397.                             break;
  1398.                         }
  1399.                     }
  1400.  
  1401.                     /* The following lines must be merged in to the above */
  1402.                     /* switch to enable the replace|and|or functionality  */
  1403.                     if ( GOT_PA1(n) ) {
  1404.                         /* Bit 5 Reserved */
  1405.  
  1406.                         switch ( pa1 & 0x0C ) {
  1407.                         case 0x00:      /* Print screen is returned in */
  1408.                                         /* response to the Read Control 7 */
  1409.                                         /* command. */
  1410.                             break;
  1411.                         }
  1412.  
  1413.                         switch ( pa1 & 0x03 ) {
  1414.                         case 0x00:      /* No time fill character is returned */
  1415.                                         /* in response to the Read Control 7 */
  1416.                                         /* command. */
  1417.                             break;
  1418.                         }
  1419.                     }
  1420.  
  1421.                     if ( GOT_PA2(n) ) {
  1422.                         if ( pa2 & 0x10 )
  1423.                             ;   /* undefined */
  1424.                         else
  1425.                             ;   /* CR/LF for the line end character is returned */
  1426.                                 /* in response to the Read Control 7 command */
  1427.  
  1428.                         if ( pa2 & 0x08 )
  1429.                             ;   /* Print data null suppression is returned in */
  1430.                                 /* response to the Read Control 7 command */
  1431.                         else
  1432.                             ;   /* Reserved */
  1433.  
  1434.                         if ( pa2 & 0x04 )
  1435.                             ;   /* Print EOL on is returned in response to the */
  1436.                                 /* Read Control 7 command */
  1437.                         else
  1438.                             ;   /* Reserved */
  1439.  
  1440.                         /* Characters */
  1441.                         switch ( pa2 & 0x03 ) {
  1442.                         case 0x00:      /* National (default) */
  1443.                             break;
  1444.                         case 0x01:      /* Reserved */
  1445.                         case 0x02:      /* Reserved */
  1446.                             break;
  1447.                         case 0x03:      /* All */
  1448.                             break;
  1449.                         }
  1450.                     }
  1451.  
  1452.                     if ( GOT_PA3(n) ) {
  1453.                         /* Bit 5 Reserved - always 0 */
  1454.  
  1455.                         switch ( pa3 & 0x0F ) {
  1456.                         case 0x00:      /* Reserved */
  1457.                             break;
  1458.                         case 0x05:      /* Is the response to the Read */
  1459.                                         /* Control 7 command that the DTR */
  1460.                                         /* signal (+) is being monitored. */
  1461.                             break;
  1462.                         }
  1463.                     }
  1464.                     break;
  1465.  
  1466.                 default:
  1467.                     escstate = ES_NORMAL ;
  1468.                     i31ascii(ch);
  1469.                 }
  1470.                 break;
  1471.             }
  1472.             case '+': {
  1473.                 ch2 = i31inc() ;
  1474.                 switch ( ch2 ) {
  1475.                 case ':':
  1476.                     /* Enable Partition Line Separator */
  1477.                     if ( debses )
  1478.                         break;
  1479.                     break;
  1480.                 case ';':
  1481.                     /* Disable Partition Line Separator */
  1482.                     if ( debses )
  1483.                         break;
  1484.                     break;
  1485.                 default:
  1486.                     escstate = ES_NORMAL ;
  1487.                     i31ascii(ch);
  1488.                 }
  1489.                 break;
  1490.             }
  1491.             case '*': {
  1492.                 ch2 = i31inc() ;
  1493.                 switch ( ch2 ) {
  1494.                 case ':':
  1495.                     /* Enable OIA Divider Line */
  1496.                     if ( debses )
  1497.                         break;
  1498.                     break;
  1499.                 case ';':
  1500.                     /* Disable OIA Divider Line */
  1501.                     if ( debses )
  1502.                         break;
  1503.                     break;
  1504.                 default:
  1505.                     escstate = ES_NORMAL ;
  1506.                     i31ascii(ch);
  1507.                 }
  1508.                 break;
  1509.             }
  1510.             case '\'': {
  1511.                 ch2 = i31inc() ;
  1512.                 switch ( ch2 ) {
  1513.                 case ':':
  1514.                     /* Enable Default Field Attribute */
  1515.                     if ( debses )
  1516.                         break;
  1517.                     break;
  1518.                 case ';':
  1519.                     /* Disable Default Field Attribute */
  1520.                     if ( debses )
  1521.                         break;
  1522.                     break;
  1523.                 default:
  1524.                     escstate = ES_NORMAL ;
  1525.                     i31ascii(ch);
  1526.                 }
  1527.                 break;
  1528.             }
  1529.             case ',': {
  1530.                 ch2 = i31inc() ;
  1531.                 switch ( ch2 ) {
  1532.                 case ':':
  1533.                     /* Enable Field Attribute Visible Renditions */
  1534.                     if ( debses )
  1535.                         break;
  1536.                     break;
  1537.                 case ';':
  1538.                     /* Disable Field Attribute Visible Renditions */
  1539.                     if ( debses )
  1540.                         break;
  1541.                     break;
  1542.                 default:
  1543.                     escstate = ES_NORMAL ;
  1544.                     i31ascii(ch);
  1545.                 }
  1546.                 break;
  1547.             }
  1548.             case '=': {
  1549.                 /* Write Host Message to the OIA buffer */
  1550.                 if ( debses )
  1551.                     break;
  1552.                 /* read message until another <ESC> = is received */
  1553.                 /* message may be Terminal Width in length.       */
  1554.                 break;
  1555.             }
  1556.             case ';':   /* Unlock keyboard */
  1557.                 if ( debses )
  1558.                     break;
  1559.                 keylock = FALSE ;
  1560.                 break;
  1561.             case ':':   /* Lock keyboard */
  1562.                 if ( debses )
  1563.                     break;
  1564.                 keylock = TRUE ;
  1565.                 break;
  1566.             case '<': {
  1567.                 /* 3161 - Select Character Set G0 */
  1568.                 struct _vtG * pG;
  1569.                 int cs = -1;
  1570.  
  1571.                 pa = i31inc();
  1572.                 if ( debses )
  1573.                     break;
  1574.  
  1575.                 pG = &G[0];
  1576.  
  1577.                 switch ( pa ) {
  1578.                 case '@':       /* US ASCII */
  1579.                     cs = TX_ASCII;
  1580.                     break;
  1581.                 case 'A':       /* Special Graphics */
  1582.                     cs = TX_WYSE60G_1;
  1583.                     break;
  1584.                 case 'B':
  1585.                     break;
  1586.                 }
  1587.  
  1588.                 if ( cs > -1 ) {
  1589.                     pG->designation = cs ;
  1590.                     pG->size = cs96;
  1591.                     pG->c1 = cs_is_std(cs) ;
  1592.                     pG->national = CSisNRC( cs ) ;
  1593.                     pG->rtoi = xl_u[cs] ;
  1594.                     pG->itol = xl_tx[tcsl] ;
  1595.                     pG->ltoi = xl_u[tcsl] ;
  1596.                     pG->itor = xl_tx[cs] ;
  1597.                 }
  1598.                 break;
  1599.             }
  1600.             case '>': {
  1601.                 /* 3161 - Select Character Set G1 */
  1602.                 struct _vtG * pG;
  1603.                 int cs = -1;
  1604.  
  1605.                 pa = i31inc();
  1606.                 if ( debses )
  1607.                     break;
  1608.  
  1609.                 pG = &G[1];
  1610.  
  1611.                 switch ( pa ) {
  1612.                 case '@':       /* US ASCII */
  1613.                     cs = TX_ASCII;
  1614.                     break;
  1615.                 case 'A':       /* Special Graphics */
  1616.                     cs = TX_WYSE60G_1;
  1617.                     break;
  1618.                 case 'B':       /* unknown - used after Special Graphics */
  1619.                     break;
  1620.                 }
  1621.  
  1622.                 if ( cs > -1 ) {
  1623.                     pG->designation = cs ;
  1624.                     pG->size = cs96;
  1625.                     pG->c1 = cs_is_std(cs) ;
  1626.                     pG->national = CSisNRC( cs ) ;
  1627.                     pG->rtoi = xl_u[cs] ;
  1628.                     pG->itol = xl_tx[tcsl] ;
  1629.                     pG->ltoi = xl_u[tcsl] ;
  1630.                     pG->itor = xl_tx[cs] ;
  1631.                 }
  1632.                 break;
  1633.             }
  1634.             case '0':
  1635.                 /* Set tab stop */
  1636.                 if ( debses )
  1637.                     break;
  1638.                 htab[wherex[VTERM]] = 'T';
  1639.                 break;
  1640.             case '1':
  1641.                 /* Clear tab stop */
  1642.                 if ( debses )
  1643.                     break;
  1644.                 htab[wherex[VTERM]] = '0';
  1645.                 break;
  1646.             case '2':
  1647.                 /* 3101-2x and 3161 - Backtab */
  1648.                 if ( debses )
  1649.                     break;
  1650.                 i = wherex[VTERM];
  1651.                 if (i > 1) {
  1652.                     do {
  1653.                         i--;
  1654.                         cursorleft(0);
  1655.                     } while ((htab[i] != 'T') &&
  1656.                               (i >= 2));
  1657.                     VscrnIsDirty(VTERM);
  1658.                 }
  1659.                 break;
  1660.             case '3':
  1661.                 /* 3101-2x and 3161 - Set field attribute */
  1662.                 n = i31rdctrl( 2, &pa1, &pa2, &pa3, &pa4, &op );
  1663.                 if ( debses || n == 0)
  1664.                     break;
  1665.                 /* field attributes take up a character position */
  1666.                 if ( !GOT_OP(n) )
  1667.                     op = BIT7|BIT6;     /* Replacement */
  1668.  
  1669.                 if ( (op & (BIT7|BIT6)) == 0x60 ) {
  1670.                     switch ( (op & (BIT5|BIT4|BIT3|BIT2|BIT1)) ) {
  1671.                     case 0x00:      /* Replacement (default) */
  1672.                         if ( GOT_PA1(n) ) {
  1673.                             /* Normal or Non-display */
  1674.                             if ( pa1 & BIT5 )
  1675.                                 attrib.invisible=TRUE;   /* Non-display */
  1676.                             else
  1677.                                 attrib.invisible=FALSE;   /* Normal (default) */
  1678.  
  1679.                             /* Intensity */
  1680.                             if ( pa1 & BIT4 )
  1681.                                 attrib.bold=TRUE;    /* High Intensity */
  1682.                             else
  1683.                                 attrib.bold=FALSE;   /* Normal (default) */
  1684.  
  1685.                             /* Blink */
  1686.                             if ( pa1 & BIT3 )
  1687.                                 attrib.blinking=TRUE;   /* Blink On */
  1688.                             else
  1689.                                 attrib.blinking=FALSE;  /* Blink off (default) */
  1690.  
  1691.                             /* Underline */
  1692.                             if ( pa1 & BIT2 )
  1693.                                 attrib.underlined=TRUE;  /* Underline On */
  1694.                             else
  1695.                                 attrib.underlined=FALSE;  /* Underline Off (default) */
  1696.  
  1697.                             /* Reverse */
  1698.                             if ( pa1 & BIT1 )
  1699.                                 attrib.reversed=TRUE;   /* Reverse */
  1700.                             else
  1701.                                 attrib.reversed=FALSE;  /* Normal (default) */
  1702.                         }
  1703.  
  1704.                         if ( GOT_PA2(n) ) {
  1705.                             /* Numeric */
  1706.                             if ( pa2 & BIT4 )
  1707.                                 ;   /* Yes */
  1708.                             else
  1709.                                 ;   /* No (default) */
  1710.  
  1711.                             /* Protected */
  1712.                             if ( pa2 & BIT2 )
  1713.                                 attrib.unerasable=TRUE;   /* Protected */
  1714.                             else
  1715.                                 attrib.unerasable=FALSE;  /* Unprotected (default) */
  1716.  
  1717.                             /* Modified Data Tag */
  1718.                             if ( pa2 & BIT1 )
  1719.                                 ;   /* Modified */
  1720.                             else
  1721.                                 ;   /* Not modified (default) */
  1722.                             }
  1723.  
  1724.                         break;
  1725.                     case 0x01:      /* Logical OR */
  1726.                         if ( GOT_PA1(n) ) {
  1727.                             /* Normal or Non-display */
  1728.                             if ( pa1 & BIT5 )
  1729.                                 attrib.invisible=TRUE;   /* Non-display */
  1730.  
  1731.                             /* Intensity */
  1732.                             if ( pa1 & BIT4 )
  1733.                                 attrib.bold=TRUE;    /* High Intensity */
  1734.  
  1735.                             /* Blink */
  1736.                                 if ( pa1 & BIT3 )
  1737.                                     attrib.blinking=TRUE;   /* Blink On */
  1738.  
  1739.                             /* Underline */
  1740.                             if ( pa1 & BIT2 )
  1741.                                 attrib.underlined=TRUE;  /* Underline On */
  1742.  
  1743.                             /* Reverse */
  1744.                             if ( pa1 & BIT1 )
  1745.                                 attrib.reversed=TRUE;   /* Reverse */
  1746.                         }
  1747.  
  1748.                         if ( GOT_PA2(n) ) {
  1749.                             /* Numeric */
  1750.                             if ( pa2 & BIT4 )
  1751.                                 ;   /* Yes */
  1752.  
  1753.                             /* Protected */
  1754.                             if ( pa2 & BIT2 )
  1755.                                 attrib.unerasable=TRUE;   /* Protected */
  1756.  
  1757.                             /* Modified Data Tag */
  1758.                             if ( pa2 & BIT1 )
  1759.                                 ;   /* Modified */
  1760.                         }
  1761.  
  1762.                         break;
  1763.                     case 0x02:      /* Logical AND */
  1764.                         if ( GOT_PA1(n) ) {
  1765.                             /* Normal or Non-display */
  1766.                             if ( !(pa1 & BIT5) )
  1767.                                 attrib.invisible=FALSE;   /* Normal (default) */
  1768.  
  1769.                             /* Intensity */
  1770.                             if ( !(pa1 & BIT4) )
  1771.                                 attrib.bold=FALSE;   /* Normal (default) */
  1772.  
  1773.                             /* Blink */
  1774.                             if ( !(pa1 & BIT3) )
  1775.                                 attrib.blinking=FALSE;  /* Blink off (default) */
  1776.  
  1777.                             /* Underline */
  1778.                             if ( !(pa1 & BIT2) )
  1779.                                 attrib.underlined=FALSE;  /* Underline Off (default) */
  1780.  
  1781.                             /* Reverse */
  1782.                             if ( !(pa1 & BIT1) )
  1783.                                 attrib.reversed=FALSE;  /* Normal (default) */
  1784.                         }
  1785.  
  1786.                         if ( GOT_PA2(n) ) {
  1787.                             /* Numeric */
  1788.                             if ( !(pa2 & BIT4) )
  1789.                                 ;   /* No (default) */
  1790.  
  1791.                             /* Protected */
  1792.                             if ( !(pa2 & BIT2) )
  1793.                                 attrib.unerasable=FALSE;  /* Unprotected (default) */
  1794.  
  1795.                             /* Modified Data Tag */
  1796.                             if ( !(pa2 & BIT1) )
  1797.                                 ;   /* Not modified (default) */
  1798.                         }
  1799.                         break;
  1800.                     case 0x1F:      /* Interpreted as the DEL character */
  1801.                         wrtch(DEL);
  1802.                         break;
  1803.                     }
  1804.                 }
  1805.                 break;
  1806.             case '4':
  1807.                 /* 3161 - Set character attribute */
  1808.                 n = i31rdctrl( 1, &pa1, &pa2, &pa3, &pa4, &op );
  1809.                 if ( debses || n == 0 )
  1810.                     break;
  1811.  
  1812.                 /* Character attributes do not take up a position */
  1813.                 if ( !GOT_OP(n) )
  1814.                     op = BIT7|BIT6;
  1815.  
  1816.                 if ( (op & (BIT7|BIT6)) == 0x60 ) {
  1817.                     switch ( (op & (BIT5|BIT4|BIT3|BIT2|BIT1)) ) {
  1818.                     case 0x00:      /* Replacement (default) */
  1819.                         if ( GOT_PA1(n) ) {
  1820.                             /* Normal or Non-display */
  1821.                             if ( pa1 & BIT5 )
  1822.                                 attrib.invisible=TRUE;   /* Non-display */
  1823.                             else
  1824.                                 attrib.invisible=FALSE;   /* Normal (default) */
  1825.  
  1826.                             /* Intensity */
  1827.                             if ( pa1 & BIT4 )
  1828.                                 attrib.bold=TRUE;    /* High Intensity */
  1829.                             else
  1830.                                 attrib.bold=FALSE;   /* Normal (default) */
  1831.  
  1832.                             /* Blink */
  1833.                             if ( pa1 & BIT3 )
  1834.                                 attrib.blinking=TRUE;   /* Blink On */
  1835.                             else
  1836.                                 attrib.blinking=FALSE;  /* Blink off (default) */
  1837.  
  1838.                             /* Underline */
  1839.                             if ( pa1 & BIT2 )
  1840.                                 attrib.underlined=TRUE;  /* Underline On */
  1841.                             else
  1842.                                 attrib.underlined=FALSE;  /* Underline Off (default) */
  1843.  
  1844.                             /* Reverse */
  1845.                             if ( pa1 & BIT1 )
  1846.                                 attrib.reversed=TRUE;   /* Reverse */
  1847.                             else
  1848.                                 attrib.reversed=FALSE;  /* Normal (default) */
  1849.                         }
  1850.  
  1851.                         if ( GOT_PA2(n) ) {
  1852.                             /* Numeric */
  1853.                             if ( pa2 & BIT4 )
  1854.                                 ;   /* Yes */
  1855.                             else
  1856.                                 ;   /* No (default) */
  1857.  
  1858.                             /* Protected */
  1859.                             if ( pa2 & BIT2 )
  1860.                                 attrib.unerasable=TRUE;   /* Protected */
  1861.                             else
  1862.                                 attrib.unerasable=FALSE;  /* Unprotected (default) */
  1863.  
  1864.                             /* Modified Data Tag */
  1865.                             if ( pa2 & BIT1 )
  1866.                                 ;   /* Modified */
  1867.                             else
  1868.                                 ;   /* Not modified (default) */
  1869.                         }
  1870.  
  1871.                         break;
  1872.                     case 0x01:      /* Logical OR */
  1873.                         if ( GOT_PA1(n) ) {
  1874.                             /* Normal or Non-display */
  1875.                             if ( pa1 & BIT5 )
  1876.                                 attrib.invisible=TRUE;   /* Non-display */
  1877.  
  1878.                             /* Intensity */
  1879.                             if ( pa1 & BIT4 )
  1880.                                 attrib.bold=TRUE;    /* High Intensity */
  1881.  
  1882.                             /* Blink */
  1883.                             if ( pa1 & BIT3 )
  1884.                                 attrib.blinking=TRUE;   /* Blink On */
  1885.  
  1886.                             /* Underline */
  1887.                             if ( pa1 & BIT2 )
  1888.                                 attrib.underlined=TRUE;  /* Underline On */
  1889.  
  1890.                             /* Reverse */
  1891.                             if ( pa1 & BIT1 )
  1892.                                 attrib.reversed=TRUE;   /* Reverse */
  1893.                         }
  1894.  
  1895.                         if ( GOT_PA2(n) ) {
  1896.                             /* Numeric */
  1897.                             if ( pa2 & BIT4 )
  1898.                                 ;   /* Yes */
  1899.  
  1900.                             /* Protected */
  1901.                             if ( pa2 & BIT2 )
  1902.                                 attrib.unerasable=TRUE;   /* Protected */
  1903.  
  1904.                             /* Modified Data Tag */
  1905.                             if ( pa2 & BIT1 )
  1906.                                 ;   /* Modified */
  1907.                         }
  1908.  
  1909.                         break;
  1910.                     case 0x02:      /* Logical AND */
  1911.                         if ( GOT_PA1(n) ) {
  1912.                             /* Normal or Non-display */
  1913.                             if ( !(pa1 & BIT5) )
  1914.                                 attrib.invisible=FALSE;   /* Normal (default) */
  1915.  
  1916.                             /* Intensity */
  1917.                             if ( !(pa1 & BIT4) )
  1918.                                 attrib.bold=FALSE;   /* Normal (default) */
  1919.  
  1920.                             /* Blink */
  1921.                             if ( !(pa1 & BIT3) )
  1922.                                 attrib.blinking=FALSE;  /* Blink off (default) */
  1923.  
  1924.                             /* Underline */
  1925.                             if ( !(pa1 & BIT2) )
  1926.                                 attrib.underlined=FALSE;  /* Underline Off (default) */
  1927.  
  1928.                             /* Reverse */
  1929.                             if ( !(pa1 & BIT1) )
  1930.                                 attrib.reversed=FALSE;  /* Normal (default) */
  1931.                         }
  1932.  
  1933.                         if ( GOT_PA2(n) ) {
  1934.                             /* Numeric */
  1935.                             if ( !(pa2 & BIT4) )
  1936.                                 ;   /* No (default) */
  1937.  
  1938.                             /* Protected */
  1939.                             if ( !(pa2 & BIT2) )
  1940.                                 attrib.unerasable=FALSE;  /* Unprotected (default) */
  1941.  
  1942.                             /* Modified Data Tag */
  1943.                             if ( !(pa2 & BIT1) )
  1944.                                 ;   /* Not modified (default) */
  1945.                         }
  1946.                         break;
  1947.                     case 0x1F:      /* Interpreted as the DEL character */
  1948.                         wrtch(DEL);
  1949.                         break;
  1950.                     }
  1951.                 }
  1952.                 break;
  1953.             case '5':
  1954.                 /* 3161 - Read cursor address in 80-column current page */
  1955.                 if ( debses )
  1956.                     break;
  1957.                 /* send Set Cursor Address response */
  1958.                 break;
  1959.             case '6':   {
  1960.                 /* 3101 - Read status */
  1961.                 /* 3161 - Report terminal status */
  1962.                 if ( debses )
  1963.                     break;
  1964.                 /* send ESC 6 pa1 pa2 LTA */
  1965.                 break;
  1966.             }
  1967.             case '7':   /* 3101 - Read setup switch */
  1968.                 if ( debses )
  1969.                     break;
  1970.                 break;
  1971.             case '8':   /* 3101-2x and 3161 - Read Page (buffer) */
  1972.                 if ( debses )
  1973.                     break;
  1974.                 break;
  1975.             case '9':   /* 3101 - Set control */
  1976.                 if ( debses )
  1977.                     break;
  1978.                 break;
  1979.             case 'A':
  1980.                 /* Cursor Up; no scroll */
  1981.                 if ( debses )
  1982.                     break;
  1983.                 cursorup(0) ;
  1984.                 break;
  1985.             case 'B':
  1986.                 /* Cursor Down; no scroll */
  1987.                 if ( debses )
  1988.                     break;
  1989.                 cursordown(0) ;
  1990.                 break;
  1991.             case 'C':
  1992.                 /* Curosr Right */
  1993.                 if ( debses )
  1994.                     break;
  1995.                 cursorright(0) ;
  1996.                 break;
  1997.             case 'D':
  1998.                 /* Cursor Left (backspace) */
  1999.                 if ( debses )
  2000.                     break;
  2001.                 cursorleft(0) ;
  2002.                 break;
  2003.             case 'E':
  2004.                 /* 3101-2x and 3161 - Write Send Mark */
  2005.                 if ( debses )
  2006.                     break;
  2007.                 /* places a send mark at the current cursor/buffer   */
  2008.                 /* address location depending on mode.  Replaces any */
  2009.                 /* previous Send Mark with NUL.                      */
  2010.                 break;
  2011.             case 'H':
  2012.                 /* Cursor Home Command */
  2013.                 /* and change to cursor addr mode from buffer addr mode */
  2014.                 if ( debses )
  2015.                     break;
  2016.                 lgotoxy(VTERM,1,1);
  2017.                 break;
  2018.             case 'I':
  2019.                 /* 3101-1x - Clear line to nulls from cursor */
  2020.                 /* 3101-2x and 3161 - Clear unprotected line */
  2021.                 /*                    to nulls from cursor  */
  2022.                 if ( debses )
  2023.                     break;
  2024.                 clrtoeoln( VTERM, NUL );
  2025.                 break;
  2026.             case 'J':
  2027.                 /* Clear unprotected page to spaces from cursor */
  2028.                 if ( debses )
  2029.                     break;
  2030.                 clreoscr_escape( VTERM, NUL );
  2031.                 break;
  2032.             case 'K':
  2033.                 /* Clear input */
  2034.                 if ( debses )
  2035.                     break;
  2036.                 clrscreen(VTERM,NUL);
  2037.                 lgotoxy(VTERM,1,1);       /* and home the cursor */
  2038.                 break;
  2039.             case 'L':
  2040.                 /* 3101-2x and 3161 - Clear page to nulls */
  2041.                 if ( debses )
  2042.                     break;
  2043.                 clrscreen( VTERM, NUL );
  2044.                 lgotoxy(VTERM,1,1);       /* and home the cursor */
  2045.                 break;
  2046.             case 'M':
  2047.                 /* Cursor to start of next line */
  2048.                 if ( debses )
  2049.                     break;
  2050.                 wrtch(CR);
  2051.                 wrtch(LF);
  2052.                 break;
  2053.             case 'N':
  2054.                 /* 3101-2x and 3161 - Insert line of nulls */
  2055.                 if ( debses )
  2056.                     break;
  2057.                 VscrnScroll(VTERM, DOWNWARD, wherey[VTERM] - 1,
  2058.                              marginbot - 1, 1, FALSE, NUL);
  2059.                 break;
  2060.             case 'O':
  2061.                 /* 3101-2x and 3161 - Delete cursor line */
  2062.                 if ( debses )
  2063.                     break;
  2064.                 VscrnScroll(VTERM,
  2065.                              UPWARD,
  2066.                              wherey[VTERM] - 1,
  2067.                              marginbot - 1,
  2068.                              1,
  2069.                              FALSE,
  2070.                              SP);
  2071.                 break;
  2072.             case 'P': {
  2073.                 /* Insert Character Command */
  2074.                 pa = i31inc();
  2075.                 if ( debses )
  2076.                     break;
  2077.  
  2078.                 break;
  2079.             }
  2080.             case 'Q': {
  2081.                 /* 3101-2x and 3161 - Delete cursor character */
  2082.                 viocell blankvcell ;
  2083.                 if ( debses )
  2084.                     break;
  2085.                 blankvcell.c = SP;
  2086.                 blankvcell.a = geterasecolor(VTERM);
  2087.                 VscrnScrollLf(VTERM, wherey[VTERM] - 1,
  2088.                                wherex[VTERM] - 1,
  2089.                                wherey[VTERM] - 1,
  2090.                                VscrnGetWidth(VTERM) - 1,
  2091.                                1, blankvcell) ;
  2092.                 break;
  2093.             }
  2094.             case 'S':
  2095.                 /* Cancel Command */
  2096.                 if ( debses )
  2097.                     break;
  2098.                 break;
  2099.             case 't': {
  2100.                 /* 3161 - Default function key */
  2101.                 int fn=0,fnx=0;
  2102.                 fn = i31inc();
  2103.                 if ( !(fn&BIT7) && (fn&BIT6) )
  2104.                     fnx = i31inc();
  2105.                 if ( debses )
  2106.                     break;
  2107.                 break;
  2108.             }
  2109.             case 'U':
  2110.                 /* 3101 - Print line */
  2111.                 if ( debses )
  2112.                     break;
  2113.                 break;
  2114.             case 'V':
  2115.                 /* 3101 - Print message */
  2116.                 if ( debses )
  2117.                     break;
  2118.                 break;
  2119.             case 'W':
  2120.                 /* 3101 - Print formatted page */
  2121.                 /* 3161 - Print viewport */
  2122.                 if ( debses )
  2123.                     break;
  2124.                 break;
  2125.             case 'X': {
  2126.                 /* Set buffer address */
  2127.                 int pr, pc ;
  2128.                 pr = i31inc();
  2129.                 pc = i31inc();
  2130.                 if ( debses )
  2131.                     break;
  2132.  
  2133.                 break;
  2134.             }
  2135.             case 'x': {
  2136.                 /* Extended Set buffer address */
  2137.                 int prh, prl, pch, pcl ;
  2138.                 prh = i31inc();
  2139.                 prl = i31inc();
  2140.                 pch = i31inc();
  2141.                 pcl = i31inc();
  2142.                 if ( debses )
  2143.                     break;
  2144.  
  2145.                 break;
  2146.             }
  2147.             case 'Y': {
  2148.                 /* Address cursor in 80-column current page */
  2149.                 int pr, pc ;
  2150.                 pr = i31inc();
  2151.                 pc = i31inc();
  2152.                 if ( debses )
  2153.                     break;
  2154.  
  2155.                 lgotoxy( VTERM, pc-31, pr-31 ) ;
  2156.                 break;
  2157.             }
  2158.             case 'y': {
  2159.                 /* Extended Set cursor address */
  2160.                 int prh, prl, pch, pcl ;
  2161.                 prh = i31inc();
  2162.                 prl = i31inc();
  2163.                 pch = i31inc();
  2164.                 pcl = i31inc();
  2165.                 if ( debses )
  2166.                     break;
  2167.                 lgotoxy( VTERM, (pch-32)*32+pcl-31,
  2168.                          (prh-32)*32+prl-31-SP ) ;
  2169.                 break;
  2170.             }
  2171.             case 'Z':
  2172.                 /* Insert cursor */
  2173.                 if ( debses )
  2174.                     break;
  2175.                 break;
  2176.             case ')': {
  2177.                 ch2 = i31inc();
  2178.                 switch ( ch2 ) {
  2179.                 case ':':
  2180.                     /* Enable Print Key Attention command */
  2181.                     if ( debses )
  2182.                         break;
  2183.                     break;
  2184.                 case ';':
  2185.                     /* Disable Print Key Attention command (default) */
  2186.                     if ( debses )
  2187.                         break;
  2188.                     break;
  2189.                 }
  2190.                 break;
  2191.             }
  2192.             case '(': {
  2193.                 ch2 = i31inc();
  2194.                 switch ( ch2 ) {
  2195.                 case ':':
  2196.                     /* Enable Reset Key Attention command */
  2197.                     if ( debses )
  2198.                         break;
  2199.                     break;
  2200.                 case ';':
  2201.                     /* Disable Reset Key Attention command (default) */
  2202.                     if ( debses )
  2203.                         break;
  2204.                     break;
  2205.                 }
  2206.                 break;
  2207.             }
  2208.             }
  2209.             escstate = ES_NORMAL ;      /* Done parsing escstate sequence */
  2210.         }
  2211.     }
  2212.     else                /* Handle as a normal character */
  2213.     {
  2214.         if ( ch < SP )
  2215.             i31ctrl(ch) ;
  2216.         else if ( !debses ) {
  2217.             if (printon && is_xprint())
  2218.                 prtchar(ch);
  2219.             else {
  2220.                 if (printon && is_uprint())
  2221.                     prtchar(ch);
  2222.                 wrtch(ch);
  2223.             }
  2224.         }
  2225.     }
  2226.     VscrnIsDirty(VTERM) ;
  2227. }
  2228. #endif /* NOTERM */
  2229.