From ff5848de9782bf0fdc07414c49db429472c5abc5 Mon Sep 17 00:00:00 2001 From: VinceAle7082 Date: Thu, 1 Aug 2024 20:06:44 +0200 Subject: [PATCH] Doesn't work --- src/bootloader/stage2/stdio.c | 48 ++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/bootloader/stage2/stdio.c b/src/bootloader/stage2/stdio.c index 439bf8f..13b54c5 100644 --- a/src/bootloader/stage2/stdio.c +++ b/src/bootloader/stage2/stdio.c @@ -143,7 +143,39 @@ int* printf_number(int* argp, int length, bool sign, int radix) case PRINTF_LENGTH_SHORT_SHORT: case PRINTF_LENGTH_SHORT: case PRINTF_LENGTH_LONG: + if (sign) + { + long int n = *(long int*)argp; + if (n < 0) + { + n = -n; + number_sign = -1; + } + number = (unsigned long long)n; + } + else + { + number = (*unsigned long int*)argp; + } + argp += 2; + break; case PRINTF_LENGTH_LONG_LONG: + if (sign) + { + long long int n = *(long long int*)argp; + if (n < 0) + { + n = -n; + number_sign = -1; + } + number = (unsigned long long)n; + } + else + { + number = (*unsigned long long int *)argp; + } + argp += 4; + break; case PRINTF_LENGTH_DEFAULT: if (sign) { @@ -162,5 +194,19 @@ int* printf_number(int* argp, int length, bool sign, int radix) } argp++; break; - } + } + do + { + uint32_t rem = number % radix; + buffer[pos++] = g_HexChars[rem]; + } while (number > 0); + + if (sign && number_sign < 0) + { + buffer[pos++] = '-'; + } + + while (--pos >= 0) + putc(buffer[pos]); + return argp; } \ No newline at end of file