home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boldly Go Collection
/
version40.iso
/
TS
/
17A
/
DRWIN101.ZIP
/
MOUSUTIL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-23
|
14KB
|
359 lines
#include <stdio.h>
#include <dos.h>
#include "mousutil.h"
static union REGS ir,or;
static MOUSTRAP mousfunc=NULL;
static char mousinitd=0;
/****************************************************************************/
/* mousinit */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* This function initializes the mouse. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/* Returns 1 if a mouse is available, 0 otherwise. */
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
int mousinit(void)
{
LWORD iv; /*interrupt vector for mouse*/
disable();
iv=*(LWORD far *)((LWORD)(MOUSINT<<2)); /*get interrupt vector*/
enable();
mousinitd=0;
if (iv==0) return 0;
ir.x.ax=0x0000;
int86(MOUSINT,&ir,&or);
if (or.x.ax==0) return 0;
mousinitd=1;
return 1;
} /*mousinit*/
/****************************************************************************/
/* mousset, mousshow, moushide */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* These functions turn on/off the display of the mouse. */
/* mousset() will call mousshow if its argument is non-zero; otherwise, */
/* it calls moushide. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
void mousshow(void)
{
if (!mousinitd) if (!mousinit()) return;
ir.x.ax=0x0001;
int86(MOUSINT,&ir,&or);
} /*mousshow*/
void moushide(void)
{
if (!mousinitd) if (!mousinit()) return;
ir.x.ax=0x0002;
int86(MOUSINT,&ir,&or);
} /*moushide*/
void mousset(int show)
{
if (show) mousshow(); else moushide();
} /*mousset*/
/****************************************************************************/
/* mousgetrow, mousgetcol, mousgetbut, mousgetall */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* These functions return status information to the caller. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
int mousgetall(MOUS *m)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
m->butstat=or.x.bx; /*button status*/
m->row=or.x.dx; /*row, Y-coordinate*/
m->col=or.x.cx; /*col, X-coordinate*/
m->butcnt=(or.x.bx!=0); /*set button count for easy-check*/
return 1;
} /*mousgetall*/
int mousgetbut(void)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
return or.x.bx; /*button status*/
} /*mousgetbut*/
int mousgetrow(void)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
return or.x.dx; /*row, Y-coordinate*/
} /*mousgetrow*/
int mousgetcol(void)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
return or.x.cx; /*column, X-coordinate*/
} /*mousgetcol*/
/****************************************************************************/
/* moussetrow, moussetcol, moussetall */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
int moussetall(MOUS *m)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0004;
ir.x.cx=m->col;
ir.x.dx=m->row;
int86(MOUSINT,&ir,&or);
return 1;
} /*moussetall*/
int moussetcpos(int row,int col)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0004;
ir.x.cx=col;
ir.x.dx=row;
int86(MOUSINT,&ir,&or);
return 1;
} /*moussetcpos*/
int moussetrow(int row)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
ir.x.ax=0x0004;
ir.x.cx=or.x.cx; /*keep current column*/
ir.x.dx=row; /*set the new row*/
int86(MOUSINT,&ir,&or);
return 1;
} /*moussetrow*/
int moussetcol(int col)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0003;
int86(MOUSINT,&ir,&or);
ir.x.ax=0x0004;
ir.x.dx=or.x.dx; /*keep current row*/
ir.x.cx=col; /*set the new column*/
int86(MOUSINT,&ir,&or);
return 1;
} /*moussetcol*/
/****************************************************************************/
/* mousgetprs, mousgetrel */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* These functions return information about the most recent button press */
/* and release. Use the constants MOUS_LBUT, MOUS_RBUT and MOUS_CBUT to */
/* specify which button you will request information for. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
int mousgetprs(WORD but,MOUS *m)
{
if (but>MOUS_CBUT) return 0;
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x0005;
ir.x.bx=but;
int86(MOUSINT,&ir,&or);
m->butstat=or.x.ax;
m->butcnt=or.x.bx; /*button-presses since last call*/
m->row=or.x.dx; /*row of last press*/
m->col=or.x.cx; /*column of last press*/
return 1;
} /*mousgetprs*/
int mousgetrel(WORD but,MOUS *m)
{
if (!mousinitd) if (!mousinit()) return 0;
if (but>MOUS_CBUT) return 0;
ir.x.ax=0x0006;
ir.x.bx=but;
int86(MOUSINT,&ir,&or);
m->butstat=or.x.ax;
m->butcnt=or.x.bx; /*button-releases since last call*/
m->row=or.x.dx; /*row of last release*/
m->col=or.x.cx; /*column of last release*/
return 1;
} /*mousgetrel*/
/****************************************************************************/
/* mouscurstype */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* This function sets the screen and cursor masks for the mouse. The */
/* screen mask is ANDed, and the cursor mask is XORed, with the attribute */
/* and character at the current mouse cursor's position. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.10.09 D. Rogers initial code */
/****************************************************************************/
int mouscurstype(WORD and,WORD xor)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x000A;
ir.x.bx=0; /*use attribute cursor, not hardware*/
ir.x.cx=and;
ir.x.dx=xor;
int86(MOUSINT,&ir,&or);
return 1;
} /*mouscurstype*/
int moushwcurs(WORD start,WORD stop)
{
if (!mousinitd) if (!mousinit()) return 0;
ir.x.ax=0x000A;
ir.x.bx=0xFFFF; /*hardware*/
ir.x.cx=start; /*start scan line*/
ir.x.dx=stop; /*stop scan line*/
int86(MOUSINT,&ir,&or);
return 1;
} /*moushwcurs*/
/****************************************************************************/
/* moustrap */
/****************************************************************************/
/*-----------------------------Description----------------------------------*/
/* This function allows you to set up a function to trap mouse conditions */
/* within regions on the screen. */
/*-----------------------------Arguments------------------------------------*/
/*-----------------------------Return value---------------------------------*/
/*-----------------------------Global constants-----------------------------*/
/*-------------------Mod-------Global variables-----------------------------*/
/*-----------------------------Functions called-----------------------------*/
/*-----------------------------Constraints/Gotchas--------------------------*/
/*--Date--------Programmer----------Comments--------------------------------*/
/* 1990.01.01 A. Turing initial code */
/****************************************************************************/
void mousintfunc(void)
{
auto int event;
auto int button;
auto int x;
auto int y;
auto int xcounts;
auto int ycounts;
asm PUSH DS
asm PUSH AX
asm PUSH BX
asm PUSH CX
asm PUSH DX
asm PUSH SI
asm PUSH DI
asm MOV event,AX
asm MOV button,BX
asm MOV x,CX
asm MOV y,DX
asm MOV xcounts,SI
asm MOV ycounts,DI
#if defined(__HUGE__)|defined(__LARGE__)|defined(__COMPACT__)
asm MOV AX,SEG mousfunc
asm MOV DS,AX
#endif
if (mousfunc) mousfunc(event,button,x,y,xcounts,ycounts);
asm POP DI
asm POP SI
asm POP DX
asm POP CX
asm POP BX
asm POP AX
asm POP DS
} /*mousintfunc*/
int moustrapinit(int event)
{
asm {
MOV AX,SEG mousintfunc
MOV ES,AX
MOV DX,OFFSET mousintfunc
MOV CX,event
MOV AX,0Ch
MOV BX,0
INT 033h
};
return 1;
} /*moustrapinit*/
int moustrap(int event,MOUSTRAP func)
{
mousfunc=func;
moustrapinit(event);
return 1;
} /*moustrap*/