From 31d8ae388a7ded576abd3e3d99c3d9193ea6d704 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 16 May 2020 14:10:08 -0400 Subject: small stub with fat info --- src/kernel/vga.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) (limited to 'src/kernel/vga.c') diff --git a/src/kernel/vga.c b/src/kernel/vga.c index d0170c0..8e438a8 100644 --- a/src/kernel/vga.c +++ b/src/kernel/vga.c @@ -1,14 +1,81 @@ #include +#include +#define VGA_COLUMNS 80 +#define VGA_LINES 25 #define VGA_START (uint16_t *)0x000b8000 -#define VGA_END (VGA_START + 80 * 25) +#define VGA_END (VGA_START + VGA_COLUMNS * VGA_LINES) uint16_t *cursor = VGA_START; uint16_t color = 0x1f00; +void vga_scroll() { + cursor = VGA_START; +} + +void vga_blank() { + uint32_t f = (color << 16) | color | 0x00200020; + uint32_t *p = (uint32_t *)VGA_START; + while (p < (uint32_t *)VGA_END) + *(p++) = f; + cursor = VGA_START; +} + +void vga_printch(uint8_t ch) { + if (ch == '\n') { + if ((cursor = cursor - (cursor - VGA_START) % VGA_COLUMNS + VGA_COLUMNS) == VGA_END) + vga_scroll(); + return; + } + *(cursor++) = color | ch; + if (cursor == VGA_END) + vga_scroll(); +} + void vga_printsz(uint8_t *sz) { - while (*sz) { - *(cursor++) = color | *(sz++); - if (cursor == VGA_END) - cursor = VGA_START; + while (*sz) + vga_printch(*(sz++)); +} + +void vga_printsn(uint8_t *sn, uint8_t n) { + while (n--) + vga_printch(*(sn++)); +} + +void vga_printu32(uint32_t n) { + bool zero = false; + for (uint32_t m = 1000000000; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } + } +} + +void vga_printu16(uint16_t n) { + bool zero = false; + for (uint16_t m = 10000; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } + } +} + +void vga_printu8(uint8_t n) { + bool zero = false; + for (uint8_t m = 100; m; m /= 10) { + uint8_t d = (n / m) % 10; + if (zero) + vga_printch(d + '0'); + else if (d) { + zero = true; + vga_printch(d + '0'); + } } } \ No newline at end of file -- cgit v1.2.3