Got memory info from multiboot & minor adjustments

This commit is contained in:
2025-02-19 10:46:35 +01:00
parent 609e10e13c
commit 8674d32f77
10 changed files with 384 additions and 23 deletions
+42 -4
View File
@@ -1,4 +1,5 @@
#include <kernel.h>
#include <system.h>
#include <tty.h>
struct {
@@ -6,14 +7,17 @@ struct {
size_t col;
uint8_t attr;
uint8_t* buf;
size_t updateWait;
} ctx;
void tty_init(void) {
int tty_init(void) {
ctx.row = 0;
ctx.col = 0;
ctx.attr = 0x07;
ctx.buf = (uint8_t*)VGA_MEMORY;
tty_clear();
return 0;
}
void tty_clear(void) {
@@ -27,6 +31,31 @@ void tty_setattr(uint8_t attr) {
ctx.attr = attr;
}
void tty_enableCursor(uint8_t start, uint8_t end) {
outb(0x3d4, 0x0a);
outb(0x3d5, (inb(0x3d5) & 0xc0) | start);
outb(0x3d4, 0x0b);
outb(0x3d5, (inb(0x3d5) & 0xe0) | end);
}
void tty_disableCursor(void) {
outb(0x3d4, 0x0a);
outb(0x3d5, 0x20);
}
void tty_updateCursor(void) {
if (ctx.updateWait > 0) {
ctx.updateWait--;
return;
}
uint16_t pos = ctx.row * VGA_WIDTH + ctx.col;
outb(0x3d4, 0x0f);
outb(0x3d5, (uint8_t)pos);
outb(0x3d4, 0x0e);
outb(0x3d5, (uint8_t)(pos >> 8));
}
// TODO:
void tty_scroll(void) {
ctx.row = 0;
@@ -44,8 +73,7 @@ void tty_putc(char c) {
if (c == '\n') {
ctx.col = 0;
ctx.row++;
if (ctx.row >= VGA_HEIGHT) tty_scroll();
return;
goto scroll_check;
}
tty_putat(c, ctx.row, ctx.col++);
@@ -54,10 +82,20 @@ void tty_putc(char c) {
ctx.row++;
}
scroll_check:
if (ctx.row >= VGA_HEIGHT) tty_scroll();
tty_updateCursor();
}
void tty_write(char* buf, size_t len) {
ctx.updateWait = len - 1;
for (int i = 0; i < len; i++) tty_putc(buf[i]);
}
void tty_puts(char* s) {
while (*s != '\0') tty_putc(*s++);
size_t len = 0;
char* p = s;
while (*p++ != '\0') len++;
tty_write(s, len);
}