Changes in uspace/app/tetris/screen.c [09f41d3:28a5ebd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/screen.c
r09f41d3 r28a5ebd 1 1 /* 2 * Copyright (c) 2024 Jiri Svoboda3 2 * Copyright (c) 2011 Martin Decky 4 3 * All rights reserved. … … 55 54 */ 56 55 57 #include <errno.h>58 56 #include <stdio.h> 59 57 #include <stdlib.h> … … 73 71 static int isset; /* true => terminal is in game mode */ 74 72 75 static bool use_rgb; /* true => use RGB colors */ 76 static bool use_color; /* true => use indexed colors */ 73 static bool use_color; /* true => use colors */ 77 74 78 75 static const struct shape *lastshape; … … 80 77 static usec_t timeleft = 0; 81 78 82 bool size_changed;83 79 console_ctrl_t *console; 84 80 … … 95 91 static void start_standout(uint32_t color) 96 92 { 97 uint8_t bg;98 uint8_t attr;99 100 93 console_flush(console); 101 if (use_rgb) { 102 console_set_rgb_color(console, color, 0xffffff); 103 } else if (use_color) { 104 bg = 0x00; 105 attr = 0; 106 if ((color & 0xff0000) != 0) 107 bg |= 0x4; 108 if ((color & 0x00ff00) != 0) 109 bg |= 0x2; 110 if ((color & 0x0000ff) != 0) 111 bg |= 0x1; 112 console_set_color(console, bg, 0x00, attr); 113 } 94 console_set_rgb_color(console, use_color ? color : 0x000000, 95 0xffffff); 114 96 } 115 97 … … 144 126 console_cursor_visibility(console, 0); 145 127 resume_normal(); 146 scr_ set();128 scr_clear(); 147 129 } 148 130 … … 160 142 } 161 143 162 static void get_display_color_sup(bool *rgb, bool *color)144 static bool get_display_color_sup(void) 163 145 { 164 146 sysarg_t ccap; 165 147 errno_t rc = console_get_color_cap(console, &ccap); 166 148 167 if (rc != EOK) { 168 *rgb = false; 169 *color = false; 170 return; 171 } 172 173 if ((ccap & CONSOLE_CAP_CURSORCTL) == 0) { 174 stop("Your screen does not support cursor control.\n"); 175 return; 176 } 177 *rgb = ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB); 178 *color = ((ccap & CONSOLE_CAP_INDEXED) == CONSOLE_CAP_INDEXED); 149 if (rc != EOK) 150 return false; 151 152 return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB); 179 153 } 180 154 … … 194 168 } 195 169 196 get_display_color_sup(&use_rgb, &use_color);170 use_color = get_display_color_sup(); 197 171 198 172 if ((Rows < MINROWS) || (Cols < MINCOLS)) { … … 200 174 201 175 snprintf(smallscr, sizeof(smallscr), 202 "the screen is too small (must be at least %dx%d) \n",176 "the screen is too small (must be at least %dx%d)", 203 177 MINROWS, MINCOLS); 204 178 stop(smallscr); … … 223 197 224 198 fprintf(stderr, "aborting: %s", why); 225 exit(1);199 abort(); 226 200 } 227 201 … … 366 340 { 367 341 usec_t timeout = fallrate; 368 errno_t rc;369 342 370 343 while (timeout > 0) { 371 344 cons_event_t event; 372 345 373 rc = console_get_event_timeout(console, &event, &timeout); 374 if (rc == ETIMEOUT) 346 if (!console_get_event_timeout(console, &event, &timeout)) 375 347 break; 376 if (rc != EOK)377 exit(1);378 348 } 379 349 } … … 384 354 int tgetchar(void) 385 355 { 386 errno_t rc;387 388 356 /* 389 357 * Reset timeleft to fallrate whenever it is not positive … … 408 376 cons_event_t event; 409 377 410 rc = console_get_event_timeout(console, &event, &timeleft); 411 if (rc == ETIMEOUT) { 378 if (!console_get_event_timeout(console, &event, &timeleft)) { 412 379 timeleft = 0; 413 380 return -1; 414 381 } 415 if (rc != EOK)416 exit(1);417 418 if (event.type == CEV_RESIZE)419 size_changed = true;420 382 421 383 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) … … 432 394 { 433 395 char32_t c = 0; 434 errno_t rc;435 396 436 397 while (c == 0) { 437 398 cons_event_t event; 438 399 439 rc = console_get_event(console, &event); 440 if (rc == ETIMEOUT) 400 if (!console_get_event(console, &event)) 441 401 return -1; 442 if (rc != EOK)443 exit(1);444 402 445 403 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
Note:
See TracChangeset
for help on using the changeset viewer.