Rev 4669 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
836 | palkovsky | 1 | /* |
3707 | decky | 2 | * Copyright (c) 2008 Martin Decky |
2071 | jermar | 3 | * Copyright (c) 2006 Ondrej Palkovsky |
836 | palkovsky | 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 | |||
3707 | decky | 30 | /** @addtogroup genarch |
1702 | cejka | 31 | * @{ |
32 | */ |
||
33 | /** @file |
||
34 | */ |
||
35 | |||
837 | palkovsky | 36 | #include <genarch/fb/font-8x16.h> |
3710 | decky | 37 | #include <genarch/fb/logo-196x66.h> |
1993 | decky | 38 | #include <genarch/fb/visuals.h> |
837 | palkovsky | 39 | #include <genarch/fb/fb.h> |
836 | palkovsky | 40 | #include <console/chardev.h> |
41 | #include <console/console.h> |
||
1317 | vana | 42 | #include <sysinfo/sysinfo.h> |
1316 | jermar | 43 | #include <mm/slab.h> |
3707 | decky | 44 | #include <align.h> |
839 | palkovsky | 45 | #include <panic.h> |
896 | jermar | 46 | #include <memstr.h> |
1316 | jermar | 47 | #include <config.h> |
1682 | palkovsky | 48 | #include <bitops.h> |
49 | #include <print.h> |
||
4223 | decky | 50 | #include <string.h> |
2015 | jermar | 51 | #include <ddi/ddi.h> |
2054 | jermar | 52 | #include <arch/types.h> |
4676 | jermar | 53 | #include <byteorder.h> |
836 | palkovsky | 54 | |
3707 | decky | 55 | SPINLOCK_INITIALIZE(fb_lock); |
862 | palkovsky | 56 | |
3707 | decky | 57 | static uint8_t *fb_addr; |
4177 | decky | 58 | static uint16_t *backbuf; |
3707 | decky | 59 | static uint8_t *glyphs; |
3710 | decky | 60 | static uint8_t *bgscan; |
836 | palkovsky | 61 | |
3707 | decky | 62 | static unsigned int xres; |
63 | static unsigned int yres; |
||
1316 | jermar | 64 | |
3710 | decky | 65 | static unsigned int ylogo; |
66 | static unsigned int ytrim; |
||
67 | static unsigned int rowtrim; |
||
68 | |||
3707 | decky | 69 | static unsigned int scanline; |
70 | static unsigned int glyphscanline; |
||
836 | palkovsky | 71 | |
3707 | decky | 72 | static unsigned int pixelbytes; |
73 | static unsigned int glyphbytes; |
||
3710 | decky | 74 | static unsigned int bgscanbytes; |
3707 | decky | 75 | |
76 | static unsigned int cols; |
||
77 | static unsigned int rows; |
||
1135 | decky | 78 | static unsigned int position = 0; |
836 | palkovsky | 79 | |
3707 | decky | 80 | #define BG_COLOR 0x000080 |
81 | #define FG_COLOR 0xffff00 |
||
4187 | decky | 82 | #define INV_COLOR 0xaaaaaa |
836 | palkovsky | 83 | |
4676 | jermar | 84 | #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
85 | #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1)) |
||
86 | #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1)) |
||
1135 | decky | 87 | |
3707 | decky | 88 | #define COL2X(col) ((col) * FONT_WIDTH) |
89 | #define ROW2Y(row) ((row) * FONT_SCANLINES) |
||
1135 | decky | 90 | |
3707 | decky | 91 | #define X2COL(x) ((x) / FONT_WIDTH) |
92 | #define Y2ROW(y) ((y) / FONT_SCANLINES) |
||
838 | palkovsky | 93 | |
3707 | decky | 94 | #define FB_POS(x, y) ((y) * scanline + (x) * pixelbytes) |
95 | #define BB_POS(col, row) ((row) * cols + (col)) |
||
96 | #define GLYPH_POS(glyph, y) ((glyph) * glyphbytes + (y) * glyphscanline) |
||
839 | palkovsky | 97 | |
1875 | jermar | 98 | |
3707 | decky | 99 | static void (*rgb_conv)(void *, uint32_t); |
836 | palkovsky | 100 | |
4676 | jermar | 101 | /* |
102 | * RGB conversion functions. |
||
3707 | decky | 103 | * |
4676 | jermar | 104 | * These functions write an RGB value to some memory in some predefined format. |
105 | * The naming convention corresponds to the format created by these functions. |
||
106 | * The functions use the so called network order (i.e. big endian) with respect |
||
107 | * to their names. |
||
3707 | decky | 108 | */ |
4676 | jermar | 109 | |
3707 | decky | 110 | static void rgb_0888(void *dst, uint32_t rgb) |
1994 | decky | 111 | { |
4676 | jermar | 112 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
113 | (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8))); |
||
1994 | decky | 114 | } |
115 | |||
3707 | decky | 116 | static void bgr_0888(void *dst, uint32_t rgb) |
1994 | decky | 117 | { |
4676 | jermar | 118 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) | |
119 | (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8))); |
||
1994 | decky | 120 | } |
121 | |||
4669 | pillai | 122 | static void rgb_8880(void *dst, uint32_t rgb) |
123 | { |
||
4676 | jermar | 124 | *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) | |
125 | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0); |
||
126 | } |
||
3707 | decky | 127 | |
4676 | jermar | 128 | static void bgr_8880(void *dst, uint32_t rgb) |
129 | { |
||
130 | *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) | |
||
131 | (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0); |
||
4669 | pillai | 132 | } |
133 | |||
3707 | decky | 134 | static void rgb_888(void *dst, uint32_t rgb) |
839 | palkovsky | 135 | { |
4676 | jermar | 136 | ((uint8_t *) dst)[0] = RED(rgb, 8); |
3710 | decky | 137 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
4676 | jermar | 138 | ((uint8_t *) dst)[2] = BLUE(rgb, 8); |
839 | palkovsky | 139 | } |
140 | |||
3876 | decky | 141 | static void bgr_888(void *dst, uint32_t rgb) |
142 | { |
||
4676 | jermar | 143 | ((uint8_t *) dst)[0] = BLUE(rgb, 8); |
3876 | decky | 144 | ((uint8_t *) dst)[1] = GREEN(rgb, 8); |
4676 | jermar | 145 | ((uint8_t *) dst)[2] = RED(rgb, 8); |
3876 | decky | 146 | } |
147 | |||
4676 | jermar | 148 | static void bgr_555(void *dst, uint32_t rgb) |
1993 | decky | 149 | { |
4676 | jermar | 150 | uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff; |
151 | uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2); |
||
152 | *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo); |
||
1993 | decky | 153 | } |
154 | |||
4676 | jermar | 155 | static void bgr_565(void *dst, uint32_t rgb) |
839 | palkovsky | 156 | { |
4676 | jermar | 157 | uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff; |
158 | uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3); |
||
159 | *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo); |
||
839 | palkovsky | 160 | } |
161 | |||
162 | |||
4676 | jermar | 163 | /** BGR 3:2:3 |
1837 | jermar | 164 | * |
165 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
||
166 | * will most likely use a color palette. The color appearance |
||
167 | * will be pretty random and depend on the default installed |
||
168 | * palette. This could be fixed by supporting custom palette |
||
169 | * and setting it to simulate the 8-bit truecolor. |
||
3692 | rimsky | 170 | * |
3709 | decky | 171 | * Currently we set the palette on the ia32, amd64 and sparc64 port. |
3692 | rimsky | 172 | * |
173 | * Note that the byte is being inverted by this function. The reason is |
||
174 | * that we would like to use a color palette where the white color code |
||
3709 | decky | 175 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500) |
3692 | rimsky | 176 | * use these codes for black and white and prevent to set codes |
177 | * 0 and 255 to other colors. |
||
3709 | decky | 178 | * |
1837 | jermar | 179 | */ |
4676 | jermar | 180 | static void bgr_323(void *dst, uint32_t rgb) |
839 | palkovsky | 181 | { |
3707 | decky | 182 | *((uint8_t *) dst) |
183 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3)); |
||
1135 | decky | 184 | } |
839 | palkovsky | 185 | |
3707 | decky | 186 | |
3710 | decky | 187 | /** Hide logo and refresh screen |
188 | * |
||
189 | */ |
||
3844 | decky | 190 | static void logo_hide(bool silent) |
3710 | decky | 191 | { |
192 | ylogo = 0; |
||
193 | ytrim = yres; |
||
194 | rowtrim = rows; |
||
3844 | decky | 195 | if (!silent) |
196 | fb_redraw(); |
||
3710 | decky | 197 | } |
198 | |||
199 | |||
3707 | decky | 200 | /** Draw character at given position |
1837 | jermar | 201 | * |
202 | */ |
||
4223 | decky | 203 | static void glyph_draw(uint16_t glyph, unsigned int col, unsigned int row, bool silent, bool overlay) |
1135 | decky | 204 | { |
3707 | decky | 205 | unsigned int x = COL2X(col); |
206 | unsigned int y = ROW2Y(row); |
||
207 | unsigned int yd; |
||
208 | |||
3710 | decky | 209 | if (y >= ytrim) |
3844 | decky | 210 | logo_hide(silent); |
3710 | decky | 211 | |
4223 | decky | 212 | if (!overlay) |
213 | backbuf[BB_POS(col, row)] = glyph; |
||
3707 | decky | 214 | |
3844 | decky | 215 | if (!silent) { |
216 | for (yd = 0; yd < FONT_SCANLINES; yd++) |
||
217 | memcpy(&fb_addr[FB_POS(x, y + yd + ylogo)], |
||
218 | &glyphs[GLYPH_POS(glyph, yd)], glyphscanline); |
||
219 | } |
||
839 | palkovsky | 220 | } |
221 | |||
1682 | palkovsky | 222 | |
3707 | decky | 223 | /** Scroll screen down by one row |
224 | * |
||
225 | * |
||
226 | */ |
||
3844 | decky | 227 | static void screen_scroll(bool silent) |
838 | palkovsky | 228 | { |
3733 | decky | 229 | if (ylogo > 0) { |
3844 | decky | 230 | logo_hide(silent); |
3733 | decky | 231 | return; |
232 | } |
||
3710 | decky | 233 | |
3844 | decky | 234 | if (!silent) { |
235 | unsigned int row; |
||
2054 | jermar | 236 | |
3844 | decky | 237 | for (row = 0; row < rows; row++) { |
238 | unsigned int y = ROW2Y(row); |
||
239 | unsigned int yd; |
||
3707 | decky | 240 | |
3844 | decky | 241 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
242 | unsigned int x; |
||
243 | unsigned int col; |
||
3707 | decky | 244 | |
3844 | decky | 245 | for (col = 0, x = 0; col < cols; col++, |
246 | x += FONT_WIDTH) { |
||
4177 | decky | 247 | uint16_t glyph; |
3707 | decky | 248 | |
3844 | decky | 249 | if (row < rows - 1) { |
250 | if (backbuf[BB_POS(col, row)] == |
||
251 | backbuf[BB_POS(col, row + 1)]) |
||
252 | continue; |
||
253 | |||
254 | glyph = backbuf[BB_POS(col, row + 1)]; |
||
255 | } else |
||
256 | glyph = 0; |
||
257 | |||
258 | memcpy(&fb_addr[FB_POS(x, y + yd)], |
||
259 | &glyphs[GLYPH_POS(glyph, yd)], |
||
260 | glyphscanline); |
||
261 | } |
||
3707 | decky | 262 | } |
2086 | jermar | 263 | } |
1682 | palkovsky | 264 | } |
3707 | decky | 265 | |
4177 | decky | 266 | memmove(backbuf, &backbuf[BB_POS(0, 1)], cols * (rows - 1) * sizeof(uint16_t)); |
267 | memsetw(&backbuf[BB_POS(0, rows - 1)], cols, 0); |
||
838 | palkovsky | 268 | } |
269 | |||
270 | |||
3844 | decky | 271 | static void cursor_put(bool silent) |
836 | palkovsky | 272 | { |
4223 | decky | 273 | unsigned int col = position % cols; |
274 | unsigned int row = position / cols; |
||
275 | |||
276 | glyph_draw(fb_font_glyph(U_CURSOR), col, row, silent, true); |
||
836 | palkovsky | 277 | } |
278 | |||
279 | |||
3844 | decky | 280 | static void cursor_remove(bool silent) |
836 | palkovsky | 281 | { |
4223 | decky | 282 | unsigned int col = position % cols; |
283 | unsigned int row = position / cols; |
||
284 | |||
285 | glyph_draw(backbuf[BB_POS(col, row)], col, row, silent, true); |
||
836 | palkovsky | 286 | } |
287 | |||
838 | palkovsky | 288 | |
836 | palkovsky | 289 | /** Print character to screen |
290 | * |
||
3707 | decky | 291 | * Emulate basic terminal commands. |
292 | * |
||
836 | palkovsky | 293 | */ |
4177 | decky | 294 | static void fb_putchar(outdev_t *dev, wchar_t ch, bool silent) |
836 | palkovsky | 295 | { |
1287 | vana | 296 | spinlock_lock(&fb_lock); |
1135 | decky | 297 | |
298 | switch (ch) { |
||
1888 | jermar | 299 | case '\n': |
3844 | decky | 300 | cursor_remove(silent); |
3707 | decky | 301 | position += cols; |
302 | position -= position % cols; |
||
1888 | jermar | 303 | break; |
304 | case '\r': |
||
3844 | decky | 305 | cursor_remove(silent); |
3707 | decky | 306 | position -= position % cols; |
1888 | jermar | 307 | break; |
308 | case '\b': |
||
3844 | decky | 309 | cursor_remove(silent); |
3707 | decky | 310 | if (position % cols) |
1888 | jermar | 311 | position--; |
312 | break; |
||
313 | case '\t': |
||
3844 | decky | 314 | cursor_remove(silent); |
1888 | jermar | 315 | do { |
4177 | decky | 316 | glyph_draw(fb_font_glyph(' '), position % cols, |
4223 | decky | 317 | position / cols, silent, false); |
838 | palkovsky | 318 | position++; |
3707 | decky | 319 | } while ((position % 8) && (position < cols * rows)); |
1888 | jermar | 320 | break; |
321 | default: |
||
4177 | decky | 322 | glyph_draw(fb_font_glyph(ch), position % cols, |
4223 | decky | 323 | position / cols, silent, false); |
1888 | jermar | 324 | position++; |
836 | palkovsky | 325 | } |
1135 | decky | 326 | |
3707 | decky | 327 | if (position >= cols * rows) { |
328 | position -= cols; |
||
3844 | decky | 329 | screen_scroll(silent); |
836 | palkovsky | 330 | } |
1135 | decky | 331 | |
3844 | decky | 332 | cursor_put(silent); |
1135 | decky | 333 | |
1287 | vana | 334 | spinlock_unlock(&fb_lock); |
836 | palkovsky | 335 | } |
336 | |||
4093 | decky | 337 | static outdev_t fb_console; |
338 | static outdev_operations_t fb_ops = { |
||
339 | .write = fb_putchar |
||
836 | palkovsky | 340 | }; |
341 | |||
342 | |||
3707 | decky | 343 | /** Render glyphs |
344 | * |
||
345 | * Convert glyphs from device independent font |
||
346 | * description to current visual representation. |
||
347 | * |
||
348 | */ |
||
3710 | decky | 349 | static void glyphs_render(void) |
3707 | decky | 350 | { |
3710 | decky | 351 | /* Prerender glyphs */ |
4177 | decky | 352 | uint16_t glyph; |
3707 | decky | 353 | |
354 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) { |
||
4187 | decky | 355 | uint32_t fg_color; |
356 | |||
357 | if (glyph == FONT_GLYPHS - 1) |
||
358 | fg_color = INV_COLOR; |
||
359 | else |
||
360 | fg_color = FG_COLOR; |
||
361 | |||
3707 | decky | 362 | unsigned int y; |
363 | |||
364 | for (y = 0; y < FONT_SCANLINES; y++) { |
||
365 | unsigned int x; |
||
366 | |||
3741 | jermar | 367 | for (x = 0; x < FONT_WIDTH; x++) { |
368 | void *dst = &glyphs[GLYPH_POS(glyph, y) + |
||
369 | x * pixelbytes]; |
||
4177 | decky | 370 | uint32_t rgb = (fb_font[glyph][y] & |
4187 | decky | 371 | (1 << (7 - x))) ? fg_color : BG_COLOR; |
3741 | jermar | 372 | rgb_conv(dst, rgb); |
373 | } |
||
3707 | decky | 374 | } |
375 | } |
||
376 | |||
3710 | decky | 377 | /* Prerender background scanline */ |
378 | unsigned int x; |
||
379 | |||
380 | for (x = 0; x < xres; x++) |
||
381 | rgb_conv(&bgscan[x * pixelbytes], BG_COLOR); |
||
3707 | decky | 382 | } |
383 | |||
384 | |||
385 | /** Refresh the screen |
||
386 | * |
||
387 | */ |
||
388 | void fb_redraw(void) |
||
389 | { |
||
3710 | decky | 390 | if (ylogo > 0) { |
391 | unsigned int y; |
||
392 | |||
393 | for (y = 0; y < LOGO_HEIGHT; y++) { |
||
394 | unsigned int x; |
||
395 | |||
396 | for (x = 0; x < xres; x++) |
||
397 | rgb_conv(&fb_addr[FB_POS(x, y)], |
||
3741 | jermar | 398 | (x < LOGO_WIDTH) ? |
399 | fb_logo[y * LOGO_WIDTH + x] : |
||
400 | LOGO_COLOR); |
||
3710 | decky | 401 | } |
402 | } |
||
403 | |||
3707 | decky | 404 | unsigned int row; |
405 | |||
3710 | decky | 406 | for (row = 0; row < rowtrim; row++) { |
407 | unsigned int y = ylogo + ROW2Y(row); |
||
3707 | decky | 408 | unsigned int yd; |
409 | |||
410 | for (yd = 0; yd < FONT_SCANLINES; yd++) { |
||
411 | unsigned int x; |
||
412 | unsigned int col; |
||
413 | |||
3741 | jermar | 414 | for (col = 0, x = 0; col < cols; |
415 | col++, x += FONT_WIDTH) { |
||
4177 | decky | 416 | uint16_t glyph = backbuf[BB_POS(col, row)]; |
417 | void *dst = &fb_addr[FB_POS(x, y + yd)]; |
||
418 | void *src = &glyphs[GLYPH_POS(glyph, yd)]; |
||
419 | memcpy(dst, src, glyphscanline); |
||
3741 | jermar | 420 | } |
3707 | decky | 421 | } |
422 | } |
||
423 | |||
424 | if (COL2X(cols) < xres) { |
||
425 | unsigned int y; |
||
3710 | decky | 426 | unsigned int size = (xres - COL2X(cols)) * pixelbytes; |
3707 | decky | 427 | |
3710 | decky | 428 | for (y = ylogo; y < yres; y++) |
429 | memcpy(&fb_addr[FB_POS(COL2X(cols), y)], bgscan, size); |
||
3707 | decky | 430 | } |
431 | |||
3733 | decky | 432 | if (ROW2Y(rowtrim) + ylogo < yres) { |
3707 | decky | 433 | unsigned int y; |
434 | |||
3733 | decky | 435 | for (y = ROW2Y(rowtrim) + ylogo; y < yres; y++) |
3710 | decky | 436 | memcpy(&fb_addr[FB_POS(0, y)], bgscan, bgscanbytes); |
3707 | decky | 437 | } |
438 | } |
||
439 | |||
440 | |||
4093 | decky | 441 | /** Initialize framebuffer as a output character device |
836 | palkovsky | 442 | * |
3707 | decky | 443 | * @param addr Physical address of the framebuffer |
444 | * @param x Screen width in pixels |
||
445 | * @param y Screen height in pixels |
||
446 | * @param scan Bytes per one scanline |
||
447 | * @param visual Color model |
||
448 | * |
||
836 | palkovsky | 449 | */ |
3672 | jermar | 450 | void fb_init(fb_properties_t *props) |
836 | palkovsky | 451 | { |
3672 | jermar | 452 | switch (props->visual) { |
1993 | decky | 453 | case VISUAL_INDIRECT_8: |
4676 | jermar | 454 | rgb_conv = bgr_323; |
1991 | jermar | 455 | pixelbytes = 1; |
456 | break; |
||
4676 | jermar | 457 | case VISUAL_BGR_5_5_5: |
458 | rgb_conv = bgr_555; |
||
1991 | jermar | 459 | pixelbytes = 2; |
460 | break; |
||
4676 | jermar | 461 | case VISUAL_BGR_5_6_5: |
462 | rgb_conv = bgr_565; |
||
1993 | decky | 463 | pixelbytes = 2; |
1991 | jermar | 464 | break; |
1993 | decky | 465 | case VISUAL_RGB_8_8_8: |
3707 | decky | 466 | rgb_conv = rgb_888; |
1993 | decky | 467 | pixelbytes = 3; |
468 | break; |
||
3876 | decky | 469 | case VISUAL_BGR_8_8_8: |
470 | rgb_conv = bgr_888; |
||
471 | pixelbytes = 3; |
||
472 | break; |
||
1993 | decky | 473 | case VISUAL_RGB_8_8_8_0: |
4669 | pillai | 474 | rgb_conv = rgb_8880; |
1991 | jermar | 475 | pixelbytes = 4; |
476 | break; |
||
1993 | decky | 477 | case VISUAL_RGB_0_8_8_8: |
3707 | decky | 478 | rgb_conv = rgb_0888; |
1993 | decky | 479 | pixelbytes = 4; |
480 | break; |
||
1994 | decky | 481 | case VISUAL_BGR_0_8_8_8: |
3707 | decky | 482 | rgb_conv = bgr_0888; |
1994 | decky | 483 | pixelbytes = 4; |
484 | break; |
||
4676 | jermar | 485 | case VISUAL_BGR_8_8_8_0: |
486 | rgb_conv = bgr_8880; |
||
487 | pixelbytes = 4; |
||
488 | break; |
||
1991 | jermar | 489 | default: |
3790 | svoboda | 490 | panic("Unsupported visual."); |
839 | palkovsky | 491 | } |
1371 | decky | 492 | |
3672 | jermar | 493 | xres = props->x; |
494 | yres = props->y; |
||
495 | scanline = props->scan; |
||
836 | palkovsky | 496 | |
3710 | decky | 497 | cols = X2COL(xres); |
498 | rows = Y2ROW(yres); |
||
3707 | decky | 499 | |
3710 | decky | 500 | if (yres > ylogo) { |
501 | ylogo = LOGO_HEIGHT; |
||
502 | rowtrim = rows - Y2ROW(ylogo); |
||
503 | if (ylogo % FONT_SCANLINES > 0) |
||
504 | rowtrim--; |
||
505 | ytrim = ROW2Y(rowtrim); |
||
506 | } else { |
||
507 | ylogo = 0; |
||
508 | ytrim = yres; |
||
509 | rowtrim = rows; |
||
510 | } |
||
511 | |||
3707 | decky | 512 | glyphscanline = FONT_WIDTH * pixelbytes; |
3710 | decky | 513 | glyphbytes = ROW2Y(glyphscanline); |
514 | bgscanbytes = xres * pixelbytes; |
||
3707 | decky | 515 | |
4177 | decky | 516 | size_t fbsize = scanline * yres; |
517 | size_t bbsize = cols * rows * sizeof(uint16_t); |
||
518 | size_t glyphsize = FONT_GLYPHS * glyphbytes; |
||
3707 | decky | 519 | |
4177 | decky | 520 | backbuf = (uint16_t *) malloc(bbsize, 0); |
3707 | decky | 521 | if (!backbuf) |
3790 | svoboda | 522 | panic("Unable to allocate backbuffer."); |
3707 | decky | 523 | |
524 | glyphs = (uint8_t *) malloc(glyphsize, 0); |
||
525 | if (!glyphs) |
||
3790 | svoboda | 526 | panic("Unable to allocate glyphs."); |
3707 | decky | 527 | |
3710 | decky | 528 | bgscan = malloc(bgscanbytes, 0); |
529 | if (!bgscan) |
||
3790 | svoboda | 530 | panic("Unable to allocate background pixel."); |
3707 | decky | 531 | |
4177 | decky | 532 | memsetw(backbuf, cols * rows, 0); |
3707 | decky | 533 | |
3710 | decky | 534 | glyphs_render(); |
3707 | decky | 535 | |
536 | fb_addr = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
||
537 | |||
1690 | palkovsky | 538 | sysinfo_set_item_val("fb", NULL, true); |
539 | sysinfo_set_item_val("fb.kind", NULL, 1); |
||
540 | sysinfo_set_item_val("fb.width", NULL, xres); |
||
541 | sysinfo_set_item_val("fb.height", NULL, yres); |
||
3707 | decky | 542 | sysinfo_set_item_val("fb.scanline", NULL, scanline); |
3672 | jermar | 543 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
544 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
||
1990 | decky | 545 | |
3707 | decky | 546 | fb_redraw(); |
547 | |||
4093 | decky | 548 | outdev_initialize("fb", &fb_console, &fb_ops); |
549 | stdout = &fb_console; |
||
836 | palkovsky | 550 | } |
1702 | cejka | 551 | |
1790 | jermar | 552 | /** @} |
1702 | cejka | 553 | */ |