Changeset ebe70f1 in mainline for uspace/app/tetris/screen.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/screen.c
r080ad7f rebe70f1 37 37 38 38 /** @addtogroup tetris 39 * @{ 39 * @{ 40 40 */ 41 41 /** @file … … 57 57 #include <io/console.h> 58 58 59 static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ 59 #define STOP (B_COLS - 3) 60 61 static cell curscreen[B_SIZE]; /* non-zero => standout (or otherwise marked) */ 60 62 static int curscore; 61 static int isset; /* true => terminal is in game mode */ 63 static int isset; /* true => terminal is in game mode */ 64 65 static const struct shape *lastshape; 62 66 63 67 … … 72 76 } 73 77 74 static void start_standout( void)75 { 76 console_set_rgb_color(fphone(stdout), 0xf0f0f0, 0);78 static void start_standout(uint32_t color) 79 { 80 console_set_rgb_color(fphone(stdout), 0xf0f0f0, color); 77 81 } 78 82 … … 91 95 * Clear the screen, forgetting the current contents in the process. 92 96 */ 93 void 94 scr_clear(void) 95 { 96 97 void scr_clear(void) 98 { 97 99 resume_normal(); 98 100 console_clear(fphone(stdout)); 99 101 curscore = -1; 100 memset( (char *)curscreen, 0, sizeof(curscreen));102 memset(curscreen, 0, sizeof(curscreen)); 101 103 } 102 104 … … 104 106 * Set up screen 105 107 */ 106 void 107 scr_init(void) 108 void scr_init(void) 108 109 { 109 110 console_cursor_visibility(fphone(stdout), 0); … … 127 128 * Set up screen mode. 128 129 */ 129 void 130 scr_set(void) 130 void scr_set(void) 131 131 { 132 132 winsize_t ws; 133 134 Rows = 0, Cols = 0; 133 134 Rows = 0; 135 Cols = 0; 136 135 137 if (get_display_size(&ws) == 0) { 136 138 Rows = ws.ws_row; 137 139 Cols = ws.ws_col; 138 140 } 139 if (Rows < MINROWS || Cols < MINCOLS) { 141 142 if ((Rows < MINROWS) || (Cols < MINCOLS)) { 140 143 char smallscr[55]; 141 144 142 145 snprintf(smallscr, sizeof(smallscr), 143 146 "the screen is too small (must be at least %dx%d)", … … 146 149 } 147 150 isset = 1; 148 151 149 152 scr_clear(); 150 153 } … … 153 156 * End screen mode. 154 157 */ 155 void 156 scr_end(void) 157 { 158 } 159 160 void 161 stop(char *why) 162 { 163 158 void scr_end(void) 159 { 160 console_cursor_visibility(fphone(stdout), 1); 161 } 162 163 void stop(char *why) 164 { 164 165 if (isset) 165 166 scr_end(); 167 166 168 errx(1, "aborting: %s", why); 167 169 } 168 170 169 170 171 /* 171 172 * Update the screen. 172 173 */ 173 void 174 scr_update(void) 175 { 176 cell *bp, *sp; 177 cell so, cur_so = 0; 178 int i, ccol, j; 179 static const struct shape *lastshape; 180 181 /* always leave cursor after last displayed point */ 174 void scr_update(void) 175 { 176 cell *bp; 177 cell *sp; 178 cell so; 179 cell cur_so = 0; 180 int i; 181 int j; 182 int ccol; 183 184 /* Always leave cursor after last displayed point */ 182 185 curscreen[D_LAST * B_COLS - 1] = -1; 183 186 184 187 if (score != curscore) { 185 188 moveto(0, 0); … … 187 190 curscore = score; 188 191 } 189 190 /* draw preview of next pattern */191 if ( showpreview&& (nextshape != lastshape)) {192 193 /* Draw preview of next pattern */ 194 if ((showpreview) && (nextshape != lastshape)) { 192 195 int i; 193 static int r =5, c=2;196 static int r = 5, c = 2; 194 197 int tr, tc, t; 195 198 196 199 lastshape = nextshape; 197 198 /* clean */200 201 /* Clean */ 199 202 resume_normal(); 200 moveto(r-1, c-1); putstr(" "); 201 moveto(r, c-1); putstr(" "); 202 moveto(r+1, c-1); putstr(" "); 203 moveto(r+2, c-1); putstr(" "); 204 205 moveto(r-3, c-2); 203 moveto(r - 1, c - 1); 204 putstr(" "); 205 moveto(r, c - 1); 206 putstr(" "); 207 moveto(r + 1, c - 1); 208 putstr(" "); 209 moveto(r + 2, c - 1); 210 putstr(" "); 211 212 moveto(r - 3, c - 2); 206 213 putstr("Next shape:"); 207 208 /* draw */209 start_standout( );214 215 /* Draw */ 216 start_standout(nextshape->color); 210 217 moveto(r, 2 * c); 211 218 putstr(" "); … … 213 220 t = c + r * B_COLS; 214 221 t += nextshape->off[i]; 215 222 216 223 tr = t / B_COLS; 217 224 tc = t % B_COLS; 218 225 219 226 moveto(tr, 2*tc); 220 227 putstr(" "); … … 222 229 resume_normal(); 223 230 } 224 231 225 232 bp = &board[D_FIRST * B_COLS]; 226 233 sp = &curscreen[D_FIRST * B_COLS]; … … 230 237 if (*sp == (so = *bp)) 231 238 continue; 239 232 240 *sp = so; 233 241 if (i != ccol) { … … 238 246 moveto(RTOD(j), CTOD(i)); 239 247 } 248 240 249 if (so != cur_so) { 241 250 if (so) 242 start_standout( );251 start_standout(so); 243 252 else 244 253 resume_normal(); … … 246 255 } 247 256 putstr(" "); 248 257 249 258 ccol = i + 1; 250 259 /* … … 256 265 * the next cell is a different color. 257 266 */ 258 #define STOP (B_COLS - 3) 259 if ( i > STOP || sp[1] != bp[1] || so != bp[1])267 268 if ((i > STOP) || (sp[1] != bp[1]) || (so != bp[1])) 260 269 continue; 270 261 271 if (sp[2] != bp[2]) 262 272 sp[1] = -1; 263 else if ( i < STOP && so == bp[2] && sp[3] != bp[3]) {273 else if ((i < STOP) && (so == bp[2]) && (sp[3] != bp[3])) { 264 274 sp[2] = -1; 265 275 sp[1] = -1; … … 267 277 } 268 278 } 279 269 280 if (cur_so) 270 281 resume_normal(); 271 fflush(stdout); 272 } 273 274 /* 275 * Write a message (set!=0), or clear the same message (set==0). 282 283 fflush(stdout); 284 } 285 286 /* 287 * Write a message (set != 0), or clear the same message (set == 0). 276 288 * (We need its length in case we have to overwrite with blanks.) 277 289 */ 278 void 279 scr_msg(char *s, int set) 280 { 281 290 void scr_msg(char *s, int set) 291 { 282 292 int l = str_size(s); 283 293 284 294 moveto(Rows - 2, ((Cols - l) >> 1) - 1); 295 285 296 if (set) 286 297 putstr(s); … … 292 303 /** @} 293 304 */ 294
Note:
See TracChangeset
for help on using the changeset viewer.