delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/04/02/10:45:14

From: "Ben Peddell" <lightspeed85 AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <b6e7d6$o6b$1 AT saphir DOT jouy DOT inra DOT fr>
Subject: Re: Using the mouse
Lines: 108
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Message-ID: <UbDia.5383$1s1.64076@newsfeeds.bigpond.com>
Date: Thu, 3 Apr 2003 01:11:40 +1000
NNTP-Posting-Host: 144.139.175.146
X-Trace: newsfeeds.bigpond.com 1049296756 144.139.175.146 (Thu, 03 Apr 2003 01:19:16 EST)
NNTP-Posting-Date: Thu, 03 Apr 2003 01:19:16 EST
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eric Wajnberg <wajnberg AT antibes DOT inra DOT fr> wrote in message
news:b6e7d6$o6b$1 AT saphir DOT jouy DOT inra DOT fr...
> Dear all,
>
> I need your help with DJGPP. I am currently developing a C code, and, in
it, I
> need to know the location of the mouse, and if the left button is pressed
or
> not. That's all!
>
> I am sure that this can be coded in a couple of lines only. Can somone
help
> me?
>
> Best, Eric.
>

If you can, you should try to determine whether interrupt 0x33 has been
initialized. An un-initialized int 0x33 will lead to problems (Page Faults,
GPFs, etc) when you try to call it.

These functions are just as an example. They would be better as assembly
functions (in an S file).

First, you must initialize the mouse.

    /*
     * initialize mouse
     *     returns:
     *        -1 if driver not installed
     *        otherwise number of buttons (0 meaning unknown)
     */
    int init_mouse (void){
        REGS regs;
        regs.w.ax = 0;
        int86 (0x33, &regs, &regs);
        if (regs.w.ax == 0){
            return -1;
        } else {
            if (regs.w.bx == 0xFFFF){
                regs.w.bx = 2;    /* 2 buttons */
            }
            return regs.w.bx;
        }
    }

Then, show or hide the mouse pointer as desired.

    /*
     * show mouse cursor
     *    mouse driver implements a counter - multiple show
     *    calls will require the same number of calls to hide
     *    calls to hide the mouse pointer.
     */
    void show_mouse (void) {
        REGS regs;
        regs.w.ax = 1;
        int86 (0x33, &regs, &regs);
    }

    /*
     * hide mouse pointer
     */
    void hide_mouse (void) {
        REGS regs;
        regs.w.ax = 2;
        int86 (0x33, &regs, &regs);
    }

You can find out the position and button status at any time after
initializing the mouse.

    /*
     * get the position and button status
     *     status:
     *        bit 0: left button pressed if set
     *        bit 1: right button pressed if set
     *        bit 2: middle button pressed if set
     *        could possibly have further bits on advanced mouse drivers.
     *    position is (x, y)
     */
    void get_mouse_pos_status (int *status, int *x, int *y) {
        REGS regs;
        regs.w.ax = 3;
        int86 (0x33, &regs, &regs);
        *status = regs.w.bx;
        *x = regs.w.cx;
        *y = regs.w.dx;
    }

You can also set the mouse position.

    /*
     * set mouse position
     */
    set_mouse_pos (int x, int y) {
        REGS regs;
        regs.w.ax = 4;
        regs.w.cx = x;
        regs.w.dx = y;
        int86 (0x33, &regs, &regs);
    }

There are further functions that you can call. They are shown in Ralf
Brown's Interrupt List.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019