2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2007, 2008 Free Software Foundation, Inc.
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.
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.
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/>.
20
#include <grub/i386/vga_common.h>
21
#include <grub/i386/io.h>
22
#include <grub/types.h>
28
static int grub_curr_x, grub_curr_y;
30
#define VGA_TEXT_SCREEN 0xb8000
33
screen_write_char (int x, int y, short c)
35
((short *) VGA_TEXT_SCREEN)[y * COLS + x] = c;
39
screen_read_char (int x, int y)
41
return ((short *) VGA_TEXT_SCREEN)[y * COLS + x];
47
unsigned int pos = grub_curr_y * COLS + grub_curr_x;
48
grub_vga_cr_write (pos >> 8, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
49
grub_vga_cr_write (pos & 0xFF, GRUB_VGA_CR_CURSOR_ADDR_LOW);
56
if (grub_curr_y < ROWS - 1)
61
for (y = 0; y < ROWS - 1; y++)
62
for (x = 0; x < COLS; x++)
63
screen_write_char (x, y, screen_read_char (x, y + 1));
64
for (x = 0; x < COLS; x++)
65
screen_write_char (x, ROWS - 1, ' ' | (grub_console_cur_color << 8));
72
if (grub_curr_x >= COLS - 1)
79
grub_vga_text_putchar (struct grub_term_output *term __attribute__ ((unused)),
80
const struct grub_unicode_glyph *c)
86
screen_write_char (grub_curr_x--, grub_curr_y, ' ');
95
screen_write_char (grub_curr_x, grub_curr_y,
96
c->base | (grub_console_cur_color << 8));
104
grub_vga_text_getxy (struct grub_term_output *term __attribute__ ((unused)))
106
return (grub_curr_x << 8) | grub_curr_y;
110
grub_vga_text_gotoxy (struct grub_term_output *term __attribute__ ((unused)),
111
grub_uint8_t x, grub_uint8_t y)
119
grub_vga_text_cls (struct grub_term_output *term)
122
for (i = 0; i < ROWS * COLS; i++)
123
((short *) VGA_TEXT_SCREEN)[i] = ' ' | (grub_console_cur_color << 8);
124
grub_vga_text_gotoxy (term, 0, 0);
128
grub_vga_text_setcursor (struct grub_term_output *term __attribute__ ((unused)),
132
old = grub_vga_cr_read (GRUB_VGA_CR_CURSOR_START);
134
grub_vga_cr_write (old & ~GRUB_VGA_CR_CURSOR_START_DISABLE,
135
GRUB_VGA_CR_CURSOR_START);
137
grub_vga_cr_write (old | GRUB_VGA_CR_CURSOR_START_DISABLE,
138
GRUB_VGA_CR_CURSOR_START);
142
grub_vga_text_init_fini (struct grub_term_output *term)
144
grub_vga_text_cls (term);
148
static struct grub_term_output grub_vga_text_term =
151
.init = grub_vga_text_init_fini,
152
.fini = grub_vga_text_init_fini,
153
.putchar = grub_vga_text_putchar,
154
.getwh = grub_console_getwh,
155
.getxy = grub_vga_text_getxy,
156
.gotoxy = grub_vga_text_gotoxy,
157
.cls = grub_vga_text_cls,
158
.setcolorstate = grub_console_setcolorstate,
159
.setcursor = grub_vga_text_setcursor,
160
.flags = GRUB_TERM_CODE_TYPE_CP437,
161
.normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
162
.highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
165
GRUB_MOD_INIT(vga_text)
167
grub_term_register_output ("vga_text", &grub_vga_text_term);
170
GRUB_MOD_FINI(vga_text)
172
grub_term_unregister_output (&grub_vga_text_term);