Index: tetris/tetris.c
===================================================================
--- tetris/tetris.c	(revision 0aa024b1d503a5c3520dc1cb1aadeee8029ed501)
+++ tetris/tetris.c	(revision 51dbadf3d0373e65b18fe92a7f6eb61e7bde59f6)
@@ -159,4 +159,91 @@
 }
 
+static void tetris_scores(int firstgame)
+{
+}
+
+static void tetris_menu_draw(int level) 
+{
+		clear_screen();
+		moveto(5,10);
+		puts("Tetris\n\n");
+			
+		moveto(8,10);
+		printf("Level = %d (press keys 1 - 9 to change)",level);
+		moveto(9,10);
+		printf("Preview is %s (press 'p' to change)", (showpreview?"on ":"off"));
+		moveto(12,10);
+		printf("Press 'h' to show hiscore table.");
+		moveto(13,10);
+		printf("Press 's' to start game.");
+		moveto(14,10);
+		printf("Press 'q' to quit game.");
+		moveto(20,10);
+		printf("In game controls:");
+		moveto(21,0);
+		puts(key_msg);
+}
+
+static int tetris_menu(int *level) 
+{
+	static int firstgame = 1;
+	int i;
+/*	if (showpreview == 0)
+		(void)printf("Your score:  %d point%s  x  level %d  =  %d\n",
+		    score, score == 1 ? "" : "s", level, score * level);
+	else {
+ 		(void)printf("Your score:  %d point%s x level %d x preview penalty %0.3f = %d\n", 
+ 		    score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, 
+ 		    (int)(score * level * PRE_PENALTY)); 
+ 		score = score * PRE_PENALTY; 
+	}
+	savescore(level);
+
+	showscores(level);
+	
+	printf("\nHit 's' to new game, 'q' to quit.\n");
+*/
+	tetris_menu_draw(*level);
+	while (1) {
+	
+		i = getchar();
+		
+		switch(i) {
+			case 'p':
+				showpreview = !showpreview;
+				moveto(9,21);
+				if (showpreview)
+					printf("on ");
+				else
+					printf("off");
+					
+				break;
+			case 'h':
+				showscores(firstgame);
+				tetris_menu_draw(*level);
+				break;
+			case 's':
+				firstgame = 0;
+				return 1;
+			case 'q':
+				return 0;
+			case '1':
+			case '2':
+			case '3':
+			case '4':
+			case '5':
+			case '6':		
+			case '7':
+			case '8':
+			case '9':
+				*level = i - '0';
+				moveto(8,18);
+				printf("%d", *level);
+				break;
+		}
+	}
+	
+}
+
 int
 main(int argc, char *argv[])
@@ -175,5 +262,6 @@
 //	setegid(gid);
 
-	classic = showpreview = 0;
+	classic = 0;
+	showpreview = 1; 
 
 /* 	while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */
@@ -233,133 +321,116 @@
 		key_write[0], key_write[1], key_write[2], key_write[3],
 		key_write[4], key_write[5]);
-newgame:
+
 	scr_init();
-	setup_board();
-
-	srandomdev();
-	scr_set();
-
-	pos = A_FIRST*B_COLS + (B_COLS/2)-1;
-	nextshape = randshape();
-	curshape = randshape();
-
-	scr_msg(key_msg, 1);
-
-	for (;;) {
-		place(curshape, pos, 1);
-		scr_update();
-		place(curshape, pos, 0);
-		c = tgetchar();
-		if (c < 0) {
+	initscores();
+	while (tetris_menu(&level)) {
+
+
+		scr_clear();
+		setup_board();
+	
+		srandomdev();
+		scr_set();
+	
+		pos = A_FIRST*B_COLS + (B_COLS/2)-1;
+		nextshape = randshape();
+		curshape = randshape();
+	
+		scr_msg(key_msg, 1);
+	
+		for (;;) {
+			place(curshape, pos, 1);
+			scr_update();
+			place(curshape, pos, 0);
+			c = tgetchar();
+			if (c < 0) {
+				/*
+				 * Timeout.  Move down if possible.
+				 */
+				if (fits_in(curshape, pos + B_COLS)) {
+					pos += B_COLS;
+					continue;
+				}
+	
+				/*
+				 * Put up the current shape `permanently',
+				 * bump score, and elide any full rows.
+				 */
+				place(curshape, pos, 1);
+				score++;
+				elide();
+	
+				/*
+				 * Choose a new shape.  If it does not fit,
+				 * the game is over.
+				 */
+				curshape = nextshape;
+				nextshape = randshape();
+				pos = A_FIRST*B_COLS + (B_COLS/2)-1;
+				if (!fits_in(curshape, pos))
+					break;
+				continue;
+			}
+	
 			/*
-			 * Timeout.  Move down if possible.
+			 * Handle command keys.
 			 */
-			if (fits_in(curshape, pos + B_COLS)) {
-				pos += B_COLS;
-				continue;
-			}
-
-			/*
-			 * Put up the current shape `permanently',
-			 * bump score, and elide any full rows.
-			 */
-			place(curshape, pos, 1);
-			score++;
-			elide();
-
-			/*
-			 * Choose a new shape.  If it does not fit,
-			 * the game is over.
-			 */
-			curshape = nextshape;
-			nextshape = randshape();
-			pos = A_FIRST*B_COLS + (B_COLS/2)-1;
-			if (!fits_in(curshape, pos))
+			if (c == keys[5]) {
+				/* quit */
 				break;
-			continue;
+			}
+			if (c == keys[4]) {
+				static char msg[] =
+				    "paused - press RETURN to continue";
+	
+				place(curshape, pos, 1);
+				do {
+					scr_update();
+					scr_msg(key_msg, 0);
+					scr_msg(msg, 1);
+	//				(void) fflush(stdout);
+				} while (rwait((struct timeval *)NULL) == -1);
+				scr_msg(msg, 0);
+				scr_msg(key_msg, 1);
+				place(curshape, pos, 0);
+				continue;
+			}
+			if (c == keys[0]) {
+				/* move left */
+				if (fits_in(curshape, pos - 1))
+					pos--;
+				continue;
+			}
+			if (c == keys[1]) {
+				/* turn */
+				const struct shape *new = &shapes[
+				    classic? curshape->rotc : curshape->rot];
+	
+				if (fits_in(new, pos))
+					curshape = new;
+				continue;
+			}
+			if (c == keys[2]) {
+				/* move right */
+				if (fits_in(curshape, pos + 1))
+					pos++;
+				continue;
+			}
+			if (c == keys[3]) {
+				/* move to bottom */
+				while (fits_in(curshape, pos + B_COLS)) {
+					pos += B_COLS;
+					score++;
+				}
+				continue;
+			}
+			if (c == '\f') {
+				scr_clear();
+				scr_msg(key_msg, 1);
+			}
 		}
-
-		/*
-		 * Handle command keys.
-		 */
-		if (c == keys[5]) {
-			/* quit */
-			break;
-		}
-		if (c == keys[4]) {
-			static char msg[] =
-			    "paused - press RETURN to continue";
-
-			place(curshape, pos, 1);
-			do {
-				scr_update();
-				scr_msg(key_msg, 0);
-				scr_msg(msg, 1);
-//				(void) fflush(stdout);
-			} while (rwait((struct timeval *)NULL) == -1);
-			scr_msg(msg, 0);
-			scr_msg(key_msg, 1);
-			place(curshape, pos, 0);
-			continue;
-		}
-		if (c == keys[0]) {
-			/* move left */
-			if (fits_in(curshape, pos - 1))
-				pos--;
-			continue;
-		}
-		if (c == keys[1]) {
-			/* turn */
-			const struct shape *new = &shapes[
-			    classic? curshape->rotc : curshape->rot];
-
-			if (fits_in(new, pos))
-				curshape = new;
-			continue;
-		}
-		if (c == keys[2]) {
-			/* move right */
-			if (fits_in(curshape, pos + 1))
-				pos++;
-			continue;
-		}
-		if (c == keys[3]) {
-			/* move to bottom */
-			while (fits_in(curshape, pos + B_COLS)) {
-				pos += B_COLS;
-				score++;
-			}
-			continue;
-		}
-		if (c == '\f') {
-			scr_clear();
-			scr_msg(key_msg, 1);
-		}
-	}
-
-	scr_clear();
-	scr_end();
-
-	if (showpreview == 0)
-		(void)printf("Your score:  %d point%s  x  level %d  =  %d\n",
-		    score, score == 1 ? "" : "s", level, score * level);
-	else {
-/* 		(void)printf("Your score:  %d point%s x level %d x preview penalty %0.3f = %d\n", */
-/* 		    score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, */
-/* 		    (int)(score * level * PRE_PENALTY)); */
-/* 		score = score * PRE_PENALTY; */
-	}
-	savescore(level);
-
-	showscores(level);
-	
-	printf("\nHit 's' to new game, 'q' to quit.\n");
-
-	
-	while (i = getchar()) {
-		if (i == 's')
-			goto newgame;
-		if (i == 'q')
-			break;
+		
+		scr_clear();
+		insertscore(score, level);
 	}
 	
@@ -371,4 +442,5 @@
 			break
 */
+	scr_end();
 	exit(0);
 }
