msmouse.pp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. {
  17. Mouse support functions and procedures, with error checking: if mouse
  18. isn't present then the routine ends. If you want to remove error checking,
  19. remove the next define.
  20. }
  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. Function InitMouse: Boolean;
  81. begin
  82. if MemL[0:$33*4] = 0 then
  83. exit(False);
  84. asm
  85. xor ax,ax
  86. push bp
  87. int $33
  88. pop bp
  89. cmp ax, $FFFF
  90. mov al, 0
  91. jne @@1
  92. inc al
  93. @@1:
  94. mov @Result, al
  95. end;
  96. end;
  97. Procedure ShowMouse;
  98. begin
  99. If (Not MouseFound) Then Exit;
  100. asm
  101. mov ax, 1
  102. push bp
  103. int $33
  104. pop bp
  105. end;
  106. end;
  107. Procedure HideMouse;
  108. begin
  109. If (Not MouseFound) Then Exit;
  110. asm
  111. mov ax, 2
  112. push bp
  113. int $33
  114. pop bp
  115. end;
  116. end;
  117. Procedure GetMouseState(var x,y,buttons:LongInt);
  118. begin
  119. If (Not MouseFound) Then Exit;
  120. asm
  121. mov ax, 3
  122. push bp
  123. int $33
  124. pop bp
  125. {$if defined(FPC_MM_TINY) or defined(FPC_MM_SMALL) or defined(FPC_MM_MEDIUM)}
  126. mov di, x
  127. mov [di], cx
  128. mov word [di + 2], 0
  129. mov di, y
  130. mov [di], dx
  131. mov word [di + 2], 0
  132. mov di, buttons
  133. mov [di], bx
  134. mov word [di + 2], 0
  135. {$else}
  136. mov ax, ds
  137. lds di, x
  138. mov [di], cx
  139. mov word [di + 2], 0
  140. lds di, y
  141. mov [di], dx
  142. mov word [di + 2], 0
  143. lds di, buttons
  144. mov [di], bx
  145. mov word [di + 2], 0
  146. mov ds, ax
  147. {$endif}
  148. end;
  149. end;
  150. Function LPressed:Boolean;
  151. Begin
  152. If (Not MouseFound) Then Exit;
  153. asm
  154. mov ax, 3
  155. push bp
  156. int $33
  157. pop bp
  158. mov ax,bx
  159. and ax, 1
  160. mov @Result, al
  161. end;
  162. end;
  163. Function RPressed:Boolean;
  164. Begin
  165. If (Not MouseFound) Then Exit;
  166. asm
  167. mov ax, 3
  168. push bp
  169. int $33
  170. pop bp
  171. mov ax,bx
  172. shr ax,1
  173. and ax,1
  174. mov @Result, al
  175. end;
  176. end;
  177. Function MPressed:Boolean;
  178. Begin
  179. If (Not MouseFound) Then Exit;
  180. asm
  181. mov ax, 3
  182. push bp
  183. int $33
  184. pop bp
  185. mov ax, bx
  186. shr ax, 1
  187. shr ax, 1
  188. and ax, 1
  189. mov @Result, al
  190. end;
  191. end;
  192. Procedure SetMousePos(x,y:LongInt);
  193. Begin
  194. If (Not MouseFound) Then Exit;
  195. asm
  196. mov ax, 4
  197. mov cx, x
  198. mov dx, y
  199. push bp
  200. int $33
  201. pop bp
  202. End;
  203. End;
  204. Function GetLastButtonPress(Button: LongInt;var x,y:LongInt):LongInt;
  205. Begin
  206. If (Not MouseFound) Then Exit;
  207. GetLastButtonPress := 0;
  208. asm
  209. mov ax, 5
  210. mov bx, button
  211. shr bx, 1 {0 = left, 1 = right, 2 = middle}
  212. push bp
  213. int $33
  214. pop bp
  215. mov word ptr @Result, bx
  216. {$if defined(FPC_MM_TINY) or defined(FPC_MM_SMALL) or defined(FPC_MM_MEDIUM)}
  217. mov di, x
  218. mov [di], cx
  219. mov word [di + 2], 0
  220. mov di, y
  221. mov [di], dx
  222. mov word [di + 2], 0
  223. {$else}
  224. mov si, ds
  225. lds di, x
  226. mov [di], cx
  227. mov word [di + 2], 0
  228. lds di, y
  229. mov [di], dx
  230. mov word [di + 2], 0
  231. mov ds, si
  232. {$endif}
  233. end;
  234. end;
  235. Function GetLastButtonRelease (button : LongInt; var x,y:LongInt): LongInt;
  236. begin
  237. If (Not MouseFound) Then Exit;
  238. GetLastButtonRelease := 0;
  239. asm
  240. mov ax, 6
  241. mov bx, button
  242. shr bx, 1 {0 = left, 1 = right, 2 = middle}
  243. push bp
  244. int $33
  245. pop bp
  246. mov word ptr @Result, bx
  247. {$if defined(FPC_MM_TINY) or defined(FPC_MM_SMALL) or defined(FPC_MM_MEDIUM)}
  248. mov di, x
  249. mov [di], cx
  250. mov word [di + 2], 0
  251. mov di, y
  252. mov [di], dx
  253. mov word [di + 2], 0
  254. {$else}
  255. mov si, ds
  256. lds di, x
  257. mov [di], cx
  258. mov word [di + 2], 0
  259. lds di, y
  260. mov [di], dx
  261. mov word [di + 2], 0
  262. mov ds, si
  263. {$endif}
  264. end;
  265. end;
  266. Procedure SetMouseXRange (Min,Max:LongInt);
  267. begin
  268. If (Not MouseFound) Then Exit;
  269. asm
  270. mov ax, 7
  271. mov cx, min
  272. mov dx, max
  273. push bp
  274. int $33
  275. pop bp
  276. end;
  277. end;
  278. Procedure SetMouseYRange (min,max:LongInt);
  279. begin
  280. If (Not MouseFound) Then Exit;
  281. asm
  282. mov ax, 8
  283. mov cx, min
  284. mov dx, max
  285. push bp
  286. int $33
  287. pop bp
  288. end;
  289. end;
  290. Procedure SetMouseWindow(x1,y1,x2,y2:LongInt);
  291. Begin
  292. If (Not MouseFound) Then Exit;
  293. SetMouseXRange(x1,x2);
  294. SetMouseYRange(y1,y2);
  295. End;
  296. Procedure SetMouseShape(ForeColor,BackColor,Ascii:Byte);
  297. Begin
  298. If (Not MouseFound) Then Exit;
  299. asm
  300. xor bx, bx
  301. mov ax, 10
  302. xor dx, dx
  303. mov dh, BackColor
  304. mov cl, 4
  305. shl dh, cl
  306. add dh, ForeColor
  307. mov dl, Ascii
  308. mov cx, $ffff
  309. push bp
  310. int $33
  311. pop bp
  312. End;
  313. End;
  314. Procedure SetMouseAscii(Ascii:byte);
  315. Begin
  316. If (Not MouseFound) Then Exit;
  317. asm
  318. xor bx, bx
  319. mov ax, 10
  320. mov cx, $ff00
  321. xor dx,dx
  322. mov dl, Ascii
  323. push bp
  324. int $33
  325. pop bp
  326. End;
  327. End;
  328. Procedure SetMouseHideWindow(x1,y1,x2,y2:LongInt);
  329. Begin
  330. If (Not MouseFound) Then Exit;
  331. asm
  332. mov ax, $0010
  333. mov cx, x1
  334. mov dx, y1
  335. mov si, x2
  336. mov di, y2
  337. push bp
  338. int $33
  339. pop bp
  340. end;
  341. End;
  342. Procedure SetMouseSpeed(Horizontal,Vertical:LongInt);
  343. Begin
  344. If (Not MouseFound) Then Exit;
  345. asm
  346. mov ax, $0f
  347. mov cx, Horizontal
  348. mov dx, Vertical
  349. push bp
  350. int $33
  351. pop bp
  352. end;
  353. End;
  354. Begin
  355. MouseFound := InitMouse;
  356. End.