Subversion Repositories HelenOS

Rev

Rev 4581 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4581 Rev 4718
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 <io/color.h>
46
#include <io/color.h>
47
#include <io/style.h>
47
#include <io/style.h>
48
#include <string.h>
48
#include <string.h>
49
 
49
 
50
#include "../console/screenbuffer.h"
50
#include "../console/screenbuffer.h"
51
#include "main.h"
51
#include "main.h"
52
#include "serial_console.h"
52
#include "serial_console.h"
53
 
53
 
54
#define MAX_CONTROL 20
54
#define MAX_CONTROL 20
55
 
55
 
56
static void serial_sgr(const unsigned int mode);
56
static void serial_sgr(const unsigned int mode);
57
void serial_putchar(wchar_t ch);
57
void serial_putchar(wchar_t ch);
58
 
58
 
59
static int scr_width;
59
static int scr_width;
60
static int scr_height;
60
static int scr_height;
61
static bool color = true;   /** True if producing color output. */
61
static bool color = true;   /** True if producing color output. */
62
static bool utf8 = false;   /** True if producing UTF8 output. */
62
static bool utf8 = false;   /** True if producing UTF8 output. */
63
static putc_function_t putc_function;
63
static putc_function_t putc_function;
64
 
64
 
65
/* Allow only 1 connection */
65
/* Allow only 1 connection */
66
static int client_connected = 0;
66
static int client_connected = 0;
67
 
67
 
68
enum sgr_color_index {
68
enum sgr_color_index {
69
    CI_BLACK    = 0,
69
    CI_BLACK    = 0,
70
    CI_RED      = 1,
70
    CI_RED      = 1,
71
    CI_GREEN    = 2,
71
    CI_GREEN    = 2,
72
    CI_BROWN    = 3,
72
    CI_BROWN    = 3,
73
    CI_BLUE     = 4,
73
    CI_BLUE     = 4,
74
    CI_MAGENTA  = 5,
74
    CI_MAGENTA  = 5,
75
    CI_CYAN     = 6,
75
    CI_CYAN     = 6,
76
    CI_WHITE    = 7,
76
    CI_WHITE    = 7,
77
};
77
};
78
 
78
 
79
enum sgr_command {
79
enum sgr_command {
80
    SGR_RESET   = 0,
80
    SGR_RESET   = 0,
81
    SGR_BOLD    = 1,
81
    SGR_BOLD    = 1,
82
    SGR_BLINK   = 5,
82
    SGR_BLINK   = 5,
83
    SGR_REVERSE = 7,
83
    SGR_REVERSE = 7,
84
    SGR_NORMAL_INT  = 22,
84
    SGR_NORMAL_INT  = 22,
85
    SGR_BLINK_OFF   = 25,
85
    SGR_BLINK_OFF   = 25,
86
    SGR_REVERSE_OFF = 27,
86
    SGR_REVERSE_OFF = 27,
87
    SGR_FGCOLOR = 30,
87
    SGR_FGCOLOR = 30,
88
    SGR_BGCOLOR = 40
88
    SGR_BGCOLOR = 40
89
};
89
};
90
 
90
 
91
static int color_map[] = {
91
static int color_map[] = {
92
    [COLOR_BLACK]   = CI_BLACK,
92
    [COLOR_BLACK]   = CI_BLACK,
93
    [COLOR_BLUE]    = CI_RED,
93
    [COLOR_BLUE]    = CI_RED,
94
    [COLOR_GREEN]   = CI_GREEN,
94
    [COLOR_GREEN]   = CI_GREEN,
95
    [COLOR_CYAN]    = CI_CYAN,
95
    [COLOR_CYAN]    = CI_CYAN,
96
    [COLOR_RED] = CI_RED,
96
    [COLOR_RED] = CI_RED,
97
    [COLOR_MAGENTA] = CI_MAGENTA,
97
    [COLOR_MAGENTA] = CI_MAGENTA,
98
    [COLOR_YELLOW]  = CI_BROWN,
98
    [COLOR_YELLOW]  = CI_BROWN,
99
    [COLOR_WHITE]   = CI_WHITE
99
    [COLOR_WHITE]   = CI_WHITE
100
};
100
};
101
 
101
 
102
void serial_puts(char *str)
102
void serial_puts(char *str)
103
{
103
{
104
    while (*str)
104
    while (*str)
105
        putc_function(*(str++));
105
        putc_function(*(str++));
106
}
106
}
107
 
107
 
108
void serial_putchar(wchar_t ch)
108
void serial_putchar(wchar_t ch)
109
{
109
{
110
    uint8_t buf[STR_BOUNDS(1)];
110
    uint8_t buf[STR_BOUNDS(1)];
111
    size_t offs;
111
    size_t offs;
112
    size_t i;
112
    size_t i;
113
 
113
 
114
    if (utf8 != true) {
114
    if (utf8 != true) {
115
        if (ch >= 0 && ch < 128)
115
        if (ch >= 0 && ch < 128)
116
            (*putc_function)((uint8_t) ch);
116
            (*putc_function)((uint8_t) ch);
117
        else
117
        else
118
            (*putc_function)('?');
118
            (*putc_function)('?');
119
        return;
119
        return;
120
    }
120
    }
121
 
121
 
122
    offs = 0;
122
    offs = 0;
123
    if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) {
123
    if (chr_encode(ch, buf, &offs, STR_BOUNDS(1)) == EOK) {
124
        for (i = 0; i < offs; i++)
124
        for (i = 0; i < offs; i++)
125
            (*putc_function)(buf[i]);
125
            (*putc_function)(buf[i]);
126
    } else {
126
    } else {
127
        (*putc_function)('?');
127
        (*putc_function)('?');
128
    }
128
    }
129
 
129
 
130
}
130
}
131
 
131
 
132
void serial_goto(const unsigned int col, const unsigned int row)
132
void serial_goto(const unsigned int col, const unsigned int row)
133
{
133
{
134
    if ((col > scr_width) || (row > scr_height))
134
    if ((col > scr_width) || (row > scr_height))
135
        return;
135
        return;
136
   
136
   
137
    char control[MAX_CONTROL];
137
    char control[MAX_CONTROL];
138
    snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1);
138
    snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1);
139
    serial_puts(control);
139
    serial_puts(control);
140
}
140
}
141
 
141
 
142
void serial_clrscr(void)
142
void serial_clrscr(void)
143
{
143
{
144
    /* Initialize graphic rendition attributes. */
144
    /* Initialize graphic rendition attributes. */
145
    serial_sgr(SGR_RESET);
145
    serial_sgr(SGR_RESET);
146
    if (color) {
146
    if (color) {
147
        serial_sgr(SGR_FGCOLOR + CI_BLACK);
147
        serial_sgr(SGR_FGCOLOR + CI_BLACK);
148
        serial_sgr(SGR_BGCOLOR + CI_WHITE);
148
        serial_sgr(SGR_BGCOLOR + CI_WHITE);
149
    }
149
    }
150
 
150
 
151
    serial_puts("\033[2J");
151
    serial_puts("\033[2J");
152
}
152
}
153
 
153
 
154
void serial_scroll(int i)
154
void serial_scroll(int i)
155
{
155
{
156
    if (i > 0) {
156
    if (i > 0) {
157
        serial_goto(0, scr_height - 1);
157
        serial_goto(0, scr_height - 1);
158
        while (i--)
158
        while (i--)
159
            serial_puts("\033D");
159
            serial_puts("\033D");
160
    } else if (i < 0) {
160
    } else if (i < 0) {
161
        serial_goto(0, 0);
161
        serial_goto(0, 0);
162
        while (i++)
162
        while (i++)
163
            serial_puts("\033M");
163
            serial_puts("\033M");
164
    }
164
    }
165
}
165
}
166
 
166
 
167
/** ECMA-48 Set Graphics Rendition. */
167
/** ECMA-48 Set Graphics Rendition. */
168
static void serial_sgr(const unsigned int mode)
168
static void serial_sgr(const unsigned int mode)
169
{
169
{
170
    char control[MAX_CONTROL];
170
    char control[MAX_CONTROL];
171
    snprintf(control, MAX_CONTROL, "\033[%um", mode);
171
    snprintf(control, MAX_CONTROL, "\033[%um", mode);
172
    serial_puts(control);
172
    serial_puts(control);
173
}
173
}
174
 
174
 
175
/** Set scrolling region. */
175
/** Set scrolling region. */
176
void serial_set_scroll_region(unsigned last_row)
176
void serial_set_scroll_region(unsigned last_row)
177
{
177
{
178
    char control[MAX_CONTROL];
178
    char control[MAX_CONTROL];
179
    snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row);
179
    snprintf(control, MAX_CONTROL, "\033[0;%ur", last_row);
180
    serial_puts(control);
180
    serial_puts(control);
181
}
181
}
182
 
182
 
183
void serial_cursor_disable(void)
183
void serial_cursor_disable(void)
184
{
184
{
185
    serial_puts("\033[?25l");
185
    serial_puts("\033[?25l");
186
}
186
}
187
 
187
 
188
void serial_cursor_enable(void)
188
void serial_cursor_enable(void)
189
{
189
{
190
    serial_puts("\033[?25h");
190
    serial_puts("\033[?25h");
191
}
191
}
192
 
192
 
193
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)
194
{
194
{
195
    scr_width = w;
195
    scr_width = w;
196
    scr_height = h;
196
    scr_height = h;
197
    putc_function = putc_fn;
197
    putc_function = putc_fn;
198
}
198
}
199
 
199
 
200
static void serial_set_style(int style)
200
static void serial_set_style(int style)
201
{
201
{
202
    if (style == STYLE_EMPHASIS) {
202
    if (style == STYLE_EMPHASIS) {
203
        if (color) {
203
        if (color) {
204
            serial_sgr(SGR_RESET);
204
            serial_sgr(SGR_RESET);
205
            serial_sgr(SGR_FGCOLOR + CI_RED);
205
            serial_sgr(SGR_FGCOLOR + CI_RED);
206
            serial_sgr(SGR_BGCOLOR + CI_WHITE);
206
            serial_sgr(SGR_BGCOLOR + CI_WHITE);
207
        }
207
        }
208
        serial_sgr(SGR_BOLD);
208
        serial_sgr(SGR_BOLD);
209
    } else {
209
    } else {
210
        if (color) {
210
        if (color) {
211
            serial_sgr(SGR_RESET);
211
            serial_sgr(SGR_RESET);
212
            serial_sgr(SGR_FGCOLOR + CI_BLACK);
212
            serial_sgr(SGR_FGCOLOR + CI_BLACK);
213
            serial_sgr(SGR_BGCOLOR + CI_WHITE);
213
            serial_sgr(SGR_BGCOLOR + CI_WHITE);
214
        }
214
        }
215
        serial_sgr(SGR_NORMAL_INT);
215
        serial_sgr(SGR_NORMAL_INT);
216
    }
216
    }
217
}
217
}
218
 
218
 
219
static void serial_set_idx(unsigned fgcolor, unsigned bgcolor,
219
static void serial_set_idx(unsigned fgcolor, unsigned bgcolor,
220
    unsigned flags)
220
    unsigned flags)
221
{
221
{
222
    if (color) {
222
    if (color) {
223
        serial_sgr(SGR_RESET);
223
        serial_sgr(SGR_RESET);
224
        serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
224
        serial_sgr(SGR_FGCOLOR + color_map[fgcolor]);
225
        serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
225
        serial_sgr(SGR_BGCOLOR + color_map[bgcolor]);
226
    } else {
226
    } else {
227
        if (fgcolor < bgcolor)
227
        if (fgcolor < bgcolor)
228
            serial_sgr(SGR_RESET);
228
            serial_sgr(SGR_RESET);
229
        else
229
        else
230
            serial_sgr(SGR_REVERSE);
230
            serial_sgr(SGR_REVERSE);
231
    }  
231
    }  
232
}
232
}
233
 
233
 
234
static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor)
234
static void serial_set_rgb(uint32_t fgcolor, uint32_t bgcolor)
235
{
235
{
236
    if (fgcolor < bgcolor)
236
    if (fgcolor < bgcolor)
237
        serial_sgr(SGR_REVERSE_OFF);
237
        serial_sgr(SGR_REVERSE_OFF);
238
    else
238
    else
239
        serial_sgr(SGR_REVERSE);
239
        serial_sgr(SGR_REVERSE);
240
}
240
}
241
 
241
 
242
static void serial_set_attrs(const attrs_t *a)
242
static void serial_set_attrs(const attrs_t *a)
243
{
243
{
244
    switch (a->t) {
244
    switch (a->t) {
245
    case at_style:
245
    case at_style:
246
        serial_set_style(a->a.s.style);
246
        serial_set_style(a->a.s.style);
247
        break;
247
        break;
248
    case at_rgb:
248
    case at_rgb:
249
        serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color);
249
        serial_set_rgb(a->a.r.fg_color, a->a.r.bg_color);
250
        break;
250
        break;
251
    case at_idx:
251
    case at_idx:
252
        serial_set_idx(a->a.i.fg_color,
252
        serial_set_idx(a->a.i.fg_color,
253
            a->a.i.bg_color, a->a.i.flags);
253
            a->a.i.bg_color, a->a.i.flags);
254
        break;
254
        break;
255
    default:
255
    default:
256
        break;
256
        break;
257
    }
257
    }
258
}
258
}
259
 
259
 
260
/** Draw text data to viewport.
260
/** Draw text data to viewport.
261
 *
261
 *
262
 * @param vport Viewport id
262
 * @param vport Viewport id
263
 * @param data  Text data.
263
 * @param data  Text data.
264
 * @param x Leftmost column of the area.
264
 * @param x Leftmost column of the area.
265
 * @param y Topmost row of the area.
265
 * @param y Topmost row of the area.
266
 * @param w Number of rows.
266
 * @param w Number of rows.
267
 * @param h Number of columns.
267
 * @param h Number of columns.
268
 */
268
 */
269
static void draw_text_data(keyfield_t *data, unsigned int x,
269
static void draw_text_data(keyfield_t *data, unsigned int x,
270
    unsigned int y, unsigned int w, unsigned int h)
270
    unsigned int y, unsigned int w, unsigned int h)
271
{
271
{
272
    unsigned int i, j;
272
    unsigned int i, j;
273
    keyfield_t *field;
273
    keyfield_t *field;
274
    attrs_t *a0, *a1;
274
    attrs_t *a0, *a1;
275
 
275
 
276
    serial_goto(x, y);
276
    serial_goto(x, y);
277
    a0 = &data[0].attrs;
277
    a0 = &data[0].attrs;
278
    serial_set_attrs(a0);
278
    serial_set_attrs(a0);
279
 
279
 
280
    for (j = 0; j < h; j++) {
280
    for (j = 0; j < h; j++) {
281
        if (j > 0 && w != scr_width)
281
        if (j > 0 && w != scr_width)
282
            serial_goto(x, j);
282
            serial_goto(x, j);
283
 
283
 
284
        for (i = 0; i < w; i++) {
284
        for (i = 0; i < w; i++) {
285
            field = &data[j * w + i];
285
            field = &data[j * w + i];
286
 
286
 
287
            a1 = &field->attrs;
287
            a1 = &field->attrs;
288
            if (!attrs_same(*a0, *a1))
288
            if (!attrs_same(*a0, *a1))
289
                serial_set_attrs(a1);
289
                serial_set_attrs(a1);
290
            serial_putchar(field->character);
290
            serial_putchar(field->character);
291
            a0 = a1;
291
            a0 = a1;
292
        }
292
        }
293
    }
293
    }
294
}
294
}
295
 
295
 
296
int lastcol = 0;
296
int lastcol = 0;
297
int lastrow = 0;
297
int lastrow = 0;
298
 
298
 
299
/**
299
/**
300
 * Main function of the thread serving client connections.
300
 * Main function of the thread serving client connections.
301
 */
301
 */
302
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)
303
{
303
{
304
    int retval;
304
    int retval;
305
    ipc_callid_t callid;
305
    ipc_callid_t callid;
306
    ipc_call_t call;
306
    ipc_call_t call;
307
    keyfield_t *interbuf = NULL;
307
    keyfield_t *interbuf = NULL;
308
    size_t intersize = 0;
308
    size_t intersize = 0;
309
 
309
 
310
    wchar_t c;
310
    wchar_t c;
311
    int col, row, w, h;
311
    int col, row, w, h;
312
    int i;
312
    int i;
313
 
313
 
314
    attrs_t cur_attr;
314
    attrs_t cur_attr;
315
   
315
   
316
    if (client_connected) {
316
    if (client_connected) {
317
        ipc_answer_0(iid, ELIMIT);
317
        ipc_answer_0(iid, ELIMIT);
318
        return;
318
        return;
319
    }
319
    }
320
   
320
   
321
    client_connected = 1;
321
    client_connected = 1;
322
    ipc_answer_0(iid, EOK);
322
    ipc_answer_0(iid, EOK);
323
 
323
 
324
    cur_attr.t = at_style;
324
    cur_attr.t = at_style;
325
    cur_attr.a.s.style = STYLE_NORMAL;
325
    cur_attr.a.s.style = STYLE_NORMAL;
326
   
326
   
327
    /* Clear the terminal, set scrolling region
327
    /* Clear the terminal, set scrolling region
328
       to 0 - height rows. */
328
       to 0 - height rows. */
329
    serial_clrscr();
329
    serial_clrscr();
330
    serial_goto(0, 0);
330
    serial_goto(0, 0);
331
    serial_set_scroll_region(scr_height);
331
    serial_set_scroll_region(scr_height);
332
   
332
   
333
    while (true) {
333
    while (true) {
334
        callid = async_get_call(&call);
334
        callid = async_get_call(&call);
335
        switch (IPC_GET_METHOD(call)) {
335
        switch (IPC_GET_METHOD(call)) {
336
        case IPC_M_PHONE_HUNGUP:
336
        case IPC_M_PHONE_HUNGUP:
337
            client_connected = 0;
337
            client_connected = 0;
338
            ipc_answer_0(callid, EOK);
338
            ipc_answer_0(callid, EOK);
339
            return;
339
            return;
340
        case IPC_M_SHARE_OUT:
340
        case IPC_M_SHARE_OUT:
341
            /* We accept one area for data interchange */
341
            /* We accept one area for data interchange */
342
            intersize = IPC_GET_ARG2(call);
342
            intersize = IPC_GET_ARG2(call);
343
            if (intersize >= scr_width * scr_height *
343
            if (intersize >= scr_width * scr_height *
344
                sizeof(*interbuf)) {
344
                sizeof(*interbuf)) {
345
                receive_comm_area(callid, &call,
345
                receive_comm_area(callid, &call,
346
                    (void *) &interbuf);
346
                    (void *) &interbuf);
347
                continue;
347
                continue;
348
            }
348
            }
349
            retval = EINVAL;
349
            retval = EINVAL;
350
            break;
350
            break;
351
        case FB_DRAW_TEXT_DATA:
351
        case FB_DRAW_TEXT_DATA:
352
            col = IPC_GET_ARG1(call);
352
            col = IPC_GET_ARG1(call);
353
            row = IPC_GET_ARG2(call);
353
            row = IPC_GET_ARG2(call);
354
            w = IPC_GET_ARG3(call);
354
            w = IPC_GET_ARG3(call);
355
            h = IPC_GET_ARG4(call);
355
            h = IPC_GET_ARG4(call);
356
            if (!interbuf) {
356
            if (!interbuf) {
357
                retval = EINVAL;
357
                retval = EINVAL;
358
                break;
358
                break;
359
            }
359
            }
360
            if (col + w > scr_width || row + h > scr_height) {
360
            if (col + w > scr_width || row + h > scr_height) {
361
                retval = EINVAL;
361
                retval = EINVAL;
362
                break;
362
                break;
363
            }
363
            }
364
            draw_text_data(interbuf, col, row, w, h);
364
            draw_text_data(interbuf, col, row, w, h);
365
            lastcol = col + w;
365
            lastcol = col + w;
366
            lastrow = row + h - 1;
366
            lastrow = row + h - 1;
367
            retval = 0;
367
            retval = 0;
368
            break;
368
            break;
369
        case FB_PUTCHAR:
369
        case FB_PUTCHAR:
370
            c = IPC_GET_ARG1(call);
370
            c = IPC_GET_ARG1(call);
371
            col = IPC_GET_ARG2(call);
371
            col = IPC_GET_ARG2(call);
372
            row = IPC_GET_ARG3(call);
372
            row = IPC_GET_ARG3(call);
373
            if ((lastcol != col) || (lastrow != row))
373
            if ((lastcol != col) || (lastrow != row))
374
                serial_goto(col, row);
374
                serial_goto(col, row);
375
            lastcol = col + 1;
375
            lastcol = col + 1;
376
            lastrow = row;
376
            lastrow = row;
377
            serial_putchar(c);
377
            serial_putchar(c);
378
            retval = 0;
378
            retval = 0;
379
            break;
379
            break;
380
        case FB_CURSOR_GOTO:
380
        case FB_CURSOR_GOTO:
381
            col = IPC_GET_ARG1(call);
381
            col = IPC_GET_ARG1(call);
382
            row = IPC_GET_ARG2(call);
382
            row = IPC_GET_ARG2(call);
383
            serial_goto(col, row);
383
            serial_goto(col, row);
384
            lastcol = col;
384
            lastcol = col;
385
            lastrow = row;
385
            lastrow = row;
386
            retval = 0;
386
            retval = 0;
387
            break;
387
            break;
388
        case FB_GET_CSIZE:
388
        case FB_GET_CSIZE:
389
            ipc_answer_2(callid, EOK, scr_width, scr_height);
389
            ipc_answer_2(callid, EOK, scr_width, scr_height);
390
            continue;
390
            continue;
-
 
391
        case FB_GET_COLOR_CAP:
-
 
392
            ipc_answer_1(callid, EOK, color ? FB_CCAP_INDEXED :
-
 
393
                FB_CCAP_STYLE);
-
 
394
            continue;
391
        case FB_CLEAR:
395
        case FB_CLEAR:
392
            serial_clrscr();
396
            serial_clrscr();
393
            retval = 0;
397
            retval = 0;
394
            break;
398
            break;
395
        case FB_SET_STYLE:
399
        case FB_SET_STYLE:
396
            cur_attr.t = at_style;
400
            cur_attr.t = at_style;
397
            cur_attr.a.s.style = IPC_GET_ARG1(call);
401
            cur_attr.a.s.style = IPC_GET_ARG1(call);
398
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
402
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
399
            serial_set_attrs(&cur_attr);
403
            serial_set_attrs(&cur_attr);
400
 
404
 
401
            retval = 0;
405
            retval = 0;
402
            break;
406
            break;
403
        case FB_SET_COLOR:
407
        case FB_SET_COLOR:
404
            cur_attr.t = at_idx;
408
            cur_attr.t = at_idx;
405
            cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
409
            cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
406
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
410
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
407
            cur_attr.a.i.flags = IPC_GET_ARG3(call);
411
            cur_attr.a.i.flags = IPC_GET_ARG3(call);
408
            serial_set_attrs(&cur_attr);
412
            serial_set_attrs(&cur_attr);
409
 
413
 
410
            retval = 0;
414
            retval = 0;
411
            break;
415
            break;
412
        case FB_SET_RGB_COLOR:
416
        case FB_SET_RGB_COLOR:
413
            cur_attr.t = at_rgb;
417
            cur_attr.t = at_rgb;
414
            cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
418
            cur_attr.a.i.fg_color = IPC_GET_ARG1(call);
415
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
419
            cur_attr.a.i.bg_color = IPC_GET_ARG2(call);
416
            serial_set_attrs(&cur_attr);
420
            serial_set_attrs(&cur_attr);
417
 
421
 
418
            retval = 0;
422
            retval = 0;
419
            break;
423
            break;
420
        case FB_SCROLL:
424
        case FB_SCROLL:
421
            i = IPC_GET_ARG1(call);
425
            i = IPC_GET_ARG1(call);
422
            if ((i > scr_height) || (i < -scr_height)) {
426
            if ((i > scr_height) || (i < -scr_height)) {
423
                retval = EINVAL;
427
                retval = EINVAL;
424
                break;
428
                break;
425
            }
429
            }
426
            serial_scroll(i);
430
            serial_scroll(i);
427
            serial_goto(lastcol, lastrow);
431
            serial_goto(lastcol, lastrow);
428
            retval = 0;
432
            retval = 0;
429
            break;
433
            break;
430
        case FB_CURSOR_VISIBILITY:
434
        case FB_CURSOR_VISIBILITY:
431
            if(IPC_GET_ARG1(call))
435
            if(IPC_GET_ARG1(call))
432
                serial_cursor_enable();
436
                serial_cursor_enable();
433
            else
437
            else
434
                serial_cursor_disable();
438
                serial_cursor_disable();
435
            retval = 0;
439
            retval = 0;
436
            break;
440
            break;
437
        case FB_SCREEN_YIELD:
441
        case FB_SCREEN_YIELD:
438
            serial_sgr(SGR_RESET);
442
            serial_sgr(SGR_RESET);
439
            serial_puts("\033[2J");
443
            serial_puts("\033[2J");
440
            serial_goto(0, 0);
444
            serial_goto(0, 0);
441
            serial_cursor_enable();
445
            serial_cursor_enable();
442
            retval = 0;
446
            retval = 0;
443
            break;
447
            break;
444
        case FB_SCREEN_RECLAIM:
448
        case FB_SCREEN_RECLAIM:
445
            serial_clrscr();
449
            serial_clrscr();
446
            serial_set_attrs(&cur_attr);
450
            serial_set_attrs(&cur_attr);
447
            retval = 0;
451
            retval = 0;
448
            break;
452
            break;
449
        default:
453
        default:
450
            retval = ENOENT;
454
            retval = ENOENT;
451
        }
455
        }
452
        ipc_answer_0(callid, retval);
456
        ipc_answer_0(callid, retval);
453
    }
457
    }
454
}
458
}
455
 
459
 
456
/**
460
/**
457
 * @}
461
 * @}
458
 */
462
 */
459
 
463