VGA driver deprecated
This commit is contained in:
parent
5ee43c6e9f
commit
5e7356f58e
2 changed files with 0 additions and 121 deletions
97
src/vga.c
97
src/vga.c
|
@ -1,97 +0,0 @@
|
|||
#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;i++) {
|
||||
*((unsigned short *) VGA_MEM_ADDR+i) = blank;
|
||||
}
|
||||
}
|
||||
void scroll(void) {
|
||||
int y;
|
||||
int x;
|
||||
*((unsigned short *) VGA_MEM_ADDR+cursor_loc) = blank;
|
||||
for (y=0;y<VGA_HEIGHT;y++) {
|
||||
for (x = 0;x<VGA_WIDTH;x++) {
|
||||
*((unsigned short *) VGA_MEM_ADDR+y*VGA_WIDTH+x) = *((unsigned short *) VGA_MEM_ADDR+(y+1)*VGA_WIDTH+x);
|
||||
}
|
||||
}
|
||||
for (x=0;x<VGA_WIDTH;x++) {
|
||||
*((unsigned short *) VGA_MEM_ADDR+CURSOR_HOME+x) = blank;
|
||||
}
|
||||
cursor_loc = CURSOR_HOME;
|
||||
draw_cursor();
|
||||
}
|
||||
void putchar(unsigned char chr) {
|
||||
if (chr == '\n') {
|
||||
scroll();
|
||||
return;
|
||||
}
|
||||
*((unsigned char *) VGA_MEM_ADDR+cursor_loc * 2) = chr;
|
||||
*((unsigned char *) VGA_MEM_ADDR+1+cursor_loc * 2) = vga_entry_color(fgcolor, bgcolor);
|
||||
cursor_loc++;
|
||||
if (cursor_loc >= 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;
|
||||
}
|
24
src/vga.h
24
src/vga.h
|
@ -1,24 +0,0 @@
|
|||
#ifndef HEADER_VGA
|
||||
#define HEADER_VGA
|
||||
|
||||
enum vga_color {
|
||||
VGA_COLOR_BLACK = 0,
|
||||
VGA_COLOR_BLUE = 1,
|
||||
VGA_COLOR_GREEN = 2,
|
||||
VGA_COLOR_CYAN = 3,
|
||||
VGA_COLOR_RED = 4,
|
||||
VGA_COLOR_MAGENTA = 5,
|
||||
VGA_COLOR_ORANGE = 6,
|
||||
VGA_COLOR_GREY = 7,
|
||||
VGA_COLOR_GRAY = 7,
|
||||
};
|
||||
|
||||
void cls(void);
|
||||
void vga_init(enum vga_color fg, enum vga_color bg);
|
||||
|
||||
void vga_write(const char* text);
|
||||
void vga_write_color( const char* text, enum vga_color fg, enum vga_color bg);
|
||||
void vga_write_line(const char* text);
|
||||
void vga_write_line_color( const char* text, enum vga_color fg, enum vga_color bg);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue