mirror of
https://github.com/fergalmoran/ferglos.git
synced 2026-01-25 10:06:45 +00:00
40 lines
992 B
C++
40 lines
992 B
C++
#include "../include/stdio.h"
|
|
|
|
#include "../include/types.h"
|
|
|
|
void printf(const char* str) {
|
|
static uint16_t* VideoMemory = (uint16_t*)0xb8000;
|
|
static uint8_t x = 0, y = 0;
|
|
|
|
for (int i = 0; str[i] != '\0'; ++i) {
|
|
switch (str[i]) {
|
|
case '\n':
|
|
y++;
|
|
x = 0;
|
|
break;
|
|
default:
|
|
VideoMemory[80 * y + x] = (VideoMemory[80 * y + x] & 0xFF00) | str[i];
|
|
x++;
|
|
break;
|
|
}
|
|
|
|
//line feed after 80 chars (terminal width)
|
|
if (x >= 80) {
|
|
y++;
|
|
x = 0;
|
|
}
|
|
//we've reached max screen rows
|
|
if (y > 25) {
|
|
clear();
|
|
}
|
|
}
|
|
}
|
|
void clear() {
|
|
static uint16_t* VideoMemory = (uint16_t*)0xb8000;
|
|
static uint8_t x = 0, y = 0;
|
|
for (y = 0; y < 25; y++) {
|
|
for (x = 0; x < 80; x++) {
|
|
VideoMemory[80 * y + x] = (VideoMemory[80 * y + x] & 0xFF00) | ' ';
|
|
}
|
|
}
|
|
} |