Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


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