Rev 4377 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4377 | Rev 4692 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * Copyright (c) 2008 Martin Decky |
3 | * Copyright (c) 2008 Martin Decky |
4 | * Copyright (c) 2008 Pavel Rimsky |
4 | * Copyright (c) 2008 Pavel Rimsky |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
9 | * are met: |
10 | * |
10 | * |
11 | * - Redistributions of source code must retain the above copyright |
11 | * - Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. |
12 | * notice, this list of conditions and the following disclaimer. |
13 | * - Redistributions in binary form must reproduce the above copyright |
13 | * - Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the |
14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. |
15 | * documentation and/or other materials provided with the distribution. |
16 | * - The name of the author may not be used to endorse or promote products |
16 | * - The name of the author may not be used to endorse or promote products |
17 | * derived from this software without specific prior written permission. |
17 | * derived from this software without specific prior written permission. |
18 | * |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
29 | */ |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * @defgroup serial Serial console |
32 | * @defgroup serial Serial console |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...) |
33 | * @brief Serial console services (putc, puts, clear screen, cursor goto,...) |
34 | * @{ |
34 | * @{ |
35 | */ |
35 | */ |
36 | 36 | ||
37 | /** @file |
37 | /** @file |
38 | */ |
38 | */ |
39 | 39 | ||
40 | #include <stdio.h> |
40 | #include <stdio.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | #include <ipc/fb.h> |
43 | #include <ipc/fb.h> |
44 | #include <bool.h> |
44 | #include <bool.h> |
45 | #include <errno.h> |
45 | #include <errno.h> |
46 | #include <console/color.h> |
46 | #include <io/color.h> |
47 | #include <console/style.h> |
47 | #include <io/style.h> |
- | 48 | #include <string.h> |
|
48 | 49 | ||
49 | #include "../console/screenbuffer.h" |
50 | #include "../console/screenbuffer.h" |
50 | #include "main.h" |
51 | #include "main.h" |
51 | #include "serial_console.h" |
52 | #include "serial_console.h" |
52 | 53 | ||
53 | #define MAX_CONTROL 20 |
54 | #define MAX_CONTROL 20 |
54 | 55 | ||
55 | static void serial_sgr(const unsigned int mode); |
56 | static void serial_sgr(const unsigned int mode); |
56 | void serial_putchar(wchar_t ch); |
57 | void serial_putchar(wchar_t ch); |
57 | 58 | ||
58 | static int scr_width; |
59 | static int scr_width; |
59 | static int scr_height; |
60 | static int scr_height; |
60 | static bool color = true; /** True if producing color output. */ |
61 | static bool color = true; /** True if producing color output. */ |
61 | static bool utf8 = false; /** True if producing UTF8 output. */ |
62 | static bool utf8 = false; /** True if producing UTF8 output. */ |
62 | static putc_function_t putc_function; |
63 | static putc_function_t putc_function; |
63 | 64 | ||
64 | /* Allow only 1 connection */ |
65 | /* Allow only 1 connection */ |
65 | static int client_connected = 0; |
66 | static int client_connected = 0; |
66 | 67 | ||
67 | enum sgr_color_index { |
68 | enum sgr_color_index { |
68 | CI_BLACK = 0, |
69 | CI_BLACK = 0, |
69 | CI_RED = 1, |
70 | CI_RED = 1, |
70 | CI_GREEN = 2, |
71 | CI_GREEN = 2, |
71 | CI_BROWN = 3, |
72 | CI_BROWN = 3, |
72 | CI_BLUE = 4, |
73 | CI_BLUE = 4, |
73 | CI_MAGENTA = 5, |
74 | CI_MAGENTA = 5, |
74 | CI_CYAN = 6, |
75 | CI_CYAN = 6, |
75 | CI_WHITE = 7, |
76 | CI_WHITE = 7, |
76 | }; |
77 | }; |
77 | 78 | ||
78 | enum sgr_command { |
79 | enum sgr_command { |
79 | SGR_RESET = 0, |
80 | SGR_RESET = 0, |
80 | SGR_BOLD = 1, |
81 | SGR_BOLD = 1, |
81 | SGR_BLINK = 5, |
82 | SGR_BLINK = 5, |
82 | SGR_REVERSE = 7, |
83 | SGR_REVERSE = 7, |
83 | SGR_NORMAL_INT = 22, |
84 | SGR_NORMAL_INT = 22, |
84 | SGR_BLINK_OFF = 25, |
85 | SGR_BLINK_OFF = 25, |
85 | SGR_REVERSE_OFF = 27, |
86 | SGR_REVERSE_OFF = 27, |
86 | SGR_FGCOLOR = 30, |
87 | SGR_FGCOLOR = 30, |
87 | SGR_BGCOLOR = 40 |
88 | SGR_BGCOLOR = 40 |
88 | }; |
89 | }; |
89 | 90 | ||
90 | static int color_map[] = { |
91 | static int color_map[] = { |
91 | [COLOR_BLACK] = CI_BLACK, |
92 | [COLOR_BLACK] = CI_BLACK, |
92 | [COLOR_BLUE] = CI_RED, |
93 | [COLOR_BLUE] = CI_RED, |
93 | [COLOR_GREEN] = CI_GREEN, |
94 | [COLOR_GREEN] = CI_GREEN, |
94 | [COLOR_CYAN] = CI_CYAN, |
95 | [COLOR_CYAN] = CI_CYAN, |
95 | [COLOR_RED] = CI_RED, |
96 | [COLOR_RED] = CI_RED, |
96 | [COLOR_MAGENTA] = CI_MAGENTA, |
97 | [COLOR_MAGENTA] = CI_MAGENTA, |
97 | [COLOR_YELLOW] = CI_BROWN, |
98 | [COLOR_YELLOW] = CI_BROWN, |
98 | [COLOR_WHITE] = CI_WHITE |
99 | [COLOR_WHITE] = CI_WHITE |
99 | }; |
100 | }; |
100 | 101 | ||
101 | void serial_puts(char *str) |
102 | void serial_puts(char *str) |
102 | { |
103 | { |
103 | while (*str) |
104 | while (*str) |
104 | putc_function(*(str++)); |
105 | putc_function(*(str++)); |
105 | } |
106 | } |
106 | 107 | ||
107 | void serial_putchar(wchar_t ch) |
108 | void serial_putchar(wchar_t ch) |
108 | { |
109 | { |
109 | uint8_t buf[STR_BOUNDS(1)]; |
110 | uint8_t buf[STR_BOUNDS(1)]; |
110 | size_t offs; |
111 | size_t offs; |
111 | size_t i; |
112 | size_t i; |
112 | 113 | ||
113 | if (utf8 != true) { |
114 | if (utf8 != true) { |
114 | if (ch >= 0 && ch < 128) |
115 | if (ch >= 0 && ch < 128) |
115 | (*putc_function)((uint8_t) ch); |
116 | (*putc_function)((uint8_t) ch); |
116 | else |
117 | else |
117 | (*putc_function)('?'); |
118 | (*putc_function)('?'); |
118 | return; |
119 | return; |
119 | } |
120 | } |
120 | 121 | ||
121 | offs = 0; |
122 | offs = 0; |
122 | if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) { |
123 | if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) { |
123 | for (i = 0; i < offs; i++) |
124 | for (i = 0; i < offs; i++) |
124 | (*putc_function)(buf[i]); |
125 | (*putc_function)(buf[i]); |
125 | } else { |
126 | } else { |
126 | (*putc_function)('?'); |
127 | (*putc_function)('?'); |
127 | } |
128 | } |
128 | 129 | ||
129 | } |
130 | } |
130 | 131 | ||
131 | void serial_goto(const unsigned int row, const unsigned int col) |
132 | void serial_goto(const unsigned int col, const unsigned int row) |
132 | { |
133 | { |
133 | if ((row > scr_height) || (col > scr_width)) |
134 | if ((col > scr_width) || (row > scr_height)) |
134 | return; |
135 | return; |
135 | 136 | ||
136 | char control[MAX_CONTROL]; |
137 | char control[MAX_CONTROL]; |
137 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
138 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
138 | serial_puts(control); |
139 | serial_puts(control); |
139 | } |
140 | } |
140 | 141 | ||
141 | void serial_clrscr(void) |
142 | void serial_clrscr(void) |
142 | { |
143 | { |
143 | /* Initialize graphic rendition attributes. */ |
144 | /* Initialize graphic rendition attributes. */ |
144 | serial_sgr(SGR_RESET); |
145 | serial_sgr(SGR_RESET); |
145 | if (color) { |
146 | if (color) { |
146 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
147 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
147 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
148 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
148 | } |
149 | } |
149 | 150 | ||
150 | serial_puts("\033[2J"); |
151 | serial_puts("\033[2J"); |
151 | } |
152 | } |
152 | 153 | ||
153 | void serial_scroll(int i) |
154 | void serial_scroll(int i) |
154 | { |
155 | { |
155 | if (i > 0) { |
156 | if (i > 0) { |
156 | serial_goto(scr_height - 1, 0); |
157 | serial_goto(0, scr_height - 1); |
157 | while (i--) |
158 | while (i--) |
158 | serial_puts("\033D"); |
159 | serial_puts("\033D"); |
159 | } else if (i < 0) { |
160 | } else if (i < 0) { |
160 | serial_goto(0, 0); |
161 | serial_goto(0, 0); |
161 | while (i++) |
162 | while (i++) |
162 | serial_puts("\033M"); |
163 | serial_puts("\033M"); |
163 | } |
164 | } |
164 | } |
165 | } |
165 | 166 | ||
166 | /** ECMA-48 Set Graphics Rendition. */ |
167 | /** ECMA-48 Set Graphics Rendition. */ |
167 | static void serial_sgr(const unsigned int mode) |
168 | static void serial_sgr(const unsigned int mode) |
168 | { |
169 | { |
169 | char control[MAX_CONTROL]; |
170 | char control[MAX_CONTROL]; |
170 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
171 | snprintf(control, MAX_CONTROL, "\033[%um", mode); |
171 | serial_puts(control); |
172 | serial_puts(control); |
172 | } |
173 | } |
173 | 174 | ||
174 | /** Set scrolling region. */ |
175 | /** Set scrolling region. */ |
175 | void serial_set_scroll_region(unsigned last_row) |
176 | void serial_set_scroll_region(unsigned last_row) |
176 | { |
177 | { |
177 | char control[MAX_CONTROL]; |
178 | char control[MAX_CONTROL]; |
178 | snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row); |
179 | snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row); |
179 | serial_puts(control); |
180 | serial_puts(control); |
180 | } |
181 | } |
181 | 182 | ||
182 | void serial_cursor_disable(void) |
183 | void serial_cursor_disable(void) |
183 | { |
184 | { |
184 | serial_puts("\033[?25l"); |
185 | serial_puts("\033[?25l"); |
185 | } |
186 | } |
186 | 187 | ||
187 | void serial_cursor_enable(void) |
188 | void serial_cursor_enable(void) |
188 | { |
189 | { |
189 | serial_puts("\033[?25h"); |
190 | serial_puts("\033[?25h"); |
190 | } |
191 | } |
191 | 192 | ||
192 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
193 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
193 | { |
194 | { |
194 | scr_width = w; |
195 | scr_width = w; |
195 | scr_height = h; |
196 | scr_height = h; |
196 | putc_function = putc_fn; |
197 | putc_function = putc_fn; |
197 | } |
198 | } |
198 | 199 | ||
199 | static void serial_set_style(int style) |
200 | static void serial_set_style(int style) |
200 | { |
201 | { |
201 | if (style == STYLE_EMPHASIS) { |
202 | if (style == STYLE_EMPHASIS) { |
202 | if (color) { |
203 | if (color) { |
203 | serial_sgr(SGR_RESET); |
204 | serial_sgr(SGR_RESET); |
204 | serial_sgr(SGR_FGCOLOR + CI_RED); |
205 | serial_sgr(SGR_FGCOLOR + CI_RED); |
205 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
206 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
206 | } |
207 | } |
207 | serial_sgr(SGR_BOLD); |
208 | serial_sgr(SGR_BOLD); |
208 | } else { |
209 | } else { |
209 | if (color) { |
210 | if (color) { |
210 | serial_sgr(SGR_RESET); |
211 | serial_sgr(SGR_RESET); |
211 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
212 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
212 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
213 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
213 | } |
214 | } |
214 | serial_sgr(SGR_NORMAL_INT); |
215 | serial_sgr(SGR_NORMAL_INT); |
215 | } |
216 | } |
216 | } |
217 | } |
217 | 218 | ||
218 | static void serial_set_idx(unsigned fgcolor, unsigned bgcolor, |
219 | static void serial_set_idx(unsigned fgcolor, unsigned bgcolor, |
219 | unsigned flags) |
220 | unsigned flags) |
220 | { |
221 | { |
221 | if (color) { |
222 | if (color) { |
222 | serial_sgr(SGR_RESET); |
223 | serial_sgr(SGR_RESET); |
223 | serial_sgr(SGR_FGCOLOR + color_map[fgcolor]); |
224 | serial_sgr(SGR_FGCOLOR + color_map[fgcolor]); |
224 | serial_sgr(SGR_BGCOLOR + color_map[bgcolor]); |
225 | serial_sgr(SGR_BGCOLOR + color_map[bgcolor]); |
225 | } else { |
226 | } else { |
226 | if (fgcolor < bgcolor) |
227 | if (fgcolor < bgcolor) |
227 | serial_sgr(SGR_RESET); |
228 | serial_sgr(SGR_RESET); |
228 | else |
229 | else |
229 | serial_sgr(SGR_REVERSE); |
230 | serial_sgr(SGR_REVERSE); |
230 | } |
231 | } |
231 | } |
232 | } |
232 | 233 | ||
233 | static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor) |
234 | static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor) |
234 | { |
235 | { |
235 | if (fgcolor < bgcolor) |
236 | if (fgcolor < bgcolor) |
236 | serial_sgr(SGR_REVERSE_OFF); |
237 | serial_sgr(SGR_REVERSE_OFF); |
237 | else |
238 | else |
238 | serial_sgr(SGR_REVERSE); |
239 | serial_sgr(SGR_REVERSE); |
239 | } |
240 | } |
240 | 241 | ||
241 | static void serial_set_attrs(const attrs_t *a) |
242 | static void serial_set_attrs(const attrs_t *a) |
242 | { |
243 | { |
243 | switch (a->t) { |
244 | switch (a->t) { |
- | 245 | case at_style: |
|
244 | case at_style: serial_set_style(a->a.s.style); break; |
246 | serial_set_style(a->a.s.style); |
- | 247 | break; |
|
- | 248 | case at_rgb: |
|
245 | case at_rgb: serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color); break; |
249 | serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color); |
- | 250 | break; |
|
- | 251 | case at_idx: |
|
246 | case at_idx: serial_set_idx(a->a.i.fg_color, |
252 | serial_set_idx(a->a.i.fg_color, |
247 | a->a.i.bg_color, a->a.i.flags); break; |
253 | a->a.i.bg_color, a->a.i.flags); |
- | 254 | break; |
|
248 | default: break; |
255 | default: |
- | 256 | break; |
|
249 | } |
257 | } |
250 | } |
258 | } |
251 | 259 | ||
252 | /** Draw text data to viewport. |
260 | /** Draw text data to viewport. |
253 | * |
261 | * |
254 | * @param vport Viewport id |
262 | * @param vport Viewport id |
255 | * @param data Text data. |
263 | * @param data Text data. |
256 | * @param x Leftmost column of the area. |
264 | * @param x Leftmost column of the area. |
257 | * @param y Topmost row of the area. |
265 | * @param y Topmost row of the area. |
258 | * @param w Number of rows. |
266 | * @param w Number of rows. |
259 | * @param h Number of columns. |
267 | * @param h Number of columns. |
260 | */ |
268 | */ |
261 | static void draw_text_data(keyfield_t *data, unsigned int x, |
269 | static void draw_text_data(keyfield_t *data, unsigned int x, |
262 | unsigned int y, unsigned int w, unsigned int h) |
270 | unsigned int y, unsigned int w, unsigned int h) |
263 | { |
271 | { |
264 | unsigned int i, j; |
272 | unsigned int i, j; |
265 | keyfield_t *field; |
273 | keyfield_t *field; |
266 | attrs_t *a0, *a1; |
274 | attrs_t *a0, *a1; |
267 | 275 | ||
268 | serial_goto(y, x); |
276 | serial_goto(x, y); |
269 | a0 = &data[0].attrs; |
277 | a0 = &data[0].attrs; |
270 | serial_set_attrs(a0); |
278 | serial_set_attrs(a0); |
271 | 279 | ||
272 | for (j = 0; j < h; j++) { |
280 | for (j = 0; j < h; j++) { |
273 | if (j > 0 && w != scr_width) |
281 | if (j > 0 && w != scr_width) |
274 | serial_goto(y, x); |
282 | serial_goto(x, j); |
275 | 283 | ||
276 | for (i = 0; i < w; i++) { |
284 | for (i = 0; i < w; i++) { |
277 | field = &data[j * w + i]; |
285 | field = &data[j * w + i]; |
278 | 286 | ||
279 | a1 = &field->attrs; |
287 | a1 = &field->attrs; |
280 | if (!attrs_same(*a0, *a1)) |
288 | if (!attrs_same(*a0, *a1)) |
281 | serial_set_attrs(a1); |
289 | serial_set_attrs(a1); |
282 | serial_putchar(field->character); |
290 | serial_putchar(field->character); |
283 | a0 = a1; |
291 | a0 = a1; |
284 | } |
292 | } |
285 | } |
293 | } |
286 | } |
294 | } |
287 | 295 | ||
288 | int lastcol = 0; |
296 | int lastcol = 0; |
289 | int lastrow = 0; |
297 | int lastrow = 0; |
290 | 298 | ||
291 | /** |
299 | /** |
292 | * Main function of the thread serving client connections. |
300 | * Main function of the thread serving client connections. |
293 | */ |
301 | */ |
294 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
302 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
295 | { |
303 | { |
296 | int retval; |
304 | int retval; |
297 | ipc_callid_t callid; |
305 | ipc_callid_t callid; |
298 | ipc_call_t call; |
306 | ipc_call_t call; |
299 | keyfield_t *interbuf = NULL; |
307 | keyfield_t *interbuf = NULL; |
300 | size_t intersize = 0; |
308 | size_t intersize = 0; |
301 | 309 | ||
302 | wchar_t c; |
310 | wchar_t c; |
303 | int col, row, w, h; |
311 | int col, row, w, h; |
304 | int i; |
312 | int i; |
305 | 313 | ||
306 | attrs_t cur_attr; |
314 | attrs_t cur_attr; |
307 | 315 | ||
308 | if (client_connected) { |
316 | if (client_connected) { |
309 | ipc_answer_0(iid, ELIMIT); |
317 | ipc_answer_0(iid, ELIMIT); |
310 | return; |
318 | return; |
311 | } |
319 | } |
312 | 320 | ||
313 | client_connected = 1; |
321 | client_connected = 1; |
314 | ipc_answer_0(iid, EOK); |
322 | ipc_answer_0(iid, EOK); |
315 | 323 | ||
316 | cur_attr.t = at_style; |
324 | cur_attr.t = at_style; |
317 | cur_attr.a.s.style = STYLE_NORMAL; |
325 | cur_attr.a.s.style = STYLE_NORMAL; |
318 | 326 | ||
319 | /* Clear the terminal, set scrolling region |
327 | /* Clear the terminal, set scrolling region |
320 | to 0 - height rows. */ |
328 | to 0 - height rows. */ |
321 | serial_clrscr(); |
329 | serial_clrscr(); |
322 | serial_goto(0, 0); |
330 | serial_goto(0, 0); |
323 | serial_set_scroll_region(scr_height); |
331 | serial_set_scroll_region(scr_height); |
324 | 332 | ||
325 | while (true) { |
333 | while (true) { |
326 | callid = async_get_call(&call); |
334 | callid = async_get_call(&call); |
327 | switch (IPC_GET_METHOD(call)) { |
335 | switch (IPC_GET_METHOD(call)) { |
328 | case IPC_M_PHONE_HUNGUP: |
336 | case IPC_M_PHONE_HUNGUP: |
329 | client_connected = 0; |
337 | client_connected = 0; |
330 | ipc_answer_0(callid, EOK); |
338 | ipc_answer_0(callid, EOK); |
331 | return; |
339 | return; |
332 | case IPC_M_SHARE_OUT: |
340 | case IPC_M_SHARE_OUT: |
333 | /* We accept one area for data interchange */ |
341 | /* We accept one area for data interchange */ |
334 | intersize = IPC_GET_ARG2(call); |
342 | intersize = IPC_GET_ARG2(call); |
335 | if (intersize >= scr_width * scr_height * |
343 | if (intersize >= scr_width * scr_height * |
336 | sizeof(*interbuf)) { |
344 | sizeof(*interbuf)) { |
337 | receive_comm_area(callid, &call, |
345 | receive_comm_area(callid, &call, |
338 | (void *) &interbuf); |
346 | (void *) &interbuf); |
339 | continue; |
347 | continue; |
340 | } |
348 | } |
341 | retval = EINVAL; |
349 | retval = EINVAL; |
342 | break; |
350 | break; |
343 | case FB_DRAW_TEXT_DATA: |
351 | case FB_DRAW_TEXT_DATA: |
344 | col = IPC_GET_ARG1(call); |
352 | col = IPC_GET_ARG1(call); |
345 | row = IPC_GET_ARG2(call); |
353 | row = IPC_GET_ARG2(call); |
346 | w = IPC_GET_ARG3(call); |
354 | w = IPC_GET_ARG3(call); |
347 | h = IPC_GET_ARG4(call); |
355 | h = IPC_GET_ARG4(call); |
348 | if (!interbuf) { |
356 | if (!interbuf) { |
349 | retval = EINVAL; |
357 | retval = EINVAL; |
350 | break; |
358 | break; |
351 | } |
359 | } |
352 | if (col + w > scr_width || row + h > scr_height) { |
360 | if (col + w > scr_width || row + h > scr_height) { |
353 | retval = EINVAL; |
361 | retval = EINVAL; |
354 | break; |
362 | break; |
355 | } |
363 | } |
356 | draw_text_data(interbuf, col, row, w, h); |
364 | draw_text_data(interbuf, col, row, w, h); |
357 | lastrow = row + h - 1; |
- | |
358 | lastcol = col + w; |
365 | lastcol = col + w; |
- | 366 | lastrow = row + h - 1; |
|
359 | retval = 0; |
367 | retval = 0; |
360 | break; |
368 | break; |
361 | case FB_PUTCHAR: |
369 | case FB_PUTCHAR: |
362 | c = IPC_GET_ARG1(call); |
370 | c = IPC_GET_ARG1(call); |
363 | row = IPC_GET_ARG2(call); |
371 | col = IPC_GET_ARG2(call); |
364 | col = IPC_GET_ARG3(call); |
372 | row = IPC_GET_ARG3(call); |
365 | if ((lastcol != col) || (lastrow != row)) |
373 | if ((lastcol != col) || (lastrow != row)) |
366 | serial_goto(row, col); |
374 | serial_goto(col, row); |
367 | lastcol = col + 1; |
375 | lastcol = col + 1; |
368 | lastrow = row; |
376 | lastrow = row; |
369 | serial_putchar(c); |
377 | serial_putchar(c); |
370 | retval = 0; |
378 | retval = 0; |
371 | break; |
379 | break; |
372 | case FB_CURSOR_GOTO: |
380 | case FB_CURSOR_GOTO: |
373 | row = IPC_GET_ARG1(call); |
381 | col = IPC_GET_ARG1(call); |
374 | col = IPC_GET_ARG2(call); |
382 | row = IPC_GET_ARG2(call); |
375 | serial_goto(row, col); |
383 | serial_goto(col, row); |
376 | lastrow = row; |
- | |
377 | lastcol = col; |
384 | lastcol = col; |
- | 385 | lastrow = row; |
|
378 | retval = 0; |
386 | retval = 0; |
379 | break; |
387 | break; |
380 | case FB_GET_CSIZE: |
388 | case FB_GET_CSIZE: |
381 | ipc_answer_2(callid, EOK, scr_height, scr_width); |
389 | ipc_answer_2(callid, EOK, scr_width, scr_height); |
- | 390 | continue; |
|
- | 391 | case FB_GET_COLOR_CAP: |
|
- | 392 | ipc_answer_1(callid, EOK, color ? FB_CCAP_INDEXED : |
|
- | 393 | FB_CCAP_STYLE); |
|
382 | continue; |
394 | continue; |
383 | case FB_CLEAR: |
395 | case FB_CLEAR: |
384 | serial_clrscr(); |
396 | serial_clrscr(); |
385 | retval = 0; |
397 | retval = 0; |
386 | break; |
398 | break; |
387 | case FB_SET_STYLE: |
399 | case FB_SET_STYLE: |
388 | cur_attr.t = at_style; |
400 | cur_attr.t = at_style; |
389 | cur_attr.a.s.style = IPC_GET_ARG1(call); |
401 | cur_attr.a.s.style = IPC_GET_ARG1(call); |
390 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
402 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
391 | serial_set_attrs(&cur_attr); |
403 | serial_set_attrs(&cur_attr); |
392 | 404 | ||
393 | retval = 0; |
405 | retval = 0; |
394 | break; |
406 | break; |
395 | case FB_SET_COLOR: |
407 | case FB_SET_COLOR: |
396 | cur_attr.t = at_idx; |
408 | cur_attr.t = at_idx; |
397 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
409 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
398 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
410 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
399 | cur_attr.a.i.flags = IPC_GET_ARG3(call); |
411 | cur_attr.a.i.flags = IPC_GET_ARG3(call); |
400 | serial_set_attrs(&cur_attr); |
412 | serial_set_attrs(&cur_attr); |
401 | 413 | ||
402 | retval = 0; |
414 | retval = 0; |
403 | break; |
415 | break; |
404 | case FB_SET_RGB_COLOR: |
416 | case FB_SET_RGB_COLOR: |
405 | cur_attr.t = at_rgb; |
417 | cur_attr.t = at_rgb; |
406 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
418 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
407 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
419 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
408 | serial_set_attrs(&cur_attr); |
420 | serial_set_attrs(&cur_attr); |
409 | 421 | ||
410 | retval = 0; |
422 | retval = 0; |
411 | break; |
423 | break; |
412 | case FB_SCROLL: |
424 | case FB_SCROLL: |
413 | i = IPC_GET_ARG1(call); |
425 | i = IPC_GET_ARG1(call); |
414 | if ((i > scr_height) || (i < -scr_height)) { |
426 | if ((i > scr_height) || (i < -scr_height)) { |
415 | retval = EINVAL; |
427 | retval = EINVAL; |
416 | break; |
428 | break; |
417 | } |
429 | } |
418 | serial_scroll(i); |
430 | serial_scroll(i); |
419 | serial_goto(lastrow, lastcol); |
431 | serial_goto(lastcol, lastrow); |
420 | retval = 0; |
432 | retval = 0; |
421 | break; |
433 | break; |
422 | case FB_CURSOR_VISIBILITY: |
434 | case FB_CURSOR_VISIBILITY: |
423 | if(IPC_GET_ARG1(call)) |
435 | if(IPC_GET_ARG1(call)) |
424 | serial_cursor_enable(); |
436 | serial_cursor_enable(); |
425 | else |
437 | else |
426 | serial_cursor_disable(); |
438 | serial_cursor_disable(); |
427 | retval = 0; |
439 | retval = 0; |
428 | break; |
440 | break; |
429 | case FB_SCREEN_YIELD: |
441 | case FB_SCREEN_YIELD: |
430 | serial_sgr(SGR_RESET); |
442 | serial_sgr(SGR_RESET); |
431 | serial_puts("\033[2J"); |
443 | serial_puts("\033[2J"); |
432 | serial_goto(0, 0); |
444 | serial_goto(0, 0); |
433 | serial_cursor_enable(); |
445 | serial_cursor_enable(); |
434 | retval = 0; |
446 | retval = 0; |
435 | break; |
447 | break; |
436 | case FB_SCREEN_RECLAIM: |
448 | case FB_SCREEN_RECLAIM: |
437 | serial_clrscr(); |
449 | serial_clrscr(); |
438 | serial_set_attrs(&cur_attr); |
450 | serial_set_attrs(&cur_attr); |
439 | retval = 0; |
451 | retval = 0; |
440 | break; |
452 | break; |
441 | default: |
453 | default: |
442 | retval = ENOENT; |
454 | retval = ENOENT; |
443 | } |
455 | } |
444 | ipc_answer_0(callid, retval); |
456 | ipc_answer_0(callid, retval); |
445 | } |
457 | } |
446 | } |
458 | } |
447 | 459 | ||
448 | /** |
460 | /** |
449 | * @} |
461 | * @} |
450 | */ |
462 | */ |
451 | 463 |