feat: ajout d'un fonction Waitascii Ajout de la gestion multiconsole

This commit is contained in:
Nicolas Hordé 2007-04-02 14:16:14 +00:00
parent cd78773ee6
commit 77d4211556
1 changed files with 305 additions and 293 deletions

View File

@ -1,293 +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]; 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()
{
void outkbd(u8 port, u8 data) u8 oldptrascii=ptrascii;
{ while(oldptrascii==ptrascii) {};
u32 timeout; return bufferascii[ptrascii];
u8 state; }
/* timeout */ /******************************************************************************/
for(timeout = 500000L; timeout != 0; timeout--)
{ void outkbd(u8 port, u8 data)
state = inb(0x64); {
/* vide le buffer du 8042 */ u32 timeout;
if((state & 0x02) == 0) break; u8 state;
}
if(timeout != 0) /* timeout */
outb(port, data); for(timeout = 500000L; timeout != 0; timeout--)
} {
state = inb(0x64);
/******************************************************************************/ /* vide le buffer du 8042 */
static void reboot(void) if((state & 0x02) == 0) break;
{ }
u8 temp; if(timeout != 0)
cli(); outb(port, data);
/* vide le 8042 */ }
do
{ /******************************************************************************/
temp = inb(0x64); static void reboot(void)
if((temp & 0x01) != 0) {
{ u8 temp;
(void)inb(0x60); cli();
continue; /* vide le 8042 */
} do
} while((temp & 0x02) != 0); {
/* active le reset CPU */ temp = inb(0x64);
outb(0x64, 0xFE); if((temp & 0x01) != 0)
while(1) {
/* boucle infinie */; (void)inb(0x60);
} continue;
}
/******************************************************************************/ } while((temp & 0x02) != 0);
unsigned convert(u32 keypressed) /* active le reset CPU */
{ outb(0x64, 0xFE);
while(1)
u8 temp,key,lastscan; /* boucle infinie */;
/* garde le dernier pointeur du buffer scan */ }
lastscan=ptrscan;
/* incrémente le pointeur est assigne au buffer le dernier scancode */ /******************************************************************************/
ptrscan++; unsigned convert(u32 keypressed)
if (ptrscan==255) ptrscan==0; {
bufferscan[ptrscan]=keypressed;
/* break key (touche relaché) ? */ u8 temp,key,lastscan;
if(keypressed >= 0x80) breakcode = 1; /* garde le dernier pointeur du buffer scan */
key = (keypressed&0x7F); lastscan=ptrscan;
/* Mise a jour des flags lors du relachement de touches de controle */ /* incrémente le pointeur est assigne au buffer le dernier scancode */
if(breakcode) ptrscan++;
{ if (ptrscan==255) ptrscan==0;
if(key == SCAN_ALT) bufferscan[ptrscan]=keypressed;
{ /* break key (touche relaché) ? */
kbdstatus &= ~STATUS_ALT; if(keypressed >= 0x80) breakcode = 1;
/* si ALT GR (E01D) alors activer aussi control */ key = (keypressed&0x7F);
if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL; /* Mise a jour des flags lors du relachement de touches de controle */
} if(breakcode)
else if(key == SCAN_CTRL) {
kbdstatus &= ~STATUS_CTRL; if(key == SCAN_ALT)
else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) {
kbdstatus &= ~STATUS_SHIFT; kbdstatus &= ~STATUS_ALT;
breakcode = 0; /* si ALT GR (E01D) alors activer aussi control */
return 0; if (bufferscan[lastscan]==0xE0) kbdstatus &= ~STATUS_CTRL;
} }
/* Mise a jour des flags lors de l'appuie de touches de controle */ else if(key == SCAN_CTRL)
if(key == SCAN_ALT) kbdstatus &= ~STATUS_CTRL;
{ else if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
kbdstatus |= STATUS_ALT; kbdstatus &= ~STATUS_SHIFT;
/* si ALT GR (E01D) alors desactiver aussi control */ breakcode = 0;
if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL; return 0;
return 0; }
} /* Mise a jour des flags lors de l'appuie de touches de controle */
if(key == SCAN_CTRL) if(key == SCAN_ALT)
{ {
kbdstatus |= STATUS_CTRL; kbdstatus |= STATUS_ALT;
return 0; /* si ALT GR (E01D) alors desactiver aussi control */
} if (bufferscan[lastscan]==0xE0) kbdstatus |= STATUS_CTRL;
if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT) return 0;
{ }
kbdstatus |= STATUS_SHIFT; if(key == SCAN_CTRL)
return 0; {
} kbdstatus |= STATUS_CTRL;
return 0;
/* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ }
if(key == SCAN_SCROLLLOCK) if(key == SCAN_LEFTSHIFT || key == SCAN_RIGHTSHIFT)
{ {
kbdstatus ^= STATUS_SCRL; kbdstatus |= STATUS_SHIFT;
goto LEDS; return 0;
} }
if(key == SCAN_NUMLOCK)
{ if ((key >= SCAN_F1) && (key <= SCAN_F8))
kbdstatus ^= STATUS_NUM; {
goto LEDS; changevc(key-SCAN_F1);
} }
if(key == SCAN_CAPSLOCK)
{ /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */
kbdstatus ^= STATUS_CAPS; if(key == SCAN_SCROLLLOCK)
LEDS: {
outkbd(0x60, 0xED); /* "mise a jour des LEDS */ kbdstatus ^= STATUS_SCRL;
temp = 0; goto LEDS;
if(kbdstatus & STATUS_SCRL) }
temp |= 1; if(key == SCAN_NUMLOCK)
if(kbdstatus & STATUS_NUM) {
temp |= 2; kbdstatus ^= STATUS_NUM;
if(kbdstatus & STATUS_CAPS) goto LEDS;
temp |= 4; }
outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */ if(key == SCAN_CAPSLOCK)
return 0; {
} kbdstatus ^= STATUS_CAPS;
/* est ce un code etendu */ LEDS:
if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e))) outkbd(0x60, 0xED); /* "mise a jour des LEDS */
/* exceptions */ temp = 0;
{ if(kbdstatus & STATUS_SCRL)
/* '/' (E035) */ temp |= 1;
if (key==0x35) return '/'; if(kbdstatus & STATUS_NUM)
/* '\r' (E01C) 2ème enter numérique*/ temp |= 2;
if (key==0x1C) return '\r'; if(kbdstatus & STATUS_CAPS)
/* 0x11 (E048) device control 1)*/ temp |= 4;
if (key==0x48) return 0x11; outkbd(0x60, temp); /* 3 bits de poids faible pour les LEDs */
/* 0x12 (E050) device control 2)*/ return 0;
if (key==0x50) return 0x12; }
/* 0x13 (E04b) device control 3)*/ /* est ce un code etendu */
if (key==0x4b) return 0x13; if ((bufferscan[lastscan]==0xE0)||((kbdstatus & STATUS_NUM)&&(key>=0x47)&&(key<=0x53)&&(key!=0x4A)&&(key!=0x4e)))
/* 0x14 (E04d) device control 4)*/ /* exceptions */
if (key==0x4d) return 0x14; {
/* 0x02 (E049) start of text)*/ /* '/' (E035) */
if (key==0x49) return 0x2; if (key==0x35) return '/';
/* 0x03 (E051) end of text)*/ /* '\r' (E01C) 2ème enter numérique*/
if (key==0x51) return 0x3; if (key==0x1C) return '\r';
/* 0x10 (E047) Line feed)*/ /* 0x11 (E048) device control 1)*/
if (key==0x47) return '\n'; if (key==0x48) return 0x11;
/* 0x1A (E052) Substitution)*/ /* 0x12 (E050) device control 2)*/
if (key==0x52) return 0x1A; if (key==0x50) return 0x12;
/* 0x18 (E053) Cancel)*/ /* 0x13 (E04b) device control 3)*/
if (key==0x53) return 0x18; if (key==0x4b) return 0x13;
/* 0x19 (E04f) End of medium)*/ /* 0x14 (E04d) device control 4)*/
if (key==0x4f) return 0x19; if (key==0x4d) return 0x14;
return 0x00; /* 0x02 (E049) start of text)*/
} if (key==0x49) return 0x2;
else /* 0x03 (E051) end of text)*/
{ if (key==0x51) return 0x3;
/* detecte les SCANCODES invalides */ /* 0x10 (E047) Line feed)*/
if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0; if (key==0x47) return '\n';
/* converti le scancode en code ASCII en fonction du statut*/ /* 0x1A (E052) Substitution)*/
if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS) if (key==0x52) return 0x1A;
temp = set1_shift[key]; /* 0x18 (E053) Cancel)*/
else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL)) if (key==0x53) return 0x18;
temp = set1_altgr[key]; /* 0x19 (E04f) End of medium)*/
else if (kbdstatus & STATUS_CTRL) if (key==0x4f) return 0x19;
temp = set1_ctrl[key]; return 0x00;
else if (kbdstatus & STATUS_ALT) }
temp = set1_alt[key]; else
else {
temp = set1_normal[key]; /* detecte les SCANCODES invalides */
} if(key >= sizeof(set1_normal) / sizeof(set1_normal[0])) return 0;
/* converti le scancode en code ASCII en fonction du statut*/
/* si scancode non reconnu fin de fonction */ if (kbdstatus & STATUS_SHIFT||kbdstatus & STATUS_CAPS)
if(temp == 0) return temp; temp = set1_shift[key];
/* Appuie de CRTL + ALT + SUPR ? */ else if ((kbdstatus & STATUS_ALT)&&(kbdstatus & STATUS_CTRL))
if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) && temp = set1_altgr[key];
(temp == KEY_DEL)) else if (kbdstatus & STATUS_CTRL)
{ temp = set1_ctrl[key];
print("redemarrage du systeme"); else if (kbdstatus & STATUS_ALT)
reboot(); temp = set1_alt[key];
} else
/* Renvoie le Code ascii */ temp = set1_normal[key];
return temp; }
}
/* si scancode non reconnu fin de fonction */
if(temp == 0) return temp;
/******************************************************************************/ /* Appuie de CRTL + ALT + SUPR ? */
if((kbdstatus & STATUS_CTRL) && (kbdstatus & STATUS_ALT) &&
void keyboard() (key == 76))
{ {
u8 scancode,ascii; print("redemarrage du systeme");
cli(); reboot();
while ((inb(0x64)&1)==0); }
scancode=inb(0x60); /* Renvoie le Code ascii */
ascii = convert(scancode); return temp;
if(ascii != 0) }
{
putchar(ascii);
ptrascii++; /******************************************************************************/
if (ptrascii==255) ptrascii==0;
bufferascii[ptrascii]=ascii; void keyboard()
} {
irqendmaster(); u8 scancode,ascii;
sti(); cli();
iret(); while ((inb(0x64)&1)==0);
} scancode=inb(0x60);
ascii = convert(scancode);
/******************************************************************************/ if(ascii != 0)
{
/*putchar(ascii);*/
ptrascii++;
if (ptrascii==255) ptrascii==0;
bufferascii[ptrascii]=ascii;
}
irqendmaster();
sti();
iret();
}
/******************************************************************************/