fork download
  1. program ComMouse;
  2.  
  3. uses
  4. Crt, Graph;
  5.  
  6. {type
  7.   TTryData =}
  8.  
  9. var
  10. { Data }
  11. Dat0, Dat1, Dat2, Dat3, Dat4 : Byte;
  12. PortAdr : Word;
  13.  
  14. { Mouse }
  15. LBut, MBut, RBut : Boolean;
  16. PX, PY : Integer;
  17.  
  18. function TryMS : boolean; far;
  19. var
  20. r : Boolean;
  21. begin
  22. r := False;
  23. asm
  24. MOV DX, PortAdr
  25. ADD DX, 5
  26. IN AL, DX
  27. TEST AL, 01h
  28. JZ @x
  29.  
  30. SUB DX, 5
  31. IN AL, DX
  32. TEST AL, 40h
  33. JZ @x
  34.  
  35. MOV Dat0, AL
  36.  
  37. ADD DX, 5
  38. @1: IN AL, DX
  39. TEST AL, 80h
  40. JNZ @x
  41. TEST AL, 01h
  42. JZ @1
  43. SUB DX, 5
  44.  
  45. IN AL, DX
  46. MOV Dat1, AL
  47.  
  48. ADD DX, 5
  49. @2: IN AL, DX
  50. TEST AL, 80h
  51. JNZ @x
  52. TEST AL, 01h
  53. JZ @2
  54. SUB DX, 5
  55.  
  56. IN Al, DX
  57. MOV Dat2, AL
  58.  
  59. MOV AH, Dat0
  60. SHL AH, 6
  61. MOV AL, Dat1
  62. AND AL, 3Fh
  63. OR AH, AL
  64. SAR AX, 8
  65. ADD PX, AX
  66.  
  67. MOV AH, Dat0
  68. AND AH, 0Ch
  69. SHL AH, 4
  70. MOV AL, Dat2
  71. AND AL, 3Fh
  72. OR AH, AL
  73. SAR AX, 8
  74. ADD PY, AX
  75.  
  76. MOV AL, Dat0
  77. MOV LBut, False
  78. TEST Al, 20h
  79. JZ @r
  80. MOV LBut, True
  81. @r: MOV MBut, False
  82. MOV RBut, False
  83. TEST Al, 10h
  84. JZ @t
  85. MOV RBut, True
  86.  
  87. @t: MOV r, True
  88. @x:
  89. end;
  90. TryMS := r;
  91. end;
  92.  
  93. function TryPC : boolean; far;
  94. var
  95. r : Boolean;
  96. begin
  97. r := False;
  98. asm
  99. MOV DX, PortAdr
  100. ADD DX, 5
  101. IN AL, DX
  102. TEST AL, 01h
  103. JZ @x
  104.  
  105. SUB DX, 5
  106. IN AL, DX
  107. MOV AH, AL
  108. AND AH, $F8
  109. CMP AH, 80h
  110. JNE @x
  111.  
  112. MOV Dat0, AL
  113.  
  114. ADD DX, 5
  115. @1: IN AL, DX
  116. TEST AL, 80h
  117. JNZ @x
  118. TEST AL, 01h
  119. JZ @1
  120. SUB DX, 5
  121.  
  122. IN AL, DX
  123. MOV Dat1, AL
  124.  
  125. ADD DX, 5
  126. @2: IN AL, DX
  127. TEST AL, 80h
  128. JNZ @x
  129. TEST AL, 01h
  130. JZ @2
  131. SUB DX, 5
  132.  
  133. IN Al, DX
  134. MOV Dat2, AL
  135.  
  136. ADD DX, 5
  137. @3: IN AL, DX
  138. TEST AL, 80h
  139. JNZ @x
  140. TEST AL, 01h
  141. JZ @3
  142. SUB DX, 5
  143.  
  144. IN Al, DX
  145. MOV Dat3, AL
  146.  
  147. ADD DX, 5
  148. @4: IN AL, DX
  149. TEST AL, 80h
  150. JNZ @x
  151. TEST AL, 01h
  152. JZ @4
  153. SUB DX, 5
  154.  
  155. IN Al, DX
  156. MOV Dat4, AL
  157.  
  158.  
  159. MOV AH, Dat1
  160. SAR AX, 8
  161. ADD PX, AX
  162.  
  163. MOV AH, Dat2
  164. SAR AX, 8
  165. SUB PY, AX
  166.  
  167. MOV AL, Dat0
  168. MOV RBut, False
  169. TEST Al, 01h
  170. JNZ @r
  171. MOV RBut, True
  172. @r: MOV MBut, False
  173. TEST Al, 02h
  174. JNZ @s
  175. MOV MBut, True
  176. @s: MOV LBut, False
  177. TEST Al, 04h
  178. JZ @t
  179. MOV LBut, True
  180.  
  181. @t: MOV r, True
  182. @x:
  183. end;
  184. TryPC := r;
  185. end;
  186.  
  187. type
  188. TTryMouse = function : Boolean;
  189. var
  190. TryMouse : TTryMouse;
  191.  
  192. procedure InitPC;
  193. begin
  194. asm
  195. MOV AX, 40h
  196. MOV ES, AX
  197. MOV DX, ES:[0]
  198. MOV PortADR, DX
  199. ADD DX, 3
  200. MOV AL, 10000000b
  201. OUT DX, AL
  202. SUB DX, 2
  203. XOR AL, AL
  204. OUT DX, AL
  205. DEC DX
  206. MOV AL, 60h
  207. OUT DX, AL
  208.  
  209. MOV AL, 00000011b
  210. ADD DX, 3
  211. OUT DX, AL
  212.  
  213. SUB DX, 2
  214. MOV AL, 0
  215. OUT DX, AL
  216.  
  217. XOR AX, AX
  218. MOV PX, AX
  219. MOV PY, AX
  220. end;
  221. TryMouse := TryPC;
  222. end;
  223.  
  224. procedure InitMS;
  225. begin
  226. asm
  227. MOV AX, 40h
  228. MOV ES, AX
  229. MOV DX, ES:[0]
  230. MOV PortADR, DX
  231.  
  232. ADD DX, 3
  233. MOV AL, 10000000b
  234. OUT DX, AL
  235. SUB DX, 2
  236. XOR AL, AL
  237. OUT DX, AL
  238. DEC DX
  239. MOV AL, 60h
  240. OUT DX, AL
  241. MOV AL, 00000010b
  242. ADD DX, 3
  243. OUT DX, AL
  244.  
  245. SUB DX, 2
  246. MOV AL, 0
  247. OUT DX, AL
  248.  
  249. XOR AX, AX
  250. MOV PX, AX
  251. MOV PY, AX
  252. end;
  253. TryMouse := TryMS;
  254. end;
  255.  
  256. procedure UpDatePicture;
  257. const
  258. Page : integer = 0;
  259. var
  260. C : Word;
  261. S : String;
  262. begin
  263. Page := Page xor 1;
  264. SetActivePage(Page);
  265. SetBkColor(Black);
  266. ClearDevice;
  267. SetColor(White);
  268. OutTextXY(10,10,'Press Q to exit');
  269. OutTextXY(10,20,'Press P to Init PC-Mouse');
  270. OutTextXY(10,30,'Press M to Init MS-Mouse');
  271.  
  272. Str(PX,S);
  273. OutTextXY(GetMaxX-80,GetMaxY-10,S);
  274. Str(PY,S);
  275. OutTextXY(GetMaxX-40,GetMaxY-10,S);
  276. end;
  277.  
  278. var
  279. GrDriv, GrMode : Integer;
  280. begin
  281. { Init Graph Section }
  282. GrDriv := VGA;
  283. InitGraph(GrDriv,GrMode,'ะก:\BP\BGI');
  284. UpDatePicture;
  285. { Maim Program Loop }
  286. while true do
  287. begin
  288. { Read A Command }
  289. if KeyPressed then
  290. case ReadKey of
  291. 'Q','q' : break;
  292. 'M','m' : InitMS;
  293. 'P','p' : InitPC;
  294. end;
  295. { Read A Mouse }
  296. if Assigned(TryMouse) then
  297. if TryMouse then
  298. UpDatePicture;
  299. end;
  300.  
  301. CloseGraph;
  302. end.
  303.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Free Pascal Compiler version 2.6.4+dfsg-6 [2015/05/31] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling prog.pas
prog.pas(4,10) Fatal: Can't find unit Graph used by ComMouse
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
stdout
Standard output is empty