Mouse Routines for Turbo C
Bill Wilson
wew at naucse.UUCP
Wed Dec 7 02:14:44 AEST 1988
Because of the overwhelming requests for this code I have decided
to put it on the net instead of emailing everyone (which could fill
a day with work). I have not typed in the code for Pascal. I have
tried all of the C code and it does work. I would like someone
who has time to get the Event code to work in the large memory
model. If "you" do, please post it. Following are three files
that need to be cut out:
/* Mousdemo.c - Example from Turbo Technix May/June 88 */
#include <stdio.h>
#include <dos.h>
#include <mouse.inc>
#define HARDWARE 1
#define SOFTWARE 0
#define LEFT 0
#define RITE 1
#define ROMBIOS int86 (0x10, &inreg, &outreg)
void clrScr (void);
void gotoxy (int col, int row);
main()
{
resetRec *theMouse;
locRec *its;
int col,row;
char input[80];
clrScr();
theMouse=mReset();
if (theMouse->exists) {
puts("Software cursor:");
printf("Demo of a mouse with %d buttons\n",theMouse->nButtons);
puts("move the mouse around and click the left button");
puts("click the right button for hardware demo\n");
mTextCursor(SOFTWARE, 0x000, 0x0718);
mShow();
do {
its=mReleased(LEFT);
if(its->opCount>0){
mHide();
printf("\nMouse is a col %d, row %d", its->column, its->row);
mShow();
}
its=mReleased(RITE);
} while (its->opCount==0);
clrScr();
puts("Hardware cursor:");
puts("Move the mouse, click left button");
puts("Type something and press Enter");
puts("Click right button to end demo");
theMouse=mReset();
mTextCursor(HARDWARE,2,5);
mShow();
do {
its=mReleased(LEFT);
if(its->opCount>0) {
col=its->column/8;
row=its->row/8;
gotoxy(col,row);
putchar('?');
gets(input);
mMoveto(its->column,its->row);
}
its=mReleased(RITE);
} while (its->opCount==0);
mTextCursor(HARDWARE,6,7);
mReset();
clrScr();
} else
puts("Mouse not present in system. Demo cannot run.");
}
void clrScr(void)
{
struct REGS inreg, outreg;
inreg.h.ah=0x0f;
ROMBIOS;
inreg.h.al=outreg.h.al;
inreg.h.ah=0;
ROMBIOS;
}
void gotoxy(int col, int row)
{
struct REGS inreg, outreg;
inreg.h.ah=2;
inreg.h.bh=0;
inreg.h.dh=row;
inreg.h.dl=col;
ROMBIOS;
}
*** CUT HERE ***
/* Mousenvt.c - Example from Turbo Technix May/June 88. */
/* compile in tiny, small or compact model */
#include <stdio.h>
#include <dos.h>
#include <mouse.inc>
#define ROMBIOS int86(0x10, &inreg, &outreg)
typedef struct {
unsigned event, btnStatus, horiz, vert;
} mEvent;
void clrScr(void);
void gotoxy(int, int);
void far handler (void)
{
mEvent far *save;
unsigned a,b,c,d;
a=_AX; b=_BX; c=_CX; d=_DX;
save=MK_FP(_CS - 0x10, 0x00c0);
save->event=a;
save->btnStatus=b;
save->horiz=c;
save->vert=d;
}
main()
{
mEvent far *mous;
resetRec *m;
clrScr();
gotoxy(17,24);
printf("Press left button for position, right to quit");
gotoxy(27,0);
puts("MOUSE EVENT-HANDLING DEMO");
printf("PSP=%p CS=%p",_psp,_CS);
m=mReset();
if (m->exists) {
mInstTask(0x14, FP_SEG (handler), FP_OFF(handler));
mous=MK_FP(_psp,0x00c0);
mous->event=0;
mShow();
do {
gotoxy(40,20);
printf("mous->event=%d",mous->event);
if (mous->event==4){
mHide();
printf("\nX=%3d, Y=%3d",mous->horiz,mous->vert);
mShow();
mous->event=0;
}
} while (mous->event !=0x10);
mHide();
mReset();
}
clrScr();
}
void clrScr(void)
{
struct REGS inreg, outreg;
inreg.h.ah=0x0f;
ROMBIOS;
inreg.h.al=outreg.h.al;
inreg.h.ah=0;
ROMBIOS;
}
void gotoxy(int col, int row)
{
struct REGS inreg, outreg;
inreg.h.ah=2;
inreg.h.bh=0;
inreg.h.dh=row;
inreg.h.dl=col;
ROMBIOS;
}
*** CUT HERE ***
/* Mouse.inc from Turbo Technix, May/June 88 */
#define callMDD int86(0x33,&inreg, &outreg)
#define lower(x,y) (x<y) ? x : y
#define upper(x,y) (x>y) ? x : y
union REGS inreg, outreg;
typedef struct {
int exists, nButtons;
} resetRec;
typedef struct {
int buttonStatus, opCount, column, row;
} locRec;
typedef struct {
int hCount, vCount;
} moveRec;
resetRec *mReset()
{
static resetRec m;
inreg.x.ax=0;
callMDD;
m.exists=outreg.x.ax;
m.nButtons=outreg.x.bx;
return (&m);
}
void mShow (void)
{
inreg.x.ax=1;
callMDD;
}
void mHide (void)
{
inreg.x.ax=2;
callMDD;
}
locRec *mPos (void)
{
static locRec m;
inreg.x.ax=3;
callMDD;
m.buttonStatus=outreg.x.bx;
m.column=outreg.x.cx;
m.row=outreg.x.dx;
return(&m);
}
void mMoveto(int newcol, int newrow)
{
inreg.x.ax=4;
inreg.x.cx=newcol;
inreg.x.dx=newrow;
callMDD;
}
locRec *mPressed(int button)
{
static locRec m;
inreg.x.ax=5;
inreg.x.bx=button;
callMDD;
m.buttonStatus=outreg.x.ax;
m.opCount=outreg.x.bx;
m.column=outreg.x.cx;
m.row=outreg.x.dx;
return(&m);
}
locRec *mReleased(int button)
{
static locRec m;
inreg.x.ax=6;
inreg.x.bx=button;
callMDD;
m.buttonStatus=outreg.x.ax;
m.opCount=outreg.x.bx;
m.column=outreg.x.cx;
m.row=outreg.x.dx;
return(&m);
}
void mColRange(int hmin, int hmax)
{
inreg.x.ax=7;
inreg.x.cx=hmin;
inreg.x.dx=hmax;
callMDD;
}
void mRowRange(int vmin, int vmax)
{
inreg.x.ax=8;
inreg.x.cx=vmin;
inreg.x.dx=vmax;
callMDD;
}
void mGraphCursor(int hHot, int vHot, unsigned maskSeg, unsigned maskOfs)
{
struct SREGS seg;
inreg.x.ax=9;
inreg.x.bx=hHot;
inreg.x.cx=vHot;
inreg.x.dx=maskOfs;
seg.es=maskSeg;
int86x(0x33,&inreg,&outreg,&seg);
}
void mTextCursor(int curstype, unsigned arg1, unsigned arg2)
{
inreg.x.ax=10;
inreg.x.bx=curstype;
inreg.x.cx=arg1;
inreg.x.dx=arg2;
callMDD;
}
moveRec *mMotion (void)
{
static moveRec m;
inreg.x.ax=11;
callMDD;
m.hCount=_CX;
m.vCount=_DX;
return(&m);
}
void mInstTask(unsigned mask, unsigned taskSeg, unsigned taskOfs)
{
struct SREGS seg;
inreg.x.ax=12;
inreg.x.cx=mask;
inreg.x.dx=taskOfs;
seg.es=taskSeg;
int86x(0x33,&inreg,&outreg,&seg);
}
void mLpenOn (void)
{
inreg.x.ax=13;
callMDD;
}
void mLpenOff(void)
{
inreg.x.ax=14;
callMDD;
}
void mRatio(int horiz, int vert)
{
inreg.x.ax=15;
inreg.x.cx=horiz;
inreg.x.dx=vert;
callMDD;
}
--
Bill Wilson (Bitnet: ucc2wew at nauvm)
Northern AZ Univ
Flagstaff, AZ 86011
{These views are mine and do not necessarily reflect those of my employer}
More information about the Comp.lang.c
mailing list