Rev 3679 | Rev 3707 | 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 | |||
1993 | decky | 148 | /** 16-bit depth (5:5:5) */ |
149 | static void rgb_byte555(void *dst, int rgb) |
||
150 | { |
||
151 | /* 5-bit, 5-bits, 5-bits */ |
||
2086 | jermar | 152 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
153 | BLUE(rgb, 5); |
||
1993 | decky | 154 | } |
155 | |||
156 | /** 16-bit depth (5:5:5) */ |
||
157 | static int byte555_rgb(void *src) |
||
158 | { |
||
159 | int color = *(uint16_t *)(src); |
||
2086 | jermar | 160 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
161 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
||
1993 | decky | 162 | } |
163 | |||
1682 | palkovsky | 164 | /** 16-bit depth (5:6:5) */ |
1993 | decky | 165 | static void rgb_byte565(void *dst, int rgb) |
839 | palkovsky | 166 | { |
1682 | palkovsky | 167 | /* 5-bit, 6-bits, 5-bits */ |
2086 | jermar | 168 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
169 | BLUE(rgb, 5); |
||
839 | palkovsky | 170 | } |
171 | |||
1682 | palkovsky | 172 | /** 16-bit depth (5:6:5) */ |
1993 | decky | 173 | static int byte565_rgb(void *src) |
839 | palkovsky | 174 | { |
1780 | jermar | 175 | int color = *(uint16_t *)(src); |
2086 | jermar | 176 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
177 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
||
839 | palkovsky | 178 | } |
179 | |||
3692 | rimsky | 180 | /** Put pixel - 8-bit depth (color palette/3:2:3, inverted) |
1837 | jermar | 181 | * |
182 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
||
183 | * will most likely use a color palette. The color appearance |
||
184 | * will be pretty random and depend on the default installed |
||
185 | * palette. This could be fixed by supporting custom palette |
||
186 | * and setting it to simulate the 8-bit truecolor. |
||
3692 | rimsky | 187 | * |
188 | * Currently we set the palette on the sparc64 port. |
||
189 | * |
||
190 | * Note that the byte is being inverted by this function. The reason is |
||
191 | * that we would like to use a color palette where the white color code |
||
192 | * is 0 and the black color code is 255, as some machines (SunBlade 1500) |
||
193 | * use these codes for black and white and prevent to set codes |
||
194 | * 0 and 255 to other colors. |
||
1837 | jermar | 195 | */ |
1993 | decky | 196 | static void rgb_byte8(void *dst, int rgb) |
839 | palkovsky | 197 | { |
3692 | rimsky | 198 | *((uint8_t *) dst) = 255 - (RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
199 | BLUE(rgb, 3)); |
||
1135 | decky | 200 | } |
839 | palkovsky | 201 | |
1837 | jermar | 202 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
203 | * |
||
1993 | decky | 204 | * See the comment for rgb_byte(). |
1837 | jermar | 205 | */ |
1993 | decky | 206 | static int byte8_rgb(void *src) |
1135 | decky | 207 | { |
3692 | rimsky | 208 | int color = 255 - (*(uint8_t *)src); |
2086 | jermar | 209 | return (((color >> 5) & 0x7) << (16 + 5)) | |
210 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
||
839 | palkovsky | 211 | } |
212 | |||
1682 | palkovsky | 213 | static void putpixel(unsigned int x, unsigned int y, int color) |
1135 | decky | 214 | { |
1990 | decky | 215 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
1682 | palkovsky | 216 | |
217 | if (dbbuffer) { |
||
218 | int dline = (y + dboffset) % yres; |
||
1990 | decky | 219 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
1682 | palkovsky | 220 | } |
1135 | decky | 221 | } |
839 | palkovsky | 222 | |
1682 | palkovsky | 223 | /** Get pixel from viewport */ |
224 | static int getpixel(unsigned int x, unsigned int y) |
||
225 | { |
||
226 | if (dbbuffer) { |
||
227 | int dline = (y + dboffset) % yres; |
||
1990 | decky | 228 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
1682 | palkovsky | 229 | } |
1990 | decky | 230 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
1682 | palkovsky | 231 | } |
1135 | decky | 232 | |
1682 | palkovsky | 233 | |
1135 | decky | 234 | /** Fill screen with background color */ |
235 | static void clear_screen(void) |
||
839 | palkovsky | 236 | { |
1135 | decky | 237 | unsigned int y; |
839 | palkovsky | 238 | |
1682 | palkovsky | 239 | for (y = 0; y < yres; y++) { |
1990 | decky | 240 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
1682 | palkovsky | 241 | if (dbbuffer) |
2086 | jermar | 242 | memcpy(&dbbuffer[scanline * y], blankline, |
243 | xres * pixelbytes); |
||
1682 | palkovsky | 244 | } |
839 | palkovsky | 245 | } |
246 | |||
1135 | decky | 247 | |
838 | palkovsky | 248 | /** Scroll screen one row up */ |
249 | static void scroll_screen(void) |
||
250 | { |
||
1682 | palkovsky | 251 | if (dbbuffer) { |
2054 | jermar | 252 | count_t first; |
253 | |||
2086 | jermar | 254 | /* Clear the last row */ |
1993 | decky | 255 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
1682 | palkovsky | 256 | |
257 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
||
2054 | jermar | 258 | first = yres - dboffset; |
2086 | jermar | 259 | |
260 | /* Move all rows one row up */ |
||
261 | if (xres * pixelbytes == scanline) { |
||
262 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
||
263 | first * scanline); |
||
264 | memcpy(&fbaddress[first * scanline], dbbuffer, |
||
265 | dboffset * scanline); |
||
266 | } else { |
||
267 | /* |
||
268 | * When the scanline is bigger than number of bytes |
||
269 | * in the X-resolution, chances are that the |
||
270 | * frame buffer memory past the X-resolution is special |
||
271 | * in some way. For example, the SUNW,ffb framebuffer |
||
272 | * wraps this area around the beginning of the same |
||
273 | * line. To avoid troubles, copy only memory as |
||
274 | * specified by the resolution. |
||
275 | */ |
||
2102 | decky | 276 | unsigned int i; |
838 | palkovsky | 277 | |
2086 | jermar | 278 | for (i = 0; i < first; i++) |
279 | memcpy(&fbaddress[i * scanline], |
||
280 | &dbbuffer[(dboffset + i) * scanline], |
||
281 | xres * pixelbytes); |
||
282 | for (i = 0; i < dboffset; i++) |
||
283 | memcpy(&fbaddress[(first + i) * scanline], |
||
284 | &dbbuffer[i * scanline], xres * pixelbytes); |
||
285 | } |
||
1682 | palkovsky | 286 | } else { |
2054 | jermar | 287 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
288 | |||
2086 | jermar | 289 | if (xres * pixelbytes == scanline) { |
290 | /* Move all rows one row up */ |
||
291 | memcpy((void *) fbaddress, |
||
292 | (void *) &fbaddress[ROW_BYTES], |
||
293 | scanline * yres - ROW_BYTES); |
||
294 | /* Clear the last row */ |
||
295 | memcpy((void *) lastline, (void *) blankline, |
||
296 | ROW_BYTES); |
||
297 | } else { |
||
298 | /* |
||
299 | * See the comment in the dbbuffer case. |
||
300 | */ |
||
2102 | decky | 301 | unsigned int i; |
2086 | jermar | 302 | |
303 | /* Move all rows one row up */ |
||
304 | for (i = 0; i < yres - FONT_SCANLINES; i++) |
||
305 | memcpy(&fbaddress[i * scanline], |
||
306 | &fbaddress[(i + FONT_SCANLINES) * scanline], |
||
307 | xres * pixelbytes); |
||
308 | /* Clear the last row */ |
||
309 | for (i = 0; i < FONT_SCANLINES; i++) |
||
310 | memcpy(&lastline[i * scanline], |
||
311 | &blankline[i * scanline], |
||
312 | xres * pixelbytes); |
||
313 | } |
||
1682 | palkovsky | 314 | } |
838 | palkovsky | 315 | } |
316 | |||
317 | |||
1135 | decky | 318 | static void invert_pixel(unsigned int x, unsigned int y) |
836 | palkovsky | 319 | { |
1682 | palkovsky | 320 | putpixel(x, y, ~getpixel(x, y)); |
836 | palkovsky | 321 | } |
322 | |||
323 | |||
324 | /** Draw one line of glyph at a given position */ |
||
1135 | decky | 325 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
836 | palkovsky | 326 | { |
1135 | decky | 327 | unsigned int i; |
836 | palkovsky | 328 | |
1135 | decky | 329 | for (i = 0; i < 8; i++) |
330 | if (glline & (1 << (7 - i))) { |
||
1682 | palkovsky | 331 | putpixel(x + i, y, FGCOLOR); |
836 | palkovsky | 332 | } else |
1682 | palkovsky | 333 | putpixel(x + i, y, BGCOLOR); |
836 | palkovsky | 334 | } |
335 | |||
838 | palkovsky | 336 | /***************************************************************/ |
337 | /* Character-console functions */ |
||
338 | |||
836 | palkovsky | 339 | /** Draw character at given position */ |
1780 | jermar | 340 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
836 | palkovsky | 341 | { |
1135 | decky | 342 | unsigned int y; |
836 | palkovsky | 343 | |
1135 | decky | 344 | for (y = 0; y < FONT_SCANLINES; y++) |
2086 | jermar | 345 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
346 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
||
836 | palkovsky | 347 | } |
348 | |||
349 | /** Invert character at given position */ |
||
1135 | decky | 350 | static void invert_char(unsigned int col, unsigned int row) |
836 | palkovsky | 351 | { |
1135 | decky | 352 | unsigned int x; |
353 | unsigned int y; |
||
836 | palkovsky | 354 | |
1135 | decky | 355 | for (x = 0; x < COL_WIDTH; x++) |
356 | for (y = 0; y < FONT_SCANLINES; y++) |
||
2086 | jermar | 357 | invert_pixel(col * COL_WIDTH + x, |
358 | row * FONT_SCANLINES + y); |
||
836 | palkovsky | 359 | } |
360 | |||
361 | /** Draw character at default position */ |
||
362 | static void draw_char(char chr) |
||
363 | { |
||
1135 | decky | 364 | draw_glyph(chr, position % columns, position / columns); |
836 | palkovsky | 365 | } |
366 | |||
1135 | decky | 367 | static void draw_logo(unsigned int startx, unsigned int starty) |
862 | palkovsky | 368 | { |
1135 | decky | 369 | unsigned int x; |
370 | unsigned int y; |
||
371 | unsigned int byte; |
||
372 | unsigned int rowbytes; |
||
862 | palkovsky | 373 | |
1135 | decky | 374 | rowbytes = (helenos_width - 1) / 8 + 1; |
862 | palkovsky | 375 | |
1135 | decky | 376 | for (y = 0; y < helenos_height; y++) |
377 | for (x = 0; x < helenos_width; x++) { |
||
378 | byte = helenos_bits[rowbytes * y + x / 8]; |
||
862 | palkovsky | 379 | byte >>= x % 8; |
380 | if (byte & 1) |
||
2054 | jermar | 381 | putpixel(startx + x, starty + y, |
2086 | jermar | 382 | COLOR(LOGOCOLOR)); |
862 | palkovsky | 383 | } |
384 | } |
||
385 | |||
838 | palkovsky | 386 | /***************************************************************/ |
387 | /* Stdout specific functions */ |
||
388 | |||
836 | palkovsky | 389 | static void invert_cursor(void) |
390 | { |
||
1135 | decky | 391 | invert_char(position % columns, position / columns); |
836 | palkovsky | 392 | } |
393 | |||
394 | /** Print character to screen |
||
395 | * |
||
396 | * Emulate basic terminal commands |
||
397 | */ |
||
398 | static void fb_putchar(chardev_t *dev, char ch) |
||
399 | { |
||
1287 | vana | 400 | spinlock_lock(&fb_lock); |
1135 | decky | 401 | |
402 | switch (ch) { |
||
1888 | jermar | 403 | case '\n': |
404 | invert_cursor(); |
||
405 | position += columns; |
||
406 | position -= position % columns; |
||
407 | break; |
||
408 | case '\r': |
||
409 | invert_cursor(); |
||
410 | position -= position % columns; |
||
411 | break; |
||
412 | case '\b': |
||
413 | invert_cursor(); |
||
414 | if (position % columns) |
||
415 | position--; |
||
416 | break; |
||
417 | case '\t': |
||
418 | invert_cursor(); |
||
419 | do { |
||
420 | draw_char(' '); |
||
838 | palkovsky | 421 | position++; |
1888 | jermar | 422 | } while ((position % 8) && position < columns * rows); |
423 | break; |
||
424 | default: |
||
425 | draw_char(ch); |
||
426 | position++; |
||
836 | palkovsky | 427 | } |
1135 | decky | 428 | |
429 | if (position >= columns * rows) { |
||
836 | palkovsky | 430 | position -= columns; |
431 | scroll_screen(); |
||
432 | } |
||
1135 | decky | 433 | |
836 | palkovsky | 434 | invert_cursor(); |
1135 | decky | 435 | |
1287 | vana | 436 | spinlock_unlock(&fb_lock); |
836 | palkovsky | 437 | } |
438 | |||
439 | static chardev_t framebuffer; |
||
440 | static chardev_operations_t fb_ops = { |
||
441 | .write = fb_putchar, |
||
442 | }; |
||
443 | |||
444 | |||
445 | /** Initialize framebuffer as a chardev output device |
||
446 | * |
||
3672 | jermar | 447 | * @param props Properties of the framebuffer device. |
836 | palkovsky | 448 | */ |
3672 | jermar | 449 | void fb_init(fb_properties_t *props) |
836 | palkovsky | 450 | { |
3672 | jermar | 451 | switch (props->visual) { |
1993 | decky | 452 | case VISUAL_INDIRECT_8: |
453 | rgb2scr = rgb_byte8; |
||
454 | scr2rgb = byte8_rgb; |
||
1991 | jermar | 455 | pixelbytes = 1; |
456 | break; |
||
1993 | decky | 457 | case VISUAL_RGB_5_5_5: |
458 | rgb2scr = rgb_byte555; |
||
459 | scr2rgb = byte555_rgb; |
||
1991 | jermar | 460 | pixelbytes = 2; |
461 | break; |
||
1993 | decky | 462 | case VISUAL_RGB_5_6_5: |
463 | rgb2scr = rgb_byte565; |
||
464 | scr2rgb = byte565_rgb; |
||
465 | pixelbytes = 2; |
||
1991 | jermar | 466 | break; |
1993 | decky | 467 | case VISUAL_RGB_8_8_8: |
468 | rgb2scr = rgb_byte888; |
||
469 | scr2rgb = byte888_rgb; |
||
470 | pixelbytes = 3; |
||
471 | break; |
||
472 | case VISUAL_RGB_8_8_8_0: |
||
473 | rgb2scr = rgb_byte888; |
||
474 | scr2rgb = byte888_rgb; |
||
1991 | jermar | 475 | pixelbytes = 4; |
476 | break; |
||
1993 | decky | 477 | case VISUAL_RGB_0_8_8_8: |
478 | rgb2scr = rgb_byte0888; |
||
479 | scr2rgb = byte0888_rgb; |
||
480 | pixelbytes = 4; |
||
481 | break; |
||
1994 | decky | 482 | case VISUAL_BGR_0_8_8_8: |
483 | rgb2scr = bgr_byte0888; |
||
484 | scr2rgb = byte0888_bgr; |
||
485 | pixelbytes = 4; |
||
486 | break; |
||
1991 | jermar | 487 | default: |
1993 | decky | 488 | panic("Unsupported visual.\n"); |
839 | palkovsky | 489 | } |
1371 | decky | 490 | |
3679 | rimsky | 491 | unsigned int fbsize = props->scan * props->y; |
1371 | decky | 492 | |
493 | /* Map the framebuffer */ |
||
3692 | rimsky | 494 | fbaddress = (uint8_t *) hw_map((uintptr_t) props->addr, |
495 | fbsize + props->offset); |
||
3672 | jermar | 496 | fbaddress += props->offset; |
1371 | decky | 497 | |
3672 | jermar | 498 | xres = props->x; |
499 | yres = props->y; |
||
500 | scanline = props->scan; |
||
836 | palkovsky | 501 | |
3672 | jermar | 502 | rows = props->y / FONT_SCANLINES; |
503 | columns = props->x / COL_WIDTH; |
||
836 | palkovsky | 504 | |
3692 | rimsky | 505 | fb_parea.pbase = (uintptr_t) props->addr + props->offset; |
2015 | jermar | 506 | fb_parea.vbase = (uintptr_t) fbaddress; |
507 | fb_parea.frames = SIZE2FRAMES(fbsize); |
||
508 | fb_parea.cacheable = false; |
||
509 | ddi_parea_register(&fb_parea); |
||
510 | |||
1690 | palkovsky | 511 | sysinfo_set_item_val("fb", NULL, true); |
512 | sysinfo_set_item_val("fb.kind", NULL, 1); |
||
513 | sysinfo_set_item_val("fb.width", NULL, xres); |
||
514 | sysinfo_set_item_val("fb.height", NULL, yres); |
||
3672 | jermar | 515 | sysinfo_set_item_val("fb.scanline", NULL, props->scan); |
516 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
||
517 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
||
3679 | rimsky | 518 | sysinfo_set_item_val("fb.offset", NULL, props->offset); |
1875 | jermar | 519 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
1690 | palkovsky | 520 | |
1682 | palkovsky | 521 | /* Allocate double buffer */ |
2054 | jermar | 522 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
523 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
||
1760 | palkovsky | 524 | if (!dbbuffer) |
1682 | palkovsky | 525 | printf("Failed to allocate scroll buffer.\n"); |
526 | dboffset = 0; |
||
527 | |||
528 | /* Initialized blank line */ |
||
1780 | jermar | 529 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
1766 | palkovsky | 530 | if (!blankline) |
531 | panic("Failed to allocate blank line for framebuffer."); |
||
3672 | jermar | 532 | unsigned int x, y; |
1990 | decky | 533 | for (y = 0; y < FONT_SCANLINES; y++) |
534 | for (x = 0; x < xres; x++) |
||
535 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
||
536 | |||
1682 | palkovsky | 537 | clear_screen(); |
538 | |||
539 | /* Update size of screen to match text area */ |
||
540 | yres = rows * FONT_SCANLINES; |
||
541 | |||
1135 | decky | 542 | draw_logo(xres - helenos_width, 0); |
836 | palkovsky | 543 | invert_cursor(); |
544 | |||
545 | chardev_initialize("fb", &framebuffer, &fb_ops); |
||
546 | stdout = &framebuffer; |
||
547 | } |
||
1702 | cejka | 548 | |
1790 | jermar | 549 | /** @} |
1702 | cejka | 550 | */ |