custom mouse pointer in c graphics

C Graphics No Comments »

In C graphics mode when you initialize the mouse you will can see a mouse pointer which is the default one like in windows. I thought of changing it and searched the books. i found a description in yeshavant kanetkar’s book c graphics. The explanation was very nice. I created a program name mice which with i generate various mouse pointers and i save it as a header file which has codes like the following.

Mice will allow you to save mouse pointers as .h file with any valid ms-dos file name.(you can find the mice program and its partial code in future from my home page links title probably “C Snippets”.

The following code used very long variable names just for the matter of understanding… so dont worry the actual code for this seems very tiny…

The shape structure has two type of data of the mouse bitmap. one for the the foreground and other for the transparency… that is cursor mask and screen mask…

When you’re designing the cursor mask, each bit is 1 if it is displayed,
and 0 if it is not. On the screen mask, bits that are 1 are transparent.

you can assume the concept of GIF file here…

	int shape [32] =
			{
				0xffff,0xffff,0xffff,0xffff,
				0xffff,0xffff,0xffff,0xffff,
				0xff3f,0xff3f,0xffff,0xffff,
				0xffff,0xffff,0xffff,0xffff,
				0xf00f,0x8001,0x8001,0x8001,
				0x0,0x0,0x0,0x180,
				0x180,0x0,0x0,0x0,
				0x8001,0x8001,0x8001,0xf00f
			};
 
//Call the function from main as change_mouse_pointer(shape);
 
void change_mouse_pointer(int *shape)
{
	union REGS inputregister,outputregister;
	struct SREGS segmentregister;
 
	inputregister.x.ax=0;
	int86(0x33,&inputregister,&outputregister);
	inputregister.x.ax=1;
	int86(0x33,&inputregister,&outputregister);
 
	inputregister.x.ax=9;
	inputregister.x.bx=0;
	inputregister.x.cx=0;
 
	inputregister.x.dx= (unsigned) shape;
	segread(&segmentregister);
	segmentregister.es=segmentregister.ds;
	int86x(0x33,&inputregister,&outputregister,&segmentregister);
}

and when i searched the net at the time of posting this code i found one good article titled Programming the Microsoft Mouse. but at this date the page was removed. The reason is to see how many such tutorials still exists these days because people almost forgot MS-DOS… but some still had like the universities and other c programmers reference links…

and a news about geocities is that yahoo is going to stop its free web hosting service… so better save a copy of the information whatever you see in geocities… 🙁

It has been a very long time since my programming with the MS-DOS mouse… anyway if good then enjoy…

free hand drawing in c graphics

C Graphics No Comments »

I wrote a program to draw on the screen using putpixel which will plot a pixel at x,y,colorvalue where x,y is the location which you can get from the mouse interrupts… so my idea is to draw but this approach was not much effective because if you move the mouse fast you will not get the desired shape…

so i read a technique which is actually the original way of drawing using the mouse using the lineto function which will not break the path where as using putpixel will break…

 
#include<graphics.h>
#include<bios.h>
#include<dos.h>
 
void getxy();
 
int prevx,prevy,mousex,mousey,butt=1;
 
void main()
{
	int x=DETECT,y;
 
	initgraph(&x,&y,""); 
       // path to EGAVGA.BGI if this is not in your current directory
 
	_AX=0;
	asm int 33h
 
	setcolor(15);
 
	while(inportb(0x60)!=1)
	{
		getxy();
 
		if(butt==1)
		{
			_AX=2;
			asm int 33h
 
			line(mousex-1,mousey-1,prevx-1,prevy-1);
		}
		else
		{
			_AX=1;
			asm int 33h
		}
	}
 
	closegraph();
}
 
void getxy()
{
	_AX=3;
	asm int 33h;
 
	prevx=mousex;
	prevy=mousey;
 
	mousex=_CX;
	mousey=_DX;
	butt=_BX;
 
	gotoxy(2,2);
	printf("%3d   %3d   %2d",mousex,mousey,butt);
}

_AX=0 – Initialize mouse
_AX=1 – show mouse pointer
_AX=2 – hide mouse pointer
_AX=3 – get coordinates and the return values will be in cs and dx.

The while loop executes till the esc key is pressed

Entries RSS