diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-19 19:06:28 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-19 19:06:28 +0200 |
| commit | ca1e725b0dc9b10997897dd2ac6d44028601d9bb (patch) | |
| tree | 0eb7bd087a2382d1d1a660ceda1eae01d1b8b3ca /src/drivers/framebuffer.c | |
| parent | f5146ca9c987ed5e6ea69a0c67b7ed03444be30c (diff) | |
Init sources
Diffstat (limited to 'src/drivers/framebuffer.c')
| -rw-r--r-- | src/drivers/framebuffer.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/drivers/framebuffer.c b/src/drivers/framebuffer.c new file mode 100644 index 0000000..110dc73 --- /dev/null +++ b/src/drivers/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<MAX_LINE;i++){ + scrollup(); + } +} + +void scrollup(){ + // Move VS.line up + for(char i=1;i<=MAX_LINE;i++){ + for(char j=0;j<=MAX_COL;j++) + VS.mem[j*2+MAX_COL*(i-1)*2]=VS.mem[j*2+MAX_COL*i*2]; + } + // Clear last VS.line + for(char i=0;i<=MAX_COL;i++){ + VS.mem[i*2+MAX_COL*(MAX_LINE-1)*2]='\0'; + } +} |
