wip: add blinking cursor

This commit is contained in:
Mathieu Maret 2018-11-14 18:03:11 +01:00
parent 9b46b60b7a
commit 146a06f0e6
3 changed files with 38 additions and 14 deletions

View File

@ -29,6 +29,7 @@ void kmain(unsigned long magic, unsigned long addr)
{
unsigned long upper_mem = 0;
VGASetup(BLACK, GREEN);
cursorEnable(14, 15);
printf("Setting up Interruptions\n");
gdtSetup();

View File

@ -130,14 +130,14 @@ void vprintf(const char *format, va_list ap)
}
}
void printf(const char *format, ...){
void printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
void printString(const char *str)
{
while (*str) {
@ -154,22 +154,16 @@ void printChar(const char str)
vgaScrollUp();
line--;
}
}
else if(str == '\r')
{
} else if (str == '\r') {
col = 0;
}
else if(str == '\b')
{
} else if (str == '\b') {
col--;
if (col < 0) {
col = VGA_WIDTH - 1;
line--;
}
printCharDetails(' ', vgaColor, vgaBgColor, col, line);
}
else
{
} else {
printCharDetails(str, vgaColor, vgaBgColor, col++, line);
if (col == VGA_WIDTH) {
col = 0;
@ -180,6 +174,7 @@ void printChar(const char str)
line--;
}
}
cursorMove(col - 1, line);
}
void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY)
@ -193,3 +188,28 @@ void printStringDetails(const char *str, uint color, uint bgColor, int startX, i
i++;
}
}
void cursorEnable(uint8_t cursor_start, uint8_t cursor_end)
{
outb(0x3D4, 0x0A);
outb(0x3D5, (inb(0x3D5) & 0xC0) | cursor_start);
outb(0x3D4, 0x0B);
outb(0x3D5, (inb(0x3D5) & 0xE0) | cursor_end);
}
void cursorDisable(void)
{
outb(0x3D4, 0x0A);
outb(0x3D5, 0x20);
}
void cursorMove(int x, int y)
{
uint16_t pos = y * VGA_WIDTH + x;
outb(0x3D4, 0x0F);
outb(0x3D5, (uint8_t)(pos & 0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
}

View File

@ -27,3 +27,6 @@ void printStringDetails(const char *str, uint color, uint bgColor, int startX, i
void printString(const char *str);
void printChar(const char str);
void vgaScrollUp(void);
void cursorEnable(uint8_t cursor_start, uint8_t cursor_end);
void cursorDisable(void);
void cursorMove(int x, int y);