]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - tetris/screen.c
Be more verbose about teleports, and fix a minor problem in autobot mode.
[bsdgames-darwin.git] / tetris / screen.c
index 6c83147dfb339fb072e5421d46466de0f3f686d9..49031645b83b3f43f689eee980d1e8612a0a17c0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: screen.c,v 1.6 1997/10/14 01:14:28 lukem Exp $ */
+/*     $NetBSD: screen.c,v 1.16 2001/11/02 18:27:00 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -67,14 +67,13 @@ static struct termios oldtt;
 static void (*tstp) __P((int));
 
 static void    scr_stop __P((int));
-static void    stopset __P((int));
+static void    stopset __P((int)) __attribute__((__noreturn__));
 
 
 /*
  * Capabilities from TERMCAP.
  */
-char   PC, *BC, *UP;           /* tgoto requires globals: ugh! */
-speed_t        ospeed;
+short  ospeed;
 
 static char
        *bcstr,                 /* backspace char */
@@ -121,18 +120,17 @@ 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
+int
 put(c)
        int c;
 {
 
-       (void) putchar(c);
+       return (putchar(c));
 }
 
 /*
@@ -141,7 +139,15 @@ 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.
@@ -153,7 +159,7 @@ scr_init()
 #ifdef unneeded
        static int ncflag;
 #endif
-       char *term, *fill;
+       char *term;
        static struct tcninfo { /* termcap numeric and flag info */
                char tcname[3];
                int *tcaddr;
@@ -174,22 +180,21 @@ scr_init()
        
        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;
 
                for (p = tcstrings; p->tcaddr; p++)
-                       *p->tcaddr = tgetstr(p->tcname, &fill);
+                       *p->tcaddr = t_agetstr(info, p->tcname);
        }
        {
                register 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";
@@ -279,8 +284,8 @@ scr_set()
        Cols = COnum;
        if (Rows < MINROWS || Cols < MINCOLS) {
                (void) fprintf(stderr,
-                   "the screen is too small: must be at least %d x %d",
-                   MINROWS, MINCOLS);
+                   "the screen is too small: must be at least %dx%d, ",
+                   MINCOLS, MINROWS);
                stop("");       /* stop() supplies \n */
        }
        if (tcgetattr(0, &oldtt) < 0)
@@ -339,7 +344,7 @@ scr_end()
 
 void
 stop(why)
-       char *why;
+       const char *why;
 {
 
        if (isset)
@@ -357,7 +362,7 @@ scr_clear()
 
        putpad(CLstr);
        curscore = -1;
-       bzero((char *)curscreen, sizeof(curscreen));
+       memset((char *)curscreen, 0, sizeof(curscreen));
 }
 
 #if vax && !__GNUC__
@@ -376,6 +381,7 @@ scr_update()
        register regcell so, cur_so = 0;
        register int i, ccol, j;
        sigset_t sigset, osigset;
+       static const struct shape *lastshape;
 
        sigemptyset(&sigset);
        sigaddset(&sigset, SIGTSTP);
@@ -389,10 +395,45 @@ scr_update()
                        putpad(HOstr);
                else
                        moveto(0, 0);
-               (void) printf("%d", score);
+               (void) printf("Score: %d", score);
                curscore = score;
        }
 
+       /* draw preview of nextpattern */
+       if (showpreview && (nextshape != lastshape)) {
+               int i;
+               static int r=5, c=2;
+               int tr, tc, t; 
+
+               lastshape = nextshape;
+               
+               /* clean */
+               putpad(SEstr);
+               moveto(r-1, c-1); putstr("          ");
+               moveto(r,   c-1); putstr("          ");
+               moveto(r+1, c-1); putstr("          ");
+               moveto(r+2, c-1); putstr("          ");
+
+               moveto(r-3, c-2);
+               putstr("Next shape:");
+                                               
+               /* draw */
+               putpad(SOstr);
+               moveto(r, 2*c);
+               putstr("  ");
+               for(i=0; i<3; i++) {
+                       t = c + r*B_COLS;
+                       t += nextshape->off[i];
+
+                       tr = t / B_COLS;
+                       tc = t % B_COLS;
+
+                       moveto(tr, 2*tc);
+                       putstr("  ");
+               }
+               putpad(SEstr);
+       }
+       
        bp = &board[D_FIRST * B_COLS];
        sp = &curscreen[D_FIRST * B_COLS];
        for (j = D_FIRST; j < D_LAST; j++) {