mouse.pp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 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 Mouse;
  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. {check if mouse is present and sets the mouse variable}
  21. Function Check_Mouse:Boolean;
  22. {shows mouse pointer,text+graphics screen support}
  23. Procedure Show_Mouse;
  24. {hides mouse pointer}
  25. Procedure Hide_Mouse;
  26. {reads mouse position in pixels,divide by 8 to get text position,and reads
  27. buttons state(1-left button,2=right button,7=middle button)}
  28. Procedure read_mouse (var x,y:Longint;var buttons:Longint);
  29. {sets mouse pointer in text mode}
  30. Procedure Mouse_Cur(X,Y:Longint);
  31. {sets the mouse shape in text mode}
  32. Procedure Mouse_Shape(BackColor,ForColor,Ascii:LongInt);
  33. {sets the mouse ascii in text mode}
  34. Procedure Mouse_Ascii(Ascii:LongInt);
  35. {returns which button was pressed after last call to function}
  36. Function mouse_press(var x,y:Longint;button:Longint):Longint;
  37. {returns which button was realeased after last call to function}
  38. Function mouse_release (var row,col:Longint;button : Longint):integer;
  39. {set's mouse y range}
  40. Procedure mouse_yrange (min,max:Longint);
  41. {set's mouse y range}
  42. Procedure mouse_xrange (min,max:Longint);
  43. {set mouse speed}
  44. Procedure Micky(Horizontal ,Vertical:Longint);
  45. {set rectangle on screen that mouse will disappear if will point on it}
  46. Procedure Unseen_Mouse(x1,y1,x2,y2:Longint);
  47. {return if right button pressed}
  48. Function IsRPressed:Boolean;
  49. {return if left button pressed}
  50. Function IsLPressed:Boolean;
  51. {return mouse X coordinate in textmode}
  52. Function MouseX:longint;
  53. {return mouse Y coordinate in textmode}
  54. Function MouseY:longint;
  55. {return which mouse buttons are pressed, only in bit 0-2}
  56. Function MouseButtons:longint;
  57. {set window for mouse}
  58. Procedure MWindow(x1,y1,x2,y2:Longint);
  59. Var
  60. MouseFound:Boolean;
  61. Implementation
  62. Function Check_Mouse:Boolean;
  63. begin
  64. asm
  65. xorl %eax,%eax
  66. pushl %ebp
  67. int $0x33
  68. popl %ebp
  69. cmpw $0xffff,%ax
  70. setz %al
  71. movb %al,MouseFound
  72. movb %al,__RESULT
  73. end;
  74. end;
  75. procedure show_mouse;
  76. begin
  77. {$IFDEF MOUSECHECK}
  78. If (Not MouseFound) Then Exit;
  79. {$ENDIF}
  80. asm
  81. movl $1,%eax
  82. pushl %ebp
  83. int $0x33
  84. popl %ebp
  85. end;
  86. end;
  87. procedure hide_mouse;
  88. begin
  89. {$IFDEF MOUSECHECK}
  90. If (Not MouseFound) Then Exit;
  91. {$ENDIF}
  92. asm
  93. movl $2,%eax
  94. pushl %ebp
  95. int $0x33
  96. popl %ebp
  97. end;
  98. end;
  99. procedure read_mouse (var x,y,buttons:Longint);
  100. begin
  101. {$IFDEF MOUSECHECK}
  102. If (Not MouseFound) Then Exit;
  103. {$ENDIF}
  104. asm
  105. movl $3,%eax
  106. pushl %ebp
  107. int $0x33
  108. popl %ebp
  109. andl $0xffff,%ecx
  110. andl $0xffff,%edx
  111. movl x,%eax
  112. movl %ecx,(%eax)
  113. movl y,%eax
  114. movl %edx,(%eax)
  115. movl buttons,%eax
  116. movw %bx,(%eax)
  117. end;
  118. end;
  119. function mouse_press(var x,y:Longint;button:Longint):Longint;
  120. begin
  121. {$IFDEF MOUSECHECK}
  122. If (Not MouseFound) Then Exit;
  123. {$ENDIF}
  124. asm
  125. movl $5,%eax
  126. movl button,%ebx
  127. pushl %ebp
  128. int $0x33
  129. popl %ebp
  130. andl $0xffff,%ecx
  131. andl $0xffff,%edx
  132. movl x,%ebx
  133. movl %ecx,(%ebx)
  134. movl y,%ebx
  135. movl %edx,(%ebx)
  136. movl %eax,__RESULT
  137. end;
  138. end;
  139. function mouse_release (var row,col:Longint;button : Longint):integer;
  140. begin
  141. {$IFDEF MOUSECHECK}
  142. If (Not MouseFound) Then Exit;
  143. {$ENDIF}
  144. asm
  145. movl $6,%eax
  146. movl button,%ebx
  147. pushl %ebp
  148. int $0x33
  149. popl %ebp
  150. andl $0xffff,%ecx
  151. andl $0xffff,%edx
  152. movl x,%ebx
  153. movl %ecx,(%ebx)
  154. movl y,%ebx
  155. movl %edx,(%ebx)
  156. movl %eax,__RESULT
  157. end;
  158. end;
  159. procedure mouse_yrange (min,max:Longint);
  160. begin
  161. {$IFDEF MOUSECHECK}
  162. If (Not MouseFound) Then Exit;
  163. {$ENDIF}
  164. asm
  165. movl $8,%eax
  166. movl min,%ecx
  167. movl max,%edx
  168. pushl %ebp
  169. int $0x33
  170. popl %ebp
  171. end;
  172. end;
  173. procedure mouse_xrange (min,max:Longint);
  174. begin
  175. {$IFDEF MOUSECHECK}
  176. If (Not MouseFound) Then Exit;
  177. {$ENDIF}
  178. asm
  179. movl $7,%eax
  180. movl min,%ecx
  181. movl max,%edx
  182. pushl %ebp
  183. int $0x33
  184. popl %ebp
  185. end;
  186. end;
  187. Procedure Mouse_Cur(X,Y:Longint);
  188. Begin
  189. {$IFDEF MOUSECHECK}
  190. If (Not MouseFound) Then Exit;
  191. {$ENDIF}
  192. asm
  193. movl $4,%eax
  194. movl X,%ecx
  195. movl Y,%edx
  196. shll $3,%ecx
  197. shll $3,%edx
  198. pushl %ebp
  199. int $0x33
  200. popl %ebp
  201. End;
  202. End;
  203. Procedure Mouse_Shape(BackColor,ForColor,Ascii:LongInt);
  204. Begin
  205. {$IFDEF MOUSECHECK}
  206. If (Not MouseFound) Then Exit;
  207. {$ENDIF}
  208. asm
  209. xorl %ebx,%ebx
  210. movl $0xa,%ax
  211. movl $0xff,%ecx
  212. xorl %edx,%edx
  213. movb 8(%ebp),%dh
  214. shlb $4,%dh
  215. addb ForColor,%dh
  216. pushl %ebp
  217. int $0x33
  218. popl %ebp
  219. End;
  220. End;
  221. Procedure Mouse_Ascii(Ascii:LongInt);
  222. Begin
  223. {$IFDEF MOUSECHECK}
  224. If (Not MouseFound) Then Exit;
  225. {$ENDIF}
  226. asm
  227. xorl %ebx,%ebx
  228. movl $0xa,%eax
  229. movl $0xff00,%ecx
  230. xorl %edx,%edx
  231. movb 8(%ebp),%dl
  232. pushl %ebp
  233. int $0x33
  234. popl %ebp
  235. End;
  236. End;
  237. Procedure Unseen_Mouse(x1,y1,x2,y2:Longint);
  238. Begin
  239. {$IFDEF MOUSECHECK}
  240. If (Not MouseFound) Then Exit;
  241. {$ENDIF}
  242. asm
  243. movl $0x0010,%eax
  244. movl x1,%ecx
  245. movl y1,%edx
  246. movl x2,%esi
  247. movl y2,%edi
  248. pushl %ebp
  249. int $0x33
  250. popl %ebp
  251. end;
  252. End;
  253. Procedure Micky(Horizontal ,Vertical:Longint);
  254. Begin
  255. {$IFDEF MOUSECHECK}
  256. If (Not MouseFound) Then Exit;
  257. {$ENDIF}
  258. asm
  259. movl $0x0f,%eax
  260. movl Horizontal,%ecx
  261. movl Vertical,%edx
  262. pushl %ebp
  263. int $0x33
  264. popl %ebp
  265. end;
  266. End;
  267. Function IsRPressed:Boolean;
  268. Begin
  269. {$IFDEF MOUSECHECK}
  270. If (Not MouseFound) Then Exit;
  271. {$ENDIF}
  272. asm
  273. movl $3,%eax
  274. pushl %ebp
  275. int $0x33
  276. popl %ebp
  277. shrl $1,%eax
  278. andl $1,%eax
  279. movb %al,__RESULT
  280. end;
  281. end;
  282. Function IsLPressed:Boolean;
  283. Begin
  284. {$IFDEF MOUSECHECK}
  285. If (Not MouseFound) Then Exit;
  286. {$ENDIF}
  287. asm
  288. movl $3,%eax
  289. pushl %ebp
  290. int $0x33
  291. popl %ebp
  292. andl $1,%eax
  293. movb %al,__RESULT
  294. end;
  295. end;
  296. function MouseX:longint;
  297. begin
  298. {$IFDEF MOUSECHECK}
  299. If (Not MouseFound) Then Exit;
  300. {$ENDIF}
  301. asm
  302. movl $3,%eax
  303. pushl %ebp
  304. int $0x33
  305. popl %ebp
  306. movzwl %cx,%eax
  307. shrl $3,%eax
  308. incl %eax
  309. movl %eax,__RESULT
  310. end;
  311. end;
  312. function MouseY:longint;
  313. begin
  314. {$IFDEF MOUSECHECK}
  315. If (Not MouseFound) Then Exit;
  316. {$ENDIF}
  317. asm
  318. movl $3,%eax
  319. pushl %ebp
  320. int $0x33
  321. popl %ebp
  322. movzwl %dx,%eax
  323. shrl $3,%eax
  324. incl %eax
  325. movl %eax,__RESULT
  326. end;
  327. end;
  328. function MouseButtons:longint;
  329. begin
  330. {$IFDEF MOUSECHECK}
  331. If (Not MouseFound) Then Exit;
  332. {$ENDIF}
  333. asm
  334. movl $3,%eax
  335. pushl %ebp
  336. int $0x33
  337. popl %ebp
  338. movl %ebx,%eax
  339. andl $7,%eax
  340. movl %eax,__RESULT
  341. end;
  342. end;
  343. Procedure MWindow(x1,y1,x2,y2:Longint);
  344. Begin
  345. {$IFDEF MOUSECHECK}
  346. If (Not MouseFound) Then Exit;
  347. {$ENDIF}
  348. mouse_xrange(x1,x2);
  349. mouse_yrange(y1,y2);
  350. End;
  351. Begin
  352. Check_Mouse;
  353. End.
  354. {
  355. $Log$
  356. Revision 1.2 1998-03-26 12:25:22 peter
  357. * integrated both mouse units
  358. Revision 1.1.1.1 1998/03/25 11:18:41 root
  359. * Restored version
  360. Revision 1.4 1998/03/24 15:53:12 peter
  361. * cleanup and doesn't give warnings when compiling
  362. Revision 1.3 1998/01/26 11:56:24 michael
  363. + Added log at the end
  364. Revision 1.2
  365. date: 1997/12/01 12:15:45; author: michael; state: Exp; lines: +14 -12
  366. + added copyright reference in header.
  367. Revision 1.1
  368. date: 1997/11/27 08:33:49; author: michael; state: Exp;
  369. Initial revision
  370. Revision 1.1.1.1
  371. date: 1997/11/27 08:33:49; author: michael; state: Exp; lines: +0 -0
  372. FPC RTL CVS start
  373. }