interim commit nothing to see here non working but need to do things on other machine
This commit is contained in:
parent
6fc97083bb
commit
536f4e8e0c
63
stlio.c
63
stlio.c
@ -3,39 +3,73 @@
|
|||||||
static u8 COLOR_FG = Green;
|
static u8 COLOR_FG = Green;
|
||||||
static u8 COLOR_BG = White;
|
static u8 COLOR_BG = White;
|
||||||
|
|
||||||
|
#define write_char(c) write_cell_fb(c, COLOR_FG, COLOR_BG)
|
||||||
|
|
||||||
// We are assuming null-terminated strings here
|
// We are assuming null-terminated strings here
|
||||||
u64 strlen(char* buffer) {
|
u32 strlen(char* buffer) {
|
||||||
char* c;
|
char* c;
|
||||||
for(c = buffer; *c != '\0'; c++); // LULW
|
for(c = buffer; *c != '\0'; c++); // LULW
|
||||||
return (u64)(c - buffer);
|
return (u32)(c - buffer);
|
||||||
}
|
|
||||||
void putch(const char c) {
|
|
||||||
write_cell_fb(c, COLOR_FG, COLOR_BG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 write(const char* buffer, const u64 size) {
|
u32 write(const char* buffer, const u32 size) {
|
||||||
u64 i;
|
u32 i;
|
||||||
for(i = 0; i < size; i++) {
|
for(i = 0; i < size; i++) {
|
||||||
// cheesy but whatever
|
// cheesy but whatever
|
||||||
if(buffer[i] == '\n') {
|
if(buffer[i] == '\n') {
|
||||||
frame_buffer_newline();
|
frame_buffer_newline();
|
||||||
//write(_line, sizeof(_line));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write_cell_fb(buffer[i], COLOR_FG, COLOR_BG);
|
write_char(buffer[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 read(const u64 n) {
|
u32 read(const u32 n) {
|
||||||
// read n bytes from keyboard
|
// read n bytes from keyboard
|
||||||
return n;
|
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) {
|
void printf(char* fmt) {
|
||||||
u64 i;
|
u32 i;
|
||||||
u64 size = strlen(fmt);
|
u32 size = strlen(fmt);
|
||||||
for(i = 0; i < size;i++) {
|
for(i = 0; i < size;i++) {
|
||||||
char c = fmt[i];
|
char c = fmt[i];
|
||||||
switch(c) {
|
switch(c) {
|
||||||
@ -48,12 +82,13 @@ void printf(char* fmt) {
|
|||||||
* NOTE: this call might not do anything interesting
|
* NOTE: this call might not do anything interesting
|
||||||
*/
|
*/
|
||||||
if((i+1) < size) {
|
if((i+1) < size) {
|
||||||
write_cell_fb(fmt[c], COLOR_FG, COLOR_BG);
|
write_char(c);
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
putch(c);
|
write_char(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
stlio.h
7
stlio.h
@ -2,8 +2,7 @@
|
|||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
// Frame buffer driver
|
// Frame buffer driver
|
||||||
|
|
||||||
u64 strlen(char*);
|
u32 strlen(char*);
|
||||||
u64 write(const char*, const u64);
|
u32 write(const char*, const u32);
|
||||||
u64 read(const u64);
|
u32 read(const u32);
|
||||||
static void __printf_percent(const char c);
|
|
||||||
void printf(char*);
|
void printf(char*);
|
||||||
|
Loading…
Reference in New Issue
Block a user