bringelle/src/drivers/framebuffer.c

59 lines
949 B
C
Raw Normal View History

2021-04-09 10:29:23 +02:00
#include "framebuffer.h"
2021-04-04 14:03:26 +02:00
#define MAX_COL 80
#define MAX_LINE 25
2021-04-05 14:46:31 +02:00
VIDEO_STATE VS={
(u8 *)0xB8000,
0,
0,
BLACK,
GRAY,
};
2021-04-04 11:19:55 +02:00
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;
}
2021-04-04 14:03:26 +02:00
// Print char
2021-04-05 14:46:31 +02:00
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;
2021-04-04 14:03:26 +02:00
// Refresh location
2021-04-05 14:46:31 +02:00
VS.col+=1;
if(VS.col>= MAX_COL){
VS.col=0;
VS.line+=1;
if(VS.line>=MAX_LINE){
VS.line=MAX_LINE-1;
2021-04-04 14:03:26 +02:00
scrollup();
}
}
}
void clear(){
for(char i=0;i<MAX_LINE;i++){
scrollup();
}
}
void scrollup(){
2021-04-05 14:46:31 +02:00
// Move VS.line up
2021-04-04 14:03:26 +02:00
for(char i=1;i<=MAX_LINE;i++){
for(char j=0;j<=MAX_COL;j++)
2021-04-05 14:46:31 +02:00
VS.mem[j*2+MAX_COL*(i-1)*2]=VS.mem[j*2+MAX_COL*i*2];
2021-04-04 14:03:26 +02:00
}
2021-04-05 14:46:31 +02:00
// Clear last VS.line
2021-04-04 14:03:26 +02:00
for(char i=0;i<=MAX_COL;i++){
2021-04-05 14:46:31 +02:00
VS.mem[i*2+MAX_COL*(MAX_LINE-1)*2]='\0';
2021-04-04 14:03:26 +02:00
}
2021-04-04 11:19:55 +02:00
}