diff --git a/vga_drv/main.c b/vga_drv/main.c index e9436dd..6bff505 100644 --- a/vga_drv/main.c +++ b/vga_drv/main.c @@ -1,3 +1,9 @@ +#include + int main() { - + text_fb_info info; + info.address=map_phys((void*)0xB8000,10); + info.width=80; + info.height=25; + vga_init(info); } diff --git a/vga_drv/ports.c b/vga_drv/ports.c new file mode 100644 index 0000000..5991314 --- /dev/null +++ b/vga_drv/ports.c @@ -0,0 +1,31 @@ +#include + +uint8_t port_byte_in(uint16_t port) { + uint8_t result; + asm("in %%dx, %%al":"=a"(result):"d"(port)); + return result; +} + +void port_byte_out(uint16_t port,uint8_t data) { + asm("out %%al, %%dx":: "a"(data),"d"(port)); +} + +uint16_t port_word_in(uint16_t port) { + uint16_t result; + asm("in %%dx, %%ax":"=a"(result):"d"(port)); + return result; +} + +void port_word_out(uint16_t port,uint16_t data) { + asm("out %%ax, %%dx":: "a" (data), "d" (port)); +} + +uint32_t port_long_in(uint16_t port) { + uint32_t result; + asm("inl %%dx, %%eax":"=a"(result):"d"(port)); + return result; +} + +void port_long_out(uint16_t port,uint32_t data) { + asm("outl %%eax, %%dx":: "a" (data), "d" (port)); +} diff --git a/vga_drv/ports.h b/vga_drv/ports.h new file mode 100644 index 0000000..4f5c6e1 --- /dev/null +++ b/vga_drv/ports.h @@ -0,0 +1,12 @@ +#ifndef PORTS_H +#define PORTS_H + +#include + +uint8_t port_byte_in(uint16_t port); +void port_byte_out(uint16_t port,uint8_t data); +uint16_t port_word_in(uint16_t port); +void port_word_out(uint16_t port,uint16_t data); +uint32_t port_long_in(uint16_t port); +void port_long_out(uint16_t port,uint32_t data); +#endif diff --git a/vga_drv/vga.c b/vga_drv/vga.c new file mode 100644 index 0000000..67fbc55 --- /dev/null +++ b/vga_drv/vga.c @@ -0,0 +1,91 @@ +#include +#include "vga.h" +#include "ports.h" +#include +#include +#define xy_to_indx(x,y) ((x+(y*width))*2) +static char* screen; +static int width; +static int height; +static int x; +static int y; +static vga_colors fg_color; +static vga_colors bg_color; +static char* scroll_buf[0xfa0]; + + +static void set_char(int x,int y,char c) { + screen[xy_to_indx(x,y)]=c; + screen[xy_to_indx(x,y)+1]=(bg_color<<4)|fg_color; +} + +void vga_clear() { + for (int y=0;y>8); +} + +void vga_init(text_fb_info framebuffer_info) { + x=0; + y=0; + fg_color=VGA_WHITE; + bg_color=VGA_BLACK; + screen=framebuffer_info.address; + width=framebuffer_info.width; + height=framebuffer_info.height; + port_byte_out(0x3D4,0xA); + port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xC0)|14); + port_byte_out(0x3D4,0xB); + port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xE0)|15); + set_cursor(0,0); + vga_clear(); +} + +void vga_write_string(const char* string) { + for (size_t i=0;i