2
0

msmouse.pp 9.5 KB

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