!******************************************************************!
!                                                                  !
!                             Roderick Widdowson  Jun 83           !
!         Mouse controlling specs.   V1.00                         !
!                                                                  !
! The mouse is just polled when needed. However in order to make   !
! any code compatable in stead of using a record (which is the     !
! desired interface to the user, a map is used. This may be thus   !
! used as a record (although writing to it is not sensible).       !
! In this manner all the updating may be done on each call of the  !
! record map. This leaves only the actual record to which the map  !
! should point. 2 ideas, 1 is to have an %own record but this is   !
! dangerous since I dont know what the compiler does. The other is !
! to have an external record which must not be %spec ed            !
!******************************************************************!

%record %format mouse fm (%integer X, Y, %byte buttons )

%own %integer offset X = 0
%own %integer offset Y = 0

%external %routine wait for (%byte %integer butt)
   ! This will wait until the appropraite buttons are depressed
   ! Will be replaced in version 2 (or 3) by a suspend order.
   %cycle;   %repeat %until butt & 7 = Mouse buttons & 7
%end

%external %routine coordinates (%integer X,Y,buttons)
   wait for (buttons)
   Mouse X = 0
   Mouse Y = 0
   offset X = X
   offset Y = Y
%end    

%external %record (mouse fm)  %map mouse
   %own %record (mouse fm) ret 
   ret_X = (Mouse X // 2 ) + offset X
   ret_Y = (Mouse Y // 2 ) + offset Y
   ret_buttons = Mouse buttons & 7
   %result == ret
%end

%endoffile
