Cursor shifts after enabling it on real hardware

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Cursor shifts after enabling it on real hardware

Post 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?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Cursor shifts after enabling it on real hardware

Post 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.
Carpe diem!
Octocontrabass
Member
Member
Posts: 5562
Joined: Mon Mar 25, 2013 7:01 pm

Re: Cursor shifts after enabling it on real hardware

Post by Octocontrabass »

Matt1223 wrote:

Code: Select all

inb(0x3E0)
That's not a VGA register.
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: Cursor shifts after enabling it on real hardware

Post 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.)
Octocontrabass
Member
Member
Posts: 5562
Joined: Mon Mar 25, 2013 7:01 pm

Re: Cursor shifts after enabling it on real hardware

Post 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.
Matt1223
Member
Member
Posts: 45
Joined: Mon Jul 30, 2018 2:58 am

Re: Cursor shifts after enabling it on real hardware

Post 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!
Post Reply