Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/vtterm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3804 - (hide annotations) (download) (as text)
Thu Feb 25 12:38:47 2010 UTC (14 years, 1 month ago) by doda
File MIME type: text/x-csrc
File size: 86004 byte(s)
ClearOnResize が on の時、DECCOLM で2度画面がクリアされていたのを修正。

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