Changeset ebe70f1 in mainline for uspace/app/tetris/input.c


Ignore:
Timestamp:
2009-06-09T11:10:31Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3afd24
Parents:
080ad7f
Message:

slightly cleanup the horrible mess of tetris
introduce colors

File:
1 edited

Legend:

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

    r080ad7f rebe70f1  
    3737
    3838/** @addtogroup tetris
    39  * @{ 
     39 * @{
    4040 */
    4141/** @file
     
    9393 *
    9494 */
    95 int
    96 rwait(struct timeval *tvp)
     95int rwait(struct timeval *tvp)
    9796{
    9897        struct timeval starttv, endtv, *s;
    9998        static ipc_call_t charcall;
    10099        ipcarg_t rc;
    101 
     100       
    102101        /*
    103102         * Someday, select() will do this for us.
     
    111110        } else
    112111                s = NULL;
    113 
     112       
    114113        if (!lastchar) {
    115114again:
     
    118117                            CONSOLE_GET_EVENT, &charcall);
    119118                }
     119               
    120120                if (!s)
    121121                        async_wait_for(getchar_inprog, &rc);
     
    125125                        return (0);
    126126                }
     127               
    127128                getchar_inprog = 0;
    128                 if (rc) {
     129                if (rc)
    129130                        stop("end of file, help");
    130                 }
     131               
    131132                if (IPC_GET_ARG1(charcall) == KEY_RELEASE)
    132133                        goto again;
    133 
     134               
    134135                lastchar = IPC_GET_ARG4(charcall);
    135136        }
     137       
    136138        if (tvp) {
    137139                /* since there is input, we may not have timed out */
    138140                (void) gettimeofday(&endtv, NULL);
    139141                TV_SUB(&endtv, &starttv);
    140                 TV_SUB(tvp, &endtv);    /* adjust *tvp by elapsed time */
     142                TV_SUB(tvp, &endtv);  /* adjust *tvp by elapsed time */
    141143        }
    142         return (1);
     144       
     145        return 1;
    143146}
    144147
     
    147150 * Eat any input that might be available.
    148151 */
    149 void
    150 tsleep(void)
     152void tsleep(void)
    151153{
    152154        struct timeval tv;
    153 
     155       
    154156        tv.tv_sec = 0;
    155157        tv.tv_usec = fallrate;
     
    164166 * getchar with timeout.
    165167 */
    166 int
    167 tgetchar(void)
     168int tgetchar(void)
    168169{
    169170        static struct timeval timeleft;
    170171        char c;
    171 
     172       
    172173        /*
    173174         * Reset timeleft to fallrate whenever it is not positive.
     
    180181         */
    181182        if (!TV_POS(&timeleft)) {
    182                 faster();       /* go faster */
     183                faster();  /* go faster */
    183184                timeleft.tv_sec = 0;
    184185                timeleft.tv_usec = fallrate;
    185186        }
     187       
    186188        if (!rwait(&timeleft))
    187                 return (-1);
     189                return -1;
     190       
    188191        c = lastchar;
    189192        lastchar = '\0';
    190         return ((int)(unsigned char)c);
     193        return ((int) (unsigned char) c);
    191194}
    192195
    193196/** @}
    194197 */
    195 
Note: See TracChangeset for help on using the changeset viewer.