Kempston mouse interface
      ----------------------------

  There was a lot of different opinions on how to connect mouse to your little
 Speccy ( or Speccy clone ). It were  advertising  style matherials from those
 who re-build original Kempston Mouse Interface  on the russian  IC's. I don't
 want to argue with any of them, all I want its offer to those who know how to
 use soldering iron in his hands build this add-on by theirselves.
  In  the beginning we must answer one  question - why Kempston Mouse ? We all
 know that some people can solder up bus mouse right to the AY ( or YM ) sound
 chip or to the Kempston joystick port. So why Kempston Mouse better ? Well I
 think that any attempts to solder up mouse to the joystick ports it is not so
 clever idea. Mouse has one great difference from the joystick - when you move
 mouse faster the  mouse pointer on  the screen  must move faster too. This is
 makes mouse  usage much  easier and intuitive. But joystick  can react to the
 speed of movement, so pointer moved with same speed all the time. Thus if you
 connect mouse to the joystick port  you're loosing mouse possibility to react
 to movement  speed! There  is no any difference how fast you move your  mouse
 over the table surface - pointer will travel the  screen with same  speed and
 this is really annoying isn't it ? Yes  the AY mouse  scheme  don't have this
 disadvantage but check out how much programs have support for this very young
 interface ? Not so many! And again - why we should  use Kempston mouse ? Hey!
 Answer is very easy - because it was standard and has support in original so-
 ftware ( I mean that software which was made in UK and other coutries ). Load
 Art-Studio and you'll find Kempston Mouse interface there! Load great Carrier
 Command and you'll find Kempston Mouse support there too. Many other programs
 has support or will have it soon. Even Vyacheslav Mednonogov added support to
 his UFO I, UFO II and Black Raven I ( and Black  Raven II which he  promissed
 release soon ) because he was  very impressed after testing that little piece
 of hardware. So why choose something other and wait untill someone make some-
 thing what will have support for this 'device' ? Choose  great interface with
 great advantages right now! Here is small part of software which  has support
 for Kempston Mouse Interface:

  System utilities:

    F Commander v4.01
    Instrument v2.01
    DCU v2.32
    FUT v2.01
    Zx-Word v2.5m
    ZxZip and ZxUnZip v1.02

  Games:

    Hero Quest I and II
    Dragon Spirit
    Space Crusade
    A New Whole Ball Game
    The A Team 1 and 2
    Operation Wolf
    Operation Thunderbolt
    World Cup Challenge
    Gunsmoke
    R-Type
    Gemini Wing
    1943 The Battle Begin
    Zombi
    Armagedon Man

  And a lot more! Also now every electronic magazine has  support for Kempston
 Mouse Interface. Number  of  programs with Kempston Mouse  support  increased
 each week! You  still  don't understand  why you need it ? So do find someone
 who already own this interface  and  just try  paint something in  Art-Studio
 with mouse, and  I believe you'll never ever want to paint something  without
 mouse anymore!
   Author of this scheme was Michael Kondratyev, scheme was made after reverse
 ingineering of Kempston Mouse drivers from Art-Studio and Artist 2/1 graphics
 editors. The very  first version has 11 IC in it because  author used easy to
 find IC's. Some time this scheme was secret commertial product and copyrights
 were owned by  Sergey Zonov ( the man after ugly ZS-Scorpion 256 clone ). One
 year ago he allowed  spreading of this scheme and scheme was sent to the FIDO
 net.
  Usualy people  choose passive mouse from Poisk computer ( that grey one ) to
 be used with this  interface, that mouse has  very small price and work well.
 But if you don't have  such a mouse  around you can use any passive mouse. In
 case you can't find  any passive mouse  you can use  normal IBM PC compatible
 mouse but you'll  need make some simple fixes in  mouse scheme. For more info
 on mouse fixing please look at  scheme comments. Well please take pen or turn
 your printer on now and carefuly copy this scheme:

==============================================================================

            DD1              DD5
        5---T--T- 6     2---T--T-18 D0
    -----oCaCT0+--------+D1|>1+-----
Xb -+- 15+--+   11     4     16 D1
--T------/C   1+--------+D2  2+-----
Xa    10     14     6     14 D2
---T-----+U/D  2+--------+D3  3+-----
      9+--+    2     8     12 D3
   ----+R   3+--------+D4  4+-----
     1           11      9 D4
   +---+S      ------+D5  5+-----
  -+- 4          13      7 D5
     --+0      -----+D6  6+-----
     12         15      5 D6
     --+1      ----+D7  7+-----
     13        17      3 D7
     --+2      ---+D8  8+-----
      3    +-+ 719+--+        
     --+3   Co---oE2        
       L--+--+-- 1          
    --------------+-oE1        
         DD2      L--+--+--     
     5---T--T- 6 /XCS          
    L--oCaCT0+---L----           
     15+--+   11                 
  L------/C   1+----                
      10     14                  
   L-----+U/D  2+-----                
        9+--+    2                   
     ----+R   3+------                
       1                           
     +---+S                          
    -+- 4                           
       --+0                          
       12                           
       --+1                          
       13                           
       --+2                          
        3    +-+ 7                    
       --+3   Co--                    
         L--+--+--                      
                                        
            DD3              DD6        
        5---T--T- 6     2---T--T-18 D0
    -----oCaCT0+--------+D1|>1+-----
Ya -+- 15+--+   11     4     16 D1
--T------/C   1+--------+D2  2+-----
Yb    10     14     6     14 D2
---T-----+U/D  2+--------+D3  3+-----
      9+--+    2     8     12 D3
   ----+R   3+--------+D4  4+-----
     1           11      9 D4
   +---+S      ------+D5  5+-----
  -+- 4          13      7 D5
     --+0      -----+D6  6+-----
     12         15      5 D6
     --+1      ----+D7  7+-----
     13        17      3 D7
     --+2      ---+D8  8+-----
      3    +-+ 719+--+        
     --+3   Co---oE2        
       L--+--+-- 1          
   ---------------+-oE1        
         DD4      L--+--+--     
     5---T--T- 6  /YCS         
   L---oCaCT0+---L------         
     15+--+   11                 
  L------/C   1+---- ==============-
      10     14   
   L-----+U/D  2+----- 
        9+--+    2    
     ----+R   3+------ 
       1            
     +---+S           
    -+- 4            
       --+0           
       12            
       --+1           
       13            
       --+2           
        3    +-+ 7     
       --+3   Co--     
         L--+--+--       
                    ====-
          DD7.2             DD8
LEFTB   5--T--6  D1A10 1--T--T-15
---------+D|>+-----+-----+1DC0o--
        4        A8  2    14
      ---oE       -----+2  1o--
        L-+---     A7  3    13
         DD7.3     -----+4  2o--
RIGHB  9--T--8  D0/RD 5+-+   12
---------+D|>+-----+-----o&  3o--
      10        A0  6    11 /BCS
      +--oE       -----+   4o-------
        L-+---         4    10
         DD7.4       ---oS  5o--
MIDLB 12--T--11 D2         9 /XCS
---------+D|>+-----       6o-------
      13                 7 /YCS
      +--oE              7o-------
        L-+---         L-+--+--
                     L------------
         /BCS              DD7.1  
      L--------     /IORQ 2--T--3 
                    -------+D|>+---
DD1..DD4 - K561IE11 A5    1   
DD5, DD6 - K555AP5  -------oE  
DD7      - K155LP8         L-+---
DD8      - K555ID7

(c) 1994 Michael Kondratyev

DD1..DD4 - 4029 (also LS191, but has different pinout)
DD5..DD6 - LS244
DD7      - LS125
DD8      - LS138

(C) 2000 Jarek Adamski

==============================================================================

   Comments:

  Bold line it is Speccy bus;
  Xa, Xb, Ya, Yb, RIGHTB, MIDLB, LEFTB, +5V, GND signals must be connected to
   mouse;
  This scheme shows how to connect it to passive mouse used with Poisk compu-
   ter. If you think to use any other mouse ( e.g. from PC ) you must take Xa,
   Xb, Ya, Yb signals from optopairs after line of transistor-Schmidt trigger;
  In computer you must have 0x00DF port blocked;
  You can use PLM chip like 556RT4 ( RT11 ) instead of decoder IC's remaining
   output pin can be used to blocke 0x00DF port in computer;

==============================================================================

  Now lets talk about how to make support for Kempston Mouse Interface in your
 own programs. Don't expect something difficult to understanding, because this
 all easy and intuitive. You've got three port addressed:

   0xFADF
   0xFBDF
   0xFFDF

  Each port is 8-bits or one byte wide.

   0xFADF - Thee bits of this port gives you mouse buttons state:

    1 - Left button state
    0 - Right button state
    2 - Middle button state

  If nothing pressed then all bits in this port should be equal to '1'. If any
 button was  pressed then  corresponding bit will  be resett to '0'. Following
 old tradition left button used as Fire/Select and right as Stop/Cancel. The
 middle button used for additional functions.

  NOTE: Please bear in mind that not all users have three button mice, someone
        can have two button mouse only, so  if you think use  middle button do
        not forget double these functions on the keyboard too!

    0xFBDF - X coordinate
    0xFFDF - Y coordinate

  Coordinates are changed cyclicaly i.e. when you reach 255 X coordinate value
 and still move mouse to  the right side  then X will be changed to 0 and will
 be increased to 255 again. Picture is same if you move mouse to the left hand
 side but X value  will be decresed  cyclicaly - 255 to 0. I think this  small
 piece of ASCII art can help you imagine what do I'm talking about:

   y^.
    .
    .
    2
    1
    012...
    +---------->
              X

  Thus you must read ports value, find the difference between copy of previous
 value and find out where to mouse was moved. If you need very precive moveme-
 nt you have to write your own 'intellectual' driver which will check how long
 use moves mouse to  one direction and  change stepping rate to 2, 3, 4, 5 and
 more points. Novadays appeared very nice thing - self configurable driver. It
 waits  untill you  first time press any mouse  button and uses this button as
 Fire/Select. This can be useful if there one  button not working on the mouse
 or there is left-handed user. You can check out how does just built interface
 work right from the BASIC with PRINT IN from mouse ports:


  64479 - X ; 65503 - Y ; Values in this ports must change cyclicaly
  64423 - Buttons, one of thee lower bits should reset when you press one of
          mouse buttons.

  Well and now assembler sourse code of the Kempston Mouse driver!

 ----------------------------------------------------------------------------

;MOUSE DRIVER WITH FIRE BUTTON AUTOCONFIG
;(C) Andrey Rachkin'95

        JR      MDRV

DIRECTZ DEFB    0 ;FIRE
        DEFB    0 ;UP
        DEFB    0 ;DOWN
        DEFB    0 ;RIGHT
        DEFB    0 ;LEFT
        DEFB    0 ;CANCEL
MCOORD  DEFW    0 ;LAST CURSOR COORDS IN PIXELZ
MPORTS  DEFW    0 ;LAST READED MAUSY COORDS

NONDEF  AND     3 ;HERE COMEZ BUTTONZ CONTROL IF FIRE BUTON NOT DEFINED
        JR      Z,MDRV4 ;IF NONE BUTTON PRESSED
        CP      1
        JR      Z,NONDEF_
        XOR     A
        LD      (MDRV3+2),A
        LD      A,5
        LD      (MDRV2+2),A
NONDEF_ LD      HL,0
        LD      (MDRV1),HL
        POP     IX
; ***** MAIN PROC OF MOUSEDRIVER *****
MDRV    PUSH    IX
        LD      HL,DIRECTZ
        PUSH    HL
        POP     IX
        XOR     A
        LD      (HL),A ;CLEARING
        INC     HL     ;OF
        LD      (HL),A ;DIRECTZ
        INC     HL     ;BUFER
        LD      (HL),A
        INC     HL
        LD      (HL),A
        INC     HL
        LD      (HL),A
        INC     HL
        LD      (HL),A
        INC     HL
        LD      BC,#FADF ;BUTTONZ CONTROL
        IN      A,(C)    ;READING FROM BUTTONS PORT
        CPL
MDRV1   JR      NONDEF ;JR UNTIL FIRE BUTTON NOT DEFINED
        RRA
MDRV2   RL      (IX+0) ;FIRE
        RRA
MDRV3   RL      (IX+5) ;CANCEL
; ***** COORDS CONTROL *****
MDRV4   LD      HL,(MCOORD) ;FORM LAST CURSOR COORDS
        LD      DE,(MPORTS) ;FROM LAST READED MOUSE COORDS
        LD      BC,#FBDF
        IN      A,(C) ;READING FROM PORT X-COORD (0-#FF)
        LD      (MPORTS),A
        SUB     E
        JR      Z,MDRV9
        JP      P,MDRV6
        LD      (IX+4),1 ;MOVE LEFT
        ADD     A,L
        JR      C,MDRV5
        XOR     A        ;MIN X-COORD
MDRV5   LD      L,A
        JR      MDRV9
MDRV6   ADD     A,L
        LD      (IX+3),1 ;MOVE RIGHT
        JR      C,MDRV7
        CP      #FE      ;MAX X-COORD
        JR      C,MDRV8
MDRV7   LD      A,#FE    ;MAX X-COORD
MDRV8   LD      L,A
MDRV9   LD      B,#FF
        IN      A,(C) ;READING FROM PORT Y-COORD (0-#FF)
        LD      (MPORTS+1),A
        SUB     D
        JR      Z,MDRV14
        NEG
        JP      P,MDRV11
        LD      (IX+1),1 ;MOVE UP
        ADD     A,H
        JR      C,MDRV10
        XOR     A        ;MIN Y-COORD
MDRV10  LD      H,A
        JR      MDRV14
MDRV11  ADD     A,H
        LD      (IX+2),1 ;MOVE DOWN
        JR      C,MDRV12
        CP      #BF      ;MAX Y-COORD
        JR      C,MDRV13
MDRV12  LD      A,#BF    ;MAX Y-COORD
MDRV13  LD      H,A
MDRV14  LD      (MCOORD),HL ;NEW CURSOR POSITION IN PIXELZ
        POP     IX
        RET
; ***** DRIVER END *****

 ----------------------------------------------------------------------------

  Scheme and manual (c) 1994 Michael Kondratyev
  Mouse Driver source (c) 1995 Andrey Rachkin
  English translation (c) 1999 Mac Buster^Extreme
  Corrections and HTML (c) 2001 Jarek Adamski
  http://8bit.yarek.pl/hardware/zx.mouse/