From 57bb6962282664a63d1beb08692d24d75ab3d57f Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 6 Oct 2019 14:44:44 -0700 Subject: [PATCH] newlines kinda working, multiple newlines are still annoying to do but oh well --- framebuffer.c | 10 ++++++++++ framebuffer.h | 3 ++- stlio.c | 25 ++++++++++--------------- stlio.h | 2 +- tests.c | 3 ++- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/framebuffer.c b/framebuffer.c index de8628c..1ed12c3 100644 --- a/framebuffer.c +++ b/framebuffer.c @@ -12,6 +12,16 @@ static u8* Frame_Buffer = (u8*)FRAME_BUFFER_ADDR; s32 Frame_Buffer_Cursor = 0x0000; +void frame_buffer_newline() { + while(Frame_Buffer_Cursor != (AREA*2)) { + if((Frame_Buffer_Cursor % 160) == 0) { + break; + } + else { + Frame_Buffer_Cursor++; + } + } +} // Writes character to a given cell in the framebuffer // @cell parameter is the logical (linear)index into the buffer void write_cell_fb(u8 c, u8 fg, u8 bg) { diff --git a/framebuffer.h b/framebuffer.h index 884e046..9bd75ce 100644 --- a/framebuffer.h +++ b/framebuffer.h @@ -39,7 +39,8 @@ extern s32 Frame_Buffer_Cursor; -// Serial wrapper for +void frame_buffer_newline(); + void write_cell_fb(u8, u8, u8); void clear_fb(void); diff --git a/stlio.c b/stlio.c index faa32fe..4e7830f 100644 --- a/stlio.c +++ b/stlio.c @@ -1,6 +1,5 @@ #include "stlio.h" -static const char _line[52] = {" "}; // We are assuming null-terminated strings here u64 strlen(char* buffer) { char* c; @@ -14,8 +13,10 @@ void putch(const char c) { u64 write(const char* buffer, const u64 size) { u64 i; for(i = 0; i < size; i++) { + // cheesy but whatever if(buffer[i] == '\n') { - write(_line, sizeof(_line)); + frame_buffer_newline(); + //write(_line, sizeof(_line)); } else { write_cell_fb(buffer[i], Green, White); @@ -29,23 +30,17 @@ u64 read(const u64 n) { return n; } -void printf(const s8* fmt, ...) { - u64 i = 0; - char c = *fmt; - while(c != '\0') { - /* Check for some kind of contol character - * for now we just have \n and \t - */ +void printf(char* fmt) { + u64 i; + for(i = 0; i < strlen(fmt);i++) { + char c = fmt[i]; switch(c) { case '\n': { - write(_line, sizeof(_line)); - } - case '%': { - continue; // eventually there will be more support but for now lmao nah + frame_buffer_newline(); + break; } default: { - putch(fmt[i]); - i++; + putch(c); } } } diff --git a/stlio.h b/stlio.h index c4aa255..e680631 100644 --- a/stlio.h +++ b/stlio.h @@ -5,4 +5,4 @@ u64 strlen(char*); u64 write(const char*, const u64); u64 read(const u64); -void printf(const s8*, ...); +void printf(char*); diff --git a/tests.c b/tests.c index 808a278..710a06b 100644 --- a/tests.c +++ b/tests.c @@ -7,6 +7,7 @@ void test_write() { clear_fb(); char* msg1 = "Imagine literally not \nwriting your own os"; serial_write((signed char*)msg1, strlen(msg1)); + serial_write((signed char*)msg1, strlen(msg1)); //write(msg1, strlen(msg1)); - printf((signed char*)msg1); + printf(msg1); }