X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/94f9016ae34e296728f9a47ca262377f3c8bcb9e..9a33f5bfb221170e823efd3c33ab5d331baf7c74:/tetris/screen.c diff --git a/tetris/screen.c b/tetris/screen.c index 007705e9..edbcddf9 100644 --- a/tetris/screen.c +++ b/tetris/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.10 1999/08/14 16:40:23 tron Exp $ */ +/* $NetBSD: screen.c,v 1.23 2009/05/25 04:33:53 dholland Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -42,6 +38,7 @@ * Tetris screen control. */ +#include #include #include @@ -64,16 +61,15 @@ static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ static int curscore; static int isset; /* true => terminal is in game mode */ static struct termios oldtt; -static void (*tstp) __P((int)); +static void (*tstp)(int); -static void scr_stop __P((int)); -static void stopset __P((int)); +static void scr_stop(int); +static void stopset(int) __dead; /* * Capabilities from TERMCAP. */ -char PC, *BC, *UP; /* tgoto requires globals: ugh! */ short ospeed; static char @@ -121,18 +117,16 @@ struct tcsinfo { /* termcap string info; some abbrevs above */ /* This is where we will actually stuff the information */ -static char combuf[1024], tbuf[1024]; - +static struct tinfo *info; /* * Routine used by tputs(). */ -void -put(c) - int c; +int +put(int c) { - (void) putchar(c); + return (putchar(c)); } /* @@ -141,19 +135,27 @@ put(c) * count=1. (See screen.h for putpad().) */ #define putstr(s) (void)fputs(s, stdout) -#define moveto(r, c) putpad(tgoto(CMstr, c, r)) + +void +moveto(int r, int c) +{ + char buf[256]; + + if (t_goto(info, CMstr, c, r, buf, 255) == 0) + putpad(buf); +} /* * Set up from termcap. */ void -scr_init() +scr_init(void) { static int bsflag, xsflag, sgnum; #ifdef unneeded static int ncflag; #endif - char *term, *fill; + char *term; static struct tcninfo { /* termcap numeric and flag info */ char tcname[3]; int *tcaddr; @@ -171,28 +173,28 @@ scr_init() {"sg", &sgnum}, { {0}, NULL} }; - + static char backspace[] = "\b"; + if ((term = getenv("TERM")) == NULL) stop("you must set the TERM environment variable"); - if (tgetent(tbuf, term) <= 0) + if (t_getent(&info, term) <= 0) stop("cannot find your termcap"); - fill = combuf; { - register struct tcsinfo *p; + struct tcsinfo *p; for (p = tcstrings; p->tcaddr; p++) - *p->tcaddr = tgetstr(p->tcname, &fill); + *p->tcaddr = t_agetstr(info, p->tcname); } { - register struct tcninfo *p; + struct tcninfo *p; for (p = tcflags; p->tcaddr; p++) - *p->tcaddr = tgetflag(p->tcname); + *p->tcaddr = t_getflag(info, p->tcname); for (p = tcnums; p->tcaddr; p++) - *p->tcaddr = tgetnum(p->tcname); + *p->tcaddr = t_getnum(info, p->tcname); } if (bsflag) - BC = "\b"; + BC = backspace; else if (BC == NULL && bcstr != NULL) BC = bcstr; if (CLstr == NULL) @@ -214,30 +216,28 @@ scr_init() static jmp_buf scr_onstop; static void -stopset(sig) - int sig; +stopset(int sig) { - sigset_t sigset; + sigset_t set; (void) signal(sig, SIG_DFL); (void) kill(getpid(), sig); - sigemptyset(&sigset); - sigaddset(&sigset, sig); - (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); + sigemptyset(&set); + sigaddset(&set, sig); + (void) sigprocmask(SIG_UNBLOCK, &set, (sigset_t *)0); longjmp(scr_onstop, 1); } static void -scr_stop(sig) - int sig; +scr_stop(int sig) { - sigset_t sigset; + sigset_t set; scr_end(); (void) kill(getpid(), sig); - sigemptyset(&sigset); - sigaddset(&sigset, sig); - (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); + sigemptyset(&set); + sigaddset(&set, sig); + (void) sigprocmask(SIG_UNBLOCK, &set, (sigset_t *)0); scr_set(); scr_msg(key_msg, 1); } @@ -246,17 +246,17 @@ scr_stop(sig) * Set up screen mode. */ void -scr_set() +scr_set(void) { struct winsize ws; struct termios newtt; - sigset_t sigset, osigset; - void (*ttou) __P((int)); + sigset_t nsigset, osigset; + void (*ttou)(int); - sigemptyset(&sigset); - sigaddset(&sigset, SIGTSTP); - sigaddset(&sigset, SIGTTOU); - (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); + sigemptyset(&nsigset); + sigaddset(&nsigset, SIGTSTP); + sigaddset(&nsigset, SIGTTOU); + (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) (void) signal(SIGTSTP, SIG_IGN); if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) @@ -291,7 +291,7 @@ scr_set() if (tcsetattr(0, TCSADRAIN, &newtt) < 0) stop("tcsetattr() fails"); ospeed = cfgetospeed(&newtt); - (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); + (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); /* * We made it. We are now in screen mode, modulo TIstr @@ -313,14 +313,14 @@ scr_set() * End screen mode. */ void -scr_end() +scr_end(void) { - sigset_t sigset, osigset; + sigset_t nsigset, osigset; - sigemptyset(&sigset); - sigaddset(&sigset, SIGTSTP); - sigaddset(&sigset, SIGTTOU); - (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); + sigemptyset(&nsigset); + sigaddset(&nsigset, SIGTSTP); + sigaddset(&nsigset, SIGTTOU); + (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); /* move cursor to last line */ if (LLstr) putstr(LLstr); /* termcap(5) says this is not padded */ @@ -338,8 +338,7 @@ scr_end() } void -stop(why) - char *why; +stop(const char *why) { if (isset) @@ -352,7 +351,7 @@ stop(why) * Clear the screen, forgetting the current contents in the process. */ void -scr_clear() +scr_clear(void) { putpad(CLstr); @@ -370,17 +369,17 @@ typedef cell regcell; * Update the screen. */ void -scr_update() +scr_update(void) { - register cell *bp, *sp; - register regcell so, cur_so = 0; - register int i, ccol, j; - sigset_t sigset, osigset; - static struct shape *lastshape; + cell *bp, *sp; + regcell so, cur_so = 0; + int i, ccol, j; + sigset_t nsigset, osigset; + static const struct shape *lastshape; - sigemptyset(&sigset); - sigaddset(&sigset, SIGTSTP); - (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); + sigemptyset(&nsigset); + sigaddset(&nsigset, SIGTSTP); + (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); /* always leave cursor after last displayed point */ curscreen[D_LAST * B_COLS - 1] = -1; @@ -396,7 +395,6 @@ scr_update() /* draw preview of nextpattern */ if (showpreview && (nextshape != lastshape)) { - int i; static int r=5, c=2; int tr, tc, t; @@ -483,13 +481,11 @@ scr_update() * (We need its length in case we have to overwrite with blanks.) */ void -scr_msg(s, set) - register char *s; - int set; +scr_msg(char *s, int set) { if (set || CEstr == NULL) { - register int l = strlen(s); + int l = strlen(s); moveto(Rows - 2, ((Cols - l) >> 1) - 1); if (set)