Changeset ebe70f1 in mainline for uspace/app/tetris/input.c
- Timestamp:
- 2009-06-09T11:10:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f3afd24
- Parents:
- 080ad7f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/input.c
r080ad7f rebe70f1 37 37 38 38 /** @addtogroup tetris 39 * @{ 39 * @{ 40 40 */ 41 41 /** @file … … 93 93 * 94 94 */ 95 int 96 rwait(struct timeval *tvp) 95 int rwait(struct timeval *tvp) 97 96 { 98 97 struct timeval starttv, endtv, *s; 99 98 static ipc_call_t charcall; 100 99 ipcarg_t rc; 101 100 102 101 /* 103 102 * Someday, select() will do this for us. … … 111 110 } else 112 111 s = NULL; 113 112 114 113 if (!lastchar) { 115 114 again: … … 118 117 CONSOLE_GET_EVENT, &charcall); 119 118 } 119 120 120 if (!s) 121 121 async_wait_for(getchar_inprog, &rc); … … 125 125 return (0); 126 126 } 127 127 128 getchar_inprog = 0; 128 if (rc) {129 if (rc) 129 130 stop("end of file, help"); 130 }131 131 132 if (IPC_GET_ARG1(charcall) == KEY_RELEASE) 132 133 goto again; 133 134 134 135 lastchar = IPC_GET_ARG4(charcall); 135 136 } 137 136 138 if (tvp) { 137 139 /* since there is input, we may not have timed out */ 138 140 (void) gettimeofday(&endtv, NULL); 139 141 TV_SUB(&endtv, &starttv); 140 TV_SUB(tvp, &endtv); 142 TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ 141 143 } 142 return (1); 144 145 return 1; 143 146 } 144 147 … … 147 150 * Eat any input that might be available. 148 151 */ 149 void 150 tsleep(void) 152 void tsleep(void) 151 153 { 152 154 struct timeval tv; 153 155 154 156 tv.tv_sec = 0; 155 157 tv.tv_usec = fallrate; … … 164 166 * getchar with timeout. 165 167 */ 166 int 167 tgetchar(void) 168 int tgetchar(void) 168 169 { 169 170 static struct timeval timeleft; 170 171 char c; 171 172 172 173 /* 173 174 * Reset timeleft to fallrate whenever it is not positive. … … 180 181 */ 181 182 if (!TV_POS(&timeleft)) { 182 faster(); 183 faster(); /* go faster */ 183 184 timeleft.tv_sec = 0; 184 185 timeleft.tv_usec = fallrate; 185 186 } 187 186 188 if (!rwait(&timeleft)) 187 return (-1); 189 return -1; 190 188 191 c = lastchar; 189 192 lastchar = '\0'; 190 return ((int) (unsigned char)c);193 return ((int) (unsigned char) c); 191 194 } 192 195 193 196 /** @} 194 197 */ 195
Note:
See TracChangeset
for help on using the changeset viewer.