msmouse.pp 8.7 KB

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