Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[MSDOS] Trouble with mouse programming

2 views
Skip to first unread message

Minti

unread,
Apr 10, 2004, 2:42:57 AM4/10/04
to
Hi I am trying to run this simple test program to on my WinXP, but
every time I try to run it just crashes. I have also tested couple of
programs from Net on my machine but they also seem to fail. I reckon
that WinXP does not allow me to set up a mouse handler.


#include <stdio.h>
#include <dos.h>
#include <conio.h>

const int MOUSE_INT_MASK = 0x15;
union REGS i, o;
union SREGS sr;

void far interrupt mouse_handler()
{

printf("You did something with mouse\n");

}
int init_mouse()
{
int i;
asm {
mov ax, 0;
int 0x33;
mov i, ax

}
return i;

}

void show_mouse() {

asm {
mov ax, 0x1;
int 0x33;
}
}

void mouse_init( )
{
unsigned short seg = FP_SEG(mouse_handler);
unsigned short off = FP_OFF(mouse_handler);
/* convert the below to assembly */
i.x.ax = 0x0C;
i.x.cx = MOUSE_INT_MASK;
i.x.dx = off;
sr.es = seg;
int86x(0x33, &i, &o, &sr);
}

int main(void)
{
clrscr();

init_mouse();
show_mouse();
mouse_init();
while(!kbhit())
continue;
return 0;
}

Kenneth Brody

unread,
Apr 10, 2004, 11:08:33 AM4/10/04
to
Minti wrote:
>
> Hi I am trying to run this simple test program to on my WinXP, but
> every time I try to run it just crashes. I have also tested couple of
> programs from Net on my machine but they also seem to fail. I reckon
> that WinXP does not allow me to set up a mouse handler.
[...]

> asm {
> mov ax, 0;
> int 0x33;
> mov i, ax
>
> }
[...]

Remember, XP does not run on top of DOS, as 95/98/Me do. It does have
a DOS emulation built in, but it does not support all of the interrupt
handlers. Perhaps the mouse's INT33 is one that is not supported?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody at spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+


Yngvar Fųlling

unread,
Apr 15, 2004, 11:53:55 AM4/15/04
to
In article <108158...@nospam.demon.co.uk>, pe...@nospam.demon.co.uk
says...

> > void far interrupt mouse_handler()
> > {
> >
> > printf("You did something with mouse\n");
> >
> > }
>

> It's not a good idea to call i/o lib functions (like printf,
> which not only consume a lot of stack but probably also invoke
> DOS services at lower levels). Try something simpler like e.g.

I'd say it more strongly: This will virtually guarantee a crash. It may
not be the *only* problem, but it is definitely a *major* problem.

> void far interrupt mouse_handler()
> {
> /* just display a plus sign */
> asm {
> push ax;
> mov al, '+';
> int 0x29;
> pop ax;
> }
> }

Even this looks risky to me. Any call to either DOS or the BIOS is
problematic, as are a large part of the library routines. Floating
point should also be avoided.

What I would do is simply to set a global variable, which could then be
tested in the main loop. Interrupt routines should be kept to an
absolute minimum, unless you're very knowledgeable about checking the
DOS state and setting up a stack.

However, I could add that the saving and restoring of AX is probably
unnecessary. I know that the Intel 80x86/Pentium interrupts only save
the CS, IP and flags registers, but if I remember Turbo/Borland C
correctly, it saves all CPU registers on the stack on entry to an
"interrupt" routine, and restores them afterwards.

> > int main(void)
> > {
> > clrscr();
> >
> > init_mouse();
>
> You declared this as returning int, but don't check the return
> value. This could be the root cause of your problem...

Not likely. You may be confusing this with defining a function in a
different file, and forgetting a declaration when calling it. That can
indeed cause trouble. But if the function is defined in the same file
as the caller, all C compilers should be able to handle the ignored
value.

> > show_mouse();
> > mouse_init();
> > while(!kbhit())
> > continue;
> > return 0;
> > }
> >
>

> Pete

On a closing note: It *is* compiled for 16-bit DOS? Not any 32-bit
solution?

Yngvar

0 new messages