www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/11/06/07:59:52

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Mouse operations under DJGPP
Date: Sun, 06 Nov 94 12:36:12 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>

The small test program attached to this message should initialize
the mouse driver in text mode, then home the mouse cursor.  Instead,
it crashes my machine after the call to initialize the mouse driver.
The support function int86dpmi() works with other calls, so it probably
is not the problem.  Then what is?

This is meant to be used for registration of user-written funtions
which should be called when the mouse button is pressed or released.
Can this be done under DJGPP?  I understand that I should allocate
a real-mode wrapper by calling go32_dpmi_allocate_real_mode_callback_retf()
(sp?), then pass the segment and offset to the mouse driver, right?

I looked also at the code in the libgrx library, but it seems that it
relies on go32 support for INT 33h, and that one (go32/exphdlr.c) seems
to only handle simple register-based functions (e.g. it doesn't use all
of the x86 registers).  Am I missing something?  Can the int33() function
in libgrx be used to register user-defined handler?

Thanks in advance for any help.

#include <stdlib.h>
#include <stdio.h>
#include <gppconio.h>
#include <dpmi.h>

/* Support functions */

/* Simulate a software interrupt from protected mode.
   This is like int86() function provided by most DOS-based
   compilers, except that this one works by directly calling
   DPMI services and thus doesn't need DOS extender, only
   a DPMI server.
 */
int
int86dpmi(int intno, const _go32_dpmi_registers *iregs, _go32_dpmi_registers *oregs)
{
  _go32_dpmi_registers regs;

  regs = *iregs;

  /* Set SS and SP to be zero, so that DPMI server would provide
     the stack for the interrupt call.  Also, zero-out FLAGS.
     We don't trust the user to provide values which point to a
     real stack and actually set bits in the FLAGS register; most
     likely, he just forgot to zero them out.  */
  regs.x.ss = regs.x.sp = 0;
  regs.x.flags = 0;

  /* This calls INT 31h AX = 0300h  */
  _go32_dpmi_simulate_int(0x21, &regs);

  *oregs = regs;

  return regs.d.eax;
}

int main(void)
{
  unsigned char buttonCount;
  _go32_dpmi_seginfo   info;
  _go32_dpmi_registers iregs, oregs;

  getch();
  /* Check if a mouse is installed.  If it is, then somebody
     (the mouse driver) should have grabbed the 33h interrupt
     vector.  */
  if (_go32_dpmi_get_real_mode_interrupt_vector(0x33, &info) != 0 ||
      info.rm_segment == 0 && info.rm_offset == 0)
    return 1;

  getch();
  /* Initialise the mouse driver.  This returns the number of buttons
     in BL register.  */
  iregs.x.ax = 0;
  (void)int86dpmi(0x33, &iregs, &oregs);
  if(oregs.x.ax == 0)
    return 1;
  
  buttonCount = oregs.h.bl;

  getch();
  /* Home the mouse cursor. */
  iregs.x.ax = 4;
  iregs.x.cx = 0;
  iregs.x.dx = 0;
  (void)int86dpmi(0x33, &iregs, &oregs);

  printf("%d buttons\n", buttonCount);
  getch();
  return 0;
}

- Raw text -


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