Code: Select all
const char* kbd_gets()
{
char *cmd=malloc(128);
uint8_t c=0;
int i=0;
while(true)
{
kbd_wait_irq();
kbd_waitForBufToEmpty();
c=inb(0x60);
if(c>0)
{
if(c==28)
{
cmd[i]='\0';
return cmd;
}
if(c==0x0e)
{
if(i>0)
{
i--;
tty_goToPos(tty_x-1, tty_y);
tty_putchar(' ');
tty_goToPos(tty_x-1, tty_y);
}
continue;
}
if(c>0x01 && c<0x81)
{
tty_putchar(scancode[c+1]);
cmd[i++]=scancode[c+1];
}
}
}
return NULL;
}
Code: Select all
void kbd_waitForBufToEmpty()
{
char c=inb(0x60);
while(inb(0x60)==c)
c=inb(0x60);
}
bool kbd_irq_fired=false;
void kbd_wait_irq()
{
while(kbd_irq_fired);
kbd_irq_fired=false;
}
void kbd_handler(struct regs *UNUSED(r))
{
kbd_irq_fired=true;
}
void initKbdInt()
{
irq_install_handler(1,kbd_handler);
}
Expected: helloworld
Result - helool
Without kbd_waitForBufToEmpty all is repeating a lot of times, because OS isn't waiting for keyboard buffer to empty.