Subversion Repositories HelenOS

Rev

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