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