/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include struct VasEBoot_term_output *VasEBoot_term_outputs_disabled; struct VasEBoot_term_input *VasEBoot_term_inputs_disabled; struct VasEBoot_term_output *VasEBoot_term_outputs; struct VasEBoot_term_input *VasEBoot_term_inputs; /* Current color state. */ VasEBoot_uint8_t VasEBoot_term_normal_color = VAS_EBOOT_TERM_DEFAULT_NORMAL_COLOR; VasEBoot_uint8_t VasEBoot_term_highlight_color = VAS_EBOOT_TERM_DEFAULT_HIGHLIGHT_COLOR; void (*VasEBoot_term_poll_usb) (int wait_for_completion) = NULL; void (*VasEBoot_net_poll_cards_idle) (void) = NULL; /* Put a Unicode character. */ static void VasEBoot_putcode_dumb (VasEBoot_uint32_t code, struct VasEBoot_term_output *term) { struct VasEBoot_unicode_glyph c = { .base = code, .variant = 0, .attributes = 0, .ncomb = 0, .estimated_width = 1 }; if (code == '\t' && term->getxy) { int n; n = VAS_EBOOT_TERM_TAB_WIDTH - ((term->getxy (term).x) % VAS_EBOOT_TERM_TAB_WIDTH); while (n--) VasEBoot_putcode_dumb (' ', term); return; } (term->putchar) (term, &c); if (code == '\n') VasEBoot_putcode_dumb ('\r', term); } static void VasEBoot_xputs_dumb (const char *str) { for (; *str; str++) { VasEBoot_term_output_t term; VasEBoot_uint32_t code = *str; if (code > 0x7f) code = '?'; FOR_ACTIVE_TERM_OUTPUTS(term) VasEBoot_putcode_dumb (code, term); } } void (*VasEBoot_xputs) (const char *str) = VasEBoot_xputs_dumb; int VasEBoot_getkey_noblock (void) { VasEBoot_term_input_t term; if (VasEBoot_term_poll_usb) VasEBoot_term_poll_usb (0); if (VasEBoot_net_poll_cards_idle) VasEBoot_net_poll_cards_idle (); FOR_ACTIVE_TERM_INPUTS(term) { int key = term->getkey (term); if (key != VAS_EBOOT_TERM_NO_KEY) return key; } return VAS_EBOOT_TERM_NO_KEY; } int VasEBoot_getkey (void) { int ret; VasEBoot_refresh (); while (1) { ret = VasEBoot_getkey_noblock (); if (ret != VAS_EBOOT_TERM_NO_KEY) return ret; VasEBoot_cpu_idle (); } } int VasEBoot_getkeystatus (void) { int status = 0; VasEBoot_term_input_t term; if (VasEBoot_term_poll_usb) VasEBoot_term_poll_usb (0); FOR_ACTIVE_TERM_INPUTS(term) { if (term->getkeystatus) status |= term->getkeystatus (term); } return status; } int VasEBoot_key_is_interrupt (int key) { /* * ESC sometimes is the BIOS setup hotkey and may be hard to discover, also * check F4, which was chosen because is not used as a hotkey to enter the * BIOS setup by any vendor. */ if (key == VAS_EBOOT_TERM_ESC || key == VAS_EBOOT_TERM_KEY_F4) return 1; /* * Pressing keys at the right time during boot is hard to time, also allow * interrupting sleeps / the menu countdown by keeping shift pressed. */ if (VasEBoot_getkeystatus() & (VAS_EBOOT_TERM_STATUS_LSHIFT | VAS_EBOOT_TERM_STATUS_RSHIFT)) return 1; return 0; } void VasEBoot_refresh (void) { struct VasEBoot_term_output *term; FOR_ACTIVE_TERM_OUTPUTS(term) VasEBoot_term_refresh (term); }