Optron #14
03 июля 1998

Kempston Mouse-2 - Determine whether the mouse. Handling buttons and coordinates.

<b>Kempston Mouse-2</b> - Determine whether the mouse. Handling buttons and coordinates.

         Kempston mouse (part II)



(C) Rasp


  The last time you, dear readers,
acquainted with the interface circuit
Kempston mouse.

  Today I'll tell you what is the mouse for a programmer - how 
to determine its availability, how to work with buttons and 
coordinates. 



        Determination of mouse



  Before the software to process the signals coming from the 
mouse, you must determine whether there is a mouse at all. 
There is two ways to determine whether the mouse - with

using the buttons and ports on ports
coordinates.

  Before we dive into coding, I
I want to make one remark. If the
computer implemented port # FF (port attributes), it can 
interfere with the mouse, so it is recommended to handle it 
ports in those moments when in port attribute value is # FF. 
This occurs when the display controller constructs curb. Very 
useful time when building the upper edge -

approximately 12-14 thousand cycles after the arrival
INT'a. This time is sufficient for
processing coordinates and mouse buttons, a survey
keyboard and play music.

  So how do you determine if a mouse or
No?

  The first way. In many programs, I
seen such an option of determining whether there
mouse: reads the value from the port of one
coordinates (does not matter which) and compared
with the value of the second coordinate, if they
not equal, then the mouse is. Software is
can be expressed as:


      EI

      HALT; forward to

                   ; Constructing curb

      LD BC, # FBDF

      IN L, (C); read the X coordinate

      LD B, # FF

      IN A, (C); compare with Y

      CP L

      JR Z, no, and if equal, then the mouse

                   Nay
there .....


  In this way, in my opinion, there is
One drawback: if you only included
computer and not move the mouse, then the counters will be read 
the same values ​​- # FF, and the program will think that mouse 
no. You should also not exclude the possibility that in the 
process for counters are not set to coordinate. The probability 
of such a coincidence - 1 / 256 (Why so much - guess yourself

;))

  The second way is also found frequently
as the first. Its essence is this: read the value from the port 
of buttons and if there is not zero, it is considered that the 
mouse is. Here, however, the question may arise: if

what a port is not implemented, then it
will be read # FF, and then, if there is no mouse interface, 
the program will think that he is still there. But no. In this 
case, will read a value from the joystick ports - # 00, since 
decryption and mouse and a joystick, in the absence of a mouse, 
using A5 bit address bus of the processor. A if there is no 
joystick, then let the program thinks that the mouse is - it 
does not stop! Because the values ​​at the ports of the mouse 
does not change. Much worse, when the program

thinks there is a mouse when it is in fact
does not exist. At the same time begin to take
values ​​from the joystick ports for the values ​​of
any port mouse. Begin false positives FIRE button and the poor
nick has no choice but to push
RESET.


      EI; think everything is

      HALT; clear

      LD BC, # FADF

      IN A, (C); read port buttons

      OR A; and check

      JR NZ, no
there .....



             Processing buttons



  Port of buttons is quite simple - # FADF, and its
layout is even easier:


  D0 - left button

  D1 - right button

  D2 - middle button


  If the discharge is set to "0", the button
pressed.

  There is one more remark. Still
there is no consensus about how cocoa bits belong to the left 
button, and what - right. While some are just such a layout, 
and others - quite the opposite: D0 - right button, D1 - left. 
Why is it so turned out I did not know. But this

things very complicated life of nick: in one
Playing everything is done right, and in
other - the left - awkward! In addition,
user can be left-handed.

  That such problems do not occur, intelligent
uncle invented such a thing as autoconfiguration mouse buttons. 
The essence is simple: the first button is pressed the button 
of choice, and another (opposite) - the cancel button. And here 
is an example implementation: 

; After level D4-D6 register C
, Will contain information about
; What buttons are pressed ("1" - Button
, Pressed
; D6 - middle button
; D5 - Cancel button
; D4 - selection button


      LD A, # FA; read port

      IN A, (# DF); buttons

      CPL; proinvertirovali

      AND 0
MICEP EQU $ -1

, In determining whether the mouse here
; Substituted # 00 if no mouse, and # FF,
And if there is


      LD B, A

      AND 4; select category

                   ; Middle button

      ADD A, A; pushes it into D6

      ADD A, A

      ADD A, A

      ADD A, A

      LD C, A

      JR CBUT; the transition to a procedure
BUT_S EQU $ -1; autoconfiguration

; Configuration procedure is invoked only
And in that case, if the button is not
, Pressed
And define a button, procedure changes
; Bias for transition team


      LD A, B

      AND 0; here substituted
M_BUT EQU $ -1; mask selection

                   ; Discharge buttons

      CP 1, fill in the register

      CCF; A relevant

      SBC A, A; discharge

      AND # 10; select D4

      OR C

      LD C, A; put in C

      LD A, B; proceed similarly with

      AND 0, the cancel button
S_BUT EQU $ -1

      CP 1

      CCF

      SBC A, A

      AND # 20; in D5

      OR C

      LD C, A
NO_BUT

      RET; output

; Procedure autoconfig buttons

CBUT

      LD A, B

      AND 3 buttons are not pressed?

      JR Z, NO_BUT; if so, output

      RRA

      JR NC, $ +4; discharge corresponding

      LD A, 0; button is pressed will

      RLA; mask to select

      LD (M_BUT), A; main buttons

      XOR 3, invert the mask

      LD (S_BUT), A; mask cancel button

      XOR A; change shift

      LD (BUT_S), A; team transition

      JR BUT_S +1; Returns



           Processing coordinates



  The presence of two independent eight-
Counters - the greatest advantage
Kempston mouse over any other. Counters at all times consider 
the coordinates and we can interrogate them at any time (At 
least ten times during an interrupt, at least once in second). 
In processing the coordinates proceed as follows: at the start 
of the driver stored coordinates mouse and for each access to 
it is the difference between old and new values, which, in 
fact, will be offset cursor on the screen, just a few

counter values ​​are substituted in place
old and the cycle can be repeated.

  Port addresses the origin, as I mentioned, the following: # 
FBDF - the X, # FFDF - coordinate Y.




                Conclusion



  Well, that's all. If you take for writing a driver, then 
please do not forget about two important things: to check if 
the mouse buttons and autoconfiguration. And if you have any 
questions, please call: (0322) 67-60-45, Vladimir.







Other articles:

Kempston Mouse-2 - Determine whether the mouse. Handling buttons and coordinates.

Iron - Graphic Modes.

Iron - Maxi-perverted "in- bambasy "PowerZX.

Contest - your tricks and tips that may be useful not only in the Spectrum, but also in the household.

Lit. Page - Beginning of the End. Poems: Debit and Credit.

Advertising - Advertisements and announcements ...

four kilobytes - The new name of the group - Steel Falcons.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Announcement - What will happen to the world in the Spectrum blizzhayshee time: Enlight 1997, Spectrofon 22-23, all sorts of party games, magazines, demo from Zaporozhye and Chelyabinsk.
Club - the Spectrum in an age of high technology.
Feedback - contact the publisher.

В этот день...   2 May