Rev 2025 | Rev 2071 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2025 | Rev 2070 | ||
---|---|---|---|
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 console |
29 | /** @addtogroup console |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <ipc/fb.h> |
35 | #include <ipc/fb.h> |
36 | #include <ipc/ipc.h> |
36 | #include <ipc/ipc.h> |
37 | #include <async.h> |
37 | #include <async.h> |
38 | #include <stdio.h> |
38 | #include <stdio.h> |
39 | #include <sys/mman.h> |
39 | #include <sys/mman.h> |
40 | #include <string.h> |
40 | #include <string.h> |
41 | #include <align.h> |
41 | #include <align.h> |
42 | 42 | ||
43 | #include "console.h" |
43 | #include "console.h" |
44 | #include "gcons.h" |
44 | #include "gcons.h" |
45 | 45 | ||
46 | #define CONSOLE_TOP 66 |
46 | #define CONSOLE_TOP 66 |
47 | #define CONSOLE_MARGIN 6 |
47 | #define CONSOLE_MARGIN 6 |
48 | 48 | ||
49 | #define STATUS_START 110 |
49 | #define STATUS_START 110 |
50 | #define STATUS_TOP 8 |
50 | #define STATUS_TOP 8 |
51 | #define STATUS_SPACE 4 |
51 | #define STATUS_SPACE 4 |
52 | #define STATUS_WIDTH 48 |
52 | #define STATUS_WIDTH 48 |
53 | #define STATUS_HEIGHT 48 |
53 | #define STATUS_HEIGHT 48 |
54 | 54 | ||
55 | #define MAIN_COLOR 0xffffff |
55 | #define MAIN_COLOR 0xffffff |
56 | 56 | ||
57 | static int use_gcons = 0; |
57 | static int use_gcons = 0; |
58 | static ipcarg_t xres,yres; |
58 | static ipcarg_t xres,yres; |
59 | 59 | ||
60 | enum butstate { |
60 | enum butstate { |
61 | CONS_DISCONNECTED = 0, |
61 | CONS_DISCONNECTED = 0, |
62 | CONS_SELECTED, |
62 | CONS_SELECTED, |
63 | CONS_IDLE, |
63 | CONS_IDLE, |
64 | CONS_HAS_DATA, |
64 | CONS_HAS_DATA, |
65 | CONS_KERNEL, |
65 | CONS_KERNEL, |
66 | CONS_DISCONNECTED_SEL, |
66 | CONS_DISCONNECTED_SEL, |
67 | CONS_LAST |
67 | CONS_LAST |
68 | }; |
68 | }; |
69 | 69 | ||
70 | static int console_vp; |
70 | static int console_vp; |
71 | static int cstatus_vp[CONSOLE_COUNT]; |
71 | static int cstatus_vp[CONSOLE_COUNT]; |
72 | static enum butstate console_state[CONSOLE_COUNT]; |
72 | static enum butstate console_state[CONSOLE_COUNT]; |
73 | 73 | ||
74 | static int fbphone; |
74 | static int fbphone; |
75 | 75 | ||
76 | /** List of pixmaps identifying these icons */ |
76 | /** List of pixmaps identifying these icons */ |
77 | static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1}; |
77 | static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1}; |
78 | static int animation = -1; |
78 | static int animation = -1; |
79 | 79 | ||
80 | static int active_console = 0; |
80 | static int active_console = 0; |
81 | 81 | ||
82 | static void vp_switch(int vp) |
82 | static void vp_switch(int vp) |
83 | { |
83 | { |
84 | async_msg(fbphone,FB_VIEWPORT_SWITCH, vp); |
84 | async_msg(fbphone,FB_VIEWPORT_SWITCH, vp); |
85 | } |
85 | } |
86 | 86 | ||
87 | /** Create view port */ |
87 | /** Create view port */ |
88 | static int vp_create(unsigned int x, unsigned int y, |
88 | static int vp_create(unsigned int x, unsigned int y, |
89 | unsigned int width, unsigned int height) |
89 | unsigned int width, unsigned int height) |
90 | { |
90 | { |
91 | return async_req_2(fbphone, FB_VIEWPORT_CREATE, |
91 | return async_req_2(fbphone, FB_VIEWPORT_CREATE, |
92 | (x << 16) | y, (width << 16) | height, |
92 | (x << 16) | y, (width << 16) | height, NULL, NULL); |
93 | NULL, NULL); |
- | |
94 | } |
93 | } |
95 | 94 | ||
96 | static void clear(void) |
95 | static void clear(void) |
97 | { |
96 | { |
98 | async_msg(fbphone, FB_CLEAR, 0); |
97 | async_msg(fbphone, FB_CLEAR, 0); |
99 | - | ||
100 | } |
98 | } |
101 | 99 | ||
102 | static void set_style(int fgcolor, int bgcolor) |
100 | static void set_style(int fgcolor, int bgcolor) |
103 | { |
101 | { |
104 | async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
102 | async_msg_2(fbphone, FB_SET_STYLE, fgcolor, bgcolor); |
105 | } |
103 | } |
106 | 104 | ||
107 | /** Transparent putchar */ |
105 | /** Transparent putchar */ |
108 | static void tran_putch(char c, int row, int col) |
106 | static void tran_putch(char c, int row, int col) |
109 | { |
107 | { |
110 | async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col); |
108 | async_msg_3(fbphone, FB_TRANS_PUTCHAR, c, row, col); |
111 | } |
109 | } |
112 | 110 | ||
113 | /** Redraw the button showing state of a given console */ |
111 | /** Redraw the button showing state of a given console */ |
114 | static void redraw_state(int consnum) |
112 | static void redraw_state(int consnum) |
115 | { |
113 | { |
116 | char data[5]; |
114 | char data[5]; |
117 | int i; |
115 | int i; |
118 | enum butstate state = console_state[consnum]; |
116 | enum butstate state = console_state[consnum]; |
119 | 117 | ||
120 | vp_switch(cstatus_vp[consnum]); |
118 | vp_switch(cstatus_vp[consnum]); |
121 | if (ic_pixmaps[state] != -1) |
119 | if (ic_pixmaps[state] != -1) |
122 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], |
120 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum], |
123 | ic_pixmaps[state]); |
121 | ic_pixmaps[state]); |
124 | 122 | ||
125 | if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state != |
123 | if (state != CONS_DISCONNECTED && state != CONS_KERNEL && |
126 | CONS_DISCONNECTED_SEL) { |
124 | state != CONS_DISCONNECTED_SEL) { |
127 | snprintf(data, 5, "%d", consnum + 1); |
125 | snprintf(data, 5, "%d", consnum + 1); |
128 | for (i=0; data[i]; i++) |
126 | for (i = 0; data[i]; i++) |
129 | tran_putch(data[i], 1, 2 + i); |
127 | tran_putch(data[i], 1, 2 + i); |
130 | } |
128 | } |
131 | } |
129 | } |
132 | 130 | ||
133 | /** Notification run on changing console (except kernel console) */ |
131 | /** Notification run on changing console (except kernel console) */ |
134 | void gcons_change_console(int consnum) |
132 | void gcons_change_console(int consnum) |
135 | { |
133 | { |
136 | int i; |
134 | int i; |
137 | 135 | ||
138 | if (!use_gcons) |
136 | if (!use_gcons) |
139 | return; |
137 | return; |
140 | 138 | ||
141 | if (active_console == KERNEL_CONSOLE) { |
139 | if (active_console == KERNEL_CONSOLE) { |
142 | for (i = 0; i < CONSOLE_COUNT; i++) |
140 | for (i = 0; i < CONSOLE_COUNT; i++) |
143 | redraw_state(i); |
141 | redraw_state(i); |
144 | if (animation != -1) |
142 | if (animation != -1) |
145 | async_msg(fbphone, FB_ANIM_START, animation); |
143 | async_msg(fbphone, FB_ANIM_START, animation); |
146 | } else { |
144 | } else { |
147 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
145 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
148 | console_state[active_console] = CONS_DISCONNECTED; |
146 | console_state[active_console] = CONS_DISCONNECTED; |
149 | else |
147 | else |
150 | console_state[active_console] = CONS_IDLE; |
148 | console_state[active_console] = CONS_IDLE; |
151 | redraw_state(active_console); |
149 | redraw_state(active_console); |
152 | } |
150 | } |
153 | active_console = consnum; |
151 | active_console = consnum; |
154 | 152 | ||
155 | if (console_state[consnum] == CONS_DISCONNECTED) { |
153 | if (console_state[consnum] == CONS_DISCONNECTED) { |
156 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
154 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
157 | redraw_state(consnum); |
155 | redraw_state(consnum); |
158 | } else |
156 | } else |
159 | console_state[consnum] = CONS_SELECTED; |
157 | console_state[consnum] = CONS_SELECTED; |
160 | redraw_state(consnum); |
158 | redraw_state(consnum); |
161 | 159 | ||
162 | vp_switch(console_vp); |
160 | vp_switch(console_vp); |
163 | } |
161 | } |
164 | 162 | ||
165 | /** Notification function that gets called on new output to virtual console */ |
163 | /** Notification function that gets called on new output to virtual console */ |
166 | void gcons_notify_char(int consnum) |
164 | void gcons_notify_char(int consnum) |
167 | { |
165 | { |
168 | if (!use_gcons) |
166 | if (!use_gcons) |
169 | return; |
167 | return; |
170 | 168 | ||
171 | if (consnum == active_console || console_state[consnum] == |
169 | if (consnum == active_console || |
172 | CONS_HAS_DATA) |
170 | console_state[consnum] == CONS_HAS_DATA) |
173 | return; |
171 | return; |
174 | 172 | ||
175 | console_state[consnum] = CONS_HAS_DATA; |
173 | console_state[consnum] = CONS_HAS_DATA; |
176 | 174 | ||
177 | if (active_console == KERNEL_CONSOLE) |
175 | if (active_console == KERNEL_CONSOLE) |
178 | return; |
176 | return; |
179 | 177 | ||
180 | redraw_state(consnum); |
178 | redraw_state(consnum); |
181 | 179 | ||
182 | vp_switch(console_vp); |
180 | vp_switch(console_vp); |
183 | } |
181 | } |
184 | 182 | ||
185 | /** Notification function called on service disconnect from console */ |
183 | /** Notification function called on service disconnect from console */ |
186 | void gcons_notify_disconnect(int consnum) |
184 | void gcons_notify_disconnect(int consnum) |
187 | { |
185 | { |
188 | if (!use_gcons) |
186 | if (!use_gcons) |
189 | return; |
187 | return; |
190 | if (active_console == consnum) |
188 | if (active_console == consnum) |
191 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
189 | console_state[consnum] = CONS_DISCONNECTED_SEL; |
192 | else |
190 | else |
193 | console_state[consnum] = CONS_DISCONNECTED; |
191 | console_state[consnum] = CONS_DISCONNECTED; |
194 | 192 | ||
195 | if (active_console == KERNEL_CONSOLE) |
193 | if (active_console == KERNEL_CONSOLE) |
196 | return; |
194 | return; |
197 | 195 | ||
198 | redraw_state(consnum); |
196 | redraw_state(consnum); |
199 | vp_switch(console_vp); |
197 | vp_switch(console_vp); |
200 | } |
198 | } |
201 | 199 | ||
202 | /** Notification function called on console connect */ |
200 | /** Notification function called on console connect */ |
203 | void gcons_notify_connect(int consnum) |
201 | void gcons_notify_connect(int consnum) |
204 | { |
202 | { |
205 | if (!use_gcons) |
203 | if (!use_gcons) |
206 | return; |
204 | return; |
207 | if (active_console == consnum) |
205 | if (active_console == consnum) |
208 | console_state[consnum] = CONS_SELECTED; |
206 | console_state[consnum] = CONS_SELECTED; |
209 | else |
207 | else |
210 | console_state[consnum] = CONS_IDLE; |
208 | console_state[consnum] = CONS_IDLE; |
211 | 209 | ||
212 | if (active_console == KERNEL_CONSOLE) |
210 | if (active_console == KERNEL_CONSOLE) |
213 | return; |
211 | return; |
214 | 212 | ||
215 | redraw_state(consnum); |
213 | redraw_state(consnum); |
216 | vp_switch(console_vp); |
214 | vp_switch(console_vp); |
217 | } |
215 | } |
218 | 216 | ||
219 | /** Change to kernel console */ |
217 | /** Change to kernel console */ |
220 | void gcons_in_kernel(void) |
218 | void gcons_in_kernel(void) |
221 | { |
219 | { |
222 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
220 | if (console_state[active_console] == CONS_DISCONNECTED_SEL) |
223 | console_state[active_console] = CONS_DISCONNECTED; |
221 | console_state[active_console] = CONS_DISCONNECTED; |
224 | else |
222 | else |
225 | console_state[active_console] = CONS_IDLE; |
223 | console_state[active_console] = CONS_IDLE; |
226 | redraw_state(active_console); |
224 | redraw_state(active_console); |
227 | 225 | ||
228 | if (animation != -1) |
226 | if (animation != -1) |
229 | async_msg(fbphone, FB_ANIM_STOP, animation); |
227 | async_msg(fbphone, FB_ANIM_STOP, animation); |
230 | 228 | ||
231 | active_console = KERNEL_CONSOLE; /* Set to kernel console */ |
229 | active_console = KERNEL_CONSOLE; /* Set to kernel console */ |
232 | vp_switch(0); |
230 | vp_switch(0); |
233 | } |
231 | } |
234 | 232 | ||
235 | /** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */ |
233 | /** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */ |
236 | static inline int limit(int a,int left, int right) |
234 | static inline int limit(int a,int left, int right) |
237 | { |
235 | { |
238 | if (a < left) |
236 | if (a < left) |
239 | a = left; |
237 | a = left; |
240 | if (a >= right) |
238 | if (a >= right) |
241 | a = right - 1; |
239 | a = right - 1; |
242 | return a; |
240 | return a; |
243 | } |
241 | } |
244 | 242 | ||
245 | int mouse_x, mouse_y; |
243 | int mouse_x, mouse_y; |
246 | int btn_pressed, btn_x, btn_y; |
244 | int btn_pressed, btn_x, btn_y; |
247 | 245 | ||
248 | /** Handle mouse move |
246 | /** Handle mouse move |
249 | * |
247 | * |
250 | * @param dx Delta X of mouse move |
248 | * @param dx Delta X of mouse move |
251 | * @param dy Delta Y of mouse move |
249 | * @param dy Delta Y of mouse move |
252 | */ |
250 | */ |
253 | void gcons_mouse_move(int dx, int dy) |
251 | void gcons_mouse_move(int dx, int dy) |
254 | { |
252 | { |
255 | mouse_x = limit(mouse_x+dx, 0, xres); |
253 | mouse_x = limit(mouse_x+dx, 0, xres); |
256 | mouse_y = limit(mouse_y+dy, 0, yres); |
254 | mouse_y = limit(mouse_y+dy, 0, yres); |
257 | 255 | ||
258 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); |
256 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y); |
259 | } |
257 | } |
260 | 258 | ||
261 | static int gcons_find_conbut(int x, int y) |
259 | static int gcons_find_conbut(int x, int y) |
262 | { |
260 | { |
263 | int status_start = STATUS_START + (xres - 800) / 2;; |
261 | int status_start = STATUS_START + (xres - 800) / 2;; |
264 | 262 | ||
265 | if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT) |
263 | if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT) |
266 | return -1; |
264 | return -1; |
267 | 265 | ||
268 | if (x < status_start) |
266 | if (x < status_start) |
269 | return -1; |
267 | return -1; |
270 | 268 | ||
271 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT) |
269 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT) |
272 | return -1; |
270 | return -1; |
273 | if (((x - status_start) % (STATUS_WIDTH+STATUS_SPACE)) < STATUS_SPACE) |
271 | if (((x - status_start) % (STATUS_WIDTH+STATUS_SPACE)) < STATUS_SPACE) |
274 | return -1; |
272 | return -1; |
275 | 273 | ||
276 | return (x - status_start) / (STATUS_WIDTH+STATUS_SPACE); |
274 | return (x - status_start) / (STATUS_WIDTH+STATUS_SPACE); |
277 | } |
275 | } |
278 | 276 | ||
279 | /** Handle mouse click |
277 | /** Handle mouse click |
280 | * |
278 | * |
281 | * @param state New state (1-pressed, 0-depressed) |
279 | * @param state New state (1-pressed, 0-depressed) |
282 | */ |
280 | */ |
283 | int gcons_mouse_btn(int state) |
281 | int gcons_mouse_btn(int state) |
284 | { |
282 | { |
285 | int conbut; |
283 | int conbut; |
286 | 284 | ||
287 | if (state) { |
285 | if (state) { |
288 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
286 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
289 | if (conbut != -1) { |
287 | if (conbut != -1) { |
290 | btn_pressed = 1; |
288 | btn_pressed = 1; |
291 | btn_x = mouse_x; |
289 | btn_x = mouse_x; |
292 | btn_y = mouse_y; |
290 | btn_y = mouse_y; |
293 | } |
291 | } |
294 | return -1; |
292 | return -1; |
295 | } |
293 | } |
296 | if (!state && !btn_pressed) |
294 | if (!state && !btn_pressed) |
297 | return -1; |
295 | return -1; |
298 | btn_pressed = 0; |
296 | btn_pressed = 0; |
299 | 297 | ||
300 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
298 | conbut = gcons_find_conbut(mouse_x, mouse_y); |
301 | if (conbut == gcons_find_conbut(btn_x, btn_y)) |
299 | if (conbut == gcons_find_conbut(btn_x, btn_y)) |
302 | return conbut; |
300 | return conbut; |
303 | return -1; |
301 | return -1; |
304 | } |
302 | } |
305 | 303 | ||
306 | 304 | ||
307 | /** Draw a PPM pixmap to framebuffer |
305 | /** Draw a PPM pixmap to framebuffer |
308 | * |
306 | * |
309 | * @param logo Pointer to PPM data |
307 | * @param logo Pointer to PPM data |
310 | * @param size Size of PPM data |
308 | * @param size Size of PPM data |
311 | * @param x Coordinate of upper left corner |
309 | * @param x Coordinate of upper left corner |
312 | * @param y Coordinate of upper left corner |
310 | * @param y Coordinate of upper left corner |
313 | */ |
311 | */ |
314 | static void draw_pixmap(char *logo, size_t size, int x, int y) |
312 | static void draw_pixmap(char *logo, size_t size, int x, int y) |
315 | { |
313 | { |
316 | char *shm; |
314 | char *shm; |
317 | int rc; |
315 | int rc; |
318 | 316 | ||
319 | /* Create area */ |
317 | /* Create area */ |
320 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | |
318 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | |
321 | MAP_ANONYMOUS, 0, 0); |
319 | MAP_ANONYMOUS, 0, 0); |
322 | if (shm == MAP_FAILED) |
320 | if (shm == MAP_FAILED) |
323 | return; |
321 | return; |
324 | 322 | ||
325 | memcpy(shm, logo, size); |
323 | memcpy(shm, logo, size); |
326 | /* Send area */ |
324 | /* Send area */ |
327 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm, 0, NULL, |
325 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm, 0, NULL, |
328 | NULL); |
326 | NULL); |
329 | if (rc) |
327 | if (rc) |
330 | goto exit; |
328 | goto exit; |
331 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t) shm, 0, |
329 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t) shm, 0, |
332 | PROTO_READ, NULL, NULL, NULL); |
330 | PROTO_READ, NULL, NULL, NULL); |
333 | if (rc) |
331 | if (rc) |
334 | goto drop; |
332 | goto drop; |
335 | /* Draw logo */ |
333 | /* Draw logo */ |
336 | async_msg_2(fbphone, FB_DRAW_PPM, x, y); |
334 | async_msg_2(fbphone, FB_DRAW_PPM, x, y); |
337 | drop: |
335 | drop: |
338 | /* Drop area */ |
336 | /* Drop area */ |
339 | async_msg(fbphone, FB_DROP_SHM, 0); |
337 | async_msg(fbphone, FB_DROP_SHM, 0); |
340 | exit: |
338 | exit: |
341 | /* Remove area */ |
339 | /* Remove area */ |
342 | munmap(shm, size); |
340 | munmap(shm, size); |
343 | } |
341 | } |
344 | 342 | ||
345 | extern char _binary_helenos_ppm_start[0]; |
343 | extern char _binary_helenos_ppm_start[0]; |
346 | extern int _binary_helenos_ppm_size; |
344 | extern int _binary_helenos_ppm_size; |
347 | extern char _binary_nameic_ppm_start[0]; |
345 | extern char _binary_nameic_ppm_start[0]; |
348 | extern int _binary_nameic_ppm_size; |
346 | extern int _binary_nameic_ppm_size; |
349 | /** Redraws console graphics */ |
347 | /** Redraws console graphics */ |
350 | static void gcons_redraw_console(void) |
348 | static void gcons_redraw_console(void) |
351 | { |
349 | { |
352 | int i; |
350 | int i; |
353 | 351 | ||
354 | if (!use_gcons) |
352 | if (!use_gcons) |
355 | return; |
353 | return; |
356 | 354 | ||
357 | vp_switch(0); |
355 | vp_switch(0); |
358 | set_style(MAIN_COLOR, MAIN_COLOR); |
356 | set_style(MAIN_COLOR, MAIN_COLOR); |
359 | clear(); |
357 | clear(); |
360 | draw_pixmap(_binary_helenos_ppm_start, (size_t) |
358 | draw_pixmap(_binary_helenos_ppm_start, |
361 | &_binary_helenos_ppm_size, xres - 66, 2); |
359 | (size_t) &_binary_helenos_ppm_size, xres - 66, 2); |
362 | draw_pixmap(_binary_nameic_ppm_start, (size_t) |
360 | draw_pixmap(_binary_nameic_ppm_start, |
363 | &_binary_nameic_ppm_size, 5, 17); |
361 | (size_t) &_binary_nameic_ppm_size, 5, 17); |
364 | 362 | ||
365 | for (i=0;i < CONSOLE_COUNT; i++) |
363 | for (i = 0;i < CONSOLE_COUNT; i++) |
366 | redraw_state(i); |
364 | redraw_state(i); |
367 | vp_switch(console_vp); |
365 | vp_switch(console_vp); |
368 | } |
366 | } |
369 | 367 | ||
370 | /** Creates a pixmap on framebuffer |
368 | /** Creates a pixmap on framebuffer |
371 | * |
369 | * |
372 | * @param data PPM data |
370 | * @param data PPM data |
373 | * @param size PPM data size |
371 | * @param size PPM data size |
374 | * @return Pixmap identification |
372 | * @return Pixmap identification |
375 | */ |
373 | */ |
376 | static int make_pixmap(char *data, int size) |
374 | static int make_pixmap(char *data, int size) |
377 | { |
375 | { |
378 | char *shm; |
376 | char *shm; |
379 | int rc; |
377 | int rc; |
380 | int pxid = -1; |
378 | int pxid = -1; |
381 | 379 | ||
382 | /* Create area */ |
380 | /* Create area */ |
383 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | |
381 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED | |
384 | MAP_ANONYMOUS, 0, 0); |
382 | MAP_ANONYMOUS, 0, 0); |
385 | if (shm == MAP_FAILED) |
383 | if (shm == MAP_FAILED) |
386 | return -1; |
384 | return -1; |
387 | 385 | ||
388 | memcpy(shm, data, size); |
386 | memcpy(shm, data, size); |
389 | /* Send area */ |
387 | /* Send area */ |
390 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm, 0, NULL, |
388 | rc = async_req_2(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm, 0, NULL, |
391 | NULL); |
389 | NULL); |
392 | if (rc) |
390 | if (rc) |
393 | goto exit; |
391 | goto exit; |
394 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t) shm, 0, |
392 | rc = async_req_3(fbphone, IPC_M_AS_AREA_SEND, (ipcarg_t) shm, 0, |
395 | PROTO_READ, NULL, NULL, NULL); |
393 | PROTO_READ, NULL, NULL, NULL); |
396 | if (rc) |
394 | if (rc) |
397 | goto drop; |
395 | goto drop; |
398 | 396 | ||
399 | /* Obtain pixmap */ |
397 | /* Obtain pixmap */ |
400 | rc = async_req(fbphone, FB_SHM2PIXMAP, 0, NULL); |
398 | rc = async_req(fbphone, FB_SHM2PIXMAP, 0, NULL); |
401 | if (rc < 0) |
399 | if (rc < 0) |
402 | goto drop; |
400 | goto drop; |
403 | pxid = rc; |
401 | pxid = rc; |
404 | drop: |
402 | drop: |
405 | /* Drop area */ |
403 | /* Drop area */ |
406 | async_msg(fbphone, FB_DROP_SHM, 0); |
404 | async_msg(fbphone, FB_DROP_SHM, 0); |
407 | exit: |
405 | exit: |
408 | /* Remove area */ |
406 | /* Remove area */ |
409 | munmap(shm, size); |
407 | munmap(shm, size); |
410 | 408 | ||
411 | return pxid; |
409 | return pxid; |
412 | } |
410 | } |
413 | 411 | ||
414 | extern char _binary_anim_1_ppm_start[0]; |
412 | extern char _binary_anim_1_ppm_start[0]; |
415 | extern int _binary_anim_1_ppm_size; |
413 | extern int _binary_anim_1_ppm_size; |
416 | extern char _binary_anim_2_ppm_start[0]; |
414 | extern char _binary_anim_2_ppm_start[0]; |
417 | extern int _binary_anim_2_ppm_size; |
415 | extern int _binary_anim_2_ppm_size; |
418 | extern char _binary_anim_3_ppm_start[0]; |
416 | extern char _binary_anim_3_ppm_start[0]; |
419 | extern int _binary_anim_3_ppm_size; |
417 | extern int _binary_anim_3_ppm_size; |
420 | extern char _binary_anim_4_ppm_start[0]; |
418 | extern char _binary_anim_4_ppm_start[0]; |
421 | extern int _binary_anim_4_ppm_size; |
419 | extern int _binary_anim_4_ppm_size; |
422 | 420 | ||
423 | static void make_anim(void) |
421 | static void make_anim(void) |
424 | { |
422 | { |
425 | int an; |
423 | int an; |
426 | int pm; |
424 | int pm; |
427 | 425 | ||
428 | an = async_req(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE], |
426 | an = async_req(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE], |
429 | NULL); |
427 | NULL); |
430 | if (an < 0) |
428 | if (an < 0) |
431 | return; |
429 | return; |
432 | 430 | ||
433 | pm = make_pixmap(_binary_anim_1_ppm_start, (int) |
431 | pm = make_pixmap(_binary_anim_1_ppm_start, |
434 | &_binary_anim_1_ppm_size); |
432 | (int) &_binary_anim_1_ppm_size); |
435 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
433 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
436 | 434 | ||
437 | pm = make_pixmap(_binary_anim_2_ppm_start, (int) |
435 | pm = make_pixmap(_binary_anim_2_ppm_start, |
438 | &_binary_anim_2_ppm_size); |
436 | (int) &_binary_anim_2_ppm_size); |
439 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
437 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
440 | 438 | ||
441 | pm = make_pixmap(_binary_anim_3_ppm_start, (int) |
439 | pm = make_pixmap(_binary_anim_3_ppm_start, |
442 | &_binary_anim_3_ppm_size); |
440 | (int) &_binary_anim_3_ppm_size); |
443 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
441 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
444 | 442 | ||
445 | pm = make_pixmap(_binary_anim_4_ppm_start, (int) |
443 | pm = make_pixmap(_binary_anim_4_ppm_start, |
446 | &_binary_anim_4_ppm_size); |
444 | (int) &_binary_anim_4_ppm_size); |
447 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
445 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm); |
448 | 446 | ||
449 | async_msg(fbphone, FB_ANIM_START, an); |
447 | async_msg(fbphone, FB_ANIM_START, an); |
450 | 448 | ||
451 | animation = an; |
449 | animation = an; |
452 | } |
450 | } |
453 | 451 | ||
454 | extern char _binary_cons_selected_ppm_start[0]; |
452 | extern char _binary_cons_selected_ppm_start[0]; |
455 | extern int _binary_cons_selected_ppm_size; |
453 | extern int _binary_cons_selected_ppm_size; |
456 | extern char _binary_cons_idle_ppm_start[0]; |
454 | extern char _binary_cons_idle_ppm_start[0]; |
457 | extern int _binary_cons_idle_ppm_size; |
455 | extern int _binary_cons_idle_ppm_size; |
458 | extern char _binary_cons_has_data_ppm_start[0]; |
456 | extern char _binary_cons_has_data_ppm_start[0]; |
459 | extern int _binary_cons_has_data_ppm_size; |
457 | extern int _binary_cons_has_data_ppm_size; |
460 | extern char _binary_cons_kernel_ppm_start[0]; |
458 | extern char _binary_cons_kernel_ppm_start[0]; |
461 | extern int _binary_cons_kernel_ppm_size; |
459 | extern int _binary_cons_kernel_ppm_size; |
462 | 460 | ||
463 | /** Initialize nice graphical console environment */ |
461 | /** Initialize nice graphical console environment */ |
464 | void gcons_init(int phone) |
462 | void gcons_init(int phone) |
465 | { |
463 | { |
466 | int rc; |
464 | int rc; |
467 | int i; |
465 | int i; |
468 | int status_start = STATUS_START; |
466 | int status_start = STATUS_START; |
469 | 467 | ||
470 | fbphone = phone; |
468 | fbphone = phone; |
471 | 469 | ||
472 | rc = async_req_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
470 | rc = async_req_2(phone, FB_GET_RESOLUTION, 0, 0, &xres, &yres); |
473 | if (rc) |
471 | if (rc) |
474 | return; |
472 | return; |
475 | 473 | ||
476 | if (xres < 800 || yres < 600) |
474 | if (xres < 800 || yres < 600) |
477 | return; |
475 | return; |
478 | 476 | ||
479 | /* create console viewport */ |
477 | /* create console viewport */ |
480 | /* Align width & height to character size */ |
478 | /* Align width & height to character size */ |
481 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, ALIGN_DOWN(xres - |
479 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, |
482 | 2 * CONSOLE_MARGIN, 8), ALIGN_DOWN(yres - (CONSOLE_TOP + |
480 | ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8), |
483 | CONSOLE_MARGIN), 16)); |
481 | ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16)); |
484 | if (console_vp < 0) |
482 | if (console_vp < 0) |
485 | return; |
483 | return; |
486 | 484 | ||
487 | /* Create status buttons */ |
485 | /* Create status buttons */ |
488 | status_start += (xres - 800) / 2; |
486 | status_start += (xres - 800) / 2; |
489 | for (i = 0; i < CONSOLE_COUNT; i++) { |
487 | for (i = 0; i < CONSOLE_COUNT; i++) { |
490 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN + i * |
488 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN + |
491 | (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP, |
489 | i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP, |
492 | STATUS_WIDTH, STATUS_HEIGHT); |
490 | STATUS_WIDTH, STATUS_HEIGHT); |
493 | if (cstatus_vp[i] < 0) |
491 | if (cstatus_vp[i] < 0) |
494 | return; |
492 | return; |
495 | vp_switch(cstatus_vp[i]); |
493 | vp_switch(cstatus_vp[i]); |
496 | set_style(0x202020, 0xffffff); |
494 | set_style(0x202020, 0xffffff); |
497 | } |
495 | } |
498 | 496 | ||
499 | /* Initialize icons */ |
497 | /* Initialize icons */ |
500 | ic_pixmaps[CONS_SELECTED] = |
498 | ic_pixmaps[CONS_SELECTED] = |
501 | make_pixmap(_binary_cons_selected_ppm_start, (int) |
499 | make_pixmap(_binary_cons_selected_ppm_start, |
502 | &_binary_cons_selected_ppm_size); |
500 | (int) &_binary_cons_selected_ppm_size); |
503 | ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start, (int) |
501 | ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start, |
504 | &_binary_cons_idle_ppm_size); |
502 | (int) &_binary_cons_idle_ppm_size); |
505 | ic_pixmaps[CONS_HAS_DATA] = |
503 | ic_pixmaps[CONS_HAS_DATA] = |
506 | make_pixmap(_binary_cons_has_data_ppm_start, (int) |
504 | make_pixmap(_binary_cons_has_data_ppm_start, |
507 | &_binary_cons_has_data_ppm_size); |
505 | (int) &_binary_cons_has_data_ppm_size); |
508 | ic_pixmaps[CONS_DISCONNECTED] = |
506 | ic_pixmaps[CONS_DISCONNECTED] = |
509 | make_pixmap(_binary_cons_idle_ppm_start, (int) |
507 | make_pixmap(_binary_cons_idle_ppm_start, |
510 | &_binary_cons_idle_ppm_size); |
508 | (int) &_binary_cons_idle_ppm_size); |
511 | ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start, |
509 | ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start, |
512 | (int) &_binary_cons_kernel_ppm_size); |
510 | (int) &_binary_cons_kernel_ppm_size); |
513 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED]; |
511 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED]; |
514 | 512 | ||
515 | make_anim(); |
513 | make_anim(); |
516 | 514 | ||
517 | use_gcons = 1; |
515 | use_gcons = 1; |
518 | console_state[0] = CONS_DISCONNECTED_SEL; |
516 | console_state[0] = CONS_DISCONNECTED_SEL; |
519 | console_state[KERNEL_CONSOLE] = CONS_KERNEL; |
517 | console_state[KERNEL_CONSOLE] = CONS_KERNEL; |
520 | gcons_redraw_console(); |
518 | gcons_redraw_console(); |
521 | } |
519 | } |
522 | 520 | ||
523 | /** @} |
521 | /** @} |
524 | */ |
522 | */ |
525 | 523 | ||
526 | 524 |