-
Notifications
You must be signed in to change notification settings - Fork 1
/
MOUSE.CPP
152 lines (135 loc) · 4.73 KB
/
MOUSE.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Module for working with the mouse
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include "graphpro.h"
#define C 101
static struct REGPACK registers; //ax, bx, cx, dx, bp, si, di, ds, es, flags
//static union REGS commonregs; //ax(al, ah), bx(bl, bh), cx(cl, ch), dx(dl, dh)
extern char msg[81];
static int cursorx, cursory;
void IsMouse(void) // checking for Mouse driver
{
registers.r_ax = 0x00;
intr(0x33, ®isters);
if (registers.r_ax == 0x0000)
{
printf("\n\a Mouse driver not loaded. Exiting...");
exit(1);
}
}
void GetMouseButtons(char* LeftYN, char* RightYN, int* mousex, int* mousey)
{
registers.r_ax = 0x03;
intr(0x33, ®isters);
if ( (registers.r_bx & 1) == 1)
*LeftYN = 1;
else
*LeftYN = 0;
if ( (registers.r_bx & 2) == 2)
*RightYN = 1;
else
*RightYN = 0;
*mousex = registers.r_cx;
*mousey = registers.r_dx;
} // End of function GetMouseButtons
void HideMouse(void)
{ // hiding the mouse pointer by drawing again with XOR_PUT mode ...
setwritemode(XOR_PUT);
BLine(cursorx, cursory - 2, cursorx, cursory - 10, C);
BLine(cursorx, cursory + 2, cursorx, cursory + 10, C);
BLine(cursorx - 2, cursory, cursorx - 10, cursory, C);
BLine(cursorx + 2, cursory, cursorx + 10, cursory, C);
// disabling the mouse event handler ...
registers.r_ax = 0x0c;
registers.r_cx = 0x00;
registers.r_es = FP_SEG(mouse_event_handler);
registers.r_dx = FP_OFF(mouse_event_handler);
intr(0x33, ®isters);
}
void ShowMouse(void)
{
char fikt1, fikt2;
int mousex, mousey;
GetMouseButtons(&fikt1, &fikt2, &mousex, &mousey);
cursorx = mousex;
cursory = mousey;
// and now draw to the new cursor place ...
setwritemode(XOR_PUT);
BLine(cursorx, cursory - 2, cursorx, cursory - 10, C);
BLine(cursorx, cursory + 2, cursorx, cursory + 10, C);
BLine(cursorx - 2, cursory, cursorx - 10, cursory, C);
BLine(cursorx + 2, cursory, cursorx + 10, cursory, C);
// istalling again the mouse event handler ...
registers.r_ax = 0x0c;
registers.r_cx = 0x01;
registers.r_es = FP_SEG(mouse_event_handler);
registers.r_dx = FP_OFF(mouse_event_handler);
intr(0x33, ®isters);
}
void InitMouse(int& mouse_maxX, int& mouse_maxY)
// functions to initialize the mouse pointer
{//reseting the mouse ...
registers.r_ax = 0x00;
intr(0x33, ®isters);
// determining the minX maxX coordinates of the mouse ...
registers.r_ax = 0x07;
registers.r_cx = 0x00; // min X coordinate
registers.r_dx = mouse_maxX; // max X coordinate
intr(0x33, ®isters);
// determining the minY maxY coordinates of the mouse ...
registers.r_ax = 0x08;
registers.r_cx = 0x00; // min Y coordinate
registers.r_dx = mouse_maxY; // max Y coordinate
intr(0x33, ®isters);
// set the start coordinates ...
registers.r_ax = 0x04;
registers.r_cx = cursorx = mouse_maxX/2;
registers.r_dx = cursory = mouse_maxY/2;
intr(0x33, ®isters);
// drawing the first cursor ...
setwritemode(XOR_PUT);
BLine(cursorx, cursory - 2, cursorx, cursory - 10, C);
BLine(cursorx, cursory + 2, cursorx, cursory + 10, C);
BLine(cursorx - 2, cursory, cursorx - 10, cursory, C);
BLine(cursorx + 2, cursory, cursorx + 10, cursory, C);
// installing event handler ...
registers.r_ax = 0x0c;
registers.r_cx = 0x01;
registers.r_es = FP_SEG(mouse_event_handler);
registers.r_dx = FP_OFF(mouse_event_handler);
intr(0x33, ®isters);
}
void SetMouseBound(int mouse_minX, int mouse_minY, int mouse_maxX, int mouse_maxY)
{ // this function sets the current mouse boundaries
// determining the minX maxX coordinates of the mouse ...
registers.r_ax = 0x07;
registers.r_cx = mouse_minX; // min X coordinate
registers.r_dx = mouse_maxX; // max X coordinate
intr(0x33, ®isters);
// determining the minY maxY coordinates of the mouse ...
registers.r_ax = 0x08;
registers.r_cx = mouse_minY; // min Y coordinate
registers.r_dx = mouse_maxY; // max Y coordinate
intr(0x33, ®isters);
}
void mouse_event_handler(void) // used only to draw the mouse cursor
{
//in these registers are the coordinates of the Mouse pointer
register int mousex = _CX, mousey = _DX;
setwritemode(XOR_PUT);
//first we draw in the old cursor place
BLine(cursorx, cursory - 2, cursorx, cursory - 10, C);
BLine(cursorx, cursory + 2, cursorx, cursory + 10, C);
BLine(cursorx - 2, cursory, cursorx - 10, cursory, C);
BLine(cursorx + 2, cursory, cursorx + 10, cursory, C);
cursorx = mousex;
cursory = mousey;
//and now to the new cursor place
BLine(cursorx, cursory - 2, cursorx, cursory - 10, C);
BLine(cursorx, cursory + 2, cursorx, cursory + 10, C);
BLine(cursorx - 2, cursory, cursorx - 10, cursory, C);
BLine(cursorx + 2, cursory, cursorx + 10, cursory, C);
draw_uvxy();
}