Rev 4338 | Rev 4347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4338 | Rev 4346 | ||
|---|---|---|---|
| Line 44... | Line 44... | ||
| 44 | #include <bool.h> |
44 | #include <bool.h> |
| 45 | #include <errno.h> |
45 | #include <errno.h> |
| 46 | #include <console/color.h> |
46 | #include <console/color.h> |
| 47 | #include <console/style.h> |
47 | #include <console/style.h> |
| 48 | 48 | ||
| - | 49 | #include "../console/screenbuffer.h" |
|
| - | 50 | #include "main.h" |
|
| 49 | #include "serial_console.h" |
51 | #include "serial_console.h" |
| 50 | 52 | ||
| 51 | #define MAX_CONTROL 20 |
53 | #define MAX_CONTROL 20 |
| 52 | 54 | ||
| 53 | static void serial_sgr(const unsigned int mode); |
55 | static void serial_sgr(const unsigned int mode); |
| 54 | 56 | ||
| 55 | static int width; |
57 | static int scr_width; |
| 56 | static int height; |
58 | static int scr_height; |
| 57 | static bool color = true; /** True if producing color output. */ |
59 | static bool color = true; /** True if producing color output. */ |
| 58 | static putc_function_t putc_function; |
60 | static putc_function_t putc_function; |
| 59 | 61 | ||
| 60 | /* Allow only 1 connection */ |
62 | /* Allow only 1 connection */ |
| 61 | static int client_connected = 0; |
63 | static int client_connected = 0; |
| Line 100... | Line 102... | ||
| 100 | putc_function(*(str++)); |
102 | putc_function(*(str++)); |
| 101 | } |
103 | } |
| 102 | 104 | ||
| 103 | void serial_goto(const unsigned int row, const unsigned int col) |
105 | void serial_goto(const unsigned int row, const unsigned int col) |
| 104 | { |
106 | { |
| 105 | if ((row > height) || (col > width)) |
107 | if ((row > scr_height) || (col > scr_width)) |
| 106 | return; |
108 | return; |
| 107 | 109 | ||
| 108 | char control[MAX_CONTROL]; |
110 | char control[MAX_CONTROL]; |
| 109 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
111 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
| 110 | serial_puts(control); |
112 | serial_puts(control); |
| Line 123... | Line 125... | ||
| 123 | } |
125 | } |
| 124 | 126 | ||
| 125 | void serial_scroll(int i) |
127 | void serial_scroll(int i) |
| 126 | { |
128 | { |
| 127 | if (i > 0) { |
129 | if (i > 0) { |
| 128 | serial_goto(height - 1, 0); |
130 | serial_goto(scr_height - 1, 0); |
| 129 | while (i--) |
131 | while (i--) |
| 130 | serial_puts("\033D"); |
132 | serial_puts("\033D"); |
| 131 | } else if (i < 0) { |
133 | } else if (i < 0) { |
| 132 | serial_goto(0, 0); |
134 | serial_goto(0, 0); |
| 133 | while (i++) |
135 | while (i++) |
| Line 161... | Line 163... | ||
| 161 | serial_puts("\033[?25h"); |
163 | serial_puts("\033[?25h"); |
| 162 | } |
164 | } |
| 163 | 165 | ||
| 164 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
166 | void serial_console_init(putc_function_t putc_fn, uint32_t w, uint32_t h) |
| 165 | { |
167 | { |
| 166 | width = w; |
168 | scr_width = w; |
| 167 | height = h; |
169 | scr_height = h; |
| 168 | putc_function = putc_fn; |
170 | putc_function = putc_fn; |
| 169 | } |
171 | } |
| 170 | 172 | ||
| - | 173 | static void serial_set_style(int style) |
|
| - | 174 | { |
|
| - | 175 | if (style == STYLE_EMPHASIS) { |
|
| - | 176 | if (color) { |
|
| - | 177 | serial_sgr(SGR_RESET); |
|
| - | 178 | serial_sgr(SGR_FGCOLOR + CI_RED); |
|
| - | 179 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
|
| - | 180 | } |
|
| - | 181 | serial_sgr(SGR_BOLD); |
|
| - | 182 | } else { |
|
| - | 183 | if (color) { |
|
| - | 184 | serial_sgr(SGR_RESET); |
|
| - | 185 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
|
| - | 186 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
|
| - | 187 | } |
|
| - | 188 | serial_sgr(SGR_NORMAL_INT); |
|
| - | 189 | } |
|
| - | 190 | } |
|
| - | 191 | ||
| - | 192 | static void serial_set_idx(unsigned fgcolor, unsigned bgcolor, |
|
| - | 193 | unsigned flags) |
|
| - | 194 | { |
|
| - | 195 | if (color) { |
|
| - | 196 | serial_sgr(SGR_RESET); |
|
| - | 197 | serial_sgr(SGR_FGCOLOR + color_map[fgcolor]); |
|
| - | 198 | serial_sgr(SGR_BGCOLOR + color_map[bgcolor]); |
|
| - | 199 | } else { |
|
| - | 200 | if (fgcolor < bgcolor) |
|
| - | 201 | serial_sgr(SGR_RESET); |
|
| - | 202 | else |
|
| - | 203 | serial_sgr(SGR_REVERSE); |
|
| - | 204 | } |
|
| - | 205 | } |
|
| - | 206 | ||
| - | 207 | static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor) |
|
| - | 208 | { |
|
| - | 209 | if (fgcolor < bgcolor) |
|
| - | 210 | serial_sgr(SGR_REVERSE_OFF); |
|
| - | 211 | else |
|
| - | 212 | serial_sgr(SGR_REVERSE); |
|
| - | 213 | } |
|
| - | 214 | ||
| - | 215 | static void serial_set_attrs(const attrs_t *a) |
|
| - | 216 | { |
|
| - | 217 | switch (a->t) { |
|
| - | 218 | case at_style: serial_set_style(a->a.s.style); break; |
|
| - | 219 | case at_rgb: serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color); break; |
|
| - | 220 | case at_idx: serial_set_idx(a->a.i.fg_color, |
|
| - | 221 | a->a.i.bg_color, a->a.i.flags); break; |
|
| - | 222 | default: break; |
|
| - | 223 | } |
|
| - | 224 | } |
|
| - | 225 | ||
| - | 226 | static void draw_text_data(keyfield_t *data) |
|
| - | 227 | { |
|
| - | 228 | int i, j; |
|
| - | 229 | attrs_t *a0, *a1; |
|
| - | 230 | ||
| - | 231 | serial_goto(0, 0); |
|
| - | 232 | a0 = &data[0].attrs; |
|
| - | 233 | serial_set_attrs(a0); |
|
| - | 234 | ||
| - | 235 | for (i = 0; i < scr_height; i++) { |
|
| - | 236 | for (j = 0; j < scr_width; j++) { |
|
| - | 237 | a1 = &data[i * scr_width + j].attrs; |
|
| - | 238 | if (!attrs_same(*a0, *a1)) |
|
| - | 239 | serial_set_attrs(a1); |
|
| - | 240 | (*putc_function)(data[i * scr_width + j].character); |
|
| - | 241 | a0 = a1; |
|
| - | 242 | } |
|
| - | 243 | } |
|
| - | 244 | } |
|
| - | 245 | ||
| 171 | /** |
246 | /** |
| 172 | * Main function of the thread serving client connections. |
247 | * Main function of the thread serving client connections. |
| 173 | */ |
248 | */ |
| 174 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
249 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
| 175 | { |
250 | { |
| 176 | int retval; |
251 | int retval; |
| 177 | ipc_callid_t callid; |
252 | ipc_callid_t callid; |
| 178 | ipc_call_t call; |
253 | ipc_call_t call; |
| - | 254 | keyfield_t *interbuf = NULL; |
|
| - | 255 | size_t intersize = 0; |
|
| - | 256 | ||
| 179 | char c; |
257 | char c; |
| 180 | int lastcol = 0; |
258 | int lastcol = 0; |
| 181 | int lastrow = 0; |
259 | int lastrow = 0; |
| 182 | int newcol; |
260 | int newcol; |
| 183 | int newrow; |
261 | int newrow; |
| 184 | int fgcolor; |
262 | int fgcolor; |
| 185 | int bgcolor; |
263 | int bgcolor; |
| - | 264 | int flags; |
|
| 186 | int style; |
265 | int style; |
| 187 | int i; |
266 | int i; |
| - | 267 | ||
| 188 | 268 | ||
| 189 | if (client_connected) { |
269 | if (client_connected) { |
| 190 | ipc_answer_0(iid, ELIMIT); |
270 | ipc_answer_0(iid, ELIMIT); |
| 191 | return; |
271 | return; |
| 192 | } |
272 | } |
| Line 196... | Line 276... | ||
| 196 | 276 | ||
| 197 | /* Clear the terminal, set scrolling region |
277 | /* Clear the terminal, set scrolling region |
| 198 | to 0 - height rows. */ |
278 | to 0 - height rows. */ |
| 199 | serial_clrscr(); |
279 | serial_clrscr(); |
| 200 | serial_goto(0, 0); |
280 | serial_goto(0, 0); |
| 201 | serial_set_scroll_region(height); |
281 | serial_set_scroll_region(scr_height); |
| 202 | 282 | ||
| 203 | while (true) { |
283 | while (true) { |
| 204 | callid = async_get_call(&call); |
284 | callid = async_get_call(&call); |
| 205 | switch (IPC_GET_METHOD(call)) { |
285 | switch (IPC_GET_METHOD(call)) { |
| 206 | case IPC_M_PHONE_HUNGUP: |
286 | case IPC_M_PHONE_HUNGUP: |
| 207 | client_connected = 0; |
287 | client_connected = 0; |
| 208 | ipc_answer_0(callid, EOK); |
288 | ipc_answer_0(callid, EOK); |
| 209 | return; |
289 | return; |
| - | 290 | case IPC_M_SHARE_OUT: |
|
| - | 291 | /* We accept one area for data interchange */ |
|
| - | 292 | intersize = IPC_GET_ARG2(call); |
|
| - | 293 | if (intersize >= scr_width * scr_height * |
|
| - | 294 | sizeof(*interbuf)) { |
|
| - | 295 | receive_comm_area(callid, &call, |
|
| - | 296 | (void *) &interbuf); |
|
| - | 297 | continue; |
|
| - | 298 | } |
|
| - | 299 | retval = EINVAL; |
|
| - | 300 | break; |
|
| - | 301 | case FB_DRAW_TEXT_DATA: |
|
| - | 302 | if (!interbuf) { |
|
| - | 303 | retval = EINVAL; |
|
| - | 304 | break; |
|
| - | 305 | } |
|
| - | 306 | draw_text_data(interbuf); |
|
| - | 307 | retval = 0; |
|
| - | 308 | break; |
|
| 210 | case FB_PUTCHAR: |
309 | case FB_PUTCHAR: |
| 211 | c = IPC_GET_ARG1(call); |
310 | c = IPC_GET_ARG1(call); |
| 212 | newrow = IPC_GET_ARG2(call); |
311 | newrow = IPC_GET_ARG2(call); |
| 213 | newcol = IPC_GET_ARG3(call); |
312 | newcol = IPC_GET_ARG3(call); |
| 214 | if ((lastcol != newcol) || (lastrow != newrow)) |
313 | if ((lastcol != newcol) || (lastrow != newrow)) |
| Line 225... | Line 324... | ||
| 225 | lastrow = newrow; |
324 | lastrow = newrow; |
| 226 | lastcol = newcol; |
325 | lastcol = newcol; |
| 227 | retval = 0; |
326 | retval = 0; |
| 228 | break; |
327 | break; |
| 229 | case FB_GET_CSIZE: |
328 | case FB_GET_CSIZE: |
| 230 | ipc_answer_2(callid, EOK, height, width); |
329 | ipc_answer_2(callid, EOK, scr_height, scr_width); |
| 231 | continue; |
330 | continue; |
| 232 | case FB_CLEAR: |
331 | case FB_CLEAR: |
| 233 | serial_clrscr(); |
332 | serial_clrscr(); |
| 234 | retval = 0; |
333 | retval = 0; |
| 235 | break; |
334 | break; |
| 236 | case FB_SET_STYLE: |
335 | case FB_SET_STYLE: |
| 237 | style = IPC_GET_ARG1(call); |
336 | style = IPC_GET_ARG1(call); |
| 238 | if (style == STYLE_EMPHASIS) { |
- | |
| 239 | if (color) { |
- | |
| 240 | serial_sgr(SGR_RESET); |
- | |
| 241 | serial_sgr(SGR_FGCOLOR + CI_RED); |
- | |
| 242 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
- | |
| 243 | } |
- | |
| 244 | serial_sgr(SGR_BOLD); |
337 | serial_set_style(style); |
| 245 | } else { |
- | |
| 246 | if (color) { |
- | |
| 247 | serial_sgr(SGR_RESET); |
- | |
| 248 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
- | |
| 249 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
- | |
| 250 | } |
- | |
| 251 | serial_sgr(SGR_NORMAL_INT); |
- | |
| 252 | } |
- | |
| 253 | retval = 0; |
338 | retval = 0; |
| 254 | break; |
339 | break; |
| 255 | case FB_SET_COLOR: |
340 | case FB_SET_COLOR: |
| 256 | fgcolor = IPC_GET_ARG1(call); |
341 | fgcolor = IPC_GET_ARG1(call); |
| 257 | bgcolor = IPC_GET_ARG2(call); |
342 | bgcolor = IPC_GET_ARG2(call); |
| - | 343 | flags = IPC_GET_ARG3(call); |
|
| 258 | 344 | ||
| 259 | if (color) { |
- | |
| 260 | serial_sgr(SGR_RESET); |
- | |
| 261 | serial_sgr(SGR_FGCOLOR + color_map[fgcolor]); |
- | |
| 262 | serial_sgr(SGR_BGCOLOR + color_map[bgcolor]); |
345 | serial_set_idx(fgcolor, bgcolor, flags); |
| 263 | } else { |
- | |
| 264 | if (fgcolor < bgcolor) |
- | |
| 265 | serial_sgr(SGR_RESET); |
- | |
| 266 | else |
- | |
| 267 | serial_sgr(SGR_REVERSE); |
- | |
| 268 | } |
- | |
| 269 | retval = 0; |
346 | retval = 0; |
| 270 | break; |
347 | break; |
| 271 | case FB_SET_RGB_COLOR: |
348 | case FB_SET_RGB_COLOR: |
| 272 | fgcolor = IPC_GET_ARG1(call); |
349 | fgcolor = IPC_GET_ARG1(call); |
| 273 | bgcolor = IPC_GET_ARG2(call); |
350 | bgcolor = IPC_GET_ARG2(call); |
| 274 | if (fgcolor < bgcolor) |
- | |
| 275 | serial_sgr(SGR_REVERSE_OFF); |
- | |
| 276 | else |
351 | |
| 277 | serial_sgr(SGR_REVERSE); |
352 | serial_set_rgb(fgcolor, bgcolor); |
| 278 | retval = 0; |
353 | retval = 0; |
| 279 | break; |
354 | break; |
| 280 | case FB_SCROLL: |
355 | case FB_SCROLL: |
| 281 | i = IPC_GET_ARG1(call); |
356 | i = IPC_GET_ARG1(call); |
| 282 | if ((i > height) || (i < -height)) { |
357 | if ((i > scr_height) || (i < -scr_height)) { |
| 283 | retval = EINVAL; |
358 | retval = EINVAL; |
| 284 | break; |
359 | break; |
| 285 | } |
360 | } |
| 286 | serial_scroll(i); |
361 | serial_scroll(i); |
| 287 | serial_goto(lastrow, lastcol); |
362 | serial_goto(lastrow, lastcol); |