Rev 4153 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4153 | Rev 4263 | ||
|---|---|---|---|
| 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 221... | Line 247... | ||
| 221 | a->a.i.bg_color, a->a.i.flags); break; |
247 | a->a.i.bg_color, a->a.i.flags); break; |
| 222 | default: break; |
248 | default: break; |
| 223 | } |
249 | } |
| 224 | } |
250 | } |
| 225 | 251 | ||
| - | 252 | /** Draw text data to viewport. |
|
| - | 253 | * |
|
| - | 254 | * @param vport Viewport id |
|
| - | 255 | * @param data Text data. |
|
| - | 256 | * @param x Leftmost column of the area. |
|
| - | 257 | * @param y Topmost row of the area. |
|
| - | 258 | * @param w Number of rows. |
|
| - | 259 | * @param h Number of columns. |
|
| - | 260 | */ |
|
| 226 | static void draw_text_data(keyfield_t *data) |
261 | static void draw_text_data(keyfield_t *data, unsigned int x, |
| - | 262 | unsigned int y, unsigned int w, unsigned int h) |
|
| 227 | { |
263 | { |
| 228 | int i, j; |
264 | unsigned int i, j; |
| - | 265 | keyfield_t *field; |
|
| 229 | attrs_t *a0, *a1; |
266 | attrs_t *a0, *a1; |
| 230 | 267 | ||
| 231 | serial_goto(0, 0); |
268 | serial_goto(y, x); |
| 232 | a0 = &data[0].attrs; |
269 | a0 = &data[0].attrs; |
| 233 | serial_set_attrs(a0); |
270 | serial_set_attrs(a0); |
| 234 | 271 | ||
| 235 | for (i = 0; i < scr_height; i++) { |
272 | for (j = 0; j < h; j++) { |
| - | 273 | if (j > 0 && w != scr_width) |
|
| - | 274 | serial_goto(y, x); |
|
| - | 275 | ||
| 236 | for (j = 0; j < scr_width; j++) { |
276 | for (i = 0; i < w; i++) { |
| - | 277 | unsigned int col = x + i; |
|
| - | 278 | unsigned int row = y + j; |
|
| - | 279 | ||
| 237 | a1 = &data[i * scr_width + j].attrs; |
280 | field = &data[j * w + i]; |
| - | 281 | ||
| - | 282 | a1 = &field->attrs; |
|
| 238 | if (!attrs_same(*a0, *a1)) |
283 | if (!attrs_same(*a0, *a1)) |
| 239 | serial_set_attrs(a1); |
284 | serial_set_attrs(a1); |
| 240 | (*putc_function)(data[i * scr_width + j].character); |
285 | serial_putchar(field->character); |
| 241 | a0 = a1; |
286 | a0 = a1; |
| 242 | } |
287 | } |
| 243 | } |
288 | } |
| 244 | } |
289 | } |
| 245 | 290 | ||
| - | 291 | int lastcol = 0; |
|
| - | 292 | int lastrow = 0; |
|
| - | 293 | ||
| 246 | /** |
294 | /** |
| 247 | * Main function of the thread serving client connections. |
295 | * Main function of the thread serving client connections. |
| 248 | */ |
296 | */ |
| 249 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
297 | void serial_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
| 250 | { |
298 | { |
| Line 252... | Line 300... | ||
| 252 | ipc_callid_t callid; |
300 | ipc_callid_t callid; |
| 253 | ipc_call_t call; |
301 | ipc_call_t call; |
| 254 | keyfield_t *interbuf = NULL; |
302 | keyfield_t *interbuf = NULL; |
| 255 | size_t intersize = 0; |
303 | size_t intersize = 0; |
| 256 | 304 | ||
| 257 | char c; |
305 | wchar_t c; |
| 258 | int lastcol = 0; |
- | |
| 259 | int lastrow = 0; |
306 | int col, row, w, h; |
| 260 | int newcol; |
- | |
| 261 | int newrow; |
- | |
| 262 | int fgcolor; |
307 | int fgcolor; |
| 263 | int bgcolor; |
308 | int bgcolor; |
| 264 | int flags; |
309 | int flags; |
| 265 | int style; |
310 | int style; |
| 266 | int i; |
311 | int i; |
| Line 297... | Line 342... | ||
| 297 | continue; |
342 | continue; |
| 298 | } |
343 | } |
| 299 | retval = EINVAL; |
344 | retval = EINVAL; |
| 300 | break; |
345 | break; |
| 301 | case FB_DRAW_TEXT_DATA: |
346 | case FB_DRAW_TEXT_DATA: |
| - | 347 | col = IPC_GET_ARG1(call); |
|
| - | 348 | row = IPC_GET_ARG2(call); |
|
| - | 349 | w = IPC_GET_ARG3(call); |
|
| - | 350 | h = IPC_GET_ARG4(call); |
|
| 302 | if (!interbuf) { |
351 | if (!interbuf) { |
| 303 | retval = EINVAL; |
352 | retval = EINVAL; |
| 304 | break; |
353 | break; |
| 305 | } |
354 | } |
| - | 355 | if (col + w > scr_width || row + h > scr_height) { |
|
| - | 356 | retval = EINVAL; |
|
| - | 357 | break; |
|
| - | 358 | } |
|
| 306 | draw_text_data(interbuf); |
359 | draw_text_data(interbuf, col, row, w, h); |
| - | 360 | lastrow = row + h - 1; |
|
| - | 361 | lastcol = col + w; |
|
| 307 | retval = 0; |
362 | retval = 0; |
| 308 | break; |
363 | break; |
| 309 | case FB_PUTCHAR: |
364 | case FB_PUTCHAR: |
| 310 | c = IPC_GET_ARG1(call); |
365 | c = IPC_GET_ARG1(call); |
| 311 | newrow = IPC_GET_ARG2(call); |
366 | row = IPC_GET_ARG2(call); |
| 312 | newcol = IPC_GET_ARG3(call); |
367 | col = IPC_GET_ARG3(call); |
| 313 | if ((lastcol != newcol) || (lastrow != newrow)) |
368 | if ((lastcol != col) || (lastrow != row)) |
| 314 | serial_goto(newrow, newcol); |
369 | serial_goto(row, col); |
| 315 | lastcol = newcol + 1; |
370 | lastcol = col + 1; |
| 316 | lastrow = newrow; |
371 | lastrow = row; |
| 317 | (*putc_function)(c); |
372 | serial_putchar(c); |
| 318 | retval = 0; |
373 | retval = 0; |
| 319 | break; |
374 | break; |
| 320 | case FB_CURSOR_GOTO: |
375 | case FB_CURSOR_GOTO: |
| 321 | newrow = IPC_GET_ARG1(call); |
376 | row = IPC_GET_ARG1(call); |
| 322 | newcol = IPC_GET_ARG2(call); |
377 | col = IPC_GET_ARG2(call); |
| 323 | serial_goto(newrow, newcol); |
378 | serial_goto(row, col); |
| 324 | lastrow = newrow; |
379 | lastrow = row; |
| 325 | lastcol = newcol; |
380 | lastcol = col; |
| 326 | retval = 0; |
381 | retval = 0; |
| 327 | break; |
382 | break; |
| 328 | case FB_GET_CSIZE: |
383 | case FB_GET_CSIZE: |
| 329 | ipc_answer_2(callid, EOK, scr_height, scr_width); |
384 | ipc_answer_2(callid, EOK, scr_height, scr_width); |
| 330 | continue; |
385 | continue; |