[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / arch / i386 / core / video_subr.c
blobc821cd02c7a289269a86c4d30636828fbb36fad0
1 /*
3 * modified from linuxbios code
4 * by Cai Qiang <rimy2000@hotmail.com>
6 */
8 #include "stddef.h"
9 #include "string.h"
10 #include <gpxe/io.h>
11 #include "console.h"
12 #include <gpxe/init.h>
13 #include "vga.h"
15 struct console_driver vga_console;
17 static char *vidmem; /* The video buffer */
18 static int video_line, video_col;
20 #define VIDBUFFER 0xB8000
22 static void memsetw(void *s, int c, unsigned int n)
24 unsigned int i;
25 u16 *ss = (u16 *) s;
27 for (i = 0; i < n; i++) {
28 ss[i] = ( u16 ) c;
32 static void video_init(void)
34 static int inited=0;
36 vidmem = (char *)phys_to_virt(VIDBUFFER);
38 if (!inited) {
39 video_line = 0;
40 video_col = 0;
42 memsetw(vidmem, VGA_ATTR_CLR_WHT, 2*1024); //
44 inited=1;
48 static void video_scroll(void)
50 int i;
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] = ' ';
57 static void vga_putc(int byte)
59 if (byte == '\n') {
60 video_line++;
61 video_col = 0;
63 } else if (byte == '\r') {
64 video_col = 0;
66 } else if (byte == '\b') {
67 video_col--;
69 } else if (byte == '\t') {
70 video_col += 4;
72 } else if (byte == '\a') {
73 //beep
74 //beep(500);
76 } else {
77 vidmem[((video_col + (video_line *COLS)) * 2)] = byte;
78 vidmem[((video_col + (video_line *COLS)) * 2) +1] = VGA_ATTR_CLR_WHT;
79 video_col++;
81 if (video_col < 0) {
82 video_col = 0;
84 if (video_col >= COLS) {
85 video_line++;
86 video_col = 0;
88 if (video_line >= LINES) {
89 video_scroll();
90 video_line--;
92 // move the cursor
93 write_crtc((video_col + (video_line *COLS)) >> 8, CRTC_CURSOR_HI);
94 write_crtc((video_col + (video_line *COLS)) & 0x0ff, CRTC_CURSOR_LO);
97 struct console_driver vga_console __console_driver = {
98 .putchar = vga_putc,
99 .disabled = 1,
102 struct init_fn video_init_fn __init_fn ( INIT_EARLY ) = {
103 .initialise = video_init,