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