Refactoring
This commit is contained in:
parent
39713a3736
commit
457a211770
13 changed files with 10 additions and 8 deletions
16
src/drivers/8042.c
Normal file
16
src/drivers/8042.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "8042.h"
|
||||
#include "drivers/framebuffer.h"
|
||||
#include "core/asm.h"
|
||||
|
||||
DEFINE_AZERTY;
|
||||
|
||||
void _8042_keypress(){
|
||||
u8 data;
|
||||
do {
|
||||
inb(0x64,data);
|
||||
}
|
||||
while((data&0x01) == 0);
|
||||
inb(0x60,data);
|
||||
if(data<0x80)
|
||||
putchar(AZERTY[data]);
|
||||
}
|
64
src/drivers/8042.h
Normal file
64
src/drivers/8042.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef _8042_H
|
||||
#define _8042_H
|
||||
|
||||
#include "core/types.h"
|
||||
|
||||
void _8042_keypress();
|
||||
|
||||
#define DEFINE_AZERTY char AZERTY[]={\
|
||||
'\0',\
|
||||
'\0',\
|
||||
'&',\
|
||||
'\0',\
|
||||
'"',\
|
||||
'\'',\
|
||||
'(',\
|
||||
'-',\
|
||||
'\0',\
|
||||
'_',/* 10 */\
|
||||
'\0',\
|
||||
'\0',\
|
||||
')',\
|
||||
'=',\
|
||||
'\0',\
|
||||
'\t',\
|
||||
'a',\
|
||||
'z',\
|
||||
'e',\
|
||||
'r',\
|
||||
't',\
|
||||
'y',\
|
||||
'u',\
|
||||
'i',\
|
||||
'o',\
|
||||
'p',\
|
||||
'^',\
|
||||
'$',\
|
||||
'\0',\
|
||||
'\0',\
|
||||
'q',/* 0x1E (30) */\
|
||||
's',\
|
||||
'd',\
|
||||
'f',\
|
||||
'g',\
|
||||
'h',\
|
||||
'j',\
|
||||
'k',\
|
||||
'l',\
|
||||
'm',\
|
||||
'\0',\
|
||||
'\0',\
|
||||
'\0',\
|
||||
'*',\
|
||||
'w',\
|
||||
'x',\
|
||||
'c',\
|
||||
'v',\
|
||||
'b',/* 0x30 (48) */\
|
||||
'n',\
|
||||
',',\
|
||||
';',\
|
||||
':',\
|
||||
}
|
||||
|
||||
#endif
|
58
src/drivers/framebuffer.c
Normal file
58
src/drivers/framebuffer.c
Normal file
|
@ -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';
|
||||
}
|
||||
}
|
35
src/drivers/framebuffer.h
Normal file
35
src/drivers/framebuffer.h
Normal file
|
@ -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
|
28
src/drivers/pic.c
Normal file
28
src/drivers/pic.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include "pic.h"
|
||||
#include "core/asm.h"
|
||||
#include "core/mem.h"
|
||||
#include "core/syscall.h"
|
||||
|
||||
void pic_init(){
|
||||
|
||||
// ICW1: Initialisation
|
||||
outbj(0x20,0x11); // Master
|
||||
outbj(0xA0,0x11); // Slave
|
||||
|
||||
// ICW2: Map IRQ index to entry into the IDT
|
||||
outbj(0x21,0x20); // Start interrupt at offset 0x20 in IDT (index 32)
|
||||
outbj(0xA1,0x70); // Start interrupt at offset 0x50 in IDT (index 80)
|
||||
|
||||
// ICW3: Indicate the connection between master and slave
|
||||
outbj(0x21,0x02); // Slave connected to pin 2
|
||||
outbj(0xA1,0x01); // Indicate pin id to the slave (2-1)
|
||||
|
||||
// ICW4: Operating mode
|
||||
outbj(0x21,0x01); // Default operating mode
|
||||
outbj(0xA1,0x01); // Default operating mode
|
||||
|
||||
// OCW: Masking
|
||||
outbj(0x21,0b11111100);
|
||||
}
|
||||
|
||||
|
9
src/drivers/pic.h
Normal file
9
src/drivers/pic.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef PIC_H
|
||||
#define PIC_H
|
||||
|
||||
/**
|
||||
* Configure
|
||||
*/
|
||||
void pic_init();
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue