Rev 1871 | Rev 1888 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1871 | Rev 1875 | ||
---|---|---|---|
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/fb.h> |
36 | #include <genarch/fb/fb.h> |
37 | #include <console/chardev.h> |
37 | #include <console/chardev.h> |
38 | #include <console/console.h> |
38 | #include <console/console.h> |
39 | #include <sysinfo/sysinfo.h> |
39 | #include <sysinfo/sysinfo.h> |
40 | #include <mm/slab.h> |
40 | #include <mm/slab.h> |
41 | #include <align.h> |
41 | #include <align.h> |
42 | #include <panic.h> |
42 | #include <panic.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
44 | #include <config.h> |
44 | #include <config.h> |
45 | #include <bitops.h> |
45 | #include <bitops.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | 47 | ||
48 | #include "helenos.xbm" |
48 | #include "helenos.xbm" |
49 | 49 | ||
50 | SPINLOCK_INITIALIZE(fb_lock); |
50 | SPINLOCK_INITIALIZE(fb_lock); |
51 | 51 | ||
52 | static uint8_t *fbaddress = NULL; |
52 | static uint8_t *fbaddress = NULL; |
53 | 53 | ||
54 | static uint8_t *blankline = NULL; |
54 | static uint8_t *blankline = NULL; |
55 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
55 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
56 | static int dboffset; |
56 | static int dboffset; |
57 | 57 | ||
58 | static unsigned int xres = 0; |
58 | static unsigned int xres = 0; |
59 | static unsigned int yres = 0; |
59 | static unsigned int yres = 0; |
60 | static unsigned int scanline = 0; |
60 | static unsigned int scanline = 0; |
61 | static unsigned int bitspp = 0; |
61 | static unsigned int bitspp = 0; |
62 | static unsigned int pixelbytes = 0; |
62 | static unsigned int pixelbytes = 0; |
- | 63 | #ifdef FB_INVERT_COLORS |
|
- | 64 | static bool invert_colors = true; |
|
- | 65 | #else |
|
- | 66 | static bool invert_colors = false; |
|
- | 67 | #endif |
|
63 | 68 | ||
64 | static unsigned int position = 0; |
69 | static unsigned int position = 0; |
65 | static unsigned int columns = 0; |
70 | static unsigned int columns = 0; |
66 | static unsigned int rows = 0; |
71 | static unsigned int rows = 0; |
67 | 72 | ||
68 | - | ||
69 | #define COL_WIDTH 8 |
73 | #define COL_WIDTH 8 |
70 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
74 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
71 | 75 | ||
72 | #define BGCOLOR 0x000080 |
76 | #define BGCOLOR 0x000080 |
73 | #define FGCOLOR 0xffff00 |
77 | #define FGCOLOR 0xffff00 |
74 | #define LOGOCOLOR 0x2020b0 |
78 | #define LOGOCOLOR 0x2020b0 |
75 | 79 | ||
76 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
80 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
77 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
81 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
78 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
82 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
79 | 83 | ||
80 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
84 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
81 | 85 | ||
82 | /***************************************************************/ |
86 | /***************************************************************/ |
83 | /* Pixel specific fuctions */ |
87 | /* Pixel specific fuctions */ |
84 | 88 | ||
85 | static void (*rgb2scr)(void *, int); |
89 | static void (*rgb2scr)(void *, int); |
86 | static int (*scr2rgb)(void *); |
90 | static int (*scr2rgb)(void *); |
87 | 91 | ||
- | 92 | static inline int COLOR(int color) |
|
- | 93 | { |
|
- | 94 | return invert_colors ? ~color : color; |
|
- | 95 | } |
|
- | 96 | ||
88 | /* Conversion routines between different color representations */ |
97 | /* Conversion routines between different color representations */ |
89 | static void rgb_4byte(void *dst, int rgb) |
98 | static void rgb_4byte(void *dst, int rgb) |
90 | { |
99 | { |
91 | *(int *)dst = rgb; |
100 | *(int *)dst = rgb; |
92 | } |
101 | } |
93 | 102 | ||
94 | static int byte4_rgb(void *src) |
103 | static int byte4_rgb(void *src) |
95 | { |
104 | { |
96 | return (*(int *)src) & 0xffffff; |
105 | return (*(int *)src) & 0xffffff; |
97 | } |
106 | } |
98 | 107 | ||
99 | static void rgb_3byte(void *dst, int rgb) |
108 | static void rgb_3byte(void *dst, int rgb) |
100 | { |
109 | { |
101 | uint8_t *scr = dst; |
110 | uint8_t *scr = dst; |
102 | #if defined(FB_INVERT_ENDIAN) |
111 | #if defined(FB_INVERT_ENDIAN) |
103 | scr[0] = RED(rgb, 8); |
112 | scr[0] = RED(rgb, 8); |
104 | scr[1] = GREEN(rgb, 8); |
113 | scr[1] = GREEN(rgb, 8); |
105 | scr[2] = BLUE(rgb, 8); |
114 | scr[2] = BLUE(rgb, 8); |
106 | #else |
115 | #else |
107 | scr[2] = RED(rgb, 8); |
116 | scr[2] = RED(rgb, 8); |
108 | scr[1] = GREEN(rgb, 8); |
117 | scr[1] = GREEN(rgb, 8); |
109 | scr[0] = BLUE(rgb, 8); |
118 | scr[0] = BLUE(rgb, 8); |
110 | #endif |
119 | #endif |
111 | } |
120 | } |
112 | 121 | ||
113 | static int byte3_rgb(void *src) |
122 | static int byte3_rgb(void *src) |
114 | { |
123 | { |
115 | uint8_t *scr = src; |
124 | uint8_t *scr = src; |
116 | #if defined(FB_INVERT_ENDIAN) |
125 | #if defined(FB_INVERT_ENDIAN) |
117 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
126 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
118 | #else |
127 | #else |
119 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
128 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
120 | #endif |
129 | #endif |
121 | } |
130 | } |
122 | 131 | ||
123 | /** 16-bit depth (5:6:5) */ |
132 | /** 16-bit depth (5:6:5) */ |
124 | static void rgb_2byte(void *dst, int rgb) |
133 | static void rgb_2byte(void *dst, int rgb) |
125 | { |
134 | { |
126 | /* 5-bit, 6-bits, 5-bits */ |
135 | /* 5-bit, 6-bits, 5-bits */ |
127 | *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
136 | *((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
128 | } |
137 | } |
129 | 138 | ||
130 | /** 16-bit depth (5:6:5) */ |
139 | /** 16-bit depth (5:6:5) */ |
131 | static int byte2_rgb(void *src) |
140 | static int byte2_rgb(void *src) |
132 | { |
141 | { |
133 | int color = *(uint16_t *)(src); |
142 | int color = *(uint16_t *)(src); |
134 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
143 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
135 | } |
144 | } |
136 | 145 | ||
137 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
146 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
138 | * |
147 | * |
139 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
148 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
140 | * will most likely use a color palette. The color appearance |
149 | * will most likely use a color palette. The color appearance |
141 | * will be pretty random and depend on the default installed |
150 | * will be pretty random and depend on the default installed |
142 | * palette. This could be fixed by supporting custom palette |
151 | * palette. This could be fixed by supporting custom palette |
143 | * and setting it to simulate the 8-bit truecolor. |
152 | * and setting it to simulate the 8-bit truecolor. |
144 | */ |
153 | */ |
145 | static void rgb_1byte(void *dst, int rgb) |
154 | static void rgb_1byte(void *dst, int rgb) |
146 | { |
155 | { |
147 | *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); |
156 | *(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); |
148 | } |
157 | } |
149 | 158 | ||
150 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
159 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
151 | * |
160 | * |
152 | * See the comment for rgb_1byte(). |
161 | * See the comment for rgb_1byte(). |
153 | */ |
162 | */ |
154 | static int byte1_rgb(void *src) |
163 | static int byte1_rgb(void *src) |
155 | { |
164 | { |
156 | int color = *(uint8_t *)src; |
165 | int color = *(uint8_t *)src; |
157 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
166 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
158 | } |
167 | } |
159 | 168 | ||
160 | static void putpixel(unsigned int x, unsigned int y, int color) |
169 | static void putpixel(unsigned int x, unsigned int y, int color) |
161 | { |
170 | { |
162 | (*rgb2scr)(&fbaddress[POINTPOS(x,y)],color); |
171 | (*rgb2scr)(&fbaddress[POINTPOS(x,y)], COLOR(color)); |
163 | 172 | ||
164 | if (dbbuffer) { |
173 | if (dbbuffer) { |
165 | int dline = (y + dboffset) % yres; |
174 | int dline = (y + dboffset) % yres; |
166 | (*rgb2scr)(&dbbuffer[POINTPOS(x,dline)],color); |
175 | (*rgb2scr)(&dbbuffer[POINTPOS(x,dline)], COLOR(color)); |
167 | } |
176 | } |
168 | } |
177 | } |
169 | 178 | ||
170 | /** Get pixel from viewport */ |
179 | /** Get pixel from viewport */ |
171 | static int getpixel(unsigned int x, unsigned int y) |
180 | static int getpixel(unsigned int x, unsigned int y) |
172 | { |
181 | { |
173 | if (dbbuffer) { |
182 | if (dbbuffer) { |
174 | int dline = (y + dboffset) % yres; |
183 | int dline = (y + dboffset) % yres; |
175 | return (*scr2rgb)(&dbbuffer[POINTPOS(x,dline)]); |
184 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x,dline)])); |
176 | } |
185 | } |
177 | return (*scr2rgb)(&fbaddress[POINTPOS(x,y)]); |
186 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x,y)])); |
178 | } |
187 | } |
179 | 188 | ||
180 | 189 | ||
181 | /** Fill screen with background color */ |
190 | /** Fill screen with background color */ |
182 | static void clear_screen(void) |
191 | static void clear_screen(void) |
183 | { |
192 | { |
184 | unsigned int y; |
193 | unsigned int y; |
185 | 194 | ||
186 | for (y = 0; y < yres; y++) { |
195 | for (y = 0; y < yres; y++) { |
187 | memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes); |
196 | memcpy(&fbaddress[scanline*y], blankline, xres*pixelbytes); |
188 | if (dbbuffer) |
197 | if (dbbuffer) |
189 | memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes); |
198 | memcpy(&dbbuffer[scanline*y], blankline, xres*pixelbytes); |
190 | } |
199 | } |
191 | } |
200 | } |
192 | 201 | ||
193 | 202 | ||
194 | /** Scroll screen one row up */ |
203 | /** Scroll screen one row up */ |
195 | static void scroll_screen(void) |
204 | static void scroll_screen(void) |
196 | { |
205 | { |
197 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
206 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
198 | int firstsz; |
207 | int firstsz; |
199 | 208 | ||
200 | if (dbbuffer) { |
209 | if (dbbuffer) { |
201 | memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline); |
210 | memcpy(&dbbuffer[dboffset*scanline], blankline, FONT_SCANLINES*scanline); |
202 | 211 | ||
203 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
212 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
204 | firstsz = yres-dboffset; |
213 | firstsz = yres-dboffset; |
205 | 214 | ||
206 | memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline); |
215 | memcpy(fbaddress, &dbbuffer[scanline*dboffset], firstsz*scanline); |
207 | memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline); |
216 | memcpy(&fbaddress[firstsz*scanline], dbbuffer, dboffset*scanline); |
208 | } else { |
217 | } else { |
209 | memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES); |
218 | memcpy((void *) fbaddress, (void *) &fbaddress[ROW_BYTES], scanline * yres - ROW_BYTES); |
210 | /* Clear last row */ |
219 | /* Clear last row */ |
211 | memcpy((void *) lastline, (void *) blankline, ROW_BYTES); |
220 | memcpy((void *) lastline, (void *) blankline, ROW_BYTES); |
212 | } |
221 | } |
213 | } |
222 | } |
214 | 223 | ||
215 | 224 | ||
216 | static void invert_pixel(unsigned int x, unsigned int y) |
225 | static void invert_pixel(unsigned int x, unsigned int y) |
217 | { |
226 | { |
218 | putpixel(x, y, ~getpixel(x, y)); |
227 | putpixel(x, y, ~getpixel(x, y)); |
219 | } |
228 | } |
220 | 229 | ||
221 | 230 | ||
222 | /** Draw one line of glyph at a given position */ |
231 | /** Draw one line of glyph at a given position */ |
223 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
232 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
224 | { |
233 | { |
225 | unsigned int i; |
234 | unsigned int i; |
226 | 235 | ||
227 | for (i = 0; i < 8; i++) |
236 | for (i = 0; i < 8; i++) |
228 | if (glline & (1 << (7 - i))) { |
237 | if (glline & (1 << (7 - i))) { |
229 | putpixel(x + i, y, FGCOLOR); |
238 | putpixel(x + i, y, FGCOLOR); |
230 | } else |
239 | } else |
231 | putpixel(x + i, y, BGCOLOR); |
240 | putpixel(x + i, y, BGCOLOR); |
232 | } |
241 | } |
233 | 242 | ||
234 | /***************************************************************/ |
243 | /***************************************************************/ |
235 | /* Character-console functions */ |
244 | /* Character-console functions */ |
236 | 245 | ||
237 | /** Draw character at given position */ |
246 | /** Draw character at given position */ |
238 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
247 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
239 | { |
248 | { |
240 | unsigned int y; |
249 | unsigned int y; |
241 | 250 | ||
242 | for (y = 0; y < FONT_SCANLINES; y++) |
251 | for (y = 0; y < FONT_SCANLINES; y++) |
243 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y); |
252 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], col * COL_WIDTH, row * FONT_SCANLINES + y); |
244 | } |
253 | } |
245 | 254 | ||
246 | /** Invert character at given position */ |
255 | /** Invert character at given position */ |
247 | static void invert_char(unsigned int col, unsigned int row) |
256 | static void invert_char(unsigned int col, unsigned int row) |
248 | { |
257 | { |
249 | unsigned int x; |
258 | unsigned int x; |
250 | unsigned int y; |
259 | unsigned int y; |
251 | 260 | ||
252 | for (x = 0; x < COL_WIDTH; x++) |
261 | for (x = 0; x < COL_WIDTH; x++) |
253 | for (y = 0; y < FONT_SCANLINES; y++) |
262 | for (y = 0; y < FONT_SCANLINES; y++) |
254 | invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
263 | invert_pixel(col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
255 | } |
264 | } |
256 | 265 | ||
257 | /** Draw character at default position */ |
266 | /** Draw character at default position */ |
258 | static void draw_char(char chr) |
267 | static void draw_char(char chr) |
259 | { |
268 | { |
260 | draw_glyph(chr, position % columns, position / columns); |
269 | draw_glyph(chr, position % columns, position / columns); |
261 | } |
270 | } |
262 | 271 | ||
263 | static void draw_logo(unsigned int startx, unsigned int starty) |
272 | static void draw_logo(unsigned int startx, unsigned int starty) |
264 | { |
273 | { |
265 | unsigned int x; |
274 | unsigned int x; |
266 | unsigned int y; |
275 | unsigned int y; |
267 | unsigned int byte; |
276 | unsigned int byte; |
268 | unsigned int rowbytes; |
277 | unsigned int rowbytes; |
269 | 278 | ||
270 | rowbytes = (helenos_width - 1) / 8 + 1; |
279 | rowbytes = (helenos_width - 1) / 8 + 1; |
271 | 280 | ||
272 | for (y = 0; y < helenos_height; y++) |
281 | for (y = 0; y < helenos_height; y++) |
273 | for (x = 0; x < helenos_width; x++) { |
282 | for (x = 0; x < helenos_width; x++) { |
274 | byte = helenos_bits[rowbytes * y + x / 8]; |
283 | byte = helenos_bits[rowbytes * y + x / 8]; |
275 | byte >>= x % 8; |
284 | byte >>= x % 8; |
276 | if (byte & 1) |
285 | if (byte & 1) |
277 | putpixel(startx + x, starty + y, LOGOCOLOR); |
286 | putpixel(startx + x, starty + y, COLOR(LOGOCOLOR)); |
278 | } |
287 | } |
279 | } |
288 | } |
280 | 289 | ||
281 | /***************************************************************/ |
290 | /***************************************************************/ |
282 | /* Stdout specific functions */ |
291 | /* Stdout specific functions */ |
283 | 292 | ||
284 | static void invert_cursor(void) |
293 | static void invert_cursor(void) |
285 | { |
294 | { |
286 | invert_char(position % columns, position / columns); |
295 | invert_char(position % columns, position / columns); |
287 | } |
296 | } |
288 | 297 | ||
289 | /** Print character to screen |
298 | /** Print character to screen |
290 | * |
299 | * |
291 | * Emulate basic terminal commands |
300 | * Emulate basic terminal commands |
292 | */ |
301 | */ |
293 | static void fb_putchar(chardev_t *dev, char ch) |
302 | static void fb_putchar(chardev_t *dev, char ch) |
294 | { |
303 | { |
295 | spinlock_lock(&fb_lock); |
304 | spinlock_lock(&fb_lock); |
296 | 305 | ||
297 | switch (ch) { |
306 | switch (ch) { |
298 | case '\n': |
307 | case '\n': |
299 | invert_cursor(); |
308 | invert_cursor(); |
300 | position += columns; |
309 | position += columns; |
301 | position -= position % columns; |
310 | position -= position % columns; |
302 | break; |
311 | break; |
303 | case '\r': |
312 | case '\r': |
304 | invert_cursor(); |
313 | invert_cursor(); |
305 | position -= position % columns; |
314 | position -= position % columns; |
306 | break; |
315 | break; |
307 | case '\b': |
316 | case '\b': |
308 | invert_cursor(); |
317 | invert_cursor(); |
309 | if (position % columns) |
318 | if (position % columns) |
310 | position--; |
319 | position--; |
311 | break; |
320 | break; |
312 | case '\t': |
321 | case '\t': |
313 | invert_cursor(); |
322 | invert_cursor(); |
314 | do { |
323 | do { |
315 | draw_char(' '); |
324 | draw_char(' '); |
316 | position++; |
325 | position++; |
317 | } while ((position % 8) && position < columns * rows); |
326 | } while ((position % 8) && position < columns * rows); |
318 | break; |
327 | break; |
319 | default: |
328 | default: |
320 | draw_char(ch); |
329 | draw_char(ch); |
321 | position++; |
330 | position++; |
322 | } |
331 | } |
323 | 332 | ||
324 | if (position >= columns * rows) { |
333 | if (position >= columns * rows) { |
325 | position -= columns; |
334 | position -= columns; |
326 | scroll_screen(); |
335 | scroll_screen(); |
327 | } |
336 | } |
328 | 337 | ||
329 | invert_cursor(); |
338 | invert_cursor(); |
330 | 339 | ||
331 | spinlock_unlock(&fb_lock); |
340 | spinlock_unlock(&fb_lock); |
332 | } |
341 | } |
333 | 342 | ||
334 | static chardev_t framebuffer; |
343 | static chardev_t framebuffer; |
335 | static chardev_operations_t fb_ops = { |
344 | static chardev_operations_t fb_ops = { |
336 | .write = fb_putchar, |
345 | .write = fb_putchar, |
337 | }; |
346 | }; |
338 | 347 | ||
339 | 348 | ||
340 | /** Initialize framebuffer as a chardev output device |
349 | /** Initialize framebuffer as a chardev output device |
341 | * |
350 | * |
342 | * @param addr Physical address of the framebuffer |
351 | * @param addr Physical address of the framebuffer |
343 | * @param x Screen width in pixels |
352 | * @param x Screen width in pixels |
344 | * @param y Screen height in pixels |
353 | * @param y Screen height in pixels |
345 | * @param bpp Bits per pixel (8, 16, 24, 32) |
354 | * @param bpp Bits per pixel (8, 16, 24, 32) |
346 | * @param scan Bytes per one scanline |
355 | * @param scan Bytes per one scanline |
347 | * @param align Request alignment for 24bpp mode. |
356 | * @param align Request alignment for 24bpp mode. |
348 | */ |
357 | */ |
349 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, bool align) |
358 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, bool align) |
350 | { |
359 | { |
351 | switch (bpp) { |
360 | switch (bpp) { |
352 | case 8: |
361 | case 8: |
353 | rgb2scr = rgb_1byte; |
362 | rgb2scr = rgb_1byte; |
354 | scr2rgb = byte1_rgb; |
363 | scr2rgb = byte1_rgb; |
355 | pixelbytes = 1; |
364 | pixelbytes = 1; |
356 | break; |
365 | break; |
357 | case 16: |
366 | case 16: |
358 | rgb2scr = rgb_2byte; |
367 | rgb2scr = rgb_2byte; |
359 | scr2rgb = byte2_rgb; |
368 | scr2rgb = byte2_rgb; |
360 | pixelbytes = 2; |
369 | pixelbytes = 2; |
361 | break; |
370 | break; |
362 | case 24: |
371 | case 24: |
363 | rgb2scr = rgb_3byte; |
372 | rgb2scr = rgb_3byte; |
364 | scr2rgb = byte3_rgb; |
373 | scr2rgb = byte3_rgb; |
365 | if (align) |
374 | if (align) |
366 | pixelbytes = 4; |
375 | pixelbytes = 4; |
367 | else |
376 | else |
368 | pixelbytes = 3; |
377 | pixelbytes = 3; |
369 | break; |
378 | break; |
370 | case 32: |
379 | case 32: |
371 | rgb2scr = rgb_4byte; |
380 | rgb2scr = rgb_4byte; |
372 | scr2rgb = byte4_rgb; |
381 | scr2rgb = byte4_rgb; |
373 | pixelbytes = 4; |
382 | pixelbytes = 4; |
374 | break; |
383 | break; |
375 | default: |
384 | default: |
376 | panic("Unsupported bpp"); |
385 | panic("Unsupported bpp"); |
377 | } |
386 | } |
378 | 387 | ||
379 | unsigned int fbsize = scan * y; |
388 | unsigned int fbsize = scan * y; |
380 | 389 | ||
381 | /* Map the framebuffer */ |
390 | /* Map the framebuffer */ |
382 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
391 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
383 | 392 | ||
384 | xres = x; |
393 | xres = x; |
385 | yres = y; |
394 | yres = y; |
386 | bitspp = bpp; |
395 | bitspp = bpp; |
387 | scanline = scan; |
396 | scanline = scan; |
388 | 397 | ||
389 | rows = y / FONT_SCANLINES; |
398 | rows = y / FONT_SCANLINES; |
390 | columns = x / COL_WIDTH; |
399 | columns = x / COL_WIDTH; |
391 | 400 | ||
392 | sysinfo_set_item_val("fb", NULL, true); |
401 | sysinfo_set_item_val("fb", NULL, true); |
393 | sysinfo_set_item_val("fb.kind", NULL, 1); |
402 | sysinfo_set_item_val("fb.kind", NULL, 1); |
394 | sysinfo_set_item_val("fb.width", NULL, xres); |
403 | sysinfo_set_item_val("fb.width", NULL, xres); |
395 | sysinfo_set_item_val("fb.height", NULL, yres); |
404 | sysinfo_set_item_val("fb.height", NULL, yres); |
396 | sysinfo_set_item_val("fb.bpp", NULL, bpp); |
405 | sysinfo_set_item_val("fb.bpp", NULL, bpp); |
397 | sysinfo_set_item_val("fb.bpp-align", NULL, align); |
406 | sysinfo_set_item_val("fb.bpp-align", NULL, align); |
398 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
407 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
399 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
408 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
- | 409 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
|
400 | 410 | ||
401 | /* Allocate double buffer */ |
411 | /* Allocate double buffer */ |
402 | int totsize = scanline * yres; |
412 | int totsize = scanline * yres; |
403 | int pages = SIZE2FRAMES(totsize); |
413 | int pages = SIZE2FRAMES(totsize); |
404 | int order; |
414 | int order; |
405 | if (pages == 1) |
415 | if (pages == 1) |
406 | order = 0; |
416 | order = 0; |
407 | else |
417 | else |
408 | order = fnzb(pages-1)+1; |
418 | order = fnzb(pages-1)+1; |
409 | 419 | ||
410 | dbbuffer = frame_alloc(order,FRAME_ATOMIC | FRAME_KA); |
420 | dbbuffer = frame_alloc(order,FRAME_ATOMIC | FRAME_KA); |
411 | if (!dbbuffer) |
421 | if (!dbbuffer) |
412 | printf("Failed to allocate scroll buffer.\n"); |
422 | printf("Failed to allocate scroll buffer.\n"); |
413 | dboffset = 0; |
423 | dboffset = 0; |
414 | 424 | ||
415 | /* Initialized blank line */ |
425 | /* Initialized blank line */ |
416 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
426 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
417 | if (!blankline) |
427 | if (!blankline) |
418 | panic("Failed to allocate blank line for framebuffer."); |
428 | panic("Failed to allocate blank line for framebuffer."); |
419 | for (y=0; y < FONT_SCANLINES; y++) |
429 | for (y=0; y < FONT_SCANLINES; y++) { |
420 | for (x=0; x < xres; x++) |
430 | for (x=0; x < xres; x++) { |
421 | (*rgb2scr)(&blankline[POINTPOS(x,y)],BGCOLOR); |
431 | (*rgb2scr)(&blankline[POINTPOS(x,y)], COLOR(BGCOLOR)); |
- | 432 | } |
|
- | 433 | } |
|
422 | 434 | ||
423 | clear_screen(); |
435 | clear_screen(); |
424 | 436 | ||
425 | /* Update size of screen to match text area */ |
437 | /* Update size of screen to match text area */ |
426 | yres = rows * FONT_SCANLINES; |
438 | yres = rows * FONT_SCANLINES; |
427 | 439 | ||
428 | draw_logo(xres - helenos_width, 0); |
440 | draw_logo(xres - helenos_width, 0); |
429 | invert_cursor(); |
441 | invert_cursor(); |
430 | 442 | ||
431 | chardev_initialize("fb", &framebuffer, &fb_ops); |
443 | chardev_initialize("fb", &framebuffer, &fb_ops); |
432 | stdout = &framebuffer; |
444 | stdout = &framebuffer; |
433 | 445 | ||
434 | } |
446 | } |
435 | 447 | ||
436 | /** @} |
448 | /** @} |
437 | */ |
449 | */ |
438 | 450 |