Rev 4347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4347 | Rev 4348 | ||
|---|---|---|---|
| Line 51... | Line 51... | ||
| 51 | #include "serial_console.h" |
51 | #include "serial_console.h" |
| 52 | 52 | ||
| 53 | #define MAX_CONTROL 20 |
53 | #define MAX_CONTROL 20 |
| 54 | 54 | ||
| 55 | static void serial_sgr(const unsigned int mode); |
55 | static void serial_sgr(const unsigned int mode); |
| - | 56 | void serial_putchar(wchar_t ch); |
|
| 56 | 57 | ||
| 57 | static int scr_width; |
58 | static int scr_width; |
| 58 | static int scr_height; |
59 | static int scr_height; |
| 59 | static bool color = true; /** True if producing color output. */ |
60 | static bool color = true; /** True if producing color output. */ |
| - | 61 | static bool utf8 = false; /** True if producing UTF8 output. */ |
|
| 60 | static putc_function_t putc_function; |
62 | static putc_function_t putc_function; |
| 61 | 63 | ||
| 62 | /* Allow only 1 connection */ |
64 | /* Allow only 1 connection */ |
| 63 | static int client_connected = 0; |
65 | static int client_connected = 0; |
| 64 | 66 | ||
| Line 100... | Line 102... | ||
| 100 | { |
102 | { |
| 101 | while (*str) |
103 | while (*str) |
| 102 | putc_function(*(str++)); |
104 | putc_function(*(str++)); |
| 103 | } |
105 | } |
| 104 | 106 | ||
| - | 107 | void serial_putchar(wchar_t ch) |
|
| - | 108 | { |
|
| - | 109 | uint8_t buf[STR_BOUNDS(1)]; |
|
| - | 110 | size_t offs; |
|
| - | 111 | size_t i; |
|
| - | 112 | ||
| - | 113 | if (utf8 != true) { |
|
| - | 114 | if (ch >= 0 && ch < 128) |
|
| - | 115 | (*putc_function)((uint8_t) ch); |
|
| - | 116 | else |
|
| - | 117 | (*putc_function)('?'); |
|
| - | 118 | return; |
|
| - | 119 | } |
|
| - | 120 | ||
| - | 121 | offs = 0; |
|
| - | 122 | if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) { |
|
| - | 123 | for (i = 0; i < offs; i++) |
|
| - | 124 | (*putc_function)(buf[i]); |
|
| - | 125 | } else { |
|
| - | 126 | (*putc_function)('?'); |
|
| - | 127 | } |
|
| - | 128 | ||
| - | 129 | } |
|
| - | 130 | ||
| 105 | void serial_goto(const unsigned int row, const unsigned int col) |
131 | void serial_goto(const unsigned int row, const unsigned int col) |
| 106 | { |
132 | { |
| 107 | if ((row > scr_height) || (col > scr_width)) |
133 | if ((row > scr_height) || (col > scr_width)) |
| 108 | return; |
134 | return; |
| 109 | 135 | ||
| Line 246... | Line 272... | ||
| 246 | for (j = 0; j < h; j++) { |
272 | for (j = 0; j < h; j++) { |
| 247 | if (j > 0 && w != scr_width) |
273 | if (j > 0 && w != scr_width) |
| 248 | serial_goto(y, x); |
274 | serial_goto(y, x); |
| 249 | 275 | ||
| 250 | for (i = 0; i < w; i++) { |
276 | for (i = 0; i < w; i++) { |
| 251 | unsigned int col = x + i; |
- | |
| 252 | unsigned int row = y + j; |
- | |
| 253 | - | ||
| 254 | field = &data[j * w + i]; |
277 | field = &data[j * w + i]; |
| 255 | 278 | ||
| 256 | a1 = &field->attrs; |
279 | a1 = &field->attrs; |
| 257 | if (!attrs_same(*a0, *a1)) |
280 | if (!attrs_same(*a0, *a1)) |
| 258 | serial_set_attrs(a1); |
281 | serial_set_attrs(a1); |
| 259 | (*putc_function)(field->character); |
282 | serial_putchar(field->character); |
| 260 | a0 = a1; |
283 | a0 = a1; |
| 261 | } |
284 | } |
| 262 | } |
285 | } |
| 263 | } |
286 | } |
| 264 | 287 | ||
| Line 274... | Line 297... | ||
| 274 | ipc_callid_t callid; |
297 | ipc_callid_t callid; |
| 275 | ipc_call_t call; |
298 | ipc_call_t call; |
| 276 | keyfield_t *interbuf = NULL; |
299 | keyfield_t *interbuf = NULL; |
| 277 | size_t intersize = 0; |
300 | size_t intersize = 0; |
| 278 | 301 | ||
| 279 | char c; |
302 | wchar_t c; |
| 280 | int col, row, w, h; |
303 | int col, row, w, h; |
| 281 | int fgcolor; |
- | |
| 282 | int bgcolor; |
- | |
| 283 | int flags; |
- | |
| 284 | int style; |
- | |
| 285 | int i; |
304 | int i; |
| 286 | 305 | ||
| - | 306 | attrs_t cur_attr; |
|
| 287 | 307 | ||
| 288 | if (client_connected) { |
308 | if (client_connected) { |
| 289 | ipc_answer_0(iid, ELIMIT); |
309 | ipc_answer_0(iid, ELIMIT); |
| 290 | return; |
310 | return; |
| 291 | } |
311 | } |
| 292 | 312 | ||
| 293 | client_connected = 1; |
313 | client_connected = 1; |
| 294 | ipc_answer_0(iid, EOK); |
314 | ipc_answer_0(iid, EOK); |
| - | 315 | ||
| - | 316 | cur_attr.t = at_style; |
|
| - | 317 | cur_attr.a.s.style = STYLE_NORMAL; |
|
| 295 | 318 | ||
| 296 | /* Clear the terminal, set scrolling region |
319 | /* Clear the terminal, set scrolling region |
| 297 | to 0 - height rows. */ |
320 | to 0 - height rows. */ |
| 298 | serial_clrscr(); |
321 | serial_clrscr(); |
| 299 | serial_goto(0, 0); |
322 | serial_goto(0, 0); |
| Line 341... | Line 364... | ||
| 341 | col = IPC_GET_ARG3(call); |
364 | col = IPC_GET_ARG3(call); |
| 342 | if ((lastcol != col) || (lastrow != row)) |
365 | if ((lastcol != col) || (lastrow != row)) |
| 343 | serial_goto(row, col); |
366 | serial_goto(row, col); |
| 344 | lastcol = col + 1; |
367 | lastcol = col + 1; |
| 345 | lastrow = row; |
368 | lastrow = row; |
| 346 | (*putc_function)(c); |
369 | serial_putchar(c); |
| 347 | retval = 0; |
370 | retval = 0; |
| 348 | break; |
371 | break; |
| 349 | case FB_CURSOR_GOTO: |
372 | case FB_CURSOR_GOTO: |
| 350 | row = IPC_GET_ARG1(call); |
373 | row = IPC_GET_ARG1(call); |
| 351 | col = IPC_GET_ARG2(call); |
374 | col = IPC_GET_ARG2(call); |
| Line 360... | Line 383... | ||
| 360 | case FB_CLEAR: |
383 | case FB_CLEAR: |
| 361 | serial_clrscr(); |
384 | serial_clrscr(); |
| 362 | retval = 0; |
385 | retval = 0; |
| 363 | break; |
386 | break; |
| 364 | case FB_SET_STYLE: |
387 | case FB_SET_STYLE: |
| - | 388 | cur_attr.t = at_style; |
|
| 365 | style = IPC_GET_ARG1(call); |
389 | cur_attr.a.s.style = IPC_GET_ARG1(call); |
| - | 390 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
|
| 366 | serial_set_style(style); |
391 | serial_set_attrs(&cur_attr); |
| - | 392 | ||
| 367 | retval = 0; |
393 | retval = 0; |
| 368 | break; |
394 | break; |
| 369 | case FB_SET_COLOR: |
395 | case FB_SET_COLOR: |
| - | 396 | cur_attr.t = at_idx; |
|
| 370 | fgcolor = IPC_GET_ARG1(call); |
397 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
| 371 | bgcolor = IPC_GET_ARG2(call); |
398 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
| 372 | flags = IPC_GET_ARG3(call); |
399 | cur_attr.a.i.flags = IPC_GET_ARG3(call); |
| - | 400 | serial_set_attrs(&cur_attr); |
|
| 373 | 401 | ||
| 374 | serial_set_idx(fgcolor, bgcolor, flags); |
- | |
| 375 | retval = 0; |
402 | retval = 0; |
| 376 | break; |
403 | break; |
| 377 | case FB_SET_RGB_COLOR: |
404 | case FB_SET_RGB_COLOR: |
| - | 405 | cur_attr.t = at_rgb; |
|
| 378 | fgcolor = IPC_GET_ARG1(call); |
406 | cur_attr.a.i.fg_color = IPC_GET_ARG1(call); |
| 379 | bgcolor = IPC_GET_ARG2(call); |
407 | cur_attr.a.i.bg_color = IPC_GET_ARG2(call); |
| - | 408 | serial_set_attrs(&cur_attr); |
|
| 380 | 409 | ||
| 381 | serial_set_rgb(fgcolor, bgcolor); |
- | |
| 382 | retval = 0; |
410 | retval = 0; |
| 383 | break; |
411 | break; |
| 384 | case FB_SCROLL: |
412 | case FB_SCROLL: |
| 385 | i = IPC_GET_ARG1(call); |
413 | i = IPC_GET_ARG1(call); |
| 386 | if ((i > scr_height) || (i < -scr_height)) { |
414 | if ((i > scr_height) || (i < -scr_height)) { |
| Line 396... | Line 424... | ||
| 396 | serial_cursor_enable(); |
424 | serial_cursor_enable(); |
| 397 | else |
425 | else |
| 398 | serial_cursor_disable(); |
426 | serial_cursor_disable(); |
| 399 | retval = 0; |
427 | retval = 0; |
| 400 | break; |
428 | break; |
| - | 429 | case FB_SCREEN_YIELD: |
|
| - | 430 | serial_sgr(SGR_RESET); |
|
| - | 431 | serial_puts("\033[2J"); |
|
| - | 432 | serial_goto(0, 0); |
|
| - | 433 | serial_cursor_enable(); |
|
| - | 434 | retval = 0; |
|
| - | 435 | break; |
|
| - | 436 | case FB_SCREEN_RECLAIM: |
|
| - | 437 | serial_clrscr(); |
|
| - | 438 | serial_set_attrs(&cur_attr); |
|
| - | 439 | retval = 0; |
|
| - | 440 | break; |
|
| 401 | default: |
441 | default: |
| 402 | retval = ENOENT; |
442 | retval = ENOENT; |
| 403 | } |
443 | } |
| 404 | ipc_answer_0(callid, retval); |
444 | ipc_answer_0(callid, retval); |
| 405 | } |
445 | } |