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 4096 - (hide annotations) (download) (as text)
Tue Sep 7 11:20:55 2010 UTC (13 years, 7 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 94618 byte(s)
DECERA と DECSERA の処理をまとめた。

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 doda 4084 case IdVT420:
1021     strncat_s(Tmp,sizeof(Tmp),"64;1;2;7;8;9;15;18;21",_TRUNCATE);
1022     break;
1023     case IdVT520:
1024     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;8;9;12;18;19;21;23;24;42;44;45;46",_TRUNCATE);
1025     break;
1026     case IdVT525:
1027     strncat_s(Tmp,sizeof(Tmp),"65;1;2;7;9;12;18;19;21;22;23;24;42;44;45;46",_TRUNCATE);
1028     break;
1029 maya 3227 }
1030     strncat_s(Tmp,sizeof(Tmp),"c",_TRUNCATE);
1031    
1032     CommBinaryOut(&cv,Tmp,strlen(Tmp)); /* Report terminal ID */
1033     }
1034    
1035     void ESCSpace(BYTE b)
1036     {
1037     switch (b) {
1038     case 'F': Send8BitMode = FALSE; break; // S7C1T
1039     case 'G': Send8BitMode = TRUE; break; // S8C1T
1040     }
1041     }
1042    
1043     void ESCSharp(BYTE b)
1044     {
1045     switch (b) {
1046     case '8': /* Fill screen with "E" */
1047     BuffUpdateScroll();
1048     BuffFillWithE();
1049     MoveCursor(0,0);
1050     ParseMode = ModeFirst;
1051     break;
1052     }
1053     }
1054    
1055     /* select double byte code set */
1056     void ESCDBCSSelect(BYTE b)
1057     {
1058     int Dist;
1059    
1060     if (ts.Language!=IdJapanese) return;
1061    
1062     switch (ICount) {
1063     case 1:
1064     if ((b=='@') || (b=='B'))
1065     {
1066     Gn[0] = IdKanji; /* Kanji -> G0 */
1067     if ((ts.TermFlag & TF_AUTOINVOKE)!=0)
1068     Glr[0] = 0; /* G0->GL */
1069     }
1070     break;
1071     case 2:
1072     /* Second intermediate char must be
1073     '(' or ')' or '*' or '+'. */
1074     Dist = (IntChar[2]-'(') & 3; /* G0 - G3 */
1075     if ((b=='1') || (b=='3') ||
1076     (b=='@') || (b=='B'))
1077     {
1078     Gn[Dist] = IdKanji; /* Kanji -> G0-3 */
1079     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1080     (Dist==0))
1081     Glr[0] = 0; /* G0->GL */
1082     }
1083     break;
1084     }
1085     }
1086    
1087     void ESCSelectCode(BYTE b)
1088     {
1089     switch (b) {
1090     case '0':
1091     if (ts.AutoWinSwitch>0)
1092     ChangeEmu = IdTEK; /* enter TEK mode */
1093     break;
1094     }
1095     }
1096    
1097     /* select single byte code set */
1098     void ESCSBCSSelect(BYTE b)
1099     {
1100     int Dist;
1101    
1102     /* Intermediate char must be
1103     '(' or ')' or '*' or '+'. */
1104     Dist = (IntChar[1]-'(') & 3; /* G0 - G3 */
1105    
1106     switch (b) {
1107     case '0': Gn[Dist] = IdSpecial; break;
1108     case '<': Gn[Dist] = IdASCII; break;
1109     case '>': Gn[Dist] = IdASCII; break;
1110     case 'A': Gn[Dist] = IdASCII; break;
1111     case 'B': Gn[Dist] = IdASCII; break;
1112     case 'H': Gn[Dist] = IdASCII; break;
1113     case 'I':
1114     if (ts.Language==IdJapanese)
1115     Gn[Dist] = IdKatakana;
1116     break;
1117     case 'J': Gn[Dist] = IdASCII; break;
1118     }
1119    
1120     if (((ts.TermFlag & TF_AUTOINVOKE)!=0) &&
1121     (Dist==0))
1122     Glr[0] = 0; /* G0->GL */
1123     }
1124    
1125     void PrnParseEscape(BYTE b) // printer mode
1126     {
1127     int i;
1128    
1129     ParseMode = ModeFirst;
1130     switch (ICount) {
1131     /* no intermediate char */
1132     case 0:
1133     switch (b) {
1134     case '[': /* CSI */
1135     ICount = 0;
1136     FirstPrm = TRUE;
1137     NParam = 1;
1138     Param[1] = -1;
1139     Prv = 0;
1140     WriteToPrnFile(ESC,FALSE);
1141     WriteToPrnFile('[',FALSE);
1142     ParseMode = ModeCSI;
1143     return;
1144     } /* end of case Icount=0 */
1145     break;
1146     /* one intermediate char */
1147     case 1:
1148     switch (IntChar[1]) {
1149     case '$':
1150     if (! DirectPrn)
1151     {
1152     ESCDBCSSelect(b);
1153     return;
1154     }
1155     break;
1156     case '(':
1157     case ')':
1158     case '*':
1159     case '+':
1160     if (! DirectPrn)
1161     {
1162     ESCSBCSSelect(b);
1163     return;
1164     }
1165     break;
1166     }
1167     break;
1168     /* two intermediate char */
1169     case 2:
1170     if ((! DirectPrn) &&
1171     (IntChar[1]=='$') &&
1172     ('('<=IntChar[2]) &&
1173     (IntChar[2]<='+'))
1174     {
1175     ESCDBCSSelect(b);
1176     return;
1177     }
1178     break;
1179     }
1180     // send the uninterpreted sequence to printer
1181     WriteToPrnFile(ESC,FALSE);
1182     for (i=1; i<=ICount; i++)
1183     WriteToPrnFile(IntChar[i],FALSE);
1184     WriteToPrnFile(b,TRUE);
1185     }
1186    
1187     void ParseEscape(BYTE b) /* b is the final char */
1188     {
1189     if (PrinterMode) { // printer mode
1190     PrnParseEscape(b);
1191     return;
1192     }
1193    
1194     switch (ICount) {
1195     /* no intermediate char */
1196     case 0:
1197     switch (b) {
1198     case '7': SaveCursor(); break;
1199     case '8': RestoreCursor(); break;
1200     case '=': AppliKeyMode = TRUE; break;
1201     case '>': AppliKeyMode = FALSE; break;
1202     case 'D': /* IND */
1203     LineFeed(0,TRUE);
1204     break;
1205     case 'E': /* NEL */
1206     MoveCursor(0,CursorY);
1207     LineFeed(0,TRUE);
1208     break;
1209     case 'H': /* HTS */
1210     SetTabStop();
1211     break;
1212     case 'M': /* RI */
1213     CursorUpWithScroll();
1214     break;
1215     case 'N': /* SS2 */
1216     GLtmp = 2;
1217     SSflag = TRUE;
1218     break;
1219     case 'O': /* SS3 */
1220     GLtmp = 3;
1221     SSflag = TRUE;
1222     break;
1223     case 'P': /* DCS */
1224     SavedMode = ParseMode;
1225     ESCFlag = FALSE;
1226     NParam = 1;
1227     Param[1] = -1;
1228     ParseMode = ModeDCS;
1229     return;
1230     case 'X': /* SOS */
1231     SavedMode = ParseMode;
1232     ESCFlag = FALSE;
1233     ParseMode = ModeSOS;
1234     return;
1235     case 'Z': AnswerTerminalType(); break;
1236     case '[': /* CSI */
1237     ICount = 0;
1238     FirstPrm = TRUE;
1239     NParam = 1;
1240     Param[1] = -1;
1241     Prv = 0;
1242     ParseMode = ModeCSI;
1243     return;
1244     case '\\': break; /* ST */
1245     case ']': /* XTERM sequence (OSC) */
1246     NParam = 1;
1247     Param[1] = 0;
1248     ParseMode = ModeXS;
1249     return;
1250     case '^':
1251     case '_': /* PM, APC */
1252     SavedMode = ParseMode;
1253     ESCFlag = FALSE;
1254     ParseMode = ModeSOS;
1255     return;
1256     case 'c': /* Hardware reset */
1257     HideStatusLine();
1258     ResetTerminal();
1259     ClearUserKey();
1260     ClearBuffer();
1261     if (ts.PortType==IdSerial) // reset serial port
1262     CommResetSerial(&ts, &cv, TRUE);
1263     break;
1264     case 'g': /* Visual Bell (screen original?) */
1265     VisualBell();
1266     break;
1267     case 'n': Glr[0] = 2; break; /* LS2 */
1268     case 'o': Glr[0] = 3; break; /* LS3 */
1269     case '|': Glr[1] = 3; break; /* LS3R */
1270     case '}': Glr[1] = 2; break; /* LS2R */
1271     case '~': Glr[1] = 1; break; /* LS1R */
1272     } /* end of case Icount=0 */
1273     break;
1274     /* one intermediate char */
1275     case 1:
1276     switch (IntChar[1]) {
1277     case ' ': ESCSpace(b); break;
1278     case '#': ESCSharp(b); break;
1279     case '$': ESCDBCSSelect(b); break;
1280     case '%': break;
1281     case '(':
1282     case ')':
1283     case '*':
1284     case '+':
1285     ESCSBCSSelect(b);
1286     break;
1287     }
1288     break;
1289     /* two intermediate char */
1290     case 2:
1291     if ((IntChar[1]=='$') &&
1292     ('('<=IntChar[2]) &&
1293     (IntChar[2]<='+'))
1294     ESCDBCSSelect(b);
1295     else if ((IntChar[1]=='%') &&
1296     (IntChar[2]=='!'))
1297     ESCSelectCode(b);
1298     break;
1299     }
1300     ParseMode = ModeFirst;
1301     }
1302    
1303     void EscapeSequence(BYTE b)
1304     {
1305     if (b<=US)
1306     ParseControl(b);
1307     else if ((b>=0x20) && (b<=0x2F))
1308     {
1309     if (ICount<IntCharMax) ICount++;
1310     IntChar[ICount] = b;
1311     }
1312     else if ((b>=0x30) && (b<=0x7E))
1313     ParseEscape(b);
1314     else if ((b>=0x80) && (b<=0x9F))
1315     ParseControl(b);
1316    
1317     JustAfterESC = FALSE;
1318     }
1319    
1320     void CSInsertCharacter()
1321     {
1322     // Insert space characters at cursor
1323     int Count;
1324    
1325     BuffUpdateScroll();
1326     if (Param[1]<1) Param[1] = 1;
1327     Count = Param[1];
1328     BuffInsertSpace(Count);
1329     }
1330    
1331     void CSCursorUp()
1332     {
1333     if (Param[1]<1) Param[1] = 1;
1334    
1335     if (CursorY >= CursorTop)
1336     {
1337     if (CursorY-Param[1] > CursorTop)
1338     MoveCursor(CursorX,CursorY-Param[1]);
1339     else
1340     MoveCursor(CursorX,CursorTop);
1341     }
1342     else {
1343     if (CursorY > 0)
1344     MoveCursor(CursorX,CursorY-Param[1]);
1345     else
1346     MoveCursor(CursorX,0);
1347     }
1348     }
1349    
1350     void CSCursorUp1()
1351     {
1352     MoveCursor(0,CursorY);
1353     CSCursorUp();
1354     }
1355    
1356     void CSCursorDown()
1357     {
1358     if (Param[1]<1) Param[1] = 1;
1359    
1360     if (CursorY <= CursorBottom)
1361     {
1362     if (CursorY+Param[1] < CursorBottom)
1363     MoveCursor(CursorX,CursorY+Param[1]);
1364     else
1365     MoveCursor(CursorX,CursorBottom);
1366     }
1367     else {
1368     if (CursorY < NumOfLines-StatusLine-1)
1369     MoveCursor(CursorX,CursorY+Param[1]);
1370     else
1371     MoveCursor(CursorX,NumOfLines-StatusLine);
1372     }
1373     }
1374    
1375     void CSCursorDown1()
1376     {
1377     MoveCursor(0,CursorY);
1378     CSCursorDown();
1379     }
1380    
1381     void CSScreenErase()
1382     {
1383     if (Param[1] == -1) Param[1] = 0;
1384     BuffUpdateScroll();
1385     switch (Param[1]) {
1386     case 0:
1387     // <ESC>[H(Cursor in left upper corner)�������J�[�\�������������w�������������A
1388     // <ESC>[J��<ESC>[2J�����������������A�����������A���s�o�b�t�@���X�N���[���A�E�g
1389     // �����������������B(2005.5.29 yutaka)
1390     // �R���t�B�O���[�V�������������������������������B(2008.5.3 yutaka)
1391     if (ts.ScrollWindowClearScreen &&
1392     (CursorX == 0 && CursorY == 0)) {
1393     // Erase screen (scroll out)
1394     BuffClearScreen();
1395     UpdateWindow(HVTWin);
1396    
1397     } else {
1398     // Erase characters from cursor to the end of screen
1399     BuffEraseCurToEnd();
1400     }
1401     break;
1402    
1403     case 1:
1404     // Erase characters from home to cursor
1405     BuffEraseHomeToCur();
1406     break;
1407    
1408     case 2:
1409     // Erase screen (scroll out)
1410     BuffClearScreen();
1411     UpdateWindow(HVTWin);
1412     break;
1413     }
1414     }
1415    
1416 doda 4070 void CSQSelScreenErase()
1417     {
1418     if (Param[1] == -1) Param[1] = 0;
1419     BuffUpdateScroll();
1420     switch (Param[1]) {
1421     case 0:
1422     // Erase characters from cursor to end
1423     BuffSelectedEraseCurToEnd();
1424     break;
1425    
1426     case 1:
1427     // Erase characters from home to cursor
1428     BuffSelectedEraseHomeToCur();
1429     break;
1430    
1431     case 2:
1432     // Erase entire screen
1433     BuffSelectedEraseScreen();
1434     break;
1435     }
1436     }
1437    
1438 maya 3227 void CSInsertLine()
1439     {
1440     // Insert lines at current position
1441     int Count, YEnd;
1442    
1443     if (CursorY < CursorTop) return;
1444     if (CursorY > CursorBottom) return;
1445     if (Param[1]<1) Param[1] = 1;
1446     Count = Param[1];
1447    
1448     YEnd = CursorBottom;
1449     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1450     if (Count > YEnd+1 - CursorY) Count = YEnd+1 - CursorY;
1451    
1452     BuffInsertLines(Count,YEnd);
1453     }
1454    
1455     void CSLineErase()
1456     {
1457     if (Param[1] == -1) Param[1] = 0;
1458     BuffUpdateScroll();
1459     switch (Param[1]) {
1460     /* erase char from cursor to end of line */
1461     case 0:
1462     BuffEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1463     break;
1464     /* erase char from start of line to cursor */
1465     case 1:
1466     BuffEraseCharsInLine(0,CursorX+1);
1467     break;
1468     /* erase entire line */
1469     case 2:
1470     BuffEraseCharsInLine(0,NumOfColumns);
1471     break;
1472     }
1473     }
1474    
1475 doda 4070 void CSQSelLineErase()
1476     {
1477     if (Param[1] == -1) Param[1] = 0;
1478     BuffUpdateScroll();
1479     switch (Param[1]) {
1480     /* erase char from cursor to end of line */
1481     case 0:
1482     BuffSelectedEraseCharsInLine(CursorX,NumOfColumns-CursorX);
1483     break;
1484     /* erase char from start of line to cursor */
1485     case 1:
1486     BuffSelectedEraseCharsInLine(0,CursorX+1);
1487     break;
1488     /* erase entire line */
1489     case 2:
1490     BuffSelectedEraseCharsInLine(0,NumOfColumns);
1491     break;
1492     }
1493     }
1494    
1495 maya 3227 void CSDeleteNLines()
1496     // Delete lines from current line
1497     {
1498     int Count, YEnd;
1499    
1500     if (CursorY < CursorTop) return;
1501     if (CursorY > CursorBottom) return;
1502     Count = Param[1];
1503     if (Count<1) Count = 1;
1504    
1505     YEnd = CursorBottom;
1506     if (CursorY > YEnd) YEnd = NumOfLines-1-StatusLine;
1507     if (Count > YEnd+1-CursorY) Count = YEnd+1-CursorY;
1508     BuffDeleteLines(Count,YEnd);
1509     }
1510    
1511     void CSDeleteCharacter()
1512     {
1513     // Delete characters in current line from cursor
1514    
1515     if (Param[1]<1) Param[1] = 1;
1516     BuffUpdateScroll();
1517     BuffDeleteChars(Param[1]);
1518     }
1519    
1520     void CSEraseCharacter()
1521     {
1522     if (Param[1]<1) Param[1] = 1;
1523     BuffUpdateScroll();
1524     BuffEraseChars(Param[1]);
1525     }
1526    
1527     void CSScrollUP()
1528     {
1529     if (Param[1]<1) Param[1] = 1;
1530     BuffUpdateScroll();
1531     BuffRegionScrollUpNLines(Param[1]);
1532     }
1533    
1534     void CSScrollDown()
1535     {
1536     if (Param[1]<1) Param[1] = 1;
1537     BuffUpdateScroll();
1538     BuffRegionScrollDownNLines(Param[1]);
1539     }
1540    
1541     void CSForwardTab()
1542     {
1543     if (Param[1]<1) Param[1] = 1;
1544     CursorForwardTab(Param[1], AutoWrapMode);
1545     }
1546    
1547     void CSBackwardTab()
1548     {
1549     if (Param[1]<1) Param[1] = 1;
1550     CursorBackwardTab(Param[1]);
1551     }
1552    
1553     void CSMoveToColumnN()
1554     {
1555     if (Param[1]<1) Param[1] = 1;
1556     Param[1]--;
1557     if (Param[1] < 0) Param[1] = 0;
1558     if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
1559     MoveCursor(Param[1],CursorY);
1560     }
1561    
1562     void CSCursorRight()
1563     {
1564     if (Param[1]<1) Param[1] = 1;
1565     if (CursorX + Param[1] > NumOfColumns-1)
1566     MoveCursor(NumOfColumns-1,CursorY);
1567     else
1568     MoveCursor(CursorX+Param[1],CursorY);
1569     }
1570    
1571     void CSCursorLeft()
1572     {
1573     if (Param[1]<1) Param[1] = 1;
1574     if (CursorX-Param[1] < 0)
1575     MoveCursor(0,CursorY);
1576     else
1577     MoveCursor(CursorX-Param[1],CursorY);
1578     }
1579    
1580     void CSMoveToLineN()
1581     {
1582     if (Param[1]<1) Param[1] = 1;
1583     if (RelativeOrgMode)
1584     {
1585     if (CursorTop+Param[1]-1 > CursorBottom)
1586     MoveCursor(CursorX,CursorBottom);
1587     else
1588     MoveCursor(CursorX,CursorTop+Param[1]-1);
1589     }
1590     else {
1591     if (Param[1] > NumOfLines-StatusLine)
1592     MoveCursor(CursorX,NumOfLines-1-StatusLine);
1593     else
1594     MoveCursor(CursorX,Param[1]-1);
1595     }
1596     }
1597    
1598     void CSMoveToXY()
1599     {
1600     int NewX, NewY;
1601    
1602     if (Param[1]<1) Param[1] = 1;
1603     if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
1604     NewX = Param[2] - 1;
1605     if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
1606    
1607     if ((StatusLine>0) && (CursorY==NumOfLines-1))
1608     NewY = CursorY;
1609     else if (RelativeOrgMode)
1610     {
1611     NewY = CursorTop + Param[1] - 1;
1612     if (NewY > CursorBottom) NewY = CursorBottom;
1613     }
1614     else {
1615     NewY = Param[1] - 1;
1616     if (NewY > NumOfLines-1-StatusLine)
1617     NewY = NumOfLines-1-StatusLine;
1618     }
1619     MoveCursor(NewX,NewY);
1620     }
1621    
1622     void CSDeleteTabStop()
1623     {
1624     if (Param[1]==-1) Param[1] = 0;
1625     ClearTabStop(Param[1]);
1626     }
1627    
1628 doda 3742 void CS_h_Mode() // SM
1629 maya 3227 {
1630     switch (Param[1]) {
1631 doda 3311 case 2: // KAM
1632     KeybEnabled = FALSE; break;
1633     case 4: // IRM
1634     InsertMode = TRUE; break;
1635     case 12: // SRM
1636 doda 3485 ts.LocalEcho = 0;
1637     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1638     TelChangeEcho();
1639     break;
1640 doda 3311 case 20: // LF/NL
1641 doda 3485 LFMode = TRUE;
1642     ts.CRSend = IdCRLF;
1643     cv.CRSend = IdCRLF;
1644     break;
1645 doda 3311 case 33: // WYSTCURM
1646 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1647     ts.NonblinkingCursor = TRUE;
1648     ChangeCaret();
1649     }
1650     break;
1651 doda 3311 case 34: // WYULCURM
1652 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1653     ts.CursorShape = IdHCur;
1654     ChangeCaret();
1655     }
1656     break;
1657 maya 3227 }
1658     }
1659    
1660 doda 3742 void CS_i_Mode() // MC
1661 maya 3227 {
1662     if (Param[1]==-1) Param[1] = 0;
1663     switch (Param[1]) {
1664     /* print screen */
1665     // PrintEX -- TRUE: print screen
1666     // FALSE: scroll region
1667     case 0: BuffPrint(! PrintEX); break;
1668     /* printer controller mode off */
1669     case 4: break; /* See PrnParseCS() */
1670     /* printer controller mode on */
1671     case 5:
1672     if (! AutoPrintMode)
1673     OpenPrnFile();
1674     DirectPrn = (ts.PrnDev[0]!=0);
1675     PrinterMode = TRUE;
1676     break;
1677     }
1678     }
1679    
1680 doda 3742 void CS_l_Mode() // RM
1681 maya 3227 {
1682     switch (Param[1]) {
1683 doda 3311 case 2: // KAM
1684     KeybEnabled = TRUE; break;
1685     case 4: // IRM
1686     InsertMode = FALSE; break;
1687     case 12: // SRM
1688 doda 3485 ts.LocalEcho = 1;
1689     if (cv.Ready && cv.TelFlag && (ts.TelEcho>0))
1690     TelChangeEcho();
1691     break;
1692 doda 3311 case 20: // LF/NL
1693 doda 3485 LFMode = FALSE;
1694     ts.CRSend = IdCR;
1695     cv.CRSend = IdCR;
1696     break;
1697 doda 3311 case 33: // WYSTCURM
1698 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1699     ts.NonblinkingCursor = FALSE;
1700     ChangeCaret();
1701     }
1702     break;
1703 doda 3311 case 34: // WYULCURM
1704 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
1705     ts.CursorShape = IdBlkCur;
1706     ChangeCaret();
1707     }
1708     break;
1709 maya 3227 }
1710     }
1711    
1712 doda 3742 void CS_n_Mode() // DSR
1713 maya 3227 {
1714     char Report[16];
1715 doda 3471 int Y, len;
1716 maya 3227
1717     switch (Param[1]) {
1718     case 5:
1719 doda 3311 /* Device Status Report -> Ready */
1720 doda 4024 SendCSIstr("0n", 0);
1721 maya 3227 break;
1722     case 6:
1723     /* Cursor Position Report */
1724     Y = CursorY+1;
1725     if ((StatusLine>0) &&
1726     (Y==NumOfLines))
1727     Y = 1;
1728 doda 3471 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
1729     SendCSIstr(Report, len);
1730 maya 3227 break;
1731     }
1732     }
1733    
1734 doda 3742 void CSSetAttr() // SGR
1735 maya 3227 {
1736     int i, P;
1737    
1738     UpdateStr();
1739     for (i=1 ; i<=NParam ; i++)
1740     {
1741     P = Param[i];
1742     if (P<0) P = 0;
1743     switch (P) {
1744     case 0: /* Clear all */
1745 doda 4070 if (CharAttr.Attr2 & Attr2Protect) {
1746     CharAttr = DefCharAttr;
1747     CharAttr.Attr2 |= Attr2Protect;
1748     }
1749     else {
1750     CharAttr = DefCharAttr;
1751     }
1752 maya 3227 BuffSetCurCharAttr(CharAttr);
1753     break;
1754    
1755     case 1: /* Bold */
1756     CharAttr.Attr |= AttrBold;
1757     BuffSetCurCharAttr(CharAttr);
1758     break;
1759    
1760     case 4: /* Under line */
1761     CharAttr.Attr |= AttrUnder;
1762     BuffSetCurCharAttr(CharAttr);
1763     break;
1764    
1765     case 5: /* Blink */
1766     CharAttr.Attr |= AttrBlink;
1767     BuffSetCurCharAttr(CharAttr);
1768     break;
1769    
1770     case 7: /* Reverse */
1771     CharAttr.Attr |= AttrReverse;
1772     BuffSetCurCharAttr(CharAttr);
1773     break;
1774    
1775     case 22: /* Bold off */
1776     CharAttr.Attr &= ~ AttrBold;
1777     BuffSetCurCharAttr(CharAttr);
1778     break;
1779    
1780     case 24: /* Under line off */
1781     CharAttr.Attr &= ~ AttrUnder;
1782     BuffSetCurCharAttr(CharAttr);
1783     break;
1784    
1785     case 25: /* Blink off */
1786     CharAttr.Attr &= ~ AttrBlink;
1787     BuffSetCurCharAttr(CharAttr);
1788     break;
1789    
1790     case 27: /* Reverse off */
1791     CharAttr.Attr &= ~ AttrReverse;
1792     BuffSetCurCharAttr(CharAttr);
1793     break;
1794    
1795     case 30:
1796     case 31:
1797     case 32:
1798     case 33:
1799     case 34:
1800     case 35:
1801     case 36:
1802     case 37: /* text color */
1803     CharAttr.Attr2 |= Attr2Fore;
1804     CharAttr.Fore = P - 30;
1805     BuffSetCurCharAttr(CharAttr);
1806     break;
1807    
1808     case 38: /* text color (256color mode) */
1809     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1810     i++;
1811     if (i < NParam) {
1812     P = Param[++i];
1813     if (P<0) {
1814     P = 0;
1815     }
1816     CharAttr.Attr2 |= Attr2Fore;
1817     CharAttr.Fore = P;
1818     BuffSetCurCharAttr(CharAttr);
1819     }
1820     }
1821     break;
1822    
1823     case 39: /* Reset text color */
1824     CharAttr.Attr2 &= ~ Attr2Fore;
1825     CharAttr.Fore = AttrDefaultFG;
1826     BuffSetCurCharAttr(CharAttr);
1827     break;
1828    
1829     case 40:
1830     case 41:
1831     case 42:
1832     case 43:
1833     case 44:
1834     case 45:
1835     case 46:
1836     case 47: /* Back color */
1837     CharAttr.Attr2 |= Attr2Back;
1838     CharAttr.Back = P - 40;
1839     BuffSetCurCharAttr(CharAttr);
1840     break;
1841    
1842     case 48: /* Back color (256color mode) */
1843     if ((ts.ColorFlag & CF_XTERM256) && i < NParam && Param[i+1] == 5) {
1844     i++;
1845     if (i < NParam) {
1846     P = Param[++i];
1847     if (P<0) {
1848     P = 0;
1849     }
1850     CharAttr.Attr2 |= Attr2Back;
1851     CharAttr.Back = P;
1852     BuffSetCurCharAttr(CharAttr);
1853     }
1854     }
1855     break;
1856    
1857     case 49: /* Reset back color */
1858     CharAttr.Attr2 &= ~ Attr2Back;
1859     CharAttr.Back = AttrDefaultBG;
1860     BuffSetCurCharAttr(CharAttr);
1861     break;
1862    
1863     case 90:
1864     case 91:
1865     case 92:
1866     case 93:
1867     case 94:
1868     case 95:
1869     case 96:
1870     case 97: /* aixterm style text color */
1871     if (ts.ColorFlag & CF_AIXTERM16) {
1872     CharAttr.Attr2 |= Attr2Fore;
1873     CharAttr.Fore = P - 90 + 8;
1874     BuffSetCurCharAttr(CharAttr);
1875     }
1876     break;
1877    
1878     case 100:
1879     if (! (ts.ColorFlag & CF_AIXTERM16)) {
1880     /* Reset text and back color */
1881     CharAttr.Attr2 &= ~ (Attr2Fore | Attr2Back);
1882     CharAttr.Fore = AttrDefaultFG;
1883     CharAttr.Back = AttrDefaultBG;
1884     BuffSetCurCharAttr(CharAttr);
1885     break;
1886     }
1887     /* fall through to aixterm style back color */
1888    
1889     case 101:
1890     case 102:
1891     case 103:
1892     case 104:
1893     case 105:
1894     case 106:
1895     case 107: /* aixterm style back color */
1896     if (ts.ColorFlag & CF_AIXTERM16) {
1897     CharAttr.Attr2 |= Attr2Back;
1898     CharAttr.Back = P - 100 + 8;
1899     BuffSetCurCharAttr(CharAttr);
1900     }
1901     break;
1902     }
1903     }
1904     }
1905    
1906     void CSSetScrollRegion()
1907     {
1908     if ((StatusLine>0) &&
1909     (CursorY==NumOfLines-1))
1910     {
1911     MoveCursor(0,CursorY);
1912     return;
1913     }
1914     if (Param[1]<1) Param[1] =1;
1915     if ((NParam < 2) | (Param[2]<1))
1916     Param[2] = NumOfLines-StatusLine;
1917     Param[1]--;
1918     Param[2]--;
1919     if (Param[1] > NumOfLines-1-StatusLine)
1920     Param[1] = NumOfLines-1-StatusLine;
1921     if (Param[2] > NumOfLines-1-StatusLine)
1922     Param[2] = NumOfLines-1-StatusLine;
1923     if (Param[1] >= Param[2]) return;
1924     CursorTop = Param[1];
1925     CursorBottom = Param[2];
1926     if (RelativeOrgMode) MoveCursor(0,CursorTop);
1927     else MoveCursor(0,0);
1928     }
1929    
1930     void CSSunSequence() /* Sun terminal private sequences */
1931     {
1932 doda 3471 int x, y, len;
1933 doda 3487 char Report[TitleBuffSize*2+10];
1934 maya 3227
1935     switch (Param[1]) {
1936 doda 3302 case 1: // De-iconify window
1937 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1938     DispShowWindow(WINDOW_RESTORE);
1939 doda 3302 break;
1940     case 2: // Iconify window
1941 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1942     DispShowWindow(WINDOW_MINIMIZE);
1943 doda 3302 break;
1944     case 3: // set window position
1945 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1946     if (NParam < 2) Param[2] = 0;
1947     if (NParam < 3) Param[3] = 0;
1948     DispMoveWindow(Param[2], Param[3]);
1949     }
1950 doda 3297 break;
1951 doda 3466 case 4: // set window size
1952 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1953     if (NParam < 2) Param[2] = 0;
1954     if (NParam < 3) Param[3] = 0;
1955     DispResizeWin(Param[3], Param[2]);
1956     }
1957 doda 3464 break;
1958 doda 3311 case 5: // Raise window
1959 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1960     DispShowWindow(WINDOW_RAISE);
1961 doda 3309 break;
1962 doda 3311 case 6: // Lower window
1963 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1964     DispShowWindow(WINDOW_LOWER);
1965 doda 3309 break;
1966 doda 3311 case 7: // Refresh window
1967 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE)
1968     DispShowWindow(WINDOW_REFRESH);
1969 doda 3310 break;
1970 maya 3227 case 8: /* set terminal size */
1971 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1972     if ((Param[2]<=1) || (NParam<2)) Param[2] = 24;
1973     if ((Param[3]<=1) || (NParam<3)) Param[3] = 80;
1974     ChangeTerminalSize(Param[3],Param[2]);
1975     }
1976 maya 3227 break;
1977 doda 3302 case 9: // Maximize/Restore window
1978 doda 3485 if (ts.WindowFlag & WF_WINDOWCHANGE) {
1979     if (NParam < 2 || Param[2] == 0) {
1980     DispShowWindow(WINDOW_RESTORE);
1981     }
1982 doda 3489 else if (Param[2] == 1) {
1983 doda 3485 DispShowWindow(WINDOW_MAXIMIZE);
1984     }
1985 doda 3302 }
1986     break;
1987 doda 3466 case 11: // Report window state
1988 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1989     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%dt", CLocale, DispWindowIconified()?2:1);
1990     SendCSIstr(Report, len);
1991     }
1992 doda 3466 break;
1993 doda 3469 case 13: // Report window position
1994 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
1995     DispGetWindowPos(&x, &y);
1996     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "3;%d;%dt", CLocale, x, y);
1997     SendCSIstr(Report, len);
1998     }
1999 doda 3469 break;
2000 maya 3227 case 14: /* get window size??? */
2001 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2002     /* this is not actual window size */
2003 doda 4024 SendCSIstr("4;640;480t", 0);
2004 doda 3485 }
2005 maya 3227 break;
2006     case 18: /* get terminal size */
2007 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2008     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "8;%u;%u;t", CLocale,
2009     NumOfLines-StatusLine, NumOfColumns);
2010     SendCSIstr(Report, len);
2011     }
2012 maya 3227 break;
2013 doda 3475 case 19: // Report display size (character)
2014 doda 3485 if (ts.WindowFlag & WF_WINDOWREPORT) {
2015     DispGetRootWinSize(&x, &y);
2016     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "9;%d;%dt", CLocale, y, x);
2017     SendCSIstr(Report, len);
2018     }
2019 doda 3475 break;
2020 doda 3487 case 20: // Report icon label
2021 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2022 doda 3774 case IdTitleReportIgnore:
2023 doda 3747 // nothing to do
2024     break;
2025 doda 3774 case IdTitleReportAccept:
2026 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2027     case IdTitleChangeRequestOff:
2028 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2029 doda 3747 break;
2030     case IdTitleChangeRequestAhead:
2031     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, cv.TitleRemote, ts.Title);
2032     break;
2033     case IdTitleChangeRequestLast:
2034     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s %s", CLocale, ts.Title, cv.TitleRemote);
2035     break;
2036     default:
2037     if (cv.TitleRemote[0] == 0) {
2038     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, ts.Title);
2039     }
2040     else {
2041     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "L%s", CLocale, cv.TitleRemote);
2042     }
2043     }
2044     SendOSCstr(Report, len);
2045     break;
2046     default: // IdTitleReportEmpty:
2047 doda 4024 SendOSCstr("L", 0);
2048 doda 3747 break;
2049 doda 3487 }
2050     break;
2051     case 21: // Report window title
2052 doda 3747 switch (ts.WindowFlag & WF_TITLEREPORT) {
2053 doda 3774 case IdTitleReportIgnore:
2054 doda 3747 // nothing to do
2055     break;
2056 doda 3774 case IdTitleReportAccept:
2057 doda 3747 switch (ts.AcceptTitleChangeRequest) {
2058     case IdTitleChangeRequestOff:
2059 doda 3487 len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2060 doda 3747 break;
2061     case IdTitleChangeRequestAhead:
2062     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, cv.TitleRemote, ts.Title);
2063     break;
2064     case IdTitleChangeRequestLast:
2065     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s %s", CLocale, ts.Title, cv.TitleRemote);
2066     break;
2067     default:
2068     if (cv.TitleRemote[0] == 0) {
2069     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, ts.Title);
2070     }
2071     else {
2072     len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "l%s", CLocale, cv.TitleRemote);
2073     }
2074     }
2075     SendOSCstr(Report, len);
2076     break;
2077     default: // IdTitleReportEmpty:
2078 doda 4024 SendOSCstr("l", 0);
2079 doda 3747 break;
2080 doda 3487 }
2081     break;
2082 maya 3227 }
2083     }
2084    
2085     void CSGT(BYTE b)
2086     {
2087     switch (b) {
2088 doda 3311 case 'c': /* second terminal report (Secondary DA) */
2089 doda 3472 if (Param[1] < 1) {
2090 doda 4024 SendCSIstr(">32;100;2c", 0); /* VT382 */
2091 doda 3472 }
2092 maya 3227 break;
2093     case 'J':
2094     if (Param[1]==3) // IO-8256 terminal
2095     {
2096 doda 4093 if (Param[2] < 1 || NParam < 2) Param[2]=1;
2097     if (Param[3] < 1 || NParam < 3) Param[3]=1;
2098     if (Param[4] < 1 || NParam < 4) Param[4]=1;
2099     if (Param[5] < 1 || NParam < 5) Param[5]=1;
2100 maya 3227 BuffEraseBox(Param[3]-1,Param[2]-1,
2101     Param[5]-1,Param[4]-1);
2102     }
2103     break;
2104     case 'K':
2105     if ((NParam>=2) && (Param[1]==5))
2106     { // IO-8256 terminal
2107     switch (Param[2]) {
2108     case 3:
2109     case 4:
2110     case 5:
2111     case 6:
2112     BuffDrawLine(CharAttr, Param[2], Param[3]);
2113     break;
2114     case 12:
2115     /* Text color */
2116     if ((Param[3]>=0) && (Param[3]<=7))
2117     {
2118     switch (Param[3]) {
2119     case 3: CharAttr.Fore = IdBlue; break;
2120     case 4: CharAttr.Fore = IdCyan; break;
2121     case 5: CharAttr.Fore = IdYellow; break;
2122     case 6: CharAttr.Fore = IdMagenta; break;
2123     default: CharAttr.Fore = Param[3]; break;
2124     }
2125     CharAttr.Attr2 |= Attr2Fore;
2126     BuffSetCurCharAttr(CharAttr);
2127     }
2128     break;
2129     }
2130     }
2131     else if (Param[1]==3)
2132     {// IO-8256 terminal
2133     if (Param[2]<1) Param[2] = 1;
2134     if (Param[3]<1) Param[2] = 1;
2135     BuffEraseCharsInLine(Param[2]-1,Param[3]-Param[2]+1);
2136     }
2137     break;
2138     }
2139     }
2140    
2141 doda 3742 void CSQExchangeColor() // DECSCNM / Visual Bell
2142 maya 3227 {
2143     COLORREF ColorRef;
2144    
2145     BuffUpdateScroll();
2146    
2147     if (ts.ColorFlag & CF_REVERSECOLOR) {
2148     ColorRef = ts.VTColor[0];
2149     ts.VTColor[0] = ts.VTReverseColor[0];
2150     ts.VTReverseColor[0] = ColorRef;
2151     ColorRef = ts.VTColor[1];
2152     ts.VTColor[1] = ts.VTReverseColor[1];
2153     ts.VTReverseColor[1] = ColorRef;
2154     }
2155     else {
2156     ColorRef = ts.VTColor[0];
2157     ts.VTColor[0] = ts.VTColor[1];
2158     ts.VTColor[1] = ColorRef;
2159     }
2160    
2161     ColorRef = ts.VTBoldColor[0];
2162     ts.VTBoldColor[0] = ts.VTBoldColor[1];
2163     ts.VTBoldColor[1] = ColorRef;
2164    
2165     ColorRef = ts.VTBlinkColor[0];
2166     ts.VTBlinkColor[0] = ts.VTBlinkColor[1];
2167     ts.VTBlinkColor[1] = ColorRef;
2168    
2169     ColorRef = ts.URLColor[0];
2170     ts.URLColor[0] = ts.URLColor[1];
2171     ts.URLColor[1] = ColorRef;
2172    
2173     ts.ColorFlag ^= CF_REVERSEVIDEO;
2174    
2175     #ifdef ALPHABLEND_TYPE2
2176 doda 3715 // BGInitialize();
2177     BGExchangeColor();
2178 maya 3227 #endif
2179     DispChangeBackground();
2180     UpdateWindow(HVTWin);
2181     }
2182    
2183 doda 3802 void CSQChangeColumnMode(int width) // DECCOLM
2184     {
2185     ChangeTerminalSize(width, NumOfLines-StatusLine);
2186 doda 3804 if ((ts.TermFlag & TF_CLEARONRESIZE) == 0) {
2187     MoveCursor(0, 0);
2188     BuffClearScreen();
2189     UpdateWindow(HVTWin);
2190     }
2191 doda 3802 }
2192    
2193 doda 3742 void CSQ_h_Mode() // DECSET
2194 maya 3227 {
2195     int i;
2196    
2197     for (i = 1 ; i<=NParam ; i++)
2198     switch (Param[i]) {
2199 doda 3742 case 1: AppliCursorMode = TRUE; break; // DECCKM
2200 doda 3802 case 3: CSQChangeColumnMode(132); break; // DECCOLM
2201 doda 3742 case 5: /* Reverse Video (DECSCNM) */
2202 maya 3227 if (!(ts.ColorFlag & CF_REVERSEVIDEO))
2203     CSQExchangeColor(); /* Exchange text/back color */
2204     break;
2205 doda 3742 case 6: // DECOM
2206 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2207 maya 3227 MoveCursor(0,CursorY);
2208     else {
2209     RelativeOrgMode = TRUE;
2210     MoveCursor(0,CursorTop);
2211     }
2212     break;
2213 doda 3742 case 7: AutoWrapMode = TRUE; break; // DECAWM
2214     case 8: AutoRepeatMode = TRUE; break; // DECARM
2215     case 9: /* X10 Mouse Tracking */
2216 maya 3227 if (ts.MouseEventTracking)
2217     MouseReportMode = IdMouseTrackX10;
2218     break;
2219 doda 3742 case 12: /* att610 cursor blinking */
2220 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2221     ts.NonblinkingCursor = FALSE;
2222     ChangeCaret();
2223     }
2224     break;
2225 doda 3742 case 19: PrintEX = TRUE; break; // DECPEX
2226     case 25: DispEnableCaret(TRUE); break; // cursor on (DECTCEM)
2227     case 38: // DECTEK
2228 maya 3227 if (ts.AutoWinSwitch>0)
2229     ChangeEmu = IdTEK; /* Enter TEK Mode */
2230     break;
2231 doda 3743 case 47: // Alternate Screen Buffer
2232     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2233     BuffSaveScreen();
2234     AltScr = TRUE;
2235     }
2236     break;
2237 maya 3227 case 59:
2238     if (ts.Language==IdJapanese)
2239     { /* kanji terminal */
2240     Gn[0] = IdASCII;
2241     Gn[1] = IdKatakana;
2242     Gn[2] = IdKatakana;
2243     Gn[3] = IdKanji;
2244     Glr[0] = 0;
2245     if ((ts.KanjiCode==IdJIS) &&
2246     (ts.JIS7Katakana==0))
2247     Glr[1] = 2; // 8-bit katakana
2248     else
2249     Glr[1] = 3;
2250     }
2251     break;
2252 doda 3742 case 66: AppliKeyMode = TRUE; break; // DECNKM
2253     case 67: ts.BSKey = IdBS; break; // DECBKM
2254     case 1000: // Mouse Tracking
2255 maya 3227 if (ts.MouseEventTracking)
2256     MouseReportMode = IdMouseTrackVT200;
2257     break;
2258 doda 3742 case 1001: // Hilite Mouse Tracking
2259 maya 3227 if (ts.MouseEventTracking)
2260     MouseReportMode = IdMouseTrackVT200Hl;
2261     break;
2262 doda 3742 case 1002: // Button-Event Mouse Tracking
2263 maya 3227 if (ts.MouseEventTracking)
2264     MouseReportMode = IdMouseTrackBtnEvent;
2265     break;
2266 doda 3742 case 1003: // Any-Event Mouse Tracking
2267 maya 3227 if (ts.MouseEventTracking)
2268     MouseReportMode = IdMouseTrackAllEvent;
2269     break;
2270 doda 3742 case 1004: // Focus Report
2271 maya 3227 if (ts.MouseEventTracking)
2272     FocusReportMode = TRUE;
2273     break;
2274 doda 3744 case 1047: // Alternate Screen Buffer
2275     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2276     BuffSaveScreen();
2277     AltScr = TRUE;
2278     }
2279     break;
2280     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2281     if (ts.TermFlag & TF_ALTSCR) {
2282     SaveCursor();
2283     }
2284 doda 3800 break;
2285 doda 3744 case 1049: // Alternate Screen Buffer
2286     if ((ts.TermFlag & TF_ALTSCR) && !AltScr) {
2287     SaveCursor();
2288     BuffSaveScreen();
2289     BuffClearScreen();
2290     AltScr = TRUE;
2291     }
2292 doda 3872 break;
2293     case 2004: // Bracketed Paste Mode
2294     BracketedPaste = TRUE;
2295     break;
2296 doda 3744 }
2297 maya 3227 }
2298    
2299 doda 4041 void CSQ_i_Mode() // DECMC
2300 maya 3227 {
2301     if (Param[1]==-1) Param[1] = 0;
2302     switch (Param[1]) {
2303     case 1:
2304     OpenPrnFile();
2305     BuffDumpCurrentLine(LF);
2306     if (! AutoPrintMode)
2307     ClosePrnFile();
2308     break;
2309     /* auto print mode off */
2310     case 4:
2311     if (AutoPrintMode)
2312     {
2313     ClosePrnFile();
2314     AutoPrintMode = FALSE;
2315     }
2316     break;
2317     /* auto print mode on */
2318     case 5:
2319     if (! AutoPrintMode)
2320     {
2321     OpenPrnFile();
2322     AutoPrintMode = TRUE;
2323     }
2324     break;
2325     }
2326     }
2327    
2328 doda 3742 void CSQ_l_Mode() // DECRST
2329 maya 3227 {
2330     int i;
2331    
2332     for (i = 1 ; i <= NParam ; i++)
2333     switch (Param[i]) {
2334 doda 3742 case 1: AppliCursorMode = FALSE; break; // DECCKM
2335 doda 3802 case 3: CSQChangeColumnMode(80); break; // DECCOLM
2336 doda 3742 case 5: /* Normal Video (DECSCNM) */
2337 maya 3227 if (ts.ColorFlag & CF_REVERSEVIDEO)
2338     CSQExchangeColor(); /* Exchange text/back color */
2339     break;
2340 doda 3742 case 6: // DECOM
2341 doda 3485 if ((StatusLine>0) && (CursorY==NumOfLines-1))
2342 maya 3227 MoveCursor(0,CursorY);
2343     else {
2344     RelativeOrgMode = FALSE;
2345     MoveCursor(0,0);
2346     }
2347     break;
2348 doda 3742 case 7: AutoWrapMode = FALSE; break; // DECAWM
2349     case 8: AutoRepeatMode = FALSE; break; // DECARM
2350     case 9: MouseReportMode = IdMouseTrackNone; break; /* X10 Mouse Tracking */
2351     case 12: /* att610 cursor blinking */
2352 doda 3485 if (ts.WindowFlag & WF_CURSORCHANGE) {
2353     ts.NonblinkingCursor = TRUE;
2354     ChangeCaret();
2355     }
2356     break;
2357 doda 3742 case 19: PrintEX = FALSE; break; // DECPEX
2358     case 25: DispEnableCaret(FALSE); break; // cursor off (DECTCEM)
2359 doda 3743 case 47: // Alternate Screen Buffer
2360     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2361     BuffRestoreScreen();
2362     AltScr = FALSE;
2363     }
2364     break;
2365 maya 3227 case 59:
2366     if (ts.Language==IdJapanese)
2367     { /* katakana terminal */
2368     Gn[0] = IdASCII;
2369     Gn[1] = IdKatakana;
2370     Gn[2] = IdKatakana;
2371     Gn[3] = IdKanji;
2372     Glr[0] = 0;
2373     if ((ts.KanjiCode==IdJIS) &&
2374     (ts.JIS7Katakana==0))
2375     Glr[1] = 2; // 8-bit katakana
2376     else
2377     Glr[1] = 3;
2378     }
2379     break;
2380 doda 3742 case 66: AppliKeyMode = FALSE; break; // DECNKM
2381     case 67: ts.BSKey = IdDEL; break; // DECBKM
2382     case 1000: // Mouse Tracking
2383     case 1001: // Hilite Mouse Tracking
2384     case 1002: // Button-Event Mouse Tracking
2385 doda 3997 case 1003: // Any-Event Mouse Tracking
2386     MouseReportMode = IdMouseTrackNone;
2387     break;
2388 doda 3742 case 1004: FocusReportMode = FALSE; break; // Focus Report
2389 doda 3744 case 1047: // Alternate Screen Buffer
2390     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2391     BuffClearScreen();
2392     BuffRestoreScreen();
2393     AltScr = FALSE;
2394     }
2395     break;
2396     case 1048: // Save Cursor Position (Alternate Screen Buffer)
2397     if (ts.TermFlag & TF_ALTSCR) {
2398     RestoreCursor();
2399     }
2400     break;
2401     case 1049: // Alternate Screen Buffer
2402     if ((ts.TermFlag & TF_ALTSCR) && AltScr) {
2403     BuffClearScreen();
2404     BuffRestoreScreen();
2405 doda 3812 AltScr = FALSE;
2406 doda 3744 RestoreCursor();
2407     }
2408     break;
2409 doda 3872 case 2004: // Bracketed Paste Mode
2410     BracketedPaste = FALSE;
2411     break;
2412 maya 3227 }
2413     }
2414    
2415 doda 4041 void CSQ_n_Mode() // DECDSR
2416 maya 3227 {
2417 doda 4023 switch (Param[1]) {
2418     case 53:
2419 doda 4041 case 55:
2420 doda 4023 /* Locator Device Status Report -> Ready */
2421 doda 4024 SendCSIstr("?50n", 0);
2422 doda 4023 break;
2423     }
2424 maya 3227 }
2425    
2426     void CSQuest(BYTE b)
2427     {
2428     switch (b) {
2429 doda 4070 case 'J': CSQSelScreenErase(); break; // DECSED
2430     case 'K': CSQSelLineErase(); break; // DECSEL
2431 doda 3742 case 'h': CSQ_h_Mode(); break; // DECSET
2432 doda 4041 case 'i': CSQ_i_Mode(); break; // DECMC
2433 doda 3742 case 'l': CSQ_l_Mode(); break; // DECRST
2434 doda 4041 case 'n': CSQ_n_Mode(); break; // DECDSR
2435 maya 3227 }
2436     }
2437    
2438     void SoftReset()
2439     // called by software-reset escape sequence handler
2440     {
2441     UpdateStr();
2442     AutoRepeatMode = TRUE;
2443     DispEnableCaret(TRUE); // cursor on
2444     InsertMode = FALSE;
2445     RelativeOrgMode = FALSE;
2446     AppliKeyMode = FALSE;
2447     AppliCursorMode = FALSE;
2448     if ((StatusLine>0) &&
2449     (CursorY == NumOfLines-1))
2450     MoveToMainScreen();
2451     CursorTop = 0;
2452     CursorBottom = NumOfLines-1-StatusLine;
2453     ResetCharSet();
2454    
2455     Send8BitMode = ts.Send8BitCtrl;
2456    
2457     /* Attribute */
2458     CharAttr = DefCharAttr;
2459     Special = FALSE;
2460     BuffSetCurCharAttr(CharAttr);
2461    
2462     // status buffers
2463 doda 3916 ResetCurSBuffer();
2464 maya 3227 }
2465    
2466     void CSExc(BYTE b)
2467     {
2468     switch (b) {
2469     case 'p':
2470     /* Software reset */
2471     SoftReset();
2472     break;
2473     }
2474     }
2475    
2476     void CSDouble(BYTE b)
2477     {
2478     switch (b) {
2479 doda 4094 case 'p': // DECSCL
2480 maya 3227 /* Select terminal mode (software reset) */
2481     SoftReset();
2482     if (NParam > 0) {
2483     switch (Param[1]) {
2484 doda 4094 case 61: // VT-Level 1 (VT100)
2485 maya 3227 Send8BitMode = FALSE; break;
2486 doda 4094 case 62: // VT-Level 2 (VT200)
2487     case 63: // VT-Level 3 (VT300)
2488     case 64: // VT-Level 4 (VT400)
2489     case 65: // VT-Level 5 (VT500)
2490 maya 3227 if (NParam > 1 && Param[2] == 1)
2491     Send8BitMode = FALSE;
2492     else
2493     Send8BitMode = TRUE;
2494     break;
2495     }
2496     }
2497     break;
2498 doda 4070 case 'q': // DECSCA
2499     if (Param[1] < 0)
2500     Param[1] = 0;
2501     switch (Param[1]) {
2502     case 0:
2503     case 2:
2504     CharAttr.Attr2 &= ~Attr2Protect;
2505     BuffSetCurCharAttr(CharAttr);
2506     break;
2507     case 1:
2508     CharAttr.Attr2 |= Attr2Protect;
2509     BuffSetCurCharAttr(CharAttr);
2510     break;
2511     default:
2512     /* nothing to do */
2513     break;
2514     }
2515     break;
2516 maya 3227 }
2517     }
2518    
2519     void CSDol(BYTE b)
2520     {
2521     switch (b) {
2522 doda 4090 case 'z': // DECERA
2523     case '{': // DECSERA
2524     if (Param[1] < 1 || NParam < 1) Param[1]=1;
2525     if (Param[2] < 1 || NParam < 2) Param[2]=1;
2526     if (Param[3] < 1 || NParam < 3) Param[3]=1;
2527     if (Param[4] < 1 || NParam < 4) Param[4]=1;
2528 doda 4095 if (RelativeOrgMode) {
2529     Param[1] += CursorTop;
2530     if (Param[1] > CursorBottom) {
2531     Param[1] = CursorBottom + 1;
2532     }
2533     Param[3] += CursorTop;
2534     if (Param[3] > CursorBottom) {
2535     Param[3] = CursorBottom + 1;
2536     }
2537     }
2538 doda 4096 if (b == 'z') {
2539     BuffEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
2540     }
2541     else {
2542     BuffSelectEraseBox(Param[2]-1, Param[1]-1, Param[4]-1, Param[3]-1);
2543     }
2544 doda 4090 break;
2545    
2546 maya 3227 case '}':