Aula Macedonia


Curso de Programación Multimedia Bajo DOS


Artículo realizado por
José Antonio Suárez.





Código fuente para el capítulo 2.


RATON.H

// LIBRERIA DEL RATON

#include <dos.h>

// Mascara-dibujo del cursor

int cursor1 [32+32] = {
 0x3FFF, 0x1FFF, 0x0FFF, 0x07FF,
 0x03FF, 0x01FF, 0x00FF, 0x007F,
 0x003F, 0x001F, 0x000F, 0x0007,
 0x0007, 0xF81F, 0xFC0F, 0xFE0F,

 0x0000, 0x4000, 0x6000, 0x7000,
 0x7800, 0x7C00, 0x7E00, 0x7F00,
 0x7F80, 0x7FC0, 0x7FE0, 0x7FF0,
 0x0780, 0x03C0, 0x01E0, 0x0000 };

// Detecta la existencia del driver del ratón
int  DetectarRaton(void);
// Muestra la flecha
void MostrarRaton(void);
// Oculta la flecha
void OcultarRaton(void);
// Establece una zona rectangular de la que el ratón no puede salir
void EstablecerLimRaton(int,int,int,int);
// Pone la flecha en una coordenada
void EstablecerPosRaton(int,int);
// Espera a que se pulse un botón determinado
void EsperarPulsadoBoton(int *);
// Espera a que se suelte el botón determinado
void EsperarSoltadoBoton(int);
// Espera a que se pulse el botón izquierdo
void EsperarPulsadoBotonI(void);
// Espera a que se suelte el botón izquierdo
void EsperarSoltadoBotonI(void);
// Espera a que se pulse el botón derecho
void EsperarPulsadoBotonD(void);
// Espera a que se suelte el botón derecho
void EsperarSoltadoBotonD(void);
// Lee la coordenada del ratón y el estado de los botones
void LeerEstadoRaton(int *,int *,int *);
// Lee sólo la coordenada del ratón
void LeerPosRaton(int *,int *);
// Lee sólo el estado de los botones
void PulsadoBoton(int *);
// Espera a que se pulse cualquier botón
void EsperarPulsadoCualquierBoton(int *);
// Cambia el puntero
void CambiaPunteroRaton(void);
// Inicializa el driver del ratón
void InicializaRaton(int *,int *,char *);
// Adec£a la coordenada del ratón para las BGI de Borland C
void EvitaIncompRaton1(int,int);
// Guarda la coordenada actual y oculta la flecha
void AlejaRaton(int *,int *);
// Deshace el alejamiento del ratón guardando la compatibilidad con las BGI
void AcercaRaton(int,int);
 
 

RATON.C

#include "raton.h"

int DetectarRaton(void)
{
 int w;

 asm{
   mov ax,0
   mov bx,2
   int 0x33
   mov w,ax
 }
 return(w);
}

void MostrarRaton( void )
{
 asm{
   mov ax,1
   int 0x33
 }
}

void OcultarRaton( void )
{
 asm{
   mov ax,2
   int 0x33
 }
}

void EstablecerLimRaton(int xi,int yi,int xf,int yf)
{
 asm{
   mov ax,7
   mov cx,xi
   mov dx,xf
   int 0x33
   mov ax,8
   mov cx,yi
   mov dx,yf
   int 0x33
 }
}

void EstablecerPosRaton(int x,int y)
{
 asm{
   mov ax,4
   mov cx,x
   mov dx,y
   int 0x33
 }
}

void EsperarPulsadoBoton(int *bot)
{
 do
 {
  PulsadoBoton(bot);
 }
 while ((*bot!=1)&&(*bot!=2));
}

void EsperarSoltadoBoton(int bot)
{
 int *boton;

 do
 {
  PulsadoBoton(boton);
 }
 while (*boton==bot);
}

void EsperarPulsadoBotonI(void)
{
 int *bot;

 *bot=1;
 do
 {
  PulsadoBoton(bot);
 }
 while (*bot!=1);
}

void EsperarSoltadoBotonI(void)
{
 int *bot;

 do
 {
  PulsadoBoton(bot);
 }
 while (*bot==1);
}

void EsperarPulsadoBotonD(void)
{
 int *bot;

// *bot=2;
 do
 {
  PulsadoBoton(bot);
 }
 while (*bot!=2);
}

void EsperarSoltadoBotonD(void)
{
 int *bot;

 do
 {
  PulsadoBoton(bot);
 }
 while (*bot==2);
}

void LeerEstadoRaton(int *x,int *y,int *bot)
{
 int xx,yy,boton;

 asm{
   mov ax,3
   int 0x33
   mov boton,bx
   mov xx,cx
   mov yy,dx
 }
 // Si vale 1 es el izquierdo, si vale 2 es el derecho,si vale 4 el central
 *x=xx;
 *y=yy;
 *bot=(int)boton;
}

void LeerPosRaton(int *x,int *y)
{
 int xx,yy;

 asm{
   mov ax,3
   int 0x33
   mov xx,cx
   mov yy,dx
 }
 *x=xx;
 *y=yy;
}

void PulsadoBoton(int *bot)
{
 int boton;
 asm{
  mov ax,3
  int 0x33
  mov boton,bx
  }
 // Si vale 1 es el izquierdo, si vale 2 es el derecho,si vale 4 el central
 *bot=(int)boton;
}

void EsperarPulsadoCualquierBoton(int *bot)
{
 do
 {
  PulsadoBoton(bot);
 }
 while ((*bot==2)||(*bot==1));
}

void CambiaPunteroRaton(void)
{
 long dir;
 int dir2,dir3;

 dir=(long)cursor1;
 dir2=(int)dir;
 dir3=(int)(dir>>16);
 asm{
   mov ax,9
   mov bx,0
   mov cx,0
   mov dx,dir2
   mov es,dir3
   int 0x33
 }
}

void InicializaRaton(int *posx,int *posy,char *hayraton)
{
 *hayraton=DetectarRaton();
 if (*hayraton==-1)
 {
  CambiaPunteroRaton();
  EstablecerPosRaton(360,250);
  // EstablecerPosRaton(650,490);
  MostrarRaton();
  LeerPosRaton(posx,posy);
 }
}

void EvitaIncompRaton(int posx,int posy)
{
 if ((posx!=650)||(posy!=490))
 {
  EstablecerLimRaton(0,0,630,470);
 }
}

void AlejaRaton(int *posx,int *posy)
{
 LeerPosRaton(posx,posy);
 OcultarRaton();
}

void AcercaRaton(int posx,int posy)
{
 EstablecerLimRaton(0,0,650,490);
 EstablecerPosRaton(650,490);
 MostrarRaton();
 EstablecerPosRaton(posx,posy);
 EstablecerLimRaton(0,0,630,470);
}
 
 

EJEMPLO DE USO

void main(void)
{
 int bot;

 DetectarRaton();
 do
 {
  sound(700);
  // Esperar pulsación del botón izquierdo
  EsperarPulsadoBoton(&bot);
//  do
//  {
// asm{
//  mov ax,3
//  int 0x33
//  mov bot,bx
// }
//  }
//  while ((bot!=1)&&(bot!=2));
  nosound();
  if (bot==1) EsperarSoltadoBotonI();
  if (bot==2) EsperarSoltadoBotonD();

 }
 while (!kbhit());
}




AULA MACEDONIA
a
MACEDONIA Magazine