Rev 3672 | Rev 3692 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3672 | Rev 3679 | ||
---|---|---|---|
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/visuals.h> |
37 | #include <genarch/fb/fb.h> |
37 | #include <genarch/fb/fb.h> |
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
41 | #include <mm/slab.h> |
41 | #include <mm/slab.h> |
42 | #include <panic.h> |
42 | #include <panic.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
44 | #include <config.h> |
44 | #include <config.h> |
45 | #include <bitops.h> |
45 | #include <bitops.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | #include <ddi/ddi.h> |
47 | #include <ddi/ddi.h> |
48 | #include <arch/types.h> |
48 | #include <arch/types.h> |
49 | 49 | ||
50 | #include "helenos.xbm" |
50 | #include "helenos.xbm" |
51 | 51 | ||
52 | static parea_t fb_parea; /**< Physical memory area for fb. */ |
52 | static parea_t fb_parea; /**< Physical memory area for fb. */ |
53 | 53 | ||
54 | SPINLOCK_INITIALIZE(fb_lock); |
54 | SPINLOCK_INITIALIZE(fb_lock); |
55 | 55 | ||
56 | static uint8_t *fbaddress = NULL; |
56 | static uint8_t *fbaddress = NULL; |
57 | 57 | ||
58 | static uint8_t *blankline = NULL; |
58 | static uint8_t *blankline = NULL; |
59 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
59 | static uint8_t *dbbuffer = NULL; /* Buffer for fast scrolling console */ |
60 | static index_t dboffset; |
60 | static index_t dboffset; |
61 | 61 | ||
62 | static unsigned int xres = 0; |
62 | static unsigned int xres = 0; |
63 | static unsigned int yres = 0; |
63 | static unsigned int yres = 0; |
64 | static unsigned int scanline = 0; |
64 | static unsigned int scanline = 0; |
65 | static unsigned int pixelbytes = 0; |
65 | static unsigned int pixelbytes = 0; |
66 | #ifdef FB_INVERT_COLORS |
66 | #ifdef FB_INVERT_COLORS |
67 | static bool invert_colors = true; |
67 | static bool invert_colors = true; |
68 | #else |
68 | #else |
69 | static bool invert_colors = false; |
69 | static bool invert_colors = false; |
70 | #endif |
70 | #endif |
71 | 71 | ||
72 | static unsigned int position = 0; |
72 | static unsigned int position = 0; |
73 | static unsigned int columns = 0; |
73 | static unsigned int columns = 0; |
74 | static unsigned int rows = 0; |
74 | static unsigned int rows = 0; |
75 | 75 | ||
76 | #define COL_WIDTH 8 |
76 | #define COL_WIDTH 8 |
77 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
77 | #define ROW_BYTES (scanline * FONT_SCANLINES) |
78 | 78 | ||
79 | #define BGCOLOR 0x000080 |
79 | #define BGCOLOR 0x000080 |
80 | #define FGCOLOR 0xffff00 |
80 | #define FGCOLOR 0xffff00 |
81 | #define LOGOCOLOR 0x2020b0 |
81 | #define LOGOCOLOR 0x2020b0 |
82 | 82 | ||
83 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
83 | #define RED(x, bits) ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1)) |
84 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
84 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
85 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
85 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
86 | 86 | ||
87 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
87 | #define POINTPOS(x, y) ((y) * scanline + (x) * pixelbytes) |
88 | 88 | ||
89 | /***************************************************************/ |
89 | /***************************************************************/ |
90 | /* Pixel specific fuctions */ |
90 | /* Pixel specific fuctions */ |
91 | 91 | ||
92 | static void (*rgb2scr)(void *, int); |
92 | static void (*rgb2scr)(void *, int); |
93 | static int (*scr2rgb)(void *); |
93 | static int (*scr2rgb)(void *); |
94 | 94 | ||
95 | static inline int COLOR(int color) |
95 | static inline int COLOR(int color) |
96 | { |
96 | { |
97 | return invert_colors ? ~color : color; |
97 | return invert_colors ? ~color : color; |
98 | } |
98 | } |
99 | 99 | ||
100 | /* Conversion routines between different color representations */ |
100 | /* Conversion routines between different color representations */ |
101 | static void rgb_byte0888(void *dst, int rgb) |
101 | static void rgb_byte0888(void *dst, int rgb) |
102 | { |
102 | { |
103 | *((int *) dst) = rgb; |
103 | *((int *) dst) = rgb; |
104 | } |
104 | } |
105 | 105 | ||
106 | static int byte0888_rgb(void *src) |
106 | static int byte0888_rgb(void *src) |
107 | { |
107 | { |
108 | return (*((int *) src)) & 0xffffff; |
108 | return (*((int *) src)) & 0xffffff; |
109 | } |
109 | } |
110 | 110 | ||
111 | static void bgr_byte0888(void *dst, int rgb) |
111 | static void bgr_byte0888(void *dst, int rgb) |
112 | { |
112 | { |
113 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | |
113 | *((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 | |
114 | RED(rgb, 8); |
114 | RED(rgb, 8); |
115 | } |
115 | } |
116 | 116 | ||
117 | static int byte0888_bgr(void *src) |
117 | static int byte0888_bgr(void *src) |
118 | { |
118 | { |
119 | int color = *(uint32_t *)(src); |
119 | int color = *(uint32_t *)(src); |
120 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
120 | return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | |
121 | ((color >> 16) & 0xff); |
121 | ((color >> 16) & 0xff); |
122 | } |
122 | } |
123 | 123 | ||
124 | static void rgb_byte888(void *dst, int rgb) |
124 | static void rgb_byte888(void *dst, int rgb) |
125 | { |
125 | { |
126 | uint8_t *scr = (uint8_t *) dst; |
126 | uint8_t *scr = (uint8_t *) dst; |
127 | #if defined(FB_INVERT_ENDIAN) |
127 | #if defined(FB_INVERT_ENDIAN) |
128 | scr[0] = RED(rgb, 8); |
128 | scr[0] = RED(rgb, 8); |
129 | scr[1] = GREEN(rgb, 8); |
129 | scr[1] = GREEN(rgb, 8); |
130 | scr[2] = BLUE(rgb, 8); |
130 | scr[2] = BLUE(rgb, 8); |
131 | #else |
131 | #else |
132 | scr[2] = RED(rgb, 8); |
132 | scr[2] = RED(rgb, 8); |
133 | scr[1] = GREEN(rgb, 8); |
133 | scr[1] = GREEN(rgb, 8); |
134 | scr[0] = BLUE(rgb, 8); |
134 | scr[0] = BLUE(rgb, 8); |
135 | #endif |
135 | #endif |
136 | } |
136 | } |
137 | 137 | ||
138 | static int byte888_rgb(void *src) |
138 | static int byte888_rgb(void *src) |
139 | { |
139 | { |
140 | uint8_t *scr = (uint8_t *) src; |
140 | uint8_t *scr = (uint8_t *) src; |
141 | #if defined(FB_INVERT_ENDIAN) |
141 | #if defined(FB_INVERT_ENDIAN) |
142 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
142 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
143 | #else |
143 | #else |
144 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
144 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
145 | #endif |
145 | #endif |
146 | } |
146 | } |
147 | 147 | ||
148 | /** 16-bit depth (5:5:5) */ |
148 | /** 16-bit depth (5:5:5) */ |
149 | static void rgb_byte555(void *dst, int rgb) |
149 | static void rgb_byte555(void *dst, int rgb) |
150 | { |
150 | { |
151 | /* 5-bit, 5-bits, 5-bits */ |
151 | /* 5-bit, 5-bits, 5-bits */ |
152 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
152 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | |
153 | BLUE(rgb, 5); |
153 | BLUE(rgb, 5); |
154 | } |
154 | } |
155 | 155 | ||
156 | /** 16-bit depth (5:5:5) */ |
156 | /** 16-bit depth (5:5:5) */ |
157 | static int byte555_rgb(void *src) |
157 | static int byte555_rgb(void *src) |
158 | { |
158 | { |
159 | int color = *(uint16_t *)(src); |
159 | int color = *(uint16_t *)(src); |
160 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
160 | return (((color >> 10) & 0x1f) << (16 + 3)) | |
161 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
161 | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
162 | } |
162 | } |
163 | 163 | ||
164 | /** 16-bit depth (5:6:5) */ |
164 | /** 16-bit depth (5:6:5) */ |
165 | static void rgb_byte565(void *dst, int rgb) |
165 | static void rgb_byte565(void *dst, int rgb) |
166 | { |
166 | { |
167 | /* 5-bit, 6-bits, 5-bits */ |
167 | /* 5-bit, 6-bits, 5-bits */ |
168 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
168 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | |
169 | BLUE(rgb, 5); |
169 | BLUE(rgb, 5); |
170 | } |
170 | } |
171 | 171 | ||
172 | /** 16-bit depth (5:6:5) */ |
172 | /** 16-bit depth (5:6:5) */ |
173 | static int byte565_rgb(void *src) |
173 | static int byte565_rgb(void *src) |
174 | { |
174 | { |
175 | int color = *(uint16_t *)(src); |
175 | int color = *(uint16_t *)(src); |
176 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
176 | return (((color >> 11) & 0x1f) << (16 + 3)) | |
177 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
177 | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
178 | } |
178 | } |
179 | 179 | ||
180 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
180 | /** Put pixel - 8-bit depth (color palette/3:2:3) |
181 | * |
181 | * |
182 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
182 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer |
183 | * will most likely use a color palette. The color appearance |
183 | * will most likely use a color palette. The color appearance |
184 | * will be pretty random and depend on the default installed |
184 | * will be pretty random and depend on the default installed |
185 | * palette. This could be fixed by supporting custom palette |
185 | * palette. This could be fixed by supporting custom palette |
186 | * and setting it to simulate the 8-bit truecolor. |
186 | * and setting it to simulate the 8-bit truecolor. |
187 | */ |
187 | */ |
188 | static void rgb_byte8(void *dst, int rgb) |
188 | static void rgb_byte8(void *dst, int rgb) |
189 | { |
189 | { |
190 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
190 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | |
191 | BLUE(rgb, 3); |
191 | BLUE(rgb, 3); |
192 | } |
192 | } |
193 | 193 | ||
194 | static void sb1500rgb_byte8(void *dst, int rgb) |
- | |
195 | { |
- | |
196 | if (RED(rgb, 1) && GREEN(rgb, 1) && BLUE(rgb, 1)) |
- | |
197 | *((uint8_t *) dst) = 255; |
- | |
198 | else if (RED(rgb, 1) && GREEN(rgb, 1)) |
- | |
199 | *((uint8_t *) dst) = 150; |
- | |
200 | else if (GREEN(rgb, 1) && BLUE(rgb, 1)) |
- | |
201 | *((uint8_t *) dst) = 47; |
- | |
202 | else if (RED(rgb, 1) && BLUE(rgb, 1)) |
- | |
203 | *((uint8_t *) dst) = 48; |
- | |
204 | else if (RED(rgb, 1)) |
- | |
205 | *((uint8_t *) dst) = 32; |
- | |
206 | else if (GREEN(rgb, 1)) |
- | |
207 | *((uint8_t *) dst) = 47; |
- | |
208 | else if (BLUE(rgb, 1)) |
- | |
209 | *((uint8_t *) dst) = 2; |
- | |
210 | else |
- | |
211 | *((uint8_t *) dst) = 1; |
- | |
212 | } |
- | |
213 | - | ||
214 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
194 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
215 | * |
195 | * |
216 | * See the comment for rgb_byte(). |
196 | * See the comment for rgb_byte(). |
217 | */ |
197 | */ |
218 | static int byte8_rgb(void *src) |
198 | static int byte8_rgb(void *src) |
219 | { |
199 | { |
220 | int color = *(uint8_t *)src; |
200 | int color = *(uint8_t *)src; |
221 | return (((color >> 5) & 0x7) << (16 + 5)) | |
201 | return (((color >> 5) & 0x7) << (16 + 5)) | |
222 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
202 | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
223 | } |
203 | } |
224 | 204 | ||
225 | static void putpixel(unsigned int x, unsigned int y, int color) |
205 | static void putpixel(unsigned int x, unsigned int y, int color) |
226 | { |
206 | { |
227 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
207 | (*rgb2scr)(&fbaddress[POINTPOS(x, y)], COLOR(color)); |
228 | 208 | ||
229 | if (dbbuffer) { |
209 | if (dbbuffer) { |
230 | int dline = (y + dboffset) % yres; |
210 | int dline = (y + dboffset) % yres; |
231 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
211 | (*rgb2scr)(&dbbuffer[POINTPOS(x, dline)], COLOR(color)); |
232 | } |
212 | } |
233 | } |
213 | } |
234 | 214 | ||
235 | /** Get pixel from viewport */ |
215 | /** Get pixel from viewport */ |
236 | static int getpixel(unsigned int x, unsigned int y) |
216 | static int getpixel(unsigned int x, unsigned int y) |
237 | { |
217 | { |
238 | if (dbbuffer) { |
218 | if (dbbuffer) { |
239 | int dline = (y + dboffset) % yres; |
219 | int dline = (y + dboffset) % yres; |
240 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
220 | return COLOR((*scr2rgb)(&dbbuffer[POINTPOS(x, dline)])); |
241 | } |
221 | } |
242 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
222 | return COLOR((*scr2rgb)(&fbaddress[POINTPOS(x, y)])); |
243 | } |
223 | } |
244 | 224 | ||
245 | 225 | ||
246 | /** Fill screen with background color */ |
226 | /** Fill screen with background color */ |
247 | static void clear_screen(void) |
227 | static void clear_screen(void) |
248 | { |
228 | { |
249 | unsigned int y; |
229 | unsigned int y; |
250 | 230 | ||
251 | for (y = 0; y < yres; y++) { |
231 | for (y = 0; y < yres; y++) { |
252 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
232 | memcpy(&fbaddress[scanline * y], blankline, xres * pixelbytes); |
253 | if (dbbuffer) |
233 | if (dbbuffer) |
254 | memcpy(&dbbuffer[scanline * y], blankline, |
234 | memcpy(&dbbuffer[scanline * y], blankline, |
255 | xres * pixelbytes); |
235 | xres * pixelbytes); |
256 | } |
236 | } |
257 | } |
237 | } |
258 | 238 | ||
259 | 239 | ||
260 | /** Scroll screen one row up */ |
240 | /** Scroll screen one row up */ |
261 | static void scroll_screen(void) |
241 | static void scroll_screen(void) |
262 | { |
242 | { |
263 | if (dbbuffer) { |
243 | if (dbbuffer) { |
264 | count_t first; |
244 | count_t first; |
265 | 245 | ||
266 | /* Clear the last row */ |
246 | /* Clear the last row */ |
267 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
247 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
268 | 248 | ||
269 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
249 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
270 | first = yres - dboffset; |
250 | first = yres - dboffset; |
271 | 251 | ||
272 | /* Move all rows one row up */ |
252 | /* Move all rows one row up */ |
273 | if (xres * pixelbytes == scanline) { |
253 | if (xres * pixelbytes == scanline) { |
274 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
254 | memcpy(fbaddress, &dbbuffer[dboffset * scanline], |
275 | first * scanline); |
255 | first * scanline); |
276 | memcpy(&fbaddress[first * scanline], dbbuffer, |
256 | memcpy(&fbaddress[first * scanline], dbbuffer, |
277 | dboffset * scanline); |
257 | dboffset * scanline); |
278 | } else { |
258 | } else { |
279 | /* |
259 | /* |
280 | * When the scanline is bigger than number of bytes |
260 | * When the scanline is bigger than number of bytes |
281 | * in the X-resolution, chances are that the |
261 | * in the X-resolution, chances are that the |
282 | * frame buffer memory past the X-resolution is special |
262 | * frame buffer memory past the X-resolution is special |
283 | * in some way. For example, the SUNW,ffb framebuffer |
263 | * in some way. For example, the SUNW,ffb framebuffer |
284 | * wraps this area around the beginning of the same |
264 | * wraps this area around the beginning of the same |
285 | * line. To avoid troubles, copy only memory as |
265 | * line. To avoid troubles, copy only memory as |
286 | * specified by the resolution. |
266 | * specified by the resolution. |
287 | */ |
267 | */ |
288 | unsigned int i; |
268 | unsigned int i; |
289 | 269 | ||
290 | for (i = 0; i < first; i++) |
270 | for (i = 0; i < first; i++) |
291 | memcpy(&fbaddress[i * scanline], |
271 | memcpy(&fbaddress[i * scanline], |
292 | &dbbuffer[(dboffset + i) * scanline], |
272 | &dbbuffer[(dboffset + i) * scanline], |
293 | xres * pixelbytes); |
273 | xres * pixelbytes); |
294 | for (i = 0; i < dboffset; i++) |
274 | for (i = 0; i < dboffset; i++) |
295 | memcpy(&fbaddress[(first + i) * scanline], |
275 | memcpy(&fbaddress[(first + i) * scanline], |
296 | &dbbuffer[i * scanline], xres * pixelbytes); |
276 | &dbbuffer[i * scanline], xres * pixelbytes); |
297 | } |
277 | } |
298 | } else { |
278 | } else { |
299 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
279 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
300 | 280 | ||
301 | if (xres * pixelbytes == scanline) { |
281 | if (xres * pixelbytes == scanline) { |
302 | /* Move all rows one row up */ |
282 | /* Move all rows one row up */ |
303 | memcpy((void *) fbaddress, |
283 | memcpy((void *) fbaddress, |
304 | (void *) &fbaddress[ROW_BYTES], |
284 | (void *) &fbaddress[ROW_BYTES], |
305 | scanline * yres - ROW_BYTES); |
285 | scanline * yres - ROW_BYTES); |
306 | /* Clear the last row */ |
286 | /* Clear the last row */ |
307 | memcpy((void *) lastline, (void *) blankline, |
287 | memcpy((void *) lastline, (void *) blankline, |
308 | ROW_BYTES); |
288 | ROW_BYTES); |
309 | } else { |
289 | } else { |
310 | /* |
290 | /* |
311 | * See the comment in the dbbuffer case. |
291 | * See the comment in the dbbuffer case. |
312 | */ |
292 | */ |
313 | unsigned int i; |
293 | unsigned int i; |
314 | 294 | ||
315 | /* Move all rows one row up */ |
295 | /* Move all rows one row up */ |
316 | for (i = 0; i < yres - FONT_SCANLINES; i++) |
296 | for (i = 0; i < yres - FONT_SCANLINES; i++) |
317 | memcpy(&fbaddress[i * scanline], |
297 | memcpy(&fbaddress[i * scanline], |
318 | &fbaddress[(i + FONT_SCANLINES) * scanline], |
298 | &fbaddress[(i + FONT_SCANLINES) * scanline], |
319 | xres * pixelbytes); |
299 | xres * pixelbytes); |
320 | /* Clear the last row */ |
300 | /* Clear the last row */ |
321 | for (i = 0; i < FONT_SCANLINES; i++) |
301 | for (i = 0; i < FONT_SCANLINES; i++) |
322 | memcpy(&lastline[i * scanline], |
302 | memcpy(&lastline[i * scanline], |
323 | &blankline[i * scanline], |
303 | &blankline[i * scanline], |
324 | xres * pixelbytes); |
304 | xres * pixelbytes); |
325 | } |
305 | } |
326 | } |
306 | } |
327 | } |
307 | } |
328 | 308 | ||
329 | 309 | ||
330 | static void invert_pixel(unsigned int x, unsigned int y) |
310 | static void invert_pixel(unsigned int x, unsigned int y) |
331 | { |
311 | { |
332 | putpixel(x, y, ~getpixel(x, y)); |
312 | putpixel(x, y, ~getpixel(x, y)); |
333 | } |
313 | } |
334 | 314 | ||
335 | 315 | ||
336 | /** Draw one line of glyph at a given position */ |
316 | /** Draw one line of glyph at a given position */ |
337 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
317 | static void draw_glyph_line(unsigned int glline, unsigned int x, unsigned int y) |
338 | { |
318 | { |
339 | unsigned int i; |
319 | unsigned int i; |
340 | 320 | ||
341 | for (i = 0; i < 8; i++) |
321 | for (i = 0; i < 8; i++) |
342 | if (glline & (1 << (7 - i))) { |
322 | if (glline & (1 << (7 - i))) { |
343 | putpixel(x + i, y, FGCOLOR); |
323 | putpixel(x + i, y, FGCOLOR); |
344 | } else |
324 | } else |
345 | putpixel(x + i, y, BGCOLOR); |
325 | putpixel(x + i, y, BGCOLOR); |
346 | } |
326 | } |
347 | 327 | ||
348 | /***************************************************************/ |
328 | /***************************************************************/ |
349 | /* Character-console functions */ |
329 | /* Character-console functions */ |
350 | 330 | ||
351 | /** Draw character at given position */ |
331 | /** Draw character at given position */ |
352 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
332 | static void draw_glyph(uint8_t glyph, unsigned int col, unsigned int row) |
353 | { |
333 | { |
354 | unsigned int y; |
334 | unsigned int y; |
355 | 335 | ||
356 | for (y = 0; y < FONT_SCANLINES; y++) |
336 | for (y = 0; y < FONT_SCANLINES; y++) |
357 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
337 | draw_glyph_line(fb_font[glyph * FONT_SCANLINES + y], |
358 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
338 | col * COL_WIDTH, row * FONT_SCANLINES + y); |
359 | } |
339 | } |
360 | 340 | ||
361 | /** Invert character at given position */ |
341 | /** Invert character at given position */ |
362 | static void invert_char(unsigned int col, unsigned int row) |
342 | static void invert_char(unsigned int col, unsigned int row) |
363 | { |
343 | { |
364 | unsigned int x; |
344 | unsigned int x; |
365 | unsigned int y; |
345 | unsigned int y; |
366 | 346 | ||
367 | for (x = 0; x < COL_WIDTH; x++) |
347 | for (x = 0; x < COL_WIDTH; x++) |
368 | for (y = 0; y < FONT_SCANLINES; y++) |
348 | for (y = 0; y < FONT_SCANLINES; y++) |
369 | invert_pixel(col * COL_WIDTH + x, |
349 | invert_pixel(col * COL_WIDTH + x, |
370 | row * FONT_SCANLINES + y); |
350 | row * FONT_SCANLINES + y); |
371 | } |
351 | } |
372 | 352 | ||
373 | /** Draw character at default position */ |
353 | /** Draw character at default position */ |
374 | static void draw_char(char chr) |
354 | static void draw_char(char chr) |
375 | { |
355 | { |
376 | draw_glyph(chr, position % columns, position / columns); |
356 | draw_glyph(chr, position % columns, position / columns); |
377 | } |
357 | } |
378 | 358 | ||
379 | static void draw_logo(unsigned int startx, unsigned int starty) |
359 | static void draw_logo(unsigned int startx, unsigned int starty) |
380 | { |
360 | { |
381 | unsigned int x; |
361 | unsigned int x; |
382 | unsigned int y; |
362 | unsigned int y; |
383 | unsigned int byte; |
363 | unsigned int byte; |
384 | unsigned int rowbytes; |
364 | unsigned int rowbytes; |
385 | 365 | ||
386 | rowbytes = (helenos_width - 1) / 8 + 1; |
366 | rowbytes = (helenos_width - 1) / 8 + 1; |
387 | 367 | ||
388 | for (y = 0; y < helenos_height; y++) |
368 | for (y = 0; y < helenos_height; y++) |
389 | for (x = 0; x < helenos_width; x++) { |
369 | for (x = 0; x < helenos_width; x++) { |
390 | byte = helenos_bits[rowbytes * y + x / 8]; |
370 | byte = helenos_bits[rowbytes * y + x / 8]; |
391 | byte >>= x % 8; |
371 | byte >>= x % 8; |
392 | if (byte & 1) |
372 | if (byte & 1) |
393 | putpixel(startx + x, starty + y, |
373 | putpixel(startx + x, starty + y, |
394 | COLOR(LOGOCOLOR)); |
374 | COLOR(LOGOCOLOR)); |
395 | } |
375 | } |
396 | } |
376 | } |
397 | 377 | ||
398 | /***************************************************************/ |
378 | /***************************************************************/ |
399 | /* Stdout specific functions */ |
379 | /* Stdout specific functions */ |
400 | 380 | ||
401 | static void invert_cursor(void) |
381 | static void invert_cursor(void) |
402 | { |
382 | { |
403 | invert_char(position % columns, position / columns); |
383 | invert_char(position % columns, position / columns); |
404 | } |
384 | } |
405 | 385 | ||
406 | /** Print character to screen |
386 | /** Print character to screen |
407 | * |
387 | * |
408 | * Emulate basic terminal commands |
388 | * Emulate basic terminal commands |
409 | */ |
389 | */ |
410 | static void fb_putchar(chardev_t *dev, char ch) |
390 | static void fb_putchar(chardev_t *dev, char ch) |
411 | { |
391 | { |
412 | spinlock_lock(&fb_lock); |
392 | spinlock_lock(&fb_lock); |
413 | 393 | ||
414 | switch (ch) { |
394 | switch (ch) { |
415 | case '\n': |
395 | case '\n': |
416 | invert_cursor(); |
396 | invert_cursor(); |
417 | position += columns; |
397 | position += columns; |
418 | position -= position % columns; |
398 | position -= position % columns; |
419 | break; |
399 | break; |
420 | case '\r': |
400 | case '\r': |
421 | invert_cursor(); |
401 | invert_cursor(); |
422 | position -= position % columns; |
402 | position -= position % columns; |
423 | break; |
403 | break; |
424 | case '\b': |
404 | case '\b': |
425 | invert_cursor(); |
405 | invert_cursor(); |
426 | if (position % columns) |
406 | if (position % columns) |
427 | position--; |
407 | position--; |
428 | break; |
408 | break; |
429 | case '\t': |
409 | case '\t': |
430 | invert_cursor(); |
410 | invert_cursor(); |
431 | do { |
411 | do { |
432 | draw_char(' '); |
412 | draw_char(' '); |
433 | position++; |
413 | position++; |
434 | } while ((position % 8) && position < columns * rows); |
414 | } while ((position % 8) && position < columns * rows); |
435 | break; |
415 | break; |
436 | default: |
416 | default: |
437 | draw_char(ch); |
417 | draw_char(ch); |
438 | position++; |
418 | position++; |
439 | } |
419 | } |
440 | 420 | ||
441 | if (position >= columns * rows) { |
421 | if (position >= columns * rows) { |
442 | position -= columns; |
422 | position -= columns; |
443 | scroll_screen(); |
423 | scroll_screen(); |
444 | } |
424 | } |
445 | 425 | ||
446 | invert_cursor(); |
426 | invert_cursor(); |
447 | 427 | ||
448 | spinlock_unlock(&fb_lock); |
428 | spinlock_unlock(&fb_lock); |
449 | } |
429 | } |
450 | 430 | ||
451 | static chardev_t framebuffer; |
431 | static chardev_t framebuffer; |
452 | static chardev_operations_t fb_ops = { |
432 | static chardev_operations_t fb_ops = { |
453 | .write = fb_putchar, |
433 | .write = fb_putchar, |
454 | }; |
434 | }; |
455 | 435 | ||
456 | 436 | ||
457 | /** Initialize framebuffer as a chardev output device |
437 | /** Initialize framebuffer as a chardev output device |
458 | * |
438 | * |
459 | * @param props Properties of the framebuffer device. |
439 | * @param props Properties of the framebuffer device. |
460 | */ |
440 | */ |
461 | void fb_init(fb_properties_t *props) |
441 | void fb_init(fb_properties_t *props) |
462 | { |
442 | { |
463 | switch (props->visual) { |
443 | switch (props->visual) { |
464 | case VISUAL_INDIRECT_8: |
444 | case VISUAL_INDIRECT_8: |
465 | rgb2scr = rgb_byte8; |
445 | rgb2scr = rgb_byte8; |
466 | scr2rgb = byte8_rgb; |
446 | scr2rgb = byte8_rgb; |
467 | pixelbytes = 1; |
447 | pixelbytes = 1; |
468 | break; |
448 | break; |
469 | case VISUAL_SB1500_PALETTE: |
- | |
470 | rgb2scr = sb1500rgb_byte8; |
- | |
471 | scr2rgb = byte8_rgb; |
- | |
472 | pixelbytes = 1; |
- | |
473 | break; |
- | |
474 | case VISUAL_RGB_5_5_5: |
449 | case VISUAL_RGB_5_5_5: |
475 | rgb2scr = rgb_byte555; |
450 | rgb2scr = rgb_byte555; |
476 | scr2rgb = byte555_rgb; |
451 | scr2rgb = byte555_rgb; |
477 | pixelbytes = 2; |
452 | pixelbytes = 2; |
478 | break; |
453 | break; |
479 | case VISUAL_RGB_5_6_5: |
454 | case VISUAL_RGB_5_6_5: |
480 | rgb2scr = rgb_byte565; |
455 | rgb2scr = rgb_byte565; |
481 | scr2rgb = byte565_rgb; |
456 | scr2rgb = byte565_rgb; |
482 | pixelbytes = 2; |
457 | pixelbytes = 2; |
483 | break; |
458 | break; |
484 | case VISUAL_RGB_8_8_8: |
459 | case VISUAL_RGB_8_8_8: |
485 | rgb2scr = rgb_byte888; |
460 | rgb2scr = rgb_byte888; |
486 | scr2rgb = byte888_rgb; |
461 | scr2rgb = byte888_rgb; |
487 | pixelbytes = 3; |
462 | pixelbytes = 3; |
488 | break; |
463 | break; |
489 | case VISUAL_RGB_8_8_8_0: |
464 | case VISUAL_RGB_8_8_8_0: |
490 | rgb2scr = rgb_byte888; |
465 | rgb2scr = rgb_byte888; |
491 | scr2rgb = byte888_rgb; |
466 | scr2rgb = byte888_rgb; |
492 | pixelbytes = 4; |
467 | pixelbytes = 4; |
493 | break; |
468 | break; |
494 | case VISUAL_RGB_0_8_8_8: |
469 | case VISUAL_RGB_0_8_8_8: |
495 | rgb2scr = rgb_byte0888; |
470 | rgb2scr = rgb_byte0888; |
496 | scr2rgb = byte0888_rgb; |
471 | scr2rgb = byte0888_rgb; |
497 | pixelbytes = 4; |
472 | pixelbytes = 4; |
498 | break; |
473 | break; |
499 | case VISUAL_BGR_0_8_8_8: |
474 | case VISUAL_BGR_0_8_8_8: |
500 | rgb2scr = bgr_byte0888; |
475 | rgb2scr = bgr_byte0888; |
501 | scr2rgb = byte0888_bgr; |
476 | scr2rgb = byte0888_bgr; |
502 | pixelbytes = 4; |
477 | pixelbytes = 4; |
503 | break; |
478 | break; |
504 | default: |
479 | default: |
505 | panic("Unsupported visual.\n"); |
480 | panic("Unsupported visual.\n"); |
506 | } |
481 | } |
507 | 482 | ||
508 | unsigned int fbsize = props->scan * props->y + props->offset; |
483 | unsigned int fbsize = props->scan * props->y; |
509 | 484 | ||
510 | /* Map the framebuffer */ |
485 | /* Map the framebuffer */ |
511 | fbaddress = (uint8_t *) hw_map((uintptr_t) props->addr, fbsize); |
486 | fbaddress = (uint8_t *) hw_map((uintptr_t) props->addr + props->offset, |
- | 487 | fbsize); |
|
512 | fbaddress += props->offset; |
488 | fbaddress += props->offset; |
513 | 489 | ||
514 | xres = props->x; |
490 | xres = props->x; |
515 | yres = props->y; |
491 | yres = props->y; |
516 | scanline = props->scan; |
492 | scanline = props->scan; |
517 | 493 | ||
518 | rows = props->y / FONT_SCANLINES; |
494 | rows = props->y / FONT_SCANLINES; |
519 | columns = props->x / COL_WIDTH; |
495 | columns = props->x / COL_WIDTH; |
520 | 496 | ||
521 | fb_parea.pbase = (uintptr_t) props->addr; |
497 | fb_parea.pbase = (uintptr_t) props->addr; |
522 | fb_parea.vbase = (uintptr_t) fbaddress; |
498 | fb_parea.vbase = (uintptr_t) fbaddress; |
523 | fb_parea.frames = SIZE2FRAMES(fbsize); |
499 | fb_parea.frames = SIZE2FRAMES(fbsize); |
524 | fb_parea.cacheable = false; |
500 | fb_parea.cacheable = false; |
525 | ddi_parea_register(&fb_parea); |
501 | ddi_parea_register(&fb_parea); |
526 | 502 | ||
527 | sysinfo_set_item_val("fb", NULL, true); |
503 | sysinfo_set_item_val("fb", NULL, true); |
528 | sysinfo_set_item_val("fb.kind", NULL, 1); |
504 | sysinfo_set_item_val("fb.kind", NULL, 1); |
529 | sysinfo_set_item_val("fb.width", NULL, xres); |
505 | sysinfo_set_item_val("fb.width", NULL, xres); |
530 | sysinfo_set_item_val("fb.height", NULL, yres); |
506 | sysinfo_set_item_val("fb.height", NULL, yres); |
531 | sysinfo_set_item_val("fb.scanline", NULL, props->scan); |
507 | sysinfo_set_item_val("fb.scanline", NULL, props->scan); |
532 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
508 | sysinfo_set_item_val("fb.visual", NULL, props->visual); |
533 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
509 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr); |
- | 510 | sysinfo_set_item_val("fb.offset", NULL, props->offset); |
|
534 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
511 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
535 | 512 | ||
536 | /* Allocate double buffer */ |
513 | /* Allocate double buffer */ |
537 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
514 | unsigned int order = fnzb(SIZE2FRAMES(fbsize) - 1) + 1; |
538 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
515 | dbbuffer = (uint8_t *) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
539 | if (!dbbuffer) |
516 | if (!dbbuffer) |
540 | printf("Failed to allocate scroll buffer.\n"); |
517 | printf("Failed to allocate scroll buffer.\n"); |
541 | dboffset = 0; |
518 | dboffset = 0; |
542 | 519 | ||
543 | /* Initialized blank line */ |
520 | /* Initialized blank line */ |
544 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
521 | blankline = (uint8_t *) malloc(ROW_BYTES, FRAME_ATOMIC); |
545 | if (!blankline) |
522 | if (!blankline) |
546 | panic("Failed to allocate blank line for framebuffer."); |
523 | panic("Failed to allocate blank line for framebuffer."); |
547 | unsigned int x, y; |
524 | unsigned int x, y; |
548 | for (y = 0; y < FONT_SCANLINES; y++) |
525 | for (y = 0; y < FONT_SCANLINES; y++) |
549 | for (x = 0; x < xres; x++) |
526 | for (x = 0; x < xres; x++) |
550 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
527 | (*rgb2scr)(&blankline[POINTPOS(x, y)], COLOR(BGCOLOR)); |
551 | 528 | ||
552 | clear_screen(); |
529 | clear_screen(); |
553 | 530 | ||
554 | /* Update size of screen to match text area */ |
531 | /* Update size of screen to match text area */ |
555 | yres = rows * FONT_SCANLINES; |
532 | yres = rows * FONT_SCANLINES; |
556 | 533 | ||
557 | draw_logo(xres - helenos_width, 0); |
534 | draw_logo(xres - helenos_width, 0); |
558 | invert_cursor(); |
535 | invert_cursor(); |
559 | 536 | ||
560 | chardev_initialize("fb", &framebuffer, &fb_ops); |
537 | chardev_initialize("fb", &framebuffer, &fb_ops); |
561 | stdout = &framebuffer; |
538 | stdout = &framebuffer; |
562 | } |
539 | } |
563 | 540 | ||
564 | /** @} |
541 | /** @} |
565 | */ |
542 | */ |
566 | 543 |