#include "system/common.hpp"
void hide_cursor() {
asm volatile (
"movw $0x3D4, %%dx\n" // select cursor start register
"movb $0, %%al\n"
"outb %%al, %%dx\n"
"movw $0x3D5, %%dx\n" // select cursor end register
"movb $0, %%al\n"
"outb %%al, %%dx\n"
:
:
: "dx", "al"
);
}
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
static inline void outb(uint16_t port, uint8_t val) {
__asm__ volatile ("outb %0, %1" : : "a"(val), "Nd"(port));
}
void set_cursor_position(int row, int col) {
unsigned short position = 80 * row + col;
// Write the high byte
outb(0x3D4, 0x0E);
outb(0x3D5, (position >> 8) & 0xFF);
// Write the low byte
outb(0x3D4, 0x0F);
outb(0x3D5, position & 0xFF);
}
void clear_screen() {
volatile char* video_memory = (char*)0xB8000;
const int screen_size = 80 * 25; // 80 columns x 25 rows
for (int i = 0; i < screen_size; ++i) {
video_memory[2*i] = ' '; // Character space
video_memory[2*i + 1] = 0x07; // Attribute (white on black)
}
}
void print_string(const char* str) {
volatile char* video_memory = (char*)0xB8000;
int i = 0;
while (str[i] != '\0') {
video_memory[2*i] = str[i]; // Character space
video_memory[2*i + 1] = 0x07; // Attribute (white on black)
i++;
}
}
extern "C" void kmain()
{
u8* address = (u8*) 0xb8000;
const u8* string = "[CrystalOS Kernel] Hello from C++";
u16 stringSize = 33;
clear_screen();
set_cursor_position(1, 0);
hide_cursor();
for (u16 i = 0; i < stringSize; i++)
{
*address = (u8) string[i];
address += 1;
*address = (u8) 0xA0;
address += 1;
}
while (true);
}