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