Hardware Cursor

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
Mastermind

Hardware Cursor

Post by Mastermind »

Forgive me if I sound stupid... How do you move the cursor when displaying text?

I have a very primitive output function:

Code: Select all

int output(int color, int row, int col, char *string) {
   char *video = (char*)0xB8000;
   int count = 0;
   row = _width * row;
   col = col + row;
   while(col!=0) {
      video++;
      video++;
      col--;
   }
   while(*string!=0) {
      *video=*string;
      string++;
      video++;
      *video=color;
      video++;
      count++;
   }
   return count;
}
Tim

Re:Hardware Cursor

Post by Tim »

Like this:

Code: Select all

static void DbgUpdateCursor(void)
{
    unsigned short Off;

    Off = (dbg_y * 80 + dbg_x) * 2;
    out(VGA_CRTC_INDEX, 14);
    out(VGA_CRTC_DATA, Off >> 9);
    out(VGA_CRTC_INDEX, 15);
    out(VGA_CRTC_DATA, Off >> 1);
}
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

Post by Pype.Clicker »

oh, btw, i suggest you don't move the cursor after every char, but after a line or a "printf" command is completed.
Otherwise, you'll have a veeeery sloooow display ...
slacker

Re:Hardware Cursor

Post by slacker »

i decided that i didnt want to use the hardware cursor in my OS. instead i just used a location in video memory and set the attribute to white background. i like this kind of cursor better. try it and you will proboly like it too. and btw its easy to update:

videomemory[GLOBALVIDOFF-1]=0x07;
videomemory[GLOBALVIDOFF+1]=0x70;
Tim

Re:Hardware Cursor

Post by Tim »

This is OK until you want to put the cursor over some other character. The hardware cursor will work when superimposed like this, but the software cursor will overwrite whatever it underneath.
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

Post by Pype.Clicker »

another widely used trick (among each other, by the mouse cursor) is to reverse the attribute byte and leaving the character byte unchanged ...

However, the cursor is mainly required when input from the keyboard is required ... what is the use for cursor update when printing the output of LS ? hide it until the application is blocked waiting for some input from the user, *then* show it (and i would show it using the hardware if possible, as this will allow automatic blinking, etc.)

Think about it: accessing video ram and video I/O port will have the same cost, as it implies crossing the very same bus...
Tim

Re:Hardware Cursor

Post by Tim »

...unless said video RAM is cached, in which case the CPU won't use the bus on every access, and when it does, it will do so in a burst (e.g. one cache line at a time).
slacker

Re:Hardware Cursor

Post by slacker »

tim: To use my method of making a cursor its proboly possible to change the attribute of the location from white on black to black on white. the program EDIT in dos changes from white on blue to black on yellow. that way the software cursor wont overwrite...
jamescox3k

Re:Hardware Cursor

Post by jamescox3k »

What are the varius out() functions in Tim Robinsons example back there.
Tim

Re:Hardware Cursor

Post by Tim »

What is the out function? It writes a byte to an I/O port. Mine looks like this:

Code: Select all

static __inline void out(uint16_t port, uint8_t value)
{
   __asm__ __volatile__ ("outb %%al, %%dx" : : "d" (port), "a" (value));
}
BTW: this function is put into my i386.h file. This is an exception to the rule of no functions in headers. It's inline, so it must be implemented in every module where it is used (the compiler can't inline functions across modules). Because of that, it's declared as private to this module (by the static keyword) so that, if more than one module uses the out function, they don't conflict.
Mastermind

Re:Hardware Cursor

Post by Mastermind »

slacker:
my code is somewhat like yours, except that it leaves the text alone instead of changing it...
Mastermind

Re:Hardware Cursor

Post by Mastermind »

Ahh. I see. I've got the cursor working. Thanks!
Post Reply