diff options
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/framebuffer.c | 58 | ||||
| -rw-r--r-- | src/drivers/framebuffer.h | 35 |
2 files changed, 93 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'; + } +} diff --git a/src/drivers/framebuffer.h b/src/drivers/framebuffer.h new file mode 100644 index 0000000..d265015 --- /dev/null +++ b/src/drivers/framebuffer.h @@ -0,0 +1,35 @@ +#ifndef FRAMEBUFFER_H +#define FRAMEBUFFER_H + +#include "core/types.h" + +typedef enum VIDEO_COLORS { + BLACK=0, BLUE=1, GREEN=2,CYAN=3, RED=4,PURPLE=5,BROWN=6,GRAY=7, + DARK_GRAY=8,LIGHT_BLUE=9,LIGHT_GREEN=10,LIGHT_CYAN=11,LIGHT_RED=12,LIGHT_PURPLE=13,YELLOW=14,WHITE=15 + +} VIDEO_COLORS; + +typedef struct VIDEO_STATE { + u8 *mem; + u8 col; + u8 line; + u8 bg; + u8 fg; +} VIDEO_STATE; + +/** + * Print char + */ +void putchar(char); + +/** + * Scroll the framebuffer from one line + */ +void scrollup(); + +/** + * Clear all char from the framebuffer + */ +void clear(); + +#endif |
