2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/term.h>
2N/A#include <grub/err.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/env.h>
2N/A#include <grub/time.h>
2N/A
2N/Astruct grub_term_output *grub_term_outputs_disabled;
2N/Astruct grub_term_input *grub_term_inputs_disabled;
2N/Astruct grub_term_output *grub_term_outputs;
2N/Astruct grub_term_input *grub_term_inputs;
2N/A
2N/Avoid (*grub_term_poll_usb) (void) = NULL;
2N/Avoid (*grub_net_poll_cards_idle) (void) = NULL;
2N/A
2N/A/* Put a Unicode character. */
2N/Astatic void
2N/Agrub_putcode_dumb (grub_uint32_t code,
2N/A struct grub_term_output *term)
2N/A{
2N/A struct grub_unicode_glyph c =
2N/A {
2N/A .base = code,
2N/A .variant = 0,
2N/A .attributes = 0,
2N/A .ncomb = 0,
2N/A .combining = 0,
2N/A .estimated_width = 1
2N/A };
2N/A
2N/A if (code == '\t' && term->getxy)
2N/A {
2N/A int n;
2N/A
2N/A n = 8 - ((term->getxy (term) >> 8) & 7);
2N/A while (n--)
2N/A grub_putcode_dumb (' ', term);
2N/A
2N/A return;
2N/A }
2N/A
2N/A (term->putchar) (term, &c);
2N/A if (code == '\n')
2N/A grub_putcode_dumb ('\r', term);
2N/A}
2N/A
2N/Astatic void
2N/Agrub_xputs_dumb (const char *str)
2N/A{
2N/A for (; *str; str++)
2N/A {
2N/A grub_term_output_t term;
2N/A grub_uint32_t code = *str;
2N/A if (code > 0x7f)
2N/A code = '?';
2N/A
2N/A FOR_ACTIVE_TERM_OUTPUTS(term)
2N/A grub_putcode_dumb (code, term);
2N/A }
2N/A}
2N/A
2N/Avoid (*grub_xputs) (const char *str) = grub_xputs_dumb;
2N/A
2N/Astatic int pending_key = GRUB_TERM_NO_KEY;
2N/A
2N/Aint
2N/Agrub_checkkey (void)
2N/A{
2N/A grub_term_input_t term;
2N/A
2N/A if (pending_key != GRUB_TERM_NO_KEY)
2N/A return pending_key;
2N/A
2N/A if (grub_term_poll_usb)
2N/A grub_term_poll_usb ();
2N/A
2N/A if (grub_net_poll_cards_idle)
2N/A grub_net_poll_cards_idle ();
2N/A
2N/A FOR_ACTIVE_TERM_INPUTS(term)
2N/A {
2N/A pending_key = term->getkey (term);
2N/A if (pending_key != GRUB_TERM_NO_KEY)
2N/A return pending_key;
2N/A }
2N/A
2N/A return -1;
2N/A}
2N/A
2N/Aint
2N/Agrub_getkey (void)
2N/A{
2N/A int ret;
2N/A
2N/A grub_refresh ();
2N/A
2N/A grub_checkkey ();
2N/A while (pending_key == GRUB_TERM_NO_KEY)
2N/A {
2N/A grub_cpu_idle ();
2N/A grub_checkkey ();
2N/A }
2N/A ret = pending_key;
2N/A pending_key = GRUB_TERM_NO_KEY;
2N/A return ret;
2N/A}
2N/A
2N/A
2N/Avoid
2N/Agrub_refresh (void)
2N/A{
2N/A struct grub_term_output *term;
2N/A
2N/A FOR_ACTIVE_TERM_OUTPUTS(term)
2N/A grub_term_refresh (term);
2N/A}