mouse.pp 9.2 KB

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