and well it works, if you have 2 or less keypresses else it adds some wierd character after the first 2 characters and acts as if the other characters entered didnt exist
so what exactly is wrong
here is my code
Code: Select all
//KEYBOARD DRIVER SOURCE FILE
//kbdus and kbduscaps tables were cut out to decrease size
typedef struct {
unsigned char caps;
unsigned char shift;
unsigned char scroll;
unsigned char num;
unsigned char ctrl;
unsigned char alt;
}
shift_locks; /*for simplicity and speed*/
volatile shift_locks shifts;
volatile unsigned int keycount=0;
volatile unsigned char keys[128];
unsigned char scan2asc(unsigned char scan){
if (shifts.caps^shifts.shift==1) {
scan=kbduscaps[scan];
}else{
scan=kbdus[scan];
}
return scan;
}
void put_kbd_buffer(unsigned char scan,unsigned char chr){
keys[keycount]=chr;
keycount++;
keys[keycount]=scan;
keycount++;
}
unsigned char get_kbd_buffer(unsigned char *scan_buf,unsigned char *asc_buf){
keycount--;
*scan_buf=keys[keycount];
keycount--;
*asc_buf=keys[keycount];
return *asc_buf;
}
char getkey(char *buf){
//char tmp[1]; error! allocated on stack
while(keycount==0){}
return get_kbd_buffer(&buf[0],&buf[1]);
}
void kbd_handler(r){
unsigned char scancode;unsigned char tmp;
if (keycount==128){return 0;}
scancode = inportb(0x60);
if (scancode & 0x80) {
switch (scancode) {
case 42:
shifts.shift=0;
break;
case 54:
shifts.shift=0;
break;
case 29:
shifts.ctrl=0;
break;
case 56:
shifts.alt=0;
break;
}
}else{
if (scancode==58) {
/*set lights*/
shifts.caps=shifts.caps ^ 1;
}
if (scancode==69) {
shifts.num=shifts.num ^ 1;
}
if (scancode==70) {
shifts.scroll=shifts.scroll ^ 1;
}
tmp=scan2asc(scancode);
put_kbd_buffer(scancode,tmp);
}
}
//PART OF _stdio.c (library file)
extern char getkey();
char *gets(char *buf){
char tmp[1];
while (*buf!='\n'){
getkey(tmp);
*buf=tmp[1];
if (*buf=='\n'){*buf=0;return 0;}
k_putchar(*buf);
buf++;
}
buf--;
*buf=0;
}