Subversion Repositories HelenOS

Rev

Rev 4093 | Rev 4182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4093 Rev 4177
Line 51... Line 51...
51
#include <arch/types.h>
51
#include <arch/types.h>
52
 
52
 
53
SPINLOCK_INITIALIZE(fb_lock);
53
SPINLOCK_INITIALIZE(fb_lock);
54
 
54
 
55
static uint8_t *fb_addr;
55
static uint8_t *fb_addr;
56
static uint8_t *backbuf;
56
static uint16_t *backbuf;
57
static uint8_t *glyphs;
57
static uint8_t *glyphs;
58
static uint8_t *bgscan;
58
static uint8_t *bgscan;
59
 
59
 
60
static unsigned int xres;
60
static unsigned int xres;
61
static unsigned int yres;
61
static unsigned int yres;
Line 197... Line 197...
197
 
197
 
198
 
198
 
199
/** Draw character at given position
199
/** Draw character at given position
200
 *
200
 *
201
 */
201
 */
202
static void glyph_draw(uint8_t glyph, unsigned int col, unsigned int row, bool silent)
202
static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent)
203
{
203
{
204
    unsigned int x = COL2X(col);
204
    unsigned int x = COL2X(col);
205
    unsigned int y = ROW2Y(row);
205
    unsigned int y = ROW2Y(row);
206
    unsigned int yd;
206
    unsigned int yd;
207
   
207
   
Line 240... Line 240...
240
                unsigned int x;
240
                unsigned int x;
241
                unsigned int col;
241
                unsigned int col;
242
               
242
               
243
                for (col = 0, x = 0; col < cols; col++,
243
                for (col = 0, x = 0; col < cols; col++,
244
                    x += FONT_WIDTH) {
244
                    x += FONT_WIDTH) {
245
                    uint8_t glyph;
245
                    uint16_t glyph;
246
                   
246
                   
247
                    if (row < rows - 1) {
247
                    if (row < rows - 1) {
248
                        if (backbuf[BB_POS(col, row)] ==
248
                        if (backbuf[BB_POS(col, row)] ==
249
                            backbuf[BB_POS(col, row + 1)])
249
                            backbuf[BB_POS(col, row + 1)])
250
                            continue;
250
                            continue;
Line 259... Line 259...
259
                }
259
                }
260
            }
260
            }
261
        }
261
        }
262
    }
262
    }
263
   
263
   
264
    memmove(backbuf, backbuf + cols, cols * (rows - 1));
264
    memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t));
265
    memsetb(&backbuf[BB_POS(0, rows - 1)], cols, 0);
265
    memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0);
266
}
266
}
267
 
267
 
268
 
268
 
269
static void cursor_put(bool silent)
269
static void cursor_put(bool silent)
270
{
270
{
271
    glyph_draw(CURSOR, position % cols, position / cols, silent);
271
    glyph_draw(fb_font_glyph(CURSOR), position % cols, position / cols, silent);
272
}
272
}
273
 
273
 
274
 
274
 
275
static void cursor_remove(bool silent)
275
static void cursor_remove(bool silent)
276
{
276
{
277
    glyph_draw(0, position % cols, position / cols, silent);
277
    glyph_draw(fb_font_glyph(0), position % cols, position / cols, silent);
278
}
278
}
279
 
279
 
280
 
280
 
281
/** Print character to screen
281
/** Print character to screen
282
 *
282
 *
283
 * Emulate basic terminal commands.
283
 * Emulate basic terminal commands.
284
 *
284
 *
285
 */
285
 */
286
static void fb_putchar(outdev_t *dev, char ch, bool silent)
286
static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent)
287
{
287
{
288
    spinlock_lock(&fb_lock);
288
    spinlock_lock(&fb_lock);
289
   
289
   
290
    switch (ch) {
290
    switch (ch) {
291
    case '\n':
291
    case '\n':
Line 303... Line 303...
303
            position--;
303
            position--;
304
        break;
304
        break;
305
    case '\t':
305
    case '\t':
306
        cursor_remove(silent);
306
        cursor_remove(silent);
307
        do {
307
        do {
308
            glyph_draw((uint8_t) ' ', position % cols,
308
            glyph_draw(fb_font_glyph(' '), position % cols,
309
                position / cols, silent);
309
                position / cols, silent);
310
            position++;
310
            position++;
311
        } while ((position % 8) && (position < cols * rows));
311
        } while ((position % 8) && (position < cols * rows));
312
        break;
312
        break;
313
    default:
313
    default:
314
        glyph_draw((uint8_t) ch, position % cols,
314
        glyph_draw(fb_font_glyph(ch), position % cols,
315
            position / cols, silent);
315
            position / cols, silent);
316
        position++;
316
        position++;
317
    }
317
    }
318
   
318
   
319
    if (position >= cols * rows) {
319
    if (position >= cols * rows) {
Line 339... Line 339...
339
 *
339
 *
340
 */
340
 */
341
static void glyphs_render(void)
341
static void glyphs_render(void)
342
{
342
{
343
    /* Prerender glyphs */
343
    /* Prerender glyphs */
344
    unsigned int glyph;
344
    uint16_t glyph;
345
   
345
   
346
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
346
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
347
        unsigned int y;
347
        unsigned int y;
348
       
348
       
349
        for (y = 0; y < FONT_SCANLINES; y++) {
349
        for (y = 0; y < FONT_SCANLINES; y++) {
350
            unsigned int x;
350
            unsigned int x;
351
           
351
           
352
            for (x = 0; x < FONT_WIDTH; x++) {
352
            for (x = 0; x < FONT_WIDTH; x++) {
353
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
353
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
354
                    x * pixelbytes];
354
                    x * pixelbytes];
355
                uint32_t rgb = (fb_font[ROW2Y(glyph) + y] &
355
                uint32_t rgb = (fb_font[glyph][y] &
356
                    (1 << (7 - x))) ? FG_COLOR : BG_COLOR;
356
                    (1 << (7 - x))) ? FG_COLOR : BG_COLOR;
357
                rgb_conv(dst, rgb);
357
                rgb_conv(dst, rgb);
358
            }
358
            }
359
        }
359
        }
360
    }
360
    }
Line 396... Line 396...
396
            unsigned int x;
396
            unsigned int x;
397
            unsigned int col;
397
            unsigned int col;
398
           
398
           
399
            for (col = 0, x = 0; col < cols;
399
            for (col = 0, x = 0; col < cols;
400
                col++, x += FONT_WIDTH) {
400
                col++, x += FONT_WIDTH) {
-
 
401
                uint16_t glyph = backbuf[BB_POS(col, row)];
401
                void *d = &fb_addr[FB_POS(x, y + yd)];
402
                void *dst = &fb_addr[FB_POS(x, y + yd)];
402
                void *s = &glyphs[GLYPH_POS(backbuf[BB_POS(col,
403
                void *src = &glyphs[GLYPH_POS(glyph, yd)];
403
                    row)], yd)];
-
 
404
                memcpy(d, s, glyphscanline);
404
                memcpy(dst, src, glyphscanline);
405
            }
405
            }
406
        }
406
        }
407
    }
407
    }
408
   
408
   
409
    if (COL2X(cols) < xres) {
409
    if (COL2X(cols) < xres) {
Line 492... Line 492...
492
   
492
   
493
    glyphscanline = FONT_WIDTH * pixelbytes;
493
    glyphscanline = FONT_WIDTH * pixelbytes;
494
    glyphbytes = ROW2Y(glyphscanline);
494
    glyphbytes = ROW2Y(glyphscanline);
495
    bgscanbytes = xres * pixelbytes;
495
    bgscanbytes = xres * pixelbytes;
496
   
496
   
497
    unsigned int fbsize = scanline * yres;
497
    size_t fbsize = scanline * yres;
498
    unsigned int bbsize = cols * rows;
498
    size_t bbsize = cols * rows * sizeof(uint16_t);
499
    unsigned int glyphsize = FONT_GLYPHS * glyphbytes;
499
    size_t glyphsize = FONT_GLYPHS * glyphbytes;
500
   
500
   
501
    backbuf = (uint8_t *) malloc(bbsize, 0);
501
    backbuf = (uint16_t *) malloc(bbsize, 0);
502
    if (!backbuf)
502
    if (!backbuf)
503
        panic("Unable to allocate backbuffer.");
503
        panic("Unable to allocate backbuffer.");
504
   
504
   
505
    glyphs = (uint8_t *) malloc(glyphsize, 0);
505
    glyphs = (uint8_t *) malloc(glyphsize, 0);
506
    if (!glyphs)
506
    if (!glyphs)
Line 508... Line 508...
508
   
508
   
509
    bgscan = malloc(bgscanbytes, 0);
509
    bgscan = malloc(bgscanbytes, 0);
510
    if (!bgscan)
510
    if (!bgscan)
511
        panic("Unable to allocate background pixel.");
511
        panic("Unable to allocate background pixel.");
512
   
512
   
513
    memsetb(backbuf, bbsize, 0);
513
    memsetw(backbuf, cols * rows, 0);
514
   
514
   
515
    glyphs_render();
515
    glyphs_render();
516
   
516
   
517
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
517
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
518
   
518