#include "vga.h" #define VGA_WIDTH 80 #define VGA_HEIGHT 25 #define VGA_MEM_ADDR 0xb8000 #define CURSOR_HOME (VGA_HEIGHT-1)*VGA_WIDTH #define CURSOR_CHR 177; unsigned int cursor_loc = CURSOR_HOME; unsigned char fgcolor; unsigned char bgcolor; unsigned short blank; static unsigned char vga_entry_color(enum vga_color fg, enum vga_color bg) { return fg | bg << 4; } unsigned short vga_blank_entry() { return vga_entry_color(fgcolor, bgcolor) << 8; } void draw_cursor(void) { *((unsigned char *)VGA_MEM_ADDR + cursor_loc * 2) = CURSOR_CHR; *((unsigned char *)VGA_MEM_ADDR+1 + cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor); } void vga_set_color(enum vga_color fg, enum vga_color bg) { fgcolor = fg; bgcolor = bg; } void vga_init(enum vga_color fg, enum vga_color bg) { vga_set_color(fg, bg); blank = vga_blank_entry(); cls(); } void cls(void) { int i; for (i=0; i= VGA_HEIGHT*VGA_WIDTH) { scroll(); } draw_cursor(); } void vga_write(const char* text) { int i = 0; while(text[i]) { putchar(text[i]); i++; } } void vga_write_color( const char* text, enum vga_color fg, enum vga_color bg) { unsigned char prevfg = fgcolor; unsigned char prevbg = bgcolor; vga_set_color(fg, bg); vga_write(text); fgcolor = prevfg; bgcolor = prevbg; } void vga_write_line(const char* text) { if (cursor_loc != CURSOR_HOME) { scroll(); } vga_write(text); scroll(); } void vga_write_line_color(const char* text, enum vga_color fg, enum vga_color bg) { unsigned char prevfg = fgcolor; unsigned char prevbg = bgcolor; vga_set_color(fg, bg); vga_write_line(text); fgcolor = prevfg; bgcolor = prevbg; }