home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / MOUSE.P < prev    next >
Encoding:
Text File  |  1989-10-23  |  11.0 KB  |  341 lines

  1. { -------------------------------------------------------------    }
  2. {                                 }
  3. {  MOUSE.P                             }
  4. {  copyright (c) 1989, Microway, Inc                }
  5. {                                 }
  6. { --------------------- MOUSE FUNCTIONS ----------------------- }
  7. {                                }
  8. {  function init_mouse:integer;                    }
  9. {  procedure show_mouse_cursor;                                 }
  10. {  procedure show_mouse_cursor;                                 }
  11. {  procedure get_mouse(i,j,k:intptr);                }
  12. {  procedure set_mouse(i,j:intptr);                }
  13. {  procedure get_press(i,j,k,l:intptr);                }
  14. {  procedure get_release(i,j,k,l:intptr);            }
  15. {  procedure mouse_viewport(i,j,k,l:intptr);            }
  16. {  procedure read_motion(i,j:intptr);                }
  17. {  procedure set_mp_ratio(i,j:intptr);                }
  18. {  procedure set_mouse__cursor(i,j,k:intptr);                   }
  19. {  procedure set_subroutine(i,j,k:intptr);            }
  20. {                                }
  21. { -------------------------------------------------------------    }
  22.  
  23. type
  24.     intptr = ^integer;
  25.  
  26. var
  27.     a,b,c,d: intptr;
  28.  
  29. function calloc(i,j:integer): intptr; external;
  30.  
  31. { mouse -------------------------------------------------------    }
  32. {                                }
  33. {    FORTRAN:    call mouse(i,j,k,l)             }
  34. {    C:        mouse(&i,&j,&k,&l);             }
  35. {                                }
  36. {  mouse takes four arguments, all pointers to integers.    }
  37. {  These are as defined in mouse documentation, for the     }
  38. {  most part.  In ordinary circumstances, the values pointed    }
  39. {  at by the arguments are placed (eventually) in the ax, bx,    }
  40. {  cx, and dx registers, and a real mode INT 33h issued.      }
  41. {  Of course, all this is done via Phar Lap service function    }
  42. {  2511h of int 21h, issue real mode interrupt with registers    }
  43. {  specified, so the Assembly code is more complicated than     }
  44. {  the description makes it sound.                }
  45. {                                }
  46. {  There are special cases, however, and these allow for        }
  47. {  pointers to real mode arrays and/or routines to be passed    }
  48. {  and enterpreted correctly.  They are as follows:        }
  49. {                                }
  50. {  1. If the first argument points at a 9 or 18 (decimal),     }
  51. {     the fourth argument is placed into the ds and es        }
  52. {     registers, and dx is set to 0.                }
  53. {                                }
  54. {  2. If the first argument points at a 12, the fourth         }
  55. {     argument is placed into ds and es and the second is    }
  56. {     placed in dx.                        }
  57. {                                }
  58. { -------------------------------------------------------------    }
  59. procedure mouse(i,j,k,l:intptr); external;
  60.  
  61.  
  62. { realbuf -----------------------------------------------------    }
  63. {                                }
  64. {    FORTRAN:    i=realbuf(i)                }
  65. {    C:        i=realbuf(&i);                 }
  66. {                                }
  67. {  realbuf requests allocation of DOS memory of the number of    }
  68. {  bytes indicated by its argument.  In the event of success,    }
  69. {  it returns the address of the allocated memory as a real    }
  70. {  mode segment value.  This is a 32 bit value, with the top    }
  71. {  16 bits zeroed out (i.e., in the range for 16 bit values.    }
  72. {  In the event of failure, it returns -1 (32 bits).  The    }
  73. {  value at the argument variable has been replaced with the     }
  74. {  return value, so it can also be treated as a procedure.    }
  75. {                                }
  76. { -------------------------------------------------------------    }
  77. procedure realbuf(i:intptr); external;
  78.  
  79.  
  80. { init_mouse --------------------------------------------------    }
  81. {                                }
  82. {    FORTRAN:    i=init_mouse                }
  83. {    C:        i=init_mouse();             }
  84. {                                }
  85. {  returns a 0 for no mouse, a 2 for a Microsoft Mouse,        }
  86. {  or a 3 for a Mouse Systems mouse.  Initializes interface    }
  87. {  variables, if this has not been done already.        }
  88. {                                }
  89. { -------------------------------------------------------------    }
  90. function init_mouse: integer;
  91. begin
  92.     if a=nil then begin    { We use calloc instead    of new    }
  93.         a:=calloc(1,4);    { becuase we want to link this    }
  94.         b:=calloc(1,4);    { to non-Pascal code.  All NDP     }
  95.         c:=calloc(1,4);    { languages have C functions    }
  96.         d:=calloc(1,4);    { in their libraries.        }
  97.     end;    
  98.     a^:=0;
  99.     mouse(a,b,c,d);
  100.     if a^=-1 then begin
  101.         init_mouse:=b^;
  102.     end else begin
  103.         init_mouse:=0;
  104.     end;
  105. end;
  106.  
  107.  
  108. { show_mouse_cursor ------------------------------------------- }
  109. {                                }
  110. {       FORTRAN:        call show_mouse_cursor                  }
  111. {       C:              show_mouse_cursor();                    }
  112. {                                }
  113. {  Displays the mouse cursor - no arguments                     }
  114. {                                }
  115. { -------------------------------------------------------------    }
  116. procedure show_mouse_cursor;
  117. begin
  118.     a^:=1;
  119.     mouse(a,b,c,d);
  120. end;
  121.  
  122.  
  123. { hide_mouse_cursor ------------------------------------------- }
  124. {                                }
  125. {       FORTRAN:        call hide_mouse_cursor                  }
  126. {       C:              hide_mouse_cursor();                    }
  127. {                                }
  128. {  Hides the mouse cursor - no arguments                        }
  129. {                                }
  130. { -------------------------------------------------------------    }
  131. procedure hide_mouse_cursor;
  132. begin
  133.     a^:=2;
  134.     mouse(a,b,c,d);
  135. end;
  136.  
  137.  
  138. { get_mouse ---------------------------------------------------    }
  139. {                                }
  140. {    FORTRAN:    call get_mouse(i,j,k)             }
  141. {    C:        get_mouse(&i,&j,&k);            }
  142. {                                }
  143. {  Get mouse data.  This procedure takes three arguments, each    }
  144. {  a pointer to an integer.  They are not initialized by the    }
  145. {  calling program.  The first is set to the value of the     }
  146. {  button press, 0=no button, 1=left, 2=right, 4=middle        }
  147. {  The second argument is set to the horizontal position.    }
  148. {  The third is set to the vertical position.            }
  149. {                                }
  150. { -------------------------------------------------------------    }
  151. procedure get_mouse(i,j,k: intptr);
  152. begin
  153.     a^:=3;
  154.     mouse(a,i,j,k);
  155. end;
  156.  
  157.  
  158. { set_mouse ---------------------------------------------------    }
  159. {                                }
  160. {    FORTRAN:    call set_mouse(i,j)             }
  161. {    C:        set_mouse(&i,&j);               }
  162. {                                }
  163. {  set_mouse has two arguments, both pointers to integers.    }
  164. {  The mouse coordinates are set to the values pointed        }
  165. {  at by the arguments.  The first is the horizontal position,    }
  166. {  and the second is the vertical.                }
  167. {                                }
  168. { -------------------------------------------------------------    }
  169. procedure set_mouse(i,j: intptr);
  170. begin
  171.     a^:=4;
  172.     mouse(a,b,i,j);
  173. end;
  174.  
  175.  
  176. { get_press ---------------------------------------------------    }
  177. {                                }
  178. {    FORTRAN:    call get_press(i,j,k)           }
  179. {    C:        get_press(&i,&j,&k);            }
  180. {                                }
  181. {  There are four arguments, all pointers to integers.        }
  182. {  input:                             }
  183. {    i^=button (1 for left, 2 for right, 4 for middle    }
  184. {  output:                            }
  185. {    j^=count of button presses since last check        }
  186. {    k^=column of last press                    }
  187. {    l^=row of last press                    }
  188. {                                }
  189. { -------------------------------------------------------------    }
  190. procedure get_press(i,j,k,l:intptr);
  191. begin
  192.     j^:=i^;
  193.     i^:=5;
  194.     mouse(i,j,k,l);
  195. end;
  196.  
  197.  
  198. { get_release -------------------------------------------------    }
  199. {                                }
  200. {    FORTRAN:    call get_release(i,j,k)         }
  201. {    C:        get_release(&i,&j,&k);          }
  202. {                                }
  203. {  Four arguments are all pointers to integers.            }
  204. {  input:                             }
  205. {    i^=button (1 for left, 2 for right, 4 for middle    }
  206. {  output:                             }
  207. {    j^=count of button releases since last check        }
  208. {    k^=column of last release                }
  209. {    l^=row of last release                    }
  210. {                                }
  211. { -------------------------------------------------------------    }
  212. procedure get_release(i,j,k,l:intptr);
  213. begin
  214.     j^:=i^;
  215.     i^:=6;
  216.     mouse(i,j,k,l);
  217. end;
  218.  
  219.  
  220. { mouse_viewport ----------------------------------------------    }
  221. {                                }
  222. {    FORTRAN:    call mouse_viewport(i,j,k,l)        }
  223. {    C:        mouse_viewport(&i,&j,&k,&l);        }
  224. {                                }
  225. {  mouse_viewport has four arguments, all pointers to integers.    }
  226. {  input:                            }
  227. {    i=min horizontal position                }
  228. {    j=max horizontal position                }
  229. {    k=min vertical position                    }
  230. {    l=max vertical position                    }
  231. {  output:                            }
  232. {    no defined return values                }
  233. {                                }
  234. { -------------------------------------------------------------    }
  235. procedure mouse_viewport(i,j,k,l:intptr);
  236. begin
  237.     a^:=7;
  238.     mouse(a,b,i,j);
  239.     a^:=8;
  240.     mouse(a,b,k,l);
  241. end;
  242.  
  243.  
  244. { read_motion -------------------------------------------------    }
  245. {                                }
  246. {    FORTRAN:    call read_motion(i,j)            }
  247. {    C:        read_motion(&i,&j);             }
  248. {                                }
  249. {  Two arguments are both pointers to integers, neither     }
  250. {  needs any initial value.                    }
  251. {  On return, the first argument points at the sum of all     }
  252. {  horizontal motion, the second at vertical.  Values are in    }
  253. {  32-bit integer format, but in 16-bit signed integer range.    }
  254. {                                }
  255. { -------------------------------------------------------------    }
  256. procedure read_motion(i,j:intptr);
  257. begin
  258.     a^:=11;
  259.     i^:=0;
  260.     j^:=0;
  261.     mouse(a,b,i,j);
  262.     if i^>32767 then i^:=i^-65536;
  263.     if j^>32767 then j^:=j^-65536;
  264. end;
  265.  
  266.  
  267. { set_mp_ratio ------------------------------------------------    }
  268. {                                }
  269. {    FORTRAN:    call set_mp_ratio(i,j)          }
  270. {    C:        set_mp_ratio(&i,&j)             }
  271. {                                }
  272. {  Two arguments are pointers to integers.  The first points    }
  273. {  a value for the ration for horizontal movement, and the     }
  274. {  second at the value for vertical.  Both are set to 8     }
  275. {  pixels.                            }
  276. {                                }
  277. { -------------------------------------------------------------    }
  278. procedure set_mp_ratio(i,j:intptr);
  279. begin
  280.     a^:=15;
  281.     mouse(a,b,i,j);
  282. end;
  283.  
  284.  
  285. { set_mouse_cursor -------------------------------------------- }
  286. {                                }
  287. {       FORTRAN:        call set_mouse_cursor(i,j,k)            }
  288. {       C:              set_mouse_cursor(&i,&j,&k);             }
  289. {                                }
  290. {  Three arguments are all integers.  The first and second are    }
  291. {  the coordinates of the so-called hot spot, the point in the    }
  292. {  array representing the actual location of the mouse          }
  293. {  cursor (this can be outside the actual array, since        }
  294. {  values can range from -16 to 16, only 1 to 16 being the     }
  295. {  array area).  The third integer is the value of a real     }
  296. {  mode segment address at which the array is to be found.    }
  297. {  Using this procedure requires the following:            }
  298. {                                }
  299. {    1. Real memory must be reserved (e.g. through         }
  300. {       the -maxreal command line switch).            }
  301. {    2. Real memory must be allocated via realbuf or     }
  302. {       a call to Phar Lap.                    }
  303. {    3. The array is be initialized.                }
  304. {    4. The array is moved to real memory by blk_bm.        }
  305. {       5. The call is made to set_mouse_cursor.                }
  306. {                                }
  307. { -------------------------------------------------------------    }
  308. procedure set_mouse_cursor(i,j,k:intptr);
  309. begin
  310.     a^:=9;
  311.     b^:=i^;
  312.     c^:=j^;
  313.     d^:=k^;
  314.     mouse(a,b,c,d);
  315. end;
  316.  
  317.  
  318. { set_subroutine ----------------------------------------------    }
  319. {                                }
  320. {    FORTRAN:    call set_subroutine(i,j,k)          }
  321. {    C:        set_subroutine(&i,&j,&k);           }
  322. {                                }
  323. {  set_subroutine takes three arguments, both integers.  The     }
  324. {  first identifies an event, the second is the value of the     }
  325. {  offset of the entry point into the real mode routine, and    }
  326. {  the third is the value of the real mode segment in which    }
  327. {  the subroutine resides.                    }
  328. {  This procedure is much like set_graphics_cursor (above)     }
  329. {  in the steps that need to be followed to load it into real    }
  330. {  memory.                            }
  331. {                                }
  332. { -------------------------------------------------------------    }
  333. procedure set_subroutine(i,j,k:intptr);
  334. begin
  335.     a^:=12;
  336.     b^:=k^;
  337.     c^:=i^;
  338.     d^:=j^;
  339.     mouse(a,b,c,d);
  340. end;
  341.