~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to term/i386/pc/console.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2002,2003,2005  Free Software Foundation, Inc.
 
4
 *
 
5
 *  This program 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 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program 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 this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 */
 
19
 
 
20
#include <grub/machine/console.h>
 
21
#include <grub/term.h>
 
22
#include <grub/types.h>
 
23
 
 
24
grub_uint8_t grub_console_cur_color = 0x7;
 
25
static grub_uint8_t grub_console_standard_color = 0x7;
 
26
static grub_uint8_t grub_console_normal_color = 0x7;
 
27
static grub_uint8_t grub_console_highlight_color = 0x70;
 
28
 
 
29
static grub_uint32_t
 
30
map_char (grub_uint32_t c)
 
31
{
 
32
  if (c > 0x7f)
 
33
    {
 
34
      /* Map some unicode characters to the VGA font, if possible.  */
 
35
      switch (c)
 
36
        {
 
37
        case 0x2190:    /* left arrow */
 
38
          c = 0x1b;
 
39
          break;
 
40
        case 0x2191:    /* up arrow */
 
41
          c = 0x18;
 
42
          break;
 
43
        case 0x2192:    /* right arrow */
 
44
          c = 0x1a;
 
45
          break;
 
46
        case 0x2193:    /* down arrow */
 
47
          c = 0x19;
 
48
          break;
 
49
        case 0x2501:    /* horizontal line */
 
50
          c = 0xc4;
 
51
          break;
 
52
        case 0x2503:    /* vertical line */
 
53
          c = 0xb3;
 
54
          break;
 
55
        case 0x250F:    /* upper-left corner */
 
56
          c = 0xda;
 
57
          break;
 
58
        case 0x2513:    /* upper-right corner */
 
59
          c = 0xbf;
 
60
          break;
 
61
        case 0x2517:    /* lower-left corner */
 
62
          c = 0xc0;
 
63
          break;
 
64
        case 0x251B:    /* lower-right corner */
 
65
          c = 0xd9;
 
66
          break;
 
67
 
 
68
        default:
 
69
          c = '?';
 
70
          break;
 
71
        }
 
72
    }
 
73
 
 
74
  return c;
 
75
}
 
76
 
 
77
static void
 
78
grub_console_putchar (grub_uint32_t c)
 
79
{
 
80
  grub_console_real_putchar (map_char (c));
 
81
}
 
82
 
 
83
static grub_ssize_t
 
84
grub_console_getcharwidth (grub_uint32_t c __attribute__ ((unused)))
 
85
{
 
86
  /* For now, every printable character has the width 1.  */
 
87
  return 1;
 
88
}
 
89
 
 
90
static grub_uint16_t
 
91
grub_console_getwh (void)
 
92
{
 
93
  return (80 << 8) | 25;
 
94
}
 
95
 
 
96
static void
 
97
grub_console_setcolorstate (grub_term_color_state state)
 
98
{
 
99
  switch (state) {
 
100
    case GRUB_TERM_COLOR_STANDARD:
 
101
      grub_console_cur_color = grub_console_standard_color;
 
102
      break;
 
103
    case GRUB_TERM_COLOR_NORMAL:
 
104
      grub_console_cur_color = grub_console_normal_color;
 
105
      break;
 
106
    case GRUB_TERM_COLOR_HIGHLIGHT:
 
107
      grub_console_cur_color = grub_console_highlight_color;
 
108
      break;
 
109
    default:
 
110
      break;
 
111
  }
 
112
}
 
113
 
 
114
static void
 
115
grub_console_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
 
116
{
 
117
  grub_console_normal_color = normal_color;
 
118
  grub_console_highlight_color = highlight_color;
 
119
}
 
120
 
 
121
static struct grub_term grub_console_term =
 
122
  {
 
123
    .name = "console",
 
124
    .init = 0,
 
125
    .fini = 0,
 
126
    .putchar = grub_console_putchar,
 
127
    .getcharwidth = grub_console_getcharwidth,
 
128
    .checkkey = grub_console_checkkey,
 
129
    .getkey = grub_console_getkey,
 
130
    .getwh = grub_console_getwh,
 
131
    .getxy = grub_console_getxy,
 
132
    .gotoxy = grub_console_gotoxy,
 
133
    .cls = grub_console_cls,
 
134
    .setcolorstate = grub_console_setcolorstate,
 
135
    .setcolor = grub_console_setcolor,
 
136
    .setcursor = grub_console_setcursor,
 
137
    .flags = 0,
 
138
    .next = 0
 
139
  };
 
140
 
 
141
void
 
142
grub_console_init (void)
 
143
{
 
144
  grub_term_register (&grub_console_term);
 
145
  grub_term_set_current (&grub_console_term);
 
146
}
 
147
 
 
148
void
 
149
grub_console_fini (void)
 
150
{
 
151
  grub_term_unregister (&grub_console_term);
 
152
}