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 4024 - (hide annotations) (download) (as text)
Thu Aug 19 08:41:25 2010 UTC (13 years, 7 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 92004 byte(s)
len に 0 を指定した時は strlen() で調べた値を使うようにした。

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