-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.c
104 lines (91 loc) · 1.8 KB
/
keyboard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "keyboard.h"
#include <stdio.h>
#include "cpu.h"
#include "kbd.h"
#include "string.h"
#include "message_file.h"
#include "semaphore.h"
#include "ecran.h"
#include "process.h"
#define ADDR_VALIDE(addr) (unsigned)addr>=0x40000000
int fid_keyboard;
int sem;
#define GB1 0x4000000
void init_keyboard()
{
fid_keyboard=pcreate(20);
sem=screate(1);
echo_fct=echo_fct_standard;
}
void scan_keyboard()
{
outb(0x20, 0x20);
int scancode=inb(0x60);
do_scancode(scancode);
}
int echo_on=1;
void cons_echo(int on)
{
echo_on=on;
}
unsigned long icour;
unsigned long cons_read(char *string, unsigned long length)
{
if (!(ADDR_VALIDE(string)))
return -1;
wait(sem);
for(icour=0; icour<length; icour++){
int msg;
preceive(fid_keyboard,&msg,1);
if (msg==13) {
signal(sem);
return icour;
} else if (msg==127 && icour>0) {
string[--icour]=0;
icour--;
} else if (msg!=127){
string[icour]=msg;
} else {
icour--;
}
}
signal(sem);
return length;
}
int cons_write(const char *str, long size)
{
if (!(ADDR_VALIDE(str)))
return -1;
for (int i=0; i<size; i++)
printf("%c",str[i]);
return 0;
}
void echo_fct_standard(char * str, int fid, int echo)
{
for (unsigned i=0; i<strlen(str); i++){
if (echo){
if ((int)(str[i])==13)
printf("%c",(char)10);
else if ((int)(str[i])<32)
printf("^%c",(char)(64+(int)(str[i])));
else if ((int)(str[i])==127 && icour>0)
//Legere protection qui permet d'eviter d'effacer le prompt
printf("\b \b");
else if ((int)(str[i])!=127)
printf("%c",str[i]);
}
psend(fid,(int)str[i]);
}
}
void keyboard_data(char *str)
{
if (table_file[fid_keyboard]->nb_message==
table_file[fid_keyboard]->tampon_length)
return;
echo_fct(str,fid_keyboard,echo_on);
}
void kbd_leds(unsigned char leds)
{
outb(0x60,0xed);
outb(0x60,leds);
}