toaruos/text.h

63 lines
1023 B
C
Raw Normal View History

2018-03-06 12:18:53 +03:00
#pragma once
#ifdef __DEBUG__
unsigned short * textmemptr = (unsigned short *)0xB8000;
static void placech(unsigned char c, int x, int y, int attr) {
unsigned short *where;
unsigned att = attr << 8;
where = textmemptr + (y * 80 + x);
*where = c | att;
}
static int x = 0;
static int y = 0;
static void print(char * str) {
while (*str) {
if (*str == '\n') {
for (; x < 80; ++x) {
placech(' ', x, y, 0x00);
}
x = 0;
y += 1;
if (y == 24) {
y = 0;
}
} else {
placech(*str, x, y, 0x07);
x++;
if (x == 80) {
x = 0;
y += 1;
if (y == 24) {
y = 0;
}
}
}
str++;
}
}
static void print_hex(unsigned int value) {
char out[9] = {0};
for (int i = 7; i > -1; i--) {
out[i] = "0123456789abcdef"[(value >> (4 * (7 - i))) & 0xF];
}
print(out);
}
static void clear() {
x = 0;
y = 0;
for (int y = 0; y < 24; ++y) {
for (int x = 0; x < 80; ++x) {
placech(' ', x, y, 0x00);
}
}
}
#else
#define print(...)
#define clear()
#define print_hex(...)
#endif