[b1f51f0] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[b1f51f0] | 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 |
|
---|
[ce5bcb4] | 29 | /** @addtogroup console
|
---|
[1601f3c] | 30 | * @{
|
---|
[ce5bcb4] | 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[b1f51f0] | 35 | #include <ipc/fb.h>
|
---|
| 36 | #include <ipc/ipc.h>
|
---|
[e1c4849] | 37 | #include <async.h>
|
---|
| 38 | #include <stdio.h>
|
---|
[2def788] | 39 | #include <sys/mman.h>
|
---|
[90f5d64] | 40 | #include <string.h>
|
---|
[a7d2d78] | 41 | #include <align.h>
|
---|
[424cd43] | 42 | #include <bool.h>
|
---|
[b1f51f0] | 43 |
|
---|
| 44 | #include "console.h"
|
---|
[e1c4849] | 45 | #include "gcons.h"
|
---|
[b1f51f0] | 46 |
|
---|
[1601f3c] | 47 | #define CONSOLE_TOP 66
|
---|
| 48 | #define CONSOLE_MARGIN 6
|
---|
[b1f51f0] | 49 |
|
---|
[1601f3c] | 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
|
---|
[b1f51f0] | 55 |
|
---|
[1601f3c] | 56 | #define MAIN_COLOR 0xffffff
|
---|
[e1c4849] | 57 |
|
---|
[424cd43] | 58 | static bool use_gcons = false;
|
---|
| 59 | static ipcarg_t xres;
|
---|
| 60 | static ipcarg_t yres;
|
---|
[b1f51f0] | 61 |
|
---|
[a7d2d78] | 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 |
|
---|
[b1f51f0] | 72 | static int console_vp;
|
---|
| 73 | static int cstatus_vp[CONSOLE_COUNT];
|
---|
[a7d2d78] | 74 | static enum butstate console_state[CONSOLE_COUNT];
|
---|
[b1f51f0] | 75 |
|
---|
| 76 | static int fbphone;
|
---|
| 77 |
|
---|
[a7d2d78] | 78 | /** List of pixmaps identifying these icons */
|
---|
[00bb6965] | 79 | static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
|
---|
[1fd7700] | 80 | static int animation = -1;
|
---|
[e1c4849] | 81 |
|
---|
[424cd43] | 82 | static size_t active_console = 0;
|
---|
| 83 |
|
---|
| 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;
|
---|
[e1c4849] | 90 |
|
---|
[b1f51f0] | 91 | static void vp_switch(int vp)
|
---|
| 92 | {
|
---|
[76fca31] | 93 | async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
|
---|
[b1f51f0] | 94 | }
|
---|
| 95 |
|
---|
[e1c4849] | 96 | /** Create view port */
|
---|
[424cd43] | 97 | static int vp_create(size_t x, size_t y, size_t width, size_t height)
|
---|
[b1f51f0] | 98 | {
|
---|
[0cc4313] | 99 | return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
|
---|
| 100 | (width << 16) | height);
|
---|
[b1f51f0] | 101 | }
|
---|
| 102 |
|
---|
[e1c4849] | 103 | static void clear(void)
|
---|
[b1f51f0] | 104 | {
|
---|
[0cc4313] | 105 | async_msg_0(fbphone, FB_CLEAR);
|
---|
[b1f51f0] | 106 | }
|
---|
| 107 |
|
---|
[424cd43] | 108 | static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
|
---|
[e1c4849] | 109 | {
|
---|
[9805cde] | 110 | async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
|
---|
[e1c4849] | 111 | }
|
---|
| 112 |
|
---|
[d530237a] | 113 | /** Transparent putchar */
|
---|
[424cd43] | 114 | static void tran_putch(wchar_t ch, size_t col, size_t row)
|
---|
[e1c4849] | 115 | {
|
---|
[424cd43] | 116 | async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
|
---|
[e1c4849] | 117 | }
|
---|
| 118 |
|
---|
[d530237a] | 119 | /** Redraw the button showing state of a given console */
|
---|
[424cd43] | 120 | static void redraw_state(size_t index)
|
---|
[b1f51f0] | 121 | {
|
---|
[424cd43] | 122 | vp_switch(cstatus_vp[index]);
|
---|
| 123 |
|
---|
| 124 | enum butstate state = console_state[index];
|
---|
[1601f3c] | 125 |
|
---|
[a7d2d78] | 126 | if (ic_pixmaps[state] != -1)
|
---|
[424cd43] | 127 | async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index],
|
---|
[0cc4313] | 128 | ic_pixmaps[state]);
|
---|
[1601f3c] | 129 |
|
---|
[424cd43] | 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);
|
---|
[1601f3c] | 139 | }
|
---|
[b1f51f0] | 140 | }
|
---|
| 141 |
|
---|
[a7d2d78] | 142 | /** Notification run on changing console (except kernel console) */
|
---|
[424cd43] | 143 | void gcons_change_console(size_t index)
|
---|
[b1f51f0] | 144 | {
|
---|
| 145 | if (!use_gcons)
|
---|
| 146 | return;
|
---|
[1601f3c] | 147 |
|
---|
[a7d2d78] | 148 | if (active_console == KERNEL_CONSOLE) {
|
---|
[424cd43] | 149 | size_t i;
|
---|
| 150 |
|
---|
[00bb6965] | 151 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 152 | redraw_state(i);
|
---|
[424cd43] | 153 |
|
---|
[70178b74] | 154 | if (animation != -1)
|
---|
[0cc4313] | 155 | async_msg_1(fbphone, FB_ANIM_START, animation);
|
---|
[a7d2d78] | 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;
|
---|
[424cd43] | 161 |
|
---|
[a7d2d78] | 162 | redraw_state(active_console);
|
---|
| 163 | }
|
---|
[1601f3c] | 164 |
|
---|
[424cd43] | 165 | active_console = index;
|
---|
| 166 |
|
---|
| 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;
|
---|
[1601f3c] | 172 |
|
---|
[424cd43] | 173 | redraw_state(index);
|
---|
[b1f51f0] | 174 | vp_switch(console_vp);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[429acb9] | 177 | /** Notification function that gets called on new output to virtual console */
|
---|
[424cd43] | 178 | void gcons_notify_char(size_t index)
|
---|
[b1f51f0] | 179 | {
|
---|
| 180 | if (!use_gcons)
|
---|
| 181 | return;
|
---|
[1601f3c] | 182 |
|
---|
[424cd43] | 183 | if ((index == active_console)
|
---|
| 184 | || (console_state[index] == CONS_HAS_DATA))
|
---|
[d6cc453] | 185 | return;
|
---|
[1601f3c] | 186 |
|
---|
[424cd43] | 187 | console_state[index] = CONS_HAS_DATA;
|
---|
[1601f3c] | 188 |
|
---|
[a7d2d78] | 189 | if (active_console == KERNEL_CONSOLE)
|
---|
[429acb9] | 190 | return;
|
---|
[1601f3c] | 191 |
|
---|
[424cd43] | 192 | redraw_state(index);
|
---|
[b1f51f0] | 193 | vp_switch(console_vp);
|
---|
[a7d2d78] | 194 | }
|
---|
[429acb9] | 195 |
|
---|
[e9073f2] | 196 | /** Notification function called on service disconnect from console */
|
---|
[424cd43] | 197 | void gcons_notify_disconnect(size_t index)
|
---|
[e9073f2] | 198 | {
|
---|
| 199 | if (!use_gcons)
|
---|
| 200 | return;
|
---|
[1601f3c] | 201 |
|
---|
[424cd43] | 202 | if (index == active_console)
|
---|
| 203 | console_state[index] = CONS_DISCONNECTED_SEL;
|
---|
[e9073f2] | 204 | else
|
---|
[424cd43] | 205 | console_state[index] = CONS_DISCONNECTED;
|
---|
[76fca31] | 206 |
|
---|
[e9073f2] | 207 | if (active_console == KERNEL_CONSOLE)
|
---|
| 208 | return;
|
---|
[76fca31] | 209 |
|
---|
[424cd43] | 210 | redraw_state(index);
|
---|
[e9073f2] | 211 | vp_switch(console_vp);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[d530237a] | 214 | /** Notification function called on console connect */
|
---|
[424cd43] | 215 | void gcons_notify_connect(size_t index)
|
---|
[a7d2d78] | 216 | {
|
---|
| 217 | if (!use_gcons)
|
---|
| 218 | return;
|
---|
[1601f3c] | 219 |
|
---|
[424cd43] | 220 | if (index == active_console)
|
---|
| 221 | console_state[index] = CONS_SELECTED;
|
---|
[a7d2d78] | 222 | else
|
---|
[424cd43] | 223 | console_state[index] = CONS_IDLE;
|
---|
[1601f3c] | 224 |
|
---|
[a7d2d78] | 225 | if (active_console == KERNEL_CONSOLE)
|
---|
| 226 | return;
|
---|
[1601f3c] | 227 |
|
---|
[424cd43] | 228 | redraw_state(index);
|
---|
[a7d2d78] | 229 | vp_switch(console_vp);
|
---|
[b1f51f0] | 230 | }
|
---|
| 231 |
|
---|
[429acb9] | 232 | /** Change to kernel console */
|
---|
| 233 | void gcons_in_kernel(void)
|
---|
| 234 | {
|
---|
[70178b74] | 235 | if (animation != -1)
|
---|
[0cc4313] | 236 | async_msg_1(fbphone, FB_ANIM_STOP, animation);
|
---|
[76fca31] | 237 |
|
---|
| 238 | active_console = KERNEL_CONSOLE;
|
---|
[429acb9] | 239 | vp_switch(0);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[424cd43] | 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)
|
---|
[830ac99] | 244 | {
|
---|
| 245 | if (a < left)
|
---|
| 246 | a = left;
|
---|
[424cd43] | 247 |
|
---|
[830ac99] | 248 | if (a >= right)
|
---|
| 249 | a = right - 1;
|
---|
[424cd43] | 250 |
|
---|
[830ac99] | 251 | return a;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[1f83244] | 254 | /** Handle mouse move
|
---|
| 255 | *
|
---|
| 256 | * @param dx Delta X of mouse move
|
---|
| 257 | * @param dy Delta Y of mouse move
|
---|
| 258 | */
|
---|
[424cd43] | 259 | void gcons_mouse_move(ssize_t dx, ssize_t dy)
|
---|
[830ac99] | 260 | {
|
---|
[f15cb3c4] | 261 | mouse_x = limit(mouse_x + dx, 0, xres);
|
---|
| 262 | mouse_y = limit(mouse_y + dy, 0, yres);
|
---|
[1601f3c] | 263 |
|
---|
[1f83244] | 264 | async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | static int gcons_find_conbut(int x, int y)
|
---|
| 268 | {
|
---|
[f15cb3c4] | 269 | int status_start = STATUS_START + (xres - 800) / 2;
|
---|
[1601f3c] | 270 |
|
---|
| 271 | if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
|
---|
[1f83244] | 272 | return -1;
|
---|
| 273 |
|
---|
| 274 | if (x < status_start)
|
---|
| 275 | return -1;
|
---|
| 276 |
|
---|
[00bb6965] | 277 | if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
|
---|
[1f83244] | 278 | return -1;
|
---|
[f15cb3c4] | 279 | if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
|
---|
[1f83244] | 280 | return -1;
|
---|
| 281 |
|
---|
[f15cb3c4] | 282 | return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
|
---|
[1f83244] | 283 | }
|
---|
[830ac99] | 284 |
|
---|
[1f83244] | 285 | /** Handle mouse click
|
---|
| 286 | *
|
---|
[424cd43] | 287 | * @param state New state (true - pressed, false - depressed)
|
---|
[1f83244] | 288 | */
|
---|
[424cd43] | 289 | int gcons_mouse_btn(bool state)
|
---|
[1f83244] | 290 | {
|
---|
| 291 | int conbut;
|
---|
[1601f3c] | 292 |
|
---|
[1f83244] | 293 | if (state) {
|
---|
| 294 | conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
| 295 | if (conbut != -1) {
|
---|
[424cd43] | 296 | btn_pressed = true;
|
---|
[1f83244] | 297 | btn_x = mouse_x;
|
---|
| 298 | btn_y = mouse_y;
|
---|
| 299 | }
|
---|
| 300 | return -1;
|
---|
[1601f3c] | 301 | }
|
---|
| 302 |
|
---|
| 303 | if ((!state) && (!btn_pressed))
|
---|
[1f83244] | 304 | return -1;
|
---|
[1601f3c] | 305 |
|
---|
[424cd43] | 306 | btn_pressed = false;
|
---|
[1601f3c] | 307 |
|
---|
[1f83244] | 308 | conbut = gcons_find_conbut(mouse_x, mouse_y);
|
---|
| 309 | if (conbut == gcons_find_conbut(btn_x, btn_y))
|
---|
| 310 | return conbut;
|
---|
[1601f3c] | 311 |
|
---|
[1f83244] | 312 | return -1;
|
---|
[830ac99] | 313 | }
|
---|
| 314 |
|
---|
| 315 |
|
---|
[429acb9] | 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 | */
|
---|
[90f5d64] | 323 | static void draw_pixmap(char *logo, size_t size, int x, int y)
|
---|
| 324 | {
|
---|
| 325 | char *shm;
|
---|
| 326 | int rc;
|
---|
[1601f3c] | 327 |
|
---|
[90f5d64] | 328 | /* Create area */
|
---|
[00bb6965] | 329 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 330 | MAP_ANONYMOUS, 0, 0);
|
---|
[90f5d64] | 331 | if (shm == MAP_FAILED)
|
---|
| 332 | return;
|
---|
[1601f3c] | 333 |
|
---|
[90f5d64] | 334 | memcpy(shm, logo, size);
|
---|
[1601f3c] | 335 |
|
---|
[90f5d64] | 336 | /* Send area */
|
---|
[0cc4313] | 337 | rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
|
---|
[90f5d64] | 338 | if (rc)
|
---|
| 339 | goto exit;
|
---|
[1601f3c] | 340 |
|
---|
[215e375] | 341 | rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[90f5d64] | 342 | if (rc)
|
---|
| 343 | goto drop;
|
---|
[1601f3c] | 344 |
|
---|
[90f5d64] | 345 | /* Draw logo */
|
---|
[085bd54] | 346 | async_msg_2(fbphone, FB_DRAW_PPM, x, y);
|
---|
[1601f3c] | 347 |
|
---|
[90f5d64] | 348 | drop:
|
---|
| 349 | /* Drop area */
|
---|
[0cc4313] | 350 | async_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 351 |
|
---|
| 352 | exit:
|
---|
[90f5d64] | 353 | /* Remove area */
|
---|
| 354 | munmap(shm, size);
|
---|
| 355 | }
|
---|
| 356 |
|
---|
[1601f3c] | 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;
|
---|
[76fca31] | 361 |
|
---|
| 362 | /** Redraws console graphics */
|
---|
| 363 | void gcons_redraw_console(void)
|
---|
[b1f51f0] | 364 | {
|
---|
[e1c4849] | 365 | int i;
|
---|
[76fca31] | 366 |
|
---|
[b1f51f0] | 367 | if (!use_gcons)
|
---|
| 368 | return;
|
---|
| 369 |
|
---|
| 370 | vp_switch(0);
|
---|
[9805cde] | 371 | set_rgb_color(MAIN_COLOR, MAIN_COLOR);
|
---|
[e1c4849] | 372 | clear();
|
---|
[1601f3c] | 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);
|
---|
[76fca31] | 377 |
|
---|
[0cc4313] | 378 | for (i = 0; i < CONSOLE_COUNT; i++)
|
---|
[a7d2d78] | 379 | redraw_state(i);
|
---|
[1601f3c] | 380 |
|
---|
[b1f51f0] | 381 | vp_switch(console_vp);
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[d530237a] | 384 | /** Creates a pixmap on framebuffer
|
---|
| 385 | *
|
---|
| 386 | * @param data PPM data
|
---|
| 387 | * @param size PPM data size
|
---|
[424cd43] | 388 | *
|
---|
[d530237a] | 389 | * @return Pixmap identification
|
---|
[424cd43] | 390 | *
|
---|
[d530237a] | 391 | */
|
---|
[424cd43] | 392 | static int make_pixmap(char *data, size_t size)
|
---|
[a7d2d78] | 393 | {
|
---|
| 394 | char *shm;
|
---|
| 395 | int rc;
|
---|
| 396 | int pxid = -1;
|
---|
[1601f3c] | 397 |
|
---|
[a7d2d78] | 398 | /* Create area */
|
---|
[00bb6965] | 399 | shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
|
---|
[0cc4313] | 400 | MAP_ANONYMOUS, 0, 0);
|
---|
[a7d2d78] | 401 | if (shm == MAP_FAILED)
|
---|
| 402 | return -1;
|
---|
[1601f3c] | 403 |
|
---|
[a7d2d78] | 404 | memcpy(shm, data, size);
|
---|
[1601f3c] | 405 |
|
---|
[a7d2d78] | 406 | /* Send area */
|
---|
[0cc4313] | 407 | rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
|
---|
[a7d2d78] | 408 | if (rc)
|
---|
| 409 | goto exit;
|
---|
[1601f3c] | 410 |
|
---|
[215e375] | 411 | rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
|
---|
[a7d2d78] | 412 | if (rc)
|
---|
| 413 | goto drop;
|
---|
[1601f3c] | 414 |
|
---|
[a7d2d78] | 415 | /* Obtain pixmap */
|
---|
[0cc4313] | 416 | rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
|
---|
[a7d2d78] | 417 | if (rc < 0)
|
---|
| 418 | goto drop;
|
---|
[1601f3c] | 419 |
|
---|
[a7d2d78] | 420 | pxid = rc;
|
---|
[1601f3c] | 421 |
|
---|
[a7d2d78] | 422 | drop:
|
---|
| 423 | /* Drop area */
|
---|
[0cc4313] | 424 | async_msg_0(fbphone, FB_DROP_SHM);
|
---|
[1601f3c] | 425 |
|
---|
| 426 | exit:
|
---|
[a7d2d78] | 427 | /* Remove area */
|
---|
| 428 | munmap(shm, size);
|
---|
[1601f3c] | 429 |
|
---|
[a7d2d78] | 430 | return pxid;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
[1601f3c] | 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;
|
---|
[00bb6965] | 441 |
|
---|
[1fd7700] | 442 | static void make_anim(void)
|
---|
| 443 | {
|
---|
[1601f3c] | 444 | int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
|
---|
[1fd7700] | 445 | if (an < 0)
|
---|
| 446 | return;
|
---|
[1601f3c] | 447 |
|
---|
| 448 | int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
|
---|
| 449 | (int) &_binary_gfx_anim_1_ppm_size);
|
---|
[1fd7700] | 450 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 451 |
|
---|
| 452 | pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
|
---|
| 453 | (int) &_binary_gfx_anim_2_ppm_size);
|
---|
[1fd7700] | 454 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 455 |
|
---|
| 456 | pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
|
---|
| 457 | (int) &_binary_gfx_anim_3_ppm_size);
|
---|
[1fd7700] | 458 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 459 |
|
---|
| 460 | pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
|
---|
| 461 | (int) &_binary_gfx_anim_4_ppm_size);
|
---|
[1fd7700] | 462 | async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
|
---|
[1601f3c] | 463 |
|
---|
[0cc4313] | 464 | async_msg_1(fbphone, FB_ANIM_START, an);
|
---|
[1601f3c] | 465 |
|
---|
[1fd7700] | 466 | animation = an;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[1601f3c] | 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;
|
---|
[00bb6965] | 477 |
|
---|
[b1f51f0] | 478 | /** Initialize nice graphical console environment */
|
---|
| 479 | void gcons_init(int phone)
|
---|
| 480 | {
|
---|
| 481 | fbphone = phone;
|
---|
[76fca31] | 482 |
|
---|
[424cd43] | 483 | int rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
|
---|
[b1f51f0] | 484 | if (rc)
|
---|
| 485 | return;
|
---|
| 486 |
|
---|
[76fca31] | 487 | if ((xres < 800) || (yres < 600))
|
---|
[b1f51f0] | 488 | return;
|
---|
[76fca31] | 489 |
|
---|
[1601f3c] | 490 | /* Create console viewport */
|
---|
| 491 |
|
---|
[a7d2d78] | 492 | /* Align width & height to character size */
|
---|
[d7baee6] | 493 | console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
|
---|
[0cc4313] | 494 | ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
|
---|
| 495 | ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
|
---|
[424cd43] | 496 |
|
---|
[b1f51f0] | 497 | if (console_vp < 0)
|
---|
| 498 | return;
|
---|
| 499 |
|
---|
| 500 | /* Create status buttons */
|
---|
[424cd43] | 501 | size_t status_start = STATUS_START + (xres - 800) / 2;
|
---|
| 502 | size_t i;
|
---|
[00bb6965] | 503 | for (i = 0; i < CONSOLE_COUNT; i++) {
|
---|
[d7baee6] | 504 | cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
|
---|
[0cc4313] | 505 | i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
|
---|
| 506 | STATUS_WIDTH, STATUS_HEIGHT);
|
---|
[424cd43] | 507 |
|
---|
[b1f51f0] | 508 | if (cstatus_vp[i] < 0)
|
---|
| 509 | return;
|
---|
[424cd43] | 510 |
|
---|
[a7d2d78] | 511 | vp_switch(cstatus_vp[i]);
|
---|
[9805cde] | 512 | set_rgb_color(0x202020, 0xffffff);
|
---|
[b1f51f0] | 513 | }
|
---|
| 514 |
|
---|
[a7d2d78] | 515 | /* Initialize icons */
|
---|
[00bb6965] | 516 | ic_pixmaps[CONS_SELECTED] =
|
---|
[1601f3c] | 517 | make_pixmap(_binary_gfx_cons_selected_ppm_start,
|
---|
[424cd43] | 518 | (size_t) &_binary_gfx_cons_selected_ppm_size);
|
---|
[1601f3c] | 519 | ic_pixmaps[CONS_IDLE] =
|
---|
| 520 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 521 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[00bb6965] | 522 | ic_pixmaps[CONS_HAS_DATA] =
|
---|
[1601f3c] | 523 | make_pixmap(_binary_gfx_cons_has_data_ppm_start,
|
---|
[424cd43] | 524 | (size_t) &_binary_gfx_cons_has_data_ppm_size);
|
---|
[00bb6965] | 525 | ic_pixmaps[CONS_DISCONNECTED] =
|
---|
[1601f3c] | 526 | make_pixmap(_binary_gfx_cons_idle_ppm_start,
|
---|
[424cd43] | 527 | (size_t) &_binary_gfx_cons_idle_ppm_size);
|
---|
[1601f3c] | 528 | ic_pixmaps[CONS_KERNEL] =
|
---|
| 529 | make_pixmap(_binary_gfx_cons_kernel_ppm_start,
|
---|
[424cd43] | 530 | (size_t) &_binary_gfx_cons_kernel_ppm_size);
|
---|
[a7d2d78] | 531 | ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
|
---|
[1fd7700] | 532 |
|
---|
| 533 | make_anim();
|
---|
[76fca31] | 534 |
|
---|
[424cd43] | 535 | use_gcons = true;
|
---|
[a7d2d78] | 536 | console_state[0] = CONS_DISCONNECTED_SEL;
|
---|
| 537 | console_state[KERNEL_CONSOLE] = CONS_KERNEL;
|
---|
[424cd43] | 538 |
|
---|
[1035437] | 539 | vp_switch(console_vp);
|
---|
[b1f51f0] | 540 | }
|
---|
[76fca31] | 541 |
|
---|
[ce5bcb4] | 542 | /** @}
|
---|
| 543 | */
|
---|