home *** CD-ROM | disk | FTP | other *** search
- { ------------------------------------------------------------- }
- { }
- { MOUSE.P }
- { copyright (c) 1989, Microway, Inc }
- { }
- { --------------------- MOUSE FUNCTIONS ----------------------- }
- { }
- { function init_mouse:integer; }
- { procedure show_mouse_cursor; }
- { procedure show_mouse_cursor; }
- { procedure get_mouse(i,j,k:intptr); }
- { procedure set_mouse(i,j:intptr); }
- { procedure get_press(i,j,k,l:intptr); }
- { procedure get_release(i,j,k,l:intptr); }
- { procedure mouse_viewport(i,j,k,l:intptr); }
- { procedure read_motion(i,j:intptr); }
- { procedure set_mp_ratio(i,j:intptr); }
- { procedure set_mouse__cursor(i,j,k:intptr); }
- { procedure set_subroutine(i,j,k:intptr); }
- { }
- { ------------------------------------------------------------- }
-
- type
- intptr = ^integer;
-
- var
- a,b,c,d: intptr;
-
- function calloc(i,j:integer): intptr; external;
-
- { mouse ------------------------------------------------------- }
- { }
- { FORTRAN: call mouse(i,j,k,l) }
- { C: mouse(&i,&j,&k,&l); }
- { }
- { mouse takes four arguments, all pointers to integers. }
- { These are as defined in mouse documentation, for the }
- { most part. In ordinary circumstances, the values pointed }
- { at by the arguments are placed (eventually) in the ax, bx, }
- { cx, and dx registers, and a real mode INT 33h issued. }
- { Of course, all this is done via Phar Lap service function }
- { 2511h of int 21h, issue real mode interrupt with registers }
- { specified, so the Assembly code is more complicated than }
- { the description makes it sound. }
- { }
- { There are special cases, however, and these allow for }
- { pointers to real mode arrays and/or routines to be passed }
- { and enterpreted correctly. They are as follows: }
- { }
- { 1. If the first argument points at a 9 or 18 (decimal), }
- { the fourth argument is placed into the ds and es }
- { registers, and dx is set to 0. }
- { }
- { 2. If the first argument points at a 12, the fourth }
- { argument is placed into ds and es and the second is }
- { placed in dx. }
- { }
- { ------------------------------------------------------------- }
- procedure mouse(i,j,k,l:intptr); external;
-
-
- { realbuf ----------------------------------------------------- }
- { }
- { FORTRAN: i=realbuf(i) }
- { C: i=realbuf(&i); }
- { }
- { realbuf requests allocation of DOS memory of the number of }
- { bytes indicated by its argument. In the event of success, }
- { it returns the address of the allocated memory as a real }
- { mode segment value. This is a 32 bit value, with the top }
- { 16 bits zeroed out (i.e., in the range for 16 bit values. }
- { In the event of failure, it returns -1 (32 bits). The }
- { value at the argument variable has been replaced with the }
- { return value, so it can also be treated as a procedure. }
- { }
- { ------------------------------------------------------------- }
- procedure realbuf(i:intptr); external;
-
-
- { init_mouse -------------------------------------------------- }
- { }
- { FORTRAN: i=init_mouse }
- { C: i=init_mouse(); }
- { }
- { returns a 0 for no mouse, a 2 for a Microsoft Mouse, }
- { or a 3 for a Mouse Systems mouse. Initializes interface }
- { variables, if this has not been done already. }
- { }
- { ------------------------------------------------------------- }
- function init_mouse: integer;
- begin
- if a=nil then begin { We use calloc instead of new }
- a:=calloc(1,4); { becuase we want to link this }
- b:=calloc(1,4); { to non-Pascal code. All NDP }
- c:=calloc(1,4); { languages have C functions }
- d:=calloc(1,4); { in their libraries. }
- end;
- a^:=0;
- mouse(a,b,c,d);
- if a^=-1 then begin
- init_mouse:=b^;
- end else begin
- init_mouse:=0;
- end;
- end;
-
-
- { show_mouse_cursor ------------------------------------------- }
- { }
- { FORTRAN: call show_mouse_cursor }
- { C: show_mouse_cursor(); }
- { }
- { Displays the mouse cursor - no arguments }
- { }
- { ------------------------------------------------------------- }
- procedure show_mouse_cursor;
- begin
- a^:=1;
- mouse(a,b,c,d);
- end;
-
-
- { hide_mouse_cursor ------------------------------------------- }
- { }
- { FORTRAN: call hide_mouse_cursor }
- { C: hide_mouse_cursor(); }
- { }
- { Hides the mouse cursor - no arguments }
- { }
- { ------------------------------------------------------------- }
- procedure hide_mouse_cursor;
- begin
- a^:=2;
- mouse(a,b,c,d);
- end;
-
-
- { get_mouse --------------------------------------------------- }
- { }
- { FORTRAN: call get_mouse(i,j,k) }
- { C: get_mouse(&i,&j,&k); }
- { }
- { Get mouse data. This procedure takes three arguments, each }
- { a pointer to an integer. They are not initialized by the }
- { calling program. The first is set to the value of the }
- { button press, 0=no button, 1=left, 2=right, 4=middle }
- { The second argument is set to the horizontal position. }
- { The third is set to the vertical position. }
- { }
- { ------------------------------------------------------------- }
- procedure get_mouse(i,j,k: intptr);
- begin
- a^:=3;
- mouse(a,i,j,k);
- end;
-
-
- { set_mouse --------------------------------------------------- }
- { }
- { FORTRAN: call set_mouse(i,j) }
- { C: set_mouse(&i,&j); }
- { }
- { set_mouse has two arguments, both pointers to integers. }
- { The mouse coordinates are set to the values pointed }
- { at by the arguments. The first is the horizontal position, }
- { and the second is the vertical. }
- { }
- { ------------------------------------------------------------- }
- procedure set_mouse(i,j: intptr);
- begin
- a^:=4;
- mouse(a,b,i,j);
- end;
-
-
- { get_press --------------------------------------------------- }
- { }
- { FORTRAN: call get_press(i,j,k) }
- { C: get_press(&i,&j,&k); }
- { }
- { There are four arguments, all pointers to integers. }
- { input: }
- { i^=button (1 for left, 2 for right, 4 for middle }
- { output: }
- { j^=count of button presses since last check }
- { k^=column of last press }
- { l^=row of last press }
- { }
- { ------------------------------------------------------------- }
- procedure get_press(i,j,k,l:intptr);
- begin
- j^:=i^;
- i^:=5;
- mouse(i,j,k,l);
- end;
-
-
- { get_release ------------------------------------------------- }
- { }
- { FORTRAN: call get_release(i,j,k) }
- { C: get_release(&i,&j,&k); }
- { }
- { Four arguments are all pointers to integers. }
- { input: }
- { i^=button (1 for left, 2 for right, 4 for middle }
- { output: }
- { j^=count of button releases since last check }
- { k^=column of last release }
- { l^=row of last release }
- { }
- { ------------------------------------------------------------- }
- procedure get_release(i,j,k,l:intptr);
- begin
- j^:=i^;
- i^:=6;
- mouse(i,j,k,l);
- end;
-
-
- { mouse_viewport ---------------------------------------------- }
- { }
- { FORTRAN: call mouse_viewport(i,j,k,l) }
- { C: mouse_viewport(&i,&j,&k,&l); }
- { }
- { mouse_viewport has four arguments, all pointers to integers. }
- { input: }
- { i=min horizontal position }
- { j=max horizontal position }
- { k=min vertical position }
- { l=max vertical position }
- { output: }
- { no defined return values }
- { }
- { ------------------------------------------------------------- }
- procedure mouse_viewport(i,j,k,l:intptr);
- begin
- a^:=7;
- mouse(a,b,i,j);
- a^:=8;
- mouse(a,b,k,l);
- end;
-
-
- { read_motion ------------------------------------------------- }
- { }
- { FORTRAN: call read_motion(i,j) }
- { C: read_motion(&i,&j); }
- { }
- { Two arguments are both pointers to integers, neither }
- { needs any initial value. }
- { On return, the first argument points at the sum of all }
- { horizontal motion, the second at vertical. Values are in }
- { 32-bit integer format, but in 16-bit signed integer range. }
- { }
- { ------------------------------------------------------------- }
- procedure read_motion(i,j:intptr);
- begin
- a^:=11;
- i^:=0;
- j^:=0;
- mouse(a,b,i,j);
- if i^>32767 then i^:=i^-65536;
- if j^>32767 then j^:=j^-65536;
- end;
-
-
- { set_mp_ratio ------------------------------------------------ }
- { }
- { FORTRAN: call set_mp_ratio(i,j) }
- { C: set_mp_ratio(&i,&j) }
- { }
- { Two arguments are pointers to integers. The first points }
- { a value for the ration for horizontal movement, and the }
- { second at the value for vertical. Both are set to 8 }
- { pixels. }
- { }
- { ------------------------------------------------------------- }
- procedure set_mp_ratio(i,j:intptr);
- begin
- a^:=15;
- mouse(a,b,i,j);
- end;
-
-
- { set_mouse_cursor -------------------------------------------- }
- { }
- { FORTRAN: call set_mouse_cursor(i,j,k) }
- { C: set_mouse_cursor(&i,&j,&k); }
- { }
- { Three arguments are all integers. The first and second are }
- { the coordinates of the so-called hot spot, the point in the }
- { array representing the actual location of the mouse }
- { cursor (this can be outside the actual array, since }
- { values can range from -16 to 16, only 1 to 16 being the }
- { array area). The third integer is the value of a real }
- { mode segment address at which the array is to be found. }
- { Using this procedure requires the following: }
- { }
- { 1. Real memory must be reserved (e.g. through }
- { the -maxreal command line switch). }
- { 2. Real memory must be allocated via realbuf or }
- { a call to Phar Lap. }
- { 3. The array is be initialized. }
- { 4. The array is moved to real memory by blk_bm. }
- { 5. The call is made to set_mouse_cursor. }
- { }
- { ------------------------------------------------------------- }
- procedure set_mouse_cursor(i,j,k:intptr);
- begin
- a^:=9;
- b^:=i^;
- c^:=j^;
- d^:=k^;
- mouse(a,b,c,d);
- end;
-
-
- { set_subroutine ---------------------------------------------- }
- { }
- { FORTRAN: call set_subroutine(i,j,k) }
- { C: set_subroutine(&i,&j,&k); }
- { }
- { set_subroutine takes three arguments, both integers. The }
- { first identifies an event, the second is the value of the }
- { offset of the entry point into the real mode routine, and }
- { the third is the value of the real mode segment in which }
- { the subroutine resides. }
- { This procedure is much like set_graphics_cursor (above) }
- { in the steps that need to be followed to load it into real }
- { memory. }
- { }
- { ------------------------------------------------------------- }
- procedure set_subroutine(i,j,k:intptr);
- begin
- a^:=12;
- b^:=k^;
- c^:=i^;
- d^:=j^;
- mouse(a,b,c,d);
- end;