diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-29 08:49:41 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-29 08:49:41 +0200 |
| commit | fde8a1ab65d5e33d90123a3aaa9b5c15e249689f (patch) | |
| tree | 14134c0c2f322cbcba0989b78bd7057f76c157c3 /src/drivers/vgatext.cc | |
| parent | 067d6e340be698b0e26b7732215a1969e0e683f3 (diff) | |
Debug, add memory print driver
Diffstat (limited to 'src/drivers/vgatext.cc')
| -rw-r--r-- | src/drivers/vgatext.cc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/drivers/vgatext.cc b/src/drivers/vgatext.cc new file mode 100644 index 0000000..be01f0e --- /dev/null +++ b/src/drivers/vgatext.cc @@ -0,0 +1,65 @@ +#include "vgatext.hpp" + +#include "boucane.hpp" + +#define MAX_COL 80 +#define MAX_LINE 25 + +VIDEO_STATE VS={ + (u8 *)0xB8000, + 0, + 0, + BLACK, + GRAY, +}; + +void vgatext_init(){ + PAGING_MAP(0xB8000); + PAGING_MAP(0xB8000+4096); +} + +void vgatext_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; + vgatext_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; + vgatext_scrollup(); + } + } +} + +void vgatext_clear(){ + for(u8 i=0;i<MAX_LINE;i++){ + vgatext_scrollup(); + } +} + +void vgatext_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'; + } +} |
