diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-26 12:37:34 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-26 12:37:34 +0200 |
| commit | 9dc527b3be9d493dcf8cf1baf78477373eb5990d (patch) | |
| tree | 0b32c28e57fc5a6a3e6210d9a601dfdbfe246cd8 /src/drivers/vga_t.cc | |
| parent | 7db6db5ae64e7ab2626bbd898c63f58e053dc1a6 (diff) | |
Enable psf font for framebuffer display
Diffstat (limited to 'src/drivers/vga_t.cc')
| -rw-r--r-- | src/drivers/vga_t.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/drivers/vga_t.cc b/src/drivers/vga_t.cc new file mode 100644 index 0000000..6e50b40 --- /dev/null +++ b/src/drivers/vga_t.cc @@ -0,0 +1,58 @@ +#include "vga_t.hpp" + +#define MAX_COL 80 +#define MAX_LINE 25 + +VIDEO_STATE VS={ + (u8 *)0xB8000, + 0, + 0, + BLACK, + GRAY, +}; + +void vga_t_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; + vga_t_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; + vga_t_scrollup(); + } + } +} + +void clear(){ + for(u8 i=0;i<MAX_LINE;i++){ + vga_t_scrollup(); + } +} + +void vga_t_scrollup(){ + // Move VS.line up + for(u8 i=1;i<=MAX_LINE;i++){ + for(u8 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(u8 i=0;i<=MAX_COL;i++){ + VS.mem[i*2+MAX_COL*(MAX_LINE-1)*2]='\0'; + } +} |
