Rev 1515 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1515 | Rev 1547 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Vana |
2 | * Copyright (C) 2006 Jakub Vana |
3 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * Copyright (C) 2006 Ondrej Palkovsky |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include <stdlib.h> |
30 | #include <stdlib.h> |
31 | #include <unistd.h> |
31 | #include <unistd.h> |
32 | #include <string.h> |
32 | #include <string.h> |
33 | #include <ddi.h> |
33 | #include <ddi.h> |
34 | #include <sysinfo.h> |
34 | #include <sysinfo.h> |
35 | #include <align.h> |
35 | #include <align.h> |
36 | #include <as.h> |
36 | #include <as.h> |
37 | #include <ipc/fb.h> |
37 | #include <ipc/fb.h> |
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/ns.h> |
39 | #include <ipc/ns.h> |
40 | #include <ipc/services.h> |
40 | #include <ipc/services.h> |
41 | #include <kernel/errno.h> |
41 | #include <kernel/errno.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | 43 | ||
44 | #include "font-8x16.h" |
44 | #include "font-8x16.h" |
45 | #include "helenos.xbm" |
45 | #include "helenos.xbm" |
46 | #include "fb.h" |
46 | #include "fb.h" |
47 | #include "main.h" |
47 | #include "main.h" |
48 | #include "../console/screenbuffer.h" |
48 | #include "../console/screenbuffer.h" |
- | 49 | #include "ppm.h" |
|
49 | 50 | ||
50 | #define DEFAULT_BGCOLOR 0x000080 |
51 | #define DEFAULT_BGCOLOR 0x000080 |
51 | #define DEFAULT_FGCOLOR 0xffff00 |
52 | #define DEFAULT_FGCOLOR 0xffff00 |
52 | 53 | ||
53 | /***************************************************************/ |
54 | /***************************************************************/ |
54 | /* Pixel specific fuctions */ |
55 | /* Pixel specific fuctions */ |
55 | 56 | ||
56 | typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color); |
57 | typedef void (*putpixel_fn_t)(unsigned int x, unsigned int y, int color); |
57 | typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y); |
58 | typedef int (*getpixel_fn_t)(unsigned int x, unsigned int y); |
58 | 59 | ||
59 | struct { |
60 | struct { |
60 | __u8 *fbaddress ; |
61 | __u8 *fbaddress ; |
61 | 62 | ||
62 | unsigned int xres ; |
63 | unsigned int xres ; |
63 | unsigned int yres ; |
64 | unsigned int yres ; |
64 | unsigned int scanline ; |
65 | unsigned int scanline ; |
65 | unsigned int pixelbytes ; |
66 | unsigned int pixelbytes ; |
66 | 67 | ||
67 | putpixel_fn_t putpixel; |
68 | putpixel_fn_t putpixel; |
68 | getpixel_fn_t getpixel; |
69 | getpixel_fn_t getpixel; |
69 | } screen; |
70 | } screen; |
70 | 71 | ||
71 | typedef struct { |
72 | typedef struct { |
72 | int initialized; |
73 | int initialized; |
73 | unsigned int x, y; |
74 | unsigned int x, y; |
74 | unsigned int width, height; |
75 | unsigned int width, height; |
75 | 76 | ||
76 | /* Text support in window */ |
77 | /* Text support in window */ |
77 | unsigned int rows, cols; |
78 | unsigned int rows, cols; |
78 | /* Style for text printing */ |
79 | /* Style for text printing */ |
79 | style_t style; |
80 | style_t style; |
80 | /* Auto-cursor position */ |
81 | /* Auto-cursor position */ |
81 | int cursor_active, cur_col, cur_row; |
82 | int cursor_active, cur_col, cur_row; |
82 | int cursor_shown; |
83 | int cursor_shown; |
83 | } viewport_t; |
84 | } viewport_t; |
84 | 85 | ||
85 | #define MAX_VIEWPORTS 128 |
86 | #define MAX_VIEWPORTS 128 |
86 | static viewport_t viewports[128]; |
87 | static viewport_t viewports[128]; |
87 | 88 | ||
88 | /* Allow only 1 connection */ |
89 | /* Allow only 1 connection */ |
89 | static int client_connected = 0; |
90 | static int client_connected = 0; |
90 | 91 | ||
91 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
92 | #define RED(x, bits) ((x >> (16 + 8 - bits)) & ((1 << bits) - 1)) |
92 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
93 | #define GREEN(x, bits) ((x >> (8 + 8 - bits)) & ((1 << bits) - 1)) |
93 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
94 | #define BLUE(x, bits) ((x >> (8 - bits)) & ((1 << bits) - 1)) |
94 | 95 | ||
95 | #define COL_WIDTH 8 |
96 | #define COL_WIDTH 8 |
96 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
97 | #define ROW_BYTES (screen.scanline * FONT_SCANLINES) |
97 | 98 | ||
98 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
99 | #define POINTPOS(x, y) ((y) * screen.scanline + (x) * screen.pixelbytes) |
99 | 100 | ||
100 | /** Put pixel - 24-bit depth, 1 free byte */ |
101 | /** Put pixel - 24-bit depth, 1 free byte */ |
101 | static void putpixel_4byte(unsigned int x, unsigned int y, int color) |
102 | static void putpixel_4byte(unsigned int x, unsigned int y, int color) |
102 | { |
103 | { |
103 | *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color; |
104 | *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) = color; |
104 | } |
105 | } |
105 | 106 | ||
106 | /** Return pixel color - 24-bit depth, 1 free byte */ |
107 | /** Return pixel color - 24-bit depth, 1 free byte */ |
107 | static int getpixel_4byte(unsigned int x, unsigned int y) |
108 | static int getpixel_4byte(unsigned int x, unsigned int y) |
108 | { |
109 | { |
109 | return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff; |
110 | return *((__u32 *)(screen.fbaddress + POINTPOS(x, y))) & 0xffffff; |
110 | } |
111 | } |
111 | 112 | ||
112 | /** Put pixel - 24-bit depth */ |
113 | /** Put pixel - 24-bit depth */ |
113 | static void putpixel_3byte(unsigned int x, unsigned int y, int color) |
114 | static void putpixel_3byte(unsigned int x, unsigned int y, int color) |
114 | { |
115 | { |
115 | unsigned int startbyte = POINTPOS(x, y); |
116 | unsigned int startbyte = POINTPOS(x, y); |
116 | 117 | ||
117 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
118 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
118 | screen.fbaddress[startbyte] = RED(color, 8); |
119 | screen.fbaddress[startbyte] = RED(color, 8); |
119 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
120 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
120 | screen.fbaddress[startbyte + 2] = BLUE(color, 8); |
121 | screen.fbaddress[startbyte + 2] = BLUE(color, 8); |
121 | #else |
122 | #else |
122 | screen.fbaddress[startbyte + 2] = RED(color, 8); |
123 | screen.fbaddress[startbyte + 2] = RED(color, 8); |
123 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
124 | screen.fbaddress[startbyte + 1] = GREEN(color, 8); |
124 | screen.fbaddress[startbyte + 0] = BLUE(color, 8); |
125 | screen.fbaddress[startbyte + 0] = BLUE(color, 8); |
125 | #endif |
126 | #endif |
126 | 127 | ||
127 | } |
128 | } |
128 | 129 | ||
129 | /** Return pixel color - 24-bit depth */ |
130 | /** Return pixel color - 24-bit depth */ |
130 | static int getpixel_3byte(unsigned int x, unsigned int y) |
131 | static int getpixel_3byte(unsigned int x, unsigned int y) |
131 | { |
132 | { |
132 | unsigned int startbyte = POINTPOS(x, y); |
133 | unsigned int startbyte = POINTPOS(x, y); |
133 | 134 | ||
134 | 135 | ||
135 | 136 | ||
136 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
137 | #if (defined(BIG_ENDIAN) || defined(FB_BIG_ENDIAN)) |
137 | return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2]; |
138 | return screen.fbaddress[startbyte] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 2]; |
138 | #else |
139 | #else |
139 | return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0]; |
140 | return screen.fbaddress[startbyte + 2] << 16 | screen.fbaddress[startbyte + 1] << 8 | screen.fbaddress[startbyte + 0]; |
140 | #endif |
141 | #endif |
141 | 142 | ||
142 | 143 | ||
143 | } |
144 | } |
144 | 145 | ||
145 | /** Put pixel - 16-bit depth (5:6:5) */ |
146 | /** Put pixel - 16-bit depth (5:6:5) */ |
146 | static void putpixel_2byte(unsigned int x, unsigned int y, int color) |
147 | static void putpixel_2byte(unsigned int x, unsigned int y, int color) |
147 | { |
148 | { |
148 | /* 5-bit, 6-bits, 5-bits */ |
149 | /* 5-bit, 6-bits, 5-bits */ |
149 | *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5); |
150 | *((__u16 *)(screen.fbaddress + POINTPOS(x, y))) = RED(color, 5) << 11 | GREEN(color, 6) << 5 | BLUE(color, 5); |
150 | } |
151 | } |
151 | 152 | ||
152 | /** Return pixel color - 16-bit depth (5:6:5) */ |
153 | /** Return pixel color - 16-bit depth (5:6:5) */ |
153 | static int getpixel_2byte(unsigned int x, unsigned int y) |
154 | static int getpixel_2byte(unsigned int x, unsigned int y) |
154 | { |
155 | { |
155 | int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y))); |
156 | int color = *((__u16 *)(screen.fbaddress + POINTPOS(x, y))); |
156 | 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); |
157 | } |
158 | } |
158 | 159 | ||
159 | /** Put pixel - 8-bit depth (3:2:3) */ |
160 | /** Put pixel - 8-bit depth (3:2:3) */ |
160 | static void putpixel_1byte(unsigned int x, unsigned int y, int color) |
161 | static void putpixel_1byte(unsigned int x, unsigned int y, int color) |
161 | { |
162 | { |
162 | screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3); |
163 | screen.fbaddress[POINTPOS(x, y)] = RED(color, 3) << 5 | GREEN(color, 2) << 3 | BLUE(color, 3); |
163 | } |
164 | } |
164 | 165 | ||
165 | /** Return pixel color - 8-bit depth (3:2:3) */ |
166 | /** Return pixel color - 8-bit depth (3:2:3) */ |
166 | static int getpixel_1byte(unsigned int x, unsigned int y) |
167 | static int getpixel_1byte(unsigned int x, unsigned int y) |
167 | { |
168 | { |
168 | int color = screen.fbaddress[POINTPOS(x, y)]; |
169 | int color = screen.fbaddress[POINTPOS(x, y)]; |
169 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
170 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
170 | } |
171 | } |
171 | 172 | ||
172 | /** Put pixel into viewport |
173 | /** Put pixel into viewport |
173 | * |
174 | * |
174 | * @param vp Viewport identification |
175 | * @param vp Viewport identification |
175 | * @param x X coord relative to viewport |
176 | * @param x X coord relative to viewport |
176 | * @param y Y coord relative to viewport |
177 | * @param y Y coord relative to viewport |
177 | * @param color RGB color |
178 | * @param color RGB color |
178 | */ |
179 | */ |
179 | static void putpixel(int vp, unsigned int x, unsigned int y, int color) |
180 | static void putpixel(int vp, unsigned int x, unsigned int y, int color) |
180 | { |
181 | { |
181 | screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color); |
182 | screen.putpixel(viewports[vp].x + x, viewports[vp].y + y, color); |
182 | } |
183 | } |
183 | /** Get pixel from viewport */ |
184 | /** Get pixel from viewport */ |
184 | static int getpixel(int vp, unsigned int x, unsigned int y) |
185 | static int getpixel(int vp, unsigned int x, unsigned int y) |
185 | { |
186 | { |
186 | return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y); |
187 | return screen.getpixel(viewports[vp].x + x, viewports[vp].y + y); |
187 | } |
188 | } |
188 | 189 | ||
189 | /** Fill line with color BGCOLOR */ |
190 | /** Fill line with color BGCOLOR */ |
190 | static void clear_line(int vp, unsigned int y) |
191 | static void clear_line(int vp, unsigned int y) |
191 | { |
192 | { |
192 | unsigned int x; |
193 | unsigned int x; |
193 | for (x = 0; x < viewports[vp].width; x++) |
194 | for (x = 0; x < viewports[vp].width; x++) |
194 | putpixel(vp, x, y, viewports[vp].style.bg_color); |
195 | putpixel(vp, x, y, viewports[vp].style.bg_color); |
195 | } |
196 | } |
196 | 197 | ||
197 | /** Fill viewport with background color */ |
198 | /** Fill viewport with background color */ |
198 | static void clear_port(int vp) |
199 | static void clear_port(int vp) |
199 | { |
200 | { |
200 | unsigned int y; |
201 | unsigned int y; |
201 | 202 | ||
202 | clear_line(vp, 0); |
203 | clear_line(vp, 0); |
203 | for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) { |
204 | for (y = viewports[vp].y+1; y < viewports[vp].y+viewports[vp].height; y++) { |
204 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
205 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
205 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
206 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
206 | screen.pixelbytes * viewports[vp].width); |
207 | screen.pixelbytes * viewports[vp].width); |
207 | } |
208 | } |
208 | } |
209 | } |
209 | 210 | ||
210 | /** Scroll port up/down |
211 | /** Scroll port up/down |
211 | * |
212 | * |
212 | * @param vp Viewport to scroll |
213 | * @param vp Viewport to scroll |
213 | * @param rows Positive number - scroll up, negative - scroll down |
214 | * @param rows Positive number - scroll up, negative - scroll down |
214 | */ |
215 | */ |
215 | static void scroll_port(int vp, int rows) |
216 | static void scroll_port(int vp, int rows) |
216 | { |
217 | { |
217 | int y; |
218 | int y; |
218 | int startline; |
219 | int startline; |
219 | int endline; |
220 | int endline; |
220 | 221 | ||
221 | if (rows > 0) { |
222 | if (rows > 0) { |
222 | for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++) |
223 | for (y=viewports[vp].y; y < viewports[vp].y+viewports[vp].height - rows*FONT_SCANLINES; y++) |
223 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
224 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
224 | &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)], |
225 | &screen.fbaddress[POINTPOS(viewports[vp].x,y + rows*FONT_SCANLINES)], |
225 | screen.pixelbytes * viewports[vp].width); |
226 | screen.pixelbytes * viewports[vp].width); |
226 | /* Clear last row */ |
227 | /* Clear last row */ |
227 | startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1); |
228 | startline = viewports[vp].y+FONT_SCANLINES*(viewports[vp].rows-1); |
228 | endline = viewports[vp].y + viewports[vp].height; |
229 | endline = viewports[vp].y + viewports[vp].height; |
229 | clear_line(vp, startline); |
230 | clear_line(vp, startline); |
230 | for (y=startline+1;y < endline; y++) |
231 | for (y=startline+1;y < endline; y++) |
231 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
232 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
232 | &screen.fbaddress[POINTPOS(viewports[vp].x,startline)], |
233 | &screen.fbaddress[POINTPOS(viewports[vp].x,startline)], |
233 | screen.pixelbytes * viewports[vp].width); |
234 | screen.pixelbytes * viewports[vp].width); |
234 | 235 | ||
235 | } else if (rows < 0) { |
236 | } else if (rows < 0) { |
236 | rows = -rows; |
237 | rows = -rows; |
237 | for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--) |
238 | for (y=viewports[vp].y + viewports[vp].height-1; y >= viewports[vp].y + rows*FONT_SCANLINES; y--) |
238 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
239 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,y)], |
239 | &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)], |
240 | &screen.fbaddress[POINTPOS(viewports[vp].x,y - rows*FONT_SCANLINES)], |
240 | screen.pixelbytes * viewports[vp].width); |
241 | screen.pixelbytes * viewports[vp].width); |
241 | /* Clear first row */ |
242 | /* Clear first row */ |
242 | clear_line(0, viewports[vp].style.bg_color); |
243 | clear_line(0, viewports[vp].style.bg_color); |
243 | for (y=1;y < rows*FONT_SCANLINES; y++) |
244 | for (y=1;y < rows*FONT_SCANLINES; y++) |
244 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)], |
245 | memcpy(&screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y+y)], |
245 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
246 | &screen.fbaddress[POINTPOS(viewports[vp].x,viewports[vp].y)], |
246 | screen.pixelbytes * viewports[vp].width); |
247 | screen.pixelbytes * viewports[vp].width); |
247 | } |
248 | } |
248 | } |
249 | } |
249 | 250 | ||
250 | static void invert_pixel(int vp,unsigned int x, unsigned int y) |
251 | static void invert_pixel(int vp,unsigned int x, unsigned int y) |
251 | { |
252 | { |
252 | putpixel(vp, x, y, ~getpixel(vp, x, y)); |
253 | putpixel(vp, x, y, ~getpixel(vp, x, y)); |
253 | } |
254 | } |
254 | 255 | ||
255 | 256 | ||
256 | /***************************************************************/ |
257 | /***************************************************************/ |
257 | /* Character-console functions */ |
258 | /* Character-console functions */ |
258 | 259 | ||
259 | /** Draw character at given position */ |
260 | /** Draw character at given position */ |
260 | static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy, style_t style) |
261 | static void draw_glyph(int vp,__u8 glyph, unsigned int sx, unsigned int sy, style_t style) |
261 | { |
262 | { |
262 | int i; |
263 | int i; |
263 | unsigned int y; |
264 | unsigned int y; |
264 | unsigned int glline; |
265 | unsigned int glline; |
265 | 266 | ||
266 | for (y = 0; y < FONT_SCANLINES; y++) { |
267 | for (y = 0; y < FONT_SCANLINES; y++) { |
267 | glline = fb_font[glyph * FONT_SCANLINES + y]; |
268 | glline = fb_font[glyph * FONT_SCANLINES + y]; |
268 | for (i = 0; i < 8; i++) { |
269 | for (i = 0; i < 8; i++) { |
269 | if (glline & (1 << (7 - i))) |
270 | if (glline & (1 << (7 - i))) |
270 | putpixel(vp, sx + i, sy + y, style.fg_color); |
271 | putpixel(vp, sx + i, sy + y, style.fg_color); |
271 | else |
272 | else |
272 | putpixel(vp, sx + i, sy + y, style.bg_color); |
273 | putpixel(vp, sx + i, sy + y, style.bg_color); |
273 | } |
274 | } |
274 | } |
275 | } |
275 | } |
276 | } |
276 | 277 | ||
277 | /** Invert character at given position */ |
278 | /** Invert character at given position */ |
278 | static void invert_char(int vp,unsigned int row, unsigned int col) |
279 | static void invert_char(int vp,unsigned int row, unsigned int col) |
279 | { |
280 | { |
280 | unsigned int x; |
281 | unsigned int x; |
281 | unsigned int y; |
282 | unsigned int y; |
282 | 283 | ||
283 | for (x = 0; x < COL_WIDTH; x++) |
284 | for (x = 0; x < COL_WIDTH; x++) |
284 | for (y = 0; y < FONT_SCANLINES; y++) |
285 | for (y = 0; y < FONT_SCANLINES; y++) |
285 | invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
286 | invert_pixel(vp, col * COL_WIDTH + x, row * FONT_SCANLINES + y); |
286 | } |
287 | } |
287 | 288 | ||
288 | static void draw_logo(int vp,unsigned int startx, unsigned int starty) |
289 | static void draw_logo(int vp,unsigned int startx, unsigned int starty) |
289 | { |
290 | { |
290 | unsigned int x; |
291 | unsigned int x; |
291 | unsigned int y; |
292 | unsigned int y; |
292 | unsigned int byte; |
293 | unsigned int byte; |
293 | unsigned int rowbytes; |
294 | unsigned int rowbytes; |
294 | 295 | ||
295 | rowbytes = (helenos_width - 1) / 8 + 1; |
296 | rowbytes = (helenos_width - 1) / 8 + 1; |
296 | 297 | ||
297 | for (y = 0; y < helenos_height; y++) |
298 | for (y = 0; y < helenos_height; y++) |
298 | for (x = 0; x < helenos_width; x++) { |
299 | for (x = 0; x < helenos_width; x++) { |
299 | byte = helenos_bits[rowbytes * y + x / 8]; |
300 | byte = helenos_bits[rowbytes * y + x / 8]; |
300 | byte >>= x % 8; |
301 | byte >>= x % 8; |
301 | if (byte & 1) |
302 | if (byte & 1) |
302 | putpixel(vp ,startx + x, starty + y, viewports[vp].style.fg_color); |
303 | putpixel(vp ,startx + x, starty + y, viewports[vp].style.fg_color); |
303 | } |
304 | } |
304 | } |
305 | } |
305 | 306 | ||
306 | /***************************************************************/ |
307 | /***************************************************************/ |
307 | /* Stdout specific functions */ |
308 | /* Stdout specific functions */ |
308 | 309 | ||
309 | 310 | ||
310 | /** Create new viewport |
311 | /** Create new viewport |
311 | * |
312 | * |
312 | * @return New viewport number |
313 | * @return New viewport number |
313 | */ |
314 | */ |
314 | static int viewport_create(unsigned int x, unsigned int y,unsigned int width, |
315 | static int viewport_create(unsigned int x, unsigned int y,unsigned int width, |
315 | unsigned int height) |
316 | unsigned int height) |
316 | { |
317 | { |
317 | int i; |
318 | int i; |
318 | 319 | ||
319 | for (i=0; i < MAX_VIEWPORTS; i++) { |
320 | for (i=0; i < MAX_VIEWPORTS; i++) { |
320 | if (!viewports[i].initialized) |
321 | if (!viewports[i].initialized) |
321 | break; |
322 | break; |
322 | } |
323 | } |
323 | if (i == MAX_VIEWPORTS) |
324 | if (i == MAX_VIEWPORTS) |
324 | return ELIMIT; |
325 | return ELIMIT; |
325 | 326 | ||
326 | if (width ==0 || height == 0 || |
327 | if (width ==0 || height == 0 || |
327 | x+width > screen.xres || y+height > screen.yres) |
328 | x+width > screen.xres || y+height > screen.yres) |
328 | return EINVAL; |
329 | return EINVAL; |
329 | if (width < FONT_SCANLINES || height < COL_WIDTH) |
330 | if (width < FONT_SCANLINES || height < COL_WIDTH) |
330 | return EINVAL; |
331 | return EINVAL; |
331 | 332 | ||
332 | viewports[i].x = x; |
333 | viewports[i].x = x; |
333 | viewports[i].y = y; |
334 | viewports[i].y = y; |
334 | viewports[i].width = width; |
335 | viewports[i].width = width; |
335 | viewports[i].height = height; |
336 | viewports[i].height = height; |
336 | 337 | ||
337 | viewports[i].rows = height / FONT_SCANLINES; |
338 | viewports[i].rows = height / FONT_SCANLINES; |
338 | viewports[i].cols = width / COL_WIDTH; |
339 | viewports[i].cols = width / COL_WIDTH; |
339 | 340 | ||
340 | viewports[i].style.bg_color = DEFAULT_BGCOLOR; |
341 | viewports[i].style.bg_color = DEFAULT_BGCOLOR; |
341 | viewports[i].style.fg_color = DEFAULT_FGCOLOR; |
342 | viewports[i].style.fg_color = DEFAULT_FGCOLOR; |
342 | 343 | ||
343 | viewports[i].cur_col = 0; |
344 | viewports[i].cur_col = 0; |
344 | viewports[i].cur_row = 0; |
345 | viewports[i].cur_row = 0; |
345 | viewports[i].cursor_active = 0; |
346 | viewports[i].cursor_active = 0; |
346 | 347 | ||
347 | viewports[i].initialized = 1; |
348 | viewports[i].initialized = 1; |
348 | 349 | ||
349 | return i; |
350 | return i; |
350 | } |
351 | } |
351 | 352 | ||
352 | 353 | ||
353 | /** Initialize framebuffer as a chardev output device |
354 | /** Initialize framebuffer as a chardev output device |
354 | * |
355 | * |
355 | * @param addr Address of theframebuffer |
356 | * @param addr Address of theframebuffer |
356 | * @param x Screen width in pixels |
357 | * @param x Screen width in pixels |
357 | * @param y Screen height in pixels |
358 | * @param y Screen height in pixels |
358 | * @param bpp Bits per pixel (8, 16, 24, 32) |
359 | * @param bpp Bits per pixel (8, 16, 24, 32) |
359 | * @param scan Bytes per one scanline |
360 | * @param scan Bytes per one scanline |
360 | * |
361 | * |
361 | */ |
362 | */ |
362 | static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) |
363 | static void screen_init(void *addr, unsigned int xres, unsigned int yres, unsigned int bpp, unsigned int scan) |
363 | { |
364 | { |
364 | switch (bpp) { |
365 | switch (bpp) { |
365 | case 8: |
366 | case 8: |
366 | screen.putpixel = putpixel_1byte; |
367 | screen.putpixel = putpixel_1byte; |
367 | screen.getpixel = getpixel_1byte; |
368 | screen.getpixel = getpixel_1byte; |
368 | screen.pixelbytes = 1; |
369 | screen.pixelbytes = 1; |
369 | break; |
370 | break; |
370 | case 16: |
371 | case 16: |
371 | screen.putpixel = putpixel_2byte; |
372 | screen.putpixel = putpixel_2byte; |
372 | screen.getpixel = getpixel_2byte; |
373 | screen.getpixel = getpixel_2byte; |
373 | screen.pixelbytes = 2; |
374 | screen.pixelbytes = 2; |
374 | break; |
375 | break; |
375 | case 24: |
376 | case 24: |
376 | screen.putpixel = putpixel_3byte; |
377 | screen.putpixel = putpixel_3byte; |
377 | screen.getpixel = getpixel_3byte; |
378 | screen.getpixel = getpixel_3byte; |
378 | screen.pixelbytes = 3; |
379 | screen.pixelbytes = 3; |
379 | break; |
380 | break; |
380 | case 32: |
381 | case 32: |
381 | screen.putpixel = putpixel_4byte; |
382 | screen.putpixel = putpixel_4byte; |
382 | screen.getpixel = getpixel_4byte; |
383 | screen.getpixel = getpixel_4byte; |
383 | screen.pixelbytes = 4; |
384 | screen.pixelbytes = 4; |
384 | break; |
385 | break; |
385 | } |
386 | } |
386 | 387 | ||
387 | 388 | ||
388 | screen.fbaddress = (unsigned char *) addr; |
389 | screen.fbaddress = (unsigned char *) addr; |
389 | screen.xres = xres; |
390 | screen.xres = xres; |
390 | screen.yres = yres; |
391 | screen.yres = yres; |
391 | screen.scanline = scan; |
392 | screen.scanline = scan; |
392 | 393 | ||
393 | /* Create first viewport */ |
394 | /* Create first viewport */ |
394 | viewport_create(0,0,xres,yres); |
395 | viewport_create(0,0,xres,yres); |
395 | } |
396 | } |
396 | 397 | ||
397 | static void cursor_hide(int vp) |
398 | static void cursor_hide(int vp) |
398 | { |
399 | { |
399 | viewport_t *vport = &viewports[vp]; |
400 | viewport_t *vport = &viewports[vp]; |
400 | 401 | ||
401 | if (vport->cursor_active && vport->cursor_shown) { |
402 | if (vport->cursor_active && vport->cursor_shown) { |
402 | invert_char(vp, vport->cur_row, vport->cur_col); |
403 | invert_char(vp, vport->cur_row, vport->cur_col); |
403 | vport->cursor_shown = 0; |
404 | vport->cursor_shown = 0; |
404 | } |
405 | } |
405 | } |
406 | } |
406 | 407 | ||
407 | static void cursor_print(int vp) |
408 | static void cursor_print(int vp) |
408 | { |
409 | { |
409 | viewport_t *vport = &viewports[vp]; |
410 | viewport_t *vport = &viewports[vp]; |
410 | 411 | ||
411 | /* Do not check for cursor_shown */ |
412 | /* Do not check for cursor_shown */ |
412 | if (vport->cursor_active) { |
413 | if (vport->cursor_active) { |
413 | invert_char(vp, vport->cur_row, vport->cur_col); |
414 | invert_char(vp, vport->cur_row, vport->cur_col); |
414 | vport->cursor_shown = 1; |
415 | vport->cursor_shown = 1; |
415 | } |
416 | } |
416 | } |
417 | } |
417 | 418 | ||
418 | static void cursor_blink(int vp) |
419 | static void cursor_blink(int vp) |
419 | { |
420 | { |
420 | viewport_t *vport = &viewports[vp]; |
421 | viewport_t *vport = &viewports[vp]; |
421 | 422 | ||
422 | if (vport->cursor_shown) |
423 | if (vport->cursor_shown) |
423 | cursor_hide(vp); |
424 | cursor_hide(vp); |
424 | else |
425 | else |
425 | cursor_print(vp); |
426 | cursor_print(vp); |
426 | } |
427 | } |
427 | 428 | ||
428 | /** Draw character at given position relative to viewport |
429 | /** Draw character at given position relative to viewport |
429 | * |
430 | * |
430 | * @param vp Viewport identification |
431 | * @param vp Viewport identification |
431 | * @param c Character to print |
432 | * @param c Character to print |
432 | * @param row Screen position relative to viewport |
433 | * @param row Screen position relative to viewport |
433 | * @param col Screen position relative to viewport |
434 | * @param col Screen position relative to viewport |
434 | */ |
435 | */ |
435 | static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style) |
436 | static void draw_char(int vp, char c, unsigned int row, unsigned int col, style_t style) |
436 | { |
437 | { |
437 | viewport_t *vport = &viewports[vp]; |
438 | viewport_t *vport = &viewports[vp]; |
438 | 439 | ||
439 | /* Optimize - do not hide cursor if we are going to overwrite it */ |
440 | /* Optimize - do not hide cursor if we are going to overwrite it */ |
440 | if (vport->cursor_active && vport->cursor_shown && |
441 | if (vport->cursor_active && vport->cursor_shown && |
441 | (vport->cur_col != col || vport->cur_row != row)) |
442 | (vport->cur_col != col || vport->cur_row != row)) |
442 | invert_char(vp, vport->cur_row, vport->cur_col); |
443 | invert_char(vp, vport->cur_row, vport->cur_col); |
443 | 444 | ||
444 | draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style); |
445 | draw_glyph(vp, c, col * COL_WIDTH, row * FONT_SCANLINES, style); |
445 | 446 | ||
446 | vport->cur_col = col; |
447 | vport->cur_col = col; |
447 | vport->cur_row = row; |
448 | vport->cur_row = row; |
448 | 449 | ||
449 | vport->cur_col++; |
450 | vport->cur_col++; |
450 | if (vport->cur_col>= vport->cols) { |
451 | if (vport->cur_col>= vport->cols) { |
451 | vport->cur_col = 0; |
452 | vport->cur_col = 0; |
452 | vport->cur_row++; |
453 | vport->cur_row++; |
453 | if (vport->cur_row >= vport->rows) |
454 | if (vport->cur_row >= vport->rows) |
454 | vport->cur_row--; |
455 | vport->cur_row--; |
455 | } |
456 | } |
456 | cursor_print(vp); |
457 | cursor_print(vp); |
457 | } |
458 | } |
458 | 459 | ||
459 | static void draw_text_data(int vp, keyfield_t *data) |
460 | static void draw_text_data(int vp, keyfield_t *data) |
460 | { |
461 | { |
461 | viewport_t *vport = &viewports[vp]; |
462 | viewport_t *vport = &viewports[vp]; |
462 | int i; |
463 | int i; |
463 | char c; |
464 | char c; |
464 | int col,row; |
465 | int col,row; |
465 | 466 | ||
466 | clear_port(vp); |
467 | clear_port(vp); |
467 | for (i=0; i < vport->cols * vport->rows; i++) { |
468 | for (i=0; i < vport->cols * vport->rows; i++) { |
468 | if (data[i].character == ' ' && style_same(data[i].style,vport->style)) |
469 | if (data[i].character == ' ' && style_same(data[i].style,vport->style)) |
469 | continue; |
470 | continue; |
470 | col = i % vport->cols; |
471 | col = i % vport->cols; |
471 | row = i / vport->cols; |
472 | row = i / vport->cols; |
472 | draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, data[i].style); |
473 | draw_glyph(vp, data[i].character, col * COL_WIDTH, row * FONT_SCANLINES, data[i].style); |
473 | } |
474 | } |
474 | cursor_print(vp); |
475 | cursor_print(vp); |
475 | } |
476 | } |
476 | 477 | ||
- | 478 | static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp) |
|
- | 479 | { |
|
- | 480 | static keyfield_t *interbuffer = NULL; |
|
- | 481 | static size_t intersize = 0; |
|
- | 482 | ||
- | 483 | static char *pixmap = NULL; |
|
- | 484 | static ipcarg_t pixmap_id = 0; |
|
- | 485 | static size_t pixmap_size; |
|
- | 486 | ||
- | 487 | int handled = 1; |
|
- | 488 | int retval = 0; |
|
- | 489 | viewport_t *vport = &viewports[vp]; |
|
- | 490 | unsigned int x,y; |
|
- | 491 | ||
- | 492 | switch (IPC_GET_METHOD(*call)) { |
|
- | 493 | case IPC_M_AS_AREA_SEND: |
|
- | 494 | /* We accept one area for data interchange */ |
|
- | 495 | if (IPC_GET_ARG1(*call) == pixmap_id) { |
|
- | 496 | void *dest = as_get_mappable_page(IPC_GET_ARG2(*call)); |
|
- | 497 | pixmap_size = IPC_GET_ARG2(*call); |
|
- | 498 | if (!ipc_answer_fast(callid, 0, (sysarg_t)dest, 0)) |
|
- | 499 | pixmap = dest; |
|
- | 500 | else |
|
- | 501 | pixmap_id = 0; |
|
- | 502 | if (pixmap[0] != 'P') |
|
- | 503 | while (1) |
|
- | 504 | ; |
|
- | 505 | return 1; |
|
- | 506 | } else { |
|
- | 507 | intersize = IPC_GET_ARG2(*call); |
|
- | 508 | receive_comm_area(callid,call,(void **)&interbuffer); |
|
- | 509 | } |
|
- | 510 | return 1; |
|
- | 511 | case FB_PREPARE_SHM: |
|
- | 512 | if (pixmap_id) |
|
- | 513 | retval = EBUSY; |
|
- | 514 | else |
|
- | 515 | pixmap_id = IPC_GET_ARG1(*call); |
|
- | 516 | break; |
|
- | 517 | ||
- | 518 | case FB_DROP_SHM: |
|
- | 519 | if (pixmap) { |
|
- | 520 | as_area_destroy(pixmap); |
|
- | 521 | pixmap = NULL; |
|
- | 522 | } |
|
- | 523 | pixmap_id = 0; |
|
- | 524 | break; |
|
- | 525 | ||
- | 526 | case FB_DRAW_PPM: |
|
- | 527 | if (!pixmap) { |
|
- | 528 | retval = EINVAL; |
|
- | 529 | break; |
|
- | 530 | } |
|
- | 531 | x = IPC_GET_ARG1(*call); |
|
- | 532 | y = IPC_GET_ARG2(*call); |
|
- | 533 | if (x > vport->width || y > vport->height) { |
|
- | 534 | retval = EINVAL; |
|
- | 535 | break; |
|
- | 536 | } |
|
- | 537 | ||
- | 538 | draw_ppm(pixmap, pixmap_size, IPC_GET_ARG1(*call), IPC_GET_ARG2(*call), |
|
- | 539 | vport->width - x, vport->height - y, putpixel, vp); |
|
- | 540 | break; |
|
- | 541 | case FB_DRAW_TEXT_DATA: |
|
- | 542 | if (!interbuffer) { |
|
- | 543 | retval = EINVAL; |
|
- | 544 | break; |
|
- | 545 | } |
|
- | 546 | if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) { |
|
- | 547 | retval = EINVAL; |
|
- | 548 | break; |
|
- | 549 | } |
|
- | 550 | draw_text_data(vp, interbuffer); |
|
- | 551 | break; |
|
- | 552 | default: |
|
- | 553 | handled = 0; |
|
- | 554 | } |
|
- | 555 | ||
- | 556 | if (handled) |
|
- | 557 | ipc_answer_fast(callid, retval, 0, 0); |
|
- | 558 | return handled; |
|
- | 559 | } |
|
477 | 560 | ||
478 | /** Function for handling connections to FB |
561 | /** Function for handling connections to FB |
479 | * |
562 | * |
480 | */ |
563 | */ |
481 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
564 | static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
482 | { |
565 | { |
483 | ipc_callid_t callid; |
566 | ipc_callid_t callid; |
484 | ipc_call_t call; |
567 | ipc_call_t call; |
485 | int retval; |
568 | int retval; |
486 | int i; |
569 | int i; |
487 | unsigned int row,col; |
570 | unsigned int row,col; |
488 | char c; |
571 | char c; |
489 | keyfield_t *interbuffer = NULL; |
- | |
490 | size_t intersize = 0; |
- | |
491 | 572 | ||
492 | int vp = 0; |
573 | int vp = 0; |
493 | viewport_t *vport = &viewports[0]; |
574 | viewport_t *vport = &viewports[0]; |
494 | 575 | ||
495 | if (client_connected) { |
576 | if (client_connected) { |
496 | ipc_answer_fast(iid, ELIMIT, 0,0); |
577 | ipc_answer_fast(iid, ELIMIT, 0,0); |
497 | return; |
578 | return; |
498 | } |
579 | } |
499 | client_connected = 1; |
580 | client_connected = 1; |
500 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
581 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
501 | 582 | ||
502 | while (1) { |
583 | while (1) { |
503 | callid = async_get_call_timeout(&call,250000); |
584 | callid = async_get_call_timeout(&call,250000); |
504 | if (!callid) { |
585 | if (!callid) { |
505 | cursor_blink(vp); |
586 | cursor_blink(vp); |
506 | continue; |
587 | continue; |
507 | } |
588 | } |
- | 589 | if (shm_handle(callid, &call, vp)) |
|
- | 590 | continue; |
|
- | 591 | ||
508 | switch (IPC_GET_METHOD(call)) { |
592 | switch (IPC_GET_METHOD(call)) { |
509 | case IPC_M_PHONE_HUNGUP: |
593 | case IPC_M_PHONE_HUNGUP: |
510 | client_connected = 0; |
594 | client_connected = 0; |
511 | /* cleanup other viewports */ |
595 | /* cleanup other viewports */ |
512 | for (i=1; i < MAX_VIEWPORTS; i++) |
596 | for (i=1; i < MAX_VIEWPORTS; i++) |
513 | vport->initialized = 0; |
597 | vport->initialized = 0; |
514 | ipc_answer_fast(callid,0,0,0); |
598 | ipc_answer_fast(callid,0,0,0); |
515 | return; /* Exit thread */ |
599 | return; /* Exit thread */ |
516 | case IPC_M_AS_AREA_SEND: |
- | |
517 | /* We accept one area for data interchange */ |
- | |
518 | intersize = IPC_GET_ARG2(call); |
- | |
519 | receive_comm_area(callid,&call,(void **)&interbuffer, |
- | |
520 | sizeof(*interbuffer)*viewports[0].cols*viewports[0].rows); |
- | |
521 | continue; |
- | |
522 | 600 | ||
523 | case FB_DRAW_TEXT_DATA: |
- | |
524 | if (!interbuffer) { |
- | |
525 | retval = EINVAL; |
- | |
526 | break; |
- | |
527 | } |
- | |
528 | if (intersize < vport->cols*vport->rows*sizeof(*interbuffer)) { |
- | |
529 | retval = EINVAL; |
- | |
530 | break; |
- | |
531 | } |
- | |
532 | draw_text_data(vp, interbuffer); |
- | |
533 | retval = 0; |
- | |
534 | break; |
- | |
535 | case FB_PUTCHAR: |
601 | case FB_PUTCHAR: |
536 | c = IPC_GET_ARG1(call); |
602 | c = IPC_GET_ARG1(call); |
537 | row = IPC_GET_ARG2(call); |
603 | row = IPC_GET_ARG2(call); |
538 | col = IPC_GET_ARG3(call); |
604 | col = IPC_GET_ARG3(call); |
539 | if (row >= vport->rows || col >= vport->cols) { |
605 | if (row >= vport->rows || col >= vport->cols) { |
540 | retval = EINVAL; |
606 | retval = EINVAL; |
541 | break; |
607 | break; |
542 | } |
608 | } |
543 | ipc_answer_fast(callid,0,0,0); |
609 | ipc_answer_fast(callid,0,0,0); |
544 | 610 | ||
545 | draw_char(vp, c, row, col, vport->style); |
611 | draw_char(vp, c, row, col, vport->style); |
546 | continue; /* msg already answered */ |
612 | continue; /* msg already answered */ |
547 | case FB_CLEAR: |
613 | case FB_CLEAR: |
548 | clear_port(vp); |
614 | clear_port(vp); |
549 | cursor_print(vp); |
615 | cursor_print(vp); |
550 | retval = 0; |
616 | retval = 0; |
551 | break; |
617 | break; |
552 | case FB_CURSOR_GOTO: |
618 | case FB_CURSOR_GOTO: |
553 | row = IPC_GET_ARG1(call); |
619 | row = IPC_GET_ARG1(call); |
554 | col = IPC_GET_ARG2(call); |
620 | col = IPC_GET_ARG2(call); |
555 | if (row >= vport->rows || col >= vport->cols) { |
621 | if (row >= vport->rows || col >= vport->cols) { |
556 | retval = EINVAL; |
622 | retval = EINVAL; |
557 | break; |
623 | break; |
558 | } |
624 | } |
559 | retval = 0; |
625 | retval = 0; |
560 | cursor_hide(vp); |
626 | cursor_hide(vp); |
561 | vport->cur_col = col; |
627 | vport->cur_col = col; |
562 | vport->cur_row = row; |
628 | vport->cur_row = row; |
563 | cursor_print(vp); |
629 | cursor_print(vp); |
564 | break; |
630 | break; |
565 | case FB_CURSOR_VISIBILITY: |
631 | case FB_CURSOR_VISIBILITY: |
566 | cursor_hide(vp); |
632 | cursor_hide(vp); |
567 | vport->cursor_active = IPC_GET_ARG1(call); |
633 | vport->cursor_active = IPC_GET_ARG1(call); |
568 | cursor_print(vp); |
634 | cursor_print(vp); |
569 | retval = 0; |
635 | retval = 0; |
570 | break; |
636 | break; |
571 | case FB_GET_CSIZE: |
637 | case FB_GET_CSIZE: |
572 | ipc_answer_fast(callid, 0, vport->rows, vport->cols); |
638 | ipc_answer_fast(callid, 0, vport->rows, vport->cols); |
573 | continue; |
639 | continue; |
574 | case FB_SCROLL: |
640 | case FB_SCROLL: |
575 | i = IPC_GET_ARG1(call); |
641 | i = IPC_GET_ARG1(call); |
576 | if (i > vport->rows || i < (- (int)vport->rows)) { |
642 | if (i > vport->rows || i < (- (int)vport->rows)) { |
577 | retval = EINVAL; |
643 | retval = EINVAL; |
578 | break; |
644 | break; |
579 | } |
645 | } |
580 | cursor_hide(vp); |
646 | cursor_hide(vp); |
581 | scroll_port(vp, i); |
647 | scroll_port(vp, i); |
582 | cursor_print(vp); |
648 | cursor_print(vp); |
583 | retval = 0; |
649 | retval = 0; |
584 | break; |
650 | break; |
585 | case FB_VIEWPORT_SWITCH: |
651 | case FB_VIEWPORT_SWITCH: |
586 | i = IPC_GET_ARG1(call); |
652 | i = IPC_GET_ARG1(call); |
587 | if (i < 0 || i >= MAX_VIEWPORTS) { |
653 | if (i < 0 || i >= MAX_VIEWPORTS) { |
588 | retval = EINVAL; |
654 | retval = EINVAL; |
589 | break; |
655 | break; |
590 | } |
656 | } |
591 | if (! viewports[i].initialized ) { |
657 | if (! viewports[i].initialized ) { |
592 | retval = EADDRNOTAVAIL; |
658 | retval = EADDRNOTAVAIL; |
593 | break; |
659 | break; |
594 | } |
660 | } |
595 | cursor_hide(vp); |
661 | cursor_hide(vp); |
596 | vp = i; |
662 | vp = i; |
597 | vport = &viewports[vp]; |
663 | vport = &viewports[vp]; |
598 | cursor_print(vp); |
664 | cursor_print(vp); |
599 | retval = 0; |
665 | retval = 0; |
600 | break; |
666 | break; |
601 | case FB_VIEWPORT_CREATE: |
667 | case FB_VIEWPORT_CREATE: |
602 | retval = viewport_create(IPC_GET_ARG1(call) >> 16, |
668 | retval = viewport_create(IPC_GET_ARG1(call) >> 16, |
603 | IPC_GET_ARG1(call) & 0xffff, |
669 | IPC_GET_ARG1(call) & 0xffff, |
604 | IPC_GET_ARG2(call) >> 16, |
670 | IPC_GET_ARG2(call) >> 16, |
605 | IPC_GET_ARG2(call) & 0xffff); |
671 | IPC_GET_ARG2(call) & 0xffff); |
606 | break; |
672 | break; |
607 | case FB_VIEWPORT_DELETE: |
673 | case FB_VIEWPORT_DELETE: |
608 | i = IPC_GET_ARG1(call); |
674 | i = IPC_GET_ARG1(call); |
609 | if (i < 0 || i >= MAX_VIEWPORTS) { |
675 | if (i < 0 || i >= MAX_VIEWPORTS) { |
610 | retval = EINVAL; |
676 | retval = EINVAL; |
611 | break; |
677 | break; |
612 | } |
678 | } |
613 | if (! viewports[i].initialized ) { |
679 | if (! viewports[i].initialized ) { |
614 | retval = EADDRNOTAVAIL; |
680 | retval = EADDRNOTAVAIL; |
615 | break; |
681 | break; |
616 | } |
682 | } |
617 | viewports[i].initialized = 0; |
683 | viewports[i].initialized = 0; |
618 | retval = 0; |
684 | retval = 0; |
619 | break; |
685 | break; |
620 | case FB_SET_STYLE: |
686 | case FB_SET_STYLE: |
621 | vport->style.fg_color = IPC_GET_ARG1(call); |
687 | vport->style.fg_color = IPC_GET_ARG1(call); |
622 | vport->style.bg_color = IPC_GET_ARG2(call); |
688 | vport->style.bg_color = IPC_GET_ARG2(call); |
623 | retval = 0; |
689 | retval = 0; |
624 | break; |
690 | break; |
625 | case FB_GET_RESOLUTION: |
691 | case FB_GET_RESOLUTION: |
626 | ipc_answer_fast(callid, 0, screen.xres,screen.yres); |
692 | ipc_answer_fast(callid, 0, screen.xres,screen.yres); |
627 | continue; |
693 | continue; |
628 | default: |
694 | default: |
629 | retval = ENOENT; |
695 | retval = ENOENT; |
630 | } |
696 | } |
631 | ipc_answer_fast(callid,retval,0,0); |
697 | ipc_answer_fast(callid,retval,0,0); |
632 | } |
698 | } |
633 | } |
699 | } |
634 | 700 | ||
635 | /** Initialization of framebuffer */ |
701 | /** Initialization of framebuffer */ |
636 | int fb_init(void) |
702 | int fb_init(void) |
637 | { |
703 | { |
638 | void *fb_ph_addr; |
704 | void *fb_ph_addr; |
639 | unsigned int fb_width; |
705 | unsigned int fb_width; |
640 | unsigned int fb_height; |
706 | unsigned int fb_height; |
641 | unsigned int fb_bpp; |
707 | unsigned int fb_bpp; |
642 | unsigned int fb_scanline; |
708 | unsigned int fb_scanline; |
643 | void *fb_addr; |
709 | void *fb_addr; |
644 | size_t asz; |
710 | size_t asz; |
645 | 711 | ||
646 | async_set_client_connection(fb_client_connection); |
712 | async_set_client_connection(fb_client_connection); |
647 | 713 | ||
648 | fb_ph_addr=(void *)sysinfo_value("fb.address.physical"); |
714 | fb_ph_addr=(void *)sysinfo_value("fb.address.physical"); |
649 | fb_width=sysinfo_value("fb.width"); |
715 | fb_width=sysinfo_value("fb.width"); |
650 | fb_height=sysinfo_value("fb.height"); |
716 | fb_height=sysinfo_value("fb.height"); |
651 | fb_bpp=sysinfo_value("fb.bpp"); |
717 | fb_bpp=sysinfo_value("fb.bpp"); |
652 | fb_scanline=sysinfo_value("fb.scanline"); |
718 | fb_scanline=sysinfo_value("fb.scanline"); |
653 | 719 | ||
654 | asz = fb_scanline*fb_height; |
720 | asz = fb_scanline*fb_height; |
655 | fb_addr = as_get_mappable_page(asz); |
721 | fb_addr = as_get_mappable_page(asz); |
656 | 722 | ||
657 | map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH, |
723 | map_physmem(fb_ph_addr, fb_addr, ALIGN_UP(asz,PAGE_SIZE) >>PAGE_WIDTH, |
658 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); |
724 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); |
659 | 725 | ||
660 | screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); |
726 | screen_init(fb_addr, fb_width, fb_height, fb_bpp, fb_scanline); |
661 | 727 | ||
662 | return 0; |
728 | return 0; |
663 | } |
729 | } |
664 | 730 | ||
665 | 731 |