os3/stage1/screen.c
John 5b17b79264
[Stage1] Fix linker to force main() at base address
[Stage1] Add basic write-to-screen utilities for VGA mode 3
2023-01-14 02:50:37 +01:00

39 lines
636 B
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') {
y = (y + 1) % 25;
x = 0;
str++;
continue;
}
write_character(c);
x++;
if (x >= 80) {
y = (y + 1) % 25;
x = 0;
}
str++;
i++;
} while(i < max_len || max_len == 0);
}