Index: tetris/screen.c
===================================================================
--- tetris/screen.c	(revision c594489d66e9376aea3b78ad26af0f0b329c74a2)
+++ tetris/screen.c	(revision 0c6984e40dcbca4c518ecebb32148c2b3d2f0cdd)
@@ -40,15 +40,10 @@
  */
 
-#include <sys/ioctl.h>
-
 #include <err.h>
-//#include <setjmp.h>
-//#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <term.h>
-#include <termios.h>
 #include <unistd.h>
+#include <io/stream.h>
 
 #include "screen.h"
@@ -135,4 +130,6 @@
 #define	moveto(r, c)	putpad(tgoto(CMstr, c, r))
 
+static int con_phone;
+
 /*
  * Set up from termcap.
@@ -141,93 +138,13 @@
 scr_init(void)
 {
-	static int bsflag, xsflag, sgnum;
-#ifdef unneeded
-	static int ncflag;
-#endif
-	char *term, *fill;
-	static struct tcninfo {	/* termcap numeric and flag info */
-		char tcname[3];
-		int *tcaddr;
-	} tcflags[] = {
-		{"bs", &bsflag},
-		{"ms", &MSflag},
-#ifdef unneeded
-		{"nc", &ncflag},
-#endif
-		{"xs", &xsflag},
-		{ {0}, NULL}
-	}, tcnums[] = {
-		{"co", &COnum},
-		{"li", &LInum},
-		{"sg", &sgnum},
-		{ {0}, NULL}
-	};
-	
-	if ((term = getenv("TERM")) == NULL)
-		stop("you must set the TERM environment variable");
-	if (tgetent(tbuf, term) <= 0)
-		stop("cannot find your termcap");
-	fill = combuf;
-	{
-		struct tcsinfo *p;
-
-		for (p = tcstrings; p->tcaddr; p++)
-			*p->tcaddr = tgetstr(p->tcname, &fill);
-	}
-	if (classic)
-		SOstr = SEstr = NULL;
-	{
-		struct tcninfo *p;
-
-		for (p = tcflags; p->tcaddr; p++)
-			*p->tcaddr = tgetflag(p->tcname);
-		for (p = tcnums; p->tcaddr; p++)
-			*p->tcaddr = tgetnum(p->tcname);
-	}
-	if (bsflag)
-		BC = "\b";
-	else if (BC == NULL && bcstr != NULL)
-		BC = bcstr;
-	if (CLstr == NULL)
-		stop("cannot clear screen");
-	if (CMstr == NULL || UP == NULL || BC == NULL)
-		stop("cannot do random cursor positioning via tgoto()");
-	PC = pcstr ? *pcstr : 0;
-	if (sgnum > 0 || xsflag)
-		SOstr = SEstr = NULL;
-#ifdef unneeded
-	if (ncflag)
-		CRstr = NULL;
-	else if (CRstr == NULL)
-		CRstr = "\r";
-#endif
-}
-
-/* this foolery is needed to modify tty state `atomically' */
-//static jmp_buf scr_onstop;
-
-/* static void */
-/* stopset(int sig) */
-/* { */
-/* 	sigset_t sigset; */
-
-/* 	(void) signal(sig, SIG_DFL); */
-/* 	(void) kill(getpid(), sig); */
-/* 	sigemptyset(&sigset); */
-/* 	sigaddset(&sigset, sig); */
-/* 	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
-/* 	longjmp(scr_onstop, 1); */
-/* } */
+	con_phone = get_fd_phone(1);
+}
+
 
 static void
 scr_stop(int sig)
 {
-//	sigset_t sigset;
 
 	scr_end();
-/* 	(void) kill(getpid(), sig); */
-/* 	sigemptyset(&sigset); */
-/* 	sigaddset(&sigset, sig); */
-/* 	(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
 	scr_set();
 	scr_msg(key_msg, 1);
@@ -242,22 +159,6 @@
 	struct winsize ws;
 	struct termios newtt;
-//	sigset_t sigset, osigset;
 	void (*ttou)(int);
 
-/* 	sigemptyset(&sigset); */
-/* 	sigaddset(&sigset, SIGTSTP); */
-/* 	sigaddset(&sigset, SIGTTOU); */
-/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
-/* 	if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */
-/* 		(void) signal(SIGTSTP, SIG_IGN); */
-/* 	if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */
-/* 		(void) signal(SIGTTOU, SIG_IGN); */
-/* 	/\* */
-/* 	 * At last, we are ready to modify the tty state.  If */
-/* 	 * we stop while at it, stopset() above will longjmp back */
-/* 	 * to the setjmp here and we will start over. */
-/* 	 *\/ */
-/* 	(void) setjmp(scr_onstop); */
-/* 	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
 	Rows = 0, Cols = 0;
 	if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
@@ -284,5 +185,4 @@
 	if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
 		stop("tcsetattr() fails");
-/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
 	/*
@@ -292,11 +192,7 @@
 	if (TIstr)
 		putstr(TIstr);	/* termcap(5) says this is not padded */
-/* 	if (tstp != SIG_IGN) */
-/* 		(void) signal(SIGTSTP, scr_stop); */
-/* 	if (ttou != SIG_IGN) */
-/* 		(void) signal(SIGTTOU, ttou); */
 
 	isset = 1;
-//	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
+
 	scr_clear();
 }
@@ -308,24 +204,4 @@
 scr_end(void)
 {
-//	sigset_t sigset, osigset;
-
-/* 	sigemptyset(&sigset); */
-/* 	sigaddset(&sigset, SIGTSTP); */
-/* 	sigaddset(&sigset, SIGTTOU); */
-/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
-	/* move cursor to last line */
-	if (LLstr)
-		putstr(LLstr);	/* termcap(5) says this is not padded */
-	else
-		moveto(Rows - 1, 0);
-	/* exit screen mode */
-	if (TEstr)
-		putstr(TEstr);	/* termcap(5) says this is not padded */
-//	(void) fflush(stdout);
-	(void) tcsetattr(0, TCSADRAIN, &oldtt);
-	isset = 0;
-	/* restore signals */
-/* 	(void) signal(SIGTSTP, tstp); */
-/* 	(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
 }
 
@@ -366,10 +242,5 @@
 	regcell so, cur_so = 0;
 	int i, ccol, j;
-//	sigset_t sigset, osigset;
 	static const struct shape *lastshape;
-
-/* 	sigemptyset(&sigset); */
-/* 	sigaddset(&sigset, SIGTSTP); */
-/* 	(void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
 	/* always leave cursor after last displayed point */
