mouse.pp 8.7 KB

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