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>
27 static int grub_curr_x
, grub_curr_y
;
29 #define VGA_TEXT_SCREEN 0xb8000
31 #define CRTC_ADDR_PORT 0x3D4
32 #define CRTC_DATA_PORT 0x3D5
34 #define CRTC_CURSOR 0x0a
35 #define CRTC_CURSOR_ADDR_HIGH 0x0e
36 #define CRTC_CURSOR_ADDR_LOW 0x0f
38 #define CRTC_CURSOR_DISABLE (1 << 5)
41 screen_write_char (int x
, int y
, short c
)
43 ((short *) VGA_TEXT_SCREEN
)[y
* COLS
+ x
] = c
;
47 screen_read_char (int x
, int y
)
49 return ((short *) VGA_TEXT_SCREEN
)[y
* COLS
+ x
];
55 unsigned int pos
= grub_curr_y
* COLS
+ grub_curr_x
;
56 grub_outb (CRTC_CURSOR_ADDR_HIGH
, CRTC_ADDR_PORT
);
57 grub_outb (pos
>> 8, CRTC_DATA_PORT
);
58 grub_outb (CRTC_CURSOR_ADDR_LOW
, CRTC_ADDR_PORT
);
59 grub_outb (pos
& 0xFF, CRTC_DATA_PORT
);
66 if (grub_curr_y
< ROWS
- 1)
71 for (y
= 0; y
< ROWS
; y
++)
72 for (x
= 0; x
< COLS
; x
++)
73 screen_write_char (x
, y
, screen_read_char (x
, y
+ 1));
80 if (grub_curr_x
>= COLS
- 2)
87 grub_console_real_putchar (int c
)
93 screen_write_char (grub_curr_x
--, grub_curr_y
, ' ');
102 screen_write_char (grub_curr_x
,
103 grub_curr_y
, c
| (grub_console_cur_color
<< 8));
111 grub_vga_text_getxy (void)
113 return (grub_curr_x
<< 8) | grub_curr_y
;
117 grub_vga_text_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
125 grub_vga_text_cls (void)
128 for (i
= 0; i
< ROWS
* COLS
; i
++)
129 ((short *) VGA_TEXT_SCREEN
)[i
] = ' ' | (grub_console_cur_color
<< 8);
130 grub_vga_text_gotoxy (0, 0);
134 grub_vga_text_setcursor (int on
)
137 grub_outb (CRTC_CURSOR
, CRTC_ADDR_PORT
);
138 old
= grub_inb (CRTC_DATA_PORT
);
140 grub_outb (old
& ~CRTC_CURSOR_DISABLE
, CRTC_DATA_PORT
);
142 grub_outb (old
| CRTC_CURSOR_DISABLE
, CRTC_DATA_PORT
);
146 grub_vga_text_init_fini ()
148 grub_vga_text_cls ();
152 static struct grub_term_output grub_vga_text_term
=
155 .init
= grub_vga_text_init_fini
,
156 .fini
= grub_vga_text_init_fini
,
157 .putchar
= grub_console_putchar
,
158 .getcharwidth
= grub_console_getcharwidth
,
159 .getwh
= grub_console_getwh
,
160 .getxy
= grub_vga_text_getxy
,
161 .gotoxy
= grub_vga_text_gotoxy
,
162 .cls
= grub_vga_text_cls
,
163 .setcolorstate
= grub_console_setcolorstate
,
164 .setcolor
= grub_console_setcolor
,
165 .getcolor
= grub_console_getcolor
,
166 .setcursor
= grub_vga_text_setcursor
,
169 GRUB_MOD_INIT(vga_text
)
171 grub_term_register_output (&grub_vga_text_term
);
174 GRUB_MOD_FINI(vga_text
)
176 grub_term_unregister_output (&grub_vga_text_term
);