Page 1 of 1

Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:00 am
by Matt1223
Hello!

My problem is that cursor in my OS gets a bit crazy after calling this funtion:

Code: Select all

void VGA_enable_cursor()
{
	int cursor_start = 13;
	int cursor_end = 14;

	outb(VGA.IO_Port_RegisterIndex, 0x0A);
	outb(VGA.IO_Port_DataRegister, (inb(0x3D5) & 0xC0) | cursor_start);
 
	outb(VGA.IO_Port_RegisterIndex, 0x0B);
	outb(VGA.IO_Port_DataRegister, (inb(0x3E0) & 0xE0) | cursor_end);
}
After I call this function the cursor moves by 4 spaces to the right and when it's in the first row it takes up 4 spaces. It only happens on a real hardware but works just fine on Quemu and Bochs emulators.

Is it something I can fix?

Re: Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:37 am
by nullplan
Well, assuming your code is correct (which I don't know because I never programmed the VGA), I would think that the problem is that your video card is not a VGA, and its VGA emulation does not support what you want to do here.

Personally, I can only tell you to stick to VBE/GOP. Get a framebuffer going, render everything to it. Then you can make the cursor any shape you should want it to have. You can even change the font.

Re: Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:44 am
by Octocontrabass
Matt1223 wrote:

Code: Select all

inb(0x3E0)
That's not a VGA register.

Re: Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:45 am
by sounds
Matt1223 wrote:After I call this function the cursor moves by 4 spaces to the right and when it's in the first row it takes up 4 spaces. It only happens on a real hardware but works just fine on Quemu and Bochs emulators.

Is it something I can fix?
I'm not sure registers 0x0A and 0x0B are what you want.

http://www.scs.stanford.edu/12au-cs140/ ... reg.htm#0E seems to indicate you want registers 0x0E and 0x0F in the CRTC registers. Can you check if your VGA.IO_Port_RegisterIndex is the base + 4 (so if the VGA is located at 0x3d0 your IO_PORT_RegisterIndex should be 0x3d4) -- assuming you agree and want to access registers 0x0E and 0x0F of course.

(Looks like Octocontrabass spotted this issue too.)

Re: Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:47 am
by Octocontrabass
sounds wrote:I'm not sure registers 0x0A and 0x0B are what you want.
It seems correct to me. This code is just supposed to make the cursor visible, not change its location.

Re: Cursor shifts after enabling it on real hardware

Posted: Fri Feb 17, 2023 11:57 am
by Matt1223
Octocontrabass wrote:
Matt1223 wrote:

Code: Select all

inb(0x3E0)
That's not a VGA register.
Right! I don't know why I used this register #-o . I corrected it and everything works fine. Thank you!