Page 1 of 1

Video Cursor

Posted: Sat Apr 23, 2005 12:12 pm
by Peter
Hi people,

I wrote a simple function to clear the screen:

Code: Select all

void clrscr()
{
    unsigned char *vidmem = (unsigned char *)0xB8000;   // Video memory
   for (yPos; yPos<ROWS; yPos++) {
    for(xPos = 0; xPos<COLLUMS; xPos++)
    {
      *(vidmem + (xPos + yPos * COLLUMS) * 2) = 0;
      *(vidmem + (xPos + yPos * COLLUMS) * 2 + 1) = 0xF;
     }
   }
   yPos = 0;
   xPos = 0;
   
}
When I run the function the cursor is blinking in the middle of the screen. Why does the cursor stand on that place? and how can I hide the cursor or set it to point 0.0.

by the way: 80*25 resolution

Thanks :D

Peter

Re:Video Cursor

Posted: Sat Apr 23, 2005 12:18 pm
by zyp
Use this snippet to put the cursor at 0,0:

Code: Select all

outb(0x3d4, 0x0e);
outb(0x3d5, 0);
outb(0x3d4, 0x0f);
outb(0x3d5, 0);

Re:Video Cursor

Posted: Sat Apr 23, 2005 1:02 pm
by kofrad
zyp wrote: Use this snippet to put the cursor at 0,0:

Code: Select all

outb(0x3d4, 0x0e);
outb(0x3d5, 0);
outb(0x3d4, 0x0f);
outb(0x3d5, 0);
I am going to use this code for my setcursorpos() function, but which one is the x coordinate and which is y? I think the first is the y coordinate because of something my old programming teacher said :P (havent done much vga programming as of yet and my kernel isnt far enough advanced that I can test the function out myself to see)

Re:Video Cursor

Posted: Sat Apr 23, 2005 1:13 pm
by zyp
Neither is, it's the lower and higher byte of the linear position.

Code: Select all

unsigned short pos = x + y * 80;
outb(0x3d4, 0x0e);
outb(0x3d5, pos >> 8);
outb(0x3d4, 0x0f);
outb(0x3d5, pos & 0xff);

Re:Video Cursor

Posted: Sat Apr 23, 2005 1:32 pm
by Peter
Thanks for the fast reactions! :)

I've got a question about the cursor. When I execute this piece of code, the cursor is set in the middle of the screen. But if you write to 0xB8000, the cursor is not moved, sn't it?

Code: Select all

int yPos = 0, xPos = 0;

void clrscr()
{
    unsigned char *vidmem = (unsigned char *)0xB8000;
   for (yPos; yPos<ROWS; yPos++) {
    for(xPos = 0; xPos<COLLUMS; xPos++)
    {
      *(vidmem + (xPos + yPos * COLLUMS) * 2) = 0;
      *(vidmem + (xPos + yPos * COLLUMS) * 2 + 1) = 0xF;
     }
   }
   yPos = 0;
   xPos = 0;

}
Peter

Re:Video Cursor

Posted: Sat Apr 23, 2005 1:54 pm
by kofrad
Hmmm, strange. I modified my code and will test once I can, which is hopefully soon, I think I'm pretty close to getting my print() function working.

Re:Video Cursor

Posted: Sat Apr 23, 2005 1:55 pm
by zyp
You have to move the cursor yourself, it's not done automatically when writing to the screen buffer.

Re:Video Cursor

Posted: Sat Apr 23, 2005 2:17 pm
by kofrad
zyp wrote: You have to move the cursor yourself, it's not done automatically when writing to the screen buffer.
Yeah I know, I have that in my print function already, but I wasnt sure how to move it unless I wrote to the screen, so I wanted a standalone solution.

Re:Video Cursor

Posted: Sun Apr 24, 2005 12:43 am
by Peter
I think I got it!
Even when I not run a clrscr or printf function the cursor stand on that place. It is a standard place I think.
Thanks for your help

Re:Video Cursor

Posted: Sun Apr 24, 2005 12:55 am
by Colonel Kernel
If you're using GRUB, the cursor is probably at the position where GRUB finished outputting text before booting your kernel. That's what happens to me, anyway...

Re:Video Cursor

Posted: Mon Apr 25, 2005 12:08 am
by distantvoices
btw, I'd only move the cursor upon user input at each keystroke, else I'd move it straight to the end of the recently output line (after all the output is done)

Saves some time. ;-)

Re:Video Cursor

Posted: Mon May 23, 2005 1:52 pm
by viral

Code: Select all

void  setcursor(byte i, byte j)
{
       unsigned short position = (j * width + i);

        // cursor LOW port to vga INDEX register
        outportb(0x3D4, 0x0F);
        outportb(0x3D5, (unsigned char)(position & 0xFF));

        // cursor HIGH port to vga INDEX register
        outportb(0x3D4, 0x0E);
       outportb(0x3D5, (unsigned char)((position >> 8) & 0xFF));
}


This will move your hardware cursor at desired X,Y position.

Re:Video Cursor

Posted: Sat May 28, 2005 5:29 pm
by cabron
One thing that I just figured out, I'm sure it's obvious to some (most?), but the cursor will be displayed in whatever color the framebuffer has for that particular character...

I was clearing my screen with memset( buf, 0, 80*25*2 ) and wondering why my cursor had disappeared... :P