2019-07-03 12:37:16 +02:00
|
|
|
#include "stdio.h"
|
|
|
|
#include "string.h"
|
2019-07-03 18:12:57 +02:00
|
|
|
#include "../drivers/tty.h"
|
2019-07-03 12:37:16 +02:00
|
|
|
|
|
|
|
int printf(const char *format, ...) {
|
2019-07-03 21:04:05 +02:00
|
|
|
uint8_t buf[20],c,*s;
|
2019-07-03 12:37:16 +02:00
|
|
|
int val;
|
|
|
|
int32_t uval;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
|
2019-07-03 21:04:05 +02:00
|
|
|
for(size_t i = 0; i < strlen((uint8_t*)format); i++) {
|
2019-07-03 12:37:16 +02:00
|
|
|
if(format[i] == '%') {
|
|
|
|
i++;
|
|
|
|
while(format[i] == ' ')
|
|
|
|
i++;
|
|
|
|
|
|
|
|
switch(format[i]) {
|
|
|
|
case 'i':
|
|
|
|
val = va_arg(ap, int);
|
|
|
|
itoa(val, buf, 10);
|
2019-07-03 18:12:57 +02:00
|
|
|
kprint(buf);
|
2019-07-03 12:37:16 +02:00
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
uval = va_arg(ap, uint32_t);
|
|
|
|
uitoa(uval, buf, 16);
|
2019-07-03 18:12:57 +02:00
|
|
|
kprint(buf);
|
2019-07-03 12:37:16 +02:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
uval = va_arg(ap, uint32_t);
|
|
|
|
uitoa(uval, buf, 10);
|
2019-07-03 18:12:57 +02:00
|
|
|
kprint(buf);
|
2019-07-03 12:37:16 +02:00
|
|
|
break;
|
|
|
|
case 'c':
|
2019-07-03 21:04:05 +02:00
|
|
|
s = va_arg(ap, uint8_t*);
|
2019-07-03 18:12:57 +02:00
|
|
|
kprint_c(&c, 1, WHITE, BLACK);
|
2019-07-03 12:37:16 +02:00
|
|
|
break;
|
|
|
|
case 's':
|
2019-07-03 21:04:05 +02:00
|
|
|
s = va_arg(ap, uint8_t*);
|
2019-07-03 18:12:57 +02:00
|
|
|
kprint(s);
|
2019-07-03 12:37:16 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-07-04 01:58:34 +02:00
|
|
|
kprint_c((uint8_t*)format+i, 1, WHITE, BLACK);
|
2019-07-03 12:37:16 +02:00
|
|
|
}
|
|
|
|
} else
|
2019-07-04 01:58:34 +02:00
|
|
|
kprint_c((uint8_t*)format+i, 1, WHITE, BLACK);
|
2019-07-03 12:37:16 +02:00
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
return 0;
|
2019-07-03 18:12:57 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 21:04:05 +02:00
|
|
|
void puts(const char *buf) {
|
2019-07-03 18:12:57 +02:00
|
|
|
printf("%s\n", buf);
|
2019-07-04 01:58:34 +02:00
|
|
|
}
|