Mouse Drivers for Your BBC BASIC Programs By Tim Surtell Since some mice have a serial interface like the Notepad and Notebook computers, I brought a cheap mouse (the "Ice Mouse" from Dixons) to see if I could program a mouse driver in BASIC. After doing some research on the internet (see foot of page) I found out that there are three main types of mice, of which only the 'serial' type can be used on the NCs: PS/2 mice have a serial interface, but the logic levels used a 0V and +5V. Bus mice have no microprocessor inside them since all decoding is done by a circuit inside the computer. The only components inside these mice are the switches, LED's, and photo-diodes. Serial mice can be used with the NC since they use the same RS232 serial transfer protocol as the NC, which has logic levels of -12V and +12V. These mice even have the correct 9-pin connector supplied, so there is no wiring. Making your mouse work on the NC There are two systems in use for sending data from a serial mouse. To get your mouse working on the NC, plug it into the serial port and then adjust the settings in the Serial Terminal Program (FUNCTION-S) to those below : Baud rate = 1200 You can now go to BASIC and try this short program which reads in the bytes sent from the mouse and displays them on the screen. 10 CLS If you don't know what system your mouse uses, this program can tell you, since pressing the left button will make the mouse send three bytes if it's using 'Microsoft Mouse' or five bytes if it's using 'Mouse Systems Mouse'. Microsoft Mouse The mouse drivers I have written have been for the 'Microsoft Mouse' system, so I'll only explain how this works. The three bytes sent are decoded as follows:
The X and Y information is in two signed bytes. This means if bit 7 is 0 the increment is negative, and if it 1, the increment is positive. When the increment is negative, the value in bits 0-6 needs to be subtracted from 128 in order to find the actual distance to be moved. Mouse Drivers The first method I used to translate the X,Y data into movement of a graphics cursor was to simply add or subtract the value from the current X,Y position of the cursor -- a linear relationship. This works OK if the mouse is moved only small amounts, but because BASIC programs run fairly slowly, moving the mouse a large amount meant there was a delay before the cursor actually stopped at a new position. This problem makes it very hard to co-ordinate the mouse movement, since the user thinks the mouse is not moving fast enough, so he moves the mouse faster, and the cursor ends up in completly the wrong place! This problem is solved by the program below, which collects all the data from the mouse until it stops, before the cursor is actually moved on the screen. Mouse Driver version 5 ... 1.6kb Program analysis
If you are using an NC100, Y in line 90 needs to be changed to 32. To produce a text cursor, a new method was used. This time, any increment over a certain threshold makes the mouse move one character/line. Mouse Driver version 6 ... 1.7kb The program works in a similar way to the first one.
If you are using an NC100 MY in line 100 needs to be changed to 56, and MY in line 300 needs to be changed to 56. PC Mouse Information by Tomi Engdahl on ePanorama.net: www.epanorama.net/documents/pc/mouse.html Programs that use the mouse driver:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home | Features | Data Sheets | Questions | BBC BASIC | Software | |