printhex now a thing in stlio

This commit is contained in:
shockrahwow 2019-11-29 01:45:30 -08:00
parent a11c3c84bf
commit d5baae3734
2 changed files with 11 additions and 12 deletions

19
stlio.c
View File

@ -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) {

View File

@ -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);