Browse Source

Plan 9 from Bell Labs 2005-12-02

David du Colombier 15 years ago
parent
commit
7482bd9048

+ 7 - 7
dist/replica/_plan9.db

@@ -499,7 +499,7 @@
 386/bin/venti/write - 775 sys sys 1132506889 102575
 386/bin/vncs - 775 sys sys 1132506890 472364
 386/bin/vncv - 775 sys sys 1132506891 519422
-386/bin/vt - 775 sys sys 1132506891 174015
+386/bin/vt - 775 sys sys 1133468806 178593
 386/bin/vtdump - 775 sys sys 1132506892 159534
 386/bin/wc - 775 sys sys 1130384372 41174
 386/bin/webcookies - 775 sys sys 1133186787 161970
@@ -7943,7 +7943,7 @@ sys/src/9/pc/ether8139.c - 664 sys sys 1131290376 18400
 sys/src/9/pc/ether8169.c - 664 sys sys 1131290377 22723
 sys/src/9/pc/ether82543gc.c - 664 sys sys 1131290377 32294
 sys/src/9/pc/ether82557.c - 664 sys sys 1131290377 30107
-sys/src/9/pc/ether83815.c - 664 sys sys 1131287537 23542
+sys/src/9/pc/ether83815.c - 664 sys sys 1133464742 23556
 sys/src/9/pc/ether8390.c - 664 sys sys 1131290377 17702
 sys/src/9/pc/ether8390.h - 664 sys sys 1015014517 1511
 sys/src/9/pc/etherdp83820.c - 664 sys sys 1131290378 29128
@@ -13629,15 +13629,15 @@ sys/src/cmd/vnc/vncv.c - 664 sys sys 1082221235 3197
 sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
 sys/src/cmd/vnc/wsys.c - 664 sys sys 1102429521 4052
 sys/src/cmd/vt - 20000000775 sys sys 954038635 0
-sys/src/cmd/vt/cons.h - 664 sys sys 984718311 1660
+sys/src/cmd/vt/cons.h - 664 sys sys 1133463638 1776
 sys/src/cmd/vt/consctl.c - 664 sys sys 1127425716 1796
-sys/src/cmd/vt/event.c - 664 sys sys 1121977166 1071
+sys/src/cmd/vt/event.c - 664 sys sys 1133463638 1245
 sys/src/cmd/vt/event.h - 664 sys sys 944961620 192
-sys/src/cmd/vt/hp.c - 664 sys sys 984718311 3362
-sys/src/cmd/vt/main.c - 664 sys sys 988225296 14451
+sys/src/cmd/vt/hp.c - 664 sys sys 1133463638 3361
+sys/src/cmd/vt/main.c - 664 sys sys 1133463639 16737
 sys/src/cmd/vt/mkfile - 664 sys sys 944961620 159
 sys/src/cmd/vt/termcap - 664 sys sys 944961620 278
-sys/src/cmd/vt/vt.c - 664 sys sys 1014926857 16841
+sys/src/cmd/vt/vt.c - 664 sys sys 1133463639 20180
 sys/src/cmd/wc.c - 664 sys sys 984717764 12652
 sys/src/cmd/webcookies.c - 664 sys sys 1132449468 23687
 sys/src/cmd/webfs - 20000000775 sys sys 1015015823 0

+ 7 - 7
dist/replica/plan9.db

@@ -499,7 +499,7 @@
 386/bin/venti/write - 775 sys sys 1132506889 102575
 386/bin/vncs - 775 sys sys 1132506890 472364
 386/bin/vncv - 775 sys sys 1132506891 519422
-386/bin/vt - 775 sys sys 1132506891 174015
+386/bin/vt - 775 sys sys 1133468806 178593
 386/bin/vtdump - 775 sys sys 1132506892 159534
 386/bin/wc - 775 sys sys 1130384372 41174
 386/bin/webcookies - 775 sys sys 1133186787 161970
@@ -7943,7 +7943,7 @@ sys/src/9/pc/ether8139.c - 664 sys sys 1131290376 18400
 sys/src/9/pc/ether8169.c - 664 sys sys 1131290377 22723
 sys/src/9/pc/ether82543gc.c - 664 sys sys 1131290377 32294
 sys/src/9/pc/ether82557.c - 664 sys sys 1131290377 30107
-sys/src/9/pc/ether83815.c - 664 sys sys 1131287537 23542
+sys/src/9/pc/ether83815.c - 664 sys sys 1133464742 23556
 sys/src/9/pc/ether8390.c - 664 sys sys 1131290377 17702
 sys/src/9/pc/ether8390.h - 664 sys sys 1015014517 1511
 sys/src/9/pc/etherdp83820.c - 664 sys sys 1131290378 29128
@@ -13629,15 +13629,15 @@ sys/src/cmd/vnc/vncv.c - 664 sys sys 1082221235 3197
 sys/src/cmd/vnc/vncv.h - 664 sys sys 1044880750 643
 sys/src/cmd/vnc/wsys.c - 664 sys sys 1102429521 4052
 sys/src/cmd/vt - 20000000775 sys sys 954038635 0
-sys/src/cmd/vt/cons.h - 664 sys sys 984718311 1660
+sys/src/cmd/vt/cons.h - 664 sys sys 1133463638 1776
 sys/src/cmd/vt/consctl.c - 664 sys sys 1127425716 1796
-sys/src/cmd/vt/event.c - 664 sys sys 1121977166 1071
+sys/src/cmd/vt/event.c - 664 sys sys 1133463638 1245
 sys/src/cmd/vt/event.h - 664 sys sys 944961620 192
-sys/src/cmd/vt/hp.c - 664 sys sys 984718311 3362
-sys/src/cmd/vt/main.c - 664 sys sys 988225296 14451
+sys/src/cmd/vt/hp.c - 664 sys sys 1133463638 3361
+sys/src/cmd/vt/main.c - 664 sys sys 1133463639 16737
 sys/src/cmd/vt/mkfile - 664 sys sys 944961620 159
 sys/src/cmd/vt/termcap - 664 sys sys 944961620 278
-sys/src/cmd/vt/vt.c - 664 sys sys 1014926857 16841
+sys/src/cmd/vt/vt.c - 664 sys sys 1133463639 20180
 sys/src/cmd/wc.c - 664 sys sys 984717764 12652
 sys/src/cmd/webcookies.c - 664 sys sys 1132449468 23687
 sys/src/cmd/webfs - 20000000775 sys sys 1015015823 0

+ 7 - 0
dist/replica/plan9.log

@@ -23329,3 +23329,10 @@
 1133400704 6 c 386/9pcf - 775 sys sys 1133399412 2424539
 1133400704 7 c 386/9pcf.gz - 664 sys sys 1133399414 903461
 1133402504 0 c sys/games/lib/fortunes - 664 sys sys 1133400893 256649
+1133463719 0 c sys/src/cmd/vt/cons.h - 664 sys sys 1133463638 1776
+1133463719 1 c sys/src/cmd/vt/event.c - 664 sys sys 1133463638 1245
+1133463719 2 c sys/src/cmd/vt/hp.c - 664 sys sys 1133463638 3361
+1133463719 3 c sys/src/cmd/vt/main.c - 664 sys sys 1133463639 16737
+1133463719 4 c sys/src/cmd/vt/vt.c - 664 sys sys 1133463639 20180
+1133465520 0 c sys/src/9/pc/ether83815.c - 664 sys sys 1133464742 23556
+1133469120 0 c 386/bin/vt - 775 sys sys 1133468806 178593

+ 9 - 7
sys/src/9/pc/ether83815.c

@@ -594,13 +594,16 @@ ctlrinit(Ether* ether)
 	ctlr = ether->ctlr;
 
 	/*
-	 * Allocate and initialise the receive ring;
-	 * allocate and initialise the transmit ring;
-	 * unmask interrupts and start the transmit side
+	 * Allocate suitable aligned descriptors
+	 * for the transmit and receive rings;
+	 * initialise the receive ring;
+	 * initialise the transmit ring;
+	 * unmask interrupts and start the transmit side.
 	 */
-	ctlr->rdr = malloc(ctlr->nrdr*sizeof(Des));
-	if (ctlr->rdr == nil)
-		error(Enomem);
+	des = xspanalloc((ctlr->nrdr+ctlr->ntdr)*sizeof(Des), 32, 0);
+	ctlr->tdr = des;
+	ctlr->rdr = des+ctlr->ntdr;
+
 	last = nil;
 	for(des = ctlr->rdr; des < &ctlr->rdr[ctlr->nrdr]; des++){
 		des->bp = iallocb(Rbsz);
@@ -616,7 +619,6 @@ ctlrinit(Ether* ether)
 	ctlr->rdrx = 0;
 	csr32w(ctlr, Rrxdp, PADDR(ctlr->rdr));
 
-	ctlr->tdr = xspanalloc(ctlr->ntdr*sizeof(Des), 8*sizeof(ulong), 0);
 	last = nil;
 	for(des = ctlr->tdr; des < &ctlr->tdr[ctlr->ntdr]; des++){
 		des->cmdsts = 0;

+ 6 - 1
sys/src/cmd/vt/cons.h

@@ -47,7 +47,7 @@ struct funckey {
 	char	*sequence;
 };
 extern struct funckey *fk;
-extern struct funckey vt100fk[], vt220fk[], ansifk[];
+extern struct funckey vt100fk[], vt220fk[], ansifk[], xtermfk[];
 
 extern int	x, y, xmax, ymax, olines;
 extern int	peekc, attribute;
@@ -71,9 +71,14 @@ extern void	drawstring(Point, char*, int);
 extern int	debug;
 extern int	yscrmin, yscrmax;
 extern int	attribute;
+extern int	attdefault;
 extern int	frgcolor;
 extern int	bckcolor;
+extern int	frgdefault;
+extern int	bckdefault;
 extern int cursoron;
+extern Font *fnt;
+extern int	wflag;
 
 extern void curson(int);
 extern void cursoff(void);

+ 8 - 0
sys/src/cmd/vt/event.c

@@ -7,6 +7,7 @@
 #define	BUFSIZ	4000
 
 extern int	outfd;
+extern int	wctlout;
 
 int	hostpid;
 
@@ -31,8 +32,15 @@ start_host(void)
 		exits("consctl");
 	}
 
+	if(wflag){
+		bind("#|", "/mnt/temp", MREPL);
+		wctlout = open("/mnt/temp/data", OWRITE);
+	}
+
 	switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
 	case 0:
+		if(wflag)
+			bind("/mnt/temp/data1", "/dev/wctl", MREPL);
 		fd = open("/dev/cons", OREAD);
 		dup(fd,0);
 		if(fd != 0)

+ 1 - 1
sys/src/cmd/vt/hp.c

@@ -199,7 +199,7 @@ emulate(void)
 					Rpt(pt(x, y), pt(xmax-n+1, y+1)), S);
 			}
 			xtipple(Rpt(pt(x,y), pt(x+n, y+1)));
-			string(&screen, pt(x, y), font, buf, DxorS);
+			string(&screen, pt(x, y), fnt, buf, DxorS);
 			if (standout)
 				rectf(&screen,
 				      Rpt(pt(x,y),pt(x+n,y+1)),

+ 135 - 47
sys/src/cmd/vt/main.c

@@ -48,21 +48,31 @@ Menu	menu3;
 char	*histp;
 char	hist[HISTSIZ];
 int	yscrmin, yscrmax;
-int	bckcolor, frgcolor;
-int	attribute;
+int	bckcolor, frgcolor, bckdefault, frgdefault;
+int	attribute, attdefault;
+int	wctlout;
+int	wflag;
 
 Image	*bordercol;
 Image	*cursback;
 Image	*black;
-Image	*white;
 Image	*red;
 Image	*green;
 Image	*blue;
 Image	*cyan;
-Image	*magenta;
-Image	*yellow;
+Image	*purple;
+Image	*brown;
 Image	*grey;
+Image	*hiblack;
+Image	*hired;
+Image	*higreen;
+Image	*hiblue;
+Image	*hicyan;
+Image	*hipurple;
+Image	*hibrown;
+Image	*higrey;
 Image	*colortab[8];
+Image	*hicolortab[8];
 
 /* terminal control */
 struct ttystate ttystate[2] = { {0, 1}, {0, 1} };
@@ -75,6 +85,7 @@ Mouse	mouse;
 int	outfd = -1;
 Biobuf	*snarffp = 0;
 
+Font	*fnt;
 char	*host_buf;
 char	*hostp;			/* input from host */
 int	host_bsize = 2*BSIZE;
@@ -122,12 +133,16 @@ initialize(int argc, char **argv)
 {
 	int dayglo = 1;
 	char *p;
+	char *fname = 0;
 
 	rfork(RFENVG|RFNAMEG|RFNOTEG);
 
 	term = "vt100";
 	fk = vt100fk;
 	ARGBEGIN{
+	case 'f':
+		fname = EARGF(useage());
+		break;
 	case 'a':
 		term = "ansi";
 		fk = ansifk;
@@ -136,6 +151,10 @@ initialize(int argc, char **argv)
 		term = "vt220";
 		fk = vt220fk;
 		break;
+	case 'x':
+		fk = xtermfk;
+		term = "xterm";
+		break;
 	case 's': /* for sape */
 		dayglo = 0;
 		break;
@@ -147,6 +166,9 @@ initialize(int argc, char **argv)
 		if(logfd < 0)
 			sysfatal("could not create log file: %s: %r", p);
 		break;
+	case 'w':
+		wflag = 1;
+		break;
 	}ARGEND;
 
 	host_buf = malloc(host_bsize);
@@ -159,42 +181,77 @@ initialize(int argc, char **argv)
 	}
 	ebegin(Ehost);
 
+	if(fname)
+		fnt = openfont(display, fname);
+	if(fnt == nil)
+		fnt = font;
+
 	histp = hist;
 	menu2.item = menutext2;
 	menu3.item = menutext3;
 	pagemode = 0;
 	blocked = 0;
-	NS = font->height ;
-	CW = stringwidth(font, "m");
+	NS = fnt->height;
+	CW = stringwidth(fnt, "m");
+
 	bordercol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCCC);
 	cursback = allocimage(display, Rect(0, 0, CW+1, NS+1), screen->chan, 0, DNofill);
-	black =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlack);
-	white =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DWhite);
-	red =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DRed);
-	green =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DGreen);
-	yellow =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DYellow);
-	blue =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlue);
-	magenta =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DMagenta);
-	cyan =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DCyan);
-	grey =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DPalegreygreen);
-
-	colortab[0] = black;
-	colortab[1] = red;
-	colortab[2] = green;
-	colortab[3] = yellow;
-	colortab[4] = blue;
-	colortab[5] = magenta;
-	colortab[6] = cyan;
-	colortab[7] = grey;
-
-	if(dayglo) {
-		bckcolor = 0;
-		frgcolor = 7;
+
+	black =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x000000FF);
+	red =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,   0xAA0000FF);
+	green =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x00AA00FF);
+	blue =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x0000FFFF);
+	cyan =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x00AAAAFF);
+	purple = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xAA00AAFF);
+	brown = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xFF5500FF);
+	grey =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x7F7F7FFF);
+
+	hiblack =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x555555FF);
+	hired =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,   0xff5555FF);
+	higreen =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x55ff55FF);
+	hiblue =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x5555ffFF);
+	hicyan =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0x55ffffFF);
+	hipurple = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0xff55ffFF);
+	hibrown = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xffff55FF);
+	higrey =  allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1,  0xffffffFF);
+
+	bckdefault = bckcolor = 0;
+	frgdefault = frgcolor = 7;
+	if(dayglo){
+		colortab[0] = black;
+		colortab[1] = red;
+		colortab[2] = green;
+		colortab[3] = brown;
+		colortab[4] = blue;
+		colortab[5] = purple;
+		colortab[6] = cyan;
+		colortab[7] = grey;
+		hicolortab[0] = hiblack;
+		hicolortab[1] = hired;
+		hicolortab[2] = higreen;
+		hicolortab[3] = hibrown;
+		hicolortab[4] = hiblue;
+		hicolortab[5] = hipurple;
+		hicolortab[6] = hicyan;
+		hicolortab[7] = higrey;
 	} else {
-		bckcolor = 7;
-		frgcolor = 0;
-		colortab[7] = white;
-	}	
+		hicolortab[0] = grey;
+		hicolortab[1] = red;
+		hicolortab[2] = green;
+		hicolortab[3] = brown;
+		hicolortab[4] = blue;
+		hicolortab[5] = purple;
+		hicolortab[6] = cyan;
+		hicolortab[7] = black;
+		colortab[0] = higrey;
+		colortab[1] = hired;
+		colortab[2] = higreen;
+		colortab[3] = hibrown;
+		colortab[4] = hiblue;
+		colortab[5] = hipurple;
+		colortab[6] = hicyan;
+		colortab[7] = hiblack;
+	}
 
 	eresized(0);
 
@@ -229,8 +286,7 @@ newline(void)
 void
 cursoff(void)
 {
-	draw(screen, Rpt(pt(x, y), addpt(pt(x, y), Pt(CW,NS))),
-		cursback, nil, cursback->r.min);
+	draw(screen, Rpt(pt(x, y), addpt(pt(x, y), Pt(CW,NS))), cursback, nil, cursback->r.min);
 }
 
 void
@@ -238,12 +294,11 @@ curson(int bl)
 {
 	Image *col;
 
-	if(!cursoron){
-		cursoff();
+	draw(cursback, cursback->r, screen, nil, pt(x, y));
+
+	if(!cursoron)
 		return;
-	}
 
-	draw(cursback, cursback->r, screen, nil, pt(x, y));
 	if(bl)
 		col = red;
 	else
@@ -421,6 +476,12 @@ waitchar(void)
 				case Kright:
 					sendfk("right key");
 					break;
+				case Kpgup:
+					sendfk("page up");
+					break;
+				case Kpgdown:
+					sendfk("page down");
+					break;
 				case KF|1:
 					sendfk("F1");
 					break;
@@ -540,6 +601,8 @@ exportsize(void)
 void
 resize(void)
 {
+	static int oldwt;
+	static int oldht;
 	if(resize_flag > 1 && getwindow(display, Refnone) < 0){
 		fprint(2, "can't reattach to window: %r\n");
 		exits("can't reattach to window");
@@ -555,6 +618,11 @@ resize(void)
 	olines = 0;
 	exportsize();
 	clear(screen->r);
+	fprint(wctlout, " %11d %11d %11d %11d",
+		screen->r.min.x, screen->r.min.y,
+		screen->r.max.x, screen->r.max.y);
+	oldwt = Dx(screen->r);
+	oldht = Dy(screen->r);
 	resize_flag = 0;
 }
 
@@ -690,6 +758,7 @@ scroll(int sy, int ly, int dy, int cy)	/* source, limit, dest, which line to cle
 {
 	draw(screen, Rpt(pt(0, dy), pt(xmax+1, dy+ly-sy)), screen, nil, pt(0, sy));
 	clear(Rpt(pt(0, cy), pt(xmax+1, cy+1)));
+	flushimage(display,1);
 }
 
 void
@@ -709,6 +778,7 @@ bigscroll(void)			/* scroll up half a page */
 	y -= half;
 	if(olines)
 		olines -= half;
+	flushimage(display, 1);
 }
 
 int
@@ -827,17 +897,35 @@ void
 drawstring(Point p, char *str, int attribute)
 {
 	Image *txt, *bg;
+	Rune *rstr;
+	int i, n;
 	
 	if(!(attribute & TReverse)) {
-		txt = colortab[frgcolor];
-		bg = colortab[bckcolor];
+		if(attribute & THighIntensity || bckcolor){
+			txt = hicolortab[frgcolor];
+			bg = colortab[bckcolor];
+		}else{
+			txt = colortab[frgcolor];
+			bg = colortab[bckcolor];
+		}
 	} else {
-		txt = colortab[bckcolor];
-		bg = colortab[frgcolor];
+		if(attribute & THighIntensity || bckcolor){
+			txt = colortab[bckcolor];
+			bg = colortab[frgcolor];
+		}else{
+			txt = colortab[bckcolor];
+			bg = colortab[frgcolor];
+		}
 	}
-	if(attribute & THighIntensity)
-		txt = white;
 
-	draw(screen, Rpt(p, addpt(p, stringsize(font, str))), bg, nil, p);
-	string(screen, p, txt, ZP, font, str);
+	n = strlen(str) + 1;
+	rstr = malloc(n * sizeof(rstr[0]));
+
+	for(i = 0; i < n; ++i)
+		rstr[i] = (uchar)str[i];
+
+	draw(screen, Rpt(p, addpt(p, runestringsize(fnt, rstr))), bg, nil, p);
+	runestring(screen, p, txt, ZP, fnt, rstr);
+
+	free(rstr);
 }

+ 185 - 50
sys/src/cmd/vt/vt.c

@@ -65,6 +65,27 @@ struct funckey vt220fk[NKEYS] = {
 	{ "right key",		"\033[C", },
 };
 
+struct funckey xtermfk[NKEYS] = {
+	{ "page up",	"\033[5~", },
+	{ "page down",	"\033[6~", },
+	{ "up key",		"\033[A", },
+	{ "down key",		"\033[B", },
+	{ "left key",		"\033[D", },
+	{ "right key",		"\033[C", },
+	{ "F1",			"\033[11~", },
+	{ "F2",			"\033[12~", },
+	{ "F3",			"\033[13~", },
+	{ "F4",			"\033[14~", },
+	{ "F5",			"\033[15~", },
+	{ "F6",			"\033[17~", },
+	{ "F7",			"\033[18~", },
+	{ "F8",			"\033[19~", },
+	{ "F9",			"\033[20~", },
+	{ "F10",		"\033[21~", },
+	{ "F11",		"\033[22~", },
+	{ "F12",		"\033[23~", },
+};
+
 char gmap[256] = {
 	['_']	' ',	/* blank */
 	['\\']	'*',	/* diamond */
@@ -102,10 +123,18 @@ char gmap[256] = {
 
 static void setattr(int argc, int *argv);
 
+void
+fixops(int *operand)
+{
+	if(operand[0] < 1)
+		operand[0] = 1;
+}
+
 void
 emulate(void)
 {
 	char buf[BUFS+1];
+	int i;
 	int n;
 	int c;
 	int operand[10];
@@ -113,6 +142,7 @@ emulate(void)
 	int savex, savey, saveattribute, saveisgraphics;
 	int isgraphics;
 	int g0set, g1set;
+	int dch;
 
 	isgraphics = 0;
 	g0set = 'B';	/* US ASCII */
@@ -166,14 +196,14 @@ emulate(void)
 		case '\013':
 		case '\014':
 			newline();
-			attribute = 0;
+			//attribute = attdefault;
 			if (ttystate[cs->raw].nlcr)
 				x = 0;
 			break;
 
 		case '\015':		/* carriage return */
 			x = 0;
-			attribute = 0;
+			//attribute = attdefault;
 			if (ttystate[cs->raw].crnl)
 				newline();
 			break;
@@ -208,7 +238,7 @@ emulate(void)
 			break;
 
 		case '\033':
-			switch(get_next_char()){
+			switch(dch = get_next_char()){
 			/*
 			 * 1 - graphic processor option on (no-op; not installed)
 			 */
@@ -225,6 +255,7 @@ emulate(void)
 			 * 7 - save cursor position.
 			 */
 			case '7':
+//print("save\n");
 				savex = x;
 				savey = y;
 				saveattribute = attribute;
@@ -235,6 +266,7 @@ emulate(void)
 			 * 8 - restore cursor position.
 			 */
 			case '8':
+//print("restore\n");
 				x = savex;
 				y = savey;
 				attribute = saveattribute;
@@ -245,8 +277,8 @@ emulate(void)
 			 * c - Reset terminal.
 			 */
 			case 'c':
+print("resetterminal\n");
 				cursoron = 1;
-				curson(0);
 				ttystate[cs->raw].nlcr = 0;
 				break;
 
@@ -357,10 +389,10 @@ emulate(void)
 				 * A semi-colon or ? delimits arguments.
 				 */
 				memset(operand, 0, sizeof(operand));
-				operand[0] = number(buf, nil);
+				operand[0] = number(buf, &i);
 				noperand = 1;
 				while(buf[0] == ';' || buf[0] == '?'){
-					if(noperand < nelem(operand)) {
+					if(noperand < nelem(operand)){
 						noperand++;
 						operand[noperand-1] = number(buf, nil);
 					} else
@@ -370,7 +402,7 @@ emulate(void)
 				/*
 				 * do escape2 stuff
 				 */
-				switch(buf[0]){
+				switch(dch = buf[0]){
 					/*
 					 * c - same as ESC Z: what are you?
 					 */
@@ -399,7 +431,8 @@ emulate(void)
 						if(noperand == 1){
 							switch(operand[0]){	
 							case 20:	/* set line feed mode */
-								ttystate[cs->raw].nlcr = 0;
+print("linefeedmode\n");
+								ttystate[cs->raw].nlcr = 1;
 								break;
 							case 30:	/* screen invisible (? not supported through VT220) */
 								break;
@@ -418,7 +451,7 @@ emulate(void)
 							case 5:	/* set normal video on screen */
 								break;
 							case 6:	/* set origin to absolute */
-print("OL\n");
+//print("OL\n");
 								originrelative = 0;
 								x = y = 0;
 								break;
@@ -431,39 +464,52 @@ print("OL\n");
 								break;
 							case 25:	/* text cursor off (VT220) */
 								cursoron = 0;
-								cursoff();
 								break;
 							}
 						}
 						break;
 
+					/*
+					* s - some dec private stuff. actually [ ? num s, but we can't detect it.
+					*/
+					case 's':
+						break;
+
 					/*
 					 * h - set various options.
 					 */
 					case 'h':
 //print("h%d:%d,%d\n", noperand, operand[0], operand[1]);
 						if(noperand == 1){
-							switch(operand[0]){	
+							switch(operand[0]){
+							default:
+//print("escape2 'h' unknown operand %d (n:%d)\n", operand[0], noperand-1);
+								break;
 							case 20:	/* set newline mode */
-								ttystate[cs->raw].nlcr = 1;
+print("newlinemode\n");
+								ttystate[cs->raw].nlcr = 0;
 								break;
 							case 30:	/* screen visible (? not supported through VT220) */
 								break;
 							}
 						}else while(--noperand > 0){
 							switch(operand[noperand]){
+							default:
+//print("escape2 'h' operand: %d (n:%d)\n", operand[noperand], noperand);
+								break;
 							case 1:	/* set cursor keys to send application function: ESC O A..D */
 								break;
 							case 2:	/* set ANSI */
 								break;
 							case 3:	/* set 132 columns */
 								setdim(-1, 132);
-							break;
+								break;
 							case 4:	/* set smooth scrolling */
 								break;
 							case 5:	/* set screen to reverse video (not implemented) */
 								break;
 							case 6:	/* set origin to relative */
+//print("origin relative\n");
 								originrelative = 1;
 								x = 0;
 								y = yscrmin;
@@ -477,7 +523,6 @@ print("OL\n");
 								break;
 							case 25:	/* text cursor on (VT220) */
 								cursoron = 1;
-								curson(0);
 								break;
 							}
 						}
@@ -499,6 +544,7 @@ print("OL\n");
 							sendnchars2(4, "\033[0n");	/* terminal ok */
 							break;
 						case 6:	/* cursor position */
+//print("cursor pos\n");
 							sendnchars2(sprint(buf, "\033[%d;%dR",
 								originrelative ? y+1 - yscrmin : y+1, x+1), buf);
 							break;
@@ -509,7 +555,7 @@ print("OL\n");
 					 * q - turn on list of LEDs; turn off others.
 					 */
 					case 'q':
-//						print("LED\n");
+//print("LED\n");
 						break;
 
 					/*
@@ -518,6 +564,7 @@ print("OL\n");
 					 * scrolling region.
 					 */
 					case 'r':
+//print("scrolling region: n:%d %d %d\n", noperand, operand[1], operand[0]);
 						yscrmin = 0;
 						yscrmax = ymax;
 						switch(noperand){
@@ -550,9 +597,9 @@ print("OL\n");
 					/*
 					 * A - cursor up.
 					 */
+					case 'e':
 					case 'A':
-						if(operand[0] == 0)
-							operand[0] = 1;
+						fixops(operand);
 						y -= operand[0];
 						if(y < yscrmin)
 							y = yscrmin;
@@ -565,8 +612,7 @@ print("OL\n");
 					 * B - cursor down
 					 */
 					case 'B':
-						if(operand[0] == 0)
-							operand[0] = 1;
+						fixops(operand);
 						y += operand[0];
 						if(y > yscrmax)
 							y=yscrmax;
@@ -575,50 +621,65 @@ print("OL\n");
 					/*
 					 * C - cursor right
 					 */
+					case 'a':
 					case 'C':
-						if(operand[0] == 0)
-							operand[0] = 1;
+						fixops(operand);
 						x += operand[0];
 						/*
 						 * VT-100-UG says not to go past the
 						 * right margin.
 						 */
 						if(x > xmax)
-							x=xmax;
+							x = xmax;
 						break;
 
 					/*
 					 * D - cursor left
 					 */
 					case 'D':
-						if(operand[0] == 0)
-							operand[0] = 1;
+						fixops(operand);
 						x -= operand[0];
 						if(x < 0)
 							x = 0;
 						break;
 
+					/*
+					 *	G - cursor to column
+					 */
+					case '\'':
+					case 'G':
+						fixops(operand);
+						x = operand[0] - 1;
+						if(x > xmax)
+							x = xmax;
+						break;
+
 					/*
 					 * H and f - cursor motion.  operand[0] is row and
 					 * operand[1] is column, origin 1.
 					 */
 					case 'H':
 					case 'f':
+						fixops(operand+1);
 						x = operand[1] - 1;
-						if(x < 0)
-							x = 0;
 						if(x > xmax)
 							x = xmax;
+
+						/* fallthrough */
+
+					/*
+					 * d - cursor to line n (xterm)
+					 */
+					case 'd':
+						fixops(operand);
 						y = operand[0] - 1;
-						if(y < 0)
-							y = 0;
 						if(originrelative){
 							y += yscrmin;
-							if(y > yscrmax)
-								y = ymax;
-						}else{
 							if(y > yscrmax)
 								y = yscrmax;
+						}else{
+							if(y > ymax)
+								y = ymax;
 						}
 						break;
 
@@ -676,18 +737,67 @@ print("OL\n");
 						}
 						break;
 
+					/*
+					 *	P - delete character(s) from right of cursor (xterm)
+					 */
+					case 'P':
+						fixops(operand);
+						i = x + operand[0];
+						draw(screen, Rpt(pt(x, y), pt(xmax+1, y+1)), screen, nil, pt(i, y));
+						clear(Rpt(pt(xmax-operand[0], y), pt(xmax+1, y+1)));
+						break;
+
+					/*
+					 *	@ - insert blank(s) to right of cursor (xterm)
+					 */
+					case '@':
+						fixops(operand);
+						i = x + operand[0];
+						draw(screen, Rpt(pt(i, y), pt(xmax+1, y+1)), screen, nil, pt(x, y));
+						clear(Rpt(pt(x, y), pt(i, y+1)));
+						break;
+
+
+					/*
+					 *	X - erase character(s) at cursor and to the right (xterm)
+					 */
+					case 'X':
+						fixops(operand);
+						i = x + operand[0];
+						clear(Rpt(pt(x, y), pt(i, y+1)));
+						break;
+
 					/*
 					 * L - insert a line at cursor position (VT102 and later)
 					 */
 					case 'L':
-						scroll(y, yscrmax, y+1, y);
+						fixops(operand);
+						for(i = 0; i < operand[0]; ++i)
+							scroll(y, yscrmax, y+1, y);
 						break;
 
 					/*
 					 * M - delete a line at cursor position (VT102 and later)
 					 */
 					case 'M':
-						scroll(y+1, yscrmax+1, y, yscrmax);
+						fixops(operand);
+						for(i = 0; i < operand[0]; ++i)
+							scroll(y+1, yscrmax+1, y, yscrmax);
+						break;
+
+					/*
+					 * S,T - scroll up/down (xterm)
+					 */
+					case 'T':
+						fixops(operand);
+						for(i = 0; i < operand[0]; ++i)
+							scroll(yscrmin, yscrmax, yscrmin+1, yscrmin);
+						break;
+
+					case 'S':
+						fixops(operand);
+						for(i = 0; i < operand[0]; ++i)
+							scroll(yscrmin+1, yscrmax+1, yscrmin, yscrmin);
 						break;
 
 					case '=':	/* ? not supported through VT220 */
@@ -703,6 +813,7 @@ print("OL\n");
 					 * Anything else we ignore for now...
 					 */
 					default:
+print("unknown escape2 '%c' (0x%x)\n", dch, dch);
 						break;
 				}
 
@@ -715,10 +826,26 @@ print("OL\n");
 				peekc = '\033';
 				break;
 
+			/* set title */
+			case ']':	/* it's actually <esc> ] num ; title <bel> */
+				{
+					int ch, fd;
+					number(buf, nil);
+					i = 0;
+					while((ch = get_next_char()) != '\a')
+						if(i < sizeof buf)
+							buf[i++] = ch;
+					fd = open("/dev/label", OWRITE);
+					write(fd, buf, i);
+					close(fd);
+				}
+				break;
+
 			/*
 			 * Ignore other commands.
 			 */
 			default:
+print("unknown command '%c' (0x%x)\n", dch, dch);
 				break;
 
 			}
@@ -763,7 +890,9 @@ setattr(int argc, int *argv)
 	for(i=0; i<argc; i++) {
 		switch(argv[i]) {
 		case 0:
-			attribute = 0;
+			attribute = attdefault;
+			frgcolor = frgdefault;
+			bckcolor = bckdefault;
 			break;
 		case 1:
 			attribute |= THighIntensity;
@@ -795,26 +924,32 @@ setattr(int argc, int *argv)
 		case 28:
 			attribute &= ~TInvisible;
 			break;
-		case 30:
-		case 31:
-		case 32:
-		case 33:
-		case 34:
-		case 35:
-		case 36:
-		case 37:
+		case 30:	/* black */
+		case 31:	/* red */
+		case 32:	/* green */
+		case 33:	/* brown */
+		case 34:	/* blue */
+		case 35:	/* purple */
+		case 36:	/* cyan */
+		case 37:	/* white */
 			frgcolor = argv[i]-30;
 			break;
-		case 40:
-		case 41:
-		case 42:
-		case 43:
-		case 44:
-		case 45:
-		case 46:
-		case 47:
+		case 39:
+			frgcolor = frgdefault;
+			break;
+		case 40:	/* black */
+		case 41:	/* red */
+		case 42:	/* green */
+		case 43:	/* brown */
+		case 44:	/* blue */
+		case 45:	/* purple */
+		case 46:	/* cyan */
+		case 47:	/* white */
 			bckcolor = argv[i]-40;
 			break;
+		case 49:
+			bckcolor = bckdefault;
+			break;
 		}
 	}
 }