acpi.h: Small fixes and adding comments.
[coreboot.git] / src / console / vga_console.c
blob0a749f653cce47f61926090b48febd919d1a806f
1 /*
3 * modified from original freebios code
4 * by Steve M. Gehlbach <steve@kesa.com>
6 */
8 /*
9 * TODO:
10 * * make vga_console_init take FB location, columns, lines and starting
11 * column/line.
12 * * track a word offset, and not columns/lines. The offset is needed more
13 * often than columns/lines and the latter two can be calculated easily.
14 * * then implement real vga scrolling, instead of memcpying stuff around.
16 * -- libv.
19 #include <arch/io.h>
20 #include <string.h>
21 #include <pc80/vga_io.h>
22 #include <pc80/vga.h>
23 #include <console/console.h>
25 /* The video buffer, should be replaced by symbol in ldscript.ld */
26 static char *vidmem;
27 static int total_lines, total_columns;
28 static int current_line, current_column;
29 static int vga_console_inited = 0;
34 void vga_console_init(void)
36 vidmem = (char *) VGA_FB;
37 total_columns = VGA_COLUMNS;
38 total_lines = VGA_LINES;
39 current_column = 0;
40 current_line = 0;
42 vga_console_inited = 1;
45 static void vga_scroll(void)
47 int i;
49 memcpy(vidmem, vidmem + total_columns * 2, (total_lines - 1) * total_columns * 2);
50 for (i = (total_lines - 1) * total_columns * 2; i < total_lines * total_columns * 2; i += 2)
51 vidmem[i] = ' ';
54 static void
55 vga_tx_byte(unsigned char byte)
57 if (!vga_console_inited)
58 return;
60 switch (byte) {
61 case '\n':
62 current_line++;
63 current_column = 0;
64 break;
65 case '\r':
66 current_column = 0;
67 break;
68 case '\b':
69 current_column--;
70 break;
71 case '\t':
72 current_column += 4;
73 break;
74 case '\a': /* beep */
75 break;
76 default:
77 vidmem[((current_column + (current_line * total_columns)) * 2)] = byte;
78 vidmem[((current_column + (current_line * total_columns)) * 2) +1] = 0x07;
79 current_column++;
80 break;
83 if (current_column < 0)
84 current_column = 0;
85 if (current_column >= total_columns) {
86 current_line++;
87 current_column = 0;
89 if (current_line >= total_lines) {
90 vga_scroll();
91 current_line--;
94 /* move the cursor */
95 vga_cr_write(0x0E, (current_column + (current_line * total_columns)) >> 8);
96 vga_cr_write(0x0F, (current_column + (current_line * total_columns)) & 0x0ff);
99 static const struct console_driver vga_console __console ={
100 .init = 0,
101 .tx_byte = vga_tx_byte,
102 .rx_byte = 0,
103 .tst_byte = 0,