From 58afc2fc619a8be9b242f78d6135d736be23daf4 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sat, 3 Oct 2026 06:57:51 +0200 Subject: [PATCH] feat: separate VGA --- kernel/kmain.cpp | 22 ++++------------------ kernel/vga.cpp | 17 +++++++++++++++++ kernel/vga.hpp | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 kernel/vga.cpp create mode 100644 kernel/vga.hpp diff --git a/kernel/kmain.cpp b/kernel/kmain.cpp index f5fac18..91947c2 100644 --- a/kernel/kmain.cpp +++ b/kernel/kmain.cpp @@ -1,29 +1,15 @@ #include "arch/arch.hpp" #include "types.hpp" - -static volatile u16* const s_vga = reinterpret_cast(0xB8000); - -static constexpr u8 VGA_ROWS = 25; -static constexpr u8 VGA_COLS = 80; - -static inline void clrsc(void) { - for (u32 i = 0; i < VGA_ROWS * VGA_COLS; ++i) - s_vga[i] = 0; -} - -static inline void puts(const char* str, u8 row, u8 col) { - for (u32 off = 0; str[off] != '\0'; ++off) - s_vga[col + off + (VGA_COLS * row)] = 0x0700 | str[off]; -} +#include "vga.hpp" extern "C" void kmain(void) { - clrsc(); + vga::clear(); arch* arch = arch::get(); arch->init(); - puts("TowOS initialized!", 0, 0); - puts("Zdravstvuyte, tovarisch!", 1, 0); + vga::puts("TowOS initialized!", 0, 0); + vga::puts("Zdravstvuyte, tovarisch!", 0, 1); for (;;) __asm__ volatile("hlt"); diff --git a/kernel/vga.cpp b/kernel/vga.cpp new file mode 100644 index 0000000..e5aeb25 --- /dev/null +++ b/kernel/vga.cpp @@ -0,0 +1,17 @@ +#include "vga.hpp" + +static volatile u16* const s_vga = reinterpret_cast(0xB8000); + +void vga::clear(void) { + for (u32 i = 0; i < ROWS * COLS; ++i) + s_vga[i] = 0; +} + +void vga::putc(char ch, u8 col, u8 row) { + s_vga[col + (COLS * row)] = 0x0700 | ch; +} + +void vga::puts(const char* str, u8 col, u8 row) { + for (u32 off = 0; str[off] != '\0'; ++off) + putc(str[off], col + off, row); +} diff --git a/kernel/vga.hpp b/kernel/vga.hpp new file mode 100644 index 0000000..f576d3d --- /dev/null +++ b/kernel/vga.hpp @@ -0,0 +1,16 @@ +#ifndef VGA_HPP +#define VGA_HPP + +#include "types.hpp" + +class vga { +public: + static constexpr u8 ROWS = 25; + static constexpr u8 COLS = 80; +public: + static void clear(); + static void putc(char ch, u8 col, u8 row); + static void puts(const char* str, u8 col, u8 row); +}; + +#endif // VGA_HPP