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 4018 - (hide annotations) (download) (as text)
Wed Aug 18 16:55:55 2010 UTC (13 years, 7 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 91382 byte(s)
DECSLE で、Filter Rectangle を正しくキャンセルするように修正。

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