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