msmouse.pp 9.2 KB

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