Add utilities functions

This commit is contained in:
Loic Guegan 2021-04-04 14:03:26 +02:00
parent 969f81bd7e
commit 48a608c895
4 changed files with 62 additions and 7 deletions

View file

@ -1,11 +1,8 @@
#include "utils/print.h"
void bringelle(){
putchar('L');
putchar('L');
clear();
print("Booting Bringelle...");
while(1);
}

View file

@ -1,7 +1,51 @@
#include "print.h"
#include "types.h"
#define MAX_COL 80
#define MAX_LINE 25
char *video=(char *)0xB8000;
u8 col=0;
u8 line=0;
void putchar(char c){
char *video=(char *)0xB8000;
video[0]=c;
// Print char
video[col*2+MAX_COL*line*2]=c;
// Refresh location
col+=1;
if(col>= MAX_COL){
col=0;
line+=1;
if(line>=MAX_LINE){
line=MAX_LINE-1;
scrollup();
}
}
}
void print(char *str){
int i=0;
while(str[i]!='\0'){
putchar(str[i]);
i++;
}
}
void clear(){
for(char i=0;i<MAX_LINE;i++){
scrollup();
}
}
void scrollup(){
// Move line up
for(char i=1;i<=MAX_LINE;i++){
for(char j=0;j<=MAX_COL;j++)
video[j*2+MAX_COL*(i-1)*2]=video[j*2+MAX_COL*i*2];
}
// Clear last line
for(char i=0;i<=MAX_COL;i++){
video[col*2+MAX_COL*(MAX_LINE-1)*2]='\0';
}
}

View file

@ -2,6 +2,12 @@
#define PRINT_H
/**
* Print char
*/
void putchar(char);
void print(char*);
void scrollup();
void clear();
#endif

8
src/utils/types.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef TYPES_H
#define TYPES_h
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
#endif