2018-03-06 12:18:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
2018-07-06 17:53:14 +03:00
|
|
|
static int txt_debug = 0;
|
2018-03-06 17:09:06 +03:00
|
|
|
|
2018-03-06 12:18:53 +03:00
|
|
|
unsigned short * textmemptr = (unsigned short *)0xB8000;
|
|
|
|
static void placech(unsigned char c, int x, int y, int attr) {
|
2018-07-06 17:53:14 +03:00
|
|
|
#ifdef EFI_PLATFORM
|
|
|
|
unsigned short ch;
|
|
|
|
switch (c) {
|
|
|
|
case '\030':
|
|
|
|
ch = L'↑';
|
|
|
|
break;
|
|
|
|
case '\031':
|
|
|
|
ch = L'↓';
|
|
|
|
break;
|
|
|
|
case '\032':
|
|
|
|
ch = L'←';
|
|
|
|
break;
|
|
|
|
case '\033':
|
|
|
|
ch = L'→';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ch = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uint16_t string[] = {ch, 0};
|
|
|
|
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, attr);
|
|
|
|
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, x, y);
|
|
|
|
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, string);
|
|
|
|
#else
|
2018-03-06 12:18:53 +03:00
|
|
|
unsigned short *where;
|
|
|
|
unsigned att = attr << 8;
|
|
|
|
where = textmemptr + (y * 80 + x);
|
|
|
|
*where = c | att;
|
2018-07-06 17:53:14 +03:00
|
|
|
#endif
|
2018-03-06 12:18:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int x = 0;
|
|
|
|
static int y = 0;
|
2018-03-06 17:47:42 +03:00
|
|
|
static int attr = 0x07;
|
2018-03-06 17:09:06 +03:00
|
|
|
static void print_(char * str) {
|
2018-03-06 12:18:53 +03:00
|
|
|
while (*str) {
|
|
|
|
if (*str == '\n') {
|
|
|
|
for (; x < 80; ++x) {
|
2018-03-06 17:47:42 +03:00
|
|
|
placech(' ', x, y, attr);
|
2018-03-06 12:18:53 +03:00
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y += 1;
|
|
|
|
if (y == 24) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2018-03-06 17:47:42 +03:00
|
|
|
placech(*str, x, y, attr);
|
2018-03-06 12:18:53 +03:00
|
|
|
x++;
|
|
|
|
if (x == 80) {
|
|
|
|
x = 0;
|
|
|
|
y += 1;
|
|
|
|
if (y == 24) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 17:53:14 +03:00
|
|
|
static void move_cursor(int _x, int _y) {
|
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_attr(int _attr) {
|
|
|
|
attr = _attr;
|
|
|
|
}
|
|
|
|
|
2018-03-06 17:47:42 +03:00
|
|
|
static void print_banner(char * str) {
|
2018-06-09 11:58:29 +03:00
|
|
|
if (!str) {
|
|
|
|
for (int i = 0; i < 80; ++i) {
|
|
|
|
placech(' ', i, y, attr);
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
return;
|
|
|
|
}
|
2018-03-06 17:47:42 +03:00
|
|
|
int len = 0;
|
|
|
|
char *c = str;
|
|
|
|
while (*c) {
|
|
|
|
len++;
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
int off = (80 - len) / 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < 80; ++i) {
|
|
|
|
placech(' ', i, y, attr);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < len; ++i) {
|
|
|
|
placech(str[i], i + off, y, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
|
2018-07-12 04:53:36 +03:00
|
|
|
#ifdef EFI_PLATFORM
|
|
|
|
static void print_int_(unsigned int value) {
|
|
|
|
unsigned int n_width = 1;
|
|
|
|
unsigned int i = 9;
|
|
|
|
while (value > i && i < UINT32_MAX) {
|
|
|
|
n_width += 1;
|
|
|
|
i *= 10;
|
|
|
|
i += 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[n_width+1];
|
|
|
|
buf[n_width] = 0;
|
|
|
|
i = n_width;
|
|
|
|
while (i > 0) {
|
|
|
|
unsigned int n = value / 10;
|
|
|
|
int r = value % 10;
|
|
|
|
buf[i - 1] = r + '0';
|
|
|
|
i--;
|
|
|
|
value = n;
|
|
|
|
}
|
|
|
|
print_(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-06 17:09:06 +03:00
|
|
|
static void print_hex_(unsigned int value) {
|
2018-03-06 12:18:53 +03:00
|
|
|
char out[9] = {0};
|
|
|
|
for (int i = 7; i > -1; i--) {
|
|
|
|
out[i] = "0123456789abcdef"[(value >> (4 * (7 - i))) & 0xF];
|
|
|
|
}
|
2018-03-06 17:09:06 +03:00
|
|
|
print_(out);
|
2018-03-06 12:18:53 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 17:09:06 +03:00
|
|
|
static void clear_() {
|
2018-03-06 12:18:53 +03:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
for (int y = 0; y < 24; ++y) {
|
|
|
|
for (int x = 0; x < 80; ++x) {
|
|
|
|
placech(' ', x, y, 0x00);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-06 17:09:06 +03:00
|
|
|
|
2018-07-06 17:53:14 +03:00
|
|
|
#define print(s) do {if (txt_debug) {print_(s);}} while(0)
|
|
|
|
#define clear() do {if (txt_debug) {clear_();}} while(0)
|
|
|
|
#define print_hex(d) do {if (txt_debug) {print_hex_(d);}} while(0)
|
2018-03-06 12:18:53 +03:00
|
|
|
|