Rev 2787 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 4377 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | #include <err.h> |
48 | #include <err.h> |
49 | #include <stdio.h> |
49 | #include <stdio.h> |
50 | #include <stdlib.h> |
50 | #include <stdlib.h> |
51 | #include <string.h> |
51 | #include <string.h> |
52 | #include <unistd.h> |
52 | #include <unistd.h> |
53 | #include <io/stream.h> |
53 | #include <console.h> |
54 | - | ||
55 | 54 | ||
56 | #include <async.h> |
55 | #include <async.h> |
57 | #include "screen.h" |
56 | #include "screen.h" |
58 | #include "tetris.h" |
57 | #include "tetris.h" |
59 | #include "../../srv/console/console.h" |
58 | #include <ipc/console.h> |
60 | 59 | ||
61 | static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ |
60 | static cell curscreen[B_SIZE]; /* 1 => standout (or otherwise marked) */ |
62 | static int curscore; |
61 | static int curscore; |
63 | static int isset; /* true => terminal is in game mode */ |
62 | static int isset; /* true => terminal is in game mode */ |
64 | 63 | ||
Line 71... | Line 70... | ||
71 | { |
70 | { |
72 | while (*s) |
71 | while (*s) |
73 | putchar(*(s++)); |
72 | putchar(*(s++)); |
74 | } |
73 | } |
75 | 74 | ||
76 | static int con_phone; |
- | |
77 | - | ||
78 | - | ||
79 | - | ||
80 | static void set_style(int fgcolor, int bgcolor) |
- | |
81 | { |
- | |
82 | async_msg_2(con_phone, CONSOLE_SET_STYLE, fgcolor, bgcolor); |
- | |
83 | } |
- | |
84 | - | ||
85 | static void start_standout(void) |
75 | static void start_standout(void) |
86 | { |
76 | { |
87 | set_style(0xf0f0f0, 0); |
77 | console_set_rgb_color(0xf0f0f0, 0); |
88 | } |
78 | } |
89 | 79 | ||
90 | static void resume_normal(void) |
80 | static void resume_normal(void) |
91 | { |
81 | { |
92 | set_style(0, 0xf0f0f0); |
82 | console_set_rgb_color(0, 0xf0f0f0); |
93 | } |
83 | } |
94 | 84 | ||
95 | - | ||
96 | void clear_screen(void) |
85 | void clear_screen(void) |
97 | { |
86 | { |
98 | async_msg_0(con_phone, CONSOLE_CLEAR); |
87 | console_clear(); |
99 | moveto(0, 0); |
88 | moveto(0, 0); |
100 | } |
89 | } |
101 | 90 | ||
102 | /* |
91 | /* |
103 | * Clear the screen, forgetting the current contents in the process. |
92 | * Clear the screen, forgetting the current contents in the process. |
Line 105... | Line 94... | ||
105 | void |
94 | void |
106 | scr_clear(void) |
95 | scr_clear(void) |
107 | { |
96 | { |
108 | 97 | ||
109 | resume_normal(); |
98 | resume_normal(); |
110 | async_msg_0(con_phone, CONSOLE_CLEAR); |
99 | console_clear(); |
111 | curscore = -1; |
100 | curscore = -1; |
112 | memset((char *)curscreen, 0, sizeof(curscreen)); |
101 | memset((char *)curscreen, 0, sizeof(curscreen)); |
113 | } |
102 | } |
114 | 103 | ||
115 | /* |
104 | /* |
116 | * Set up screen |
105 | * Set up screen |
117 | */ |
106 | */ |
118 | void |
107 | void |
119 | scr_init(void) |
108 | scr_init(void) |
120 | { |
109 | { |
121 | con_phone = get_cons_phone(); |
110 | console_cursor_visibility(0); |
122 | async_msg_1(con_phone, CONSOLE_CURSOR_VISIBILITY, 0); |
- | |
123 | resume_normal(); |
111 | resume_normal(); |
124 | scr_clear(); |
112 | scr_clear(); |
125 | } |
113 | } |
126 | 114 | ||
127 | void moveto(int r, int c) |
115 | void moveto(int r, int c) |
128 | { |
116 | { |
129 | async_msg_2(con_phone, CONSOLE_GOTO, r, c); |
117 | console_goto(r, c); |
130 | } |
- | |
131 | - | ||
132 | static void fflush(void) |
- | |
133 | { |
- | |
134 | async_msg_0(con_phone, CONSOLE_FLUSH); |
- | |
135 | } |
118 | } |
136 | 119 | ||
137 | winsize_t winsize; |
120 | winsize_t winsize; |
138 | 121 | ||
139 | static int get_display_size(winsize_t *ws) |
122 | static int get_display_size(winsize_t *ws) |
140 | { |
123 | { |
141 | return async_req_0_2(con_phone, CONSOLE_GETSIZE, &ws->ws_row, |
124 | return console_get_size(&ws->ws_row, &ws->ws_col); |
142 | &ws->ws_col); |
- | |
143 | } |
125 | } |
144 | 126 | ||
145 | /* |
127 | /* |
146 | * Set up screen mode. |
128 | * Set up screen mode. |
147 | */ |
129 | */ |
Line 285... | Line 267... | ||
285 | } |
267 | } |
286 | } |
268 | } |
287 | } |
269 | } |
288 | if (cur_so) |
270 | if (cur_so) |
289 | resume_normal(); |
271 | resume_normal(); |
290 | fflush(); |
272 | fflush(stdout); |
291 | } |
273 | } |
292 | 274 | ||
293 | /* |
275 | /* |
294 | * Write a message (set!=0), or clear the same message (set==0). |
276 | * Write a message (set!=0), or clear the same message (set==0). |
295 | * (We need its length in case we have to overwrite with blanks.) |
277 | * (We need its length in case we have to overwrite with blanks.) |
296 | */ |
278 | */ |
297 | void |
279 | void |
298 | scr_msg(char *s, int set) |
280 | scr_msg(char *s, int set) |
299 | { |
281 | { |
300 | 282 | ||
301 | int l = strlen(s); |
283 | int l = str_size(s); |
302 | 284 | ||
303 | moveto(Rows - 2, ((Cols - l) >> 1) - 1); |
285 | moveto(Rows - 2, ((Cols - l) >> 1) - 1); |
304 | if (set) |
286 | if (set) |
305 | putstr(s); |
287 | putstr(s); |
306 | else |
288 | else |