Page 1 of 1
[Solved] Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 11:36 am
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));
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 12:47 pm
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.
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 12:59 pm
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?
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 1:07 pm
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?
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 1:43 pm
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.
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 1:50 pm
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.
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
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 1:55 pm
by BrightLight
Try this.
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.
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 2:00 pm
by Octacone
omarrx024 wrote:Try this.
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!
Re: Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 2:02 pm
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.
[Solved] Cursor Never Blinks/Appears
Posted: Sat Dec 31, 2016 2:03 pm
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.