flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > Strange PS2 Mouse Packet :-(

Author
Thread Post new topic Reply to topic
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
Hi, i am writing a polling code for PS2 mouse, but i am receiving strange packet format. Anywhere i found that standard sequence is: Control flags, x delta, y delta, but i am receiving the three bytes in the order: x delta, control flags, y delta.
I am confused a lot. Soem body have pass the same experience, or i am wrong at code...? Here is the read code, i use the actual var assigment but in comments the documented one.
The previous code is the default initialization comands for PS2 (F6,F4)
And the rest is for visualize mousex, mousey and control in binary format. I know the packet is right because of this and i am able to see buttons state data when are used.
Code:
     mousepoll: in      al,64h
                test    al,1
                jz      mousepoll

                test    al,20h          ; Test for mouse data
                jz      mousepoll

                cmp     [secuencia],0   ; Check packet sequence
                jne     @f
                in      al,60h
                mov     [mousey],al     ; read first packet(should be control flags but results in _y delta)
                inc     [secuencia]
                jmp     mousepoll
            @@: cmp     [secuencia],1   ; Check packet sequence
                jne     @f
                in      al,60h
                mov     [control],al    ; read second packet(should be _x delta but results in control flags)
                inc     [secuencia]
                jmp     mousepoll
            @@: in      al,60h
                mov     [mousex],al     ; read third packet(should be _y delta but results in _x delta)
                mov     [secuencia],0
    

May be i am missunderstanding ps2 protocol? Sad

_________________
i don't hate goto
Post 23 Mar 2012, 22:05
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 258
Location: California
what is "secuencia" initialized to?
Post 23 Mar 2012, 22:35
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
When a packet is marked as ready, you can read all data bytes at once without re-polling, so there should be no reason to force the sequence.
Post 24 Mar 2012, 00:16
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 258
Location: California
Quote:

When a packet is marked as ready, you can read all data bytes at once without re-polling, so there should be no reason to force the sequence.

you need to poll for the next byte. in fact, I've had issues in this respect with my driver. VirtualBox allows you to read in each byte as easily as a sequence of in instructions yet VMware (and my real hardware) simply ends up reading in the same byte each time.
Post 24 Mar 2012, 01:18
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
Hello BAiC! secuencia is initialized to zero. I copy the code, it is just a simple floppy boot code. I am testing it on qemu:
Code:
use16
org 7C00h

          mov     di,1660
             mov     ax,0b800h
           mov     es,ax
           @@: in  al,64h
              test    al,2
                jnz     @b              
            mov     al,0A8h         ; Activar el dispositivo auxiliar PS2
               out     64h,al

      @@:     in      al,64h
              test    al,1
                jz      TestOut
             in      al,60h
              jmp     @f
       TestOut: test  al,2
                jnz     @b

          @@: in  al,64h
              test    al,2
                jnz     @b
          mov     al,0D4h         ; Indicar el envío de un comando al dispositivo
            out     64h,al

      @@: in  al,64h
              test    al,2
                jnz     @b
          mov     al,0F6h         ; Enviar comando reset(para inicializar el dispositivo)
             out     60h,al

      @@:     in      al,64h
              test    al,1
                jz      @b
          in      al,60h

          cmp     al,0xAA
             je      @f

          @@: in  al,64h
              test    al,2
                jnz     @b
          mov     al,0D4h         ; Indicar el envío de otro comando
         out     64h,al

      @@: in  al,64h
              test    al,2
                jnz     @b
          mov     al,0F4h         ; Activar el ratón
         out     60h,al

     mousepoll: in    al,64h
              test    al,1
                jz      mousepoll

               test    al,20h
              jz      mousepoll

               ; Here starts the problematic part, just at sequence reading            
            cmp     [secuencia],0
               jne     @f
          in      al,60h
              mov     [mousey],al
         inc     [secuencia]
         jmp     mousepoll
       @@: cmp [secuencia],1
               jne     @f
          in      al,60h
              mov     [control],al
                inc     [secuencia]
         jmp     mousepoll
       @@: in  al,60h
              mov     [mousex],al
         mov     [secuencia],0

           push    di              
            mov     al,[control]
                call    bin8
                add     di,144
              mov     al,[mousex]
         call    bin8
                add     di,144
              mov     al,[mousey]
         call    bin8
                pop     di
          
            push    di
          add     di,20
               test    [control],1
         jz      @f
          mov     [es:di], word 0100111001001001b
         mov     [es:di+2], word 0000111000100000b
               mov     [es:di+4], word 0000111000100000b
           @@:     test    [control],2
         jz      @f
          mov     [es:di], word 0000111000100000b
         mov     [es:di+2], word 0000111000100000b           
            mov     [es:di+4], word 0100111001000100b
           @@:     test    [control],4
         jz      @f
          mov     [es:di], word 0000111000100000b
         mov     [es:di+2], word 0100111001000011b
               mov     [es:di+4], word 0000111000100000b
           @@: pop di
          jmp     mousepoll

       bin8:       mov     cx,8
            @@:     shl     al,1
                jc      uno
         mov     [es:di],word '0 '
             add     di,2
                loop    @b
          ret
 uno:        mov     [es:di],word '1 '
             add     di,2
                loop    @b
          ret

      secuencia db 0
     control db 0
         mousex db 0
         mousey db 0

times 510-($-$$) db 0
            dw 0xAA55
    
Post 24 Mar 2012, 03:10
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 258
Location: California
the error that you describe sounds like you haven't read in all of the data bytes from the initialization sequence.
Post 24 Mar 2012, 09:50
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 258
Location: California
immediately before the "mousepoll" label you are issuing Command 0xF4. That command has a response byte which you'll need to poll for. I'm looking at my driver for that type of command and it has an interrupt which expects to read in 1 byte. my driver is an Interrupt-powered State Machine so it looks considerably different from what you have.
Post 24 Mar 2012, 10:02
View user's profile Send private message Visit poster's website Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
Thank's a lot BAiC! It works fine now!!!!
Just adding a read poll before label:
Code:
          @@:     in      al,64h
              test    al,1
                jz      @b
          in      al,60h
    
Post 25 Mar 2012, 00:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.