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