]> thyrsus.com Git - tetrix.git/commitdiff
Working with ncurses.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 29 Nov 1994 03:50:36 +0000 (03:50 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 29 Nov 1994 03:50:36 +0000 (03:50 +0000)
Colors.c
Makefile
tet.c
tet.h

index 2690373cb3fb5559789c522e681da45c6550e913..0ba0ddf4deb1d7a144beafc62775c4be7e68c59e 100644 (file)
--- a/Colors.c
+++ b/Colors.c
@@ -3,7 +3,7 @@
 #include <curses.h>
 #include "tet.h"
 
-#ifdef COLOR
+#ifdef A_COLOR
 /* color pair indexes for pieces */
 #define BLACK  0
 #define GREEN  1
@@ -81,4 +81,4 @@ int   x, y, z;
     attrset(0);
 }
 
-#endif /* COLOR */
+#endif /* A_COLOR */
index 3d9e73363558b08583d9e319174fcfcb679419ab..f00e3f587a2b53b4cd9ac99c2c6debe55a3cc21a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,13 +4,13 @@
 #  - this will create a high score file in /usr/tmp, so doing it again
 #    later on will erase high scores for the machine.
 
-CFLAGS=-O -DCOLOR -DTERMINFO -DEGA
-LFLAGS = -s
+CFLAGS=-g -DEGA
+LFLAGS = # -s
 OBJS= MoveR.o MoveL.o DrawP.o AdvanceP.o Rotate.o Colors.o tet.o
 INCS= tet.h
 
 tetrix: $(OBJS) $(INCS)
-       cc $(LFLAGS) $(OBJS) -o tetrix -lcurses
+       cc $(LFLAGS) $(OBJS) -ldcurses -o tetrix
 
 MoveR.o: MoveR.c tet.h
 MoveL.o: MoveL.c tet.h
diff --git a/tet.c b/tet.c
index 6575a1032180c769d2195432f267c5e2f24dc055..975f0e8aea84dc5caa4dcbaf6981e32e51b0d64a 100644 (file)
--- a/tet.c
+++ b/tet.c
@@ -40,9 +40,6 @@ struct ScoreStruct {
 } High[HIGHCOUNT];
 int ThisScore,HighsChanged;
                
-char *ttyname();
-char combuf[2];
-struct termio origtty, tty;
 char Board[BOARD_WIDE][BOARD_HIGH];
 char Temp[BOARD_WIDE][BOARD_HIGH];     /* temp storage for TestRows */
 
@@ -99,27 +96,17 @@ Init()
        time(&timein);          /* get start time */
        srand48(timein);        /* start rand randomly */
 
-       ttnam = ttyname (0); 
-       close (0); 
-       open (ttnam, O_NDELAY);
-       /*
-        * setup raw mode, no echo
-        */
-       ioctl (0, TCGETA, &origtty);
-       ioctl (0, TCGETA, &tty);
-       tty.c_iflag &= 077;
-       tty.c_oflag &= 077700;
-       tty.c_lflag = 0201;
-       tty.c_cc[4] =  1;
-       ioctl (1, TCSETAW, &tty);
        signal(SIGINT, SIG_IGN);
        
        Beep=0;
        HighsChanged = 0;
-       ScoreIt();
        initscr();
+       nodelay(stdscr, TRUE);
+       noecho();
+       cbreak();
+       ScoreIt();
 
-#ifdef TERMINFO
+#ifdef ACS_VLINE
     /* good, we can use the defined forms-drawing characters */
     VERT = ACS_VLINE;
     HORIZ = ACS_HLINE;
@@ -127,11 +114,11 @@ Init()
     URC = ACS_URCORNER;
     LLC = ACS_LLCORNER;
     LRC = ACS_LRCORNER;
-#endif /* TERMINFO */
+#endif /* ACS_VLINE */
 
-#ifdef COLOR
+#ifdef A_COLOR
         init_colors();
-#endif /* COLOR */
+#endif /* A_COLOR */
        /* initialize board to spaces */
        for (x=0; x<BOARD_WIDE; x++) 
                for (y=0; y<BOARD_HIGH; y++) 
@@ -177,9 +164,6 @@ int t, l, d, w;
 {
     register int x, y;
 
-#ifdef TERMINFO
-    attron(A_ALTCHARSET);
-#endif
     for (y = t + 1; y < t + d; y++)
     {
        mvaddch(y, l, VERT);
@@ -194,9 +178,6 @@ int t, l, d, w;
     mvaddch(t + d,     l,     LLC);
     mvaddch(t,         l + w, URC);
     mvaddch(t + d,     l + w, LRC);
-#ifdef TERMINFO
-    attroff(A_ALTCHARSET);
-#endif
 }
 
 /******************************************************************/
@@ -341,7 +322,7 @@ ScoreIt()
        for(i=0; i<HIGHCOUNT; i++)
                High[i].Score = 0;
        for(i=0; i<HIGHCOUNT; i++)
-               strncpy("         ",High[i].Name,NAMELEN);
+               strncpy(High[i].Name,"         ",NAMELEN);
        }
        umask(oldmask);
 
@@ -404,11 +385,6 @@ int        highindex;
 Boss()
 {      register int x,y;
 
-       clear();
-       refresh();
-       ioctl (0, TCSETA, &origtty);
-       system("sh </dev/tty >/dev/tty");
-       ioctl (1, TCSETAW, &tty);
        clear();
        DrawMenu();
        /* restore board */
@@ -422,12 +398,13 @@ Boss()
 /*********************************************************************/
 GetKey()
 {
-/*     fflush(stdout); */
+       int c;
+
        Key = NULL_KEY;
        top:
-       if (read (0, combuf, 1) == 0) 
+       if ((c = getch()) == ERR) 
                return;
-       else Key = (*combuf&0177); 
+       else Key = (c & 0177); 
        goto top;
 }
 
@@ -497,6 +474,6 @@ Leave()
        mvaddstr(23,0,"");
        refresh();
        sleep(1);
-       ioctl (0, TCSETA, &origtty);
+       endwin();
        exit(0);
 }
diff --git a/tet.h b/tet.h
index b65f64a2e439101b0b024c3386e53129b663ddcb..81c76dec3396ab4651869502e00ba14435a48c13 100644 (file)
--- a/tet.h
+++ b/tet.h
 
 extern char Board[BOARD_WIDE][BOARD_HIGH];
 
-#ifndef COLOR
+#ifndef A_COLOR
 /* Macros */
 /* offset the character on screen by MINX and MINY */
 #define PUTCH(x,y,z) {  mvaddch(y,x,z); if (INBOARD(x, y)) Board[x-MINX][y-MINY]=z; }
 #else
 extern void PUTCH();
 extern void init_colors();
-#endif /* COLOR */
+#endif /* A_COLOR */
 
 #ifdef BIGCPP
 /* test whether a square is empty and legal */