在无限循环中显示相同的字符

The same char is being displayed in infinite loop

我正在学习这个教程:

http://wiki.osdev.org/Keyboard

http://wiki.osdev.org/User:Zesterer/Bare_Bones

我正在尝试添加键盘支持,但我最终发现,如果我按一个字符,例如 'A',程序会一直显示数千'A' 直到我按下另一个键,例如 '1'(它显示了数千个 '1' 直到我按下另一个键,等等)。我想一个一个地放置字符,我的意思是如果 'A' 被按下一次它显示一次并且它仍然让我添加另一个字符。

//Places single char onto the screen
void term_putc(char c);


//Provides the scancode from kb controller
char getScancode(){
char c=0;
do {
if(inb(0x60) != c)
{
c=inb(0x60);
if(c>0)
return c;
}
}while(1);}

//transfroms scancodes to chars
char getchar();

//shows the character on the screen
void kb_print(){ 
char chara = getchar(); // Pressed key value
term_putc(chara);
}

现在调用主函数

void kernel_main(){
term_init();

while(1){
    kb_print();
}
}

完整代码:

https://pastebin.com/CMNvZN3P

感谢解答!

我认为我找到了第二好的解决方案。 我使用了这个功能:

// Sends a 8/16/32-bit value on a I/O location
static inline void outb(uint16_t port, uint8_t val){
  asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );

放置

outb(0x60, 0x0); 

char getScancode(){

  char c=0;
  outb(0x60, 0x0);
  do{
    if(inb(0x60) != c){
      c=inb(0x60);
      if(c>0)
      return c;
    }
  }while(1);
}

由于某些原因,按键后端口 0x60 不是空的。 (如果应该的话)