Subversion Repositories HelenOS

Rev

Rev 3022 | Rev 4156 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 55... Line 55...
55
 
55
 
56
#include "input.h"
56
#include "input.h"
57
#include "tetris.h"
57
#include "tetris.h"
58
 
58
 
59
#include <async.h>
59
#include <async.h>
60
#include "../../srv/console/console.h"
60
#include <ipc/console.h>
-
 
61
#include <kbd/kbd.h>
61
 
62
 
62
/* return true iff the given timeval is positive */
63
/* return true iff the given timeval is positive */
63
#define TV_POS(tv) \
64
#define TV_POS(tv) \
64
    ((tv)->tv_sec > 0 || ((tv)->tv_sec == 0 && (tv)->tv_usec > 0))
65
    ((tv)->tv_sec > 0 || ((tv)->tv_sec == 0 && (tv)->tv_usec > 0))
65
 
66
 
Line 94... Line 95...
94
rwait(struct timeval *tvp)
95
rwait(struct timeval *tvp)
95
{
96
{
96
    struct timeval starttv, endtv, *s;
97
    struct timeval starttv, endtv, *s;
97
    static ipc_call_t charcall;
98
    static ipc_call_t charcall;
98
    ipcarg_t rc;
99
    ipcarg_t rc;
-
 
100
    int cons_phone;
99
 
101
 
100
    /*
102
    /*
101
     * Someday, select() will do this for us.
103
     * Someday, select() will do this for us.
102
     * Just in case that day is now, and no one has
104
     * Just in case that day is now, and no one has
103
     * changed this, we use a temporary.
105
     * changed this, we use a temporary.
Line 108... Line 110...
108
        s = &endtv;
110
        s = &endtv;
109
    } else
111
    } else
110
        s = NULL;
112
        s = NULL;
111
 
113
 
112
    if (!lastchar) {
114
    if (!lastchar) {
-
 
115
again:
113
        if (!getchar_inprog)
116
        if (!getchar_inprog) {
-
 
117
            cons_phone = get_console_phone();
114
            getchar_inprog = async_send_2(1,CONSOLE_GETCHAR,0,0,&charcall);
118
            getchar_inprog = async_send_2(cons_phone,
-
 
119
                CONSOLE_GETKEY, 0, 0, &charcall);
-
 
120
        }
115
        if (!s)
121
        if (!s)
116
            async_wait_for(getchar_inprog, &rc);
122
            async_wait_for(getchar_inprog, &rc);
117
        else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) {
123
        else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) {
118
            tvp->tv_sec = 0;
124
            tvp->tv_sec = 0;
119
            tvp->tv_usec = 0;
125
            tvp->tv_usec = 0;
Line 121... Line 127...
121
        }
127
        }
122
        getchar_inprog = 0;
128
        getchar_inprog = 0;
123
        if (rc) {
129
        if (rc) {
124
            stop("end of file, help");
130
            stop("end of file, help");
125
        }
131
        }
-
 
132
        if (IPC_GET_ARG1(charcall) == KE_RELEASE)
-
 
133
            goto again;
-
 
134
 
126
        lastchar = IPC_GET_ARG1(charcall);
135
        lastchar = IPC_GET_ARG4(charcall);
127
    }
136
    }
128
    if (tvp) {
137
    if (tvp) {
129
        /* since there is input, we may not have timed out */
138
        /* since there is input, we may not have timed out */
130
        (void) gettimeofday(&endtv, NULL);
139
        (void) gettimeofday(&endtv, NULL);
131
        TV_SUB(&endtv, &starttv);
140
        TV_SUB(&endtv, &starttv);