我一直在努力在当前正在开发的操作系统中移动文本模式光标。我很难让它显示出来。这是我用来更新游标的代码:

   void update_cursor()
    {
        unsigned char cursor_loc = (y_pos*Cols)+x_pos;
         // cursor LOW port to vga INDEX register
        outb(0x3D4, 0x0F);
        outb(0x3D5, (unsigned char)(cursor_loc));
        // cursor HIGH port to vga INDEX register
        outb(0x3D4, 0x0E);
        outb(0x3D5, (unsigned char)((cursor_loc>>8)));


    }
   static inline void outb(unsigned short port, unsigned char value)
   {
      asm volatile ( "outb %0, %1" : : "a"(value), "Nd"(port) );

    }
    static inline unsigned char inb(unsigned short port)
    {
       unsigned char ret;
       asm volatile ( "inb %1, %0" : "=a"(ret) : "Nd"(port) );

       return ret;
    }

我使用gcc版本4.8.3(GCC)来编译我的主文件。我完全迷路了。关于此问题可能有任何建议吗?
如果您想查看完整的源代码,请访问这里:https://github.com/AnonymousUser1337/Anmu/blob/master/Kernel/kernel.cpp

编辑:我正在使用虚拟盒子来运行它

提前致谢。

最佳答案

您选择了错误的VGA寄存器。您必须使用0x0F表示低电平,使用0x0E表示高电平(两者都使用0x0A)。

编辑:如果您的光标被禁用,这是启用它的方法:

void enable_cursor() {
    outb(0x3D4, 0x0A);
    char curstart = inb(0x3D5) & 0x1F; // get cursor scanline start

    outb(0x3D4, 0x0A);
    outb(0x3D5, curstart | 0x20); // set enable bit
}

还要检查this link以获取寄存器编号和用法的列表。

Edit2:您的光标位置变量的宽度不足以存储光标位置。 unsigned char cursor_loc应该是unsigned short cursor_loc

关于c++ - 移动文本模式光标不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25321608/

10-11 22:39
查看更多