home *** CD-ROM | disk | FTP | other *** search
- \ MOUSE.SEQ Mouse driver software, requires MOUSE.SYS by Ray Isaac
-
- comment:
-
- Mouse support for Forth. Adding mouse support to a program is if you
- have looked at this file not a trivial problem. The technique chosen here
- is to install a driver at the level of KEY? which monitors the movement of
- the mouse and turns on its cursor if it is moved. A press of a key restores
- the normal terminal cursor.
-
- In this system only the outside buttons of a three button mouse are used.
- The left button is used to select or trigger an operation, while the right
- button always is equivelant to the ESC key, which will usually cancel an
- operation.
-
- This generic mouse driver is enhanced at each application level that wants
- to use the mouse with an application specific button driver. The application
- level button drivers are installed into the defered word DOBUTTON. The
- button driver is expected to interpret the button presses, and perform the
- appropriate function. Several button drivers are already present in F-PC,
- which can be used as examples for how to make button drivers. See the
- files MENUBUT.SEQ, SEDBUT.SEQ, SEDCHARS.SEQ and LEDIT.SEQ for further
- information.
-
- The mouse is automatically initialized at program boot time, if you want
- to disable or re-enable the mouse after program boot time, you can use the
- following words:
-
- HIDE.MOUSE disables mouse operation
- SHOW.MOUSE enables mouse operation if a mosue driver present
-
- This code was originally written by Ray Isaac at Calos Systems.
-
- This code has been extensively modified and extended by Tom Zimmer at
- Maxtor.
-
- comment;
-
- prefix \ use prefix assembler syntax
-
- decimal
-
- only forth also hidden definitions also
-
-
- 0 value havemouse \ was a good mouse driver present at boot?
- 0 value mousechar \ character to return from mouse key press
- 0 value mousewasdown \ was mouse button down last time we saw it
- 0 value badmouse \ non-zero if bad driver present
- 0 value lastx \ previous location of mouse X and Y
- 0 value lasty
- 0 value last-cursor \ cursor shape before we moved the mouse
- 0 value fixcur? \ do we need to reset cursor position & size?
-
- \ defer dobutton ' noop is dobutton \ moved to UTILS
-
- code hide.ms ( -- ) \ turn OFF the hardware mouse cursor
- mov ax, # 2 \ we are not using hardware cursor
- int 51
- next
- end-code
-
- code init.mouse ( --- ) \ initialize mouse if good driver present
- mov ax, # 0 \ mouse driver init.mouse function code
- int 51 \ call mouse driver
- cmp ax, # 0
- 0= if mov ' badmouse >body # true word
- next
- then
- mov ax, # 14 \ function code to disable light pen
- \ emulation. mouse driver turned
- \ this on as default in
- \ function 1, done in init.mouse1
- int 51 \ call mouse driver.
- mov ' mouseflg >body # true word
- mov ' havemouse >body # true word
- next
- end-code
-
- code getmous ( --dx dy buttons.status ) \ get mouse information
- mov ax, # 03
- int 51
- push cx
- push dx
- and bx, # 3
- push bx
- next
- end-code
-
- : nomouse ( --- ) \ mark us as not having a mouse
- off> mouseflg
- off> havemouse ;
-
- code mouse.scale ( --- ) \ adjust mouse scaling for display
- mov cx, # 0
- mov dx, ' rows >body
- shl dx, # 1
- shl dx, # 1
- shl dx, # 1
- mov ax, # 08 \ set max Y
- int 51
- mov cx, # 0
- mov dx, ' cols >body
- shl dx, # 1
- shl dx, # 1
- shl dx, # 1
- mov ax, # 07 \ set max x
- int 51
- next
- end-code
-
- forth definitions
-
- : mousexy ( --- x1/y1 ) \ x=0-79, y=0-24
- mouseflg 0= if 0 0 exit then
- getmous
- drop u8/ rows 1- min
- swap u8/ cols 1- min swap ;
-
- : mousebutton ( --- n1 ) \ n1=0,1,2,4 or a combination
- mouseflg 0= if false exit then
- getmous nip nip 3 and ;
-
- : hide.mouse ( --- ) \ turn off the mouse cursor
- off> mouseflg ;
-
- : show.mouse ( --- ) \ enable display of mouse cursor
- havemouse =: mouseflg ;
-
- : ?set-cursor ( --- )
- fixcur? 0=
- if get-cursor =: last-cursor
- big-cursor
- cursor-on
- on> fixcur?
- then ;
-
- : ?fix-cursor ( --- )
- fixcur?
- if #out @ #line @ at
- last-cursor set-cursor
- off> fixcur?
- then ;
-
- : track-mouse ( --- ) \ follow the mouse on screen
- mouseflg 0=
- if ?fix-cursor exit
- then
- mousexy lastx lasty d- or \ has mouse moved?
- if mousexy 2dup =: lasty =: lastx
- ibm-at
- ?set-cursor
- then ;
-
- hidden definitions
-
- : defbutton ( --- ) \ default button handler
- mousebutton
- case
- 2 of 27 ( ESC ) =: mousechar endof
- 1 of 13 ( Enter ) =: mousechar ?fix-cursor endof
- drop
- endcase ;
-
- : initmouse ( --- ) \ initialize the mose if present
- nomouse
- 0 204 @L 0<> \ interupt vector may be 51 ok
- \ if it is <>0
- if init.mouse
- badmouse ?exit
- hide.ms \ we won't use hardware mouse cursor
- mouse.scale \ adjust mouse scaling to screen
- get-cursor =: last-cursor
- off> mousechar
- off> mousewasdown
- ['] defbutton is dobutton \ default button
- mousexy =: lasty =: lastx
- ?fix-cursor
- then ; \ handler
-
- initmouse \ initialize the mouse now so we can test it
-
- : ?mouseinit ( --- ) \ initialize mouse if present at boot time
- initmouse
- defers initstuff ;
-
- ' ?mouseinit is initstuff
-
- forth definitions
-
- : mousekey? ( --- f1 ) \ new mouseable version of KEY?
- defers key?
- dup 0=
- if mouseflg 0= ?exit
- mousewasdown
- if fixcur?
- if cursor-on
- then mousexy ibm-at
- begin mousebutton 0=
- track-mouse
- until
- then off> mousewasdown
- off> mousechar
- track-mouse
- mousebutton \ if button pressed then
- if dobutton \ handle it
- on> mousewasdown
- then
- else ?fix-cursor
- then ;
-
- ' mousekey? is key?
-
- : mousekey ( -- CHAR ) \ allow mouse press to return key
- begin pause
- key?
- mousechar or
- until mousechar ?dup
- if off> mousechar
- on> mousewasdown
- ?fix-cursor
- else bioskey dup 127 and 0=
- if flip dup 3 =
- if drop 0
- else 127 and 128 or
- then
- else 255 and
- then
- then keyfilter ;
-
- ' mousekey is key
-
- only forth also definitions
-
-