]>
git.proxmox.com Git - grub2.git/blob - term/i386/pc/vga_text.c
ec3c0f56534394b53b9a0d3372a8f8d240a6b995
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2007 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/>.
19 #include <grub/machine/console.h>
20 #include <grub/cpu/io.h>
21 #include <grub/types.h>
26 static int grub_curr_x
, grub_curr_y
;
28 #define VGA_TEXT_SCREEN 0xb8000
30 #define CRTC_ADDR_PORT 0x3D4
31 #define CRTC_DATA_PORT 0x3D5
33 #define CRTC_CURSOR 0x0a
34 #define CRTC_CURSOR_ADDR_HIGH 0x0e
35 #define CRTC_CURSOR_ADDR_LOW 0x0f
37 #define CRTC_CURSOR_DISABLE (1 << 5)
40 screen_write_char (int x
, int y
, short c
)
42 ((short *) VGA_TEXT_SCREEN
)[y
* COLS
+ x
] = c
;
46 screen_read_char (int x
, int y
)
48 return ((short *) VGA_TEXT_SCREEN
)[y
* COLS
+ x
];
54 unsigned int pos
= grub_curr_y
* COLS
+ grub_curr_x
;
55 grub_outb (CRTC_CURSOR_ADDR_HIGH
, CRTC_ADDR_PORT
);
56 grub_outb (pos
>> 8, CRTC_DATA_PORT
);
57 grub_outb (CRTC_CURSOR_ADDR_LOW
, CRTC_ADDR_PORT
);
58 grub_outb (pos
& 0xFF, CRTC_DATA_PORT
);
65 if (grub_curr_y
< ROWS
- 1)
70 for (y
= 0; y
< ROWS
; y
++)
71 for (x
= 0; x
< COLS
; x
++)
72 screen_write_char (x
, y
, screen_read_char (x
, y
+ 1));
79 if (grub_curr_x
>= COLS
- 2)
86 grub_console_real_putchar (int c
)
92 screen_write_char (grub_curr_x
--, grub_curr_y
, ' ');
101 screen_write_char (grub_curr_x
,
102 grub_curr_y
, c
| (grub_console_cur_color
<< 8));
110 grub_console_getxy (void)
112 return (grub_curr_x
<< 8) | grub_curr_y
;
116 grub_console_gotoxy (grub_uint8_t x
, grub_uint8_t y
)
124 grub_console_cls (void)
127 for (i
= 0; i
< ROWS
* COLS
; i
++)
128 ((short *) VGA_TEXT_SCREEN
)[i
] = ' ' | (grub_console_cur_color
<< 8);
129 grub_console_gotoxy (0, 0);
133 grub_console_setcursor (int on
)
136 grub_outb (CRTC_CURSOR
, CRTC_ADDR_PORT
);
137 old
= grub_inb (CRTC_DATA_PORT
);
139 grub_outb (old
& ~CRTC_CURSOR_DISABLE
, CRTC_DATA_PORT
);
141 grub_outb (old
| CRTC_CURSOR_DISABLE
, CRTC_DATA_PORT
);