Link to home
Start Free TrialLog in
Avatar of LucJanssens
LucJanssens

asked on

int86 0x33 (mouse) Borland C++ 3.0 Console app

Borland C++ 3.0 allows me to create a console application (exe) with the Console Wizard(new project).  In the help of the compiler I find documentation of the int86 routine (normally found in dos.h).  (Unfortunaly no int86 in dos.h)

I try to run all my old dos examples (mouse driven) with Borland C++ 3.0.

Because int86 doesn't work.  I tried to place directly
asm mov ax,...; asm int 33h; in the C++ code, but my
assemble knowledge is poor.   I even tried the smallest possible mouse int 33h (just initialize the mouse), but the program crashes.

I am looking for an easy way to check the mouse position, state of the buttons,... in the old way.  Perhaps it is no longer possible. (Nevertheless it is still documented in the help file).

If I want to run the old dos programs under windows I have to simulate all: getch, kbhit, cin, cout, delay (not easy).
I am working on this possibility, but this is an hard way (I have to use a separated thread ).  I still hope that someone will be able to help me to check the mouse position, mouse buttons in the old way (int86) with Borland C++ Builder.  

(Also C++ Builder 1.0 has the same problem).

I include here the code of a small example under dos in the hope that someone will be able to run it under Borland C++ 3.0.

///////////good luck
#include <stdio.h>
#include <conio.h>
#include <iostream.h>

// Mouse.h
#include <dos.h>

#if !defined MOUSE_H
#define MOUSE_H


class Mouse
{static union REGS r;
static int aantalknoppen;
// status van een Mouse-object
static int status;
public:

Mouse()
{setbuf(stdout,NULL);  // nodig voor DJGPP compiler (geen schermbuffering)
 // cout is met stdout verbonden
// status=0;
 r.x.ax = 0;        int86(0x33,&r,&r);
 status = r.x.ax;   aantalknoppen = r.x.bx;
}
int allgood(){return status=-1 || status== 65535;}
void show(){ r.x.ax = 1; int86(0x33,&r,&r); }
void hide()  { r.x.ax = 2; int86(0x33,&r,&r); }

void changeposition(int xm,int ym )
  {   r.x.ax = 4;  r.x.cx = xm; r.x.dx = ym; int86(0x33,&r,&r);  }

void position(int &xm,int &ym)
{ if(!allgood()){xm=0;ym=0;return;}
  xm=ym=1;
  r.x.ax = 3;     int86(0x33,&r,&r);   xm = r.x.cx;ym= r.x.dx ;
}

void textposition(int &xm,int &ym){ position(xm,ym);
                           xm=xm>>3;ym=ym>>3;
                                 xm++;ym++;// nodig omdat Mouse anders linker
                              }

void setArea( int minX, int maxX, int minY, int maxY )
  {   r.x.ax = 7; r.x.cx = minX;r.x.dx = maxX;   int86( 0x33, &r, &r );
      r.x.ax = 8; r.x.cx = minY; r.x.dx = maxY;  int86( 0x33, &r, &r );
  }

private:
int pressed( int knop=1/*left*/ )
  {   r.x.ax = 5;  r.x.bx = knop; int86(0x33,&r,&r);
      return r.x.ax & knop;  }

int released( int knop=1/*left*/ )
  {   r.x.ax = 6;    r.x.bx = knop;   int86( 0x33, &r, &r );
      return r.x.ax & knop;  }

public:
int left()       { return pressed( 1 ); }
//int midden()    { return pressed( 4 ); }
int right()      { return pressed( 2 ); }
int leftreleased()    { return released( 1 ); }
//int middenreleased() { return released( 4 ); }
int rightreleased()   { return released( 2 ); }
};
int Mouse::status=0;
union REGS Mouse::r;
int Mouse::aantalknoppen;

#endif

#include <iostream.h>                   // nodig voor cout
#include <conio.h>                      // nodig voor clrscr,gotoxy,...
#include   <dos.h>

#include <iostream.h>                   // nodig voor cout
#include <conio.h>                      // nodig voor clrscr,gotoxy,...
#include   <dos.h>

class clock
{ struct  time t;
  int x, y;
  int hour, minute, second;
public:
clock(int xx,int yy){x = xx; y = yy;}
void show()
  {gettime(&t);
   if ( (int)t.ti_hour != hour || (int)t.ti_min != minute
                        || (int)t.ti_sec != second)
      {  gotoxy(x, y);
       cout<< (int)t.ti_hour<<":"  << (int)t.ti_min<<":"
           << (int)t.ti_sec<<"    ";
       hour= (int)t.ti_hour; minute = (int)t.ti_min ;
       second = (int)t.ti_sec;
      }
  }
};

main()
 { Mouse m;
   clock kl(1,1);
   clock kl2(40,25);
   char letter;   int oldx, oldy, x, y;
   letter =' ';   m.show();   clrscr();
   while( letter != 'x' )
     {kl.show();kl2.show();
      if (m.left() )
       { // left clicked
         m.textposition(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"L";
         while (m.left() )
              {m.textposition(x, y);
               if ( oldx != x || oldy != y )
                   { // left pressed en moving
                     gotoxy(x, y);   cout<<"*"; }
               oldx = x; oldy  = y;
               kl.show();kl2.show();
              }
         // left released
         gotoxy(oldx ,oldy);cout<<"released";
       }
      if (m.right() )
       { // right clicked
         m.textposition(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"R";
         while (m.right() )
              {m.textposition(x, y);
               if ( oldx != x || oldy != y )
                   { // right pressed en moving
                     gotoxy(x, y);   cout<<"."; }
               oldx = x; oldy = y;
               kl.show();kl2.show();
              }
         // right released
         gotoxy(oldx ,oldy);cout<<"right";
       }
      if (kbhit() ) {letter =getch();
                 cout<<letter;    }
     }
   m.hide();
   return 0;
 }
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

You can use the window API functions to access the mouse.  I'll list the functions that will be of most value to you.  Why don't you then read up on them in the windows documentation and if you have questions you can ask me about them.  Then we can discuss actually changing your code to use them (there will be one difficulty).

Use GetCursorPos() to get the current mouse position (for position()).
Use the SetCursorPos() to move the mouse (for changeposition()).
Use GetKeyState() with keys of VK_LBUTTON, VK_MBUTTON, and VK_RBUTTON to get the state of the mouse buttons.