os3/stage1/screen.c
John 17a18e4f91
[Stage1] Start IDT implementation
[Stage1] Screen.h improvements
2023-01-18 10:59:09 +01:00

83 lines
No EOL
1.2 KiB
C

#include "include/screen.h"
#include "../os3_common/datatypes.h"
#include "../os3_common/packing.h"
int x = 0;
int y = 0;
void write_character(char c) {
os_u16 color_byte = 0x0A;
os_u16* vram = (os_u16*) 0xB8000;
os_u16* cursor_pos = vram + ((y * 80) + x);
*cursor_pos = c | (color_byte << 8);
}
void write_string(const char* str, int max_len) {
int i = 0;
do {
char c = *str;
if (c == 0) {
return;
}
if (c == '\n') {
if (y == 24) {
clear_screen();
}
y = (y + 1) % 25;
x = 0;
str++;
continue;
}
write_character(c);
x++;
if (x >= 80) {
if (y == 24) {
clear_screen();
}
y = (y + 1) % 25;
x = 0;
}
str++;
i++;
} while(i < max_len || max_len == 0);
}
void clear_screen() {
os_u16* ptr = (os_u16*) 0xB8000;
for (int y = 0; y < 25; y++) {
for (int x = 0; x < 80; x++) {
*ptr = 0;
ptr++;
}
}
x = 0;
y = 0;
}
void write_number(os_u32 number) {
char buffer[32];
char buffer_2[32];
os_s32 i = 1;
while(i < 32) {
if (i > 1 && number == 0) {
break;
}
buffer[i] = ((char)(number % 10)) + '0';
i++;
number /= 10;
}
i--;
buffer[0] = '\0';
char* buffer_2_ptr = buffer_2;
while(i >= 0) {
*buffer_2_ptr = buffer[i];
buffer_2_ptr++;
i--;
}
write_string(buffer_2, 0);
}