From: Eric S. Raymond Date: Tue, 29 Nov 1994 03:50:36 +0000 (+0000) Subject: Working with ncurses. X-Git-Tag: 2.1~7 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=ea7c43066a7ca4053a192846126d41dbef51a3e1;p=tetrix.git Working with ncurses. --- diff --git a/Colors.c b/Colors.c index 2690373..0ba0ddf 100644 --- a/Colors.c +++ b/Colors.c @@ -3,7 +3,7 @@ #include #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 */ diff --git a/Makefile b/Makefile index 3d9e733..f00e3f5 100644 --- 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 6575a10..975f0e8 100644 --- 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/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 b65f64a..81c76de 100644 --- a/tet.h +++ b/tet.h @@ -40,14 +40,14 @@ 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 */