Subversion Repositories HelenOS

Rev

Rev 1486 | Rev 1490 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1363 vana 1
/*
2
 * Copyright (C) 2006 Jakub Vana
1404 palkovsky 3
 * Copyright (C) 2006 Ondrej Palkovsky
1363 vana 4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
#include <stdio.h>
1430 jermar 31
#include <stdlib.h>
32
#include <unistd.h>
33
#include <string.h>
1363 vana 34
#include <ddi.h>
35
#include <task.h>
36
#include <sysinfo.h>
37
#include <align.h>
38
#include <as.h>
39
#include <ipc/fb.h>
40
#include <ipc/ipc.h>
1430 jermar 41
#include <ipc/ns.h>
1363 vana 42
#include <ipc/services.h>
43
#include <kernel/errno.h>
1392 palkovsky 44
#include <async.h>
1404 palkovsky 45
#include "font-8x16.h"
46
#include "helenos.xbm"
1363 vana 47
#include "fb.h"
48
 
1485 palkovsky 49
#define DEFAULT_BGCOLOR                0x000080
50
#define DEFAULT_FGCOLOR                0xffff00
1363 vana 51
 
52
/***************************************************************/
53
/* Pixel specific fuctions */
54
 
1485 palkovsky 55
typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color);
56
typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y);
1363 vana 57
 
1485 palkovsky 58
struct {
1363 vana 59
    __u8 *fbaddress ;
60
 
61
    unsigned int xres ;
62
    unsigned int yres ;
63
    unsigned int scanline ;
64
    unsigned int pixelbytes ;
65
 
66
    putpixel_fn_t putpixel;
67
    getpixel_fn_t getpixel;
1485 palkovsky 68
} screen;
1363 vana 69
 
1485 palkovsky 70
typedef struct {
71
    int initialized;
72
    unsigned int x, y;
73
    unsigned int width, height;
1363 vana 74
 
1485 palkovsky 75
    /* Text support in window */
76
    unsigned int rows, cols;
77
    /* Style for text printing */
78
    int bgcolor, fgcolor;
79
    /* Auto-cursor position */
1486 palkovsky 80
    int cursor_active, cur_col, cur_row;
1485 palkovsky 81
} viewport_t;
1363 vana 82
 
1485 palkovsky 83
#define MAX_VIEWPORTS 128
84
static viewport_t viewports[128];
85
 
86
/* Allow only 1 connection */
87
static int client_connected = 0;
88
 
1363 vana 89
#define RED(x, bits)    ((x >> (16 + 8 - bits)) & ((1 << bits) - 1))
90
#define GREEN(x, bits)  ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
91
#define BLUE(x, bits)   ((x >> (8 - bits)) & ((1 << bits) - 1))
92
 
1485 palkovsky 93
#define COL_WIDTH   8
94
#define ROW_BYTES   (screen.scanline * FONT_SCANLINES)
1363 vana 95
 
1485 palkovsky 96
#define POINTPOS(x, y)  ((y) * screen.scanline + (x) * screen.pixelbytes)
1363 vana 97
 
98
/** Put pixel - 24-bit depth, 1 free byte */
1485 palkovsky 99
static void putpixel_4byte(unsigned int x, unsigned int y, int color)
1363 vana 100
{
1485 palkovsky 101
    *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color;
1363 vana 102
}
103
 
104
/** Return pixel color - 24-bit depth, 1 free byte */
1485 palkovsky 105
static int getpixel_4byte(unsigned int x, unsigned int y)
1363 vana 106
{
1485 palkovsky 107
    return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff;
1363 vana 108
}
109
 
110
/** Put pixel - 24-bit depth */
1485 palkovsky 111
static void putpixel_3byte(unsigned int x, unsigned int y, int color)
1363 vana 112
{
113
    unsigned int startbyte = POINTPOS(x, y);
114
 
115
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
1485 palkovsky 116
    screen.fbaddress[startbyte] = RED(color, 8);
117
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
118
    screen.fbaddress[startbyte + 2] = BLUE(color, 8);
1363 vana 119
#else
1485 palkovsky 120
    screen.fbaddress[startbyte + 2] = RED(color, 8);
121
    screen.fbaddress[startbyte + 1] = GREEN(color, 8);
122
    screen.fbaddress[startbyte + 0] = BLUE(color, 8);
1363 vana 123
#endif
124
 
125
}
126
 
127
/** Return pixel color - 24-bit depth */
1485 palkovsky 128
static int getpixel_3byte(unsigned int x, unsigned int y)
1363 vana 129
{
130
    unsigned int startbyte = POINTPOS(x, y);
131
 
132
 
133
 
134
#if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN))
1485 palkovsky 135
    return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2];
1363 vana 136
#else
1485 palkovsky 137
    return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0];
1363 vana 138
#endif
139
 
140
 
141
}
142
 
143
/** Put pixel - 16-bit depth (5:6:5) */
1485 palkovsky 144
static void putpixel_2byte(unsigned int x, unsigned int y, int color)
1363 vana 145
{
146
    /* 5-bit, 6-bits, 5-bits */
1485 palkovsky 147
    *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5);
1363 vana 148
}
149
 
150
/** Return pixel color - 16-bit depth (5:6:5) */
1485 palkovsky 151
static int getpixel_2byte(unsigned int x, unsigned int y)
1363 vana 152
{
1485 palkovsky 153
    int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y)));
1363 vana 154
    return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
155
}
156
 
157
/** Put pixel - 8-bit depth (3:2:3) */
1485 palkovsky 158
static void putpixel_1byte(unsigned int x, unsigned int y, int color)
1363 vana 159
{
1485 palkovsky 160
    screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3);
1363 vana 161
}
162
 
163
/** Return pixel color - 8-bit depth (3:2:3) */
1485 palkovsky 164
static int getpixel_1byte(unsigned int x, unsigned int y)
1363 vana 165
{
1485 palkovsky 166
    int color = screen.fbaddress[POINTPOS(x, y)];
1363 vana 167
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
168
}
169
 
1485 palkovsky 170
static void putpixel(int vp, unsigned int x, unsigned int y, int color)
171
{
172
    screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color);
173
}
174
static int getpixel(int vp, unsigned int x, unsigned int y)
175
{
176
    return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y);
177
}
178
 
1363 vana 179
/** Fill line with color BGCOLOR */
1485 palkovsky 180
static void clear_line(int vp, unsigned int y)
1363 vana 181
{
182
    unsigned int x;
1485 palkovsky 183
    for (x = 0; x < viewports[vp].width; x++)
184
        putpixel(vp, x, y, viewports[vp].bgcolor);
1363 vana 185
}
186
 
1485 palkovsky 187
/** Fill viewport with background color */
188
static void clear_port(int vp)
1363 vana 189
{
190
    unsigned int y;
1485 palkovsky 191
 
192
    clear_line(vp, 0);
193
    for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) {
194
        memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
195
               &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
196
               screen.pixelbytes * viewports[vp].width);
1363 vana 197
    }  
198
}
199
 
1485 palkovsky 200
/** Scroll port up/down
201
 *
202
 * @param vp Viewport to scroll
203
 * @param rows Positive number - scroll up, negative - scroll down
204
 */
205
static void scroll_port(int vp, int rows)
1363 vana 206
{
1485 palkovsky 207
    int y;
208
    int startline;
209
    int endline;
210
 
211
    if (rows > 0) {
212
        for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++)
213
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
214
                   &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)],
215
                   screen.pixelbytes * viewports[vp].width);
216
        /* Clear last row */
217
        startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1);
218
        endline = viewports[vp].y + viewports[vp].height;
219
        clear_line(vp, startline);
220
        for (y=startline+1;y < endline; y++)
221
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
222
                   &screen.fbaddress[POINTPOS(viewports[vp].x,startline)],
223
                   screen.pixelbytes * viewports[vp].width);
224
 
225
    } else if (rows < 0) {
226
        rows = -rows;
227
        for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--)
228
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)],
229
                &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)],
230
                screen.pixelbytes * viewports[vp].width);
231
        /* Clear first row */
232
        clear_line(0, viewports[vp].bgcolor);
233
        for (y=1;y < rows*FONT_SCANLINES; y++)
234
            memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)],
235
                   &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)],
236
                   screen.pixelbytes * viewports[vp].width);
237
    }
1363 vana 238
}
239
 
1485 palkovsky 240
static void invert_pixel(int vp,unsigned int x, unsigned int y)
1363 vana 241
{
1485 palkovsky 242
    putpixel(vp, x, y, ~getpixel(vp, x, y));
1363 vana 243
}
244
 
245
 
246
/** Draw one line of glyph at a given position */
1485 palkovsky 247
static void draw_glyph_line(int vp,unsigned int glline, unsigned int x, unsigned int y)
1363 vana 248
{
249
    unsigned int i;
250
 
251
    for (i = 0; i < 8; i++)
252
        if (glline & (1 << (7 - i))) {
1485 palkovsky 253
            putpixel(vp, x + i, y, viewports[vp].fgcolor);
1363 vana 254
        } else
1485 palkovsky 255
            putpixel(vp, x + i, y, viewports[vp].bgcolor);
1363 vana 256
}
257
 
258
/***************************************************************/
259
/* Character-console functions */
260
 
261
/** Draw character at given position */
1485 palkovsky 262
static void draw_glyph(int vp,__u8 glyph, unsigned int row, unsigned int col)
1363 vana 263
{
264
    unsigned int y;
265
 
266
    for (y = 0; y < FONT_SCANLINES; y++)
1485 palkovsky 267
        draw_glyph_line(vp ,fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y);
1363 vana 268
}
269
 
270
/** Invert character at given position */
1489 palkovsky 271
static void invert_char(int vp,unsigned int row, unsigned int col)
1363 vana 272
{
273
    unsigned int x;
274
    unsigned int y;
275
 
276
    for (x = 0; x < COL_WIDTH; x++)
277
        for (y = 0; y < FONT_SCANLINES; y++)
1485 palkovsky 278
            invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y);
1363 vana 279
}
280
 
1485 palkovsky 281
static void draw_logo(int vp,unsigned int startx, unsigned int starty)
1363 vana 282
{
283
    unsigned int x;
284
    unsigned int y;
285
    unsigned int byte;
286
    unsigned int rowbytes;
287
 
288
    rowbytes = (helenos_width - 1) / 8 + 1;
289
 
290
    for (y = 0; y < helenos_height; y++)
291
        for (x = 0; x < helenos_width; x++) {
292
            byte = helenos_bits[rowbytes * y + x / 8];
293
            byte >>= x % 8;
294
            if (byte & 1)
1485 palkovsky 295
                putpixel(vp ,startx + x, starty + y, viewports[vp].fgcolor);
1363 vana 296
        }
297
}
298
 
299
/***************************************************************/
300
/* Stdout specific functions */
301
 
302
 
1485 palkovsky 303
/** Create new viewport
1363 vana 304
 *
1485 palkovsky 305
 * @return New viewport number
1363 vana 306
 */
1485 palkovsky 307
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
308
               unsigned int height)
1363 vana 309
{
1485 palkovsky 310
    int i;
311
 
312
    for (i=0; i < MAX_VIEWPORTS; i++) {
313
        if (!viewports[i].initialized)
1363 vana 314
            break;
315
    }
1485 palkovsky 316
    if (i == MAX_VIEWPORTS)
317
        return ELIMIT;
318
 
1486 palkovsky 319
    if (width ==0 || height == 0 ||
320
        x+width > screen.xres || y+height > screen.yres)
321
        return EINVAL;
322
    if (width < FONT_SCANLINES || height < COL_WIDTH)
323
        return EINVAL;
324
 
1485 palkovsky 325
    viewports[i].x = x;
326
    viewports[i].y = y;
327
    viewports[i].width = width;
328
    viewports[i].height = height;
1363 vana 329
 
1485 palkovsky 330
    viewports[i].rows = height / FONT_SCANLINES;
331
    viewports[i].cols = width / COL_WIDTH;
332
 
333
    viewports[i].bgcolor = DEFAULT_BGCOLOR;
334
    viewports[i].fgcolor = DEFAULT_FGCOLOR;
1363 vana 335
 
1489 palkovsky 336
    viewports[i].cur_col = 0;
337
    viewports[i].cur_row = 0;
338
    viewports[i].cursor_active = 0;
339
 
1486 palkovsky 340
    viewports[i].initialized = 1;
341
 
1485 palkovsky 342
    return i;
1363 vana 343
}
344
 
345
 
346
/** Initialize framebuffer as a chardev output device
347
 *
348
 * @param addr Address of theframebuffer
349
 * @param x    Screen width in pixels
350
 * @param y    Screen height in pixels
351
 * @param bpp  Bits per pixel (8, 16, 24, 32)
352
 * @param scan Bytes per one scanline
353
 *
354
 */
1485 palkovsky 355
static void screen_init(__address addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan)
1363 vana 356
{
357
    switch (bpp) {
358
        case 8:
1485 palkovsky 359
            screen.putpixel = putpixel_1byte;
360
            screen.getpixel = getpixel_1byte;
361
            screen.pixelbytes = 1;
1363 vana 362
            break;
363
        case 16:
1485 palkovsky 364
            screen.putpixel = putpixel_2byte;
365
            screen.getpixel = getpixel_2byte;
366
            screen.pixelbytes = 2;
1363 vana 367
            break;
368
        case 24:
1485 palkovsky 369
            screen.putpixel = putpixel_3byte;
370
            screen.getpixel = getpixel_3byte;
371
            screen.pixelbytes = 3;
1363 vana 372
            break;
373
        case 32:
1485 palkovsky 374
            screen.putpixel = putpixel_4byte;
375
            screen.getpixel = getpixel_4byte;
376
            screen.pixelbytes = 4;
1363 vana 377
            break;
378
    }
379
 
380
 
1485 palkovsky 381
    screen.fbaddress = (unsigned char *) addr;
382
    screen.xres = xres;
383
    screen.yres = yres;
384
    screen.scanline = scan;
1363 vana 385
 
1485 palkovsky 386
    /* Create first viewport */
387
    viewport_create(0,0,xres,yres);
1363 vana 388
 
1485 palkovsky 389
    clear_port(0);
390
}
1363 vana 391
 
1485 palkovsky 392
static int init_fb(void)
393
{
394
    __address fb_ph_addr;
395
    unsigned int fb_width;
396
    unsigned int fb_height;
397
    unsigned int fb_bpp;
398
    unsigned int fb_scanline;
399
    __address fb_addr;
400
    int a=0;
401
    int i,j,k;
402
    int w;
403
    char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";
1363 vana 404
 
1485 palkovsky 405
    fb_ph_addr=sysinfo_value("fb.address.physical");
406
    fb_width=sysinfo_value("fb.width");
407
    fb_height=sysinfo_value("fb.height");
408
    fb_bpp=sysinfo_value("fb.bpp");
409
    fb_scanline=sysinfo_value("fb.scanline");
1363 vana 410
 
1485 palkovsky 411
    fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
412
 
413
    map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,
414
            (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,
415
            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
416
 
417
    screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline);
1363 vana 418
 
1485 palkovsky 419
    return 0;
1363 vana 420
}
421
 
1489 palkovsky 422
static void draw_char(int vp, char c, unsigned int row, unsigned int col)
1486 palkovsky 423
{
424
    viewport_t *vport = &viewports[vp];
425
 
426
    if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row))
1489 palkovsky 427
        invert_char(vp, vport->cur_row, vport->cur_col);
1486 palkovsky 428
 
1489 palkovsky 429
    draw_glyph(vp, c, row, col);
430
 
431
    vport->cur_col = col;
432
    vport->cur_row = row;
433
 
434
    vport->cur_col++;
435
    if (vport->cur_col>= vport->cols) {
436
        vport->cur_col = 0;
437
        vport->cur_row++;
438
        if (vport->cur_row >= vport->rows)
439
            vport->cur_row--;
1486 palkovsky 440
    }
1489 palkovsky 441
    if (vport->cursor_active)
442
        invert_char(vp, vport->cur_row, vport->cur_col);
1486 palkovsky 443
}
444
 
1485 palkovsky 445
void client_connection(ipc_callid_t iid, ipc_call_t *icall)
1363 vana 446
{
1485 palkovsky 447
    ipc_callid_t callid;
448
    ipc_call_t call;
449
    int retval;
450
    int i;
451
    unsigned int row,col;
452
    char c;
1486 palkovsky 453
 
1485 palkovsky 454
    int vp = 0;
1486 palkovsky 455
    viewport_t *vport = &viewports[0];
1363 vana 456
 
1485 palkovsky 457
    if (client_connected) {
458
        ipc_answer_fast(iid, ELIMIT, 0,0);
459
        return;
460
    }
1486 palkovsky 461
    client_connected = 1;
1485 palkovsky 462
    ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */
1363 vana 463
 
1485 palkovsky 464
    while (1) {
465
        callid = async_get_call(&call);
466
        switch (IPC_GET_METHOD(call)) {
467
        case IPC_M_PHONE_HUNGUP:
468
            client_connected = 0;
469
            /* cleanup other viewports */
470
            for (i=1; i < MAX_VIEWPORTS; i++)
1486 palkovsky 471
                vport->initialized = 0;
1485 palkovsky 472
            ipc_answer_fast(callid,0,0,0);
473
            return; /* Exit thread */
474
        case FB_PUTCHAR:
475
            c = IPC_GET_ARG1(call);
476
            row = IPC_GET_ARG2(call);
477
            col = IPC_GET_ARG3(call);
1486 palkovsky 478
            if (row >= vport->rows || col >= vport->cols) {
1485 palkovsky 479
                retval = EINVAL;
480
                break;
481
            }
482
            ipc_answer_fast(callid,0,0,0);
1486 palkovsky 483
 
484
            draw_char(vp, c, row, col);
1485 palkovsky 485
            continue; /* msg already answered */
486
        case FB_CLEAR:
487
            clear_port(vp);
1486 palkovsky 488
            if (vport->cursor_active)
1489 palkovsky 489
                invert_char(vp, vport->cur_row, vport->cur_col);
1485 palkovsky 490
            retval = 0;
491
            break;
1486 palkovsky 492
        case FB_CURSOR_GOTO:
493
            row = IPC_GET_ARG1(call);
494
            col = IPC_GET_ARG2(call);
495
            if (row >= vport->rows || col >= vport->cols) {
496
                retval = EINVAL;
497
                break;
498
            }
499
            retval = 0;
500
            if (viewports[vp].cursor_active) {
1489 palkovsky 501
                invert_char(vp, vport->cur_row, vport->cur_col);
502
                invert_char(vp, row, col);
1486 palkovsky 503
            }
504
            vport->cur_col = col;
505
            vport->cur_row = row;
506
            break;
507
        case FB_CURSOR_VISIBILITY:
508
            i = IPC_GET_ARG1(call);
509
            retval = 0;
510
            if ((i && vport->cursor_active) || (!i && !vport->cursor_active))
511
                break;
512
 
513
            vport->cursor_active = i;
1489 palkovsky 514
            invert_char(vp, vport->cur_row, vport->cur_col);
1486 palkovsky 515
            break;
1485 palkovsky 516
        case FB_GET_CSIZE:
1486 palkovsky 517
            ipc_answer_fast(callid, 0, vport->rows, vport->cols);
1485 palkovsky 518
            continue;
1486 palkovsky 519
        case FB_SCROLL:
520
            i = IPC_GET_ARG1(call);
521
            if (i > vport->rows || i < (- (int)vport->rows)) {
522
                retval = EINVAL;
523
                break;
524
            }
525
            if (vport->cursor_active)
1489 palkovsky 526
                invert_char(vp, vport->cur_row, vport->cur_col);
1486 palkovsky 527
            scroll_port(vp, i);
528
            if (vport->cursor_active)
1489 palkovsky 529
                invert_char(vp, vport->cur_row, vport->cur_col);
1486 palkovsky 530
            retval = 0;
531
            break;
532
        case FB_VIEWPORT_SWITCH:
533
            i = IPC_GET_ARG1(call);
534
            if (i < 0 || i >= MAX_VIEWPORTS) {
535
                retval = EINVAL;
536
                break;
537
            }
538
            if (! viewports[i].initialized ) {
539
                retval = EADDRNOTAVAIL;
540
                break;
541
            }
542
            vp = i;
543
            vport = &viewports[vp];
544
            retval = 0;
545
            break;
546
        case FB_VIEWPORT_CREATE:
547
            retval = viewport_create(IPC_GET_ARG1(call) >> 16,
548
                         IPC_GET_ARG1(call) & 0xffff,
549
                         IPC_GET_ARG2(call) >> 16,
550
                         IPC_GET_ARG2(call) & 0xffff);
551
            break;
552
        case FB_VIEWPORT_DELETE:
553
            i = IPC_GET_ARG1(call);
554
            if (i < 0 || i >= MAX_VIEWPORTS) {
555
                retval = EINVAL;
556
                break;
557
            }
558
            if (! viewports[i].initialized ) {
559
                retval = EADDRNOTAVAIL;
560
                break;
561
            }
562
            viewports[i].initialized = 0;
563
            retval = 0;
564
            break;
565
        case FB_SET_STYLE:
566
            vport->fgcolor = IPC_GET_ARG1(call);
567
            vport->bgcolor = IPC_GET_ARG2(call);
568
            retval = 0;
569
            break;
570
        case FB_GET_RESOLUTION:
571
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
572
            continue;
1485 palkovsky 573
        default:
574
            retval = ENOENT;
575
        }
576
        ipc_answer_fast(callid,retval,0,0);
1363 vana 577
    }
1485 palkovsky 578
}
1363 vana 579
 
1485 palkovsky 580
int main(int argc, char *argv[])
581
{
582
    char connected = 0;
583
    int res;
584
    ipcarg_t phonead;
1363 vana 585
 
1485 palkovsky 586
    if(!sysinfo_value("fb"))
587
        return -1;
1363 vana 588
 
1485 palkovsky 589
    if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)
590
        return -1;
591
 
592
    if (init_fb() != 0)
593
        return -1;
1363 vana 594
 
1485 palkovsky 595
    async_manager();
596
    /* Never reached */
597
    return 0;
1363 vana 598
}