NutsOS/kernel/src/print.c
2020-04-17 17:44:23 +02:00

130 lines
2.2 KiB
C

/* print.c - This file is a part of NutsOS
*
* NutsOS
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* NutsOS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* NutsOS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
*
* Valentin Verdier <valentin.verdier03@gmail.com>
*/
#include "print.h"
#include "types.h"
#include "utils.h"
#include "asm_x86.h"
#include <stdarg.h>
static printArgs(char* str, T_byte color, va_list args) {
}
void fatalError(char *str)
{
print("FATAL ERROR : %s\n", 0x47, str);
_ClearInterrupt();
asm("hlt");
}
void putc(char c) {
}
void print(char *str, char color, ...)
{
va_list arg;
va_start(arg, color);
while(*str != 0)
{
if(*str == '%')
{
if(str[1] == 'd')
{
printDec(va_arg(arg, bits32), color);
str+=2;
}
else if(str[1] == 'x')
{
printHex(va_arg(arg, bits32), color);
str+=2;
}
else if(str[1] == 'b')
{
printBin(va_arg(arg, bits32), color);
str+=2;
}
else if(str[1] == 's')
{
print(va_arg(arg, char*), color);
str+=2;
}
else
{
PutCharVterm('%', color, VirtualTerminal_0);
str++;
}
}
else
{
putcVterm(*str, color, VirtualTerminal_0);
str++;
}
}
va_end(arg);
}
void printDec(bits32 a, char color)
{
char buffer[11];
char *str = buffer;
IntToChar(a, str, 10);
while(*str != 0)
{
PutCharVterm(*str, color, VirtualTerminal_0);
str++;
}
}
void printHex(bits32 a, char color)
{
char buffer[9];
char *str = buffer;
IntToChar(a, str, 16);
while(*str != 0)
{
PutCharVterm(*str, color, VirtualTerminal_0);
str++;
}
}
void printBin(bits32 a, char color)
{
char buffer[33];
char *str = buffer;
IntToChar(a, str, 2);
while(*str != 0)
{
PutCharVterm(*str, color, VirtualTerminal_0);
str++;
}
}