]> git.proxmox.com Git - grub2.git/blob - grub-core/term/i386/pc/console.c
pull-in emu-lite branch
[grub2.git] / grub-core / term / i386 / pc / console.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <grub/machine/memory.h>
20 #include <grub/machine/console.h>
21 #include <grub/term.h>
22 #include <grub/types.h>
23
24 static const struct grub_machine_bios_data_area *bios_data_area =
25 (struct grub_machine_bios_data_area *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR;
26
27 #define KEYBOARD_LEFT_SHIFT (1 << 0)
28 #define KEYBOARD_RIGHT_SHIFT (1 << 1)
29 #define KEYBOARD_CTRL (1 << 2)
30 #define KEYBOARD_ALT (1 << 3)
31
32 static int
33 grub_console_getkeystatus (void)
34 {
35 grub_uint8_t status = bios_data_area->keyboard_flag_lower;
36 int mods = 0;
37
38 if (status & (KEYBOARD_LEFT_SHIFT | KEYBOARD_RIGHT_SHIFT))
39 mods |= GRUB_TERM_STATUS_SHIFT;
40 if (status & KEYBOARD_CTRL)
41 mods |= GRUB_TERM_STATUS_CTRL;
42 if (status & KEYBOARD_ALT)
43 mods |= GRUB_TERM_STATUS_ALT;
44
45 return mods;
46 }
47
48 static struct grub_term_input grub_console_term_input =
49 {
50 .name = "console",
51 .checkkey = grub_console_checkkey,
52 .getkey = grub_console_getkey,
53 .getkeystatus = grub_console_getkeystatus,
54 };
55
56 static struct grub_term_output grub_console_term_output =
57 {
58 .name = "console",
59 .putchar = grub_console_putchar,
60 .getcharwidth = grub_console_getcharwidth,
61 .getwh = grub_console_getwh,
62 .getxy = grub_console_getxy,
63 .gotoxy = grub_console_gotoxy,
64 .cls = grub_console_cls,
65 .setcolorstate = grub_console_setcolorstate,
66 .setcolor = grub_console_setcolor,
67 .getcolor = grub_console_getcolor,
68 .setcursor = grub_console_setcursor
69 };
70
71 void
72 grub_console_init (void)
73 {
74 grub_term_register_output ("console", &grub_console_term_output);
75 grub_term_register_input ("console", &grub_console_term_input);
76 }
77
78 void
79 grub_console_fini (void)
80 {
81 grub_term_unregister_input (&grub_console_term_input);
82 grub_term_unregister_output (&grub_console_term_output);
83 }