gpt4 book ai didi

c++ - 移动文本模式光标不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:38 25 4
gpt4 key购买 nike

我一直致力于在我目前正在开发的操作系统中移动文本模式光标。我根本无法让它出现。这是我用来更新光标的代码:

   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

编辑:我正在使用 Virtual box 来运行它

提前致谢。

最佳答案

您选择了错误的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com