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