some modify
This commit is contained in:
55
text.c
Normal file → Executable file
55
text.c
Normal file → Executable file
@@ -57,6 +57,11 @@ void textinit(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fsp) {
|
||||
|
||||
void textout(UINT8 code) {
|
||||
static UINTN x = 0, y = 0;
|
||||
if (code == '\n') {
|
||||
x = 0;
|
||||
y++;
|
||||
return;
|
||||
}
|
||||
for (int row = 0; row < 13; row++) {
|
||||
for (int column = 0; column < 8; column++) {
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel =
|
||||
@@ -64,7 +69,7 @@ void textout(UINT8 code) {
|
||||
y * 13 * buffer.HorizontalRes + row * buffer.HorizontalRes +
|
||||
8 * x + column;
|
||||
if ((font[code][row] >> (7 - column)) & 0x1)
|
||||
RGBtoPixel(pixel, 0x00FF00);
|
||||
RGBtoPixel(pixel, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
if (x < (buffer.HorizontalRes / 8) - 1)
|
||||
@@ -73,4 +78,50 @@ void textout(UINT8 code) {
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print(char *string) {
|
||||
do {
|
||||
textout(*string);
|
||||
string++;
|
||||
} while (*string != '\0');
|
||||
}
|
||||
|
||||
UINT64 pow(UINT64 base, UINT64 exponent) {
|
||||
UINT64 ans = 1;
|
||||
for (UINT64 i = 0; i < exponent; i++) {
|
||||
ans *= base;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
void printhex(UINT64 num, UINT8 digit) {
|
||||
if (digit == 0) {
|
||||
UINT8 maxdigit = 0;
|
||||
while (num >= pow(16, maxdigit)) maxdigit++;
|
||||
print("0x");
|
||||
if (maxdigit == 0) textout('0' + num);
|
||||
while (maxdigit) {
|
||||
UINT64 weight = pow(16, maxdigit - 1);
|
||||
UINT64 ans = num / weight;
|
||||
if (ans < 10)
|
||||
textout('0' + ans);
|
||||
else
|
||||
textout('A' + ans - 10);
|
||||
num -= ans * weight;
|
||||
maxdigit--;
|
||||
}
|
||||
} else {
|
||||
print("0x");
|
||||
while (digit) {
|
||||
UINT64 weight = pow(16, digit - 1);
|
||||
UINT64 ans = num / weight;
|
||||
if (ans < 10)
|
||||
textout('0' + ans);
|
||||
else
|
||||
textout('A' + ans - 10);
|
||||
num -= ans * weight;
|
||||
digit--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user