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 4101 - (hide annotations) (download) (as text)
Mon Sep 13 07:02:31 2010 UTC (13 years, 7 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtterm.c
File MIME type: text/x-csrc
File size: 94796 byte(s)
パラメータの評価の順番が他とは違っていて見づらいので IO-8256 関連を書き直した。

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