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