57,9 → 57,9 |
#include "tetris.h" |
|
#include <async.h> |
#include <vfs/vfs.h> |
#include <io/console.h> |
#include <ipc/console.h> |
#include <console.h> |
#include <kbd/kbd.h> |
|
/* return true iff the given timeval is positive */ |
#define TV_POS(tv) \ |
92,13 → 92,11 |
* Return 0 => no input, 1 => can read() from stdin |
* |
*/ |
int |
rwait(struct timeval *tvp) |
int rwait(struct timeval *tvp) |
{ |
struct timeval starttv, endtv, *s; |
static ipc_call_t charcall; |
ipcarg_t rc; |
int cons_phone; |
|
/* |
* Someday, select() will do this for us. |
115,10 → 113,10 |
if (!lastchar) { |
again: |
if (!getchar_inprog) { |
cons_phone = console_open(true); |
getchar_inprog = async_send_2(cons_phone, |
CONSOLE_GETKEY, 0, 0, &charcall); |
getchar_inprog = async_send_0(fphone(stdin), |
CONSOLE_GET_EVENT, &charcall); |
} |
|
if (!s) |
async_wait_for(getchar_inprog, &rc); |
else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { |
126,15 → 124,17 |
tvp->tv_usec = 0; |
return (0); |
} |
|
getchar_inprog = 0; |
if (rc) { |
if (rc) |
stop("end of file, help"); |
} |
if (IPC_GET_ARG1(charcall) == KE_RELEASE) |
|
if (IPC_GET_ARG1(charcall) == KEY_RELEASE) |
goto again; |
|
lastchar = IPC_GET_ARG4(charcall); |
} |
|
if (tvp) { |
/* since there is input, we may not have timed out */ |
(void) gettimeofday(&endtv, NULL); |
141,7 → 141,8 |
TV_SUB(&endtv, &starttv); |
TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ |
} |
return (1); |
|
return 1; |
} |
|
/* |
148,8 → 149,7 |
* `sleep' for the current turn time (using select). |
* Eat any input that might be available. |
*/ |
void |
tsleep(void) |
void tsleep(void) |
{ |
struct timeval tv; |
|
165,8 → 165,7 |
/* |
* getchar with timeout. |
*/ |
int |
tgetchar(void) |
int tgetchar(void) |
{ |
static struct timeval timeleft; |
char c; |
185,8 → 184,10 |
timeleft.tv_sec = 0; |
timeleft.tv_usec = fallrate; |
} |
|
if (!rwait(&timeleft)) |
return (-1); |
return -1; |
|
c = lastchar; |
lastchar = '\0'; |
return ((int)(unsigned char)c); |
194,4 → 195,3 |
|
/** @} |
*/ |
|