Ignore:
File:
1 edited

Legend:

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

    r09f41d3 r28a5ebd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
    32 * Copyright (c) 2011 Martin Decky
    43 * All rights reserved.
     
    5554 */
    5655
    57 #include <errno.h>
    5856#include <stdio.h>
    5957#include <stdlib.h>
     
    7371static int isset;               /* true => terminal is in game mode */
    7472
    75 static bool use_rgb;          /* true => use RGB colors */
    76 static bool use_color;          /* true => use indexed colors */
     73static bool use_color;          /* true => use colors */
    7774
    7875static const struct shape *lastshape;
     
    8077static usec_t timeleft = 0;
    8178
    82 bool size_changed;
    8379console_ctrl_t *console;
    8480
     
    9591static void start_standout(uint32_t color)
    9692{
    97         uint8_t bg;
    98         uint8_t attr;
    99 
    10093        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);
    11496}
    11597
     
    144126        console_cursor_visibility(console, 0);
    145127        resume_normal();
    146         scr_set();
     128        scr_clear();
    147129}
    148130
     
    160142}
    161143
    162 static void get_display_color_sup(bool *rgb, bool *color)
     144static bool get_display_color_sup(void)
    163145{
    164146        sysarg_t ccap;
    165147        errno_t rc = console_get_color_cap(console, &ccap);
    166148
    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);
    179153}
    180154
     
    194168        }
    195169
    196         get_display_color_sup(&use_rgb, &use_color);
     170        use_color = get_display_color_sup();
    197171
    198172        if ((Rows < MINROWS) || (Cols < MINCOLS)) {
     
    200174
    201175                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)",
    203177                    MINROWS, MINCOLS);
    204178                stop(smallscr);
     
    223197
    224198        fprintf(stderr, "aborting: %s", why);
    225         exit(1);
     199        abort();
    226200}
    227201
     
    366340{
    367341        usec_t timeout = fallrate;
    368         errno_t rc;
    369342
    370343        while (timeout > 0) {
    371344                cons_event_t event;
    372345
    373                 rc = console_get_event_timeout(console, &event, &timeout);
    374                 if (rc == ETIMEOUT)
     346                if (!console_get_event_timeout(console, &event, &timeout))
    375347                        break;
    376                 if (rc != EOK)
    377                         exit(1);
    378348        }
    379349}
     
    384354int tgetchar(void)
    385355{
    386         errno_t rc;
    387 
    388356        /*
    389357         * Reset timeleft to fallrate whenever it is not positive
     
    408376                cons_event_t event;
    409377
    410                 rc = console_get_event_timeout(console, &event, &timeleft);
    411                 if (rc == ETIMEOUT) {
     378                if (!console_get_event_timeout(console, &event, &timeleft)) {
    412379                        timeleft = 0;
    413380                        return -1;
    414381                }
    415                 if (rc != EOK)
    416                         exit(1);
    417 
    418                 if (event.type == CEV_RESIZE)
    419                         size_changed = true;
    420382
    421383                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
     
    432394{
    433395        char32_t c = 0;
    434         errno_t rc;
    435396
    436397        while (c == 0) {
    437398                cons_event_t event;
    438399
    439                 rc = console_get_event(console, &event);
    440                 if (rc == ETIMEOUT)
     400                if (!console_get_event(console, &event))
    441401                        return -1;
    442                 if (rc != EOK)
    443                         exit(1);
    444402
    445403                if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS)
Note: See TracChangeset for help on using the changeset viewer.