From d5baae37348eab846154a920576f1bbc4de6373d Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Fri, 29 Nov 2019 01:45:30 -0800 Subject: [PATCH] printhex now a thing in stlio --- stlio.c | 19 ++++++++++--------- stlio.h | 4 +--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/stlio.c b/stlio.c index a66f336..100b707 100644 --- a/stlio.c +++ b/stlio.c @@ -30,12 +30,6 @@ u32 write(const char* buffer, const u32 size) { return i; } -u32 read(char* buf, u32 n) { - // read n bytes from keyboard - return n; -} - - void printf(const char* fmt) { // Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working u32 size = strlen(fmt); @@ -49,9 +43,16 @@ void printf(const char* fmt) { } } -void printHex(u32 num) { - u8 nibble = 0; - char map[15] = "0123456789abcdef"; +void printhex(u32 num) { + // Prints our hex version of whatever is given + const char _chars[] = "0123456789abcdef"; + u32 idx = 0; // used as hash into the _chars mapping + // iterate over each nibble + for(u32 i = 0 ;i < 8;i++) { + idx = (ptr << (i * 4)) & 0xf0000000; + idx = idx >> 28; + putch(_chars[idx]); + } } void putch(const char c) { diff --git a/stlio.h b/stlio.h index 39d3771..6c73d39 100644 --- a/stlio.h +++ b/stlio.h @@ -7,10 +7,8 @@ u32 strlen(const char*); u32 write(const char*, const u32); -u32 read(char*, u32); - void printf(const char*); -void printHex(u32); +void printhex(u32); void putch(const char);