Subversion Repositories HelenOS

Rev

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

Rev 1981 Rev 1990
Line 95... Line 95...
95
}
95
}
96
 
96
 
97
/* Conversion routines between different color representations */
97
/* Conversion routines between different color representations */
98
static void rgb_4byte(void *dst, int rgb)
98
static void rgb_4byte(void *dst, int rgb)
99
{
99
{
100
    *(int *)dst = rgb;
100
    *((int *) dst) = rgb;
101
}
101
}
102
 
102
 
103
static int byte4_rgb(void *src)
103
static int byte4_rgb(void *src)
104
{
104
{
105
    return (*(int *)src) & 0xffffff;
105
    return (*((int *) src)) & 0xffffff;
106
}
106
}
107
 
107
 
108
static void rgb_3byte(void *dst, int rgb)
108
static void rgb_3byte(void *dst, int rgb)
109
{
109
{
110
    uint8_t *scr = dst;
110
    uint8_t *scr = dst;
Line 131... Line 131...
131
 
131
 
132
/**  16-bit depth (5:6:5) */
132
/**  16-bit depth (5:6:5) */
133
static void rgb_2byte(void *dst, int rgb)
133
static void rgb_2byte(void *dst, int rgb)
134
{
134
{
135
    /* 5-bit, 6-bits, 5-bits */
135
    /* 5-bit, 6-bits, 5-bits */
136
    *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
136
    *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5);
137
}
137
}
138
 
138
 
139
/** 16-bit depth (5:6:5) */
139
/** 16-bit depth (5:6:5) */
140
static int byte2_rgb(void *src)
140
static int byte2_rgb(void *src)
141
{
141
{
Line 151... Line 151...
151
 * palette. This could be fixed by supporting custom palette
151
 * palette. This could be fixed by supporting custom palette
152
 * and setting it to simulate the 8-bit truecolor.
152
 * and setting it to simulate the 8-bit truecolor.
153
 */
153
 */
154
static void rgb_1byte(void *dst, int rgb)
154
static void rgb_1byte(void *dst, int rgb)
155
{
155
{
156
    *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
156
    *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
157
}
157
}
158
 
158
 
159
/** Return pixel color - 8-bit depth (color palette/3:2:3)
159
/** Return pixel color - 8-bit depth (color palette/3:2:3)
160
 *
160
 *
161
 * See the comment for rgb_1byte().
161
 * See the comment for rgb_1byte().
Line 166... Line 166...
166
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
166
    return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
167
}
167
}
168
 
168
 
169
static void putpixel(unsigned int x, unsigned int y, int color)
169
static void putpixel(unsigned int x, unsigned int y, int color)
170
{
170
{
171
    (*rgb2scr)(&fbaddress[POINTPOS(x,y)], COLOR(color));
171
    (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color));
172
 
172
 
173
    if (dbbuffer) {
173
    if (dbbuffer) {
174
        int dline = (y + dboffset) % yres;
174
        int dline = (y + dboffset) % yres;
175
        (*rgb2scr)(&dbbuffer[POINTPOS(x,dline)], COLOR(color));
175
        (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color));
176
    }
176
    }
177
}
177
}
178
 
178
 
179
/** Get pixel from viewport */
179
/** Get pixel from viewport */
180
static int getpixel(unsigned int x, unsigned int y)
180
static int getpixel(unsigned int x, unsigned int y)
181
{
181
{
182
    if (dbbuffer) {
182
    if (dbbuffer) {
183
        int dline = (y + dboffset) % yres;
183
        int dline = (y + dboffset) % yres;
184
        return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x,dline)]));
184
        return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)]));
185
    }
185
    }
186
    return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x,y)]));
186
    return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)]));
187
}
187
}
188
 
188
 
189
 
189
 
190
/** Fill screen with background color */
190
/** Fill screen with background color */
191
static void clear_screen(void)
191
static void clear_screen(void)
192
{
192
{
193
    unsigned int y;
193
    unsigned int y;
194
 
194
 
195
    for (y = 0; y < yres; y++) {
195
    for (y = 0; y < yres; y++) {
196
        memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes);
196
        memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes);
197
        if (dbbuffer)
197
        if (dbbuffer)
198
            memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes);
198
            memcpy(&dbbuffer[scanline * y], blankline, xres * pixelbytes);
199
    }
199
    }
200
}
200
}
201
 
201
 
202
 
202
 
203
/** Scroll screen one row up */
203
/** Scroll screen one row up */
Line 205... Line 205...
205
{
205
{
206
    uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
206
    uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES];
207
    int firstsz;
207
    int firstsz;
208
 
208
 
209
    if (dbbuffer) {
209
    if (dbbuffer) {
210
        memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline);
210
        memcpy(&dbbuffer[dboffset * scanline], blankline, FONT_SCANLINES * scanline);
211
       
211
       
212
        dboffset = (dboffset + FONT_SCANLINES) % yres;
212
        dboffset = (dboffset + FONT_SCANLINES) % yres;
213
        firstsz = yres-dboffset;
213
        firstsz = yres - dboffset;
214
 
214
 
215
        memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline);
215
        memcpy(fbaddress, &dbbuffer[scanline * dboffset], firstsz * scanline);
216
        memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline);
216
        memcpy(&fbaddress[firstsz * scanline], dbbuffer, dboffset * scanline);
217
    } else {
217
    } else {
218
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
218
        memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES);
219
        /* Clear last row */
219
        /* Clear last row */
220
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
220
        memcpy((void *) lastline, (void *) blankline, ROW_BYTES);
221
    }
221
    }
Line 356... Line 356...
356
 * @param align Request alignment for 24bpp mode.
356
 * @param align Request alignment for 24bpp mode.
357
 */
357
 */
358
void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, bool align)
358
void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, bool align)
359
{
359
{
360
    switch (bpp) {
360
    switch (bpp) {
361
    case 8:
361
        case 8:
362
        rgb2scr = rgb_1byte;
362
            rgb2scr = rgb_1byte;
363
        scr2rgb = byte1_rgb;
363
            scr2rgb = byte1_rgb;
364
        pixelbytes = 1;
364
            pixelbytes = 1;
365
        break;
365
            break;
366
    case 16:
366
        case 16:
367
        rgb2scr = rgb_2byte;
367
            rgb2scr = rgb_2byte;
368
        scr2rgb = byte2_rgb;
368
            scr2rgb = byte2_rgb;
369
        pixelbytes = 2;
369
            pixelbytes = 2;
370
        break;
370
            break;
371
    case 24:
371
        case 24:
372
        rgb2scr = rgb_3byte;
372
            rgb2scr = rgb_3byte;
373
        scr2rgb = byte3_rgb;
373
            scr2rgb = byte3_rgb;
374
        if (align)
374
            if (align)
-
 
375
                pixelbytes = 4;
-
 
376
            else
-
 
377
                pixelbytes = 3;
-
 
378
            break;
-
 
379
        case 32:
-
 
380
            rgb2scr = rgb_4byte;
-
 
381
            scr2rgb = byte4_rgb;
375
            pixelbytes = 4;
382
            pixelbytes = 4;
376
        else
-
 
377
            pixelbytes = 3;
-
 
378
        break;
383
            break;
379
    case 32:
-
 
380
        rgb2scr = rgb_4byte;
-
 
381
        scr2rgb = byte4_rgb;
-
 
382
        pixelbytes = 4;
-
 
383
        break;
-
 
384
    default:
384
        default:
385
        panic("Unsupported bpp.\n");
385
            panic("Unsupported bpp.\n");
386
    }
386
    }
387
   
387
   
388
    unsigned int fbsize = scan * y;
388
    unsigned int fbsize = scan * y;
389
   
389
   
390
    /* Map the framebuffer */
390
    /* Map the framebuffer */
Line 407... Line 407...
407
    sysinfo_set_item_val("fb.scanline", NULL, scan);
407
    sysinfo_set_item_val("fb.scanline", NULL, scan);
408
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
408
    sysinfo_set_item_val("fb.address.physical", NULL, addr);
409
    sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
409
    sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors);
410
 
410
 
411
    /* Allocate double buffer */
411
    /* Allocate double buffer */
412
    int totsize = scanline * yres;
-
 
413
    int pages = SIZE2FRAMES(totsize);
412
    unsigned int order = fnzb(SIZE2FRAMES(ALIGN_UP(fbsize, FRAME_SIZE))) + 1;
414
    int order;
-
 
415
    if (pages == 1)
-
 
416
        order = 0;
-
 
417
    else
-
 
418
        order = fnzb(pages - 1) + 1;
-
 
419
 
-
 
420
    dbbuffer = frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
413
    dbbuffer = (uint8_t * ) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
421
    if (!dbbuffer)
414
    if (!dbbuffer)
422
        printf("Failed to allocate scroll buffer.\n");
415
        printf("Failed to allocate scroll buffer.\n");
423
    dboffset = 0;
416
    dboffset = 0;
424
 
417
 
425
    /* Initialized blank line */
418
    /* Initialized blank line */
426
    blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC);
419
    blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC);
427
    if (!blankline)
420
    if (!blankline)
428
        panic("Failed to allocate blank line for framebuffer.");
421
        panic("Failed to allocate blank line for framebuffer.");
429
    for (y=0; y < FONT_SCANLINES; y++) {
422
    for (y = 0; y < FONT_SCANLINES; y++)
430
        for (x=0; x < xres; x++) {
423
        for (x = 0; x < xres; x++)
431
            (*rgb2scr)(&blankline[POINTPOS(x,y)], COLOR(BGCOLOR));
424
            (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR));
432
        }
-
 
433
    }
425
   
434
 
-
 
435
    clear_screen();
426
    clear_screen();
436
 
427
 
437
    /* Update size of screen to match text area */
428
    /* Update size of screen to match text area */
438
    yres = rows * FONT_SCANLINES;
429
    yres = rows * FONT_SCANLINES;
439
 
430
 
440
    draw_logo(xres - helenos_width, 0);
431
    draw_logo(xres - helenos_width, 0);
441
    invert_cursor();
432
    invert_cursor();
442
 
433
 
443
    chardev_initialize("fb", &framebuffer, &fb_ops);
434
    chardev_initialize("fb", &framebuffer, &fb_ops);
444
    stdout = &framebuffer;
435
    stdout = &framebuffer;
445
   
-
 
446
}
436
}
447
 
437
 
448
/** @}
438
/** @}
449
 */
439
 */