interim commit nothing to see here non working but need to do things on other machine

This commit is contained in:
shockrahwow 2019-10-08 22:35:00 -07:00
parent 6fc97083bb
commit 536f4e8e0c
2 changed files with 52 additions and 18 deletions

63
stlio.c
View File

@ -3,39 +3,73 @@
static u8 COLOR_FG = Green;
static u8 COLOR_BG = White;
#define write_char(c) write_cell_fb(c, COLOR_FG, COLOR_BG)
// We are assuming null-terminated strings here
u64 strlen(char* buffer) {
u32 strlen(char* buffer) {
char* c;
for(c = buffer; *c != '\0'; c++); // LULW
return (u64)(c - buffer);
}
void putch(const char c) {
write_cell_fb(c, COLOR_FG, COLOR_BG);
return (u32)(c - buffer);
}
u64 write(const char* buffer, const u64 size) {
u64 i;
u32 write(const char* buffer, const u32 size) {
u32 i;
for(i = 0; i < size; i++) {
// cheesy but whatever
if(buffer[i] == '\n') {
frame_buffer_newline();
//write(_line, sizeof(_line));
}
else {
write_cell_fb(buffer[i], COLOR_FG, COLOR_BG);
write_char(buffer[i]);
}
}
return i;
}
u64 read(const u64 n) {
u32 read(const u32 n) {
// read n bytes from keyboard
return n;
}
char* tohex(u32* data, u32 size) {
static char ret[19] = {'\0'}; // 8 bytes + \0
ret[0] = '0'; ret[1] = 'x';
const char* map = "0123456789abcdef"; // muh 'tism
switch(size) {
// (unsigned)char/u8/s8
case (1): {
u8 idx;
u8 val = (u8)*data;
for(u32 i = 0; i<2; i++ ) {
idx = val & 0x0f;
ret[19-i] = map[idx];
vall >>= 4;
}
break;
}
// s16/u16
case (2): {
for(u32 i = 0; i<4; i++) {
}
break;
}
// s32/u64
case (4): {
break;
}
// s64/u64
case (8): {
break;
}
default: return "Bad-Size";
}
return "sadf";
}
void printf(char* fmt) {
u64 i;
u64 size = strlen(fmt);
u32 i;
u32 size = strlen(fmt);
for(i = 0; i < size;i++) {
char c = fmt[i];
switch(c) {
@ -48,12 +82,13 @@ void printf(char* fmt) {
* NOTE: this call might not do anything interesting
*/
if((i+1) < size) {
write_cell_fb(fmt[c], COLOR_FG, COLOR_BG);
write_char(c);
i += 2;
}
break;
}
default: {
putch(c);
write_char(c);
}
}
}

View File

@ -2,8 +2,7 @@
#include "framebuffer.h"
// Frame buffer driver
u64 strlen(char*);
u64 write(const char*, const u64);
u64 read(const u64);
static void __printf_percent(const char c);
u32 strlen(char*);
u32 write(const char*, const u32);
u32 read(const u32);
void printf(char*);