msmouse.pp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Mouse unit for microsoft mouse compatible drivers
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************
  12. }
  13. Unit MSMouse;
  14. Interface
  15. {
  16. Mouse support functions and procedures, with error checking: if mouse
  17. isn't present then the routine ends. If you want to remove error checking,
  18. remove the next define.
  19. }
  20. {$DEFINE MOUSECHECK}
  21. {initializes the mouse with the default values for the current screen mode}
  22. Function InitMouse:Boolean;
  23. {shows mouse pointer,text+graphics screen support}
  24. Procedure ShowMouse;
  25. {hides mouse pointer}
  26. Procedure HideMouse;
  27. {reads mouse position in pixels (divide by 8 to get text position in standard
  28. text mode) and reads the buttons state:
  29. bit 1 set -> left button pressed
  30. bit 2 set -> right button pressed
  31. bit 3 set -> middle button pressed
  32. Have a look at the example program in the manual to see how you can use this}
  33. Procedure GetMouseState(var x,y, buttons :Longint);
  34. {returns true if the left button is pressed}
  35. Function LPressed:Boolean;
  36. {returns true if the right button is pressed}
  37. Function RPressed:Boolean;
  38. {returns true if the middle button is pressed}
  39. Function MPressed:Boolean;
  40. {positions the mouse pointer}
  41. Procedure SetMousePos(x,y:Longint);
  42. {returns at which position "button" was last pressed in x,y and returns the
  43. number of times this button has been pressed since the last time this
  44. function was called with "button" as parameter. For button you can use the
  45. LButton, RButton and MButton constants for resp. the left, right and middle
  46. button}
  47. Function GetLastButtonPress(button:Longint;var x,y:Longint): Longint;
  48. {returns at which position "button" was last released in x,y and returns the
  49. number of times this button has been re since the last time. For button
  50. you can use the LButton, RButton and MButton constants for resp. the left,
  51. right and middle button}
  52. Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
  53. {sets mouse's x range, with Min and Max resp. the higest and the lowest
  54. column (in pixels) in between which the mouse cursor can move}
  55. Procedure SetMouseXRange (Min,Max:Longint);
  56. {sets mouse's y range, with Min and Max resp. the higest and the lowest
  57. row (in pixels) in between which the mouse cursor can move}
  58. Procedure SetMouseYRange (Min,Max:Longint);
  59. {set the window coordinates in which the mouse cursor can move}
  60. Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
  61. {sets the mouse shape in text mode: background and foreground color and the
  62. Ascii value with which the character on screen is XOR'ed when the cursor
  63. moves over it. Set to 0 for a "transparent" cursor}
  64. Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
  65. {sets the mouse ascii in text mode. The difference between this one and
  66. SetMouseShape, is that the foreground and background colors stay the same
  67. and that the Ascii code you enter is the character that you will get on
  68. screen; there's no XOR'ing}
  69. Procedure SetMouseAscii(Ascii:Byte);
  70. {set mouse speed in mickey's/pixel; default: horizontal: 8; vertical: 16}
  71. Procedure SetMouseSpeed(Horizontal ,Vertical:Longint);
  72. {set a rectangle on screen that mouse will disappear if it is moved into}
  73. Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
  74. Const LButton = 1; {left button}
  75. RButton = 2; {right button}
  76. MButton = 4; {middle button}
  77. Var
  78. MouseFound: Boolean;
  79. Implementation
  80. {$asmmode ATT}
  81. Function InitMouse: Boolean;
  82. begin
  83. asm
  84. xorl %eax,%eax
  85. pushl %ebp
  86. int $0x33
  87. popl %ebp
  88. cmpw $0xffff,%ax
  89. setz %al
  90. movb %al,__RESULT
  91. end;
  92. end;
  93. Procedure ShowMouse;
  94. begin
  95. {$IFDEF MOUSECHECK}
  96. If (Not MouseFound) Then Exit;
  97. {$ENDIF}
  98. asm
  99. movl $1,%eax
  100. pushl %ebp
  101. int $0x33
  102. popl %ebp
  103. end;
  104. end;
  105. Procedure HideMouse;
  106. begin
  107. {$IFDEF MOUSECHECK}
  108. If (Not MouseFound) Then Exit;
  109. {$ENDIF}
  110. asm
  111. movl $2,%eax
  112. pushl %ebp
  113. int $0x33
  114. popl %ebp
  115. end;
  116. end;
  117. Procedure GetMouseState(var x,y,buttons:Longint);
  118. begin
  119. {$IFDEF MOUSECHECK}
  120. If (Not MouseFound) Then Exit;
  121. {$ENDIF}
  122. asm
  123. movl $3,%eax
  124. pushl %ebp
  125. int $0x33
  126. popl %ebp
  127. andl $0xffff,%ecx
  128. andl $0xffff,%edx
  129. movl x,%eax
  130. movl %ecx,(%eax)
  131. movl y,%eax
  132. movl %edx,(%eax)
  133. movl buttons,%eax
  134. movw %bx,(%eax)
  135. end;
  136. end;
  137. Function LPressed:Boolean;
  138. Begin
  139. {$IFDEF MOUSECHECK}
  140. If (Not MouseFound) Then Exit;
  141. {$ENDIF}
  142. asm
  143. movl $3,%eax
  144. pushl %ebp
  145. int $0x33
  146. popl %ebp
  147. movl %ebx,%eax
  148. andl $1,%eax
  149. movb %al,__RESULT
  150. end;
  151. end;
  152. Function RPressed:Boolean;
  153. Begin
  154. {$IFDEF MOUSECHECK}
  155. If (Not MouseFound) Then Exit;
  156. {$ENDIF}
  157. asm
  158. movl $3,%eax
  159. pushl %ebp
  160. int $0x33
  161. popl %ebp
  162. movl %ebx,%eax
  163. shrl $1,%eax
  164. andl $1,%eax
  165. movb %al,__RESULT
  166. end;
  167. end;
  168. Function MPressed:Boolean;
  169. Begin
  170. {$IFDEF MOUSECHECK}
  171. If (Not MouseFound) Then Exit;
  172. {$ENDIF}
  173. asm
  174. movl $3,%eax
  175. pushl %ebp
  176. int $0x33
  177. popl %ebp
  178. movl %ebx,%eax
  179. shrl $2,%eax
  180. andl $1,%eax
  181. movb %al,__RESULT
  182. end;
  183. end;
  184. Procedure SetMousePos(x,y:Longint);
  185. Begin
  186. {$IFDEF MOUSECHECK}
  187. If (Not MouseFound) Then Exit;
  188. {$ENDIF}
  189. asm
  190. movl $4,%eax
  191. movl x,%ecx
  192. movl y,%edx
  193. pushl %ebp
  194. int $0x33
  195. popl %ebp
  196. End;
  197. End;
  198. Function GetLastButtonPress(Button: Longint;var x,y:Longint):Longint;
  199. Begin
  200. {$IFDEF MOUSECHECK}
  201. If (Not MouseFound) Then Exit;
  202. {$ENDIF}
  203. asm
  204. movl $5,%eax
  205. movl button,%ebx
  206. shrl $1, %ebx {0 = left, 1 = right, 2 = middle}
  207. pushl %ebp
  208. int $0x33
  209. popl %ebp
  210. andl $0xffff,%ebx
  211. andl $0xffff,%edx
  212. andl $0xffff,%ecx
  213. movl %ebx, __RESULT
  214. movl x,%eax
  215. movl %ecx,(%eax)
  216. movl y,%eax
  217. movl %edx,(%eax)
  218. end;
  219. end;
  220. Function GetLastButtonRelease (button : Longint; var x,y:Longint): Longint;
  221. begin
  222. {$IFDEF MOUSECHECK}
  223. If (Not MouseFound) Then Exit;
  224. {$ENDIF}
  225. asm
  226. movl $6,%eax
  227. movl button,%ebx
  228. shrl $1, %ebx {0 = left, 1 = right, 2 = middle}
  229. pushl %ebp
  230. int $0x33
  231. popl %ebp
  232. andl $0xffff,%ebx
  233. andl $0xffff,%ecx
  234. andl $0xffff,%edx
  235. movl %ebx,__RESULT
  236. movl x,%eax
  237. movl %ecx,(%eax)
  238. movl y,%eax
  239. movl %edx,(%eax)
  240. end;
  241. end;
  242. Procedure SetMouseXRange (Min,Max:Longint);
  243. begin
  244. {$IFDEF MOUSECHECK}
  245. If (Not MouseFound) Then Exit;
  246. {$ENDIF}
  247. asm
  248. movl $7,%eax
  249. movl min,%ecx
  250. movl max,%edx
  251. pushl %ebp
  252. int $0x33
  253. popl %ebp
  254. end;
  255. end;
  256. Procedure SetMouseYRange (min,max:Longint);
  257. begin
  258. {$IFDEF MOUSECHECK}
  259. If (Not MouseFound) Then Exit;
  260. {$ENDIF}
  261. asm
  262. movl $8,%eax
  263. movl min,%ecx
  264. movl max,%edx
  265. pushl %ebp
  266. int $0x33
  267. popl %ebp
  268. end;
  269. end;
  270. Procedure SetMouseWindow(x1,y1,x2,y2:Longint);
  271. Begin
  272. {$IFDEF MOUSECHECK}
  273. If (Not MouseFound) Then Exit;
  274. {$ENDIF}
  275. SetMouseXRange(x1,x2);
  276. SetMouseYRange(y1,y2);
  277. End;
  278. Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
  279. Begin
  280. {$IFDEF MOUSECHECK}
  281. If (Not MouseFound) Then Exit;
  282. {$ENDIF}
  283. asm
  284. xorl %ebx,%ebx
  285. movl $0xa,%eax
  286. movl $0xffff,%ecx
  287. xorl %edx,%edx
  288. movb BackColor,%dh
  289. shlb $4,%dh
  290. addb ForeColor,%dh
  291. movb Ascii,%dl
  292. pushl %ebp
  293. int $0x33
  294. popl %ebp
  295. End;
  296. End;
  297. Procedure SetMouseAscii(Ascii:byte);
  298. Begin
  299. {$IFDEF MOUSECHECK}
  300. If (Not MouseFound) Then Exit;
  301. {$ENDIF}
  302. asm
  303. xorl %ebx,%ebx
  304. movl $0xa,%eax
  305. movl $0xff00,%ecx
  306. xorl %edx,%edx
  307. movb Ascii,%dl
  308. pushl %ebp
  309. int $0x33
  310. popl %ebp
  311. End;
  312. End;
  313. Procedure SetMouseHideWindow(x1,y1,x2,y2:Longint);
  314. Begin
  315. {$IFDEF MOUSECHECK}
  316. If (Not MouseFound) Then Exit;
  317. {$ENDIF}
  318. asm
  319. movl $0x0010,%eax
  320. movl x1,%ecx
  321. movl y1,%edx
  322. movl x2,%esi
  323. movl y2,%edi
  324. pushl %ebp
  325. int $0x33
  326. popl %ebp
  327. end;
  328. End;
  329. Procedure SetMouseSpeed(Horizontal,Vertical:Longint);
  330. Begin
  331. {$IFDEF MOUSECHECK}
  332. If (Not MouseFound) Then Exit;
  333. {$ENDIF}
  334. asm
  335. movl $0x0f,%eax
  336. movl Horizontal,%ecx
  337. movl Vertical,%edx
  338. pushl %ebp
  339. int $0x33
  340. popl %ebp
  341. end;
  342. End;
  343. Begin
  344. MouseFound := InitMouse;
  345. End.
  346. {
  347. $Log$
  348. Revision 1.4 2000-02-09 16:59:29 peter
  349. * truncated log
  350. Revision 1.3 2000/01/07 16:41:32 daniel
  351. * copyright 2000
  352. Revision 1.2 2000/01/07 16:32:23 daniel
  353. * copyright 2000 added
  354. }