Rev 2071 | Rev 2089 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2086 | ||
---|---|---|---|
Line 79... | Line 79... | ||
79 | 79 | ||
80 | #define BGCOLOR 0x000080 |
80 | #define BGCOLOR 0x000080 |
81 | #define FGCOLOR 0xffff00 |
81 | #define FGCOLOR 0xffff00 |
82 | #define LOGOCOLOR 0x2020b0 |
82 | #define LOGOCOLOR 0x2020b0 |
83 | 83 | ||
84 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
84 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
86 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
86 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
87 | 87 | ||
88 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
88 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
89 | 89 | ||
Line 109... | Line 109... | ||
109 | return (*((int *) src)) & 0xffffff; |
109 | return (*((int *) src)) & 0xffffff; |
110 | } |
110 | } |
111 | 111 | ||
112 | static void bgr_byte0888(void *dst, int rgb) |
112 | static void bgr_byte0888(void *dst, int rgb) |
113 | { |
113 | { |
114 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | RED(rgb, |
114 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | |
115 | 8); |
115 | RED(rgb, 8); |
116 | } |
116 | } |
117 | 117 | ||
118 | static int byte0888_bgr(void *src) |
118 | static int byte0888_bgr(void *src) |
119 | { |
119 | { |
120 | int color = *(uint32_t *)(src); |
120 | int color = *(uint32_t *)(src); |
121 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color |
121 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
122 | >> 16) & 0xff); |
122 | ((color >> 16) & 0xff); |
123 | } |
123 | } |
124 | 124 | ||
125 | static void rgb_byte888(void *dst, int rgb) |
125 | static void rgb_byte888(void *dst, int rgb) |
126 | { |
126 | { |
127 | uint8_t *scr = dst; |
127 | uint8_t *scr = dst; |
Line 148... | Line 148... | ||
148 | 148 | ||
149 | /** 16-bit depth (5:5:5) */ |
149 | /** 16-bit depth (5:5:5) */ |
150 | static void rgb_byte555(void *dst, int rgb) |
150 | static void rgb_byte555(void *dst, int rgb) |
151 | { |
151 | { |
152 | /* 5-bit, 5-bits, 5-bits */ |
152 | /* 5-bit, 5-bits, 5-bits */ |
153 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, |
153 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
154 | 5); |
154 | BLUE(rgb, 5); |
155 | } |
155 | } |
156 | 156 | ||
157 | /** 16-bit depth (5:5:5) */ |
157 | /** 16-bit depth (5:5:5) */ |
158 | static int byte555_rgb(void *src) |
158 | static int byte555_rgb(void *src) |
159 | { |
159 | { |
160 | int color = *(uint16_t *)(src); |
160 | int color = *(uint16_t *)(src); |
161 | return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << |
161 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
162 | (8 + 3)) | ((color & 0x1f) << 3); |
162 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
163 | } |
163 | } |
164 | 164 | ||
165 | /** 16-bit depth (5:6:5) */ |
165 | /** 16-bit depth (5:6:5) */ |
166 | static void rgb_byte565(void *dst, int rgb) |
166 | static void rgb_byte565(void *dst, int rgb) |
167 | { |
167 | { |
168 | /* 5-bit, 6-bits, 5-bits */ |
168 | /* 5-bit, 6-bits, 5-bits */ |
169 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
169 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
- | 170 | BLUE(rgb, 5); |
|
170 | } |
171 | } |
171 | 172 | ||
172 | /** 16-bit depth (5:6:5) */ |
173 | /** 16-bit depth (5:6:5) */ |
173 | static int byte565_rgb(void *src) |
174 | static int byte565_rgb(void *src) |
174 | { |
175 | { |
175 | int color = *(uint16_t *)(src); |
176 | int color = *(uint16_t *)(src); |
176 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << |
177 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
177 | (8 + 2)) | ((color & 0x1f) << 3); |
178 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
178 | } |
179 | } |
179 | 180 | ||
180 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
181 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
181 | * |
182 | * |
182 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
183 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
Line 185... | Line 186... | ||
185 | * palette. This could be fixed by supporting custom palette |
186 | * palette. This could be fixed by supporting custom palette |
186 | * and setting it to simulate the 8-bit truecolor. |
187 | * and setting it to simulate the 8-bit truecolor. |
187 | */ |
188 | */ |
188 | static void rgb_byte8(void *dst, int rgb) |
189 | static void rgb_byte8(void *dst, int rgb) |
189 | { |
190 | { |
190 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, |
191 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
191 | 3); |
192 | BLUE(rgb, 3); |
192 | } |
193 | } |
193 | 194 | ||
194 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
195 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
195 | * |
196 | * |
196 | * See the comment for rgb_byte(). |
197 | * See the comment for rgb_byte(). |
197 | */ |
198 | */ |
198 | static int byte8_rgb(void *src) |
199 | static int byte8_rgb(void *src) |
199 | { |
200 | { |
200 | int color = *(uint8_t *)src; |
201 | int color = *(uint8_t *)src; |
201 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 |
202 | return (((color >> 5) & 0x7) << (16 + 5)) | |
202 | + 6)) | ((color & 0x7) << 5); |
203 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
203 | } |
204 | } |
204 | 205 | ||
205 | static void putpixel(unsigned int x, unsigned int y, int color) |
206 | static void putpixel(unsigned int x, unsigned int y, int color) |
206 | { |
207 | { |
207 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
208 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
Line 229... | Line 230... | ||
229 | unsigned int y; |
230 | unsigned int y; |
230 | 231 | ||
231 | for (y = 0; y < yres; y++) { |
232 | for (y = 0; y < yres; y++) { |
232 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
233 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
233 | if (dbbuffer) |
234 | if (dbbuffer) |
234 | memcpy(&dbbuffer[scanline * y], blankline, xres * |
235 | memcpy(&dbbuffer[scanline * y], blankline, |
235 | pixelbytes); |
236 | xres * pixelbytes); |
236 | } |
237 | } |
237 | } |
238 | } |
238 | 239 | ||
239 | 240 | ||
240 | /** Scroll screen one row up */ |
241 | /** Scroll screen one row up */ |
241 | static void scroll_screen(void) |
242 | static void scroll_screen(void) |
242 | { |
243 | { |
243 | if (dbbuffer) { |
244 | if (dbbuffer) { |
244 | count_t first; |
245 | count_t first; |
245 | 246 | ||
- | 247 | /* Clear the last row */ |
|
246 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
248 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
247 | 249 | ||
248 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
250 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
249 | first = yres - dboffset; |
251 | first = yres - dboffset; |
250 | 252 | ||
- | 253 | /* Move all rows one row up */ |
|
- | 254 | if (xres * pixelbytes == scanline) { |
|
251 | memcpy(fbaddress, &dbbuffer[scanline * dboffset], first * |
255 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
252 | scanline); |
256 | first * scanline); |
253 | memcpy(&fbaddress[first * scanline], dbbuffer, dboffset * |
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 | */ |
|
254 | scanline); |
269 | int i; |
- | 270 | ||
- | 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 | } |
|
255 | } else { |
279 | } else { |
256 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
280 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
257 | 281 | ||
- | 282 | if (xres * pixelbytes == scanline) { |
|
- | 283 | /* Move all rows one row up */ |
|
- | 284 | memcpy((void *) fbaddress, |
|
258 | memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], |
285 | (void *) &fbaddress[ROW_BYTES], |
259 | scanline * yres - ROW_BYTES); |
286 | scanline * yres - ROW_BYTES); |
260 | /* Clear last row */ |
287 | /* Clear the last row */ |
261 | memcpy((void *) lastline, (void *) blankline, ROW_BYTES); |
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 | } |
|
262 | } |
307 | } |
263 | } |
308 | } |
264 | 309 | ||
265 | 310 | ||
266 | static void invert_pixel(unsigned int x, unsigned int y) |
311 | static void invert_pixel(unsigned int x, unsigned int y) |
Line 288... | Line 333... | ||
288 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
333 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
289 | { |
334 | { |
290 | unsigned int y; |
335 | unsigned int y; |
291 | 336 | ||
292 | for (y = 0; y < FONT_SCANLINES; y++) |
337 | for (y = 0; y < FONT_SCANLINES; y++) |
293 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * |
338 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
294 | COL_WIDTH, row * FONT_SCANLINES + y); |
339 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
295 | } |
340 | } |
296 | 341 | ||
297 | /** Invert character at given position */ |
342 | /** Invert character at given position */ |
298 | static void invert_char(unsigned int col, unsigned int row) |
343 | static void invert_char(unsigned int col, unsigned int row) |
299 | { |
344 | { |
300 | unsigned int x; |
345 | unsigned int x; |
301 | unsigned int y; |
346 | unsigned int y; |
302 | 347 | ||
303 | for (x = 0; x < COL_WIDTH; x++) |
348 | for (x = 0; x < COL_WIDTH; x++) |
304 | for (y = 0; y < FONT_SCANLINES; y++) |
349 | for (y = 0; y < FONT_SCANLINES; y++) |
305 | invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + |
350 | invert_pixel(col * COL_WIDTH + x, |
306 | y); |
351 | row * FONT_SCANLINES + y); |
307 | } |
352 | } |
308 | 353 | ||
309 | /** Draw character at default position */ |
354 | /** Draw character at default position */ |
310 | static void draw_char(char chr) |
355 | static void draw_char(char chr) |
311 | { |
356 | { |
Line 325... | Line 370... | ||
325 | for (x = 0; x < helenos_width; x++) { |
370 | for (x = 0; x < helenos_width; x++) { |
326 | byte = helenos_bits[rowbytes * y + x / 8]; |
371 | byte = helenos_bits[rowbytes * y + x / 8]; |
327 | byte >>= x % 8; |
372 | byte >>= x % 8; |
328 | if (byte & 1) |
373 | if (byte & 1) |
329 | putpixel(startx + x, starty + y, |
374 | putpixel(startx + x, starty + y, |
330 | COLOR(LOGOCOLOR)); |
375 | COLOR(LOGOCOLOR)); |
331 | } |
376 | } |
332 | } |
377 | } |
333 | 378 | ||
334 | /***************************************************************/ |
379 | /***************************************************************/ |
335 | /* Stdout specific functions */ |
380 | /* Stdout specific functions */ |
Line 398... | Line 443... | ||
398 | * @param scan Bytes per one scanline |
443 | * @param scan Bytes per one scanline |
399 | * @param visual Color model |
444 | * @param visual Color model |
400 | * |
445 | * |
401 | */ |
446 | */ |
402 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, |
447 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, |
403 | unsigned int visual) |
448 | unsigned int visual) |
404 | { |
449 | { |
405 | switch (visual) { |
450 | switch (visual) { |
406 | case VISUAL_INDIRECT_8: |
451 | case VISUAL_INDIRECT_8: |
407 | rgb2scr = rgb_byte8; |
452 | rgb2scr = rgb_byte8; |
408 | scr2rgb = byte8_rgb; |
453 | scr2rgb = byte8_rgb; |
Line 465... | Line 510... | ||
465 | sysinfo_set_item_val("fb.width", NULL, xres); |
510 | sysinfo_set_item_val("fb.width", NULL, xres); |
466 | sysinfo_set_item_val("fb.height", NULL, yres); |
511 | sysinfo_set_item_val("fb.height", NULL, yres); |
467 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
512 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
468 | sysinfo_set_item_val("fb.visual", NULL, visual); |
513 | sysinfo_set_item_val("fb.visual", NULL, visual); |
469 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
514 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
470 | sysinfo_set_item_val("fb.address.color", NULL, PAGE_COLOR((uintptr_t) |
515 | sysinfo_set_item_val("fb.address.color", NULL, |
471 | fbaddress)); |
516 | PAGE_COLOR((uintptr_t) fbaddress)); |
472 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
517 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
473 | 518 | ||
474 | /* Allocate double buffer */ |
519 | /* Allocate double buffer */ |
475 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
520 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
476 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
521 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |