X-Git-Url: http://git.dujemihanovic.xyz/%7B%7B?a=blobdiff_plain;f=kernel%2Farch%2Fx86%2Ftty%2Ftty.c;h=861610dde3bc80b08231cc8cbe745abd96dfd615;hb=e8c050c11b7f05ec562888d6a8129ab841d163fb;hp=2110a7d003703dc3e0d2f89c483521889e2f33d7;hpb=485fd9b6752dd8590ac786397e9a0a4487860290;p=nameless-os.git diff --git a/kernel/arch/x86/tty/tty.c b/kernel/arch/x86/tty/tty.c index 2110a7d..861610d 100644 --- a/kernel/arch/x86/tty/tty.c +++ b/kernel/arch/x86/tty/tty.c @@ -175,3 +175,38 @@ void kprintq(uint64_t qword) temp = qword & 0xF; kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY); } + +int kprintdec(uint32_t num) +{ + char buffer[11]; + int digits = 10; + /* TODO: make an actual memset function to use instead of this */ + for (int i=0; i<11; i++) { + buffer[i] = 0; + } + + /* put the numbers in the buffer */ + for (int i=9; i>0 && num>0; i--) { + uint8_t currdigit = num%10; + buffer[i] = currdigit+'0'; + num /= 10; + } + + /* shift the array as much as needed */ + while (*buffer == '\0') { + digits--; + for (int i=0; i<9; i++) { + buffer[i] = buffer[i+1]; + } + } + + /* zero out any leftovers */ + if (digits < 10) { + for (int i=digits; i<10; i++) { + buffer[i] = '\0'; + } + } + + kprint(buffer, 0); + return digits; +}