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 4199 - (hide annotations) (download) (as text)
Tue Nov 30 13:19:27 2010 UTC (13 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 95532 byte(s)
DECERA 等のパラメータのデフォルト値を修正。

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