#include "io/Serial.h" #include "io/IO.h" #include #include #define COM1 0x3f8 void Serial::wait() { while (!(IO::inb(COM1 + 5) & 0x20)) { asm volatile("pause"); } } void Serial::write(const char* string, size_t size) { for (size_t i = 0; i < size; i++) { wait(); IO::outb(COM1, *(string + i)); } } void Serial::print(const char* string) { Serial::write(string, strlen(string)); } void Serial::println(const char* string) { Serial::write(string, strlen(string)); wait(); IO::outb(COM1, '\n'); } static const char* format_color(Color& color) { static char output[20]; snprintf(output, sizeof(output), "\x1b[38;2;%d;%d;%dm", color.red, color.green, color.blue); return output; } void Serial::set_color(Color& color) { Serial::print(format_color(color)); } void Serial::reset_color() { Serial::print("\x1b[0m"); }