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