Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3998 - (hide annotations) (download) (as text)
Sun Aug 15 11:59:22 2010 UTC (13 years, 7 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 90760 byte(s)
DECSLE で複数のパラメータが正しく扱えていなかったのを修正。

1 maya 3227 /* Tera Term
2     Copyright(C) 1994-1998 T. Teranishi
3     All rights reserved. */
4    
5     /* TERATERM.EXE, VT terminal emulation */
6     #include "teraterm.h"
7     #include "tttypes.h"
8     #include <stdio.h>
9     #include <string.h>
10     #include <stdlib.h>
11     #include <mbstring.h>
12     #include <locale.h>
13    
14     #include "buffer.h"
15     #include "ttwinman.h"
16     #include "ttcommon.h"
17     #include "commlib.h"
18     #include "vtdisp.h"
19     #include "keyboard.h"
20     #include "ttlib.h"
21     #include "ttftypes.h"
22     #include "filesys.h"
23     #include "teraprn.h"
24     #include "telnet.h"
25    
26     #include "vtterm.h"
27    
28 doda 3443 #define MAPSIZE(x) (sizeof(x)/sizeof((x)[0]))
29 doda 3491 #define Accept8BitCtrl ((ts.TerminalID>=IdVT220J) && (ts.TermFlag & TF_ACCEPT8BITCTRL))
30 doda 3443
31 maya 3227 /* Parsing modes */
32     #define ModeFirst 0
33     #define ModeESC 1
34     #define ModeDCS 2
35     #define ModeDCUserKey 3
36     #define ModeSOS 4
37     #define ModeCSI 5
38     #define ModeXS 6
39     #define ModeDLE 7
40     #define ModeCAN 8
41    
42     #define NParamMax 16
43     #define IntCharMax 5
44    
45 doda 3997 /* DEC Locator Flag */
46     #define DecLocatorOneShot 1
47     #define DecLocatorPixel 2
48     #define DecLocatorButtonDown 4
49     #define DecLocatorButtonUp 8
50     #define DecLocatorFiltered 16
51    
52 maya 3227 void VisualBell();
53    
54     /* character attribute */
55     static TCharAttr CharAttr;
56    
57     /* various modes of VT emulation */
58     static BOOL RelativeOrgMode;
59     static BOOL InsertMode;
60     static BOOL LFMode;
61     static BOOL AutoWrapMode;
62     static BOOL FocusReportMode;
63 doda 3743 static BOOL AltScr;
64 doda 3872 BOOL BracketedPaste;
65 maya 3227
66     // save/restore cursor
67     typedef struct {
68     int CursorX, CursorY;
69     TCharAttr Attr;
70     int Glr[2], Gn[4]; // G0-G3, GL & GR
71     BOOL AutoWrapMode;
72     BOOL RelativeOrgMode;
73     } TStatusBuff;
74     typedef TStatusBuff *PStatusBuff;
75    
76     // status buffer for main screen & status line
77 doda 3797 static TStatusBuff SBuff1, SBuff2, SBuff3;
78 maya 3227
79     static BOOL ESCFlag, JustAfterESC;
80     static BOOL KanjiIn;
81     static BOOL EUCkanaIn, EUCsupIn;
82     static int EUCcount;
83     static BOOL Special;
84    
85     static int Param[NParamMax+1];
86     static int NParam;
87     static BOOL FirstPrm;
88     static BYTE IntChar[IntCharMax+1];
89     static int ICount;
90     static BYTE Prv;
91     static int ParseMode, SavedMode;
92     static int ChangeEmu;
93    
94     /* user defined keys */
95     static BOOL WaitKeyId, WaitHi;
96    
97     /* GL, GR code group */
98     static int Glr[2];
99     /* G0, G1, G2, G3 code group */
100     static int Gn[4];
101     /* GL for single shift 2/3 */
102     static int GLtmp;
103     /* single shift 2/3 flag */
104     static BOOL SSflag;
105     /* JIS -> SJIS conversion flag */
106     static BOOL ConvJIS;
107     static WORD Kanji;
108    
109     // variables for status line mode
110     static int StatusX=0;
111     static BOOL StatusWrap=FALSE;
112     static BOOL StatusCursor=TRUE;
113     static int MainX, MainY; //cursor registers
114     static int MainTop, MainBottom; // scroll region registers
115     static BOOL MainWrap;
116     static BOOL MainCursor=TRUE;
117    
118     /* status for printer escape sequences */
119     static BOOL PrintEX = TRUE; // printing extent
120     // (TRUE: screen, FALSE: scroll region)
121     static BOOL AutoPrintMode = FALSE;
122     static BOOL PrinterMode = FALSE;
123     static BOOL DirectPrn = FALSE;
124    
125     /* User key */
126     static BYTE NewKeyStr[FuncKeyStrMax];
127     static int NewKeyId, NewKeyLen;
128    
129 doda 3997 /* Mouse Report */
130     int MouseReportMode;
131     unsigned int DecLocatorFlag;
132     int LastX, LastY;
133     int ButtonStat;
134    
135 doda 3450 static _locale_t CLocale = NULL;
136 maya 3227
137 doda 3916 void ResetSBuffer(PStatusBuff sbuff)
138 maya 3227 {
139 doda 3916 sbuff->CursorX = 0;
140     sbuff->CursorY = 0;
141     sbuff->Attr = DefCharAttr;
142 maya 3227 if (ts.Language==IdJapanese)
143     {
144 doda 3916 sbuff->Gn[0] = IdASCII;
145     sbuff->Gn[1] = IdKatakana;
146     sbuff->Gn[2] = IdKatakana;
147     sbuff->Gn[3] = IdKanji;
148     sbuff->Glr[0] = 0;
149 maya 3227 if ((ts.KanjiCode==IdJIS) &&
150     (ts.JIS7Katakana==0))
151 doda 3916 sbuff->Glr[1] = 2; // 8-bit katakana
152 maya 3227 else
153 doda 3916 sbuff->Glr[1] = 3;
154 maya 3227 }
155     else {
156 doda 3916 sbuff->Gn[0] = IdASCII;
157     sbuff->Gn[1] = IdSpecial;
158     sbuff->Gn[2] = IdASCII;
159     sbuff->Gn[3] = IdASCII;
160     sbuff->Glr[0] = 0;
161     sbuff->Glr[1] = 0;
162 maya 3227 }
163 doda 3916 sbuff->AutoWrapMode = TRUE;
164     sbuff->RelativeOrgMode = FALSE;
165     }
166    
167     void ResetAllSBuffers()
168     {
169     ResetSBuffer(&SBuff1);
170 maya 3227 // copy SBuff1 to SBuff2
171     SBuff2 = SBuff1;
172 doda 3797 SBuff3 = SBuff1;
173 maya 3227 }
174    
175 doda 3916 void ResetCurSBuffer()
176     {
177     PStatusBuff Buff;
178    
179     if (AltScr) {
180     Buff = &SBuff3; // Alternate screen buffer
181     }
182     else {
183     Buff = &SBuff1; // Normal screen buffer
184     }
185     ResetSBuffer(Buff);
186     SBuff2 = *Buff;
187     }
188    
189 maya 3227 void ResetTerminal() /*reset variables but don't update screen */
190     {
191     DispReset();
192     BuffReset();
193    
194     /* Attribute */
195     CharAttr = DefCharAttr;
196     Special = FALSE;
197     BuffSetCurCharAttr(CharAttr);
198    
199     /* Various modes */
200     InsertMode = FALSE;
201     LFMode = (ts.CRSend == IdCRLF);
202     AutoWrapMode = TRUE;
203     AppliKeyMode = FALSE;
204     AppliCursorMode = FALSE;
205     RelativeOrgMode = FALSE;
206     ts.ColorFlag &= ~CF_REVERSEVIDEO;
207     AutoRepeatMode = TRUE;
208     Send8BitMode = ts.Send8BitCtrl;
209     FocusReportMode = FALSE;
210     MouseReportMode = IdMouseTrackNone;
211 doda 3997 DecLocatorFlag = 0;
212 maya 3227
213 doda 3997 LastX = 0;
214     LastY = 0;
215     ButtonStat = 0;
216    
217 doda 3450 if (CLocale == NULL) {
218     CLocale = _create_locale(LC_ALL, "C");
219     }
220 maya 3227
221     /* Character sets */
222     ResetCharSet();
223    
224     /* ESC flag for device control sequence */
225     ESCFlag = FALSE;
226     /* for TEK sequence */
227     JustAfterESC = FALSE;
228    
229     /* Parse mode */
230     ParseMode = ModeFirst;
231    
232     /* Clear printer mode */
233     PrinterMode = FALSE;
234    
235     // status buffers
236 doda 3916 ResetAllSBuffers();
237 doda 3745
238     // Alternate Screen Buffer
239     AltScr = FALSE;
240 doda 3872
241     // Bracketed Paste Mode
242     BracketedPaste = FALSE;
243 maya 3227 }
244    
245     void ResetCharSet()
246     {
247     if (ts.Language==IdJapanese)
248     {
249     Gn[0] = IdASCII;
250     Gn[1] = IdKatakana;
251     Gn[2] = IdKatakana;
252     Gn[3] = IdKanji;
253     Glr[0] = 0;
254     if ((ts.KanjiCode==IdJIS) &&
255     (ts.JIS7Katakana==0))
256     Glr[1] = 2; // 8-bit katakana
257     else
258     Glr[1] = 3;
259     }
260     else {
261     Gn[0] = IdASCII;
262     Gn[1] = IdSpecial;
263     Gn[2] = IdASCII;
264     Gn[3] = IdASCII;
265     Glr[0] = 0;
266     Glr[1] = 0;
267     cv.SendCode = IdASCII;
268     cv.SendKanjiFlag = FALSE;
269     cv.EchoCode = IdASCII;
270     cv.EchoKanjiFlag = FALSE;
271     }
272     /* Kanji flag */
273     KanjiIn = FALSE;
274     EUCkanaIn = FALSE;
275     EUCsupIn = FALSE;
276     SSflag = FALSE;
277    
278     cv.Language = ts.Language;
279     cv.CRSend = ts.CRSend;
280     cv.KanjiCodeEcho = ts.KanjiCode;
281     cv.JIS7KatakanaEcho = ts.JIS7Katakana;
282     cv.KanjiCodeSend = ts.KanjiCodeSend;
283     cv.JIS7KatakanaSend = ts.JIS7KatakanaSend;
284     cv.KanjiIn = ts.KanjiIn;
285     cv.KanjiOut = ts.KanjiOut;
286     }
287    
288     void ResetKeypadMode(BOOL DisabledModeOnly)
289     {
290     if (!DisabledModeOnly || ts.DisableAppKeypad) AppliKeyMode = FALSE;
291     if (!DisabledModeOnly || ts.DisableAppCursor) AppliCursorMode = FALSE;
292     }
293    
294     void MoveToMainScreen()
295     {
296     StatusX = CursorX;
297     StatusWrap = Wrap;
298     StatusCursor = IsCaretEnabled();
299    
300     CursorTop = MainTop;
301     CursorBottom = MainBottom;
302     Wrap = MainWrap;
303     DispEnableCaret(MainCursor);
304     MoveCursor(MainX,MainY); // move to main screen
305     }
306    
307     void MoveToStatusLine()
308     {
309     MainX = CursorX;
310     MainY = CursorY;
311     MainTop = CursorTop;
312     MainBottom = CursorBottom;
313     MainWrap = Wrap;
314     MainCursor = IsCaretEnabled();
315    
316     DispEnableCaret(StatusCursor);
317     MoveCursor(StatusX,NumOfLines-1); // move to status line
318     CursorTop = NumOfLines-1;
319     CursorBottom = CursorTop;
320     Wrap = StatusWrap;
321     }
322    
323     void HideStatusLine()
324     {
325     if ((StatusLine>0) &&
326     (CursorY==NumOfLines-1))
327     MoveToMainScreen();
328     StatusX = 0;
329     StatusWrap = FALSE;
330     StatusCursor = TRUE;
331     ShowStatusLine(0); //hide
332     }
333    
334     void ChangeTerminalSize(int Nx, int Ny)
335     {
336     BuffChangeTerminalSize(Nx,Ny);
337     StatusX = 0;
338     MainX = 0;
339     MainY = 0;
340     MainTop = 0;
341     MainBottom = NumOfColumns-1;
342     }
343    
344 doda 3471 void SendCSIstr(char *str, int len) {
345     if (str == NULL || len <= 0)
346     return;
347    
348     if (Send8BitMode)
349     CommBinaryOut(&cv,"\233", 1);
350     else
351     CommBinaryOut(&cv,"\033[", 2);
352    
353     CommBinaryOut(&cv, str, len);
354     }
355    
356     void SendOSCstr(char *str, int len) {
357     if (str == NULL || len <= 0)
358     return;
359    
360 doda 3486 if (Send8BitMode) {
361 doda 3471 CommBinaryOut(&cv,"\235", 1);
362 doda 3486 CommBinaryOut(&cv, str, len);
363     CommBinaryOut(&cv,"\234", 1);
364     }
365     else {
366 doda 3471 CommBinaryOut(&cv,"\033]", 2);
367 doda 3486 CommBinaryOut(&cv, str, len);
368     CommBinaryOut(&cv,"\033\\", 2);
369     }
370 doda 3471
371     }
372    
373 maya 3227 void BackSpace()
374     {
375     if (CursorX == 0)
376     {
377     if ((CursorY>0) &&
378     ((ts.TermFlag & TF_BACKWRAP)!=0))
379     {
380     MoveCursor(NumOfColumns-1,CursorY-1);
381     // if (cv.HLogBuf!=0) Log1Byte(BS);
382     // (2005.2.20 yutaka)
383     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
384     }
385     }
386     else if (CursorX > 0)
387     {
388     MoveCursor(CursorX-1,CursorY);
389     // if (cv.HLogBuf!=0) Log1Byte(BS);
390     // (2005.2.20 yutaka)
391     if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
392     }
393     }
394    
395     void CarriageReturn(BOOL logFlag)
396     {
397     #ifndef NO_COPYLINE_FIX
398     if (!ts.EnableContinuedLineCopy || logFlag)
399     #endif /* NO_COPYLINE_FIX */
400     if (cv.HLogBuf!=0) Log1Byte(CR);
401    
402     if (CursorX>0)
403     MoveCursor(0,CursorY);
404     }
405    
406     void LineFeed(BYTE b, BOOL logFlag)
407     {
408     /* for auto print mode */
409     if ((AutoPrintMode) &&
410     (b>=LF) && (b<=FF))
411     BuffDumpCurrentLine(b);
412    
413     #ifndef NO_COPYLINE_FIX
414     if (!ts.EnableContinuedLineCopy || logFlag)
415     #endif /* NO_COPYLINE_FIX */
416     if (cv.HLogBuf!=0) Log1Byte(LF);
417    
418     if (CursorY < CursorBottom)
419     MoveCursor(CursorX,CursorY+1);
420     else if (CursorY == CursorBottom) BuffScrollNLines(1);
421     else if (CursorY < NumOfLines-StatusLine-1)
422     MoveCursor(CursorX,CursorY+1);
423    
424 doda 3312 #ifndef NO_COPYLINE_FIX
425     ClearLineContinued();
426     #endif /* NO_COPYLINE_FIX */
427    
428 maya 3227 if (LFMode) CarriageReturn(logFlag);
429     }
430    
431     void Tab()
432     {
433     if (Wrap && !ts.VTCompatTab) {
434     CarriageReturn(FALSE);
435     LineFeed(LF,FALSE);
436     #ifndef NO_COPYLINE_FIX
437     if (ts.EnableContinuedLineCopy) {
438     SetLineContinued();
439     }
440     #endif /* NO_COPYLINE_FIX */
441     Wrap = FALSE;
442     }
443     CursorForwardTab(1, AutoWrapMode);
444     if (cv.HLogBuf!=0) Log1Byte(HT);
445     }
446    
447     void PutChar(BYTE b)
448     {
449     BOOL SpecialNew;
450     TCharAttr CharAttrTmp;
451    
452     CharAttrTmp = CharAttr;
453    
454     if (PrinterMode) { // printer mode
455     WriteToPrnFile(b,TRUE);
456     return;
457     }
458    
459     if (Wrap)
460     {
461     CarriageReturn(FALSE);
462     LineFeed(LF,FALSE);
463     #ifndef NO_COPYLINE_FIX
464     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
465     #endif /* NO_COPYLINE_FIX */
466     }
467    
468     // if (cv.HLogBuf!=0) Log1Byte(b);
469     // (2005.2.20 yutaka)
470     if (ts.LogTypePlainText) {
471     if (__isascii(b) && !isprint(b)) {
472     // ASCII�������A���\�������������O�����������B
473     } else {
474     if (cv.HLogBuf!=0) Log1Byte(b);
475     }
476     } else {
477     if (cv.HLogBuf!=0) Log1Byte(b);
478     }
479    
480     Wrap = FALSE;
481    
482     SpecialNew = FALSE;
483     if ((b>0x5F) && (b<0x80))
484     {
485     if (SSflag)
486     SpecialNew = (Gn[GLtmp]==IdSpecial);
487     else
488     SpecialNew = (Gn[Glr[0]]==IdSpecial);
489     }
490     else if (b>0xDF)
491     {
492     if (SSflag)
493     SpecialNew = (Gn[GLtmp]==IdSpecial);
494     else
495     SpecialNew = (Gn[Glr[1]]==IdSpecial);
496     }
497    
498     if (SpecialNew != Special)
499     {
500     UpdateStr();
501     Special = SpecialNew;
502     }
503    
504     if (Special)
505     {
506     b = b & 0x7F;
507     CharAttrTmp.Attr |= AttrSpecial;
508     }
509     else
510     CharAttrTmp.Attr |= CharAttr.Attr;
511    
512     BuffPutChar(b, CharAttrTmp, InsertMode);
513    
514     if (CursorX < NumOfColumns-1)
515     MoveRight();
516     else {
517     UpdateStr();
518     Wrap = AutoWrapMode;
519     }
520     }
521    
522     void PutDecSp(BYTE b)
523     {
524     TCharAttr CharAttrTmp;
525    
526     CharAttrTmp = CharAttr;
527    
528     if (PrinterMode) { // printer mode
529     WriteToPrnFile(b, TRUE);
530     return;
531     }
532    
533     if (Wrap) {
534     CarriageReturn(FALSE);
535     LineFeed(LF, FALSE);
536     #ifndef NO_COPYLINE_FIX
537     CharAttrTmp.Attr |= ts.EnableContinuedLineCopy ? AttrLineContinued : 0;
538     #endif /* NO_COPYLINE_FIX */
539     }
540    
541     if (cv.HLogBuf!=0) Log1Byte(b);
542     /*
543     if (ts.LogTypePlainText && __isascii(b) && !isprint(b)) {
544     // ASCII�������A���\�������������O�����������B
545     } else {
546     if (cv.HLogBuf!=0) Log1Byte(b);
547     }
548     */
549    
550     Wrap = FALSE;
551    
552     if (!Special) {
553     UpdateStr();
554     Special = TRUE;
555     }
556    
557     CharAttrTmp.Attr |= AttrSpecial;
558     BuffPutChar(b, CharAttrTmp, InsertMode);
559    
560     if (CursorX < NumOfColumns-1)
561     MoveRight();
562     else {
563     UpdateStr();
564     Wrap = AutoWrapMode;
565     }
566     }
567    
568     void PutKanji(BYTE b)
569     {
570     #ifndef NO_COPYLINE_FIX
571     TCharAttr CharAttrTmp;
572    
573     CharAttrTmp = CharAttr;
574     #endif /* NO_COPYLINE_FIX */
575     Kanji = Kanji + b;
576    
577     if (PrinterMode && DirectPrn)
578     {
579     WriteToPrnFile(HIBYTE(Kanji),FALSE);
580     WriteToPrnFile(LOBYTE(Kanji),TRUE);
581     return;
582     }
583    
584     if (ConvJIS)
585     Kanji = JIS2SJIS((WORD)(Kanji & 0x7f7f));
586    
587     if (PrinterMode) { // printer mode
588     WriteToPrnFile(HIBYTE(Kanji),FALSE);
589     WriteToPrnFile(LOBYTE(Kanji),TRUE);
590     return;
591     }
592    
593     if (Wrap)
594     {
595     CarriageReturn(FALSE);
596     LineFeed(LF,FALSE);
597     #ifndef NO_COPYLINE_FIX
598     if (ts.EnableContinuedLineCopy)
599     CharAttrTmp.Attr |= AttrLineContinued;
600     #endif /* NO_COPYLINE_FIX */
601     }
602     else if (CursorX > NumOfColumns-2)
603     if (AutoWrapMode)
604     {
605     #ifndef NO_COPYLINE_FIX
606     if (ts.EnableContinuedLineCopy)
607     {
608     CharAttrTmp.Attr |= AttrLineContinued;
609     if (CursorX == NumOfColumns-1)
610     BuffPutChar(0x20, CharAttr, FALSE);
611     }
612     #endif /* NO_COPYLINE_FIX */
613     CarriageReturn(FALSE);
614     LineFeed(LF,FALSE);
615     }
616     else return;
617    
618     Wrap = FALSE;
619    
620     if (cv.HLogBuf!=0)
621     {
622     Log1Byte(HIBYTE(Kanji));
623     Log1Byte(LOBYTE(Kanji));
624     }
625    
626     if (Special)
627     {
628     UpdateStr();
629     Special = FALSE;
630     }
631    
632     #ifndef NO_COPYLINE_FIX
633     BuffPutKanji(Kanji, CharAttrTmp, InsertMode);
634     #else
635     BuffPutKanji(Kanji, CharAttr, InsertMode);
636     #endif /* NO_COPYLINE_FIX */
637    
638     if (CursorX < NumOfColumns-2)
639     {
640     MoveRight();
641     MoveRight();
642     }
643     else {
644     UpdateStr();
645     Wrap = AutoWrapMode;
646     }
647     }
648    
649     void PutDebugChar(BYTE b)
650     {
651 yutakapon 3637 static BYTE buff[3];
652     int i = 0;
653    
654     if (DebugFlag!=DEBUG_FLAG_NONE) {
655 maya 3227 InsertMode = FALSE;
656     AutoWrapMode = TRUE;
657    
658 yutakapon 3637 if (DebugFlag==DEBUG_FLAG_HEXD) {
659     _snprintf(buff,3,"%02X",(unsigned int) b);
660    
661     for (;i<2;i++)
662     PutChar(buff[i]);
663     PutChar(' ');
664     }
665     else if (DebugFlag==DEBUG_FLAG_NORM) {
666    
667 maya 3227 if ((b & 0x80) == 0x80)
668     {
669     UpdateStr();
670     CharAttr.Attr = AttrReverse;
671     b = b & 0x7f;
672     }
673    
674     if (b<=US)
675     {
676     PutChar('^');
677     PutChar((char)(b+0x40));
678     }
679     else if (b==DEL)
680     {
681     PutChar('<');
682     PutChar('D');
683     PutChar('E');
684     PutChar('L');
685     PutChar('>');
686     }
687     else
688     PutChar(b);
689 yutakapon 3637 }
690 maya 3227
691     if (CharAttr.Attr != AttrDefault)
692     {
693     UpdateStr();
694     CharAttr.Attr = AttrDefault;
695     }
696 yutakapon 3637 }
697 maya 3227 }
698    
699     void PrnParseControl(BYTE b) // printer mode
700     {
701     switch (b) {
702     case NUL: return;
703     case SO:
704     if (! DirectPrn)
705     {
706     if ((ts.Language==IdJapanese) &&
707     (ts.KanjiCode==IdJIS) &&
708     (ts.JIS7Katakana==1) &&
709     ((ts.TermFlag & TF_FIXEDJIS)!=0))
710     Gn[1] = IdKatakana;
711     Glr[0] = 1; /* LS1 */
712     return;
713     }
714     break;
715     case SI:
716     if (! DirectPrn)
717     {
718     Glr[0] = 0; /* LS0 */
719     return;
720     }
721     break;
722     case DC1:
723     case DC3: return;
724     case ESC:
725     ICount = 0;
726     JustAfterESC = TRUE;
727     ParseMode = ModeESC;
728     WriteToPrnFile(0,TRUE); // flush prn buff
729     return;
730     case CSI:
731 doda 3491 if (! Accept8BitCtrl) {
732 maya 3227 PutChar(b); /* Disp C1 char in VT100 mode */
733     return;
734     }
735     ICount = 0;
736     FirstPrm = TRUE;
737     NParam = 1;
738     Param[1] = -1;
739     Prv = 0;
740     ParseMode = ModeCSI;
741     WriteToPrnFile(0,TRUE); // flush prn buff
742     WriteToPrnFile(b,FALSE);
743     return;
744     }
745     /* send the uninterpreted character to printer */
746     WriteToPrnFile(b,TRUE);
747     }
748    
749     void ParseControl(BYTE b)
750     {
751     if (PrinterMode) { // printer mode
752     PrnParseControl(b);
753     return;
754     }
755    
756     if (b>=0x80) /* C1 char */
757     {
758     /* English mode */
759     if (ts.Language==IdEnglish)
760     {
761 doda 3491 if (!Accept8BitCtrl) {
762 maya 3227 PutChar(b); /* Disp C1 char in VT100 mode */
763     return;
764     }
765     }
766     else { /* Japanese mode */
767     if ((ts.TermFlag & TF_ACCEPT8BITCTRL)==0)
768     return; /* ignore C1 char */
769     /* C1 chars are interpreted as C0 chars in VT100 mode */
770     if (ts.TerminalID<IdVT220J)
771     b = b & 0x7F;
772     }
773     }
774     switch (b) {
775     /* C0 group */
776     case ENQ:
777     CommBinaryOut(&cv,&(ts.Answerback[0]),ts.AnswerbackLen);
778     break;
779     case BEL:
780     switch (ts.Beep) {
781     case IdBeepOff:
782     /* nothing to do */
783     break;
784     case IdBeepOn:
785     MessageBeep(0);
786     break;
787     case IdBeepVisual:
788     VisualBell();
789     break;
790     }
791     break;
792     case BS: BackSpace(); break;
793     case HT: Tab(); break;
794    
795     case LF:
796     // ���M�������s�R�[�h�� LF ���������A�T�[�o���� LF ���������������������������A
797     // CR+LF���������������������B
798     // cf. http://www.neocom.ca/forum/viewtopic.php?t=216
799     // (2007.1.21 yutaka)
800     if (ts.CRReceive == IdLF) {
801     CarriageReturn(TRUE);
802     LineFeed(b, TRUE);
803     break;
804     }
805    
806     case VT: LineFeed(b,TRUE); break;
807    
808     case FF:
809     if ((ts.AutoWinSwitch>0) && JustAfterESC)
810     {
811     CommInsert1Byte(&cv,b);
812     CommInsert1Byte(&cv,ESC);
813     ChangeEmu = IdTEK; /* Enter TEK Mode */
814     }
815     else
816     LineFeed(b,TRUE);
817     break;
818     case CR:
819     CarriageReturn(TRUE);
820     if (ts.CRReceive==IdCRLF)
821     CommInsert1Byte(&cv,LF);
822     break;
823     case SO:
824     if ((ts.Language==IdJapanese) &&
825     (ts.KanjiCode==IdJIS) &&
826     (ts.JIS7Katakana==1) &&
827     ((ts.TermFlag & TF_FIXEDJIS)!=0))
828     Gn[1] = IdKatakana;
829    
830     Glr[0] = 1; /* LS1 */
831     break;
832     case SI: Glr[0] = 0; break; /* LS0 */
833     case DLE:
834     if ((ts.FTFlag & FT_BPAUTO)!=0)
835     ParseMode = ModeDLE; /* Auto B-Plus activation */
836     break;
837     case CAN:
838     if ((ts.FTFlag & FT_ZAUTO)!=0)
839     ParseMode = ModeCAN; /* Auto ZMODEM activation */
840     // else if (ts.AutoWinSwitch>0)
841     // ChangeEmu = IdTEK; /* Enter TEK Mode */
842     else
843     ParseMode = ModeFirst;
844     break;
845     case SUB: ParseMode = ModeFirst; break;
846     case ESC:
847     ICount = 0;
848     JustAfterESC = TRUE;
849     ParseMode = ModeESC;
850     break;
851     case FS:
852     case GS:
853     case RS:
854     case US:
855     if (ts.AutoWinSwitch>0)
856     {
857     CommInsert1Byte(&cv,b);
858     ChangeEmu = IdTEK; /* Enter TEK Mode */
859     }
860     break;
861    
862     /* C1 char */
863     case IND: LineFeed(0,TRUE); break;
864     case NEL:
865     LineFeed(0,TRUE);
866     CarriageReturn(TRUE);
867     break;
868     case HTS: SetTabStop(); break;
869     case RI: CursorUpWithScroll(); break;
870     case SS2:
871     GLtmp = 2;
872     SSflag = TRUE;
873     break;
874     case SS3:
875     GLtmp = 3;
876     SSflag = TRUE;
877     break;
878     case DCS:
879     SavedMode = ParseMode;
880     ESCFlag = FALSE;
881     NParam = 1;
882     Param[1] = -1;
883     ParseMode = ModeDCS;
884     break;
885     case SOS:
886     SavedMode = ParseMode;
887     ESCFlag = FALSE;
888     ParseMode = ModeSOS;
889     break;
890     case CSI:
891     ICount = 0;
892     FirstPrm = TRUE;
893     NParam = 1;
894     Param[1] = -1;
895     Prv = 0;
896     ParseMode = ModeCSI;
897     break;
898     case OSC:
899     Param[1] = 0;
900     ParseMode = ModeXS;
901     break;
902     case PM:
903     case APC:
904     SavedMode = ParseMode;
905     ESCFlag = FALSE;
906     ParseMode = ModeSOS;
907     break;
908     }
909     }
910    
911     void SaveCursor()
912     {
913     int i;
914     PStatusBuff Buff;
915    
916     if ((StatusLine>0) &&
917     (CursorY==NumOfLines-1))
918     Buff = &SBuff2; // for status line
919 doda 3797 else if (AltScr)
920     Buff = &SBuff3; // for alternate screen
921 maya 3227 else
922     Buff = &SBuff1; // for main screen
923    
924     Buff->CursorX = CursorX;
925     Buff->CursorY = CursorY;
926     Buff->Attr = CharAttr;
927     Buff->Glr[0] = Glr[0];
928     Buff->Glr[1] = Glr[1];
929     for (i=0 ; i<=3; i++)
930     Buff->Gn[i] = Gn[i];
931     Buff->AutoWrapMode = AutoWrapMode;
932     Buff->RelativeOrgMode = RelativeOrgMode;
933     }
934    
935     void RestoreCursor()
936     {
937     int i;
938     PStatusBuff Buff;
939     UpdateStr();
940    
941     if ((StatusLine>0) &&
942     (CursorY==NumOfLines-1))
943     Buff = &SBuff2; // for status line
944 doda 3797 else if (AltScr)
945     Buff = &SBuff3; // for alternate screen
946 maya 3227 else
947     Buff = &SBuff1; // for main screen
948    
949     if (Buff->CursorX > NumOfColumns-1)
950     Buff->CursorX = NumOfColumns-1;
951     if (Buff->CursorY > NumOfLines-1-StatusLine)
952     Buff->CursorY = NumOfLines-1-StatusLine;
953     MoveCursor(Buff->CursorX,Buff->CursorY);
954     CharAttr = Buff->Attr;
955     Glr[0] = Buff->Glr[0];
956     Glr[1] = Buff->Glr[1];
957     for (i=0 ; i<=3; i++)
958     Gn[i] = Buff->Gn[i];
959     AutoWrapMode = Buff->AutoWrapMode;
960     RelativeOrgMode = Buff->RelativeOrgMode;
961     }
962    
963     void AnswerTerminalType()
964     {
965     char Tmp[31];
966    
967     if (ts.TerminalID<IdVT320)
968     strncpy_s(Tmp, sizeof(Tmp),"\033[?", _TRUNCATE);
969     else
970     strncpy_s(Tmp, sizeof(Tmp),"\233?", _TRUNCATE);
971    
972     switch (ts.TerminalID) {
973     case IdVT100:
974     strncat_s(Tmp,sizeof(Tmp),"1;2",_TRUNCATE);
975     break;
976     case IdVT100J:
977     strncat_s(Tmp,sizeof(Tmp),"5;2",_TRUNCATE);
978     break;
979     case IdVT101:
980     strncat_s(Tmp,sizeof(Tmp),"1;0",_TRUNCATE);
981     break;
982     case IdVT102:
983     strncat_s(Tmp,sizeof(Tmp),"6",_TRUNCATE);
984     break;
985     case IdVT102J:
986     strncat_s(Tmp,sizeof(Tmp),"15",_TRUNCATE);
987     break;
988     case IdVT220J:
989     strncat_s(Tmp,sizeof(Tmp),"62;1;2;5;6;7;8",_TRUNCATE);
990     break;
991     case IdVT282:
992     strncat_s(Tmp,sizeof(Tmp),"62;1;2;4;5;6;7;8;10;11",_TRUNCATE);
993     break;
994     case IdVT320:
995     strncat_s(Tmp,sizeof(Tmp),"63;1;2;6;7;8",_TRUNCATE);
996     break;
997     case IdVT382:
998     strncat_s(Tmp,sizeof(Tmp),"63;1;2;4;5;6;7;8;10;15",_TRUNCATE);
999     break;
1000     }
1001     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
1002    
1003     CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
1004     }
1005    
1006     void ESCSpace(BYTE b)
1007     {
1008     switch (b) {
1009     case 'F': Send8BitMode = FALSE; break; // S7C1T
1010     case 'G': Send8BitMode = TRUE; break; // S8C1T
1011     }
1012     }
1013    
1014     void ESCSharp(BYTE b)
1015     {
1016     switch (b) {
1017     case '8': /* Fill screen with "E" */
1018     BuffUpdateScroll();
1019     BuffFillWithE();
1020     MoveCursor(0,0);
1021     ParseMode = ModeFirst;
1022     break;
1023     }
1024     }
1025    
1026     /* select double byte code set */
1027     void ESCDBCSSelect(BYTE b)
1028     {
1029     int Dist;
1030    
1031     if (ts.Language!=IdJapanese) return;
1032    
1033     switch (ICount) {
1034     case 1:
1035     if ((b=='@') || (b=='B'))
1036     {
1037     Gn[0] = IdKanji; /* Kanji -> G0 */
1038     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
1039     Glr[0] = 0; /* G0->GL */
1040     }
1041     break;
1042     case 2:
1043     /* Second intermediate char must be
1044     '(' or ')' or '*' or '+'. */
1045     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
1046     if ((b=='1') || (b=='3') ||
1047     (b=='@') || (b=='B'))
1048     {
1049     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
1050     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1051     (Dist==0))
1052     Glr[0] = 0; /* G0->GL */
1053     }
1054     break;
1055     }
1056     }
1057    
1058     void ESCSelectCode(BYTE b)
1059     {
1060     switch (b) {
1061     case '0':
1062     if (ts.AutoWinSwitch>0)
1063     ChangeEmu = IdTEK; /* enter TEK mode */
1064     break;
1065     }
1066     }
1067    
1068     /* select single byte code set */
1069     void ESCSBCSSelect(BYTE b)
1070     {
1071     int Dist;
1072    
1073     /* Intermediate char must be
1074     '(' or ')' or '*' or '+'. */
1075     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
1076    
1077     switch (b) {
1078     case '0': Gn[Dist] = IdSpecial; break;
1079     case '<': Gn[Dist] = IdASCII; break;
1080     case '>': Gn[Dist] = IdASCII; break;
1081     case 'A': Gn[Dist] = IdASCII; break;
1082     case 'B': Gn[Dist] = IdASCII; break;
1083     case 'H': Gn[Dist] = IdASCII; break;
1084     case 'I':
1085     if (ts.Language==IdJapanese)
1086     Gn[Dist] = IdKatakana;
1087     break;
1088     case 'J': Gn[Dist] = IdASCII; break;
1089     }
1090    
1091     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1092     (Dist==0))
1093     Glr[0] = 0; /* G0->GL */
1094     }
1095    
1096     void PrnParseEscape(BYTE b) // printer mode
1097     {
1098     int i;
1099    
1100     ParseMode = ModeFirst;
1101     switch (ICount) {
1102     /* no intermediate char */
1103     case 0:
1104     switch (b) {
1105     case '[': /* CSI */
1106     ICount = 0;
1107     FirstPrm = TRUE;
1108     NParam = 1;
1109     Param[1] = -1;
1110     Prv = 0;
1111     WriteToPrnFile(ESC,FALSE);
1112     WriteToPrnFile('[',FALSE);
1113     ParseMode = ModeCSI;
1114     return;
1115     } /* end of case Icount=0 */
1116     break;
1117     /* one intermediate char */
1118     case 1:
1119     switch (IntChar[1]) {
1120     case '$':
1121     if (! DirectPrn)
1122     {
1123     ESCDBCSSelect(b);
1124     return;
1125     }
1126     break;
1127     case '(':
1128     case ')':
1129     case '*':
1130     case '+':
1131     if (! DirectPrn)
1132     {
1133     ESCSBCSSelect(b);
1134     return;
1135     }
1136     break;
1137     }
1138     break;
1139     /* two intermediate char */
1140     case 2:
1141     if ((! DirectPrn) &&
1142     (IntChar[1]=='$') &&
1143     ('('<=IntChar[2]) &&
1144     (IntChar[2]<='+'))
1145     {
1146     ESCDBCSSelect(b);
1147     return;
1148     }
1149     break;
1150     }
1151     // send the uninterpreted sequence to printer
1152     WriteToPrnFile(ESC,FALSE);
1153     for (i=1; i<=ICount; i++)
1154     WriteToPrnFile(IntChar[i],FALSE);
1155     WriteToPrnFile(b,TRUE);
1156     }
1157    
1158     void ParseEscape(BYTE b) /* b is the final char */
1159     {
1160     if (PrinterMode) { // printer mode
1161     PrnParseEscape(b);
1162     return;
1163     }
1164    
1165     switch (ICount) {
1166     /* no intermediate char */
1167     case 0:
1168     switch (b) {
1169     case '7': SaveCursor(); break;
1170     case '8': RestoreCursor(); break;
1171     case '=': AppliKeyMode = TRUE; break;
1172     case '>': AppliKeyMode = FALSE; break;
1173     case 'D': /* IND */
1174     LineFeed(0,TRUE);
1175     break;
1176     case 'E': /* NEL */
1177     MoveCursor(0,CursorY);
1178     LineFeed(0,TRUE);
1179     break;
1180     case 'H': /* HTS */
1181     SetTabStop();
1182     break;
1183     case 'M': /* RI */
1184     CursorUpWithScroll();
1185     break;
1186     case 'N': /* SS2 */
1187     GLtmp = 2;
1188     SSflag = TRUE;
1189     break;
1190     case 'O': /* SS3 */
1191     GLtmp = 3;
1192     SSflag = TRUE;
1193     break;
1194     case 'P': /* DCS */
1195     SavedMode = ParseMode;
1196     ESCFlag = FALSE;
1197     NParam = 1;
1198     Param[1] = -1;
1199     ParseMode = ModeDCS;
1200     return;
1201     case 'X': /* SOS */
1202     SavedMode = ParseMode;
1203     ESCFlag = FALSE;
1204     ParseMode = ModeSOS;
1205     return;
1206     case 'Z': AnswerTerminalType(); break;
1207     case '[': /* CSI */
1208     ICount = 0;
1209     FirstPrm = TRUE;
1210     NParam = 1;
1211     Param[1] = -1;
1212     Prv = 0;
1213     ParseMode = ModeCSI;
1214     return;
1215     case '\\': break; /* ST */
1216     case ']': /* XTERM sequence (OSC) */
1217     NParam = 1;
1218     Param[1] = 0;
1219     ParseMode = ModeXS;
1220     return;
1221     case '^':
1222     case '_': /* PM, APC */
1223     SavedMode = ParseMode;
1224     ESCFlag = FALSE;
1225     ParseMode = ModeSOS;
1226     return;
1227     case 'c': /* Hardware reset */
1228     HideStatusLine();
1229     ResetTerminal();
1230     ClearUserKey();
1231     ClearBuffer();
1232     if (ts.PortType==IdSerial) // reset serial port
1233     CommResetSerial(&ts, &cv, TRUE);
1234     break;
1235     case 'g': /* Visual Bell (screen original?) */
1236     VisualBell();
1237     break;
1238     case 'n': Glr[0] = 2; break; /* LS2 */
1239     case 'o': Glr[0] = 3; break; /* LS3 */
1240     case '|': Glr[1] = 3; break; /* LS3R */
1241     case '}': Glr[1] = 2; break; /* LS2R */
1242     case '~': Glr[1] = 1; break; /* LS1R */
1243     } /* end of case Icount=0 */
1244     break;
1245     /* one intermediate char */
1246     case 1:
1247     switch (IntChar[1]) {
1248     case ' ': ESCSpace(b); break;
1249     case '#': ESCSharp(b); break;
1250     case '$': ESCDBCSSelect(b); break;
1251     case '%': break;
1252     case '(':
1253     case ')':
1254     case '*':
1255     case '+':
1256     ESCSBCSSelect(b);
1257     break;
1258     }
1259     break;
1260     /* two intermediate char */
1261     case 2:
1262     if ((IntChar[1]=='$') &&
1263     ('('<=IntChar[2]) &&
1264     (IntChar[2]<='+'))
1265     ESCDBCSSelect(b);
1266     else if ((IntChar[1]=='%') &&
1267     (IntChar[2]=='!'))
1268     ESCSelectCode(b);
1269     break;
1270     }
1271     ParseMode = ModeFirst;
1272     }
1273    
1274     void EscapeSequence(BYTE b)
1275     {
1276     if (b<=US)
1277     ParseControl(b);
1278     else if ((b>=0x20) && (b<=0x2F))
1279     {
1280     if (ICount<IntCharMax) ICount++;
1281     IntChar[ICount] = b;
1282     }
1283     else if ((b>=0x30) && (b<=0x7E))
1284     ParseEscape(b);
1285     else if ((b>=0x80) && (b<=0x9F))
1286     ParseControl(b);
1287    
1288     JustAfterESC = FALSE;
1289     }
1290    
1291     void CSInsertCharacter()
1292     {
1293     // Insert space characters at cursor
1294     int Count;
1295    
1296     BuffUpdateScroll();
1297     if (Param[1]<1) Param[1] = 1;
1298     Count = Param[1];
1299     BuffInsertSpace(Count);
1300     }
1301    
1302     void CSCursorUp()
1303     {
1304     if (Param[1]<1) Param[1] = 1;
1305    
1306     if (CursorY >= CursorTop)
1307     {
1308     if (CursorY-Param[1] > CursorTop)
1309     MoveCursor(CursorX,CursorY-Param[1]);
1310     else
1311     MoveCursor(CursorX,CursorTop);
1312     }
1313     else {
1314     if (CursorY > 0)
1315     MoveCursor(CursorX,CursorY-Param[1]);
1316     else
1317     MoveCursor(CursorX,0);
1318     }
1319     }
1320    
1321     void CSCursorUp1()
1322     {
1323     MoveCursor(0,CursorY);
1324     CSCursorUp();
1325     }
1326    
1327     void CSCursorDown()
1328     {
1329     if (Param[1]<1) Param[1] = 1;
1330    
1331     if (CursorY <= CursorBottom)
1332     {
1333     if (CursorY+Param[1] < CursorBottom)
1334     MoveCursor(CursorX,CursorY+Param[1]);
1335     else
1336     MoveCursor(CursorX,CursorBottom);
1337     }
1338     else {
1339     if (CursorY < NumOfLines-StatusLine-1)
1340     MoveCursor(CursorX,CursorY+Param[1]);
1341     else
1342     MoveCursor(CursorX,NumOfLines-StatusLine);
1343     }
1344     }
1345    
1346     void CSCursorDown1()
1347     {
1348     MoveCursor(0,CursorY);
1349     CSCursorDown();
1350     }
1351    
1352     void CSScreenErase()
1353     {
1354     if (Param[1] == -1) Param[1] = 0;
1355     BuffUpdateScroll();
1356     switch (Param[1]) {
1357     case 0:
1358     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1359     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1360     // �����������������B(2005.5.29 yutaka)
1361     // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1362     if (ts.ScrollWindowClearScreen &&
1363     (CursorX == 0 && CursorY == 0)) {
1364     // Erase screen (scroll out)
1365     BuffClearScreen();
1366     UpdateWindow(HVTWin);
1367    
1368     } else {
1369     // Erase characters from cursor to the end of screen
1370     BuffEraseCurToEnd();
1371     }
1372     break;
1373    
1374     case 1:
1375     // Erase characters from home to cursor
1376     BuffEraseHomeToCur();
1377     break;
1378    
1379     case 2:
1380     // Erase screen (scroll out)
1381     BuffClearScreen();
1382     UpdateWindow(HVTWin);
1383     break;
1384     }
1385     }
1386    
1387     void CSInsertLine()
1388     {
1389     // Insert lines at current position
1390     int Count, YEnd;
1391    
1392     if (CursorY < CursorTop) return;
1393     if (CursorY > CursorBottom) return;
1394     if (Param[1]<1) Param[1] = 1;
1395     Count = Param[1];
1396    
1397     YEnd = CursorBottom;
1398     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1399     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1400    
1401     BuffInsertLines(Count,YEnd);
1402     }
1403    
1404     void CSLineErase()
1405     {
1406     if (Param[1] == -1) Param[1] = 0;
1407     BuffUpdateScroll();
1408     switch (Param[1]) {
1409     /* erase char from cursor to end of line */
1410     case 0:
1411     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1412     break;
1413     /* erase char from start of line to cursor */
1414     case 1:
1415     BuffEraseCharsInLine(0,CursorX+1);
1416     break;
1417     /* erase entire line */
1418     case 2:
1419     BuffEraseCharsInLine(0,NumOfColumns);
1420     break;
1421     }
1422     }
1423    
1424     void CSDeleteNLines()
1425     // Delete lines from current line
1426     {
1427     int Count, YEnd;
1428    
1429     if (CursorY < CursorTop) return;
1430     if (CursorY > CursorBottom) return;
1431     Count = Param[1];
1432     if (Count<1) Count = 1;
1433    
1434     YEnd = CursorBottom;
1435     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1436     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1437     BuffDeleteLines(Count,YEnd);
1438     }
1439    
1440     void CSDeleteCharacter()
1441     {
1442     // Delete characters in current line from cursor
1443    
1444     if (Param[1]<1) Param[1] = 1;
1445     BuffUpdateScroll();
1446     BuffDeleteChars(Param[1]);
1447     }
1448    
1449     void CSEraseCharacter()
1450     {
1451     if (Param[1]<1) Param[1] = 1;
1452     BuffUpdateScroll();
1453     BuffEraseChars(Param[1]);
1454     }
1455    
1456     void CSScrollUP()
1457     {
1458     if (Param[1]<1) Param[1] = 1;
1459     BuffUpdateScroll();
1460     BuffRegionScrollUpNLines(Param[1]);
1461     }
1462    
1463     void CSScrollDown()
1464     {
1465     if (Param[1]<1) Param[1] = 1;
1466     BuffUpdateScroll();
1467     BuffRegionScrollDownNLines(Param[1]);
1468     }
1469    
1470     void CSForwardTab()
1471     {
1472     if (Param[1]<1) Param[1] = 1;
1473     CursorForwardTab(Param[1], AutoWrapMode);
1474     }
1475    
1476     void CSBackwardTab()
1477     {
1478     if (Param[1]<1) Param[1] = 1;
1479     CursorBackwardTab(Param[1]);
1480     }
1481    
1482     void CSMoveToColumnN()
1483     {
1484     if (Param[1]<1) Param[1] = 1;
1485     Param[1]--;
1486     if (Param[1] < 0) Param[1] = 0;
1487     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1488     MoveCursor(Param[1],CursorY);
1489     }
1490    
1491     void CSCursorRight()
1492     {
1493     if (Param[1]<1) Param[1] = 1;
1494     if (CursorX + Param[1] > NumOfColumns-1)
1495     MoveCursor(NumOfColumns-1,CursorY);
1496     else
1497     MoveCursor(CursorX+Param[1],CursorY);
1498     }
1499    
1500     void CSCursorLeft()
1501     {
1502     if (Param[1]<1) Param[1] = 1;
1503     if (CursorX-Param[1] < 0)
1504     MoveCursor(0,CursorY);
1505     else
1506     MoveCursor(CursorX-Param[1],CursorY);
1507     }
1508    
1509     void CSMoveToLineN()
1510     {
1511     if (Param[1]<1) Param[1] = 1;
1512     if (RelativeOrgMode)
1513     {
1514     if (CursorTop+Param[1]-1 > CursorBottom)
1515     MoveCursor(CursorX,CursorBottom);
1516     else
1517     MoveCursor(CursorX,CursorTop+Param[1]-1);
1518     }
1519     else {
1520     if (Param[1] > NumOfLines-StatusLine)
1521     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1522     else
1523     MoveCursor(CursorX,Param[1]-1);
1524     }
1525     }
1526    
1527     void CSMoveToXY()
1528     {
1529     int NewX, NewY;
1530    
1531     if (Param[1]<1) Param[1] = 1;
1532     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1533     NewX = Param[2] - 1;
1534     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1535    
1536     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1537     NewY = CursorY;
1538     else if (RelativeOrgMode)
1539     {
1540     NewY = CursorTop + Param[1] - 1;
1541     if (NewY > CursorBottom) NewY = CursorBottom;
1542     }
1543     else {
1544     NewY = Param[1] - 1;
1545     if (NewY > NumOfLines-1-StatusLine)
1546     NewY = NumOfLines-1-StatusLine;
1547     }
1548     MoveCursor(NewX,NewY);
1549     }
1550    
1551     void CSDeleteTabStop()
1552     {
1553     if (Param[1]==-1) Param[1] = 0;
1554     ClearTabStop(Param[1]);
1555     }
1556    
1557 doda 3742 void CS_h_Mode() // SM
1558 maya 3227 {
1559     switch (Param[1]) {
1560 doda 3311 case 2: // KAM
1561     KeybEnabled = FALSE; break;
1562     case 4: // IRM
1563     InsertMode = TRUE; break;
1564     case 12: // SRM
1565 doda 3485 ts.LocalEcho = 0;
1566     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1567     TelChangeEcho();
1568     break;
1569 doda 3311 case 20: // LF/NL
1570 doda 3485 LFMode = TRUE;
1571     ts.CRSend = IdCRLF;
1572     cv.CRSend = IdCRLF;
1573     break;
1574 doda 3311 case 33: // WYSTCURM
1575 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1576     ts.NonblinkingCursor = TRUE;
1577     ChangeCaret();
1578     }
1579     break;
1580 doda 3311 case 34: // WYULCURM
1581 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1582     ts.CursorShape = IdHCur;
1583     ChangeCaret();
1584     }
1585     break;
1586 maya 3227 }
1587     }
1588    
1589 doda 3742 void CS_i_Mode() // MC
1590 maya 3227 {
1591     if (Param[1]==-1) Param[1] = 0;
1592     switch (Param[1]) {
1593     /* print screen */
1594     // PrintEX -- TRUE: print screen
1595     // FALSE: scroll region
1596     case 0: BuffPrint(! PrintEX); break;
1597     /* printer controller mode off */
1598     case 4: break; /* See PrnParseCS() */
1599     /* printer controller mode on */
1600     case 5:
1601     if (! AutoPrintMode)
1602     OpenPrnFile();
1603     DirectPrn = (ts.PrnDev[0]!=0);
1604     PrinterMode = TRUE;
1605     break;
1606     }
1607     }
1608    
1609 doda 3742 void CS_l_Mode() // RM
1610 maya 3227 {
1611     switch (Param[1]) {
1612 doda 3311 case 2: // KAM
1613     KeybEnabled = TRUE; break;
1614     case 4: // IRM
1615     InsertMode = FALSE; break;
1616     case 12: // SRM
1617 doda 3485 ts.LocalEcho = 1;
1618     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1619     TelChangeEcho();
1620     break;
1621 doda 3311 case 20: // LF/NL
1622 doda 3485 LFMode = FALSE;
1623     ts.CRSend = IdCR;
1624     cv.CRSend = IdCR;
1625     break;
1626 doda 3311 case 33: // WYSTCURM
1627 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1628     ts.NonblinkingCursor = FALSE;
1629     ChangeCaret();
1630     }
1631     break;
1632 doda 3311 case 34: // WYULCURM
1633 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1634     ts.CursorShape = IdBlkCur;
1635     ChangeCaret();
1636     }
1637     break;
1638 maya 3227 }
1639     }
1640    
1641 doda 3742 void CS_n_Mode() // DSR
1642 maya 3227 {
1643     char Report[16];
1644 doda 3471 int Y, len;
1645 maya 3227
1646     switch (Param[1]) {
1647     case 5:
1648 doda 3311 /* Device Status Report -> Ready */
1649 doda 3471 SendCSIstr("0n", 2);
1650 maya 3227 break;
1651     case 6:
1652     /* Cursor Position Report */
1653     Y = CursorY+1;
1654     if ((StatusLine>0) &&
1655     (Y==NumOfLines))
1656     Y = 1;
1657 doda 3471 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
1658     SendCSIstr(Report, len);
1659 maya 3227 break;
1660     }
1661     }
1662    
1663 doda 3742 void CSSetAttr() // SGR
1664 maya 3227 {
1665     int i, P;
1666    
1667     UpdateStr();
1668     for (i=1 ; i<=NParam ; i++)
1669     {
1670     P = Param[i];
1671     if (P<0) P = 0;
1672     switch (P) {
1673     case 0: /* Clear all */
1674     CharAttr = DefCharAttr;
1675     BuffSetCurCharAttr(CharAttr);
1676     break;
1677    
1678     case 1: /* Bold */
1679     CharAttr.Attr |= AttrBold;
1680     BuffSetCurCharAttr(CharAttr);
1681     break;
1682    
1683     case 4: /* Under line */
1684     CharAttr.Attr |= AttrUnder;
1685     BuffSetCurCharAttr(CharAttr);
1686     break;
1687    
1688     case 5: /* Blink */
1689     CharAttr.Attr |= AttrBlink;
1690     BuffSetCurCharAttr(CharAttr);
1691     break;
1692    
1693     case 7: /* Reverse */
1694     CharAttr.Attr |= AttrReverse;
1695     BuffSetCurCharAttr(CharAttr);
1696     break;
1697    
1698     case 22: /* Bold off */
1699     CharAttr.Attr &= ~ AttrBold;
1700     BuffSetCurCharAttr(CharAttr);
1701     break;
1702    
1703     case 24: /* Under line off */
1704     CharAttr.Attr &= ~ AttrUnder;
1705     BuffSetCurCharAttr(CharAttr);
1706     break;
1707    
1708     case 25: /* Blink off */
1709     CharAttr.Attr &= ~ AttrBlink;
1710     BuffSetCurCharAttr(CharAttr);
1711     break;
1712    
1713     case 27: /* Reverse off */
1714     CharAttr.Attr &= ~ AttrReverse;
1715     BuffSetCurCharAttr(CharAttr);
1716     break;
1717    
1718     case 30:
1719     case 31:
1720     case 32:
1721     case 33:
1722     case 34:
1723     case 35:
1724     case 36:
1725     case 37: /* text color */
1726     CharAttr.Attr2 |= Attr2Fore;
1727     CharAttr.Fore = P - 30;
1728     BuffSetCurCharAttr(CharAttr);
1729     break;
1730    
1731     case 38: /* text color (256color mode) */
1732     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1733     i++;
1734     if (i < NParam) {
1735     P = Param[++i];
1736     if (P<0) {
1737     P = 0;
1738     }
1739     CharAttr.Attr2 |= Attr2Fore;
1740     CharAttr.Fore = P;
1741     BuffSetCurCharAttr(CharAttr);
1742     }
1743     }
1744     break;
1745    
1746     case 39: /* Reset text color */
1747     CharAttr.Attr2 &= ~ Attr2Fore;
1748     CharAttr.Fore = AttrDefaultFG;
1749     BuffSetCurCharAttr(CharAttr);
1750     break;
1751    
1752     case 40:
1753     case 41:
1754     case 42:
1755     case 43:
1756     case 44:
1757     case 45:
1758     case 46:
1759     case 47: /* Back color */
1760     CharAttr.Attr2 |= Attr2Back;
1761     CharAttr.Back = P - 40;
1762     BuffSetCurCharAttr(CharAttr);
1763     break;
1764    
1765     case 48: /* Back color (256color mode) */
1766     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1767     i++;
1768     if (i < NParam) {
1769     P = Param[++i];
1770     if (P<0) {
1771     P = 0;
1772     }
1773     CharAttr.Attr2 |= Attr2Back;
1774     CharAttr.Back = P;
1775     BuffSetCurCharAttr(CharAttr);
1776     }
1777     }
1778     break;
1779    
1780     case 49: /* Reset back color */
1781     CharAttr.Attr2 &= ~ Attr2Back;
1782     CharAttr.Back = AttrDefaultBG;
1783     BuffSetCurCharAttr(CharAttr);
1784     break;
1785    
1786     case 90:
1787     case 91:
1788     case 92:
1789     case 93:
1790     case 94:
1791     case 95:
1792     case 96:
1793     case 97: /* aixterm style text color */
1794     if (ts.ColorFlag & CF_AIXTERM16) {
1795     CharAttr.Attr2 |= Attr2Fore;
1796     CharAttr.Fore = P - 90 + 8;
1797     BuffSetCurCharAttr(CharAttr);
1798     }
1799     break;
1800    
1801     case 100:
1802     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1803     /* Reset text and back color */
1804     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1805     CharAttr.Fore = AttrDefaultFG;
1806     CharAttr.Back = AttrDefaultBG;
1807     BuffSetCurCharAttr(CharAttr);
1808     break;
1809     }
1810     /* fall through to aixterm style back color */
1811    
1812     case 101:
1813     case 102:
1814     case 103:
1815     case 104:
1816     case 105:
1817     case 106:
1818     case 107: /* aixterm style back color */
1819     if (ts.ColorFlag & CF_AIXTERM16) {
1820     CharAttr.Attr2 |= Attr2Back;
1821     CharAttr.Back = P - 100 + 8;
1822     BuffSetCurCharAttr(CharAttr);
1823     }
1824     break;
1825     }
1826     }
1827     }
1828    
1829     void CSSetScrollRegion()
1830     {
1831     if ((StatusLine>0) &&
1832     (CursorY==NumOfLines-1))
1833     {
1834     MoveCursor(0,CursorY);
1835     return;
1836     }
1837     if (Param[1]<1) Param[1] =1;
1838     if ((NParam < 2) | (Param[2]<1))
1839     Param[2] = NumOfLines-StatusLine;
1840     Param[1]--;
1841     Param[2]--;
1842     if (Param[1] > NumOfLines-1-StatusLine)
1843     Param[1] = NumOfLines-1-StatusLine;
1844     if (Param[2] > NumOfLines-1-StatusLine)
1845     Param[2] = NumOfLines-1-StatusLine;
1846     if (Param[1] >= Param[2]) return;
1847     CursorTop = Param[1];
1848     CursorBottom = Param[2];
1849     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1850     else MoveCursor(0,0);
1851     }
1852    
1853     void CSSunSequence() /* Sun terminal private sequences */
1854     {
1855 doda 3471 int x, y, len;
1856 doda 3487 char Report[TitleBuffSize*2+10];
1857 maya 3227
1858     switch (Param[1]) {
1859 doda 3302 case 1: // De-iconify window
1860 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1861     DispShowWindow(WINDOW_RESTORE);
1862 doda 3302 break;
1863     case 2: // Iconify window
1864 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1865     DispShowWindow(WINDOW_MINIMIZE);
1866 doda 3302 break;
1867     case 3: // set window position
1868 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1869     if (NParam < 2) Param[2] = 0;
1870     if (NParam < 3) Param[3] = 0;
1871     DispMoveWindow(Param[2], Param[3]);
1872     }
1873 doda 3297 break;
1874 doda 3466 case 4: // set window size
1875 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1876     if (NParam < 2) Param[2] = 0;
1877     if (NParam < 3) Param[3] = 0;
1878     DispResizeWin(Param[3], Param[2]);
1879     }
1880 doda 3464 break;
1881 doda 3311 case 5: // Raise window
1882 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1883     DispShowWindow(WINDOW_RAISE);
1884 doda 3309 break;
1885 doda 3311 case 6: // Lower window
1886 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1887     DispShowWindow(WINDOW_LOWER);
1888 doda 3309 break;
1889 doda 3311 case 7: // Refresh window
1890 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1891     DispShowWindow(WINDOW_REFRESH);
1892 doda 3310 break;
1893 maya 3227 case 8: /* set terminal size */
1894 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1895     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1896     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1897     ChangeTerminalSize(Param[3],Param[2]);
1898     }
1899 maya 3227 break;
1900 doda 3302 case 9: // Maximize/Restore window
1901 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1902     if (NParam < 2 || Param[2] == 0) {
1903     DispShowWindow(WINDOW_RESTORE);
1904     }
1905 doda 3489 else if (Param[2] == 1) {
1906 doda 3485 DispShowWindow(WINDOW_MAXIMIZE);
1907     }
1908 doda 3302 }
1909     break;
1910 doda 3466 case 11: // Report window state
1911 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1912     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
1913     SendCSIstr(Report, len);
1914     }
1915 doda 3466 break;
1916 doda 3469 case 13: // Report window position
1917 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1918     DispGetWindowPos(&x, &y);
1919     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%d;%dt", CLocale, x, y);
1920     SendCSIstr(Report, len);
1921     }
1922 doda 3469 break;
1923 maya 3227 case 14: /* get window size??? */
1924 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1925     /* this is not actual window size */
1926     SendCSIstr("4;640;480t", 10);
1927     }
1928 maya 3227 break;
1929     case 18: /* get terminal size */
1930 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1931     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%u;t", CLocale,
1932     NumOfLines-StatusLine, NumOfColumns);
1933     SendCSIstr(Report, len);
1934     }
1935 maya 3227 break;
1936 doda 3475 case 19: // Report display size (character)
1937 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1938     DispGetRootWinSize(&x, &y);
1939     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
1940     SendCSIstr(Report, len);
1941     }
1942 doda 3475 break;
1943 doda 3487 case 20: // Report icon label
1944 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
1945 doda 3774 case IdTitleReportIgnore:
1946 doda 3747 // nothing to do
1947     break;
1948 doda 3774 case IdTitleReportAccept:
1949 doda 3747 switch (ts.AcceptTitleChangeRequest) {
1950     case IdTitleChangeRequestOff:
1951 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
1952 doda 3747 break;
1953     case IdTitleChangeRequestAhead:
1954     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
1955     break;
1956     case IdTitleChangeRequestLast:
1957     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
1958     break;
1959     default:
1960     if (cv.TitleRemote[0] == 0) {
1961     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
1962     }
1963     else {
1964     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
1965     }
1966     }
1967     SendOSCstr(Report, len);
1968     break;
1969     default: // IdTitleReportEmpty:
1970     SendOSCstr("L", 1);
1971     break;
1972 doda 3487 }
1973     break;
1974     case 21: // Report window title
1975 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
1976 doda 3774 case IdTitleReportIgnore:
1977 doda 3747 // nothing to do
1978     break;
1979 doda 3774 case IdTitleReportAccept:
1980 doda 3747 switch (ts.AcceptTitleChangeRequest) {
1981     case IdTitleChangeRequestOff:
1982 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
1983 doda 3747 break;
1984     case IdTitleChangeRequestAhead:
1985     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
1986     break;
1987     case IdTitleChangeRequestLast:
1988     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
1989     break;
1990     default:
1991     if (cv.TitleRemote[0] == 0) {
1992     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
1993     }
1994     else {
1995     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
1996     }
1997     }
1998     SendOSCstr(Report, len);
1999     break;
2000     default: // IdTitleReportEmpty:
2001 doda 3753 SendOSCstr("l", 1);
2002 doda 3747 break;
2003 doda 3487 }
2004     break;
2005 maya 3227 }
2006     }
2007    
2008     void CSGT(BYTE b)
2009     {
2010     switch (b) {
2011 doda 3311 case 'c': /* second terminal report (Secondary DA) */
2012 doda 3472 if (Param[1] < 1) {
2013     SendCSIstr(">32;10;2c", 9); /* VT382 */
2014     }
2015 maya 3227 break;
2016     case 'J':
2017     if (Param[1]==3) // IO-8256 terminal
2018     {
2019     if (Param[2]<1) Param[2]=1;
2020     if (Param[3]<1) Param[3]=1;
2021     if (Param[4]<1) Param[4]=1;
2022     if (Param[5]<1) Param[5]=1;
2023     BuffEraseBox(Param[3]-1,Param[2]-1,
2024     Param[5]-1,Param[4]-1);
2025     }
2026     break;
2027     case 'K':
2028     if ((NParam>=2) && (Param[1]==5))
2029     { // IO-8256 terminal
2030     switch (Param[2]) {
2031     case 3:
2032     case 4:
2033     case 5:
2034     case 6:
2035     BuffDrawLine(CharAttr, Param[2], Param[3]);
2036     break;
2037     case 12:
2038     /* Text color */
2039     if ((Param[3]>=0) && (Param[3]<=7))
2040     {
2041     switch (Param[3]) {
2042     case 3: CharAttr.Fore = IdBlue; break;
2043     case 4: CharAttr.Fore = IdCyan; break;
2044     case 5: CharAttr.Fore = IdYellow; break;
2045     case 6: CharAttr.Fore = IdMagenta; break;
2046     default: CharAttr.Fore = Param[3]; break;
2047     }
2048     CharAttr.Attr2 |= Attr2Fore;
2049     BuffSetCurCharAttr(CharAttr);
2050     }
2051     break;
2052     }
2053     }
2054     else if (Param[1]==3)
2055     {// IO-8256 terminal
2056     if (Param[2]<1) Param[2] = 1;
2057     if (Param[3]<1) Param[2] = 1;
2058     BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
2059     }
2060     break;
2061     }
2062     }
2063    
2064 doda 3742 void CSQExchangeColor() // DECSCNM / Visual Bell
2065 maya 3227 {
2066     COLORREF ColorRef;
2067    
2068     BuffUpdateScroll();
2069    
2070     if (ts.ColorFlag & CF_REVERSECOLOR) {
2071     ColorRef = ts.VTColor[0];
2072     ts.VTColor[0] = ts.VTReverseColor[0];
2073     ts.VTReverseColor[0] = ColorRef;
2074     ColorRef = ts.VTColor[1];
2075     ts.VTColor[1] = ts.VTReverseColor[1];
2076     ts.VTReverseColor[1] = ColorRef;
2077     }
2078     else {
2079     ColorRef = ts.VTColor[0];
2080     ts.VTColor[0] = ts.VTColor[1];
2081     ts.VTColor[1] = ColorRef;
2082     }
2083    
2084     ColorRef = ts.VTBoldColor[0];
2085     ts.VTBoldColor[0] = ts.VTBoldColor[1];
2086     ts.VTBoldColor[1] = ColorRef;
2087    
2088     ColorRef = ts.VTBlinkColor[0];
2089     ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2090     ts.VTBlinkColor[1] = ColorRef;
2091    
2092     ColorRef = ts.URLColor[0];
2093     ts.URLColor[0] = ts.URLColor[1];
2094     ts.URLColor[1] = ColorRef;
2095    
2096     ts.ColorFlag ^= CF_REVERSEVIDEO;
2097    
2098     #ifdef ALPHABLEND_TYPE2
2099 doda 3715 // BGInitialize();
2100     BGExchangeColor();
2101 maya 3227 #endif
2102     DispChangeBackground();
2103     UpdateWindow(HVTWin);
2104     }
2105    
2106 doda 3802 void CSQChangeColumnMode(int width) // DECCOLM
2107     {
2108     ChangeTerminalSize(width, NumOfLines-StatusLine);
2109 doda 3804 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2110     MoveCursor(0, 0);
2111     BuffClearScreen();
2112     UpdateWindow(HVTWin);
2113     }
2114 doda 3802 }
2115    
2116 doda 3742 void CSQ_h_Mode() // DECSET
2117 maya 3227 {
2118     int i;
2119    
2120     for (i = 1 ; i<=NParam ; i++)
2121     switch (Param[i]) {
2122 doda 3742 case 1: AppliCursorMode = TRUE; break; // DECCKM
2123 doda 3802 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2124 doda 3742 case 5: /* Reverse Video (DECSCNM) */
2125 maya 3227 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2126     CSQExchangeColor(); /* Exchange text/back color */
2127     break;
2128 doda 3742 case 6: // DECOM
2129 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2130 maya 3227 MoveCursor(0,CursorY);
2131     else {
2132     RelativeOrgMode = TRUE;
2133     MoveCursor(0,CursorTop);
2134     }
2135     break;
2136 doda 3742 case 7: AutoWrapMode = TRUE; break; // DECAWM
2137     case 8: AutoRepeatMode = TRUE; break; // DECARM
2138     case 9: /* X10 Mouse Tracking */
2139 maya 3227 if (ts.MouseEventTracking)
2140     MouseReportMode = IdMouseTrackX10;
2141     break;
2142 doda 3742 case 12: /* att610 cursor blinking */
2143 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2144     ts.NonblinkingCursor = FALSE;
2145     ChangeCaret();
2146     }
2147     break;
2148 doda 3742 case 19: PrintEX = TRUE; break; // DECPEX
2149     case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2150     case 38: // DECTEK
2151 maya 3227 if (ts.AutoWinSwitch>0)
2152     ChangeEmu = IdTEK; /* Enter TEK Mode */
2153     break;
2154 doda 3743 case 47: // Alternate Screen Buffer
2155     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2156     BuffSaveScreen();
2157     AltScr = TRUE;
2158     }
2159     break;
2160 maya 3227 case 59:
2161     if (ts.Language==IdJapanese)
2162     { /* kanji terminal */
2163     Gn[0] = IdASCII;
2164     Gn[1] = IdKatakana;
2165     Gn[2] = IdKatakana;
2166     Gn[3] = IdKanji;
2167     Glr[0] = 0;
2168     if ((ts.KanjiCode==IdJIS) &&
2169     (ts.JIS7Katakana==0))
2170     Glr[1] = 2; // 8-bit katakana
2171     else
2172     Glr[1] = 3;
2173     }
2174     break;
2175 doda 3742 case 66: AppliKeyMode = TRUE; break; // DECNKM
2176     case 67: ts.BSKey = IdBS; break; // DECBKM
2177     case 1000: // Mouse Tracking
2178 maya 3227 if (ts.MouseEventTracking)
2179     MouseReportMode = IdMouseTrackVT200;
2180     break;
2181 doda 3742 case 1001: // Hilite Mouse Tracking
2182 maya 3227 if (ts.MouseEventTracking)
2183     MouseReportMode = IdMouseTrackVT200Hl;
2184     break;
2185 doda 3742 case 1002: // Button-Event Mouse Tracking
2186 maya 3227 if (ts.MouseEventTracking)
2187     MouseReportMode = IdMouseTrackBtnEvent;
2188     break;
2189 doda 3742 case 1003: // Any-Event Mouse Tracking
2190 maya 3227 if (ts.MouseEventTracking)
2191     MouseReportMode = IdMouseTrackAllEvent;
2192     break;
2193 doda 3742 case 1004: // Focus Report
2194 maya 3227 if (ts.MouseEventTracking)
2195     FocusReportMode = TRUE;
2196     break;
2197 doda 3744 case 1047: // Alternate Screen Buffer
2198     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2199     BuffSaveScreen();
2200     AltScr = TRUE;
2201     }
2202     break;
2203     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2204     if (ts.TermFlag & TF_ALTSCR) {
2205     SaveCursor();
2206     }
2207 doda 3800 break;
2208 doda 3744 case 1049: // Alternate Screen Buffer
2209     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2210     SaveCursor();
2211     BuffSaveScreen();
2212     BuffClearScreen();
2213     AltScr = TRUE;
2214     }
2215 doda 3872 break;
2216     case 2004: // Bracketed Paste Mode
2217     BracketedPaste = TRUE;
2218     break;
2219 doda 3744 }
2220 maya 3227 }
2221    
2222 doda 3742 void CSQ_i_Mode() // MC (DEC)
2223 maya 3227 {
2224     if (Param[1]==-1) Param[1] = 0;
2225     switch (Param[1]) {
2226     case 1:
2227     OpenPrnFile();
2228     BuffDumpCurrentLine(LF);
2229     if (! AutoPrintMode)
2230     ClosePrnFile();
2231     break;
2232     /* auto print mode off */
2233     case 4:
2234     if (AutoPrintMode)
2235     {
2236     ClosePrnFile();
2237     AutoPrintMode = FALSE;
2238     }
2239     break;
2240     /* auto print mode on */
2241     case 5:
2242     if (! AutoPrintMode)
2243     {
2244     OpenPrnFile();
2245     AutoPrintMode = TRUE;
2246     }
2247     break;
2248     }
2249     }
2250    
2251 doda 3742 void CSQ_l_Mode() // DECRST
2252 maya 3227 {
2253     int i;
2254    
2255     for (i = 1 ; i <= NParam ; i++)
2256     switch (Param[i]) {
2257 doda 3742 case 1: AppliCursorMode = FALSE; break; // DECCKM
2258 doda 3802 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2259 doda 3742 case 5: /* Normal Video (DECSCNM) */
2260 maya 3227 if (ts.ColorFlag & CF_REVERSEVIDEO)
2261     CSQExchangeColor(); /* Exchange text/back color */
2262     break;
2263 doda 3742 case 6: // DECOM
2264 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2265 maya 3227 MoveCursor(0,CursorY);
2266     else {
2267     RelativeOrgMode = FALSE;
2268     MoveCursor(0,0);
2269     }
2270     break;
2271 doda 3742 case 7: AutoWrapMode = FALSE; break; // DECAWM
2272     case 8: AutoRepeatMode = FALSE; break; // DECARM
2273     case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2274     case 12: /* att610 cursor blinking */
2275 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2276     ts.NonblinkingCursor = TRUE;
2277     ChangeCaret();
2278     }
2279     break;
2280 doda 3742 case 19: PrintEX = FALSE; break; // DECPEX
2281     case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2282 doda 3743 case 47: // Alternate Screen Buffer
2283     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2284     BuffRestoreScreen();
2285     AltScr = FALSE;
2286     }
2287     break;
2288 maya 3227 case 59:
2289     if (ts.Language==IdJapanese)
2290     { /* katakana terminal */
2291     Gn[0] = IdASCII;
2292     Gn[1] = IdKatakana;
2293     Gn[2] = IdKatakana;
2294     Gn[3] = IdKanji;
2295     Glr[0] = 0;
2296     if ((ts.KanjiCode==IdJIS) &&
2297     (ts.JIS7Katakana==0))
2298     Glr[1] = 2; // 8-bit katakana
2299     else
2300     Glr[1] = 3;
2301     }
2302     break;
2303 doda 3742 case 66: AppliKeyMode = FALSE; break; // DECNKM
2304     case 67: ts.BSKey = IdDEL; break; // DECBKM
2305     case 1000: // Mouse Tracking
2306     case 1001: // Hilite Mouse Tracking
2307     case 1002: // Button-Event Mouse Tracking
2308 doda 3997 case 1003: // Any-Event Mouse Tracking
2309     MouseReportMode = IdMouseTrackNone;
2310     break;
2311 doda 3742 case 1004: FocusReportMode = FALSE; break; // Focus Report
2312 doda 3744 case 1047: // Alternate Screen Buffer
2313     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2314     BuffClearScreen();
2315     BuffRestoreScreen();
2316     AltScr = FALSE;
2317     }
2318     break;
2319     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2320     if (ts.TermFlag & TF_ALTSCR) {
2321     RestoreCursor();
2322     }
2323     break;
2324     case 1049: // Alternate Screen Buffer
2325     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2326     BuffClearScreen();
2327     BuffRestoreScreen();
2328 doda 3812 AltScr = FALSE;
2329 doda 3744 RestoreCursor();
2330     }
2331     break;
2332 doda 3872 case 2004: // Bracketed Paste Mode
2333     BracketedPaste = FALSE;
2334     break;
2335 maya 3227 }
2336     }
2337    
2338 doda 3742 void CSQ_n_Mode() // DSR (DEC)
2339 maya 3227 {
2340     }
2341    
2342     void CSQuest(BYTE b)
2343     {
2344     switch (b) {
2345 doda 3742 case 'K': CSLineErase(); break; // DECSEL
2346     case 'h': CSQ_h_Mode(); break; // DECSET
2347     case 'i': CSQ_i_Mode(); break; // MC (DEC)
2348     case 'l': CSQ_l_Mode(); break; // DECRST
2349     case 'n': CSQ_n_Mode(); break; // DSR (DEC)
2350 maya 3227 }
2351     }
2352    
2353     void SoftReset()
2354     // called by software-reset escape sequence handler
2355     {
2356     UpdateStr();
2357     AutoRepeatMode = TRUE;
2358     DispEnableCaret(TRUE); // cursor on
2359     InsertMode = FALSE;
2360     RelativeOrgMode = FALSE;
2361     AppliKeyMode = FALSE;
2362     AppliCursorMode = FALSE;
2363     if ((StatusLine>0) &&
2364     (CursorY == NumOfLines-1))
2365     MoveToMainScreen();
2366     CursorTop = 0;
2367     CursorBottom = NumOfLines-1-StatusLine;
2368     ResetCharSet();
2369    
2370     Send8BitMode = ts.Send8BitCtrl;
2371    
2372     /* Attribute */
2373     CharAttr = DefCharAttr;
2374     Special = FALSE;
2375     BuffSetCurCharAttr(CharAttr);
2376    
2377     // status buffers
2378 doda 3916 ResetCurSBuffer();
2379 maya 3227 }
2380    
2381     void CSExc(BYTE b)
2382     {
2383     switch (b) {
2384     case 'p':
2385     /* Software reset */
2386     SoftReset();
2387     break;
2388     }
2389     }
2390    
2391     void CSDouble(BYTE b)
2392     {
2393     switch (b) {
2394     case 'p':
2395     /* Select terminal mode (software reset) */
2396     SoftReset();
2397     if (NParam > 0) {
2398     switch (Param[1]) {
2399     case 61: // VT100 Mode
2400     Send8BitMode = FALSE; break;
2401     case 62: // VT200 Mode
2402     case 63: // VT300 Mode
2403     case 64: // VT400 Mode
2404     if (NParam > 1 && Param[2] == 1)
2405     Send8BitMode = FALSE;
2406     else
2407     Send8BitMode = TRUE;
2408     break;
2409     }
2410     }
2411     break;
2412     }
2413     }
2414    
2415     void CSDol(BYTE b)
2416     {
2417     switch (b) {
2418     case '}':
2419     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2420     if (StatusLine==0) return;
2421     if ((Param[1]<1) && (CursorY==NumOfLines-1))
2422     MoveToMainScreen();
2423     else if ((Param[1]==1) && (CursorY<NumOfLines-1))
2424     MoveToStatusLine();
2425     break;
2426     case '~':
2427     if ((ts.TermFlag & TF_ENABLESLINE)==0) return;
2428     if (Param[1]<=1)
2429     HideStatusLine();
2430     else if ((StatusLine==0) && (Param[1]==2))
2431     ShowStatusLine(1); // show
2432     break;
2433     }
2434     }
2435    
2436 doda 3997 void CSQuote(BYTE b)
2437     {
2438 doda 3998 int i;
2439 doda 3997 switch (b) {
2440     case 'w': // Enable Filter Rectangle (DECEFR)
2441     break;
2442    
2443     case 'z': // Enable DEC Locator reporting (DECELR)
2444     if (Param[1] < 0) {
2445     Param[1] = 0;
2446     }
2447     switch (Param[1]) {
2448     case 0:
2449     if (MouseReportMode == IdMouseTrackDECELR) {
2450     MouseReportMode = IdMouseTrackNone;
2451     }
2452     break;
2453     case 1:
2454     if (ts.MouseEventTracking) {
2455     MouseReportMode = IdMouseTrackDECELR;
2456     DecLocatorFlag &= ~DecLocatorOneShot;
2457     }
2458     break;
2459     case 2:
2460     if (ts.MouseEventTracking) {
2461     MouseReportMode = IdMouseTrackDECELR;
2462     DecLocatorFlag |= DecLocatorOneShot;
2463     }
2464     break;
2465     }
2466     if (NParam > 1 && Param[2] == 1) {
2467     DecLocatorFlag |= DecLocatorPixel;
2468     }
2469     break;
2470    
2471     case '{': // Select Locator Events (DECSLE)
2472 doda 3998 for (i=1; i<=NParam; i++) {
2473     if (Param[i] < 0) {
2474     Param[i] = 0;
2475     }
2476     switch (Param[i]) {
2477     case 0:
2478     DecLocatorFlag &= ~(DecLocatorButtonUp | DecLocatorButtonDown);
2479     break;
2480     case 1:
2481     DecLocatorFlag |= DecLocatorButtonDown;
2482     break;
2483     case 2:
2484     DecLocatorFlag &= ~DecLocatorButtonDown;
2485     break;
2486     case 3:
2487     DecLocatorFlag |= DecLocatorButtonUp;
2488     break;
2489     case 4:
2490     DecLocatorFlag &= ~DecLocatorButtonUp;
2491     break;
2492     }
2493 doda 3997 }
2494     break;
2495    
2496     case '|': // Request Locator Position (DECRQLP)
2497     DecLocatorReport(IdMouseEventCurStat, 0);
2498     break;
2499     }
2500     }
2501    
2502 doda 3263 void CSSpace(BYTE b) {
2503     switch (b) {
2504     case 'q':
2505 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2506     if (NParam > 0) {
2507     if (Param[1] < 0) Param[1] = 0;
2508     switch (Param[1]) {
2509     case 0:
2510     case 1:
2511     ts.CursorShape = IdBlkCur;
2512     ts.NonblinkingCursor = FALSE;
2513     break;
2514     case 2:
2515     ts.CursorShape = IdBlkCur;
2516     ts.NonblinkingCursor = TRUE;
2517     break;
2518     case 3:
2519     ts.CursorShape = IdHCur;
2520     ts.NonblinkingCursor = FALSE;
2521     break;
2522     case 4:
2523     ts.CursorShape = IdHCur;
2524     ts.NonblinkingCursor = TRUE;
2525     break;
2526     case 5:
2527     ts.CursorShape = IdVCur;
2528     ts.NonblinkingCursor = FALSE;
2529     break;
2530     case 6:
2531     ts.CursorShape = IdVCur;
2532     ts.NonblinkingCursor = TRUE;
2533     break;
2534     default:
2535     return;
2536     }
2537     ChangeCaret();
2538 doda 3263 }
2539     }
2540     break;
2541     }
2542     }
2543    
2544 maya 3227 void PrnParseCS(BYTE b) // printer mode
2545     {
2546     ParseMode = ModeFirst;
2547     switch (ICount) {
2548     /* no intermediate char */
2549     case 0:
2550     switch (Prv) {
2551     /* no private parameter */
2552     case 0:
2553     switch (b) {
2554     case 'i':
2555     if (Param[1]==4)
2556     {
2557     PrinterMode = FALSE;
2558     // clear prn buff
2559     WriteToPrnFile(0,FALSE);
2560     if (! AutoPrintMode)
2561     ClosePrnFile();
2562     return;
2563     }
2564     break;
2565     } /* of case Prv=0 */
2566     break;
2567     }
2568     break;
2569     /* one intermediate char */
2570     case 1: break;
2571     } /* of case Icount */
2572    
2573     WriteToPrnFile(b,TRUE);
2574     }