<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 31 Aug 1999 14:58:35 +0100
From   : jgh@... (Jonathan Graham Harston)
Subject: Mouse on the BBC

Carsten Langkvist Brasholt <clb@...> wrote:
> Does any of you guys know how to connect a standard PC-mouse to the
> user-port in order to use the AMX-software?? (if at all possible?)
 
No such thing as a 'standard' PC mouse.
 
Iain Williamson <Iain@...> wrote:
> The AMX mouse connected to the user port? That's strange; I would have
> assumed it'd be an old-fashioned quadrature mouse, and be connected to
> the analogue port. If that's the case, you can only get quadrature
 
The /analogue/ port????  Mice are digital creatures.  On a BBC, a mouse
plugs into the user port.
 
PC mice come in three 'flavours': PS/2 clocked serial data, PC serial
port, and the quadrature mouse.  The PS/2 mouse is a serial mouse, but
that doesn't mean it's an RS232 mouse!  It just means that the data is
sent serially, in the same way that an Arc or PC keyboard sends serial
data.  Serial does not mean RS232.  RS232 means serial.
 
Serial port mice plug into the serial port and send several bytes of data
to the computer every time it changes state.  You could use one of these
on a BBC by plugging it into the BBC's serial port and writing the correct
drivers.
 
The quadrature mouse, however, is a 'proper' mouse.  It is also known as a
PC-BUS mouse or an Amiga mouse, and is the type used on the Archimedes,
Amiga, Atari, Amstrad and BBC/Masters.  It sends purely the signals that
say what it is doing, vis:
 
   Mouse has moved horizontally  - Xaxis
   Horizontal direction          - Xdir
   Mouse has moved vertically    - Yaxis
   Vertical direction            - Ydir
   Button 1 state                - LEFT
   Button 2 state                - RIGHT
   Button 3 state                - MIDDLE
 
...and with +5v and 0v, that make 9 lines, which will fit into a 9-pin D
plug.  The 'mouse have moved' signals need to interrupt the computer, and
the other lines are data that the computer reads when it needs to.
 
There are various plugs you can find on the mouse's tail:
 
  9-pin D Compact wiring
  9-pin D Amiga/Atari wiring
  PS/2 mini plug
  Arc mini plug
 
The mice I use tend to be nice Archimedes mice with the plug chopped off
and a 9-pin D Compact plug put on.  I also have a few small adaptors to
plug a Amiga-wired mouse into to convert it to Compact wiring.
 
Rather that fiddling about trying to wire a 20-pin IDC connector onto a
mouse to plug into the BBC or Master I have made up some short cables with
an IDC plug at one end and a 9-pin D socket at the other end which I lead
permanently plugged into my BBCs and Masters.  The mice can then easily
plug into the 9-pin D socket.
 
The Atari mice are wired         Compact mice are wired
 as follows:                      as follows:
 
  Xdir  --> 1                      Xdir  --> 1
  Xaxis --> 2                      R     --> 2
  Ydir  --> 3                      M     --> 3
  Yaxis --> 4                      Ydir  --> 4
  M     --> 5                      Xaxis --> 5
  L     --> 6                      L     --> 6
  +5v   --> 7                      +5v   --> 7
  0v    --> 8                      0v    --> 8
  R     --> 9                      Yaxis --> 9
 
So, an Atari-to-Compact adaptor is wired as:
 
          1  -->  1
          2  -->  5
          3  -->  4
   9-D    4  -->  9  9-D
  Socket  5  -->  3  Plug
          6  -->  6
          7  -->  7
          8  -->  8
          9  -->  2
 
A Compact 9-D connector to BBC/Master user port adaptor is wired as:
 
       Xdir  1 -->  13 D0
       R     2 -->  20 D7
       M     3 -->  19 D6
9-D    Ydir  4 -->  15 D2   20-pin
Socket Xaxis 5 -->  11 CB1   IDC
       L     6 -->  18 D5
       +5v   7 -->  1  +5v
       0v    8 -->  3  0v
       Yaxis 9 -->  12 CB2
 
About ten years ago I got a load of Archimedes mice cheaply as the plugs
had got all mangled, and they are a real pain to attach a new one.  I just
chopped them off and soldered 9-pin Ds to them.
 
That's the hardware dealt with, now the software.
 
Every time the mouse moves, it interrupts the computer.  On the
BBC/Master, that is the CB1 and CB2 interrupts on the user port.  On the
interupt, the driver looks at the Xdir and Ydir lines to see which
direction on each axis the mouse has moved.  When the user needs to know
the state of the buttons, the R/M/L lines are read.
 
Now here, we have a small problem.  They signal definitions that AMX
defined for the BBC are different to what Acorn defined on the Compact. 
 
On the BBC/Master:     On the Compact:
 
   Xaxis  CB1             Xaxis  CB1
   Yaxis  CB2             Yaxis  CB2
   Xdir   D0              Xdir   D3
   Ydir   D2              Ydir   D4
 
   LEFT   D5              LEFT   D0
   MIDDLE D6              MIDDLE D1
   RIGHT  D7              RIGHT  D2
 
However, this is fairly easy to cope with.  On the startup of the mouse
driver, it should check what host it is running on, and change it's
actions accordingly.
 
The driver must set up the User VIA to interrupt on CB1 and CB2, and point
the interupt vector to point to its handler.
 
The first thing the handler must do is check if the interupt was from the
User VIA:
 
     .new_int
     LDA &FE6D:BMI user_via
     .do_old
     JMP (oldvecs)
 
and then check that it was CB1/CB2:
 
     .user_via
     AND #&18:BEQ do_old
 
Preserve everthing and disable interupts:
 
     LDA &FC:PHA
     TXA:PHA:TYA:PHA:SEI
 
Get the interupt info from &FE6D and write it back to clear them.
If it was CB1, note that it is X movement
If it was CB2, note that it is Y movement
 
Get the data from &FE60 to check the X&Y direction.
On a Compact, the Xdir is B3 (AND #&08), and the Ydir is B4 (AND #&10)
On a BBC/Mst, the Xdir is D0 (AND #&01), and the Ydir is B2 (AND #&04)
 
If the bit is set, the increment the mouse position, else decrement it.
The X position should be bound to &000 to &4FF, and the Y position should
be bound to &000 to &3FF.  I have found that one mickey = 4, so add or
subtract the position by 4.
 
When finished, restore everthing and exit:
 
     PLA:TAY:PLA:TAX:PLA:STA &FC:RTI
 
You should then provide routines to read the mouse state.  There are two
defined interfaces, AMX and Arc:
 
Osword 64:
Returns:  XY+0,1 Mouse X
             2,3 Mouse Y
             4   Text X
             5   Text Y
             6   Button state: RML-----
 
ADVAL(7) (Osbyte 128,7) - Read mouse X position
ADVAL(8) (Osbyte 128,8) - Read mouse Y position
 
INKEY-109 (Osbyte 129,&FF93) - Read RIGHT button
INKEY-13  (Osbyte 129,&FFF3) - Read RIGHT button
 
INKEY-108 (Osbyte 129,&FF94) - Read MIDDLE button
INKEY-12  (Osbyte 129,&FFF4) - Read MIDDLE button
 
INKEY-107 (Osbyte 129,&FF95) - Read LEFT button
INKEY-11  (Osbyte 129,&FFF5) - Read LEFT button
 
I have a *MOUSE command that works on all BBC/Master computers and
provided Osword 64, Osbyte 128 and Osbyte 129 read routines.  I will put
it on my website today, along with a test program that shows how to read
the mouse state.  They will be at http://mdfs.net/Software/CommandSrc/Mouse/
 
A common problem when wiring up a mouse is to find that one or both of the
directions are reversed.  Up/Down instead of Left/Right, or Right instead
or Left, etc.  U/D<->L/R means that you have the X and Y lines swapped. 
L<->R and U<->D means that you have a -dir and -axis line pair reversed.
 
I've found you can get hold of fairly nice PC BUS mice quite cheaply.  As
the dinkly little plugs are easily damaged and a real pig to replace, you
might be able to find some at a discount if they have damaged plugs.  Just
chop it off.
 
I wouldn't bother with any 2-button mice.
 
F. H. Choudhry wrote:
> that the one?  What kind of mice are the Risc PC ones and can they be
> interfaced to a BBC Micro that way, or in any way?
 
I beleive that RiscPC mice are OS/2 mice - they send state-change data
serially (not RS232!!!). The RiscPC philosophy was to be able to use lots
of off-the-shelf PC accessories - I believe the keyboard interface will
take a standard PC keyboard as well.
 
-- 
J.G.Harston (JGH BBC PD Library) 70 Camm Street, Walkley, SHEFFIELD S6 3TR
jgh@...                - Running on BBCs & Masters with SJ MDFS FileServer
            Z80+6502/CoPro+Tubes/Econet+SJ -- http://mdfs.net/
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>