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