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 3744 - (hide annotations) (download) (as text)
Thu Jan 28 01:40:37 2010 UTC (14 years, 2 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 85138 byte(s)
Alternate Screen Buffer (拡張: DECSET 1047-1049)に対応。

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