Welcome, Guest. Please login or register.


Author Topic: EnterMice (Joy & PS/2 mouse interface) (Read 242824 times)

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #60 on: 2015.June.02. 07:24:10 »
I understand the PS/2 protocol. In a few days I finish write it full support.
I'm starting to think about MSX protocol. I read that each successive reading is performed after complementing the state of the RTS line.
I was a little worried. I was counting on falling edge, because then I could use a hardware interrupt instead of polling (PS/2 operates on interrupts).
I have not found anywhere timings of MSX protocol.
Does anyone could confirm my sketch made on the basis of available descriptions ?
Code: [Select]
            below 40 ms pulse (Tcycle)  
    long gap        ____        ____        ____        ____        
    how long ?(T1) /    \      /    \      /    \      /    \      
RTS ______________/      \____/      \____/      \____/      \________________
                    |
    ________________  ____  ____  ____  ____  ____  ____  ____  ____  _________
                    \/ HX \/ LX \/ HY \/ LY \/ HB3\/ LB3\/ HB4\/ LB4\/
D0..D3               \____/\____/\____/\____/\____/\____/\____/\____/
               T2-> | |_     _     _     _     _     _     _     _
READ                  / \   / \   / \   / \   / \   / \   / \   / \
    _________________/ 1 \_/ 2 \_/ 3 \_/ 4 \_/ 5 \_/ 6 \_/ 7 \_/ 8 \___________
               T3->   ||
As READ I marked the moment in which, it seems to me, is performed reading of D0..D3 line.
I am most interested labeled timings.
Tcycle - the time between successive readings a nibble
T1 - the time interval before the next full reading, I assume that is longer than Tcycle
T2+T3 - time to set and stable data on lines D0..D3 after the change in RTS
« Last Edit: 2015.June.03. 08:20:15 by pear »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #61 on: 2015.June.02. 09:24:05 »
As far a I know:

The Neos chip(inside the MSX mouse) triggers the sequence when it detects the STROBE signal flipped from 0v to +5v during at least 135000 ns.

(481 tics x 285 ns on the MSX Z80 at 3,58MHZ)(542 tics x 250ns on the Enterprise Z80 at 4Mhz).

The first nibble X is send in parallel on the four directions of the mouse port, pins 1 to 4.

The Neos chip waits  for the STROBE signal flipped from +5v to 0v at least 70000 ns.

If so the second nibble X is send.

The Neos chip waits  for the STROBE signal flipped from 0v to +5v at least 70000 ns.

If so the first nibble Y is send.

The Neos chip waits for the STROBE signal flipped from +5v to 0v at least 70000 ns.

If so the second nibble Y is send.

---------------
This ends the sequence until the STROBE signal is flipped again from 0v to +5v during at least 135000 ns.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #62 on: 2015.June.02. 09:32:05 »
This is the routine used on MSX1 machines, thanks to Prodatron here.

; A routine  to read the mouse on a MSX machine with Z80 running at 3.58MHZ:
;                   1tic=285ns
;
;        LD    D,&B10010011     ; Use these values for a mouse in port 1
;        LD    E,&B00010000
;
;
;        LD    D,&B11101100     ; Use these values for a mouse in port 2
;        LD    E,&B00100000
;
; Read the mouse.   Input: D/E=.... Output: H=X-offset, L=Y-offset
; Note that the routine will output H=L=255 if no mouse is present!
GTMOUS:
 
        LD    B,WAIT2          ; Long delay for first read
        CALL  GTOFS2          ; Read bit 7-4 of the x-offset
        AND   0FH
        RLCA
        RLCA
        RLCA
        RLCA
        LD    C,A
        CALL  GTOFST          ; Read bit 3-0 of the x-offset
        AND   0FH
        OR    C
        LD    H,A             ; Store combined x-offset
        CALL  GTOFST          ; Read bit 7-4 of the y-offset
        AND   0FH
        RLCA
        RLCA
        RLCA
        RLCA
        LD    C,A
        CALL  GTOFST          ; Read bit 3-0 of the y-offset
        AND   0FH
        OR    C
        LD    L,A             ; Store combined y-offset
        RET
 
WAIT1:  EQU   10              ; Short delay value
WAIT2:  EQU   30              ; Long delay value
 
GTOFST: LD    B,WAIT1
GTOFS2: LD    A,15            ; Read psg register 15 voor mouse
        OUT   (0A0H),A
        LD    A,D
        OUT   (0A1H),A
        XOR   E
        LD    D,A
 
WAIT:   DJNZ  WAIT           ; Extra delay because the mouse is slow.
 
        LD    A,14
        OUT   (0A0H),A
        IN    A,(0A2H)
        RET

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #63 on: 2015.June.02. 09:39:11 »
And this is the actual routine on the Enterprise128, Z80 4Mh, 1 tic = 250ns:

sub_C3C8:

     ld a, (INPUT_DEVICE) ; input device, EXOS variable 189, default 3
     cp 1
     jp z, EXT1_READ ; go to external joystick 1 reading
     cp 2
     jp z, EXT2_READ ; go to external joystick 2 reading
     or a
     jp z, INT_READ ; go to internal joystick  reading
;Here begin the Neos mouse reading
     ld hl, X_REL ; first byte
     ld a, 2 ; RTS low
     out (0B7h), a
     ld b, 8 ; long delay
     call WAIT
     call READ_4BIT ; read four higher bits
     rld ; push them in (HL)
     xor a ; RTS high
    out (0B7h), a
     ld b, 1 ; short delay
     call WAIT
     call READ_4BIT ; read four lower bits
     rld ; push them in (HL)
     ld hl, Y_REL ; second byte
     ld a, 2 ; RTS low
     out (0B7h), a
     ld b, 1 ; short delay
     call WAIT
     call READ_4BIT ; read four higher bits
     rld ; push them in (HL)
     xor a ; RTS high
     out (0B7h), a
     ld b, 1 ; short delay
     call WAIT
     call READ_4BIT ; read four lower bits
     rld ; push them in (HL)

                         <======Here will be added the future Wheel and three spare buttons reading

     xor a
     out (0B5h), a
     in a, (0B6h) ; read Mouse button. Modified to read left button. Not valid for Neos!!
     and 2               ; Mask: 1 for bit 0, 2 for bit 1, 4 for bit 2
     ; srl a
     srl a ; no "srl a" -> data taken from J, one -> from K, two ->  from L
     xor 1
     ld (FIRE_STATUS), a ; EXOS Variable 188
     call sub_C4B1 ; this is the "corrections and drawing" routine where the "velocity" 1.1 modification was made
     ld a, (X_REL)
     ld c, a
     ld a, (Y_REL)
     or c
     ret
; End of function sub_C3C8
--------------------------------------------
WAIT:
     nop
     nop
     nop
     dec b
     jr nz, WAIT
     ret
; End of function WAIT
--------------------------------------------
READ_4BIT:
     ld b, 4
     ld d, 0

BITREAD:
     ld a, b
     inc c
     out (0B5h), a
     in a, (0B6h)
     rra                     ; Two rigth sift ---> data taken from K column
     SRL a                   ;better "srl a" than "rra" as the driver remains the same lenght
     rl d
     djnz BITREAD
     ld a, d
     ret
; End of function READ_4BIT
« Last Edit: 2015.June.02. 09:45:55 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #64 on: 2015.June.02. 09:56:32 »
We are speaking here of the MSX STROBE signal normally at 0v, but you know already that the RTS signal is normally at +12v.

Yo have put a inverter-reducer to cope that, haven't you?

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #65 on: 2015.June.02. 10:58:22 »
Prodatron and NYYRIKKI have expanded the MSX protocol to add the information of the wheel and three buttons more:

Byte 1: X-axis signed delta (Original protocol) Positive value means mouse is moved to Left.

Byte 2: Y-axis signed delta (Original protocol) Positive value means mouse is moved to Up.

Byte 3 high nibble = ID nibble: (bits 7-4) = 0001
   bits 7 & 6 are "00" for MSX-BIOS mouse identification
   bits 5 & 4 are "01 "for Extended mouse protocol identification

Byte 3 low nibble = Button nibble:
   bit 3 : 0 = Unused, reserved for future (to expand ID or to support additional button)
   bit 2 : 5th mouse button: 0=Not pressed, 1=Pressed
   bit 1 : 4th mouse button: 0=Not pressed, 1=Pressed
   bit 0 : 3rd button (wheel button): 0=Not pressed, 1=Pressed

Byte 4: Z-axis signed delta. Positive value means wheel is moved to Up

Please note:

    If bytes 3/4 are not read within 3 ms (counting starts from reading of 1st byte) mouse will return 1st byte on next read. (This is to improve compatibility with existing software)
    Minimum time between clocks is 0.18 ms.

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #66 on: 2015.June.02. 11:30:57 »
We are speaking here of the MSX STROBE signal normally at 0v, but you know already that the RTS signal is normally at +12v.
You have put a inverter-reducer to cope that, haven't you?
In the current draft of + 12V from RTS gives logical 0 on the MCU input.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #67 on: 2015.June.02. 12:12:15 »
Ok, and when 0v on RTS you have +5v on the MCU. That is the way the MSX side can work.



Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #68 on: 2015.June.02. 12:45:33 »
Code: [Select]
logic |   RS-232    | RS-423 | Enterprise | TTL
-------------------------------------------------
  0   | +12V or +5V |  +6V   | +12V (+7V) |  0 V
  1   | -12V or 0V  |  -6V   |  0V  (-5V) | +5 V  
« Last Edit: 2015.June.02. 12:56:00 by pear »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #69 on: 2015.June.02. 13:09:57 »
Ok,ok. Only for reassuring....

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #70 on: 2015.June.02. 13:11:33 »
It will be useful for the future :)

Offline pear

  • EP lover
  • *
  • Posts: 825
  • Country: pl
  • Z80 only
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #71 on: 2015.June.02. 13:44:58 »
I still please to confirm my timing diagram.
I am a visual person and I prefer one drawing than many sides description.

EDIT:
One more thing. On the basis of the shortest of time I want to set the resolution of timer (also on interrupts).
Then I need not to count of the procedure cycles and it is easier to change the timing of the MCU if necessary.
« Last Edit: 2015.June.02. 14:17:58 by pear »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #72 on: 2015.June.02. 16:22:03 »
It seems to be good, only RTS  at the end has one more cycle than necessary.

About timings or interrupts, I don't understand. The MCU has to wait for the changes on STROBE and check that the delays are correct. Then write the output register and wait again.

It is a passive task for a powerful MCU....


Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14779
  • Country: hu
    • http://enterprise.iko.hu/
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #73 on: 2015.June.02. 21:36:28 »
About the timings: good idea also calculate up to 10MHz Z80. Will be great if can work without delays.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: EnterMice (Joy & PS/2 mouse interface)
« Reply #74 on: 2015.June.02. 22:05:32 »
Or some settings to select the Mz of the Z80 to make it easier if it can't be done automatically. May be with rapid pulses on the RTS line with a program. Or better comunicating by the serial port with the MCU.....