Cursor code
-
FireDemon
Cursor code
//Devices.h
//System
__inline__ unsigned inportb(unsigned port)
{
unsigned ret_val;
__asm__ __volatile__("inb %w1,%b0"
: "=a"(ret_val)
: "d"(port));
return ret_val;
}
__inline__ void outportb(unsigned port, unsigned val)
{
__asm__ __volatile__("outb %b0,%w1"
:
: "a"(val), "d"(port));
}
//Cursor.h
class Cursor
{
public:
Cursor()
{
y=0;
x=0;
}
~Cursor()
{
}
void resetcursor()
{
positioncursor(0,0);
}
void positioncursor(int pcx,int pcy)
{
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
x = x;
y = y;
}
unsigned int getx()
{
return x;
}
unsigned int gety()
{
return y;
}
private:
unsigned int y;
unsigned int x;
}; //don't forget the semicolon!
Does not work for some reason
//System
__inline__ unsigned inportb(unsigned port)
{
unsigned ret_val;
__asm__ __volatile__("inb %w1,%b0"
: "=a"(ret_val)
: "d"(port));
return ret_val;
}
__inline__ void outportb(unsigned port, unsigned val)
{
__asm__ __volatile__("outb %b0,%w1"
:
: "a"(val), "d"(port));
}
//Cursor.h
class Cursor
{
public:
Cursor()
{
y=0;
x=0;
}
~Cursor()
{
}
void resetcursor()
{
positioncursor(0,0);
}
void positioncursor(int pcx,int pcy)
{
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
x = x;
y = y;
}
unsigned int getx()
{
return x;
}
unsigned int gety()
{
return y;
}
private:
unsigned int y;
unsigned int x;
}; //don't forget the semicolon!
Does not work for some reason
-
jrfritz
Re:Cursor code
Here is my poscursor...it's function is called gotoxy():
// data:
int cur_cursorX, cur_cursorY; // this is for keeping track of the text mode cursor
static unsigned short *vgaadr; // the VGA address
static unsigned textattrib, scrwidth, scrheight; // the text color, the screen width, & height
// use this function to set up all the variables needed. call this once and it is needed before you use gotoxy.
void start_textmode()
{
cur_cursorX = 0;
cur_cursorY = 0;
gotoxy( 0, 0 );
vgaadr = ( unsigned short * ) 0xb8000;
textattrib = WHITE_BLACK; // white on black
scrwidth = 80;
scrheight = 25;
}
void gotoxy( int x, int y )
{
USHORT position = ( y * scrwidth + x );
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( UCHAR ) ( position & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( UCHAR ) ( ( position >> 8 ) & 0xFF ) );
cur_cursorX = x;
cur_cursorY = y;
}
// data:
int cur_cursorX, cur_cursorY; // this is for keeping track of the text mode cursor
static unsigned short *vgaadr; // the VGA address
static unsigned textattrib, scrwidth, scrheight; // the text color, the screen width, & height
// use this function to set up all the variables needed. call this once and it is needed before you use gotoxy.
void start_textmode()
{
cur_cursorX = 0;
cur_cursorY = 0;
gotoxy( 0, 0 );
vgaadr = ( unsigned short * ) 0xb8000;
textattrib = WHITE_BLACK; // white on black
scrwidth = 80;
scrheight = 25;
}
void gotoxy( int x, int y )
{
USHORT position = ( y * scrwidth + x );
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( UCHAR ) ( position & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( UCHAR ) ( ( position >> 8 ) & 0xFF ) );
cur_cursorX = x;
cur_cursorY = y;
}
Re:Cursor code
dont forget to add the video memory address to the value!FireDemon wrote: void positioncursor(int pcx,int pcy)
{
// cursor LOW port to vga INDEX register
outportb( 0x3D4, 0x0F );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
// cursor HIGH port to vga INDEX register
outportb( 0x3D4, 0x0E );
outportb( 0x3D5, ( unsigned char ) ( ( pcy * 80 + pcx ) & 0xFF ) );
x = x;
y = y;
}
so its + 0xB8000
this is how I do it;
Code: Select all
void UpdateCursor(text_screen *vc)
{
int xx=(vc->intCurrentRow * vc->intMaximumColumn)+vc->intCurrentColumn;
xx+=(int)(vc->intVideoMemoryBuffer)>>1;
out_byte(TEXT_INDEX, TEXT_CURSOR_LO); /* access lo cursor data reg */
out_byte(TEXT_DATA, xx&0xFF);
out_byte(TEXT_INDEX, TEXT_CURSOR_HI); /* access hi cursor data reg */
out_byte(TEXT_DATA, (xx>>8)&0xFF);
}-- Stu --
-
FireDemon
Re:Cursor code
Thanks, I forgot to shift the code. I used the FritzOS code.
Using the above code,how could I change it to get the mouse position.
Using the above code,how could I change it to get the mouse position.
-
FireDemon
Re:Cursor code
I got the text position already, I need to know how to get data from a mouse
-
nullify
Re:Cursor code
You need to write mouse driver code then, e.g., to track the mouse position.
-
FireDemon
Re:Cursor code
Man, can it get anymore complex then this.
Maybe I will do the mouse last.
Maybe I will do the mouse last.
-
DarylD
Re:Cursor code
As I always say, leave things like the keyboard and mouse until later on when you have a scheduler/memory manager etc in place.
What is the use of reading in keyboard presses or mouse movements when you have no OS kernel to have actions acted upon?!!
To be honest, I have a working keyboard driver but it will be no use until I have an elf loader which needs an IO system/cache manager which in my case means I will have a good chunk of the kernel done before I even process my first keystroke.
Daryl.
What is the use of reading in keyboard presses or mouse movements when you have no OS kernel to have actions acted upon?!!
To be honest, I have a working keyboard driver but it will be no use until I have an elf loader which needs an IO system/cache manager which in my case means I will have a good chunk of the kernel done before I even process my first keystroke.
Daryl.
-
FireDemon
Re:Cursor code
I am really not making an OS.
It is a game that will work on all OS systems.
It is a game that will work on all OS systems.
-
jrfritz
Re:Cursor code
That would not always work...some OSes don't allow ports to be read like that...
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Cursor code
The only OS i know that allow such kind of direct hardware access is MS-DOS and clones.Solar Ray wrote: That would not always work...some OSes don't allow ports to be read like that...