OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 11:23 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: [Solved] Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 11:36 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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:
   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));

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Last edited by Octacone on Sat Dec 31, 2016 2:01 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 12:47 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
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.


Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 12:59 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 1:07 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Is this drawing method okay?
Code:
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


Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 1:43 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
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:
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.


Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 1:50 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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:
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:
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

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Last edited by Octacone on Sat Dec 31, 2016 1:59 pm, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 1:55 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
Try this. :roll:
Code:
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.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Last edited by BrightLight on Sat Dec 31, 2016 2:04 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 2:00 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
omarrx024 wrote:
Try this. :roll:
Code:
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:
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


Top
 Profile  
 
 Post subject: Re: Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 2:02 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
octacone wrote:
This part over here fixed it:
Code:
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.


Top
 Profile  
 
 Post subject: [Solved] Cursor Never Blinks/Appears
PostPosted: Sat Dec 31, 2016 2:03 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
omarrx024 wrote:
octacone wrote:
This part over here fixed it:
Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], SemrushBot [Bot] and 232 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group