Hardware cursor changes color.

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
TheChuckster

Hardware cursor changes color.

Post by TheChuckster »

My OS's text by default is green over black in color, along with the cursor. Recently, I wrote a function that would scroll up the screen 1 line. It starts at 160, because a message is displayed on the first line that remains there throughtout the entire execution of the OS.

Code: Select all

void scrollup() // Scroll up the screen to make room for prompt or text.
{   
   char *vidmem = (char *) 0xb8000; // Address in memory where Video RAM begins.
   unsigned int i=0;

   for(i=160; i < 4180; i++)
   {
     vidmem[i]=vidmem[i+160];
   }
   
   moveprompt(promptline);
};
The move prompt function is as follows:

Code: Select all

void moveprompt(int line)
{   
    prompt[0] = '>'; // Add drive.
    prompt[1] = '\0'; // Terminate.
    k_printf(prompt,line); // Print the prompt.
    movecursor(1,line); // Move the cursor.
    promptline=line; // Start at line 1 of the screen.
    currentpos=1; // Start 1 character from the left of the screen.
};
Execution of the scrollup() function causes the hardware cursor to change color to grey (not the color I want). I discovered that if I cleared the screen, the cursor reverts back to green again, but if I clear the screen by rewriting the whole video RAM with spaces with the green over black color code, the data in scrollup() gets lost with it. What should I do?
Nairou

Re:Hardware cursor changes color.

Post by Nairou »

Without knowing what your movecursor() code does, my only thought is that you might not be moving the hardware cursor to the correct byte of video memory. Does anything change if you set the cursor position to 0 or 2 instead of 1 ?
slacker

Re:Hardware cursor changes color.

Post by slacker »

i thought the hardware cursor was only capable of one color....
TheChuckster

Re:Hardware cursor changes color.

Post by TheChuckster »

The code for the movecursor function is as follows:

Code: Select all

void movecursor(unsigned int x, unsigned int y) // Adjusts the X-Y position of the cursor.
{
    int position = ( y * 80 + x ); // Calculate the cursor's new position based on the function arguments.

    // Cursor LOW port to VGA INDEX register.
    out( 0x3D4, 0x0F );
    out( 0x3D5, (unsigned char) ( position & 0xFF ) );

    // Cursor HIGH port to VGA INDEX register.
    out( 0x3D4, 0x0E );
   out( 0x3D5, (unsigned char) ( ( position >> 8 ) & 0xFF ) );
};
slacker: You are wrong. Try changing the color of the text before the cursor.
Therx

Re:Hardware cursor changes color.

Post by Therx »

No the hardware cursor goes to the foreground color. That way enless the background and foreground colours are the same it will always show up.

I'm not sure if this will solve the problem but just a point:-

80x25 = 4000
Take off 2x80 (=160) because you aren't resetting the last line and you get........3840.
for(i=160; i < 4180; i++)
{
vidmem=vidmem[i+160];
}


Therefore is probally looping a few too many times. The memory beyond 0xb0000 + 4000 is probally either garbage or set to 0 there fore if your code doesn't crash the last line of the screen will contain 0 for character and attribute bytes. This will give you a black cursor on a black background. If the memory beyond 0xb0000 + 4000 contains random values (which may always be the same on a single computer) the cursor may be set to grey. Try the code on another computer if you get no cursor on an another random colour then this is what needs changing. What you should do is print 80 spaces to the last line changing the attribute byte as you go.

Hope this helps

Pete
TheChuckster

Re:Hardware cursor changes color.

Post by TheChuckster »

Thanks for your help, Pete. Although I made mistakes in the total number of video RAM available. ;D Ooops!

The actual problem though was that somehow the last line was being reset to grey on black. I searched my code for the culprit without success.
slacker

Re:Hardware cursor changes color.

Post by slacker »

chuckster: so the forecolor of the hrdwre cursor is dependent on the forecolor of the text?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Hardware cursor changes color.

Post by Pype.Clicker »

slacker: indeed.
slacker

Re:Hardware cursor changes color.

Post by slacker »

...interesting...i prefer a homemade cursor by setting the attribute
Post Reply