48,7 → 48,9 |
#include <screenbuffer.h> |
#include <sys/mman.h> |
#include <stdio.h> |
#include <string.h> |
#include <sysinfo.h> |
#include <event.h> |
|
#include "console.h" |
#include "gcons.h" |
62,8 → 64,7 |
int active_console = 0; |
int prev_console = 0; |
|
/** Information about framebuffer |
*/ |
/** Information about framebuffer */ |
struct { |
int phone; /**< Framebuffer phone */ |
ipcarg_t rows; /**< Framebuffer rows */ |
90,7 → 91,22 |
* faster virtual console |
* switching */ |
|
/** Information on row-span yet unsent to FB driver. */ |
struct { |
int row; /**< Row where the span lies. */ |
int col; /**< Leftmost column of the span. */ |
int n; /**< Width of the span. */ |
} fb_pending; |
|
/** Size of cwrite_buf. */ |
#define CWRITE_BUF_SIZE 256 |
|
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */ |
static char cwrite_buf[CWRITE_BUF_SIZE]; |
|
static void fb_putchar(wchar_t c, int row, int col); |
|
|
/** Find unused virtual console. |
* |
*/ |
158,21 → 174,100 |
} |
} |
|
static void prtchr(char c, int row, int col) |
/** Send an area of screenbuffer to the FB driver. */ |
static void fb_update_area(connection_t *conn, int x, int y, int w, int h) |
{ |
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
int i, j; |
int rc; |
attrs_t *attrs; |
keyfield_t *field; |
|
if (interbuffer) { |
for (j = 0; j < h; j++) { |
for (i = 0; i < w; i++) { |
interbuffer[i + j * w] = |
*get_field_at(&conn->screenbuffer, |
x + i, y + j); |
} |
} |
|
rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
x, y, w, h); |
} else { |
rc = ENOTSUP; |
} |
|
if (rc != 0) { |
/* |
attrs = &conn->screenbuffer.attrs; |
|
for (j = 0; j < h; j++) { |
for (i = 0; i < w; i++) { |
field = get_field_at(&conn->screenbuffer, |
x + i, y + j); |
if (!attrs_same(*attrs, field->attrs)) |
set_attrs(&field->attrs); |
attrs = &field->attrs; |
|
fb_putchar(field->character, y + j, x + i); |
} |
}*/ |
} |
} |
|
/** Check key and process special keys. |
/** Flush pending cells to FB. */ |
static void fb_pending_flush(void) |
{ |
screenbuffer_t *scr; |
|
scr = &(connections[active_console].screenbuffer); |
|
if (fb_pending.n > 0) { |
fb_update_area(&connections[active_console], fb_pending.col, |
fb_pending.row, fb_pending.n, 1); |
fb_pending.n = 0; |
} |
} |
|
/** Mark a character cell as changed. |
* |
* |
* This adds the cell to the pending rowspan if possible. Otherwise |
* the old span is flushed first. |
*/ |
static void write_char(int console, char key) |
static void cell_mark_changed(int row, int col) |
{ |
if (fb_pending.n != 0) { |
if (row != fb_pending.row || |
col != fb_pending.col + fb_pending.n) { |
fb_pending_flush(); |
} |
} |
|
if (fb_pending.n == 0) { |
fb_pending.row = row; |
fb_pending.col = col; |
} |
|
++fb_pending.n; |
} |
|
|
/** Print a character to the active VC with buffering. */ |
static void fb_putchar(wchar_t c, int row, int col) |
{ |
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col); |
} |
|
/** Process a character from the client (TTY emulation). */ |
static void write_char(int console, wchar_t ch) |
{ |
bool flush_cursor = false; |
screenbuffer_t *scr = &(connections[console].screenbuffer); |
|
switch (key) { |
|
switch (ch) { |
case '\n': |
fb_pending_flush(); |
flush_cursor = true; |
scr->position_y++; |
scr->position_x = 0; |
break; |
187,20 → 282,24 |
break; |
scr->position_x--; |
if (console == active_console) |
prtchr(' ', scr->position_y, scr->position_x); |
cell_mark_changed(scr->position_y, scr->position_x); |
screenbuffer_putchar(scr, ' '); |
break; |
default: |
if (console == active_console) |
prtchr(key, scr->position_y, scr->position_x); |
cell_mark_changed(scr->position_y, scr->position_x); |
|
screenbuffer_putchar(scr, key); |
screenbuffer_putchar(scr, ch); |
scr->position_x++; |
} |
|
if (scr->position_x >= scr->size_x) { |
flush_cursor = true; |
scr->position_y++; |
} |
|
scr->position_y += (scr->position_x >= scr->size_x); |
|
if (scr->position_y >= scr->size_y) { |
fb_pending_flush(); |
scr->position_y = scr->size_y - 1; |
screenbuffer_clear_line(scr, scr->top_line); |
scr->top_line = (scr->top_line + 1) % scr->size_y; |
207,12 → 306,11 |
if (console == active_console) |
async_msg_1(fb_info.phone, FB_SCROLL, 1); |
} |
|
|
scr->position_x = scr->position_x % scr->size_x; |
|
if (console == active_console) |
|
if (console == active_console && flush_cursor) |
curs_goto(scr->position_y, scr->position_x); |
|
} |
|
/** Switch to new console */ |
225,7 → 323,9 |
|
if (newcons == active_console) |
return; |
|
|
fb_pending_flush(); |
|
if (newcons == KERNEL_CONSOLE) { |
async_serialize_start(); |
curs_hide_sync(); |
252,16 → 352,19 |
set_attrs(&conn->screenbuffer.attrs); |
curs_visibility(false); |
if (interbuffer) { |
for (i = 0; i < conn->screenbuffer.size_x; i++) |
for (j = 0; j < conn->screenbuffer.size_y; j++) { |
for (j = 0; j < conn->screenbuffer.size_y; j++) { |
for (i = 0; i < conn->screenbuffer.size_x; i++) { |
unsigned int size_x; |
|
size_x = conn->screenbuffer.size_x; |
interbuffer[i + j * size_x] = |
interbuffer[j * size_x + i] = |
*get_field_at(&conn->screenbuffer, i, j); |
} |
} |
/* This call can preempt, but we are already at the end */ |
rc = async_req_0_0(fb_info.phone, FB_DRAW_TEXT_DATA); |
rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA, |
0, 0, conn->screenbuffer.size_x, |
conn->screenbuffer.size_y); |
} |
|
if ((!interbuffer) || (rc != 0)) { |
280,7 → 383,7 |
conn->screenbuffer.attrs))) |
continue; |
|
prtchr(field->character, j, i); |
fb_putchar(field->character, j, i); |
} |
} |
|
333,7 → 436,7 |
conn = &connections[active_console]; |
|
if ((ev.key >= KC_F1) && (ev.key < KC_F1 + |
CONSOLE_COUNT)) { |
CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) { |
if (ev.key == KC_F12) |
change_console(KERNEL_CONSOLE); |
else |
360,6 → 463,34 |
} |
} |
|
/** Handle CONSOLE_WRITE call. */ |
static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request) |
{ |
ipc_callid_t callid; |
size_t size; |
wchar_t ch; |
size_t off; |
|
if (!ipc_data_write_receive(&callid, &size)) { |
ipc_answer_0(callid, EINVAL); |
ipc_answer_0(rid, EINVAL); |
} |
|
if (size > CWRITE_BUF_SIZE) |
size = CWRITE_BUF_SIZE; |
|
(void) ipc_data_write_finalize(callid, cwrite_buf, size); |
|
off = 0; |
while (off < size) { |
ch = str_decode(cwrite_buf, &off, size); |
write_char(consnum, ch); |
} |
|
gcons_notify_char(consnum); |
ipc_answer_1(rid, EOK, size); |
} |
|
/** Default thread for new connections */ |
static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
{ |
368,6 → 499,7 |
int consnum; |
ipcarg_t arg1, arg2, arg3, arg4; |
connection_t *conn; |
screenbuffer_t *scr; |
|
if ((consnum = find_free_connection()) == -1) { |
ipc_answer_0(iid, ELIMIT); |
411,6 → 543,9 |
write_char(consnum, IPC_GET_ARG1(call)); |
gcons_notify_char(consnum); |
break; |
case CONSOLE_WRITE: |
cons_write(consnum, callid, &call); |
continue; |
case CONSOLE_CLEAR: |
/* Send message to fb */ |
if (consnum == active_console) { |
432,10 → 567,16 |
arg2 = fb_info.cols; |
break; |
case CONSOLE_FLUSH: |
if (consnum == active_console) |
fb_pending_flush(); |
if (consnum == active_console) { |
async_req_0_0(fb_info.phone, FB_FLUSH); |
|
scr = &(connections[consnum].screenbuffer); |
curs_goto(scr->position_y, scr->position_x); |
} |
break; |
case CONSOLE_SET_STYLE: |
fb_pending_flush(); |
arg1 = IPC_GET_ARG1(call); |
screenbuffer_set_style(&conn->screenbuffer, arg1); |
if (consnum == active_console) |
442,6 → 583,7 |
set_style(arg1); |
break; |
case CONSOLE_SET_COLOR: |
fb_pending_flush(); |
arg1 = IPC_GET_ARG1(call); |
arg2 = IPC_GET_ARG2(call); |
arg3 = IPC_GET_ARG3(call); |
451,6 → 593,7 |
set_color(arg1, arg2, arg3); |
break; |
case CONSOLE_SET_RGB_COLOR: |
fb_pending_flush(); |
arg1 = IPC_GET_ARG1(call); |
arg2 = IPC_GET_ARG2(call); |
screenbuffer_set_rgb_color(&conn->screenbuffer, arg1, |
459,6 → 602,7 |
set_rgb_color(arg1, arg2); |
break; |
case CONSOLE_CURSOR_VISIBILITY: |
fb_pending_flush(); |
arg1 = IPC_GET_ARG1(call); |
conn->screenbuffer.is_cursor_visible = arg1; |
if (consnum == active_console) |
487,6 → 631,9 |
arg3 = ev.mods; |
arg4 = ev.c; |
break; |
case CONSOLE_KCON_ENABLE: |
change_console(KERNEL_CONSOLE); |
break; |
} |
ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4); |
} |
564,6 → 711,8 |
ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows; |
interbuffer = as_get_mappable_page(ib_size); |
|
fb_pending.n = 0; |
|
if (as_area_create(interbuffer, ib_size, AS_AREA_READ | |
AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) { |
interbuffer = NULL; |
586,13 → 735,10 |
return -1; |
|
/* Receive kernel notifications */ |
// if (sysinfo_value("kconsole.present")) { |
// int inr = sysinfo_value("kconsole.inr"); |
// if (ipc_register_irq(inr, device_assign_devno(), 0, NULL) != EOK) |
// printf(NAME ": Error registering kconsole notifications\n"); |
// |
// async_set_interrupt_received(interrupt_received); |
// } |
if (event_subscribe(EVENT_KCONSOLE, 0) != EOK) |
printf(NAME ": Error registering kconsole notifications\n"); |
|
async_set_interrupt_received(interrupt_received); |
|
// FIXME: avoid connectiong to itself, keep using klog |
// printf(NAME ": Accepting connections\n"); |