Changeset f1b4e74 in mainline
- Timestamp:
- 2006-06-02T17:45:07Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a9bd960c
- Parents:
- 0c6984e
- Location:
- tetris
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tetris/screen.c
r0c6984e rf1b4e74 47 47 #include <io/stream.h> 48 48 49 50 #include <async.h> 49 51 #include "screen.h" 50 52 #include "tetris.h" 53 #include "../console/console.h" 51 54 52 55 static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ … … 59 62 static void stopset(int); 60 63 61 /*62 * Capabilities from TERMCAP.63 */64 char PC, *BC, *UP; /* tgoto requires globals: ugh! */65 66 64 static char 67 *bcstr, /* backspace char */ 68 *CEstr, /* clear to end of line */ 69 *CLstr, /* clear screen */ 70 *CMstr, /* cursor motion string */ 71 #ifdef unneeded 72 *CRstr, /* "\r" equivalent */ 73 #endif 74 *HOstr, /* cursor home */ 75 *LLstr, /* last line, first column */ 76 *pcstr, /* pad character */ 77 *TEstr, /* end cursor motion mode */ 78 *TIstr; /* begin cursor motion mode */ 79 char 80 *SEstr, /* end standout mode */ 81 *SOstr; /* begin standout mode */ 82 static int 83 COnum, /* co# value */ 84 LInum, /* li# value */ 85 MSflag; /* can move in standout mode */ 86 87 88 struct tcsinfo { /* termcap string info; some abbrevs above */ 89 char tcname[3]; 90 char **tcaddr; 91 } tcstrings[] = { 92 {"bc", &bcstr}, 93 {"ce", &CEstr}, 94 {"cl", &CLstr}, 95 {"cm", &CMstr}, 96 #ifdef unneeded 97 {"cr", &CRstr}, 98 #endif 99 {"le", &BC}, /* move cursor left one space */ 100 {"pc", &pcstr}, 101 {"se", &SEstr}, 102 {"so", &SOstr}, 103 {"te", &TEstr}, 104 {"ti", &TIstr}, 105 {"up", &UP}, /* cursor up */ 106 { {0}, NULL} 65 *CEstr; /* clear to end of line */ 66 67 68 /* 69 * putstr() is for unpadded strings (either as in termcap(5) or 70 * simply literal strings); 71 */ 72 #define putstr(s) puts(s) 73 74 static int con_phone; 75 76 77 78 static void set_style(int fgcolor, int bgcolor) 79 { 80 send_call_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor); 81 } 82 83 static void start_standout(void) 84 { 85 set_style(0, 0xe0e0e0); 86 } 87 88 static void resume_normal(void) 89 { 90 set_style(0xe0e0e0, 0); 91 } 92 93 /* 94 * Clear the screen, forgetting the current contents in the process. 95 */ 96 void 97 scr_clear(void) 98 { 99 100 send_call(con_phone, CONSOLE_CLEAR, 0); 101 curscore = -1; 102 memset((char *)curscreen, 0, sizeof(curscreen)); 103 } 104 105 /* 106 * Set up screen 107 */ 108 void 109 scr_init(void) 110 { 111 con_phone = get_fd_phone(1); 112 resume_normal(); 113 scr_clear(); 114 } 115 116 static void moveto(int r, int c) 117 { 118 send_call_2(con_phone, CONSOLE_GOTO, r, c); 119 } 120 121 static void fflush(void) 122 { 123 send_call(con_phone, CONSOLE_FLUSH, 0); 124 } 125 126 struct winsize { 127 ipcarg_t ws_row; 128 ipcarg_t ws_col; 107 129 }; 108 130 109 /* This is where we will actually stuff the information */ 110 111 static char combuf[1024], tbuf[1024]; 112 113 114 /* 115 * Routine used by tputs(). 116 */ 117 int 118 put(int c) 119 { 120 121 return (putchar(c)); 122 } 123 124 /* 125 * putstr() is for unpadded strings (either as in termcap(5) or 126 * simply literal strings); putpad() is for padded strings with 127 * count=1. (See screen.h for putpad().) 128 */ 129 #define putstr(s) (void)fputs(s, stdout) 130 #define moveto(r, c) putpad(tgoto(CMstr, c, r)) 131 132 static int con_phone; 133 134 /* 135 * Set up from termcap. 136 */ 137 void 138 scr_init(void) 139 { 140 con_phone = get_fd_phone(1); 141 } 142 131 static int get_display_size(struct winsize *ws) 132 { 133 return sync_send_2(con_phone, CONSOLE_GETSIZE, 0, 0, &ws->ws_row, &ws->ws_col); 134 } 143 135 144 136 static void … … 158 150 { 159 151 struct winsize ws; 160 struct termios newtt;161 void (*ttou)(int);162 152 163 153 Rows = 0, Cols = 0; 164 if ( ioctl(0, TIOCGWINSZ,&ws) == 0) {154 if (get_display_size(&ws) == 0) { 165 155 Rows = ws.ws_row; 166 156 Cols = ws.ws_col; 167 157 } 168 if (Rows == 0)169 Rows = LInum;170 if (Cols == 0)171 Cols = COnum;172 158 if (Rows < MINROWS || Cols < MINCOLS) { 173 159 char smallscr[55]; … … 178 164 stop(smallscr); 179 165 } 180 if (tcgetattr(0, &oldtt) < 0)181 stop("tcgetattr() fails");182 newtt = oldtt;183 newtt.c_lflag &= ~(ICANON|ECHO);184 newtt.c_oflag &= ~OXTABS;185 if (tcsetattr(0, TCSADRAIN, &newtt) < 0)186 stop("tcsetattr() fails");187 188 /*189 * We made it. We are now in screen mode, modulo TIstr190 * (which we will fix immediately).191 */192 if (TIstr)193 putstr(TIstr); /* termcap(5) says this is not padded */194 195 166 isset = 1; 196 167 … … 215 186 } 216 187 217 /*218 * Clear the screen, forgetting the current contents in the process.219 */220 void221 scr_clear(void)222 {223 224 putpad(CLstr);225 curscore = -1;226 memset((char *)curscreen, 0, sizeof(curscreen));227 }228 188 229 189 #if vax && !__GNUC__ … … 248 208 249 209 if (score != curscore) { 250 if (HOstr) 251 putpad(HOstr); 252 else 253 moveto(0, 0); 210 moveto(0, 0); 254 211 (void) printf("Score: %d", score); 255 212 curscore = score; … … 265 222 266 223 /* clean */ 267 putpad(SEstr);224 resume_normal(); 268 225 moveto(r-1, c-1); putstr(" "); 269 226 moveto(r, c-1); putstr(" "); … … 275 232 276 233 /* draw */ 277 if (SOstr) 278 putpad(SOstr); 234 start_standout(); 279 235 moveto(r, 2 * c); 280 putstr( SOstr ? " " : "[]");236 putstr(" "); 281 237 for (i = 0; i < 3; i++) { 282 238 t = c + r * B_COLS; … … 287 243 288 244 moveto(tr, 2*tc); 289 putstr( SOstr ? " " : "[]");245 putstr(" "); 290 246 } 291 putpad(SEstr);247 resume_normal(); 292 248 } 293 249 … … 301 257 *sp = so; 302 258 if (i != ccol) { 303 if (cur_so && MSflag) {304 putpad(SEstr);305 cur_so = 0;306 }307 259 moveto(RTOD(j), CTOD(i)); 308 260 } 309 if ( SOstr) {310 if (so != cur_so) {311 putpad(so ? SOstr : SEstr);312 cur_so = so;313 }314 putstr(" ");315 } else316 putstr(so ? "[]" :" ");261 if (so != cur_so) { 262 if (so) 263 start_standout(); 264 else 265 resume_normal(); 266 cur_so = so; 267 } 268 putstr(" "); 317 269 ccol = i + 1; 318 270 /* … … 335 287 } 336 288 } 337 if (cur_so) 338 putpad(SEstr); 339 /* (void) fflush(stdout); */ 340 /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */ 289 resume_normal(); 290 291 fflush(); 341 292 } 342 293 -
tetris/screen.h
r0c6984e rf1b4e74 37 37 38 38 /* 39 * Capabilities from TERMCAP (used in the score code).40 */41 extern char *SEstr; /* end standout mode */42 extern char *SOstr; /* begin standout mode */43 44 /*45 39 * putpad() is for padded strings with count=1. 46 40 */ -
tetris/tetris.c
r0c6984e rf1b4e74 236 236 key_write[4], key_write[5]); 237 237 238 // (void)signal(SIGINT, onintr);239 238 scr_init(); 240 239 setup_board();
Note:
See TracChangeset
for help on using the changeset viewer.