[Ttssh2-commit] [5324] DECLRMM/ DECSLRMに仮対応

svnno****@sourc***** svnno****@sourc*****
2013年 6月 17日 (月) 21:14:31 JST


Revision: 5324
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5324
Author:   doda
Date:     2013-06-17 21:14:30 +0900 (Mon, 17 Jun 2013)
Log Message:
-----------
DECLRMM/DECSLRMに仮対応
差分が大きくなってきたのでとりあえずコミット。まだ直さないといけない所があるけれど。

Modified Paths:
--------------
    trunk/teraterm/teraterm/buffer.c
    trunk/teraterm/teraterm/buffer.h
    trunk/teraterm/teraterm/vtterm.c
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/buffer.c
===================================================================
--- trunk/teraterm/teraterm/buffer.c	2013-06-17 11:56:58 UTC (rev 5323)
+++ trunk/teraterm/teraterm/buffer.c	2013-06-17 12:14:30 UTC (rev 5324)
@@ -30,8 +30,8 @@
 
 // status line
 int StatusLine;	//0: none 1: shown 
-/* top & bottom margin */
-int CursorTop, CursorBottom;
+/* top, bottom, left & right margin */
+int CursorTop, CursorBottom, CursorLeftM, CursorRightM;
 BOOL Selected;
 BOOL Wrap;
 
@@ -419,6 +419,8 @@
 	/* Top/bottom margin */
 	CursorTop = 0;
 	CursorBottom = NumOfLines-1;
+	CursorLeftM = 0;
+	CursorRightM = NumOfColumns-1;
 
 	/* Tab stops */
 	NTabStops = (NumOfColumns-1) >> 3;
@@ -559,41 +561,45 @@
 // Insert space characters at the current position
 //   Count: Number of characters to be inserted
 {
+	int LineEnd, MoveLen;
+
 	NewLine(PageStart+CursorY);
 
-	if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
+	if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8)
 		EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
-	}
 
-	if (Count > NumOfColumns - CursorX) {
-		Count = NumOfColumns - CursorX;
+	if (CursorX > CursorRightM)
+		LineEnd = NumOfColumns - 1;
+	else
+		LineEnd = CursorRightM;
+
+	if (Count > LineEnd - CursorX)
+		Count = LineEnd + 1 - CursorX;
+
+	MoveLen = LineEnd + 1 - CursorX - Count;
+
+	if (MoveLen > 0) {
+		memmove(&(CodeLine[CursorX+Count]), &(CodeLine[CursorX]), MoveLen);
+		memmove(&(AttrLine[CursorX+Count]), &(AttrLine[CursorX]), MoveLen);
+		memmove(&(AttrLine2[CursorX+Count]), &(AttrLine2[CursorX]), MoveLen);
+		memmove(&(AttrLineFG[CursorX+Count]), &(AttrLineFG[CursorX]), MoveLen);
+		memmove(&(AttrLineBG[CursorX+Count]), &(AttrLineBG[CursorX]), MoveLen);
 	}
-
-	memmove(&(CodeLine[CursorX+Count]),&(CodeLine[CursorX]),
-	        NumOfColumns-Count-CursorX);
-	memmove(&(AttrLine[CursorX+Count]),&(AttrLine[CursorX]),
-	        NumOfColumns-Count-CursorX);
-	memmove(&(AttrLine2[CursorX+Count]),&(AttrLine2[CursorX]),
-	        NumOfColumns-Count-CursorX);
-	memmove(&(AttrLineFG[CursorX+Count]),&(AttrLineFG[CursorX]),
-	        NumOfColumns-Count-CursorX);
-	memmove(&(AttrLineBG[CursorX+Count]),&(AttrLineBG[CursorX]),
-	        NumOfColumns-Count-CursorX);
-	memset(&(CodeLine[CursorX]),0x20,Count);
-	memset(&(AttrLine[CursorX]),AttrDefault,Count);
-	memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2 & Attr2ColorMask, Count);
-	memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
-	memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
+	memset(&(CodeLine[CursorX]), 0x20, Count);
+	memset(&(AttrLine[CursorX]), AttrDefault, Count);
+	memset(&(AttrLine2[CursorX]), CurCharAttr.Attr2 & Attr2ColorMask, Count);
+	memset(&(AttrLineFG[CursorX]), CurCharAttr.Fore, Count);
+	memset(&(AttrLineBG[CursorX]), CurCharAttr.Back, Count);
 	/* last char in current line is kanji first? */
-	if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+	if ((AttrLine[LineEnd] & AttrKanji) != 0) {
 		/* then delete it */
-		CodeLine[NumOfColumns-1] = 0x20;
-		AttrLine[NumOfColumns-1] = AttrDefault;
-		AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-		AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-		AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+		CodeLine[LineEnd] = 0x20;
+		AttrLine[LineEnd] = AttrDefault;
+		AttrLine2[LineEnd] = CurCharAttr.Attr2;
+		AttrLineFG[LineEnd] = CurCharAttr.Fore;
+		AttrLineBG[LineEnd] = CurCharAttr.Back;
 	}
-	BuffUpdateRect(CursorX,CursorY,NumOfColumns-1,CursorY);
+	BuffUpdateRect(CursorX, CursorY, LineEnd, CursorY);
 }
 
 void BuffEraseCurToEnd()
@@ -610,8 +616,7 @@
 	offset = CursorX;
 	TmpPtr = GetLinePtr(PageStart+CursorY);
 	YEnd = NumOfLines-1;
-	if ((StatusLine>0) &&
-		(CursorY<NumOfLines-1)) {
+	if (StatusLine && !isCursorOnStatusLine) {
 		YEnd--;
 	}
 	for (i = CursorY ; i <= YEnd ; i++) {
@@ -639,7 +644,7 @@
 		EraseKanji(0); /* if cursor is on left half of a kanji, erase the kanji */
 	}
 	offset = NumOfColumns;
-	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+	if (isCursorOnStatusLine) {
 		YHome = CursorY;
 	}
 	else {
@@ -667,33 +672,34 @@
 //   Count: number of lines to be inserted
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
-	int i;
+	int i, linelen;
 	LONG SrcPtr, DestPtr;
 
 	BuffUpdateScroll();
 
-	SrcPtr = GetLinePtr(PageStart+YEnd-Count);
-	DestPtr = GetLinePtr(PageStart+YEnd);
+	SrcPtr = GetLinePtr(PageStart+YEnd-Count) + CursorLeftM;
+	DestPtr = GetLinePtr(PageStart+YEnd) + CursorLeftM;
+	linelen = CursorRightM - CursorLeftM + 1;
 	for (i= YEnd-Count ; i>=CursorY ; i--) {
-		memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+		memcpy(&(CodeBuff[DestPtr]), &(CodeBuff[SrcPtr]), linelen);
+		memcpy(&(AttrBuff[DestPtr]), &(AttrBuff[SrcPtr]), linelen);
+		memcpy(&(AttrBuff2[DestPtr]), &(AttrBuff2[SrcPtr]), linelen);
+		memcpy(&(AttrBuffFG[DestPtr]), &(AttrBuffFG[SrcPtr]), linelen);
+		memcpy(&(AttrBuffBG[DestPtr]), &(AttrBuffBG[SrcPtr]), linelen);
 		SrcPtr = PrevLinePtr(SrcPtr);
 		DestPtr = PrevLinePtr(DestPtr);
 	}
 	for (i = 1 ; i <= Count ; i++) {
-		memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-		memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-		memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
-		memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-		memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+		memset(&(CodeBuff[DestPtr]), 0x20, linelen);
+		memset(&(AttrBuff[DestPtr]), AttrDefault, linelen);
+		memset(&(AttrBuff2[DestPtr]), CurCharAttr.Attr2 & Attr2ColorMask, linelen);
+		memset(&(AttrBuffFG[DestPtr]), CurCharAttr.Fore, linelen);
+		memset(&(AttrBuffBG[DestPtr]), CurCharAttr.Back, linelen);
 		DestPtr = PrevLinePtr(DestPtr);
 	}
 
-	if (! DispInsertLines(Count,YEnd)) {
-		BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1 || !DispInsertLines(Count, YEnd)) {
+		BuffUpdateRect(CursorLeftM, CursorY, CursorRightM, YEnd);
 	}
 }
 
@@ -741,33 +747,34 @@
 //   Count: number of lines to be deleted
 //   YEnd: bottom line number of scroll region (screen coordinate)
 {
-	int i;
+	int i, linelen;
 	LONG SrcPtr, DestPtr;
 
 	BuffUpdateScroll();
 
-	SrcPtr = GetLinePtr(PageStart+CursorY+Count);
-	DestPtr = GetLinePtr(PageStart+CursorY);
+	SrcPtr = GetLinePtr(PageStart+CursorY+Count) + (LONG)CursorLeftM;
+	DestPtr = GetLinePtr(PageStart+CursorY) + (LONG)CursorLeftM;
+	linelen = CursorRightM - CursorLeftM + 1;
 	for (i=CursorY ; i<= YEnd-Count ; i++) {
-		memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-		memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+		memcpy(&(CodeBuff[DestPtr]), &(CodeBuff[SrcPtr]), linelen);
+		memcpy(&(AttrBuff[DestPtr]), &(AttrBuff[SrcPtr]), linelen);
+		memcpy(&(AttrBuff2[DestPtr]), &(AttrBuff2[SrcPtr]), linelen);
+		memcpy(&(AttrBuffFG[DestPtr]), &(AttrBuffFG[SrcPtr]), linelen);
+		memcpy(&(AttrBuffBG[DestPtr]), &(AttrBuffBG[SrcPtr]), linelen);
 		SrcPtr = NextLinePtr(SrcPtr);
 		DestPtr = NextLinePtr(DestPtr);
 	}
 	for (i = YEnd+1-Count ; i<=YEnd ; i++) {
-		memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-		memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-		memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
-		memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-		memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+		memset(&(CodeBuff[DestPtr]), 0x20, linelen);
+		memset(&(AttrBuff[DestPtr]), AttrDefault, linelen);
+		memset(&(AttrBuff2[DestPtr]), CurCharAttr.Attr2 & Attr2ColorMask,  linelen);
+		memset(&(AttrBuffFG[DestPtr]), CurCharAttr.Fore, linelen);
+		memset(&(AttrBuffBG[DestPtr]), CurCharAttr.Back, linelen);
 		DestPtr = NextLinePtr(DestPtr);
 	}
 
-	if (! DispDeleteLines(Count,YEnd)) {
-		BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
+	if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1 || ! DispDeleteLines(Count,YEnd)) {
+		BuffUpdateRect(CursorLeftM, CursorY, CursorRightM, YEnd);
 	}
 }
 
@@ -1587,7 +1594,7 @@
 //   Attr: attributes
 //   Insert: Insert flag
 {
-	int XStart;
+	int XStart, LineEnd, MoveLen;
 
 #ifndef NO_COPYLINE_FIX
 	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
@@ -1603,24 +1610,32 @@
 	}
 
 	if (Insert) {
-		memmove(&CodeLine[CursorX+1],&CodeLine[CursorX],NumOfColumns-1-CursorX);
-		memmove(&AttrLine[CursorX+1],&AttrLine[CursorX],NumOfColumns-1-CursorX);
-		memmove(&AttrLine2[CursorX+1],&AttrLine2[CursorX],NumOfColumns-1-CursorX);
-		memmove(&AttrLineFG[CursorX+1],&AttrLineFG[CursorX],NumOfColumns-1-CursorX);
-		memmove(&AttrLineBG[CursorX+1],&AttrLineBG[CursorX],NumOfColumns-1-CursorX);
+		if (CursorX > CursorRightM)
+			LineEnd = NumOfColumns - 1;
+		else
+			LineEnd = CursorRightM;
+
+		MoveLen = LineEnd - CursorX;
+		if (MoveLen > 0) {
+			memmove(&CodeLine[CursorX+1], &CodeLine[CursorX], MoveLen);
+			memmove(&AttrLine[CursorX+1], &AttrLine[CursorX], MoveLen);
+			memmove(&AttrLine2[CursorX+1], &AttrLine2[CursorX], MoveLen);
+			memmove(&AttrLineFG[CursorX+1], &AttrLineFG[CursorX], MoveLen);
+			memmove(&AttrLineBG[CursorX+1], &AttrLineBG[CursorX], MoveLen);
+		}
 		CodeLine[CursorX] = b;
 		AttrLine[CursorX] = Attr.Attr;
 		AttrLine2[CursorX] = Attr.Attr2;
 		AttrLineFG[CursorX] = Attr.Fore;
 		AttrLineBG[CursorX] = Attr.Back;
 		/* last char in current line is kanji first? */
-		if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+		if ((AttrLine[LineEnd] & AttrKanji) != 0) {
 			/* then delete it */
-			CodeLine[NumOfColumns-1] = 0x20;
-			AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
-			AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-			AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-			AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+			CodeLine[LineEnd] = 0x20;
+			AttrLine[LineEnd] = CurCharAttr.Attr;
+			AttrLine2[LineEnd] = CurCharAttr.Attr2;
+			AttrLineFG[LineEnd] = CurCharAttr.Fore;
+			AttrLineBG[LineEnd] = CurCharAttr.Back;
 		}
 		/* begin - ishizaki */
 		markURL(CursorX+1);
@@ -1634,7 +1649,7 @@
 			XStart = StrChangeStart;
 		}
 		StrChangeCount = 0;
-		BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
+		BuffUpdateRect(XStart, CursorY, LineEnd, CursorY);
 	}
 	else {
 		CodeLine[CursorX] = b;
@@ -1659,7 +1674,7 @@
 //   Attr: attributes
 //   Insert: Insert flag
 {
-	int XStart;
+	int XStart, LineEnd, MoveLen;
 
 #ifndef NO_COPYLINE_FIX
 	if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
@@ -1670,18 +1685,26 @@
 	EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
 
 	if (Insert) {
-		memmove(&CodeLine[CursorX+2],&CodeLine[CursorX],NumOfColumns-2-CursorX);
-		memmove(&AttrLine[CursorX+2],&AttrLine[CursorX],NumOfColumns-2-CursorX);
-		memmove(&AttrLine2[CursorX+2],&AttrLine2[CursorX],NumOfColumns-2-CursorX);
-		memmove(&AttrLineFG[CursorX+2],&AttrLineFG[CursorX],NumOfColumns-2-CursorX);
-		memmove(&AttrLineBG[CursorX+2],&AttrLineBG[CursorX],NumOfColumns-2-CursorX);
+		if (CursorX > CursorRightM)
+			LineEnd = NumOfColumns - 1;
+		else
+			LineEnd = CursorRightM;
 
+		MoveLen = LineEnd - CursorX - 1;
+		if (MoveLen > 0) {
+			memmove(&CodeLine[CursorX+2], &CodeLine[CursorX], MoveLen);
+			memmove(&AttrLine[CursorX+2], &AttrLine[CursorX], MoveLen);
+			memmove(&AttrLine2[CursorX+2], &AttrLine2[CursorX], MoveLen);
+			memmove(&AttrLineFG[CursorX+2], &AttrLineFG[CursorX], MoveLen);
+			memmove(&AttrLineBG[CursorX+2], &AttrLineBG[CursorX], MoveLen);
+		}
+
 		CodeLine[CursorX] = HIBYTE(w);
 		AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
 		AttrLine2[CursorX] = Attr.Attr2;
 		AttrLineFG[CursorX] = Attr.Fore;
 		AttrLineBG[CursorX] = Attr.Back;
-		if (CursorX < NumOfColumns-1) {
+		if (CursorX < LineEnd) {
 			CodeLine[CursorX+1] = LOBYTE(w);
 			AttrLine[CursorX+1] = Attr.Attr;
 			AttrLine2[CursorX+1] = Attr.Attr2;
@@ -1694,13 +1717,13 @@
 		/* end - ishizaki */
 
 		/* last char in current line is kanji first? */
-		if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
+		if ((AttrLine[LineEnd] & AttrKanji) != 0) {
 			/* then delete it */
-			CodeLine[NumOfColumns-1] = 0x20;
-			AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
-			AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
-			AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
-			AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
+			CodeLine[LineEnd] = 0x20;
+			AttrLine[LineEnd] = CurCharAttr.Attr;
+			AttrLine2[LineEnd] = CurCharAttr.Attr2;
+			AttrLineFG[LineEnd] = CurCharAttr.Fore;
+			AttrLineBG[LineEnd] = CurCharAttr.Back;
 		}
 
 		if (StrChangeCount==0) {
@@ -1710,7 +1733,7 @@
 			XStart = StrChangeStart;
 		}
 		StrChangeCount = 0;
-		BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
+		BuffUpdateRect(XStart, CursorY, LineEnd, CursorY);
 	}
 	else {
 		CodeLine[CursorX] = HIBYTE(w);
@@ -1977,35 +2000,39 @@
 
 void ScrollUp1Line()
 {
-	int i;
+	int i, linelen;
 	LONG SrcPtr, DestPtr;
 
 	if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
 		UpdateStr();
 
-		DestPtr = GetLinePtr(PageStart+CursorBottom);
+		linelen = CursorRightM - CursorLeftM + 1;
+		DestPtr = GetLinePtr(PageStart+CursorBottom) + CursorLeftM;
 		for (i = CursorBottom-1 ; i >= CursorTop ; i--) {
 			SrcPtr = PrevLinePtr(DestPtr);
-			memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-			memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-			memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-			memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-			memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+			memcpy(&(CodeBuff[DestPtr]), &(CodeBuff[SrcPtr]), linelen);
+			memcpy(&(AttrBuff[DestPtr]), &(AttrBuff[SrcPtr]), linelen);
+			memcpy(&(AttrBuff2[DestPtr]), &(AttrBuff2[SrcPtr]), linelen);
+			memcpy(&(AttrBuffFG[DestPtr]), &(AttrBuffFG[SrcPtr]), linelen);
+			memcpy(&(AttrBuffBG[DestPtr]), &(AttrBuffBG[SrcPtr]), linelen);
 			DestPtr = SrcPtr;
 		}
-		memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
-		memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
-		memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
-		memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
-		memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
+		memset(&(CodeBuff[SrcPtr]), 0x20, linelen);
+		memset(&(AttrBuff[SrcPtr]), AttrDefault, linelen);
+		memset(&(AttrBuff2[SrcPtr]), CurCharAttr.Attr2 & Attr2ColorMask, linelen);
+		memset(&(AttrBuffFG[SrcPtr]), CurCharAttr.Fore, linelen);
+		memset(&(AttrBuffBG[SrcPtr]), CurCharAttr.Back, linelen);
 
-		DispScrollNLines(CursorTop,CursorBottom,-1);
+		if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1)
+			BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+		else
+			DispScrollNLines(CursorTop, CursorBottom, -1);
 	}
 }
 
 void BuffScrollNLines(int n)
 {
-	int i;
+	int i, linelen;
 	LONG SrcPtr, DestPtr;
 
 	if (n<1) {
@@ -2013,38 +2040,44 @@
 	}
 	UpdateStr();
 
-	if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
-		WinOrgY = WinOrgY-n;
-		/* \x8Dʼn\xBA\x8Ds\x82ł\xBE\x82\xAF\x8E\xA9\x93\xAE\x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB7\x82\xE9 */
-		if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
-			NewOrgY = WinOrgY;
-		}
-		BuffScroll(n,CursorBottom);
-		DispCountScroll(n);
-	}
-	else if ((CursorTop==0) && (CursorY<=CursorBottom)) {
-		/* \x8Dʼn\xBA\x8Ds\x82ł\xBE\x82\xAF\x8E\xA9\x93\xAE\x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB7\x82\xE9 */
-		if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
-			/* \x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB3\x82\xB9\x82Ȃ\xA2\x8Fꍇ\x82̏\x88\x97\x9D */
+	if (CursorLeftM == 0 && CursorRightM == NumOfColumns-1 && CursorTop == 0) {
+		if (CursorBottom == NumOfLines-1) {
 			WinOrgY = WinOrgY-n;
-			NewOrgY = WinOrgY;
+			/* \x8Dʼn\xBA\x8Ds\x82ł\xBE\x82\xAF\x8E\xA9\x93\xAE\x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB7\x82\xE9 */
+			if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
+				NewOrgY = WinOrgY;
+			}
 			BuffScroll(n,CursorBottom);
 			DispCountScroll(n);
-		} else {
-			BuffScroll(n,CursorBottom);
-			DispScrollNLines(WinOrgY,CursorBottom,n);
+			return;
 		}
+		else if (CursorY <= CursorBottom) {
+			/* \x8Dʼn\xBA\x8Ds\x82ł\xBE\x82\xAF\x8E\xA9\x93\xAE\x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB7\x82\xE9 */
+			if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
+				/* \x83X\x83N\x83\x8D\x81[\x83\x8B\x82\xB3\x82\xB9\x82Ȃ\xA2\x8Fꍇ\x82̏\x88\x97\x9D */
+				WinOrgY = WinOrgY-n;
+				NewOrgY = WinOrgY;
+				BuffScroll(n,CursorBottom);
+				DispCountScroll(n);
+			} else {
+				BuffScroll(n,CursorBottom);
+				DispScrollNLines(WinOrgY,CursorBottom,n);
+			}
+			return;
+		}
 	}
-	else if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
-		DestPtr = GetLinePtr(PageStart+CursorTop);
+
+	if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
+		linelen = CursorRightM - CursorLeftM + 1;
+		DestPtr = GetLinePtr(PageStart+CursorTop) + (LONG)CursorLeftM;
 		if (n<CursorBottom-CursorTop+1) {
-			SrcPtr = GetLinePtr(PageStart+CursorTop+n);
+			SrcPtr = GetLinePtr(PageStart+CursorTop+n) + (LONG)CursorLeftM;
 			for (i = CursorTop+n ; i<=CursorBottom ; i++) {
-				memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
-				memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
-				memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
-				memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
-				memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
+				memmove(&(CodeBuff[DestPtr]), &(CodeBuff[SrcPtr]), linelen);
+				memmove(&(AttrBuff[DestPtr]), &(AttrBuff[SrcPtr]), linelen);
+				memmove(&(AttrBuff2[DestPtr]), &(AttrBuff2[SrcPtr]), linelen);
+				memmove(&(AttrBuffFG[DestPtr]), &(AttrBuffFG[SrcPtr]), linelen);
+				memmove(&(AttrBuffBG[DestPtr]), &(AttrBuffBG[SrcPtr]), linelen);
 				SrcPtr = NextLinePtr(SrcPtr);
 				DestPtr = NextLinePtr(DestPtr);
 			}
@@ -2053,14 +2086,17 @@
 			n = CursorBottom-CursorTop+1;
 		}
 		for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
-			memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
-			memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
-			memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
-			memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
-			memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
+			memset(&(CodeBuff[DestPtr]), 0x20, linelen);
+			memset(&(AttrBuff[DestPtr]), AttrDefault, linelen);
+			memset(&(AttrBuff2[DestPtr]), CurCharAttr.Attr2 & Attr2ColorMask, linelen);
+			memset(&(AttrBuffFG[DestPtr]), CurCharAttr.Fore, linelen);
+			memset(&(AttrBuffBG[DestPtr]), CurCharAttr.Back, linelen);
 			DestPtr = NextLinePtr(DestPtr);
 		}
-		DispScrollNLines(CursorTop,CursorBottom,n);
+		if (CursorLeftM > 0 || CursorRightM < NumOfColumns-1)
+			BuffUpdateRect(CursorLeftM, CursorTop, CursorRightM, CursorBottom);
+		else
+			DispScrollNLines(CursorTop, CursorBottom, n);
 	}
 }
 
@@ -2152,7 +2188,7 @@
 
 void BuffClearScreen()
 { // clear screen
-	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+	if (isCursorOnStatusLine) {
 		BuffScrollNLines(1); /* clear status line */
 	}
 	else { /* clear main screen */
@@ -2970,7 +3006,7 @@
 		Ny = ts.ScrollBuffMax;
 	}
 
-	St = ((StatusLine>0) && (CursorY==NumOfLines-1));
+	St = isCursorOnStatusLine;
 	if ((Nx!=NumOfColumns) || (Ny!=NumOfLines)) {
 		if ((ts.ScrollBuffSize < Ny) ||
 		    (ts.EnableScrollBuff==0)) {
@@ -3023,7 +3059,7 @@
 
 	/* Set Cursor */
 	if (ts.TermFlag & TF_CLEARONRESIZE) {
-		CursorX = 0;
+		CursorRightM = NumOfColumns-1;
 		if (St) {
 			CursorY = NumOfLines-1;
 			CursorTop = CursorY;
@@ -3036,6 +3072,8 @@
 		}
 	}
 	else {
+		CursorLeftM = 0;
+		CursorRightM = NumOfColumns-1;
 		if (CursorX >= NumOfColumns) {
 			CursorX = NumOfColumns - 1;
 		}
@@ -3052,6 +3090,8 @@
 			CursorBottom = NumOfLines - 1 - StatusLine;
 		}
 	}
+	CursorX = 0;
+	CursorLeftM = 0;
 
 	SelectStart.x = 0;
 	SelectStart.y = 0;
@@ -3166,7 +3206,9 @@
 
 	/* Top/bottom margin */
 	CursorTop = 0;
-	CursorBottom = NumOfLines-1;
+	CursorBottom = NumOfLines - 1;
+	CursorLeftM = 0;
+	CursorRightM = NumOfColumns - 1;
 
 	StrChangeCount = 0;
 
@@ -3470,8 +3512,7 @@
 	offset = CursorX;
 	TmpPtr = GetLinePtr(PageStart+CursorY);
 	YEnd = NumOfLines-1;
-	if ((StatusLine>0) &&
-		(CursorY<NumOfLines-1)) {
+	if (StatusLine && !isCursorOnStatusLine) {
 		YEnd--;
 	}
 	for (i = CursorY ; i <= YEnd ; i++) {
@@ -3502,7 +3543,7 @@
 		}
 	}
 	offset = NumOfColumns;
-	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+	if (isCursorOnStatusLine) {
 		YHome = CursorY;
 	}
 	else {

Modified: trunk/teraterm/teraterm/buffer.h
===================================================================
--- trunk/teraterm/teraterm/buffer.h	2013-06-17 11:56:58 UTC (rev 5323)
+++ trunk/teraterm/teraterm/buffer.h	2013-06-17 12:14:30 UTC (rev 5324)
@@ -85,10 +85,12 @@
 BOOL BuffCheckMouseOnURL(int Xw, int Yw);
 
 extern int StatusLine;
-extern int CursorTop, CursorBottom;
+extern int CursorTop, CursorBottom, CursorLeftM, CursorRightM;
 extern BOOL Selected;
 extern BOOL Wrap;
 
+#define isCursorOnStatusLine (StatusLine && CursorY == NumOfColumns-1)
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/teraterm/vtterm.c
===================================================================
--- trunk/teraterm/teraterm/vtterm.c	2013-06-17 11:56:58 UTC (rev 5323)
+++ trunk/teraterm/teraterm/vtterm.c	2013-06-17 12:14:30 UTC (rev 5324)
@@ -69,6 +69,7 @@
 static BOOL AutoWrapMode;
 static BOOL FocusReportMode;
 static BOOL AltScr;
+static BOOL LRMarginMode;
 BOOL BracketedPaste;
 
 static int VTlevel;
@@ -290,6 +291,9 @@
   // Alternate Screen Buffer
   AltScr = FALSE;
 
+  // Left/Right Margin Mode
+  LRMarginMode = FALSE;
+
   // Bracketed Paste Mode
   BracketedPaste = FALSE;
 
@@ -387,8 +391,7 @@
 
 void HideStatusLine()
 {
-  if ((StatusLine>0) &&
-      (CursorY==NumOfLines-1))
+  if (isCursorOnStatusLine)
     MoveToMainScreen();
   StatusX = 0;
   StatusWrap = FALSE;
@@ -481,24 +484,16 @@
 
 void BackSpace()
 {
-  if (CursorX == 0)
-  {
-    if ((CursorY>0) &&
-	((ts.TermFlag & TF_BACKWRAP)!=0))
-    {
-      MoveCursor(NumOfColumns-1,CursorY-1);
-//      if (cv.HLogBuf!=0) Log1Byte(BS);
-// (2005.2.20 yutaka)
-	  if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
-    }
-  }
-  else if (CursorX > 0)
-  {
-    MoveCursor(CursorX-1,CursorY);
-//    if (cv.HLogBuf!=0) Log1Byte(BS);
-// (2005.2.20 yutaka)
-	  if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
-  }
+	if (CursorX == CursorLeftM || CursorX == 0) {
+		if (CursorY > 0 && (ts.TermFlag & TF_BACKWRAP)) {
+			MoveCursor(CursorRightM, CursorY-1);
+			if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
+		}
+	}
+	else if (CursorX > 0) {
+		MoveCursor(CursorX-1, CursorY);
+		if (cv.HLogBuf!=0 && !ts.LogTypePlainText) Log1Byte(BS);
+	}
 }
 
 void CarriageReturn(BOOL logFlag)
@@ -508,8 +503,10 @@
 #endif /* NO_COPYLINE_FIX */
         if (cv.HLogBuf!=0) Log1Byte(CR);
 
-	if (CursorX>0)
-		MoveCursor(0,CursorY);
+	if (RelativeOrgMode || CursorX > CursorLeftM)
+		MoveCursor(CursorLeftM, CursorY);
+	else if (CursorX < CursorLeftM)
+		MoveCursor(0, CursorY);
 }
 
 void LineFeed(BYTE b, BOOL logFlag)
@@ -620,12 +617,13 @@
 
   BuffPutChar(b, CharAttrTmp, InsertMode);
 
-  if (CursorX < NumOfColumns-1)
-    MoveRight();
-  else {
+  if (CursorX == CursorRightM || CursorX >= NumOfColumns-1) {
     UpdateStr();
     Wrap = AutoWrapMode;
   }
+  else {
+    MoveRight();
+  }
 }
 
 void PutDecSp(BYTE b)
@@ -666,16 +664,18 @@
   CharAttrTmp.Attr |= AttrSpecial;
   BuffPutChar(b, CharAttrTmp, InsertMode);
 
-  if (CursorX < NumOfColumns-1)
-    MoveRight();
-  else {
+  if (CursorX == CursorRightM || CursorX >= NumOfColumns-1) {
     UpdateStr();
     Wrap = AutoWrapMode;
   }
+  else {
+    MoveRight();
+  }
 }
 
 void PutKanji(BYTE b)
 {
+  int LineEnd;
 #ifndef NO_COPYLINE_FIX
   TCharAttr CharAttrTmp;
 
@@ -699,6 +699,11 @@
     return;
   }
 
+  if (CursorX > CursorRightM)
+    LineEnd = NumOfColumns - 1;
+  else
+    LineEnd = CursorRightM;
+
   if (Wrap)
   {
     CarriageReturn(FALSE);
@@ -708,21 +713,24 @@
       CharAttrTmp.Attr |= AttrLineContinued;
 #endif /* NO_COPYLINE_FIX */
   }
-  else if (CursorX > NumOfColumns-2)
+  else if (CursorX > LineEnd - 1) {
     if (AutoWrapMode)
     {
 #ifndef NO_COPYLINE_FIX
       if (ts.EnableContinuedLineCopy)
       {
       CharAttrTmp.Attr |= AttrLineContinued;
-      if (CursorX == NumOfColumns-1)
+      if (CursorX == LineEnd)
 	BuffPutChar(0x20, CharAttr, FALSE);
       }
 #endif /* NO_COPYLINE_FIX */
       CarriageReturn(FALSE);
       LineFeed(LF,FALSE);
     }
-    else return;
+    else {
+      return;
+    }
+  }
 
   Wrap = FALSE;
 
@@ -744,8 +752,7 @@
   BuffPutKanji(Kanji, CharAttr, InsertMode);
 #endif /* NO_COPYLINE_FIX */
 
-  if (CursorX < NumOfColumns-2)
-  {
+  if (CursorX < LineEnd - 1) {
     MoveRight();
     MoveRight();
   }
@@ -1032,8 +1039,7 @@
   int i;
   PStatusBuff Buff;
 
-  if ((StatusLine>0) &&
-      (CursorY==NumOfLines-1))
+  if (isCursorOnStatusLine)
     Buff = &SBuff2; // for status line
   else if (AltScr) 
     Buff = &SBuff3; // for alternate screen
@@ -1057,8 +1063,7 @@
   PStatusBuff Buff;
   UpdateStr();
 
-  if ((StatusLine>0) &&
-      (CursorY==NumOfLines-1))
+  if (isCursorOnStatusLine)
     Buff = &SBuff2; // for status line
   else if (AltScr) 
     Buff = &SBuff3; // for alternate screen
@@ -1153,6 +1158,8 @@
       BuffFillWithE();
       CursorTop = 0;
       CursorBottom = NumOfLines-1-StatusLine;
+      CursorLeftM = 0;
+      CursorRightM = NumOfColumns - 1;
       MoveCursor(0,0);
       ParseMode = ModeFirst;
       break;
@@ -1465,7 +1472,7 @@
 
   void CSCursorUp1()
   {
-    MoveCursor(0,CursorY);
+    MoveCursor(CursorLeftM, CursorY);
     CSCursorUp();
   }
 
@@ -1490,7 +1497,7 @@
 
   void CSCursorDown1()
   {
-    MoveCursor(0,CursorY);
+    MoveCursor(CursorLeftM, CursorY);
     CSCursorDown();
   }
 
@@ -1636,7 +1643,7 @@
     BuffEraseChars(Param[1]);
   }
 
-  void CSScrollUP()
+  void CSScrollUp()
   {
     if (Param[1]<1) Param[1] = 1;
     BuffUpdateScroll();
@@ -1662,32 +1669,63 @@
     CursorBackwardTab(Param[1]);
   }
 
-  void CSMoveToColumnN()
-  {
-    if (Param[1]<1) Param[1] = 1;
-    Param[1]--;
-    if (Param[1] > NumOfColumns-1) Param[1] = NumOfColumns-1;
-    MoveCursor(Param[1],CursorY);
-  }
+void CSMoveToColumnN()		// CHA / HPA
+{
+	if (Param[1]<1)
+		Param[1] = 1;
+	else if (Param[1] > NumOfColumns-1)
+		Param[1] = NumOfColumns-1;
 
-  void CSCursorRight()
-  {
-    if (Param[1]<1) Param[1] = 1;
-    if (CursorX + Param[1] > NumOfColumns-1)
-      MoveCursor(NumOfColumns-1,CursorY);
-    else
-      MoveCursor(CursorX+Param[1],CursorY);
-  }
+	Param[1]--;
 
-  void CSCursorLeft()
-  {
-    if (Param[1]<1) Param[1] = 1;
-    if (CursorX-Param[1] < 0)
-      MoveCursor(0,CursorY);
-    else
-      MoveCursor(CursorX-Param[1],CursorY);
-  }
+	if (RelativeOrgMode) {
+		if (CursorLeftM + Param[1] > CursorRightM )
+			MoveCursor(CursorRightM, CursorY);
+		else
+			MoveCursor(CursorLeftM + Param[1], CursorY);
+	}
+	else {
+		MoveCursor(Param[1], CursorY);
+	}
+}
 
+void CSCursorRight()		// CUF / HPR
+{
+	int NewX;
+
+	if (Param[1] < 1)
+		Param[1] = 1;
+	else if (Param[1] > NumOfColumns - 1)
+		Param[1] = NumOfColumns - 1;
+
+	NewX = CursorX + Param[1];
+
+	if (CursorX <= CursorRightM && NewX > CursorRightM)
+		NewX = CursorRightM;
+	else if (NewX > NumOfColumns-1)
+		NewX = NumOfColumns-1;
+
+	MoveCursor(NewX, CursorY);
+}
+
+void CSCursorLeft()		// CUB / HPB
+{
+	int NewX;
+
+	if (Param[1] < 1)
+		Param[1] = 1;
+
+	if (CursorX < Param[1])
+		NewX = 0;
+	else
+		NewX = CursorX - Param[1];
+
+	if (CursorX >= CursorLeftM && NewX < CursorLeftM)
+		NewX = CursorLeftM;
+
+	MoveCursor(NewX, CursorY);
+}
+
   void CSMoveToLineN()
   {
     if (Param[1]<1) Param[1] = 1;
@@ -1706,30 +1744,43 @@
     }
   }
 
-  void CSMoveToXY()
-  {
-    int NewX, NewY;
+void CSMoveToXY()		// CUP / HVP
+{
+	int NewX, NewY;
 
-    if (Param[1]<1) Param[1] = 1;
-    if ((NParam < 2) || (Param[2]<1)) Param[2] = 1;
-    NewX = Param[2] - 1;
-    if (NewX > NumOfColumns-1) NewX = NumOfColumns-1;
+	if (Param[1] < 1)
+		Param[1] = 1;
+	else if (Param[1] > NumOfLines-StatusLine)
+		Param[1] = NumOfLines-StatusLine;
 
-    if ((StatusLine>0) && (CursorY==NumOfLines-1))
-      NewY = CursorY;
-    else if (RelativeOrgMode)
-    {
-      NewY = CursorTop + Param[1] - 1;
-      if (NewY > CursorBottom) NewY = CursorBottom;
-    }
-    else {
-      NewY = Param[1] - 1;
-      if (NewY > NumOfLines-1-StatusLine)
-	NewY = NumOfLines-1-StatusLine;
-    }
-    MoveCursor(NewX,NewY);
-  }
+	if ((NParam < 2) || (Param[2]<1))
+		Param[2] = 1;
+	else if (Param[2] > NumOfColumns)
+		Param[2] = NumOfColumns;
 
+	NewY = Param[1] - 1;
+	NewX = Param[2] - 1;
+
+	if (isCursorOnStatusLine)
+		NewY = CursorY;
+	else if (RelativeOrgMode) {
+		NewX += CursorLeftM;
+		if (NewX > CursorRightM)
+			NewX = CursorRightM;
+
+		NewY += CursorTop;
+		if (NewY > CursorBottom)
+			NewY = CursorBottom;
+	}
+	else {
+		NewY = Param[1] - 1;
+		if (NewY > NumOfLines-1-StatusLine)
+			NewY = NumOfLines-1-StatusLine;
+	}
+
+	MoveCursor(NewX, NewY);
+}
+
   void CSDeleteTabStop()
   {
     ClearTabStop(Param[1]);
@@ -1836,10 +1887,10 @@
 	break;
       case 6:
 	/* Cursor Position Report */
-	Y = CursorY+1;
-	if ((StatusLine>0) &&
-	    (Y==NumOfLines))
+	if (isCursorOnStatusLine)
 	  Y = 1;
+	else
+	  Y = CursorY+1;
 	len = _snprintf_s_l(Report, sizeof(Report), _TRUNCATE, "%u;%uR", CLocale, Y, CursorX+1);
 	SendCSIstr(Report, len);
 	break;
@@ -2135,9 +2186,7 @@
 
   void CSSetScrollRegion()
   {
-    if ((StatusLine>0) &&
-	(CursorY==NumOfLines-1))
-    {
+    if (isCursorOnStatusLine) {
       MoveCursor(0,CursorY);
       return;
     }
@@ -2157,6 +2206,36 @@
 		    else MoveCursor(0,0);
   }
 
+void CSSetLRScrollRegion()
+{
+//	if (isCursorOnStatusLine) {
+//		MoveCursor(0,CursorY);
+//		return;
+//	}
+
+	if (Param[1] < 1)
+		Param[1] =1;
+	else if (Param[1] > NumOfColumns)
+		Param[1] = NumOfColumns;
+
+	if (NParam < 2 || Param[2] < 1 || Param[2] > NumOfColumns)
+		Param[2] = NumOfColumns;
+
+	if (Param[1] >= Param[2])
+		return;
+
+	Param[1]--;
+	Param[2]--;
+
+	CursorLeftM = Param[1];
+	CursorRightM = Param[2];
+
+	if (RelativeOrgMode)
+		MoveCursor(CursorLeftM, CursorTop);
+	else
+		MoveCursor(0, 0);
+}
+
   void CSSunSequence() /* Sun terminal private sequences */
   {
     int x, y, len;
@@ -2509,7 +2588,7 @@
 	      CSQExchangeColor(); /* Exchange text/back color */
 	    break;
 	  case 6: // DECOM
-	    if ((StatusLine>0) && (CursorY==NumOfLines-1))
+	    if (isCursorOnStatusLine)
 	      MoveCursor(0,CursorY);
 	    else {
 	      RelativeOrgMode = TRUE;
@@ -2557,6 +2636,7 @@
 	    break;
 	  case 66: AppliKeyMode = TRUE; break;		// DECNKM
 	  case 67: ts.BSKey = IdBS; break;		// DECBKM
+	  case 69: LRMarginMode = TRUE; break;		// DECLRMM (DECVSSM)
 	  case 1000: // Mouse Tracking
 	    if (ts.MouseEventTracking)
 	      MouseReportMode = IdMouseTrackVT200;
@@ -2671,7 +2751,7 @@
 	      CSQExchangeColor(); /* Exchange text/back color */
 	    break;
 	  case 6: // DECOM
-	    if ((StatusLine>0) && (CursorY==NumOfLines-1))
+	    if (isCursorOnStatusLine)
 	      MoveCursor(0,CursorY);
 	    else {
 	      RelativeOrgMode = FALSE;
@@ -2712,6 +2792,11 @@
 	    break;
 	  case 66: AppliKeyMode = FALSE; break;		// DECNKM
 	  case 67: ts.BSKey = IdDEL; break;		// DECBKM
+	  case 69: // DECLRMM (DECVSSM)
+	    LRMarginMode = FALSE;
+	    CursorLeftM = 0;
+	    CursorRightM = NumOfColumns - 1;
+	    break;
 	  case 1000: // Mouse Tracking
 	  case 1001: // Hilite Mouse Tracking
 	  case 1002: // Button-Event Mouse Tracking
@@ -2796,11 +2881,12 @@
     AppliCursorMode = FALSE;
     AppliEscapeMode = FALSE;
     AcceptWheelToCursor = ts.TranslateWheelToCursor;
-    if ((StatusLine>0) &&
-	(CursorY == NumOfLines-1))
+    if (isCursorOnStatusLine)
       MoveToMainScreen();
     CursorTop = 0;
     CursorBottom = NumOfLines-1-StatusLine;
+    CursorLeftM = 0;
+    CursorRightM = NumOfColumns - 1;
     ResetCharSet();
 
     /* Attribute */
@@ -3486,7 +3572,7 @@
 			  case 'P': CSDeleteCharacter(); break;   // DCH
 //			  case 'Q': break;                        // SEE  -- Not support
 //			  case 'R': break;                        // CPR  -- Report only, ignore.
-			  case 'S': CSScrollUP(); break;          // SU
+			  case 'S': CSScrollUp(); break;          // SU
 			  case 'T': CSScrollDown(); break;        // SD
 //			  case 'U': break;                        // NP   -- Not support
 //			  case 'V': break;                        // PP   -- Not support
@@ -3517,7 +3603,12 @@
 
 			// Private Sequence
 			  case 'r': CSSetScrollRegion(); break;   // DECSTBM
-			  case 's': SaveCursor(); break;          // SCP (Save cursor (ANSI.SYS/SCO?))
+			  case 's':
+			    if (LRMarginMode)
+			      CSSetLRScrollRegion();              // DECSLRM
+			    else
+			      SaveCursor();                       // SCP (Save cursor (ANSI.SYS/SCO?))
+			    break;
 			  case 't': CSSunSequence(); break;       // DECSLPP / Window manipulation(dtterm?)
 			  case 'u': RestoreCursor(); break;       // RCP (Restore cursor (ANSI.SYS/SCO))
 			}

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2013-06-17 11:56:58 UTC (rev 5323)
+++ trunk/teraterm/teraterm/vtwin.cpp	2013-06-17 12:14:30 UTC (rev 5324)
@@ -4147,7 +4147,7 @@
 {
 	LockBuffer();
 	BuffClearScreen();
-	if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
+	if (isCursorOnStatusLine) {
 		MoveCursor(0,CursorY);
 	}
 	else {



Ttssh2-commit メーリングリストの案内