Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tetris/screen.c

    r28a5ebd re116461  
    5454 */
    5555
     56#include <errno.h>
    5657#include <stdio.h>
    5758#include <stdlib.h>
     
    7172static int isset;               /* true => terminal is in game mode */
    7273
    73 static bool use_color;          /* true => use colors */
     74static bool use_rgb;          /* true => use RGB colors */
     75static bool use_color;          /* true => use indexed colors */
    7476
    7577static const struct shape *lastshape;
     
    9193static void start_standout(uint32_t color)
    9294{
     95        uint8_t bg;
     96        uint8_t attr;
     97
    9398        console_flush(console);
    94         console_set_rgb_color(console, use_color ? color : 0x000000,
    95             0xffffff);
     99        if (use_rgb) {
     100                console_set_rgb_color(console, color, 0xffffff);
     101        } else if (use_color) {
     102                bg = 0x00;
     103                attr = 0;
     104                if ((color & 0xff0000) != 0)
     105                        bg |= 0x4;
     106                if ((color & 0x00ff00) != 0)
     107                        bg |= 0x2;
     108                if ((color & 0x0000ff) != 0)
     109                        bg |= 0x1;
     110                console_set_color(console, bg, 0x00, attr);
     111        }
    96112}
    97113
     
    142158}
    143159
    144 static bool get_display_color_sup(void)
     160static void get_display_color_sup(bool *rgb, bool *color)
    145161{
    146162        sysarg_t ccap;
    147163        errno_t rc = console_get_color_cap(console, &ccap);
    148164
    149         if (rc != EOK)
    150                 return false;
    151 
    152         return ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
     165        if (rc != EOK) {
     166                *rgb = false;
     167                *color = false;
     168                return;
     169        }
     170
     171        *rgb = ((ccap & CONSOLE_CAP_RGB) == CONSOLE_CAP_RGB);
     172        *color = ((ccap & CONSOLE_CAP_INDEXED) == CONSOLE_CAP_INDEXED);
    153173}
    154174
     
    168188        }
    169189
    170         use_color = get_display_color_sup();
     190        get_display_color_sup(&use_rgb, &use_color);
    171191
    172192        if ((Rows < MINROWS) || (Cols < MINCOLS)) {
     
    340360{
    341361        usec_t timeout = fallrate;
     362        errno_t rc;
    342363
    343364        while (timeout > 0) {
    344365                cons_event_t event;
    345366
    346                 if (!console_get_event_timeout(console, &event, &timeout))
     367                rc = console_get_event_timeout(console, &event, &timeout);
     368                if (rc == ETIMEOUT)
    347369                        break;
     370                if (rc != EOK)
     371                        exit(1);
    348372        }
    349373}
     
    354378int tgetchar(void)
    355379{
     380        errno_t rc;
     381
    356382        /*
    357383         * Reset timeleft to fallrate whenever it is not positive
     
    376402                cons_event_t event;
    377403
    378                 if (!console_get_event_timeout(console, &event, &timeleft)) {
     404                rc = console_get_event_timeout(console, &event, &timeleft);
     405                if (rc == ETIMEOUT) {
    379406                        timeleft = 0;
    380407                        return -1;
    381408                }
     409                if (rc != EOK)
     410                        exit(1);
    382411
    383412                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
     
    394423{
    395424        char32_t c = 0;
     425        errno_t rc;
    396426
    397427        while (c == 0) {
    398428                cons_event_t event;
    399429
    400                 if (!console_get_event(console, &event))
     430                rc = console_get_event(console, &event);
     431                if (rc == ETIMEOUT)
    401432                        return -1;
     433                if (rc != EOK)
     434                        exit(1);
    402435
    403436                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
Note: See TracChangeset for help on using the changeset viewer.