代码之家  ›  专栏  ›  技术社区  ›  Dykow

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

  •  1
  • Dykow  · 技术社区  · 8 年前

    我遵循以下教程:

    http://wiki.osdev.org/Keyboard

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

    我试图添加键盘支持,但最后我遇到了一个问题,例如,如果我按一个字符 “A” 该节目不断播放成千上万的 直到我按下另一个键,例如 (它展示了数千个 '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);
    }
    

    现在我调用main函数

    void kernel_main(){
    term_init();
    
    while(1){
        kb_print();
    }
    }
    

    完整代码:

    https://pastebin.com/CMNvZN3P
    

    1 回复  |  直到 8 年前
        1
  •  0
  •   Dykow    8 年前

    我认为我找到了第二个最好的解决方案。

    // 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不是空的。(如果应该)