Changes in uspace/app/tetris/screen.c [79ae36dd:96b02eb9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/screen.c
r79ae36dd r96b02eb9 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 1 /* $OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray Exp $ */ 2 /* $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $ */ 3 4 /*- 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Chris Torek and Darren F. Provine. 4 10 * 5 11 * Redistribution and use in source and binary forms, with or without 6 12 * modification, are permitted provided that the following conditions 7 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 8 22 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 16 34 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** Attributations 30 * 31 * screen.c 8.1 (Berkeley) 5/31/93 32 * NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft 33 * OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray 34 * 35 * Based upon BSD Tetris 36 * 37 * Copyright (c) 1992, 1993 38 * The Regents of the University of California. 39 * Distributed under BSD license. 40 * 41 * This code is derived from software contributed to Berkeley by 42 * Chris Torek and Darren F. Provine. 43 * 35 * @(#)screen.c 8.1 (Berkeley) 5/31/93 44 36 */ 45 37 … … 77 69 static const struct shape *lastshape; 78 70 79 static suseconds_t timeleft = 0;80 81 console_ctrl_t *console;82 83 71 84 72 /* … … 94 82 static void start_standout(uint32_t color) 95 83 { 96 console_flush(console);97 console_set_rgb_color( console, 0xffffff,84 fflush(stdout); 85 console_set_rgb_color(fphone(stdout), 0xffffff, 98 86 use_color ? color : 0x000000); 99 87 } … … 101 89 static void resume_normal(void) 102 90 { 103 console_flush(console);104 console_set_style( console, STYLE_NORMAL);91 fflush(stdout); 92 console_set_style(fphone(stdout), STYLE_NORMAL); 105 93 } 106 94 107 95 void clear_screen(void) 108 96 { 109 console_clear( console);97 console_clear(fphone(stdout)); 110 98 moveto(0, 0); 111 99 } … … 117 105 { 118 106 resume_normal(); 119 console_clear( console);107 console_clear(fphone(stdout)); 120 108 curscore = -1; 121 109 memset(curscreen, 0, sizeof(curscreen)); … … 127 115 void scr_init(void) 128 116 { 129 console_cursor_visibility( console, 0);117 console_cursor_visibility(fphone(stdout), 0); 130 118 resume_normal(); 131 119 scr_clear(); … … 134 122 void moveto(sysarg_t r, sysarg_t c) 135 123 { 136 console_flush(console);137 console_set_pos( console, c, r);124 fflush(stdout); 125 console_set_pos(fphone(stdout), c, r); 138 126 } 139 127 … … 142 130 static int get_display_size(winsize_t *ws) 143 131 { 144 return console_get_size( console, &ws->ws_col, &ws->ws_row);132 return console_get_size(fphone(stdout), &ws->ws_col, &ws->ws_row); 145 133 } 146 134 … … 148 136 { 149 137 sysarg_t ccap; 150 int rc = console_get_color_cap( console, &ccap);138 int rc = console_get_color_cap(fphone(stdout), &ccap); 151 139 152 140 if (rc != 0) … … 191 179 void scr_end(void) 192 180 { 193 console_cursor_visibility( console, 1);181 console_cursor_visibility(fphone(stdout), 1); 194 182 } 195 183 … … 314 302 resume_normal(); 315 303 316 console_flush(console);304 fflush(stdout); 317 305 } 318 306 … … 334 322 } 335 323 336 /** Sleep for the current turn time337 *338 * Eat any input that might be available.339 *340 */341 void tsleep(void)342 {343 suseconds_t timeout = fallrate;344 345 while (timeout > 0) {346 kbd_event_t event;347 348 if (!console_get_kbd_event_timeout(console, &event, &timeout))349 break;350 }351 }352 353 /** Get char with timeout354 *355 */356 int tgetchar(void)357 {358 /*359 * Reset timeleft to fallrate whenever it is not positive360 * and increase speed.361 */362 363 if (timeleft <= 0) {364 faster();365 timeleft = fallrate;366 }367 368 /*369 * Wait to see if there is any input. If so, take it and370 * update timeleft so that the next call to tgetchar()371 * will not wait as long. If there is no input,372 * make timeleft zero and return -1.373 */374 375 wchar_t c = 0;376 377 while (c == 0) {378 kbd_event_t event;379 380 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {381 timeleft = 0;382 return -1;383 }384 385 if (event.type == KEY_PRESS)386 c = event.c;387 }388 389 return (int) c;390 }391 392 /** Get char without timeout393 *394 */395 int twait(void)396 {397 wchar_t c = 0;398 399 while (c == 0) {400 kbd_event_t event;401 402 if (!console_get_kbd_event(console, &event))403 return -1;404 405 if (event.type == KEY_PRESS)406 c = event.c;407 }408 409 return (int) c;410 }411 412 324 /** @} 413 325 */
Note:
See TracChangeset
for help on using the changeset viewer.