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