#include #include #include #include static char buffer[3 * sizeof(int) + 2]; int printf(const char *restrict format, ...) { int written = 0; va_list params; va_start(params, format); int s = 0; int l = 0; for (int i = 0; format[i] != '\0'; ++i) { if (format[i] == '%') { written += uart_puts(COM1, &format[s], l); s = i + 2; ++i; switch (format[i]) { case 's': written += uart_puts(COM1, va_arg(params, const char *), -1); break; case 'd': written += uart_puts(COM1, itoa(buffer, va_arg(params, int), 10), -1); break; case 'u': written += uart_puts(COM1, utoa(buffer, va_arg(params, unsigned int), 10), -1); break; case 'x': written += uart_puts(COM1, utoa(buffer, va_arg(params, unsigned int), 16), -1); break; } l = 0; } else ++l; } if (l > 0) written += uart_puts(COM1, &format[s], l); va_end(params); return written; }