Page 1 of 1
Hardware Cursor
Posted: Wed Apr 23, 2003 2:03 pm
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;
}
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 2:20 pm
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);
}
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 3:02 pm
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 ...
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 3:47 pm
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;
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 4:00 pm
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.
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 4:25 pm
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...
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 5:04 pm
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).
Re:Hardware Cursor
Posted: Wed Apr 23, 2003 5:20 pm
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...
Re:Hardware Cursor
Posted: Fri Apr 25, 2003 12:16 pm
by jamescox3k
What are the varius out() functions in Tim Robinsons example back there.
Re:Hardware Cursor
Posted: Fri Apr 25, 2003 12:21 pm
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.
Re:Hardware Cursor
Posted: Fri Apr 25, 2003 1:41 pm
by Mastermind
slacker:
my code is somewhat like yours, except that it leaves the text alone instead of changing it...
Re:Hardware Cursor
Posted: Fri Apr 25, 2003 1:42 pm
by Mastermind
Ahh. I see. I've got the cursor working. Thanks!