]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - tetris/screen.c
Update to the new t_agetstr() API.
[bsdgames-darwin.git] / tetris / screen.c
index 99a9d3e71d426d47aedd1598c4114d69ce81996a..49031645b83b3f43f689eee980d1e8612a0a17c0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $       */
+/*     $NetBSD: screen.c,v 1.16 2001/11/02 18:27:00 christos Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -49,6 +49,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <termcap.h>
 #include <termios.h>
 #include <unistd.h>
 
 #include "screen.h"
 #include "tetris.h"
 
-/*
- * XXX - need a <termcap.h>
- */
-int    tgetent __P((char *, const char *));
-int    tgetflag __P((const char *));
-int    tgetnum __P((const char *));
-int    tputs __P((const char *, int, int (*)(int)));
-
 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)();
+static void (*tstp) __P((int));
 
-char   *tgetstr(), *tgoto();
+static void    scr_stop __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 */
@@ -108,27 +101,26 @@ struct tcsinfo {  /* termcap string info; some abbrevs above */
        char tcname[3];
        char **tcaddr;
 } tcstrings[] = {
-       "bc", &bcstr,
-       "ce", &CEstr,
-       "cl", &CLstr,
-       "cm", &CMstr,
+       {"bc", &bcstr},
+       {"ce", &CEstr},
+       {"cl", &CLstr},
+       {"cm", &CMstr},
 #ifdef unneeded
-       "cr", &CRstr,
+       {"cr", &CRstr},
 #endif
-       "le", &BC,              /* move cursor left one space */
-       "pc", &pcstr,
-       "se", &SEstr,
-       "so", &SOstr,
-       "te", &TEstr,
-       "ti", &TIstr,
-       "up", &UP,              /* cursor up */
-       0
+       {"le", &BC},            /* move cursor left one space */
+       {"pc", &pcstr},
+       {"se", &SEstr},
+       {"so", &SOstr},
+       {"te", &TEstr},
+       {"ti", &TIstr},
+       {"up", &UP},            /* cursor up */
+       { {0}, NULL}
 };
 
 /* This is where we will actually stuff the information */
 
-static char combuf[1024], tbuf[1024];
-
+static struct tinfo *info;
 
 /*
  * Routine used by tputs().
@@ -147,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.
@@ -159,43 +159,42 @@ 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;
        } tcflags[] = {
-               "bs", &bsflag,
-               "ms", &MSflag,
+               {"bs", &bsflag},
+               {"ms", &MSflag},
 #ifdef unneeded
-               "nc", &ncflag,
+               {"nc", &ncflag},
 #endif
-               "xs", &xsflag,
-               0
+               {"xs", &xsflag},
+               { {0}, NULL}
        }, tcnums[] = {
-               "co", &COnum,
-               "li", &LInum,
-               "sg", &sgnum,
-               0
+               {"co", &COnum},
+               {"li", &LInum},
+               {"sg", &sgnum},
+               { {0}, NULL}
        };
        
        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";
@@ -257,7 +256,7 @@ scr_set()
        struct winsize ws;
        struct termios newtt;
        sigset_t sigset, osigset;
-       void (*ttou)();
+       void (*ttou) __P((int));
 
        sigemptyset(&sigset);
        sigaddset(&sigset, SIGTSTP);
@@ -285,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)
@@ -345,7 +344,7 @@ scr_end()
 
 void
 stop(why)
-       char *why;
+       const char *why;
 {
 
        if (isset)
@@ -363,7 +362,7 @@ scr_clear()
 
        putpad(CLstr);
        curscore = -1;
-       bzero((char *)curscreen, sizeof(curscreen));
+       memset((char *)curscreen, 0, sizeof(curscreen));
 }
 
 #if vax && !__GNUC__
@@ -382,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);
@@ -395,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++) {