Category : C Source Code
Archive   : MOUSE_TC.ZIP
Filename : MOUSE.C

 
Output of file : MOUSE.C contained in archive : MOUSE_TC.ZIP
/* Mouse.c
*/

#pragma inline

#include
#include "mouse.h"
#include

#define INTMOUSE asm INT 33h

card32 mouIntCt = 0;

/* check mark image */
mouGCursorDef mouCheckIm =
{
6, 7,
{
0xFFF0, 0xFFE0, 0xFFC0, 0xFF81, /* screen mask */
0xFF03, 0x0607, 0x000F, 0x001F,
0xC03F, 0xF07F, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
},
{
0x0000, 0x0006, 0x000C, 0x0018, /* cursor mask */
0x0030, 0x0060, 0x70C0, 0x1D80,
0x0700, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
},
};


/* Left arrow image */
mouGCursorDef mouArrowIm =
{
0, 0,
{
0x7FFF, 0x1FFF, 0x07FF, 0x01FF, /* screen mask */
0x007F, 0x03FF, 0x01FF, 0xB0FF,
0xF87F, 0xFC7F, 0xFEFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
},
{
0x0000, 0x4000, 0x7000, 0x7C00, /* cursor mask */
0x7F00, 0x7800, 0x4C00, 0x0600,
0x0300, 0x0100, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
},
};

/* Cross image */
mouGCursorDef mouCrossIm =
{
7, 4,
{
0xFC3F, 0xFC3F, 0xFC3F, 0x0000, /* screen mask */
0x0000, 0x0000, 0xFC3F, 0xFC3F,
0xFC3F, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
},
{
0x0000, 0x0180, 0x0180, 0x0180, /* cursor mask */
0x7FFE, 0x0180, 0x0180, 0x0180,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000 ,
},
};

/* Pointing hand image */
mouGCursorDef mouHandIm =
{
5, 0,
{
0xE1FF, 0xE1FF, 0xE1FF, 0xE1FF, /* screen mask */
0xE1FF, 0xE000, 0xE000, 0xE000,
0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000,
},
{
0x1E00, 0x1200, 0x1200, 0x1200, /* cursor mask */
0x1200, 0x13FF, 0x1249, 0x1249,
0x1249, 0x9001, 0x9001, 0x9001,
0x8001, 0x8001, 0x8001, 0xFFFF,
},
};

mouGCursorDef mouIBeamIm =
{
7, 7,
{
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* screen mask */
0XFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
},
{
0xF00F, 0x0C30, 0x0240, 0x0240, /* cursor mask */
0x0180, 0x0180, 0x0180, 0x0180,
0x0180, 0x0180, 0x0180, 0x0180,
0x0240, 0x0240, 0x0C30, 0xF00F,
},
};

/* Stop-sign image */
mouGCursorDef mouStopIm =
{
7, 7,
{
0xF81F, 0xF00F, 0xE007, 0xC003, /* screen mask */
0x8001, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x8001,
0xC003, 0xE007, 0xF00F, 0xF81F,
},
{
0x0000, 0x07E0, 0x0810, 0x1188, /* cursor mask */
0x2184, 0x4182, 0x4182, 0x4182,
0x4182, 0x4002, 0x4002, 0x2184,
0x1188, 0x0810, 0x07E0, 0x0000 ,
},
};

/*
Static mouse event record buffer
*/
#define MAXEVENT 63 /* typically 1 second look-ahead */

static card8 bufferLevel = 0;
static boolean frozen = false;

static mouEvent theEvents [MAXEVENT+1] = {{0,},};
static mouEvent near *nextEvent = theEvents+MAXEVENT;
static mouEvent near *prevEvent = theEvents+MAXEVENT;
static mouGCursorDef *currentIm = &mouArrowIm;


static void pascal GraphCursor (const mouGCursorDef far *curP)
/*
Sets graphic cursor shape
*/
{
I LES bx, curP
I lea dx, [bx].(mouGCursorDef) mask
I mov cl, ES:[bx].(mouGCursorDef) vHot
I mov ch, 0
I mov bl, ES:[bx].(mouGCursorDef) hHot
I mov bh, 0
_AX = 9; /* function 9 */
INTMOUSE
}


void far mouHandler (void)
{
I push DS
I push ax
I mov ax, DGROUP
I mov DS, ax
I pop ax
I or ax, ax
I jz exit
I mov si, nextEvent
I cmp WRD ([si].(mouEvent) flag), 0
I jnz skip /* event buffer overflow */
I mov [si].(mouEvent) row, dx
I mov [si].(mouEvent) col, cx
I mov [si].(mouEvent) button, bx
/*
.flag field must be the last field updated because when it
becomes non-zero it is the signal that the record may be read.
*/
I mov [si].(mouEvent) flag, ax

if (FP_OFF (nextEvent) == FP_OFF (theEvents))
nextEvent += MAXEVENT;
else
nextEvent --;

/*
In order to avoid overflow we give the user some visual feedback.
When the buffer becomes more than half full we put a stop sign
cursor shape on the screen, and leave it there until the buffer
level subsides below 1/4 full. We still record events when the
stop sign is set.

if the user ignores the stop sign eventually the buffer fills
and events are just ignored.
*/
bufferLevel ++;
if (! frozen && bufferLevel > (MAXEVENT/2))
{
frozen = true;
GraphCursor (&mouStopIm);
}
else if (bufferLevel < (MAXEVENT/4))
{
GraphCursor (currentIm);
frozen = false;
}

skip:
/*
We arrive at skip if the buffer of mouEvents is full, which can
happen when the mouse events arrive faster than the application
can process them. Presently we just discard such events.
*/

exit:
mouIntCt ++;
I pop DS
return;

}


bits16 ENTRY mouNextEvent(mouEvent far*eventP)
/*
The caller is returned the flags for the most recent
mouse event. If the flags are all zero, then nothing
has happened. If any flag is set then the mouse event
record is copied into the caller's mouEvent.
*/
{
bits16 flags;

I cli
if ((flags = prevEvent->flag) != 0)
{
*eventP = *prevEvent;
prevEvent->flag = 0;
I sti
if (FP_OFF (prevEvent) == FP_OFF (theEvents))
prevEvent += MAXEVENT;
else
prevEvent --;
bufferLevel--;
}
else
{
I sti
}
return flags;
}

/* --------------------------------------------------------------- */
/* Following are implementations of the Microsoft mouse functions */

card8 ENTRYND mouReset (void)
/*
Resets mouse to default state. Returns count of mouse buttons,
zero if no mouse.
Always call this function during program initialization.
*/
{
_AX = 0;
INTMOUSE
return _AL;
}

void ENTRYND mouShow (void)
/*
Makes the mouse cursor visible. Don't call if cursor is already
visible, and alternate with calls to mHide.
*/
{
_AX = 1;
INTMOUSE
}

void ENTRYND mouHide (void)
/*
Makes mouse cursor invisible. Movement and button activity are
still tracked. Do not call if cursor is already hidden, and
alternate with calls to mShow
*/
{
_AX = 2;
INTMOUSE
}

void ENTRYND mouPos (mouLocRec far*mP)
/*
Gets mouse cursor position and button status, returns pointer
to structure containing this info
*/
{
_AX = 3;
INTMOUSE
mP->buttonStatus = _BL;
mP->column = _CX;
mP->row = _DX;
return;
}

void ENTRYND mouMoveto (int16 newCol, int16 newRow)
/*
Move mouse cursor to new position
*/
{
_AX = 4; /* function 4 */
_CX = newCol;
_DX = newRow;
INTMOUSE
}

void ENTRYND mouButtonInfo
(
ord16 button,
ord16 function,
mouLocRec far *mP
)
/*
Gets press/release info about named button: current status (up/down),
times pressed since last call, position at most recent press.
Resets count and position info. Button 0 is left, 1 is right on
Microsoft mouse.
*/
{
_AX = function;
_BX = button; /* request for specific button */
INTMOUSE
mP->buttonStatus = _AX;
mP->opCount = _BX;
mP->column = _CX;
mP->row = _DX;
return;
}

void ENTRYND mouColRange (int16 hmin, int16 hmax)
/*
Sets min and max horizontal range for mouse cursor. Moves
cursor inside range if outside when called. Swaps values if
hmin and hmax are reversed.
*/
{
_AX = 7; /* function 7 */
_CX = hmin;
_DX = hmax;
INTMOUSE
}

void ENTRYND mouRowRange (int16 vmin, int16 vmax)
/*
Same as mHminmax, except sets vertical boundaries.
*/
{
_AX = 8; /* function 8 */
_CX = vmin;
_DX = vmax;
INTMOUSE
}

void ENTRY mouGraphCursor (const mouGCursorDef far *curP)
/*
Sets graphic cursor shape
*/
{
currentIm = curP; /* remember cursor */
if (! frozen) GraphCursor (curP);
}

void ENTRYND mouTextCursor (ord16 curstype, bits16 arg1, bits16 arg2)
/*
Sets text cursor type, where 0 = software and 1 = hardware)
For software cursor, arg1 and arg2 are the screen and cursor
masks.
For hardware cursor, arg1 and arg2 specify scan line start/stop
i.e. cursor shape.
*/
{
_AX = 10; /* function 10 */
_BX = curstype;
_CX = arg1;
_DX = arg2;
INTMOUSE
}

void ENTRYND mouMotion (mouMoveRec far *mP)
/*
Reports net motion of cursor since last call to this function
*/
{
_AX = 11; /* function 11 */
INTMOUSE
mP->hCount = _CX; /* net horizontal */
mP->vCount = _DX; /* net vertical */
return;
}

void ENTRYND mouInstTask (bits16 mask, void far *TaskP)
/*
Installs a user-defined task to be executed upon one or more
mouse events specified by mask.
*/
{
_AX = 12; /* function 12 */
_CX = mask;
I LES DX, TaskP
INTMOUSE
}

void ENTRYND mouLpenOn (void)
/*
Turns on light pen emulation. This is the default condition.
*/
{
_AX = 13; /* function 13 */
INTMOUSE
}

void ENTRYND mouLpenOff (void)
/*
Turns off light pen emulation.
*/
{
_AX = 14; /* function 14 */
INTMOUSE
}

void ENTRYND mouRatio (int16 horiz, int16 vert)
/*
Sets mickey-to-pixel ratio, where ratio is R/8. Default is 16
for vertical, 8 for horizontal
*/
{
_AX = 15; /* function 15 */
_CX = horiz;
_DX = vert;
INTMOUSE
}


void ENTRYND mouCondHide (ord16 left, ord16 upper, ord16 right, ord16 lower)
/*
Excludes the cursor from a region being updated.

This appears not to work as reliably as mHide and makes no
visible difference to speed. When the cursor passes over
the active drawing gaps appear (at least with the MS Mouse).
mHide () is recommended instead.
*/
{
_CX = left;
_DX = upper;
_SI = right;
_DI = lower;
_AX = 16;
INTMOUSE
}


  3 Responses to “Category : C Source Code
Archive   : MOUSE_TC.ZIP
Filename : MOUSE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/