summaryrefslogtreecommitdiff
path: root/fpcsrc/rtl/go32v2/msmouse.pp
blob: 287394e5fce75b8b53e9dca8f823e1a8a58dae93 (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 1999-2000 by the Free Pascal development team

    Mouse unit for microsoft mouse compatible drivers

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************
}
Unit MSMouse;
Interface

{$calling oldfpccall}

{
  Mouse support functions and procedures, with error checking: if mouse
  isn't present then the routine ends. If you want to remove error checking,
  remove the next define.
}


{initializes the mouse with the default values for the current screen mode}
  Function InitMouse:Boolean;

{shows mouse pointer,text+graphics screen support}
  Procedure ShowMouse;

{hides mouse pointer}
  Procedure HideMouse;

{reads mouse position in pixels (divide by 8 to get text position in standard
 text mode) and reads the buttons state:
    bit 1 set -> left button pressed
    bit 2 set -> right button pressed
    bit 3 set -> middle button pressed
 Have a look at the example program in the manual to see how you can use this}
  Procedure GetMouseState(var x,y, buttons :Longint);

{returns true if the left button is pressed}
  Function LPressed:Boolean;

{returns true if the right button is pressed}
  Function RPressed:Boolean;

{returns true if the middle button is pressed}
  Function MPressed:Boolean;

{positions the mouse pointer}
  Procedure SetMousePos(x,y:Longint);

{returns at which position "button" was last pressed in x,y and returns the
 number of times this button has been pressed since the last time this
 function was called with "button" as parameter. For button you can use the
 LButton, RButton and MButton constants for resp. the left, right and middle
 button}
  Function GetLastButtonPress(button:Longint;var x,y:Longint): Longint;

{returns at which position "button" was last released in x,y and returns the
 number of times this button has been re since the last time. For button
 you can use the LButton, RButton and MButton constants for resp. the left,
 right and middle button}
Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;

{sets mouse's x range, with Min and Max resp. the higest and the lowest
 column (in pixels) in between which the mouse cursor can move}
  Procedure SetMouseXRange (Min,Max:Longint);

{sets mouse's y range, with Min and Max resp. the higest and the lowest
 row (in pixels) in between which the mouse cursor can move}
  Procedure SetMouseYRange (Min,Max:Longint);

{set the window coordinates in which the mouse cursor can move}
  Procedure SetMouseWindow(x1,y1,x2,y2:Longint);

{sets the mouse shape in text mode: background and foreground color and the
 Ascii value with which the character on screen is XOR'ed when the cursor
 moves over it. Set to 0 for a "transparent" cursor}
  Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);

{sets the mouse ascii in text mode. The difference between this one and
 SetMouseShape, is that the foreground and background colors stay the same
 and that the Ascii code you enter is the character that you will get on
 screen; there's no XOR'ing}
  Procedure SetMouseAscii(Ascii:Byte);

{set mouse speed in mickey's/pixel; default: horizontal: 8; vertical: 16}
  Procedure SetMouseSpeed(Horizontal ,Vertical:Longint);

{set a rectangle on screen that mouse will disappear if it is moved into}
  Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);

Const LButton = 1; {left button}
      RButton = 2; {right button}
      MButton = 4; {middle button}

Var
  MouseFound: Boolean;

Implementation

{$asmmode ATT}

Function InitMouse: Boolean;
begin
  asm
        xorl    %eax,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
        cmpw    $0xffff,%ax
        setz    %al
        movb    %al,__RESULT
  end;
end;


Procedure ShowMouse;
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $1,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
end;

Procedure HideMouse;
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $2,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
end;

Procedure GetMouseState(var x,y,buttons:Longint);
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $3,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
        andl    $0xffff,%ecx
        andl    $0xffff,%edx
        movl    x,%eax
        movl    %ecx,(%eax)
        movl    y,%eax
        movl    %edx,(%eax)
        movl    buttons,%eax
        movw    %bx,(%eax)
  end;
end;

Function LPressed:Boolean;
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $3,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
        movl    %ebx,%eax
        andl    $1,%eax
        movb    %al,__RESULT
  end;
end;

Function RPressed:Boolean;
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $3,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
        movl    %ebx,%eax
        shrl    $1,%eax
        andl    $1,%eax
        movb    %al,__RESULT
  end;
end;

Function MPressed:Boolean;
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $3,%eax
        pushl   %ebp
        int     $0x33
        popl    %ebp
        movl    %ebx,%eax
        shrl    $2,%eax
        andl    $1,%eax
        movb    %al,__RESULT
  end;
end;

Procedure SetMousePos(x,y:Longint);
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $4,%eax
        movl    x,%ecx
        movl    y,%edx
        pushl   %ebp
        int     $0x33
        popl    %ebp
  End;
End;

Function GetLastButtonPress(Button: Longint;var x,y:Longint):Longint;
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $5,%eax
        movl    button,%ebx
        shrl    $1, %ebx        {0 = left, 1 = right, 2 = middle}
        pushl   %ebp
        int     $0x33
        popl    %ebp
        andl    $0xffff,%ebx
        andl    $0xffff,%edx
        andl    $0xffff,%ecx
        movl    %ebx, __RESULT
        movl    x,%eax
        movl    %ecx,(%eax)
        movl    y,%eax
        movl    %edx,(%eax)
  end;
end;

Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $6,%eax
        movl    button,%ebx
        shrl    $1, %ebx        {0 = left, 1 = right, 2 = middle}
        pushl   %ebp
        int     $0x33
        popl    %ebp
        andl    $0xffff,%ebx
        andl    $0xffff,%ecx
        andl    $0xffff,%edx
        movl    %ebx,__RESULT
        movl    x,%eax
        movl    %ecx,(%eax)
        movl    y,%eax
        movl    %edx,(%eax)
  end;
end;

Procedure SetMouseXRange (Min,Max:Longint);
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $7,%eax
        movl    min,%ecx
        movl    max,%edx
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
end;

Procedure SetMouseYRange (min,max:Longint);
begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $8,%eax
        movl    min,%ecx
        movl    max,%edx
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
end;

Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
Begin
  If (Not MouseFound) Then Exit;
  SetMouseXRange(x1,x2);
  SetMouseYRange(y1,y2);
End;

Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
Begin
  If (Not MouseFound) Then Exit;
  asm
        xorl    %ebx,%ebx
        movl    $0xa,%eax
        movl    $0xffff,%ecx
        xorl    %edx,%edx
        movb    BackColor,%dh
        shlb    $4,%dh
        addb    ForeColor,%dh
        movb    Ascii,%dl
        pushl   %ebp
        int     $0x33
        popl    %ebp
  End;
End;

Procedure SetMouseAscii(Ascii:byte);
Begin
  If (Not MouseFound) Then Exit;
  asm
        xorl    %ebx,%ebx
        movl    $0xa,%eax
        movl    $0xff00,%ecx
        xorl    %edx,%edx
        movb    Ascii,%dl
        pushl   %ebp
        int     $0x33
        popl    %ebp
  End;
End;

Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $0x0010,%eax
        movl    x1,%ecx
        movl    y1,%edx
        movl    x2,%esi
        movl    y2,%edi
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
End;

Procedure SetMouseSpeed(Horizontal,Vertical:Longint);
Begin
  If (Not MouseFound) Then Exit;
  asm
        movl    $0x0f,%eax
        movl    Horizontal,%ecx
        movl    Vertical,%edx
        pushl   %ebp
        int     $0x33
        popl    %ebp
  end;
End;

Begin
  MouseFound := InitMouse;
End.