idt
This commit is contained in:
62
src/vga.c
62
src/vga.c
@@ -116,7 +116,6 @@ void vga_print_success(const char* message)
|
||||
vga_print_colored("success", VGA_GREEN);
|
||||
vga_print(" ] ");
|
||||
vga_print(message);
|
||||
vga_print("\n");
|
||||
}
|
||||
|
||||
void vga_print_error(const char* message)
|
||||
@@ -125,5 +124,64 @@ void vga_print_error(const char* message)
|
||||
vga_print_colored("error", VGA_RED);
|
||||
vga_print(" ] ");
|
||||
vga_print(message);
|
||||
vga_print("\n");
|
||||
}
|
||||
|
||||
static void reverse(char* str, int length)
|
||||
{
|
||||
int start = 0;
|
||||
int end = length - 1;
|
||||
while (start < end)
|
||||
{
|
||||
char temp = str[start];
|
||||
str[start] = str[end];
|
||||
str[end] = temp;
|
||||
start++;
|
||||
end--;
|
||||
}
|
||||
}
|
||||
|
||||
static int uitoa(unsigned int value, char* buffer)
|
||||
{
|
||||
int i = 0;
|
||||
if (value == 0)
|
||||
{
|
||||
buffer[i++] = '0';
|
||||
buffer[i] = '\0';
|
||||
return i;
|
||||
}
|
||||
|
||||
while (value > 0)
|
||||
{
|
||||
buffer[i++] = (value % 10) + '0';
|
||||
value /= 10;
|
||||
}
|
||||
|
||||
buffer[i] = '\0';
|
||||
reverse(buffer, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
void vga_print_uint(unsigned int value)
|
||||
{
|
||||
char buffer[11];
|
||||
uitoa(value, buffer);
|
||||
vga_print(buffer);
|
||||
}
|
||||
|
||||
void vga_print_int(int value)
|
||||
{
|
||||
char buffer[12];
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
vga_print("-");
|
||||
unsigned int abs_val = (unsigned int)(-value);
|
||||
uitoa(abs_val, buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
uitoa((unsigned int)value, buffer);
|
||||
}
|
||||
|
||||
vga_print(buffer);
|
||||
}
|
||||
Reference in New Issue
Block a user