- Initial checkin of the freebios2 tree
[coreboot.git] / src / console / vga_console.c
1 /*
2  *
3  * modified from original freebios code
4  * by Steve M. Gehlbach <steve@kesa.com>
5  *
6  */
7
8 #include <arch/io.h>
9 #include <string.h>
10 #include <pc80/vga.h>
11 #include <console/console.h>
12
13 void beep(int ms);
14
15 static char *vidmem;            /* The video buffer, should be replaced by symbol in ldscript.ld */
16 int vga_line, vga_col;
17
18 #define VIDBUFFER 0xB8000;
19
20 static void memsetw(void *s, int c, unsigned int n)
21 {
22         int i;
23          u16 *ss = (u16 *) s;
24
25         for (i = 0; i < n; i++) {
26                 ss[i] = ( u16 ) c;
27         }
28 }
29
30 static void vga_init(void)
31 {
32
33         // these are globals
34         vga_line = 0;
35         vga_col = 0;
36         vidmem = (unsigned char *) VIDBUFFER;
37         
38         // mainboard or chip specific init routines
39         // also loads font
40         vga_hardware_fixup();
41         
42         // set attributes, char for entire screen
43         // font should be previously loaded in 
44         // device specific code (vga_hardware_fixup)
45          memsetw(vidmem, VGA_ATTR_CLR_WHT, 2*1024); //
46 }
47
48 static void vga_scroll(void)
49 {
50         int i;
51
52         memcpy(vidmem, vidmem + COLS * 2, (LINES - 1) * COLS * 2);
53         for (i = (LINES - 1) * COLS * 2; i < LINES * COLS * 2; i += 2)
54                 vidmem[i] = ' ';
55 }
56
57 static void vga_tx_byte(unsigned char byte)
58 {
59         if (byte == '\n') {
60                 vga_line++;
61                 vga_col = 0;
62
63         } else if (byte == '\r') {
64                 vga_col = 0;
65
66         } else if (byte == '\b') {
67                 vga_col--;
68
69         } else if (byte == '\t') {
70                 vga_col += 4;
71
72         } else if (byte == '\a') {
73                 //beep
74                 beep(500);
75
76         } else {
77                 vidmem[((vga_col + (vga_line *COLS)) * 2)] = byte;
78                 vidmem[((vga_col + (vga_line *COLS)) * 2) +1] = VGA_ATTR_CLR_WHT;
79                 vga_col++;
80         }
81         if (vga_col < 0) {
82                 vga_col = 0;
83         }
84         if (vga_col >= COLS) {
85                 vga_line++;
86                 vga_col = 0;
87         }
88         if (vga_line >= LINES) {
89                 vga_scroll();
90                 vga_line--;
91         }
92         // move the cursor
93         write_crtc((vga_col + (vga_line *COLS)) >> 8, CRTC_CURSOR_HI);
94         write_crtc((vga_col + (vga_line *COLS)) & 0x0ff, CRTC_CURSOR_LO);
95 }
96
97 struct console_driver {
98         .init    = vga_init,
99         .tx_byte = vga_tx_byte,
100 };