feat: ajout d'un buffer pour les scancodes

This commit is contained in:
Nicolas Hordé 2007-04-02 14:34:19 +00:00
parent 6d16c840ea
commit 1027401800
1 changed files with 305 additions and 305 deletions

View File

@ -1,305 +1,305 @@
#include "idt.h" #include "idt.h"
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "memory.h" #include "memory.h"
#include "keyboard.h" #include "keyboard.h"
#include "video.h" #include "video.h"
static u8 bufferscan[256]={0}; static u8 bufferscan[256]={0};
static u8 bufferascii[256]={0}; static u8 bufferascii[256]={0};
static u8 ptrscan=0; static u8 ptrscan=0;
static u8 ptrascii=0; static u8 ptrascii=0;
static u16 kbdstatus,breakcode ; static u16 kbdstatus,breakcode ;
static const u8 set1_normal[] = static const u8 set1_normal[] =
{ {
0, 0x1B, '&', 'é', '\"', '\'', '(', '-', 0, 0x1B, '&', 'é', '\"', '\'', '(', '-',
'è', '_', 'ç', 'à', ')', '=', '\b', '\t', 'è', '_', 'ç', 'à', ')', '=', '\b', '\t',
'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '^', '$', '\r', 0, 'q', 's', 'o', 'p', '^', '$', '\r', 0, 'q', 's',
'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
'ù', '²', 0, '*', 'w', 'x', 'c', 'v', 'ù', '²', 0, '*', 'w', 'x', 'c', 'v',
'b', 'n', ',', ';', ':', '!', 0, '*', 'b', 'n', ',', ';', ':', '!', 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '7', 0, 0, 0, 0, 0, 0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9','-', '4','5','6', '+', '1',
'2', '3','0','.',0, 0, '<', 0, '2', '3','0','.',0, 0, '<', 0,
0 0
}; };
static const u8 set1_shift[] = static const u8 set1_shift[] =
{ {
0, 0x1B, '1', '2', '3', '4', '5', '6', 0, 0x1B, '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '°', '+', '\b', '\t', '7', '8', '9', '0', '°', '+', '\b', '\t',
'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', '¨', '£', '\r', 0, 'Q', 'S', 'O', 'P', '¨', '£', '\r', 0, 'Q', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'%', 0, 0, 'µ', 'W', 'X', 'C', 'V', '%', 0, 0, 'µ', 'W', 'X', 'C', 'V',
'B', 'N', '?', '.', '/', '§', 0, '*', 'B', 'N', '?', '.', '/', '§', 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0,0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9','-', '4','5','6', '+', '1',
'2', '3','0','.',0, 0, '>', 0, '2', '3','0','.',0, 0, '>', 0,
0 0
}; };
static const u8 set1_alt[] = static const u8 set1_alt[] =
{ {
0, 0x1B, 0, 0, 0, 0, 0, 0, 0, 0x1B, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, '\r', 0, 0, 0, 0, 0, 0, 0, '\r', 0, 0, 0,
0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '*', 0, 0, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0,0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9','-', '4','5','6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3','0','.',0, 0, 0, 0,
0 0
}; };
static const u8 set1_altgr[] = static const u8 set1_altgr[] =
{ {
0, 0x1B, 0, '~', '#', '{', '[', '|', 0, 0x1B, 0, '~', '#', '{', '[', '|',
'`', '\\', '^', '@', ']', '}', '\b', '\t', '`', '\\', '^', '@', ']', '}', '\b', '\t',
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, '¤', '\r', 0, 0, 0, 0, 0, 0, '¤', '\r', 0, 0, 0,
0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, '*', 0, 0, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0,0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9','-', '4','5','6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3','0','.',0, 0, 0, 0,
0 0
}; };
static const u8 set1_ctrl[] = static const u8 set1_ctrl[] =
{ {
0, 0x1B, 0, 0,0, 0, 0x1B, 0, 0, 0x1B, 0, 0,0, 0, 0x1B, 0,
0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F, 0, 0x1C, 0, 0, 0x1D, 0, 0, 0x1F,
0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09, 0x01, 0x1A, 0x05, 0x012, 0x14, 0x19, 0x15, 0x09,
0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13, 0x0F, 0x10, 0x1E, 0, 0, 0, 0x11, 0x13,
0x04, 0x06, 0x07,0x08, 0x0A, 0x0B, 0x0C, 0x0D, 0x04, 0x06, 0x07,0x08, 0x0A, 0x0B, 0x0C, 0x0D,
0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16, 0, 0, 0, 0, 0x17, 0x18, 0x03, 0x16,
0x02, 0x0E, 0, 0, 0, 0, 0, '*', 0x02, 0x0E, 0, 0, 0, 0, 0, '*',
0, ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,0, 0, '7', 0, 0, 0, 0, 0,0, 0, '7',
'8', '9','-', '4','5','6', '+', '1', '8', '9','-', '4','5','6', '+', '1',
'2', '3','0','.',0, 0, 0, 0, '2', '3','0','.',0, 0, 0, 0,
0 0
}; };
/******************************************************************************/ /******************************************************************************/
u8 waitascii() u8 waitascii()
{ {
u8 oldptrascii=ptrascii; u8 oldptrscan=ptrscan;
while(oldptrascii==ptrascii) {}; u8 oldptrascii=ptrascii;
return bufferascii[ptrascii]; while((oldptrascii==ptrascii));/*(oldptrscan==ptrscan)&&*/
} return bufferascii[ptrascii];
}
/******************************************************************************/
/******************************************************************************/
void outkbd(u8 port, u8 data)
{ void outkbd(u8 port, u8 data)
u32 timeout; {
u8 state; u32 timeout;
u8 state;
/* timeout */
for(timeout = 500000L; timeout != 0; timeout--) /* timeout */
{ for(timeout = 500000L; timeout != 0; timeout--)
state = inb(0x64); {
/* vide le buffer du 8042 */ state = inb(0x64);
if((state & 0x02) == 0) break; /* vide le buffer du 8042 */
} if((state & 0x02) == 0) break;
if(timeout != 0) }
outb(port, data); if(timeout != 0)
} outb(port, data);
}
/******************************************************************************/
static void reboot(void) /******************************************************************************/
{ static void reboot(void)
u8 temp; {
cli(); u8 temp;
/* vide le 8042 */ cli();
do /* vide le 8042 */
{ do
temp = inb(0x64); {
if((temp & 0x01) != 0) temp = inb(0x64);
{ if((temp & 0x01) != 0)
(void)inb(0x60); {
continue; (void)inb(0x60);
} continue;
} while((temp & 0x02) != 0); }
/* active le reset CPU */ } while((temp & 0x02) != 0);
outb(0x64, 0xFE); /* active le reset CPU */
while(1) outb(0x64, 0xFE);
/* boucle infinie */; while(1)
} /* boucle infinie */;
}
/******************************************************************************/
unsigned convert(u32 keypressed) /******************************************************************************/
{ unsigned convert(u32 keypressed)
{
u8 temp,key,lastscan; u8 temp,key,lastscan;
/* garde le dernier pointeur du buffer scan */ /* garde le dernier pointeur du buffer scan */
lastscan=ptrscan; lastscan=ptrscan;
/* incrémente le pointeur est assigne au buffer le dernier scancode */ /* incrémente le pointeur est assigne au buffer le dernier scancode */
ptrscan++; ptrscan++;
if (ptrscan==255) ptrscan==0; if (ptrscan==255) ptrscan==0;
bufferscan[ptrscan]=keypressed; bufferscan[ptrscan]=keypressed;
/* break key (touche relaché) ? */ /* break key (touche relaché) ? */
if(keypressed >= 0x80) breakcode = 1; if(keypressed >= 0x80) breakcode = 1;
key = (keypressed&0x7F); key = (keypressed&0x7F);
/* Mise a jour des flags lors du relachement de touches de controle */ /* Mise a jour des flags lors du relachement de touches de controle */
if(breakcode) if(breakcode)
{ {
if(key == SCAN_ALT) if(key == SCAN_ALT)
{ {
kbdstatus &= ~STATUS_ALT; kbdstatus &= ~STATUS_ALT;
/* si ALT GR (E01D) alors activer aussi control */ /* si ALT GR (E01D) alors activer aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL; if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL;
} }
else if(key == SCAN_CTRL) else if(key == SCAN_CTRL)
kbdstatus &= ~STATUS_CTRL; kbdstatus &= ~STATUS_CTRL;
else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
kbdstatus &= ~STATUS_SHIFT; kbdstatus &= ~STATUS_SHIFT;
breakcode = 0; breakcode = 0;
return 0; return 0;
} }
/* Mise a jour des flags lors de l'appuie de touches de controle */ /* Mise a jour des flags lors de l'appuie de touches de controle */
if(key == SCAN_ALT) if(key == SCAN_ALT)
{ {
kbdstatus |= STATUS_ALT; kbdstatus |= STATUS_ALT;
/* si ALT GR (E01D) alors desactiver aussi control */ /* si ALT GR (E01D) alors desactiver aussi control */
if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL; if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if(key == SCAN_CTRL) if(key == SCAN_CTRL)
{ {
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_CTRL;
return 0; return 0;
} }
if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
{ {
kbdstatus |= STATUS_SHIFT; kbdstatus |= STATUS_SHIFT;
return 0; return 0;
} }
if ((key >= SCAN_F1) && (key <= SCAN_F8)) if ((key >= SCAN_F1) && (key <= SCAN_F8))
{ {
changevc(key-SCAN_F1); changevc(key-SCAN_F1);
} }
/* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
if(key == SCAN_SCROLLLOCK) if(key == SCAN_SCROLLLOCK)
{ {
kbdstatus ^= STATUS_SCRL; kbdstatus ^= STATUS_SCRL;
goto LEDS; goto LEDS;
} }
if(key == SCAN_NUMLOCK) if(key == SCAN_NUMLOCK)
{ {
kbdstatus ^= STATUS_NUM; kbdstatus ^= STATUS_NUM;
goto LEDS; goto LEDS;
} }
if(key == SCAN_CAPSLOCK) if(key == SCAN_CAPSLOCK)
{ {
kbdstatus ^= STATUS_CAPS; kbdstatus ^= STATUS_CAPS;
LEDS: LEDS:
outkbd(0x60, 0xED); /* "mise a jour des LEDS */ outkbd(0x60, 0xED); /* "mise a jour des LEDS */
temp = 0; temp = 0;
if(kbdstatus & STATUS_SCRL) if(kbdstatus & STATUS_SCRL)
temp |= 1; temp |= 1;
if(kbdstatus & STATUS_NUM) if(kbdstatus & STATUS_NUM)
temp |= 2; temp |= 2;
if(kbdstatus & STATUS_CAPS) if(kbdstatus & STATUS_CAPS)
temp |= 4; temp |= 4;
outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */ outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */
return 0; return 0;
} }
/* est ce un code etendu */ /* est ce un code etendu */
if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e))) if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e)))
/* exceptions */ /* exceptions */
{ {
/* '/' (E035) */ /* '/' (E035) */
if (key==0x35) return '/'; if (key==0x35) return '/';
/* '\r' (E01C) 2ème enter numérique*/ /* '\r' (E01C) 2ème enter numérique*/
if (key==0x1C) return '\r'; if (key==0x1C) return '\r';
/* 0x11 (E048) device control 1)*/ /* 0x11 (E048) device control 1)*/
if (key==0x48) return 0x11; if (key==0x48) return 0x11;
/* 0x12 (E050) device control 2)*/ /* 0x12 (E050) device control 2)*/
if (key==0x50) return 0x12; if (key==0x50) return 0x12;
/* 0x13 (E04b) device control 3)*/ /* 0x13 (E04b) device control 3)*/
if (key==0x4b) return 0x13; if (key==0x4b) return 0x13;
/* 0x14 (E04d) device control 4)*/ /* 0x14 (E04d) device control 4)*/
if (key==0x4d) return 0x14; if (key==0x4d) return 0x14;
/* 0x02 (E049) start of text)*/ /* 0x02 (E049) start of text)*/
if (key==0x49) return 0x2; if (key==0x49) return 0x2;
/* 0x03 (E051) end of text)*/ /* 0x03 (E051) end of text)*/
if (key==0x51) return 0x3; if (key==0x51) return 0x3;
/* 0x10 (E047) Line feed)*/ /* 0x10 (E047) Line feed)*/
if (key==0x47) return '\n'; if (key==0x47) return '\n';
/* 0x1A (E052) Substitution)*/ /* 0x1A (E052) Substitution)*/
if (key==0x52) return 0x1A; if (key==0x52) return 0x1A;
/* 0x18 (E053) Cancel)*/ /* 0x18 (E053) Cancel)*/
if (key==0x53) return 0x18; if (key==0x53) return 0x18;
/* 0x19 (E04f) End of medium)*/ /* 0x19 (E04f) End of medium)*/
if (key==0x4f) return 0x19; if (key==0x4f) return 0x19;
return 0x00; return 0x00;
} }
else else
{ {
/* detecte les SCANCODES invalides */ /* detecte les SCANCODES invalides */
if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0; if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0;
/* converti le scancode en code ASCII en fonction du statut*/ /* converti le scancode en code ASCII en fonction du statut*/
if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS) if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS)
temp = set1_shift[key]; temp = set1_shift[key];
else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL)) else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL))
temp = set1_altgr[key]; temp = set1_altgr[key];
else if (kbdstatus & STATUS_CTRL) else if (kbdstatus & STATUS_CTRL)
temp = set1_ctrl[key]; temp = set1_ctrl[key];
else if (kbdstatus & STATUS_ALT) else if (kbdstatus & STATUS_ALT)
temp = set1_alt[key]; temp = set1_alt[key];
else else
temp = set1_normal[key]; temp = set1_normal[key];
} }
/* si scancode non reconnu fin de fonction */ /* si scancode non reconnu fin de fonction */
if(temp == 0) return temp; if(temp == 0) return temp;
/* Appuie de CRTL + ALT + SUPR ? */ /* Appuie de CRTL + ALT + SUPR ? */
if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) &&
(key == 76)) (key == 76))
{ {
print("redemarrage du systeme"); print("redemarrage du systeme");
reboot(); reboot();
} }
/* Renvoie le Code ascii */ /* Renvoie le Code ascii */
return temp; return temp;
} }
/******************************************************************************/ /******************************************************************************/
void keyboard() void keyboard()
{ {
u8 scancode,ascii; u8 scancode,ascii;
cli(); cli();
while ((inb(0x64)&1)==0); while ((inb(0x64)&1)==0);
scancode=inb(0x60); scancode=inb(0x60);
ascii = convert(scancode); ascii = convert(scancode);
if(ascii != 0) if(ascii != 0)
{ {
/*putchar(ascii);*/ putchar(ascii);
ptrascii++; ptrascii++;
if (ptrascii==255) ptrascii==0; if (ptrascii==255) ptrascii==0;
bufferascii[ptrascii]=ascii; bufferascii[ptrascii]=ascii;
} }
irqendmaster(); irqendmaster();
sti(); sti();
iret(); iret();
} }
/******************************************************************************/ /******************************************************************************/