Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

aspguru

please help!!! Turbo c problem.

This topic is 5681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to draw using mouse in Turbo c/c++. I can draw stuff without using mouse, but I don''t know how to capture current mouse position etc. I want to draw(paint) each pixel, where i click with the left mouse button. please give me an example. thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
Sorry I cant help you, but Im curious of what Turbo C is. Could you give an explication?

----PATRIOTISM----

“Beware the leader who bangs the drums of war in order to whip the citizenry into a patriotic fervor, for patriotism is indeed a double-edged sword. It both emboldens the blood, just as it narrows the mind. And when the drums of war have reached a fever pitch and the blood boils with hate and the mind has closed, the leader will have no need in seizing the rights of the citizenry. Rather, the citizenry, infused with fear and blinded by patriotism, will offer up all of their rights unto the leader and gladly so. How do I know? For this is what I have done.
And I am Caesar.”

— Julius Caesar

Share this post


Link to post
Share on other sites
unless you want to code int 33 calls in (possibly inline) assembly, which is doubtful, i suggest you look around for free mouse libraries for dos on google or elsewhere.

Share this post


Link to post
Share on other sites
Actually, int 33h is really pretty easy. I''d actually like to see what is going on inside... Anyway...


  
#include <iostream.h>
#include <conio.h>

unsigned char far* videoBuffer = (unsigned char far*)0xA0000000;

int resetMouseDriver();
void showMouse();
void hideMouse();
void getMousePos(unsigned int* x, unsigned int* y);


int main() {
unsigned int x,y;

asm {
mov ah, 0
mov al, 0x13
int 0x10
}

if(!resetMouseDriver()) {
cout << "Error...";
return 0;
}

hideMouse();

while(!kbhit()) {
getMousePos(&x, &y);
videoBuffer[(y*320)+(x/2)] = 11;
}

asm {
mov ah, 0
mov al, 0x03
int 0x10
}

return 0;
}

/*
Returns 0 in AX on failure, 0xFFFF on success.
The number of mouse buttons is returned in BX, but this is a mouse movement demo, so... ;)
*/
int resetMouseDriver() {
asm {
mov ax, 0
int 0x33
};
}

/*
Shows the default cursor.
*/
void showMouse() {
asm {
mov ax, 0x01
int 0x33
};
}

/*
Hide the default cursor.
*/
void hideMouse() {
asm {
mov ax, 0x02
int 0x33
};
}

/*
Returns Absolute XPos in CX, and absoulte YPos in DX.
Also returns status of buttons in BX, but again, this is a mouse movement demo...

bits 0,1,2 are for the three mouse buttons, left,right,center (respectively). If the bit is 1 the mouse button is down, it''ll be 0 otherwise.
*/

void getMousePos(unsigned int* x, unsigned int* y) {
unsigned int mx, my;
asm {
mov ax, 0x03
int 33h
mov mx, cx
mov my, dx
};

*x = mx;
*y = my;
}


I compiled this with TurboC++ 3.0, and it worked fine. You''ll have to changed the "cout", and include stdio.h, but other than that it should compile under TurboC.

Sorry, this only shows mouse movement, but I really have to run. I left some comments for mouse buttoning though. (Was going to do the whole shabang, but I ran out of time.)

Share this post


Link to post
Share on other sites
Phew... Almost missed Futurama (I could kiss Cartoon Network. I missed the series when it first aired.)

Anyway, I updated the code from above for clicking and stuff.


        
#include <iostream.h>
#include <conio.h>

unsigned char far* videoBuffer = (unsigned char far*)0xA0000000;

int resetMouseDriver();
void showMouse();
void hideMouse();
void getMouseInput(unsigned int* x, unsigned int* y, unsigned int* buttons);


int main() {

unsigned int x, y, buttons;

asm {
mov ah, 0
mov al, 0x13
int 0x10
}

if(!resetMouseDriver()) {
cout << "Error...";
return 0;
}

hideMouse();

while(!kbhit()) {
getMouseInput(&x, &y, &buttons);

videoBuffer[y*320+((x/2))] = 11;

if(buttons & 0x01) videoBuffer[y*320+((x/2))] = 4; /*Left Button*/
if(buttons & 0x02) videoBuffer[y*320+((x/2))] = 1; /*Right Button*/
if(buttons & 0x04) videoBuffer[y*320+((x/2))] = 15; /*Middle Button*/
}

asm {
mov ah, 0
mov al, 0x03
int 0x10
}

return 0;
}

/*
Returns 0 in AX on failure, 0xFFFF on success.
The number of available mouse buttons is returned in BX.
*/
int resetMouseDriver() {
asm {
mov ax, 0
int 0x33
};
}

/*
Shows the default cursor.
*/
void showMouse() {
asm {
mov ax, 0x01
int 0x33
};
}

/*
Hides the default cursor.
*/
void hideMouse() {
asm {
mov ax, 0x02
int 0x33
};
}

/*
Returns Absolute XPos in CX, and absoulte YPos in DX.
Also returns status of the mouse buttons in BX.

bits 0,1,2 are for the three mouse buttons, left,right,center (respectively). If the bit is 1 the mouse button is down, otherwise it'll be 0.
*/

void getMouseInput(unsigned int* x, unsigned int* y, unsigned int* buttons) {
unsigned int mx, my, mb;

asm {
mov ax, 0x03
int 33h
mov mx, cx
mov my, dx
mov mb, bx
};

*x = mx;
*y = my;
*buttons = mb;

return;
}




quote:
Sorry I cant help you, but Im curious of what Turbo C is. Could you give an explication?


Turbo C is a compiler, made by Borland www.borland.com, you can download version one for free on Borland's website.

[edited by - Xanth on January 23, 2003 12:21:23 AM]

[edited by - Xanth on January 23, 2003 12:28:17 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
okay, this solution is simple. firstly, dont use assembler with your mouse program. i wrote a mouse program in turbo C entirely aswell but that was ages ago. make a structure that all your functions put data into. my structure consisted of only three
integers, thats all (X,Y and button) it may look like this:

info->X = outregs.x.cx;
info->Y = outregs.x.dx;
info->Button = outregs.x.bx;

just say that info is your structure.

i hope this helped you.

Share this post


Link to post
Share on other sites
quote:
okay, this solution is simple. firstly, dont use assembler with your mouse program. i wrote a mouse program in turbo C entirely aswell but that was ages ago. make a structure that all your functions put data into. my structure consisted of only three
integers, thats all (X,Y and button) it may look like this:

info->X = outregs.x.cx;
info->Y = outregs.x.dx;
info->Button = outregs.x.bx;

just say that info is your structure.


union REGS is Assembly (technically), I agree with the structure part though.

Share this post


Link to post
Share on other sites
Heres an example with a struct. (Again, tested in Turbo C++ 3)


  #include <iostream.h>
#include <conio.h>

unsigned char far* videoBuffer = (unsigned char far*)0xA0000000;

struct mouseInfo {
unsigned int x, y, button;
};

int resetMouseDriver();
void showMouse();
void hideMouse();
void getMouseInput(mouseInfo* mouse);

int main() {

mouseInfo mouse;

asm {
mov ah, 0
mov al, 0x13
int 0x10
}

if(!resetMouseDriver()) {
cout << "Error...";
return 0;
}

hideMouse();

while(!kbhit()) {
getMouseInput(&mouse);

videoBuffer[mouse.y*320+mouse.x/2] = 11;

if(mouse.button & 0x01) videoBuffer[mouse.y*320+mouse.x/2] = 4; /*Left Button*/
if(mouse.button & 0x02) videoBuffer[mouse.y*320+mouse.x/2] = 1; /*Right Button*/
if(mouse.button & 0x04) videoBuffer[mouse.y*320+mouse.x/2] = 5; /*Middle Button*/
}

asm {
mov ah, 0
mov al, 0x03
int 0x10
}

return 0;
}

/*
Returns 0 in AX on failure, 0xFFFF on success.
The number of available mouse buttons is returned in BX.
*/
int resetMouseDriver() {
asm {
mov ax, 0
int 0x33
};
}

/*
Shows the default cursor.
*/
void showMouse() {
asm {
mov ax, 0x01
int 0x33
};
}

/*
Hides the default cursor.
*/
void hideMouse() {
asm {
mov ax, 0x02
int 0x33
};
}

/*
Returns Absolute XPos in CX, and absoulte YPos in DX.
Also returns status of the mouse buttons in BX.

bits 0,1,2 are for the three mouse buttons, left,right,center (respectively). If the bit is 1 the mouse button is down, otherwise it''ll be 0.
*/

void getMouseInput(mouseInfo* mouse) {
asm {
mov ax, 0x03
int 33h
mov [mouse+2], cx
mov [mouse+4], dx
mov [mouse+6], bx
};

return;
}

Share this post


Link to post
Share on other sites
Thanks everybody for the replies. Thanks Xanth. I was required to use int86 instead of using embedded asm instructions such as mov. Besides that, I got exactly what I needed.

Just one more question. I would like to draw a circle in TC30 using C, by getting the center coordinates and the radius from the user. I am not allowed to use the circle function in graphics.h. How would I do that. I believe I am going to have to use trignometry functions but I don''t know how.

Thanks for your help.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!