Rev 3478 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
836 | palkovsky | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2006 Ondrej Palkovsky |
836 | palkovsky | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1790 | jermar | 29 | /** @addtogroup genarch |
1702 | cejka | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
837 | palkovsky | 35 | #include <genarch/fb/font-8x16.h> |
1993 | decky | 36 | #include <genarch/fb/visuals.h> |
837 | palkovsky | 37 | #include <genarch/fb/fb.h> |
836 | palkovsky | 38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
||
1317 | vana | 40 | #include <sysinfo/sysinfo.h> |
1316 | jermar | 41 | #include <mm/slab.h> |
839 | palkovsky | 42 | #include <panic.h> |
896 | jermar | 43 | #include <memstr.h> |
1316 | jermar | 44 | #include <config.h> |
1682 | palkovsky | 45 | #include <bitops.h> |
46 | #include <print.h> |
||
2015 | jermar | 47 | #include <ddi/ddi.h> |
2054 | jermar | 48 | #include <arch/types.h> |
836 | palkovsky | 49 | |
862 | palkovsky | 50 | #include "helenos.xbm" |
51 | |||
2015 | jermar | 52 | static parea_t fb_parea; /**< Physical memory area for fb. */ |
53 | |||
836 | palkovsky | 54 | SPINLOCK_INITIALIZE(fb_lock); |
55 | |||
1780 | jermar | 56 | static uint8_t *fbaddress = NULL; |
836 | palkovsky | 57 | |
1780 | jermar | 58 | static uint8_t *blankline = NULL; |
2054 | jermar | 59 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
60 | static index_t dboffset; |
||
1316 | jermar | 61 | |
1135 | decky | 62 | static unsigned int xres = 0; |
63 | static unsigned int yres = 0; |
||
64 | static unsigned int scanline = 0; |
||
65 | static unsigned int pixelbytes = 0; |
||
1875 | jermar | 66 | #ifdef FB_INVERT_COLORS |
67 | static bool invert_colors = true; |
||
68 | #else |
||
69 | static bool invert_colors = false; |
||
70 | #endif |
||
836 | palkovsky | 71 | |
1135 | decky | 72 | static unsigned int position = 0; |
73 | static unsigned int columns = 0; |
||
74 | static unsigned int rows = 0; |
||
836 | palkovsky | 75 | |
1135 | decky | 76 | #define COL_WIDTH 8 |
77 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
||
836 | palkovsky | 78 | |
1135 | decky | 79 | #define BGCOLOR 0x000080 |
80 | #define FGCOLOR 0xffff00 |
||
81 | #define LOGOCOLOR 0x2020b0 |
||
82 | |||
2086 | jermar | 83 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
1135 | decky | 84 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
||
86 | |||
1682 | palkovsky | 87 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
1135 | decky | 88 | |
838 | palkovsky | 89 | /***************************************************************/ |
90 | /* Pixel specific fuctions */ |
||
91 | |||
1682 | palkovsky | 92 | static void (*rgb2scr)(void *, int); |
93 | static int (*scr2rgb)(void *); |
||
839 | palkovsky | 94 | |
1875 | jermar | 95 | static inline int COLOR(int color) |
96 | { |
||
97 | return invert_colors ? ~color : color; |
||
98 | } |
||
99 | |||
1682 | palkovsky | 100 | /* Conversion routines between different color representations */ |
1993 | decky | 101 | static void rgb_byte0888(void *dst, int rgb) |
836 | palkovsky | 102 | { |
1990 | decky | 103 | *((int *) dst) = rgb; |
836 | palkovsky | 104 | } |
105 | |||
1993 | decky | 106 | static int byte0888_rgb(void *src) |
838 | palkovsky | 107 | { |
1990 | decky | 108 | return (*((int *) src)) & 0xffffff; |
839 | palkovsky | 109 | } |
110 | |||
1994 | decky | 111 | static void bgr_byte0888(void *dst, int rgb) |
112 | { |
||
2086 | jermar | 113 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | |
114 | RED(rgb, 8); |
||
1994 | decky | 115 | } |
116 | |||
117 | static int byte0888_bgr(void *src) |
||
118 | { |
||
119 | int color = *(uint32_t *)(src); |
||
2086 | jermar | 120 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
121 | ((color >> 16) & 0xff); |
||
1994 | decky | 122 | } |
123 | |||
1993 | decky | 124 | static void rgb_byte888(void *dst, int rgb) |
839 | palkovsky | 125 | { |
2102 | decky | 126 | uint8_t *scr = (uint8_t *) dst; |
1871 | jermar | 127 | #if defined(FB_INVERT_ENDIAN) |
1682 | palkovsky | 128 | scr[0] = RED(rgb, 8); |
129 | scr[1] = GREEN(rgb, 8); |
||
130 | scr[2] = BLUE(rgb, 8); |
||
1298 | vana | 131 | #else |
1682 | palkovsky | 132 | scr[2] = RED(rgb, 8); |
133 | scr[1] = GREEN(rgb, 8); |
||
134 | scr[0] = BLUE(rgb, 8); |
||
135 | #endif |
||
839 | palkovsky | 136 | } |
137 | |||
1993 | decky | 138 | static int byte888_rgb(void *src) |
839 | palkovsky | 139 | { |
2102 | decky | 140 | uint8_t *scr = (uint8_t *) src; |
1871 | jermar | 141 | #if defined(FB_INVERT_ENDIAN) |
1682 | palkovsky | 142 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
1298 | vana | 143 | #else |
1682 | palkovsky | 144 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
1298 | vana | 145 | #endif |
838 | palkovsky | 146 | } |
147 | |||
3528 | pillai | 148 | static void bgr_byte8880(void *dst, int rgb) |
149 | { |
||
150 | uint8_t *scr = (uint8_t *) dst; |
||
151 | scr[3] = RED(rgb, 8); |
||
152 | scr[2] = GREEN(rgb, 8); |
||
153 | scr[1] = BLUE(rgb, 8); |
||
154 | } |
||
155 | |||
156 | static int byte8880_bgr(void *src) |
||
157 | { |
||
158 | uint8_t *scr = (uint8_t *) src; |
||
159 | return scr[3] << 16 | scr[2] << 8 | scr[1]; |
||
160 | } |
||
161 | |||
1993 | decky | 162 | /** 16-bit depth (5:5:5) */ |
163 | static void rgb_byte555(void *dst, int rgb) |
||
164 | { |
||
165 | /* 5-bit, 5-bits, 5-bits */ |
||
2086 | jermar | 166 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
167 | BLUE(rgb, 5); |
||
1993 | decky | 168 | } |
169 | |||
170 | /** 16-bit depth (5:5:5) */ |
||
171 | static int byte555_rgb(void *src) |
||
172 | { |
||
173 | int color = *(uint16_t *)(src); |
||
2086 | jermar | 174 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
175 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
||
1993 | decky | 176 | } |
177 | |||
1682 | palkovsky | 178 | /** 16-bit depth (5:6:5) */ |
1993 | decky | 179 | static void rgb_byte565(void *dst, int rgb) |
839 | palkovsky | 180 | { |
1682 | palkovsky | 181 | /* 5-bit, 6-bits, 5-bits */ |
2086 | jermar | 182 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
183 | BLUE(rgb, 5); |
||
839 | palkovsky | 184 | } |
185 | |||
1682 | palkovsky | 186 | /** 16-bit depth (5:6:5) */ |
1993 | decky | 187 | static int byte565_rgb(void *src) |
839 | palkovsky | 188 | { |
1780 | jermar | 189 | int color = *(uint16_t *)(src); |
2086 | jermar | 190 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
191 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
||
839 | palkovsky | 192 | } |
193 | |||
1837 | jermar | 194 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
195 | * |
||
196 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
||
197 | * will most likely use a color palette. The color appearance |
||
198 | * will be pretty random and depend on the default installed |
||
199 | * palette. This could be fixed by supporting custom palette |
||
200 | * and setting it to simulate the 8-bit truecolor. |
||
201 | */ |
||
1993 | decky | 202 | static void rgb_byte8(void *dst, int rgb) |
839 | palkovsky | 203 | { |
2086 | jermar | 204 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
205 | BLUE(rgb, 3); |
||
1135 | decky | 206 | } |
839 | palkovsky | 207 | |
1837 | jermar | 208 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
209 | * |
||
1993 | decky | 210 | * See the comment for rgb_byte(). |
1837 | jermar | 211 | */ |
1993 | decky | 212 | static int byte8_rgb(void *src) |
1135 | decky | 213 | { |
1780 | jermar | 214 | int color = *(uint8_t *)src; |
2086 | jermar | 215 | return (((color >> 5) & 0x7) << (16 + 5)) | |
216 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
||
839 | palkovsky | 217 | } |
218 | |||
1682 | palkovsky | 219 | static void putpixel(unsigned int x, unsigned int y, int color) |
1135 | decky | 220 | { |
1990 | decky | 221 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
1682 | palkovsky | 222 | |
223 | if (dbbuffer) { |
||
224 | int dline = (y + dboffset) % yres; |
||
1990 | decky | 225 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
1682 | palkovsky | 226 | } |
1135 | decky | 227 | } |
839 | palkovsky | 228 | |
1682 | palkovsky | 229 | /** Get pixel from viewport */ |
230 | static int getpixel(unsigned int x, unsigned int y) |
||
231 | { |
||
232 | if (dbbuffer) { |
||
233 | int dline = (y + dboffset) % yres; |
||
1990 | decky | 234 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
1682 | palkovsky | 235 | } |
1990 | decky | 236 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
1682 | palkovsky | 237 | } |
1135 | decky | 238 | |
1682 | palkovsky | 239 | |
1135 | decky | 240 | /** Fill screen with background color */ |
241 | static void clear_screen(void) |
||
839 | palkovsky | 242 | { |
1135 | decky | 243 | unsigned int y; |
839 | palkovsky | 244 | |
1682 | palkovsky | 245 | for (y = 0; y < yres; y++) { |
1990 | decky | 246 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
1682 | palkovsky | 247 | if (dbbuffer) |
2086 | jermar | 248 | memcpy(&dbbuffer[scanline * y], blankline, |
249 | xres * pixelbytes); |
||
1682 | palkovsky | 250 | } |
839 | palkovsky | 251 | } |
252 | |||
1135 | decky | 253 | |
838 | palkovsky | 254 | /** Scroll screen one row up */ |
255 | static void scroll_screen(void) |
||
256 | { |
||
1682 | palkovsky | 257 | if (dbbuffer) { |
2054 | jermar | 258 | count_t first; |
259 | |||
2086 | jermar | 260 | /* Clear the last row */ |
1993 | decky | 261 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
1682 | palkovsky | 262 | |
263 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
||
2054 | jermar | 264 | first = yres - dboffset; |
2086 | jermar | 265 | |
266 | /* Move all rows one row up */ |
||
267 | if (xres * pixelbytes == scanline) { |
||
268 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
||
269 | first * scanline); |
||
270 | memcpy(&fbaddress[first * scanline], dbbuffer, |
||
271 | dboffset * scanline); |
||
272 | } else { |
||
273 | /* |
||
274 | * When the scanline is bigger than number of bytes |
||
275 | * in the X-resolution, chances are that the |
||
276 | * frame buffer memory past the X-resolution is special |
||
277 | * in some way. For example, the SUNW,ffb framebuffer |
||
278 | * wraps this area around the beginning of the same |
||
279 | * line. To avoid troubles, copy only memory as |
||
280 | * specified by the resolution. |
||
281 | */ |
||
2102 | decky | 282 | unsigned int i; |
838 | palkovsky | 283 | |
2086 | jermar | 284 | for (i = 0; i < first; i++) |
285 | memcpy(&fbaddress[i * scanline], |
||
286 | &dbbuffer[(dboffset + i) * scanline], |
||
287 | xres * pixelbytes); |
||
288 | for (i = 0; i < dboffset; i++) |
||
289 | memcpy(&fbaddress[(first + i) * scanline], |
||
290 | &dbbuffer[i * scanline], xres * pixelbytes); |
||
291 | } |
||
1682 | palkovsky | 292 | } else { |
2054 | jermar | 293 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
294 | |||
2086 | jermar | 295 | if (xres * pixelbytes == scanline) { |
296 | /* Move all rows one row up */ |
||
297 | memcpy((void *) fbaddress, |
||
298 | (void *) &fbaddress[ROW_BYTES], |
||
299 | scanline * yres - ROW_BYTES); |
||
300 | /* Clear the last row */ |
||
301 | memcpy((void *) lastline, (void *) blankline, |
||
302 | ROW_BYTES); |
||
303 | } else { |
||
304 | /* |
||
305 | * See the comment in the dbbuffer case. |
||
306 | */ |
||
2102 | decky | 307 | unsigned int i; |
2086 | jermar | 308 | |
309 | /* Move all rows one row up */ |
||
310 | for (i = 0; i < yres - FONT_SCANLINES; i++) |
||
311 | memcpy(&fbaddress[i * scanline], |
||
312 | &fbaddress[(i + FONT_SCANLINES) * scanline], |
||
313 | xres * pixelbytes); |
||
314 | /* Clear the last row */ |
||
315 | for (i = 0; i < FONT_SCANLINES; i++) |
||
316 | memcpy(&lastline[i * scanline], |
||
317 | &blankline[i * scanline], |
||
318 | xres * pixelbytes); |
||
319 | } |
||
1682 | palkovsky | 320 | } |
838 | palkovsky | 321 | } |
322 | |||
323 | |||
1135 | decky | 324 | static void invert_pixel(unsigned int x, unsigned int y) |
836 | palkovsky | 325 | { |
1682 | palkovsky | 326 | putpixel(x, y, ~getpixel(x, y)); |
836 | palkovsky | 327 | } |
328 | |||
329 | |||
330 | /** Draw one line of glyph at a given position */ |
||
1135 | decky | 331 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
836 | palkovsky | 332 | { |
1135 | decky | 333 | unsigned int i; |
836 | palkovsky | 334 | |
1135 | decky | 335 | for (i = 0; i < 8; i++) |
336 | if (glline & (1 << (7 - i))) { |
||
1682 | palkovsky | 337 | putpixel(x + i, y, FGCOLOR); |
836 | palkovsky | 338 | } else |
1682 | palkovsky | 339 | putpixel(x + i, y, BGCOLOR); |
836 | palkovsky | 340 | } |
341 | |||
838 | palkovsky | 342 | /***************************************************************/ |
343 | /* Character-console functions */ |
||
344 | |||
836 | palkovsky | 345 | /** Draw character at given position */ |
1780 | jermar | 346 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
836 | palkovsky | 347 | { |
1135 | decky | 348 | unsigned int y; |
836 | palkovsky | 349 | |
1135 | decky | 350 | for (y = 0; y < FONT_SCANLINES; y++) |
2086 | jermar | 351 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
352 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
||
836 | palkovsky | 353 | } |
354 | |||
355 | /** Invert character at given position */ |
||
1135 | decky | 356 | static void invert_char(unsigned int col, unsigned int row) |
836 | palkovsky | 357 | { |
1135 | decky | 358 | unsigned int x; |
359 | unsigned int y; |
||
836 | palkovsky | 360 | |
1135 | decky | 361 | for (x = 0; x < COL_WIDTH; x++) |
362 | for (y = 0; y < FONT_SCANLINES; y++) |
||
2086 | jermar | 363 | invert_pixel(col * COL_WIDTH + x, |
364 | row * FONT_SCANLINES + y); |
||
836 | palkovsky | 365 | } |
366 | |||
367 | /** Draw character at default position */ |
||
368 | static void draw_char(char chr) |
||
369 | { |
||
1135 | decky | 370 | draw_glyph(chr, position % columns, position / columns); |
836 | palkovsky | 371 | } |
372 | |||
1135 | decky | 373 | static void draw_logo(unsigned int startx, unsigned int starty) |
862 | palkovsky | 374 | { |
1135 | decky | 375 | unsigned int x; |
376 | unsigned int y; |
||
377 | unsigned int byte; |
||
378 | unsigned int rowbytes; |
||
862 | palkovsky | 379 | |
1135 | decky | 380 | rowbytes = (helenos_width - 1) / 8 + 1; |
862 | palkovsky | 381 | |
1135 | decky | 382 | for (y = 0; y < helenos_height; y++) |
383 | for (x = 0; x < helenos_width; x++) { |
||
384 | byte = helenos_bits[rowbytes * y + x / 8]; |
||
862 | palkovsky | 385 | byte >>= x % 8; |
386 | if (byte & 1) |
||
2054 | jermar | 387 | putpixel(startx + x, starty + y, |
2086 | jermar | 388 | COLOR(LOGOCOLOR)); |
862 | palkovsky | 389 | } |
390 | } |
||
391 | |||
838 | palkovsky | 392 | /***************************************************************/ |
393 | /* Stdout specific functions */ |
||
394 | |||
836 | palkovsky | 395 | static void invert_cursor(void) |
396 | { |
||
1135 | decky | 397 | invert_char(position % columns, position / columns); |
836 | palkovsky | 398 | } |
399 | |||
400 | /** Print character to screen |
||
401 | * |
||
402 | * Emulate basic terminal commands |
||
403 | */ |
||
404 | static void fb_putchar(chardev_t *dev, char ch) |
||
405 | { |
||
1287 | vana | 406 | spinlock_lock(&fb_lock); |
1135 | decky | 407 | |
408 | switch (ch) { |
||
1888 | jermar | 409 | case '\n': |
410 | invert_cursor(); |
||
411 | position += columns; |
||
412 | position -= position % columns; |
||
413 | break; |
||
414 | case '\r': |
||
415 | invert_cursor(); |
||
416 | position -= position % columns; |
||
417 | break; |
||
418 | case '\b': |
||
419 | invert_cursor(); |
||
420 | if (position % columns) |
||
421 | position--; |
||
422 | break; |
||
423 | case '\t': |
||
424 | invert_cursor(); |
||
425 | do { |
||
426 | draw_char(' '); |
||
838 | palkovsky | 427 | position++; |
1888 | jermar | 428 | } while ((position % 8) && position < columns * rows); |
429 | break; |
||
430 | default: |
||
431 | draw_char(ch); |
||
432 | position++; |
||
836 | palkovsky | 433 | } |
1135 | decky | 434 | |
435 | if (position >= columns * rows) { |
||
836 | palkovsky | 436 | position -= columns; |
437 | scroll_screen(); |
||
438 | } |
||
1135 | decky | 439 | |
836 | palkovsky | 440 | invert_cursor(); |
1135 | decky | 441 | |
1287 | vana | 442 | spinlock_unlock(&fb_lock); |
836 | palkovsky | 443 | } |
444 | |||
445 | static chardev_t framebuffer; |
||
446 | static chardev_operations_t fb_ops = { |
||
447 | .write = fb_putchar, |
||
448 | }; |
||
449 | |||
450 | |||
451 | /** Initialize framebuffer as a chardev output device |
||
452 | * |
||
1993 | decky | 453 | * @param addr Physical address of the framebuffer |
454 | * @param x Screen width in pixels |
||
455 | * @param y Screen height in pixels |
||
456 | * @param scan Bytes per one scanline |
||
457 | * @param visual Color model |
||
458 | * |
||
836 | palkovsky | 459 | */ |
2054 | jermar | 460 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, |
2086 | jermar | 461 | unsigned int visual) |
836 | palkovsky | 462 | { |
1993 | decky | 463 | switch (visual) { |
464 | case VISUAL_INDIRECT_8: |
||
465 | rgb2scr = rgb_byte8; |
||
466 | scr2rgb = byte8_rgb; |
||
1991 | jermar | 467 | pixelbytes = 1; |
468 | break; |
||
1993 | decky | 469 | case VISUAL_RGB_5_5_5: |
470 | rgb2scr = rgb_byte555; |
||
471 | scr2rgb = byte555_rgb; |
||
1991 | jermar | 472 | pixelbytes = 2; |
473 | break; |
||
1993 | decky | 474 | case VISUAL_RGB_5_6_5: |
475 | rgb2scr = rgb_byte565; |
||
476 | scr2rgb = byte565_rgb; |
||
477 | pixelbytes = 2; |
||
1991 | jermar | 478 | break; |
1993 | decky | 479 | case VISUAL_RGB_8_8_8: |
480 | rgb2scr = rgb_byte888; |
||
481 | scr2rgb = byte888_rgb; |
||
482 | pixelbytes = 3; |
||
483 | break; |
||
484 | case VISUAL_RGB_8_8_8_0: |
||
485 | rgb2scr = rgb_byte888; |
||
486 | scr2rgb = byte888_rgb; |
||
1991 | jermar | 487 | pixelbytes = 4; |
488 | break; |
||
1993 | decky | 489 | case VISUAL_RGB_0_8_8_8: |
490 | rgb2scr = rgb_byte0888; |
||
491 | scr2rgb = byte0888_rgb; |
||
492 | pixelbytes = 4; |
||
493 | break; |
||
1994 | decky | 494 | case VISUAL_BGR_0_8_8_8: |
495 | rgb2scr = bgr_byte0888; |
||
496 | scr2rgb = byte0888_bgr; |
||
497 | pixelbytes = 4; |
||
498 | break; |
||
3528 | pillai | 499 | case VISUAL_BGR_8_8_8_0: |
500 | rgb2scr = bgr_byte8880; |
||
501 | scr2rgb = byte8880_bgr; |
||
502 | pixelbytes = 4; |
||
503 | break; |
||
1991 | jermar | 504 | default: |
1993 | decky | 505 | panic("Unsupported visual.\n"); |
839 | palkovsky | 506 | } |
1371 | decky | 507 | |
508 | unsigned int fbsize = scan * y; |
||
509 | |||
510 | /* Map the framebuffer */ |
||
1780 | jermar | 511 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
1371 | decky | 512 | |
836 | palkovsky | 513 | xres = x; |
514 | yres = y; |
||
1135 | decky | 515 | scanline = scan; |
836 | palkovsky | 516 | |
1135 | decky | 517 | rows = y / FONT_SCANLINES; |
518 | columns = x / COL_WIDTH; |
||
836 | palkovsky | 519 | |
2015 | jermar | 520 | fb_parea.pbase = (uintptr_t) addr; |
521 | fb_parea.vbase = (uintptr_t) fbaddress; |
||
522 | fb_parea.frames = SIZE2FRAMES(fbsize); |
||
523 | fb_parea.cacheable = false; |
||
524 | ddi_parea_register(&fb_parea); |
||
525 | |||
1690 | palkovsky | 526 | sysinfo_set_item_val("fb", NULL, true); |
527 | sysinfo_set_item_val("fb.kind", NULL, 1); |
||
528 | sysinfo_set_item_val("fb.width", NULL, xres); |
||
529 | sysinfo_set_item_val("fb.height", NULL, yres); |
||
530 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
||
1993 | decky | 531 | sysinfo_set_item_val("fb.visual", NULL, visual); |
1690 | palkovsky | 532 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
1875 | jermar | 533 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
1690 | palkovsky | 534 | |
1682 | palkovsky | 535 | /* Allocate double buffer */ |
2054 | jermar | 536 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
537 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
||
1760 | palkovsky | 538 | if (!dbbuffer) |
1682 | palkovsky | 539 | printf("Failed to allocate scroll buffer.\n"); |
540 | dboffset = 0; |
||
541 | |||
542 | /* Initialized blank line */ |
||
1780 | jermar | 543 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
1766 | palkovsky | 544 | if (!blankline) |
545 | panic("Failed to allocate blank line for framebuffer."); |
||
1990 | decky | 546 | for (y = 0; y < FONT_SCANLINES; y++) |
547 | for (x = 0; x < xres; x++) |
||
548 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
||
549 | |||
1682 | palkovsky | 550 | clear_screen(); |
551 | |||
552 | /* Update size of screen to match text area */ |
||
553 | yres = rows * FONT_SCANLINES; |
||
554 | |||
1135 | decky | 555 | draw_logo(xres - helenos_width, 0); |
836 | palkovsky | 556 | invert_cursor(); |
557 | |||
558 | chardev_initialize("fb", &framebuffer, &fb_ops); |
||
559 | stdout = &framebuffer; |
||
560 | } |
||
1702 | cejka | 561 | |
1790 | jermar | 562 | /** @} |
1702 | cejka | 563 | */ |