Welcome, Guest. Please login or register.


Author Topic: Universal Mouse Driver (Read 77606 times)

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Universal Mouse Driver
« on: 2015.July.02. 16:29:48 »
Now that the  PS/2 mouse interface(Pear´s EnterMice) is closer and closer to be real, it's increasingly necessary to have a Mouse Driver that serves to almost any controller type.

The problem here is that a few people still have old interfaces(Boxsoft or Hsoft), and they can't be forgotten when thinking on new developments.

There are already Boxsoft drivers modified to work with Mészáros' serial cards, but they are modified from the GUY KOPEXY's caped ones, and then they can't read a Neos mouse.

Recently I've achieved to mix the Hsoft drivers with the latest 1.1 Boxsoft version. Zozo says they work on the serial side...

Then he suggested me to broaden the INPUT_DEVICE variable:

I more prefer use variable 189:
0: Int Joy
1: Ext 1
2: Ext 2
3: Boxsoft mouse
4: EnterMice
5: serial in Mouse System mode
6: serial in Microsoft mode
(7: the Rat?)

The PaintBox 2.1 already can set the 189 to 0-7 (F1-F8 keys)

I'm not a real programmer, but at last I've managed to approach his wishes....

By now option 5 and 6 do the same(Mouse Systems+internal joy) but I'm studying the 8251a UART to see what I can do to read a Microsoft mouse...

And about the "Rat"(Patkány)... I even don't know how it works....


MOUSEHmix.EXT has to be renamed to Mouse.xr to be usable with Paintbox or the EGI. If you want to test it from basic you must load it and use :pb on EXOS to link the driver.


The next great modification of the driver will be to adapt it to the new Prodatron's MSX protocol. It will allow in EnterMice mode the use of up to five mouse buttons and the Wheel, on new programs.
« Last Edit: 2015.July.03. 15:40:30 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #1 on: 2015.July.05. 23:43:23 »
I'm studying the Hsoft part of the driver. It is odd, very odd. But brilliant....

Here we have the original EXOS rst 30 call:

002B 00 NOP
002C 00 NOP
002D 00 NOP
002E 00 NOP
002F 00 NOP
0030 F3 DI
0031 32 5A 00 LD  (005Ah), A
0034 B7 OR   A
0035 E3 EX  (SP), HL
0036 18 07 JR  003Fh
0038 F5 PUSH AF
0039 37 SCF
003A 18 09 JR  0045h
003C C3 FF 00 JP  00FFh
003F 7E LD  A, (HL)
0040 23 INC  HL
0041 E3 EX (SP), HL
0042 32 59 00 LD (0059h), A
0045 DB B3 IN A,(B3)
0047 32 55 00 LD (0055h), A
004A 3E 00 LD A, 00
004C D3 B3 OUT (B3), A
004E C3 10 C4 JP C410h


Then in the driver they hook a different memory segment and address(where the driver is):

in a, (0B3h)
 ld (4Bh), a
 ld hl, INT   ; This is the subroutine where the read of the serial port is made in the driver
ld (4Fh), hl
ld hl, 0B3D3h
ld (2Bh), hl ; Puts "OUT (B3),A" at 2Bh



Later, in the INT subroutine, this is the way it returns to C410:

INT800:
 pop af
 pop de
 jr nc, INT900 ; EXOS call
 in a, (0B4h)
 and 10101010b
 scf
 jr nz, INT900 ; Interrupt
 ld hl, 0FBF1h
 ld (2Dh), hl
 ld a, 0C9h ; 'É'
 ld (2Fh), a
 pop hl
 ld a, (55h)
 jp 2Bh ; OUT (B3),A;POP AF;EI;RET
; ---------------------------------------------------------------------------

INT900:
 ld hl, 10C3h
 ld (2Dh), hl
 ld a, 0C4h ; 'Ä'
 ld (2Fh), a
 pop hl
 ld a, 0
 jp 2Bh          ;OUT (B3),A;JP C410


It creates for two options two different little codes on that unused bytes from 2Bh to 2Fh..!

On another part the code even auto-modifies itself!

Is for that "details" I doubt the serial mouse can be ported to SimbOS.....
« Last Edit: 2015.July.06. 23:28:54 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #2 on: 2015.July.12. 22:58:07 »
The Hsoft mouse driver maintains a counter of what byte of the five count cycle is actually reading, and shows it as a number over the "a" letter inside of the "program" word  at the Status Line:

ERZEK10:
 
 add a, 31h ; Ascii  '1'    ;a holds the number on the five count cycle.
 ld hl, (0BFF6h)  ;ST_POINTER
 ld de, 1Bh        ;adds 24
 add hl, de
 ld (hl), a          ;somewhere at the Status Line
 ret


This subroutine was put for test only and can be suppressed.

Edit: It is a count of pressed buttons, from 0 to 3 and again 0, left or right counts,  central button doesn't counts. The result is viewed as the respective ASCII character on the Status Bar.
« Last Edit: 2015.September.16. 10:27:53 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #3 on: 2015.July.26. 19:06:16 »
At last I've managed to fix one error with the buttons.

The principal button of the Boxsoft interface is the right one unlike other computers, and is read at the L column.
On the other side the secondary is at the left but you can't press it in mouse mode(you lose the movement of the pointer), only in joystick mode %&&!.... To make things worse this button is the same fire of the Joy1 controller on J column .

It was not Tim Box's fault, because the Enterprise control ports are very strange and he did what he could to match them with the even more strange Neos mouse. We could consider it a prowess...

On the Entermice mode some things have been modified to avoid incompatibilities and one of them is the position of the buttons.

Now the main button is at the left(no problem with left-handed here...) and is read on the K column.
The right button is the secondary now but is read in the same L column.

What I have achieved now is to store its status on the right place, this is, no mater if  Boxsoft or Entermice mode (3 or 4 on the system var 189, INPUT_DEVICE), the main button will be stored on system Var 188(FIRE_STATUS), and the secondary on bit 7 of system Var 190(SW_Z_STATUS). (I know, it could appear easy... but not for me...)


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


Also, I present here the implementation of Prodatron's extension for the MSX protocol.

Provided you have an Entermice adapter(not yet...) or an Arduino Ps/2 to MSX adapter+Boxsoft modified interface(my case), the driver now allows mice with up to five buttons and a wheel. Now I can use a basic PS/2 mouse with only two buttons(the reading routine only reads two bytes) or a more actual mouse with wheel(then it reads two more bytes).

Why so much buttons and wheel? Because they are implemented on marvellous SymbOS...(not yet the Enterprise version obviously...)

But the best is that now all these buttons and wheel are accessible on the EXOS variable 190(SW_Z_STATUS) for use on new development or immediately on Basic....

You can read them as this: ASK 190 A will store the status on variable A.

Bits 0 to 3: Z movement(wheel) four signed bits for a scroll displacement of up to 7 or -8 lines.
Bits 4 to 6: three spare buttons. bit 4 is the wheel button.
Bit  7: secondary mouse button.

I have to play with it to discover little errors, but the next mayor change on the next version will be Microsoft serial mouse
 reading. That will took a time, but by now the Entermice option is complete.

As always you must rename the extension to Mouse.xr to use it on the EGI.
And on Basic execute :PB to initialise the mouse driver.
« Last Edit: 2015.July.29. 12:33:49 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #4 on: 2015.July.28. 15:30:22 »
I've realised that just only copying the value of Z(wheel) to the system variable is not sufficient. It isn't because the data read is the displacement occurred between two readings. So if you stop suddenly your finger over the wheel the data read will be zero and all previous movement will be lost.

Then is necessary to add successively the readings to the system variable ignoring it if exceeds 7 or -8.

It will be the task of the User (the program that access the system variable)  to reset the counter and supervise further movement of the wheel. Once  read the movement it must reset the counter again and go to execute the reaction, for example a scroll. And then it must return again and again to read the movement and inmediately reset the counter.

What do you think? I accept suggestions...
« Last Edit: 2015.July.29. 12:33:16 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #5 on: 2015.August.04. 21:41:16 »
I want to do also a buttons&wheel read by the channel as the driver do when you write "O", "o" or "p" on it.

I have holidays to think on it.... but no real Enterprise.

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #6 on: 2015.August.11. 17:28:12 »
I refuse to do a new read function on the channel for the spare buttons and wheel. The driver would need changes I'm not prepared to do. Is easier and faster to do a system variable read call and process the data.

But I've been thinking about  potentially writing a click or a  mouse movement on the channel. Maybe when we have net access...
« Last Edit: 2015.August.12. 11:05:34 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #7 on: 2015.August.12. 10:49:19 »
I've fixed the driver to store the count of Z movement. Now the driver will add the data read to the old value but will stop the count when greater than  7 or lower than -8.

At the moment I don't have my EP to test it.


Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #8 on: 2015.September.02. 13:02:56 »
I've tested the modification but it doesn't work as expected.

I want to add two signed bytes, one on "a" with the other in "(hl)".

The result can't be higher than 7 nor lower than -8 as only the first nibble is significant.

This is my attempt:

      add a, (hl)
      cp 128                              ;positive or negative?
      jr c, POSITIVE
      cp 248                             ;lower than -8?
      jr nc, FINISHED             ;
      ld a, 248                          ; -8 is the bottom
      jr FINISHED
POSITIVE:
      cp 8                                 ;higher than 7?
      jr c, FINISHED
      ld a, 7                              ; 7 is the top
FINISHED:                                                  ; the excess  of 7 or -8 has been wipped


It works right with positive results, but not with negatives.

I want to learn what I'm doing bad... can somebody give me advice?

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #9 on: 2015.September.02. 21:20:45 »
What exactly does not work ?
I tested your code and received the correct results - both numbers positive and negative.

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #10 on: 2015.September.02. 21:46:42 »
Maybe I have the same Basic problem.....

Thanks.


What I'm trying to do is to maintain an account of pulses for the wheel, then it can't go greater than 7 nor lower than -8. The user(the program accesing the system variable) has to reset it and read later the pulses given.

I will try with the brute force trick from Zozo's.
« Last Edit: 2015.September.02. 22:07:03 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #11 on: 2015.September.02. 21:55:04 »
But, what I' saying? The mouse driver is interrupt-driven....

If the routine is well writen then I will test other assembly lines that can corrupt the result.

Thanks Pear.

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #12 on: 2015.September.05. 22:26:03 »
I've found the error..... a beginner's one... :

          and 00Fh
           bit 4, a
           jr z, SIGN_DONE
           or 0F0h
SIGN_DONE:      



I used this code to expand the sign from the first nibble of register "a" to all the byte, but of course the test has to be made to bit 3....

Now, as promised, the lowest nibble of system var 190 holds a counter of wheel displacement from 7 to -8.

This is the fixed driver:
« Last Edit: 2015.September.07. 11:44:05 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #13 on: 2015.September.16. 17:51:25 »
Actually I'm modifying the driver to work with the Mészáros' serial cards reading common Microsoft serial mice instead of the scarce Mouse Systems mice. The protocols are a little different but I think I've found the way to read the two systems.

The controller options(var 189) are now complete:

0: Int Joy
1: Ext 1
2: Ext 2
3: Boxsoft mouse
4: EnterMice
5: serial in Mouse System mode + internal joy
6: serial in Microsoft mode + internal joy

The problem here is: I don't have that serial hardware to verify if it works.....

I don't know how many users of that card exist(probably one or two...). Maybe somebody can try a Microsoft mouse with the driver:

Offline gflorez

  • EP addict
  • *
  • Posts: 3607
  • Country: es
    • Támogató Támogató
Re: Universal Mouse Driver
« Reply #14 on: 2015.September.16. 18:09:59 »
I've read on old forums that the typical Microsoft or compatible serial mice can read also Mouse Systems protocol. Just in the same way as a Neos mouse can be transformed and act as a sort of joystick: pressing the left button while turning on the computer. Or can be the right button...
« Last Edit: 2015.September.16. 19:48:27 by gflorez »