[Solved] Cursor Never Blinks/Appears

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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Solved] Cursor Never Blinks/Appears

Post by Octacone »

I have a very strange issue. My text mode cursor never shows up or blinks at all. Is that normal?
Does your cursor blink/appear on the screen?

Is this how are you supposed to move one right?

Code: Select all

   uint16_t position = cursor_y * rows + cursor_x;
	Outportb(0x3D4, 0x0F);
	Outportb(0x3D5, (uint8_t) (position & 0xFF));
	Outportb(0x3D4, 0x0E);
	Outportb(0x3D5, (uint8_t) ((position >> 8) & 0xFF));
Last edited by Octacone on Sat Dec 31, 2016 2:01 pm, edited 1 time in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Cursor Never Blinks/Appears

Post by BrightLight »

Make sure that at the X/Y position of the cursor is a color attribute even if not a character. The cursor needs an attribute just like any character to appear.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Cursor Never Blinks/Appears

Post by Octacone »

omarrx024 wrote:Make sure that at the X/Y position of the cursor is a color attribute even if not a character. The cursor needs an attribute just like any character to appear.
Wait wait wait... A color attribute, so cursor is not an unique structure it is like a character. How can I implement that? Do I need to draw a character at cursor position + 1?
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Cursor Never Blinks/Appears

Post by Octacone »

Is this drawing method okay?

Code: Select all

char* tty_buffer = (char*) 0xB8000;
tty_buffer[((cursor_y * rows + cursor_x)) * color_depth] = character; 
tty_buffer[((cursor_y * rows + cursor_x)) * color_depth + 1] = tty_color;
Does this mess up with my cursor?
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Cursor Never Blinks/Appears

Post by BrightLight »

It's fine, but what is color depth? BTW, you are calculating the pointer to the character twice, which is going to decrease performance. In text modes, I guess the color depth is always 1 byte.
No, you don't need to draw a character at cursor position. You just need to have an attribute at the X/Y position of the cursor as if there was a character. Try clearing your screen but putting character 0x20 (space) in all character fields, and attribute 0x70 (just random color for testing) in all attribute fields. Then run this code:

Code: Select all

outb(0x3D4, 0x0E);
outb(0x3D5, 0x00);
outb(0x3D4, 0x0F);
outb(0x3D5, 0x00);
You should see a cursor at the top-left corner. If not, then you need to tweak the VGA registers to make the cursor visible. I'll dig up the docs; I have them somewhere but haven't used them for a long time. :mrgreen:
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Cursor Never Blinks/Appears

Post by Octacone »

omarrx024 wrote:It's fine, but what is color depth? BTW, you are calculating the pointer to the character twice, which is going to decrease performance. In text modes, I guess the color depth is always 1 byte.
No, you don't need to draw a character at cursor position. You just need to have an attribute at the X/Y position of the cursor as if there was a character. Try clearing your screen but putting character 0x20 (space) in all character fields, and attribute 0x70 (just random color for testing) in all attribute fields. Then run this code:

Code: Select all

outb(0x3D4, 0x0E);
outb(0x3D5, 0x00);
outb(0x3D4, 0x0F);
outb(0x3D5, 0x00);
You should see a cursor at the top-left corner. If not, then you need to tweak the VGA registers to make the cursor visible. I'll dig up the docs; I have them somewhere but haven't used them for a long time. :mrgreen:
Color depth is two. I did it all exactly as you told me to do:

Code: Select all

for(int i = 0; i < rows * columns; i++)
{
		tty_buffer[i * 2] = 0x20;
		tty_buffer[i * 2 + 1] = 0x70;
}
Outportb(0x3D4, 0x0E);
Outportb(0x3D5, 0x00);
Outportb(0x3D4, 0x0F);
Outportb(0x3D5, 0x00);
then I got a gray screen with nothing on it, that is really weird. No cursor at all. :| VGA documents :D
Last edited by Octacone on Sat Dec 31, 2016 1:59 pm, edited 4 times in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Cursor Never Blinks/Appears

Post by BrightLight »

Try this. :roll:

Code: Select all

outb(0x3D4, 0x09);	// set maximum scan line register to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0B);	// set the cursor end line to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0A);	// set the cursor start line to 14 and enable cursor visibility
outb(0x3D5, 0x0E);
EDIT: Fixed a tiny mistake in the end of the code.
Last edited by BrightLight on Sat Dec 31, 2016 2:04 pm, edited 1 time in total.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Cursor Never Blinks/Appears

Post by Octacone »

omarrx024 wrote:Try this. :roll:

Code: Select all

outb(0x3D4, 0x09);	// set maximum scan line register to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0B);	// set the cursor end line to 15
outb(0x3D5, 0x0F);

outb(0x3D4, 0x0A);	// set the cursor start line to 14 and enable cursor visibility
outb(0x3D5, 0x2E);
This part over here fixed it:

Code: Select all

Outportw(0x3D4,0xE0A);
Outportw(0x3D4,0xF0B);
Thanks for helping!
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Cursor Never Blinks/Appears

Post by BrightLight »

octacone wrote: This part over here fixed it:

Code: Select all

Outportw(0x3D4,0xE0A);
Outportw(0x3D4,0xF0B);
OK, just notice that my code has one tiny mistake. The last line should write 0x0E and not 0x2E.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Solved] Cursor Never Blinks/Appears

Post by Octacone »

omarrx024 wrote:
octacone wrote: This part over here fixed it:

Code: Select all

Outportw(0x3D4,0xE0A);
Outportw(0x3D4,0xF0B);
OK, just notice that my code has one tiny mistake. The last line should write 0x0E and not 0x2E.
Yup! That fixes it. Your code is also correct. :D
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Post Reply