Center game board on screen. OK from christos@.diff -r1.31 -r1.32 src/games/tetris/screen.c
(nat)
--- src/games/tetris/screen.c 2015/11/06 19:53:37 1.31
+++ src/games/tetris/screen.c 2016/03/03 21:38:55 1.32
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: screen.c,v 1.31 2015/11/06 19:53:37 christos Exp $ */ | 1 | /* $NetBSD: screen.c,v 1.32 2016/03/03 21:38:55 nat Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Chris Torek and Darren F. Provine. | 8 | * Chris Torek and Darren F. Provine. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -187,26 +187,27 @@ scr_set(void) | @@ -187,26 +187,27 @@ scr_set(void) | |||
187 | Rows = ws.ws_row; | 187 | Rows = ws.ws_row; | |
188 | Cols = ws.ws_col; | 188 | Cols = ws.ws_col; | |
189 | } | 189 | } | |
190 | if (Rows == 0) | 190 | if (Rows == 0) | |
191 | Rows = lines; | 191 | Rows = lines; | |
192 | if (Cols == 0) | 192 | if (Cols == 0) | |
193 | Cols = columns; | 193 | Cols = columns; | |
194 | if (Rows < MINROWS || Cols < MINCOLS) { | 194 | if (Rows < MINROWS || Cols < MINCOLS) { | |
195 | (void) fprintf(stderr, | 195 | (void) fprintf(stderr, | |
196 | "the screen is too small: must be at least %dx%d, ", | 196 | "the screen is too small: must be at least %dx%d, ", | |
197 | MINCOLS, MINROWS); | 197 | MINCOLS, MINROWS); | |
198 | stop(""); /* stop() supplies \n */ | 198 | stop(""); /* stop() supplies \n */ | |
199 | } | 199 | } | |
200 | Offset = (Rows - D_LAST + D_FIRST - 2) / 2; | |||
200 | if (tcgetattr(0, &oldtt) < 0) | 201 | if (tcgetattr(0, &oldtt) < 0) | |
201 | stop("tcgetattr() fails"); | 202 | stop("tcgetattr() fails"); | |
202 | newtt = oldtt; | 203 | newtt = oldtt; | |
203 | newtt.c_lflag &= ~(ICANON|ECHO); | 204 | newtt.c_lflag &= ~(ICANON|ECHO); | |
204 | newtt.c_oflag &= ~OXTABS; | 205 | newtt.c_oflag &= ~OXTABS; | |
205 | if (tcsetattr(0, TCSADRAIN, &newtt) < 0) | 206 | if (tcsetattr(0, TCSADRAIN, &newtt) < 0) | |
206 | stop("tcsetattr() fails"); | 207 | stop("tcsetattr() fails"); | |
207 | ospeed = cfgetospeed(&newtt); | 208 | ospeed = cfgetospeed(&newtt); | |
208 | (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); | 209 | (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); | |
209 | 210 | |||
210 | /* | 211 | /* | |
211 | * We made it. We are now in screen mode, modulo TIstr | 212 | * We made it. We are now in screen mode, modulo TIstr | |
212 | * (which we will fix immediately). | 213 | * (which we will fix immediately). | |
@@ -350,27 +351,27 @@ scr_update(void) | @@ -350,27 +351,27 @@ scr_update(void) | |||
350 | bp = &board[D_FIRST * B_COLS]; | 351 | bp = &board[D_FIRST * B_COLS]; | |
351 | sp = &curscreen[D_FIRST * B_COLS]; | 352 | sp = &curscreen[D_FIRST * B_COLS]; | |
352 | for (j = D_FIRST; j < D_LAST; j++) { | 353 | for (j = D_FIRST; j < D_LAST; j++) { | |
353 | ccol = -1; | 354 | ccol = -1; | |
354 | for (i = 0; i < B_COLS; bp++, sp++, i++) { | 355 | for (i = 0; i < B_COLS; bp++, sp++, i++) { | |
355 | if (*sp == (so = *bp)) | 356 | if (*sp == (so = *bp)) | |
356 | continue; | 357 | continue; | |
357 | *sp = so; | 358 | *sp = so; | |
358 | if (i != ccol) { | 359 | if (i != ccol) { | |
359 | if (cur_so && move_standout_mode) { | 360 | if (cur_so && move_standout_mode) { | |
360 | putpad(exit_standout_mode); | 361 | putpad(exit_standout_mode); | |
361 | cur_so = 0; | 362 | cur_so = 0; | |
362 | } | 363 | } | |
363 | moveto(RTOD(j), CTOD(i)); | 364 | moveto(RTOD(j + Offset), CTOD(i)); | |
364 | } | 365 | } | |
365 | if (enter_standout_mode) { | 366 | if (enter_standout_mode) { | |
366 | if (so != cur_so) { | 367 | if (so != cur_so) { | |
367 | setcolor(so); | 368 | setcolor(so); | |
368 | putpad(so ? | 369 | putpad(so ? | |
369 | enter_standout_mode : | 370 | enter_standout_mode : | |
370 | exit_standout_mode); | 371 | exit_standout_mode); | |
371 | cur_so = so; | 372 | cur_so = so; | |
372 | } | 373 | } | |
373 | #ifdef DEBUG | 374 | #ifdef DEBUG | |
374 | char buf[3]; | 375 | char buf[3]; | |
375 | snprintf(buf, sizeof(buf), "%d%d", so, so); | 376 | snprintf(buf, sizeof(buf), "%d%d", so, so); | |
376 | putstr(buf); | 377 | putstr(buf); |
--- src/games/tetris/tetris.c 2015/11/06 19:53:37 1.31
+++ src/games/tetris/tetris.c 2016/03/03 21:38:55 1.32
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tetris.c,v 1.31 2015/11/06 19:53:37 christos Exp $ */ | 1 | /* $NetBSD: tetris.c,v 1.32 2016/03/03 21:38:55 nat Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Chris Torek and Darren F. Provine. | 8 | * Chris Torek and Darren F. Provine. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -52,26 +52,27 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19 | @@ -52,26 +52,27 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19 | |||
52 | #include <stdio.h> | 52 | #include <stdio.h> | |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> | |
54 | #include <string.h> | 54 | #include <string.h> | |
55 | #include <unistd.h> | 55 | #include <unistd.h> | |
56 | 56 | |||
57 | #include "input.h" | 57 | #include "input.h" | |
58 | #include "scores.h" | 58 | #include "scores.h" | |
59 | #include "screen.h" | 59 | #include "screen.h" | |
60 | #include "tetris.h" | 60 | #include "tetris.h" | |
61 | 61 | |||
62 | cell board[B_SIZE]; /* 1 => occupied, 0 => empty */ | 62 | cell board[B_SIZE]; /* 1 => occupied, 0 => empty */ | |
63 | 63 | |||
64 | int Rows, Cols; /* current screen size */ | 64 | int Rows, Cols; /* current screen size */ | |
65 | int Offset; /* used to center board & shapes */ | |||
65 | 66 | |||
66 | static const struct shape *curshape; | 67 | static const struct shape *curshape; | |
67 | const struct shape *nextshape; | 68 | const struct shape *nextshape; | |
68 | 69 | |||
69 | long fallrate; /* less than 1 million; smaller => faster */ | 70 | long fallrate; /* less than 1 million; smaller => faster */ | |
70 | 71 | |||
71 | int score; /* the obvious thing */ | 72 | int score; /* the obvious thing */ | |
72 | gid_t gid, egid; | 73 | gid_t gid, egid; | |
73 | 74 | |||
74 | char key_msg[100]; | 75 | char key_msg[100]; | |
75 | int showpreview; | 76 | int showpreview; | |
76 | int nocolor; | 77 | int nocolor; | |
77 | 78 |
--- src/games/tetris/tetris.h 2014/07/13 16:23:55 1.14
+++ src/games/tetris/tetris.h 2016/03/03 21:38:55 1.15
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tetris.h,v 1.14 2014/07/13 16:23:55 pgoyette Exp $ */ | 1 | /* $NetBSD: tetris.h,v 1.15 2016/03/03 21:38:55 nat Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Chris Torek and Darren F. Provine. | 8 | * Chris Torek and Darren F. Provine. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -63,26 +63,27 @@ extern cell board[B_SIZE]; /* 1 => occup | @@ -63,26 +63,27 @@ extern cell board[B_SIZE]; /* 1 => occup | |||
63 | #define D_LAST 22 | 63 | #define D_LAST 22 | |
64 | 64 | |||
65 | /* the active area (rows) */ | 65 | /* the active area (rows) */ | |
66 | #define A_FIRST 1 | 66 | #define A_FIRST 1 | |
67 | #define A_LAST 21 | 67 | #define A_LAST 21 | |
68 | 68 | |||
69 | /* | 69 | /* | |
70 | * Minimum display size. | 70 | * Minimum display size. | |
71 | */ | 71 | */ | |
72 | #define MINROWS 23 | 72 | #define MINROWS 23 | |
73 | #define MINCOLS 40 | 73 | #define MINCOLS 40 | |
74 | 74 | |||
75 | extern int Rows, Cols; /* current screen size */ | 75 | extern int Rows, Cols; /* current screen size */ | |
76 | extern int Offset; /* vert. offset to center board */ | |||
76 | 77 | |||
77 | /* | 78 | /* | |
78 | * Translations from board coordinates to display coordinates. | 79 | * Translations from board coordinates to display coordinates. | |
79 | * As with board coordinates, display coordiates are zero origin. | 80 | * As with board coordinates, display coordiates are zero origin. | |
80 | */ | 81 | */ | |
81 | #define RTOD(x) ((x) - 1) | 82 | #define RTOD(x) ((x) - 1) | |
82 | #define CTOD(x) ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1)) | 83 | #define CTOD(x) ((x) * 2 + (((Cols - 2 * B_COLS) >> 1) - 1)) | |
83 | 84 | |||
84 | /* | 85 | /* | |
85 | * A `shape' is the fundamental thing that makes up the game. There | 86 | * A `shape' is the fundamental thing that makes up the game. There | |
86 | * are 7 basic shapes, each consisting of four `blots': | 87 | * are 7 basic shapes, each consisting of four `blots': | |
87 | * | 88 | * | |
88 | * X.X X.X X.X | 89 | * X.X X.X X.X |