Subject: port-mac68k/4482: ite console driver a bit buggy
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 11/13/1997 04:09:38
>Number:         4482
>Category:       port-mac68k
>Synopsis:       ite console driver a bit buggy
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 13 02:20:03 1997
>Last-Modified:
>Originator:     Dave Huang
>Organization:
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet: khym@bga.com   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 22 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release:        NetBSD-1.3_ALPHA as of November 12, 1997
>Environment:
	
System: NetBSD dahan.metonymy.com 1.3_ALPHA NetBSD 1.3_ALPHA (SPIFF) #160: Sun Nov 9 01:36:40 CST 1997 khym@dahan.metonymy.com:/usr/src.local/sys/arch/i386/compile/SPIFF i386


>Description:
	The Mac's console driver tries to emulate a vt100 or vt220,
but doesn't quite succeed. The major bug is that tab stops are broken;
they often tab to the end of the line, instead of to the next tab
stop. This patch fixes some minor bugs too:

     ^[0g should clear any tab stop at the current cursor position

     ^[3g should clear all tab stops

     ^[E should move the cursor to the next line, scrolling if necessary,
     then put the cursor in column 1.

     ^[[A should move the cursor up, but not scroll if trying to move out
     of the scrolling region.

     ^[[B should move the cursor down, but not scroll if trying to move out
     of the scrolling region.

     ^[[?;?f should be the same as ^[[?;?H (move the cursor to row, column)
>How-To-Repeat:
	% stty -oxtabs
	% printf 'a\tb\tc\n'
	a
	b
	c

	Then run the "vttest" program and watch it mangle the screen.
(src/sys/arch/i386/isa/pcvt/Utils/vttest). This patch still doesn't
let vttest run successfully, but it's a bit better :)
>Fix:
	ite_putchar(' ') will increment x, so the code that prints
spaces until the next tabstop is reached doesn't need to do it.

--- /usr/src/sys/arch/mac68k/dev/ite.c	Sat Sep  6 06:17:40 1997
+++ ite.c	Thu Nov 13 03:30:19 1997
@@ -103,6 +103,7 @@
 static void	clear_screen __P((int));
 static void	clear_line __P((int));
 static void	reset_tabs __P((void));
+static void	clear_tabs __P((void));
 static void	vt100_reset __P((void));
 static void	putc_normal __P((char));
 static void	putc_esc __P((char));
@@ -571,6 +572,15 @@
 }
 
 static void
+clear_tabs()
+{
+	int i;
+
+	for (i = 0; i <= scrcols; i++)
+		tab_stops[i] = 0;
+}
+
+static void
 vt100_reset()
 {
 	reset_tabs();
@@ -595,10 +605,9 @@
 			x--;
 		break;
 	case '\t':		/* Tab			 */
-		do {
+		do
 			ite_putchar(' ');
-			x++;
-		} while ((tab_stops[x] == 0) && (x < scrcols));
+		while ((tab_stops[x] == 0) && (x < scrcols));
 		break;
 	case '\n':		/* Line feed		 */
 		if (y == scrreg_bottom)
@@ -656,6 +665,9 @@
 	case ')':
 		vt100state = ESsetG1;
 		break;
+	case 'E':		/* Next line		 */
+		x = 0;
+		/* FALLTHROUGH */
 	case 'D':		/* Line feed		 */
 		if (y == scrreg_bottom)
 			scrollup();
@@ -697,24 +709,10 @@
 	vt100state = ESnormal;
 	switch (ch) {
 	case 'A':		/* Up			 */
-		i = par[0];
-		do {
-			if (y == scrreg_top)
-				scrolldown();
-			else
-				y--;
-			i--;
-		} while (i > 0);
+		y -= par[0] ? par[0] : 1;
 		break;
 	case 'B':		/* Down			 */
-		i = par[0];
-		do {
-			if (y == scrreg_bottom)
-				scrollup();
-			else
-				y++;
-			i--;
-		} while (i > 0);
+		y += par[0] ? par[0] : 1;
 		break;
 	case 'C':		/* Right		 */
 		x+= par[0] ? par[0] : 1;
@@ -723,6 +721,7 @@
 		x-= par[0] ? par[0] : 1;
 		break;
 	case 'H':		/* Set cursor position	 */
+	case 'f':		/* Set cursor position   */
 		x = par[1] - 1;
 		y = par[0] - 1;
 		hanging_cursor = 0;
@@ -752,8 +751,12 @@
 			clear_line(0);
 		break;
 	case 'g':		/* Clear tab stops	 */
-		if (numpars >= 1 && par[0] == 3)
-			reset_tabs();
+		if (numpars >= 1) {
+			if (par[0] == 3)
+				clear_tabs();
+			else if (par[0] == 0)
+				tab_stops[x] = 0;
+		}
 		break;
 	case 'm':		/* Set attribute	 */
 		for (i = 0; i < numpars; i++) {
>Audit-Trail:
>Unformatted: