67 lines
1.2 KiB
C
67 lines
1.2 KiB
C
#include <vga.h>
|
|
#include <memory.h>
|
|
#include <ports.h>
|
|
|
|
void *vidmem;
|
|
struct vga_cell{
|
|
uint8_t c;
|
|
uint8_t f;
|
|
}__attribute__((packed));
|
|
|
|
struct vga_cell buffer[VGA_SIZE];
|
|
|
|
uint64_t cursor;
|
|
uint8_t format;
|
|
|
|
void vga_init()
|
|
{
|
|
vidmem = VGA_MEMORY;
|
|
memset(vidmem, 0, VGA_SIZE*2);
|
|
|
|
format = 0x7;
|
|
}
|
|
|
|
void movecursor()
|
|
{
|
|
outb(VGA_ADDRESS_PORT, VGA_REGISTER_CURSOR_POS_LOW);
|
|
outb(VGA_DATA_PORT, (uint8_t)(cursor & 0xFF));
|
|
outb(VGA_ADDRESS_PORT, VGA_REGISTER_CURSOR_POS_HIGH);
|
|
outb(VGA_DATA_PORT, (uint8_t)((cursor >> 8) & 0xFF));
|
|
}
|
|
|
|
void flush()
|
|
{
|
|
memcpy(vidmem, buffer, sizeof(buffer));
|
|
}
|
|
|
|
void scroll()
|
|
{
|
|
while(cursor >= VGA_SIZE)
|
|
{
|
|
for(int i = 0; i < VGA_ROWS-1; i++)
|
|
for(int j = 0; j < VGA_COLS; j++)
|
|
buffer[VGA_POS(i, j)] = buffer[VGA_POS(i+1, j)];
|
|
for(int i = 0; i < VGA_COLS; i++)
|
|
buffer[VGA_POS(VGA_ROWS-1, i)] = (struct vga_cell){.c='\0', .f=format};
|
|
cursor -= VGA_COLS;
|
|
}
|
|
|
|
}
|
|
|
|
void vga_write(char c)
|
|
{
|
|
switch(c)
|
|
{
|
|
case '\n':
|
|
cursor += VGA_COLS;
|
|
cursor -= VGA_COL(cursor);
|
|
break;
|
|
default:
|
|
buffer[cursor] = (struct vga_cell){.c = c, .f=format};
|
|
cursor++;
|
|
}
|
|
scroll();
|
|
flush();
|
|
movecursor();
|
|
}
|