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