-/* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */
+/* $NetBSD: tetris.c,v 1.8 1999/02/11 02:34:24 simonb Exp $ */
/*-
* Copyright (c) 1992, 1993
* @(#)tetris.c 8.1 (Berkeley) 5/31/93
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1992, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
/*
#include "screen.h"
#include "tetris.h"
-void onintr __P((int));
-void usage __P((void));
+static void elide __P((void));
+static void setup_board __P((void));
+ int main __P((int, char **));
+ void onintr __P((int)) __attribute__((__noreturn__));
+ void usage __P((void)) __attribute__((__noreturn__));
/*
* Set up the initial board. The bottom display row is completely set,
p = board;
for (i = B_SIZE; i; i--)
-#ifndef mips
*p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2;
-#else /* work around compiler bug */
- *p++ = i <= (2 * B_COLS) || (i % B_COLS) < 2 ? 1 : 0;
-#endif
}
/*
for (j = B_COLS - 2; *p++ != 0;) {
if (--j <= 0) {
/* this row is to be elided */
- bzero(&board[base], B_COLS - 2);
+ memset(&board[base], 0, B_COLS - 2);
scr_update();
tsleep();
while (--base != 0)
char *argv[];
{
register int pos, c;
- register struct shape *curshape;
register char *keys;
register int level = 2;
char key_write[6][10];
keys = "jkl pq";
- while ((ch = getopt(argc, argv, "k:l:s")) != EOF)
+ while ((ch = getopt(argc, argv, "k:l:ps")) != -1)
switch(ch) {
case 'k':
if (strlen(keys = optarg) != 6)
exit(1);
}
break;
+ case 'p':
+ showpreview = 1;
+ break;
case 's':
showscores(0);
exit(0);
scr_set();
pos = A_FIRST*B_COLS + (B_COLS/2)-1;
+ nextshape = randshape();
curshape = randshape();
scr_msg(key_msg, 1);
* Choose a new shape. If it does not fit,
* the game is over.
*/
- curshape = randshape();
+ curshape = nextshape;
+ nextshape = randshape();
pos = A_FIRST*B_COLS + (B_COLS/2)-1;
if (!fits_in(curshape, pos))
break;
}
continue;
}
- if (c == '\f')
+ if (c == '\f') {
scr_clear();
+ scr_msg(key_msg, 1);
+ }
}
scr_clear();
void
usage()
{
- (void)fprintf(stderr, "usage: tetris [-s] [-l level] [-keys]\n");
+ (void)fprintf(stderr, "usage: tetris [-ps] [-l level] [-keys]\n");
exit(1);
}