Subversion Repositories HelenOS

Rev

Rev 4223 | Rev 4676 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4223 Rev 4669
1
/*
1
/*
2
 * Copyright (c) 2008 Martin Decky
2
 * Copyright (c) 2008 Martin Decky
3
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * Copyright (c) 2006 Ondrej Palkovsky
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
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
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.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
/** @addtogroup genarch
30
/** @addtogroup genarch
31
 * @{
31
 * @{
32
 */
32
 */
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
#include <genarch/fb/font-8x16.h>
36
#include <genarch/fb/font-8x16.h>
37
#include <genarch/fb/logo-196x66.h>
37
#include <genarch/fb/logo-196x66.h>
38
#include <genarch/fb/visuals.h>
38
#include <genarch/fb/visuals.h>
39
#include <genarch/fb/fb.h>
39
#include <genarch/fb/fb.h>
40
#include <console/chardev.h>
40
#include <console/chardev.h>
41
#include <console/console.h>
41
#include <console/console.h>
42
#include <sysinfo/sysinfo.h>
42
#include <sysinfo/sysinfo.h>
43
#include <mm/slab.h>
43
#include <mm/slab.h>
44
#include <align.h>
44
#include <align.h>
45
#include <panic.h>
45
#include <panic.h>
46
#include <memstr.h>
46
#include <memstr.h>
47
#include <config.h>
47
#include <config.h>
48
#include <bitops.h>
48
#include <bitops.h>
49
#include <print.h>
49
#include <print.h>
50
#include <string.h>
50
#include <string.h>
51
#include <ddi/ddi.h>
51
#include <ddi/ddi.h>
52
#include <arch/types.h>
52
#include <arch/types.h>
53
 
53
 
54
SPINLOCK_INITIALIZE(fb_lock);
54
SPINLOCK_INITIALIZE(fb_lock);
55
 
55
 
56
static uint8_t *fb_addr;
56
static uint8_t *fb_addr;
57
static uint16_t *backbuf;
57
static uint16_t *backbuf;
58
static uint8_t *glyphs;
58
static uint8_t *glyphs;
59
static uint8_t *bgscan;
59
static uint8_t *bgscan;
60
 
60
 
61
static unsigned int xres;
61
static unsigned int xres;
62
static unsigned int yres;
62
static unsigned int yres;
63
 
63
 
64
static unsigned int ylogo;
64
static unsigned int ylogo;
65
static unsigned int ytrim;
65
static unsigned int ytrim;
66
static unsigned int rowtrim;
66
static unsigned int rowtrim;
67
 
67
 
68
static unsigned int scanline;
68
static unsigned int scanline;
69
static unsigned int glyphscanline;
69
static unsigned int glyphscanline;
70
 
70
 
71
static unsigned int pixelbytes;
71
static unsigned int pixelbytes;
72
static unsigned int glyphbytes;
72
static unsigned int glyphbytes;
73
static unsigned int bgscanbytes;
73
static unsigned int bgscanbytes;
74
 
74
 
75
static unsigned int cols;
75
static unsigned int cols;
76
static unsigned int rows;
76
static unsigned int rows;
77
static unsigned int position = 0;
77
static unsigned int position = 0;
78
 
78
 
79
#define BG_COLOR     0x000080
79
#define BG_COLOR     0x000080
80
#define FG_COLOR     0xffff00
80
#define FG_COLOR     0xffff00
81
#define INV_COLOR    0xaaaaaa
81
#define INV_COLOR    0xaaaaaa
82
 
82
 
83
#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
83
#define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
84
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
84
#define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
85
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
85
#define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
86
 
86
 
87
#define COL2X(col)           ((col) * FONT_WIDTH)
87
#define COL2X(col)           ((col) * FONT_WIDTH)
88
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
88
#define ROW2Y(row)           ((row) * FONT_SCANLINES)
89
 
89
 
90
#define X2COL(x)             ((x) / FONT_WIDTH)
90
#define X2COL(x)             ((x) / FONT_WIDTH)
91
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
91
#define Y2ROW(y)             ((y) / FONT_SCANLINES)
92
 
92
 
93
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
93
#define FB_POS(x, y)         ((y) * scanline + (x) * pixelbytes)
94
#define BB_POS(col, row)     ((row) * cols + (col))
94
#define BB_POS(col, row)     ((row) * cols + (col))
95
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
95
#define GLYPH_POS(glyph, y)  ((glyph) * glyphbytes + (y) * glyphscanline)
96
 
96
 
97
 
97
 
98
static void (*rgb_conv)(void *, uint32_t);
98
static void (*rgb_conv)(void *, uint32_t);
99
 
99
 
100
 
100
 
101
/** ARGB 8:8:8:8 conversion
101
/** ARGB 8:8:8:8 conversion
102
 *
102
 *
103
 */
103
 */
104
static void rgb_0888(void *dst, uint32_t rgb)
104
static void rgb_0888(void *dst, uint32_t rgb)
105
{
105
{
106
    *((uint32_t *) dst) = rgb & 0xffffff;
106
    *((uint32_t *) dst) = rgb & 0xffffff;
107
}
107
}
108
 
108
 
109
 
109
 
110
/** ABGR 8:8:8:8 conversion
110
/** ABGR 8:8:8:8 conversion
111
 *
111
 *
112
 */
112
 */
113
static void bgr_0888(void *dst, uint32_t rgb)
113
static void bgr_0888(void *dst, uint32_t rgb)
114
{
114
{
115
    *((uint32_t *) dst)
115
    *((uint32_t *) dst)
116
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
116
        = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
117
}
117
}
118
 
118
 
-
 
119
static void rgb_8880(void *dst, uint32_t rgb)
-
 
120
{
-
 
121
    *((uint32_t *) dst)
-
 
122
       = (RED(rgb, 8) << 24) | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8);
-
 
123
 
-
 
124
}
-
 
125
 
119
 
126
 
120
/** RGB 8:8:8 conversion
127
/** RGB 8:8:8 conversion
121
 *
128
 *
122
 */
129
 */
123
static void rgb_888(void *dst, uint32_t rgb)
130
static void rgb_888(void *dst, uint32_t rgb)
124
{
131
{
125
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
132
    ((uint8_t *) dst)[0] = BLUE(rgb, 8);
126
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
133
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
127
    ((uint8_t *) dst)[2] = RED(rgb, 8);
134
    ((uint8_t *) dst)[2] = RED(rgb, 8);
128
}
135
}
129
 
136
 
130
 
137
 
131
/** BGR 8:8:8 conversion
138
/** BGR 8:8:8 conversion
132
 *
139
 *
133
 */
140
 */
134
static void bgr_888(void *dst, uint32_t rgb)
141
static void bgr_888(void *dst, uint32_t rgb)
135
{
142
{
136
    ((uint8_t *) dst)[0] = RED(rgb, 8);
143
    ((uint8_t *) dst)[0] = RED(rgb, 8);
137
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
144
    ((uint8_t *) dst)[1] = GREEN(rgb, 8);
138
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
145
    ((uint8_t *) dst)[2] = BLUE(rgb, 8);
139
}
146
}
140
 
147
 
141
 
148
 
142
/** RGB 5:5:5 conversion
149
/** RGB 5:5:5 conversion
143
 *
150
 *
144
 */
151
 */
145
static void rgb_555(void *dst, uint32_t rgb)
152
static void rgb_555(void *dst, uint32_t rgb)
146
{
153
{
147
    *((uint16_t *) dst)
154
    *((uint16_t *) dst)
148
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
155
        = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
149
}
156
}
150
 
157
 
151
 
158
 
152
/** RGB 5:6:5 conversion
159
/** RGB 5:6:5 conversion
153
 *
160
 *
154
 */
161
 */
155
static void rgb_565(void *dst, uint32_t rgb)
162
static void rgb_565(void *dst, uint32_t rgb)
156
{
163
{
157
    *((uint16_t *) dst)
164
    *((uint16_t *) dst)
158
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
165
        = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
159
}
166
}
160
 
167
 
161
 
168
 
162
/** RGB 3:2:3
169
/** RGB 3:2:3
163
 *
170
 *
164
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
171
 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
165
 * will most likely use a color palette. The color appearance
172
 * will most likely use a color palette. The color appearance
166
 * will be pretty random and depend on the default installed
173
 * will be pretty random and depend on the default installed
167
 * palette. This could be fixed by supporting custom palette
174
 * palette. This could be fixed by supporting custom palette
168
 * and setting it to simulate the 8-bit truecolor.
175
 * and setting it to simulate the 8-bit truecolor.
169
 *
176
 *
170
 * Currently we set the palette on the ia32, amd64 and sparc64 port.
177
 * Currently we set the palette on the ia32, amd64 and sparc64 port.
171
 *
178
 *
172
 * Note that the byte is being inverted by this function. The reason is
179
 * Note that the byte is being inverted by this function. The reason is
173
 * that we would like to use a color palette where the white color code
180
 * that we would like to use a color palette where the white color code
174
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
181
 * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
175
 * use these codes for black and white and prevent to set codes
182
 * use these codes for black and white and prevent to set codes
176
 * 0 and 255 to other colors.
183
 * 0 and 255 to other colors.
177
 *
184
 *
178
 */
185
 */
179
static void rgb_323(void *dst, uint32_t rgb)
186
static void rgb_323(void *dst, uint32_t rgb)
180
{
187
{
181
    *((uint8_t *) dst)
188
    *((uint8_t *) dst)
182
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
189
        = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
183
}
190
}
184
 
191
 
185
 
192
 
186
/** Hide logo and refresh screen
193
/** Hide logo and refresh screen
187
 *
194
 *
188
 */
195
 */
189
static void logo_hide(bool silent)
196
static void logo_hide(bool silent)
190
{
197
{
191
    ylogo = 0;
198
    ylogo = 0;
192
    ytrim = yres;
199
    ytrim = yres;
193
    rowtrim = rows;
200
    rowtrim = rows;
194
    if (!silent)
201
    if (!silent)
195
        fb_redraw();
202
        fb_redraw();
196
}
203
}
197
 
204
 
198
 
205
 
199
/** Draw character at given position
206
/** Draw character at given position
200
 *
207
 *
201
 */
208
 */
202
static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay)
209
static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay)
203
{
210
{
204
    unsigned int x = COL2X(col);
211
    unsigned int x = COL2X(col);
205
    unsigned int y = ROW2Y(row);
212
    unsigned int y = ROW2Y(row);
206
    unsigned int yd;
213
    unsigned int yd;
207
   
214
   
208
    if (y >= ytrim)
215
    if (y >= ytrim)
209
        logo_hide(silent);
216
        logo_hide(silent);
210
   
217
   
211
    if (!overlay)
218
    if (!overlay)
212
        backbuf[BB_POS(col, row)] = glyph;
219
        backbuf[BB_POS(col, row)] = glyph;
213
   
220
   
214
    if (!silent) {
221
    if (!silent) {
215
        for (yd = 0; yd < FONT_SCANLINES; yd++)
222
        for (yd = 0; yd < FONT_SCANLINES; yd++)
216
            memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)],
223
            memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)],
217
                &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
224
                &glyphs[GLYPH_POS(glyph, yd)], glyphscanline);
218
    }
225
    }
219
}
226
}
220
 
227
 
221
 
228
 
222
/** Scroll screen down by one row
229
/** Scroll screen down by one row
223
 *
230
 *
224
 *
231
 *
225
 */
232
 */
226
static void screen_scroll(bool silent)
233
static void screen_scroll(bool silent)
227
{
234
{
228
    if (ylogo > 0) {
235
    if (ylogo > 0) {
229
        logo_hide(silent);
236
        logo_hide(silent);
230
        return;
237
        return;
231
    }
238
    }
232
   
239
   
233
    if (!silent) {
240
    if (!silent) {
234
        unsigned int row;
241
        unsigned int row;
235
       
242
       
236
        for (row = 0; row < rows; row++) {
243
        for (row = 0; row < rows; row++) {
237
            unsigned int y = ROW2Y(row);
244
            unsigned int y = ROW2Y(row);
238
            unsigned int yd;
245
            unsigned int yd;
239
           
246
           
240
            for (yd = 0; yd < FONT_SCANLINES; yd++) {
247
            for (yd = 0; yd < FONT_SCANLINES; yd++) {
241
                unsigned int x;
248
                unsigned int x;
242
                unsigned int col;
249
                unsigned int col;
243
               
250
               
244
                for (col = 0, x = 0; col < cols; col++,
251
                for (col = 0, x = 0; col < cols; col++,
245
                    x += FONT_WIDTH) {
252
                    x += FONT_WIDTH) {
246
                    uint16_t glyph;
253
                    uint16_t glyph;
247
                   
254
                   
248
                    if (row < rows - 1) {
255
                    if (row < rows - 1) {
249
                        if (backbuf[BB_POS(col, row)] ==
256
                        if (backbuf[BB_POS(col, row)] ==
250
                            backbuf[BB_POS(col, row + 1)])
257
                            backbuf[BB_POS(col, row + 1)])
251
                            continue;
258
                            continue;
252
                       
259
                       
253
                        glyph = backbuf[BB_POS(col, row + 1)];
260
                        glyph = backbuf[BB_POS(col, row + 1)];
254
                    } else
261
                    } else
255
                        glyph = 0;
262
                        glyph = 0;
256
                   
263
                   
257
                    memcpy(&fb_addr[FB_POS(x, y + yd)],
264
                    memcpy(&fb_addr[FB_POS(x, y + yd)],
258
                        &glyphs[GLYPH_POS(glyph, yd)],
265
                        &glyphs[GLYPH_POS(glyph, yd)],
259
                        glyphscanline);
266
                        glyphscanline);
260
                }
267
                }
261
            }
268
            }
262
        }
269
        }
263
    }
270
    }
264
   
271
   
265
    memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t));
272
    memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t));
266
    memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0);
273
    memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0);
267
}
274
}
268
 
275
 
269
 
276
 
270
static void cursor_put(bool silent)
277
static void cursor_put(bool silent)
271
{
278
{
272
    unsigned int col = position % cols;
279
    unsigned int col = position % cols;
273
    unsigned int row = position / cols;
280
    unsigned int row = position / cols;
274
   
281
   
275
    glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true);
282
    glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true);
276
}
283
}
277
 
284
 
278
 
285
 
279
static void cursor_remove(bool silent)
286
static void cursor_remove(bool silent)
280
{
287
{
281
    unsigned int col = position % cols;
288
    unsigned int col = position % cols;
282
    unsigned int row = position / cols;
289
    unsigned int row = position / cols;
283
   
290
   
284
    glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true);
291
    glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true);
285
}
292
}
286
 
293
 
287
 
294
 
288
/** Print character to screen
295
/** Print character to screen
289
 *
296
 *
290
 * Emulate basic terminal commands.
297
 * Emulate basic terminal commands.
291
 *
298
 *
292
 */
299
 */
293
static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent)
300
static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent)
294
{
301
{
295
    spinlock_lock(&fb_lock);
302
    spinlock_lock(&fb_lock);
296
   
303
   
297
    switch (ch) {
304
    switch (ch) {
298
    case '\n':
305
    case '\n':
299
        cursor_remove(silent);
306
        cursor_remove(silent);
300
        position += cols;
307
        position += cols;
301
        position -= position % cols;
308
        position -= position % cols;
302
        break;
309
        break;
303
    case '\r':
310
    case '\r':
304
        cursor_remove(silent);
311
        cursor_remove(silent);
305
        position -= position % cols;
312
        position -= position % cols;
306
        break;
313
        break;
307
    case '\b':
314
    case '\b':
308
        cursor_remove(silent);
315
        cursor_remove(silent);
309
        if (position % cols)
316
        if (position % cols)
310
            position--;
317
            position--;
311
        break;
318
        break;
312
    case '\t':
319
    case '\t':
313
        cursor_remove(silent);
320
        cursor_remove(silent);
314
        do {
321
        do {
315
            glyph_draw(fb_font_glyph(' '), position % cols,
322
            glyph_draw(fb_font_glyph(' '), position % cols,
316
                position / cols, silent, false);
323
                position / cols, silent, false);
317
            position++;
324
            position++;
318
        } while ((position % 8) && (position < cols * rows));
325
        } while ((position % 8) && (position < cols * rows));
319
        break;
326
        break;
320
    default:
327
    default:
321
        glyph_draw(fb_font_glyph(ch), position % cols,
328
        glyph_draw(fb_font_glyph(ch), position % cols,
322
            position / cols, silent, false);
329
            position / cols, silent, false);
323
        position++;
330
        position++;
324
    }
331
    }
325
   
332
   
326
    if (position >= cols * rows) {
333
    if (position >= cols * rows) {
327
        position -= cols;
334
        position -= cols;
328
        screen_scroll(silent);
335
        screen_scroll(silent);
329
    }
336
    }
330
   
337
   
331
    cursor_put(silent);
338
    cursor_put(silent);
332
   
339
   
333
    spinlock_unlock(&fb_lock);
340
    spinlock_unlock(&fb_lock);
334
}
341
}
335
 
342
 
336
static outdev_t fb_console;
343
static outdev_t fb_console;
337
static outdev_operations_t fb_ops = {
344
static outdev_operations_t fb_ops = {
338
    .write = fb_putchar
345
    .write = fb_putchar
339
};
346
};
340
 
347
 
341
 
348
 
342
/** Render glyphs
349
/** Render glyphs
343
 *
350
 *
344
 * Convert glyphs from device independent font
351
 * Convert glyphs from device independent font
345
 * description to current visual representation.
352
 * description to current visual representation.
346
 *
353
 *
347
 */
354
 */
348
static void glyphs_render(void)
355
static void glyphs_render(void)
349
{
356
{
350
    /* Prerender glyphs */
357
    /* Prerender glyphs */
351
    uint16_t glyph;
358
    uint16_t glyph;
352
   
359
   
353
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
360
    for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
354
        uint32_t fg_color;
361
        uint32_t fg_color;
355
       
362
       
356
        if (glyph == FONT_GLYPHS - 1)
363
        if (glyph == FONT_GLYPHS - 1)
357
            fg_color = INV_COLOR;
364
            fg_color = INV_COLOR;
358
        else
365
        else
359
            fg_color = FG_COLOR;
366
            fg_color = FG_COLOR;
360
       
367
       
361
        unsigned int y;
368
        unsigned int y;
362
       
369
       
363
        for (y = 0; y < FONT_SCANLINES; y++) {
370
        for (y = 0; y < FONT_SCANLINES; y++) {
364
            unsigned int x;
371
            unsigned int x;
365
           
372
           
366
            for (x = 0; x < FONT_WIDTH; x++) {
373
            for (x = 0; x < FONT_WIDTH; x++) {
367
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
374
                void *dst = &glyphs[GLYPH_POS(glyph, y) +
368
                    x * pixelbytes];
375
                    x * pixelbytes];
369
                uint32_t rgb = (fb_font[glyph][y] &
376
                uint32_t rgb = (fb_font[glyph][y] &
370
                    (1 << (7 - x))) ? fg_color : BG_COLOR;
377
                    (1 << (7 - x))) ? fg_color : BG_COLOR;
371
                rgb_conv(dst, rgb);
378
                rgb_conv(dst, rgb);
372
            }
379
            }
373
        }
380
        }
374
    }
381
    }
375
   
382
   
376
    /* Prerender background scanline */
383
    /* Prerender background scanline */
377
    unsigned int x;
384
    unsigned int x;
378
   
385
   
379
    for (x = 0; x < xres; x++)
386
    for (x = 0; x < xres; x++)
380
        rgb_conv(&bgscan[x * pixelbytes], BG_COLOR);
387
        rgb_conv(&bgscan[x * pixelbytes], BG_COLOR);
381
}
388
}
382
 
389
 
383
 
390
 
384
/** Refresh the screen
391
/** Refresh the screen
385
 *
392
 *
386
 */
393
 */
387
void fb_redraw(void)
394
void fb_redraw(void)
388
{
395
{
389
    if (ylogo > 0) {
396
    if (ylogo > 0) {
390
        unsigned int y;
397
        unsigned int y;
391
       
398
       
392
        for (y = 0; y < LOGO_HEIGHT; y++) {
399
        for (y = 0; y < LOGO_HEIGHT; y++) {
393
            unsigned int x;
400
            unsigned int x;
394
           
401
           
395
            for (x = 0; x < xres; x++)
402
            for (x = 0; x < xres; x++)
396
                rgb_conv(&fb_addr[FB_POS(x, y)],
403
                rgb_conv(&fb_addr[FB_POS(x, y)],
397
                    (x < LOGO_WIDTH) ?
404
                    (x < LOGO_WIDTH) ?
398
                    fb_logo[y * LOGO_WIDTH + x] :
405
                    fb_logo[y * LOGO_WIDTH + x] :
399
                    LOGO_COLOR);
406
                    LOGO_COLOR);
400
        }
407
        }
401
    }
408
    }
402
   
409
   
403
    unsigned int row;
410
    unsigned int row;
404
   
411
   
405
    for (row = 0; row < rowtrim; row++) {
412
    for (row = 0; row < rowtrim; row++) {
406
        unsigned int y = ylogo + ROW2Y(row);
413
        unsigned int y = ylogo + ROW2Y(row);
407
        unsigned int yd;
414
        unsigned int yd;
408
       
415
       
409
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
416
        for (yd = 0; yd < FONT_SCANLINES; yd++) {
410
            unsigned int x;
417
            unsigned int x;
411
            unsigned int col;
418
            unsigned int col;
412
           
419
           
413
            for (col = 0, x = 0; col < cols;
420
            for (col = 0, x = 0; col < cols;
414
                col++, x += FONT_WIDTH) {
421
                col++, x += FONT_WIDTH) {
415
                uint16_t glyph = backbuf[BB_POS(col, row)];
422
                uint16_t glyph = backbuf[BB_POS(col, row)];
416
                void *dst = &fb_addr[FB_POS(x, y + yd)];
423
                void *dst = &fb_addr[FB_POS(x, y + yd)];
417
                void *src = &glyphs[GLYPH_POS(glyph, yd)];
424
                void *src = &glyphs[GLYPH_POS(glyph, yd)];
418
                memcpy(dst, src, glyphscanline);
425
                memcpy(dst, src, glyphscanline);
419
            }
426
            }
420
        }
427
        }
421
    }
428
    }
422
   
429
   
423
    if (COL2X(cols) < xres) {
430
    if (COL2X(cols) < xres) {
424
        unsigned int y;
431
        unsigned int y;
425
        unsigned int size = (xres - COL2X(cols)) * pixelbytes;
432
        unsigned int size = (xres - COL2X(cols)) * pixelbytes;
426
       
433
       
427
        for (y = ylogo; y < yres; y++)
434
        for (y = ylogo; y < yres; y++)
428
            memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size);
435
            memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size);
429
    }
436
    }
430
   
437
   
431
    if (ROW2Y(rowtrim) + ylogo < yres) {
438
    if (ROW2Y(rowtrim) + ylogo < yres) {
432
        unsigned int y;
439
        unsigned int y;
433
       
440
       
434
        for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++)
441
        for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++)
435
            memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes);
442
            memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes);
436
    }
443
    }
437
}
444
}
438
 
445
 
439
 
446
 
440
/** Initialize framebuffer as a output character device
447
/** Initialize framebuffer as a output character device
441
 *
448
 *
442
 * @param addr   Physical address of the framebuffer
449
 * @param addr   Physical address of the framebuffer
443
 * @param x      Screen width in pixels
450
 * @param x      Screen width in pixels
444
 * @param y      Screen height in pixels
451
 * @param y      Screen height in pixels
445
 * @param scan   Bytes per one scanline
452
 * @param scan   Bytes per one scanline
446
 * @param visual Color model
453
 * @param visual Color model
447
 *
454
 *
448
 */
455
 */
449
void fb_init(fb_properties_t *props)
456
void fb_init(fb_properties_t *props)
450
{
457
{
451
    switch (props->visual) {
458
    switch (props->visual) {
452
    case VISUAL_INDIRECT_8:
459
    case VISUAL_INDIRECT_8:
453
        rgb_conv = rgb_323;
460
        rgb_conv = rgb_323;
454
        pixelbytes = 1;
461
        pixelbytes = 1;
455
        break;
462
        break;
456
    case VISUAL_RGB_5_5_5:
463
    case VISUAL_RGB_5_5_5:
457
        rgb_conv = rgb_555;
464
        rgb_conv = rgb_555;
458
        pixelbytes = 2;
465
        pixelbytes = 2;
459
        break;
466
        break;
460
    case VISUAL_RGB_5_6_5:
467
    case VISUAL_RGB_5_6_5:
461
        rgb_conv = rgb_565;
468
        rgb_conv = rgb_565;
462
        pixelbytes = 2;
469
        pixelbytes = 2;
463
        break;
470
        break;
464
    case VISUAL_RGB_8_8_8:
471
    case VISUAL_RGB_8_8_8:
465
        rgb_conv = rgb_888;
472
        rgb_conv = rgb_888;
466
        pixelbytes = 3;
473
        pixelbytes = 3;
467
        break;
474
        break;
468
    case VISUAL_BGR_8_8_8:
475
    case VISUAL_BGR_8_8_8:
469
        rgb_conv = bgr_888;
476
        rgb_conv = bgr_888;
470
        pixelbytes = 3;
477
        pixelbytes = 3;
471
        break;
478
        break;
472
    case VISUAL_RGB_8_8_8_0:
479
    case VISUAL_RGB_8_8_8_0:
473
        rgb_conv = rgb_888;
480
        rgb_conv = rgb_8880;
474
        pixelbytes = 4;
481
        pixelbytes = 4;
475
        break;
482
        break;
476
    case VISUAL_RGB_0_8_8_8:
483
    case VISUAL_RGB_0_8_8_8:
477
        rgb_conv = rgb_0888;
484
        rgb_conv = rgb_0888;
478
        pixelbytes = 4;
485
        pixelbytes = 4;
479
        break;
486
        break;
480
    case VISUAL_BGR_0_8_8_8:
487
    case VISUAL_BGR_0_8_8_8:
481
        rgb_conv = bgr_0888;
488
        rgb_conv = bgr_0888;
482
        pixelbytes = 4;
489
        pixelbytes = 4;
483
        break;
490
        break;
484
    default:
491
    default:
485
        panic("Unsupported visual.");
492
        panic("Unsupported visual.");
486
    }
493
    }
487
   
494
   
488
    xres = props->x;
495
    xres = props->x;
489
    yres = props->y;
496
    yres = props->y;
490
    scanline = props->scan;
497
    scanline = props->scan;
491
   
498
   
492
    cols = X2COL(xres);
499
    cols = X2COL(xres);
493
    rows = Y2ROW(yres);
500
    rows = Y2ROW(yres);
494
   
501
   
495
    if (yres > ylogo) {
502
    if (yres > ylogo) {
496
        ylogo = LOGO_HEIGHT;
503
        ylogo = LOGO_HEIGHT;
497
        rowtrim = rows - Y2ROW(ylogo);
504
        rowtrim = rows - Y2ROW(ylogo);
498
        if (ylogo % FONT_SCANLINES > 0)
505
        if (ylogo % FONT_SCANLINES > 0)
499
            rowtrim--;
506
            rowtrim--;
500
        ytrim = ROW2Y(rowtrim);
507
        ytrim = ROW2Y(rowtrim);
501
    } else {
508
    } else {
502
        ylogo = 0;
509
        ylogo = 0;
503
        ytrim = yres;
510
        ytrim = yres;
504
        rowtrim = rows;
511
        rowtrim = rows;
505
    }
512
    }
506
   
513
   
507
    glyphscanline = FONT_WIDTH * pixelbytes;
514
    glyphscanline = FONT_WIDTH * pixelbytes;
508
    glyphbytes = ROW2Y(glyphscanline);
515
    glyphbytes = ROW2Y(glyphscanline);
509
    bgscanbytes = xres * pixelbytes;
516
    bgscanbytes = xres * pixelbytes;
510
   
517
   
511
    size_t fbsize = scanline * yres;
518
    size_t fbsize = scanline * yres;
512
    size_t bbsize = cols * rows * sizeof(uint16_t);
519
    size_t bbsize = cols * rows * sizeof(uint16_t);
513
    size_t glyphsize = FONT_GLYPHS * glyphbytes;
520
    size_t glyphsize = FONT_GLYPHS * glyphbytes;
514
   
521
   
515
    backbuf = (uint16_t *) malloc(bbsize, 0);
522
    backbuf = (uint16_t *) malloc(bbsize, 0);
516
    if (!backbuf)
523
    if (!backbuf)
517
        panic("Unable to allocate backbuffer.");
524
        panic("Unable to allocate backbuffer.");
518
   
525
   
519
    glyphs = (uint8_t *) malloc(glyphsize, 0);
526
    glyphs = (uint8_t *) malloc(glyphsize, 0);
520
    if (!glyphs)
527
    if (!glyphs)
521
        panic("Unable to allocate glyphs.");
528
        panic("Unable to allocate glyphs.");
522
   
529
   
523
    bgscan = malloc(bgscanbytes, 0);
530
    bgscan = malloc(bgscanbytes, 0);
524
    if (!bgscan)
531
    if (!bgscan)
525
        panic("Unable to allocate background pixel.");
532
        panic("Unable to allocate background pixel.");
526
   
533
   
527
    memsetw(backbuf, cols * rows, 0);
534
    memsetw(backbuf, cols * rows, 0);
528
   
535
   
529
    glyphs_render();
536
    glyphs_render();
530
   
537
   
531
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
538
    fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize);
532
   
539
   
533
    sysinfo_set_item_val("fb", NULL, true);
540
    sysinfo_set_item_val("fb", NULL, true);
534
    sysinfo_set_item_val("fb.kind", NULL, 1);
541
    sysinfo_set_item_val("fb.kind", NULL, 1);
535
    sysinfo_set_item_val("fb.width", NULL, xres);
542
    sysinfo_set_item_val("fb.width", NULL, xres);
536
    sysinfo_set_item_val("fb.height", NULL, yres);
543
    sysinfo_set_item_val("fb.height", NULL, yres);
537
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
544
    sysinfo_set_item_val("fb.scanline", NULL, scanline);
538
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
545
    sysinfo_set_item_val("fb.visual", NULL, props->visual);
539
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
546
    sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
540
   
547
   
541
    fb_redraw();
548
    fb_redraw();
542
   
549
   
543
    outdev_initialize("fb", &fb_console, &fb_ops);
550
    outdev_initialize("fb", &fb_console, &fb_ops);
544
    stdout = &fb_console;
551
    stdout = &fb_console;
545
}
552
}
546
 
553
 
547
/** @}
554
/** @}
548
 */
555
 */
549
 
556