A bit of cleanup in vga functions

This commit is contained in:
Thomas Lovén 2017-12-14 23:49:46 +01:00
parent 15bbfd6e6a
commit e6d046d593

View File

@ -16,9 +16,10 @@ uint8_t format;
void vga_init() void vga_init()
{ {
vidmem = VGA_MEMORY; vidmem = VGA_MEMORY;
memset(vidmem, 0, VGA_SIZE*2); memset(vidmem, 0, VGA_SIZE*sizeof(struct vga_cell));
format = 0x7; // White text on black background
format = 0x07;
} }
void movecursor() void movecursor()
@ -38,14 +39,12 @@ void scroll()
{ {
while(cursor >= VGA_SIZE) while(cursor >= VGA_SIZE)
{ {
for(int i = 0; i < VGA_ROWS-1; i++) // Move everything up one row
for(int j = 0; j < VGA_COLS; j++) memmove(buffer, &buffer[VGA_POS(1,0)], VGA_COLS*(VGA_ROWS-1)*sizeof(struct vga_cell));
buffer[VGA_POS(i, j)] = buffer[VGA_POS(i+1, j)]; // Clear last row
for(int i = 0; i < VGA_COLS; i++) memset(&buffer[VGA_POS(VGA_ROWS-1, 0)], 0, VGA_COLS*sizeof(struct vga_cell));
buffer[VGA_POS(VGA_ROWS-1, i)] = (struct vga_cell){.c='\0', .f=format};
cursor -= VGA_COLS; cursor -= VGA_COLS;
} }
} }
void vga_write(char c) void vga_write(char c)
@ -53,12 +52,10 @@ void vga_write(char c)
switch(c) switch(c)
{ {
case '\n': case '\n':
cursor += VGA_COLS; cursor += VGA_COLS - VGA_COL(cursor);
cursor -= VGA_COL(cursor);
break; break;
default: default:
buffer[cursor] = (struct vga_cell){.c = c, .f=format}; buffer[cursor++] = (struct vga_cell){.c = c, .f=format};
cursor++;
} }
scroll(); scroll();
flush(); flush();