X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/164f814056645ef1910d5bf4c9147929e07c3a7c..ae987621fe3f97469837617481d558ae8a66683f:/tetris/screen.c diff --git a/tetris/screen.c b/tetris/screen.c index ed9e849b..bc065aaa 100644 --- a/tetris/screen.c +++ b/tetris/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.26 2010/02/03 15:34:39 roy Exp $ */ +/* $NetBSD: screen.c,v 1.33 2017/03/20 22:05:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -89,7 +89,25 @@ moveto(int r, int c) { char *buf; - buf = vtparm(cursor_address, r, c); + buf = tiparm(cursor_address, r, c); + if (buf != NULL) + putpad(buf); +} + +static void +setcolor(int c) +{ + char *buf; + char monochrome[] = "\033[0m"; + if (nocolor == 1) + return; + if (set_a_foreground == NULL) + return; + + if (c == 0 || c == 7) + buf = monochrome; + else + buf = tiparm(set_a_foreground, c); if (buf != NULL) putpad(buf); } @@ -179,6 +197,7 @@ scr_set(void) MINCOLS, MINROWS); stop(""); /* stop() supplies \n */ } + Offset = (Rows - D_LAST + D_FIRST - 2) / 2; if (tcgetattr(0, &oldtt) < 0) stop("tcgetattr() fails"); newtt = oldtt; @@ -193,10 +212,11 @@ scr_set(void) * We made it. We are now in screen mode, modulo TIstr * (which we will fix immediately). */ - if (enter_ca_mode) - putstr(enter_ca_mode); - if (cursor_invisible) - putstr(cursor_invisible); + const char *tstr; + if ((tstr = enter_ca_mode) != NULL) + putstr(tstr); + if ((tstr = cursor_invisible) != NULL) + putstr(tstr); if (tstp != SIG_IGN) (void) signal(SIGTSTP, scr_stop); if (ttou != SIG_IGN) @@ -220,15 +240,16 @@ scr_end(void) sigaddset(&nsigset, SIGTTOU); (void) sigprocmask(SIG_BLOCK, &nsigset, &osigset); /* move cursor to last line */ - if (cursor_to_ll) - putstr(cursor_to_ll); + const char *tstr; + if ((tstr = cursor_to_ll) != NULL) + putstr(tstr); else moveto(Rows - 1, 0); /* exit screen mode */ - if (exit_ca_mode) - putstr(exit_ca_mode); - if (cursor_normal) - putstr(cursor_normal); + if ((tstr = exit_ca_mode) != NULL) + putstr(tstr); + if ((tstr = cursor_normal) != NULL) + putstr(tstr); (void) fflush(stdout); (void) tcsetattr(0, TCSADRAIN, &oldtt); isset = 0; @@ -289,6 +310,7 @@ scr_update(void) putpad(cursor_home); else moveto(0, 0); + setcolor(0); (void) printf("Score: %d", score); curscore = score; } @@ -311,6 +333,7 @@ scr_update(void) putstr("Next shape:"); /* draw */ + setcolor(nextshape->color); putpad(enter_standout_mode); moveto(r, 2*c); putstr(" "); @@ -340,16 +363,23 @@ scr_update(void) putpad(exit_standout_mode); cur_so = 0; } - moveto(RTOD(j), CTOD(i)); + moveto(RTOD(j + Offset), CTOD(i)); } if (enter_standout_mode) { if (so != cur_so) { + setcolor(so); putpad(so ? enter_standout_mode : exit_standout_mode); cur_so = so; } +#ifdef DEBUG + char buf[3]; + snprintf(buf, sizeof(buf), "%d%d", so, so); + putstr(buf); +#else putstr(" "); +#endif } else putstr(so ? "XX" : " "); ccol = i + 1;