From f6323421e22c3585c58b54658a11e1e4706cc8fa Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 9 Apr 2021 10:29:23 +0200 Subject: Cleaning code and provide minimal libc --- src/utils/framebuffer.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/utils/framebuffer.c (limited to 'src/utils/framebuffer.c') diff --git a/src/utils/framebuffer.c b/src/utils/framebuffer.c new file mode 100644 index 0000000..110dc73 --- /dev/null +++ b/src/utils/framebuffer.c @@ -0,0 +1,58 @@ +#include "framebuffer.h" + +#define MAX_COL 80 +#define MAX_LINE 25 + +VIDEO_STATE VS={ + (u8 *)0xB8000, + 0, + 0, + BLACK, + GRAY, +}; + +void putchar(char c){ + // Handle newline here + if(c=='\n'){ + VS.col=0; + VS.line+=1; + if(VS.line>=MAX_LINE){ + VS.line=MAX_LINE-1; + scrollup(); + } + return; + } + + // Print char + VS.mem[VS.col*2+MAX_COL*VS.line*2]=c; + VS.mem[VS.col*2+MAX_COL*VS.line*2+1]=VS.fg|VS.bg<<4; + + // Refresh location + VS.col+=1; + if(VS.col>= MAX_COL){ + VS.col=0; + VS.line+=1; + if(VS.line>=MAX_LINE){ + VS.line=MAX_LINE-1; + scrollup(); + } + } +} + +void clear(){ + for(char i=0;i